{"id":42187,"library":"unist-util-add","title":"unist-util-add","description":"unist-util-add is a utility for the unified ecosystem that simplifies adding and managing extensions for toMarkdown, micromark, and fromMarkdown to data objects. Version 1.2.0, released in 2023, is the current stable version. It provides a single add() function that handles appending extensions to arrays, and it ships with TypeScript types. Unlike manually pushing to arrays, it handles initialization and validation. It requires Node.js >=18 and works with unified, mdast-util-to-markdown, micromark-util-types, and mdast-util-from-markdown.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/shlroland/unist-util-add","tags":["javascript","unist","unist-util","util","utility","remark","retext","rehype","remark-plugin","typescript"],"install":[{"cmd":"npm install unist-util-add","lang":"bash","label":"npm"},{"cmd":"yarn add unist-util-add","lang":"bash","label":"yarn"},{"cmd":"pnpm add unist-util-add","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only since Node >=18; use import syntax.","wrong":"const add = require('unist-util-add').add","symbol":"add","correct":"import { add } from 'unist-util-add'"},{"note":"This package exports both named and default exports; the default export is also the add function.","wrong":"import { add } from 'unist-util-add'","symbol":"add (default import)","correct":"import add from 'unist-util-add'"},{"note":"TypeScript type imports should use import type to avoid runtime errors.","wrong":"import { AddFunction } from 'unist-util-add' (when using at runtime)","symbol":"Types","correct":"import { add, type AddFunction } from 'unist-util-add'"}],"quickstart":{"code":"import { add } from 'unist-util-add';\nimport type { Data } from 'unified';\nimport type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown';\nimport type { Extension as MicromarkExtension } from 'micromark-util-types';\n\nconst data: Data = {};\n\nconst toMarkdownExt: ToMarkdownExtension = {\n  handlers: {\n    emphasis(node, _, state) {\n      state.write('*' + state.all(node).join('') + '*');\n    }\n  }\n};\n\nconst micromarkExt: MicromarkExtension = {\n  text: {\n    '123': {\n      tokenize(effects, ok, nok) {\n        const self = this;\n        return start;\n        function start(code) {\n          effects.enter('number');\n          effects.consume(code);\n          return more;\n        }\n        function more(code) {\n          if (code !== null && code >= 48 && code <= 57) {\n            effects.consume(code);\n            return more;\n          }\n          effects.exit('number');\n          return ok(code);\n        }\n      }\n    }\n  }\n};\n\nadd(data, 'toMarkdownExtensions', toMarkdownExt);\nadd(data, 'micromarkExtensions', micromarkExt);\n\nconsole.log(JSON.stringify(data));","lang":"typescript","description":"Demonstrates adding toMarkdown and micromark extensions to a unified data object using the add function."},"warnings":[{"fix":"Upgrade Node.js to version 18 or later.","message":"The package requires Node.js >=18.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure you are not relying on immutability; pass a new object if needed.","message":"The add function mutates the data object; it does not return a new object.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use add(data, 'fromMarkdownExtensions', [ext1, ext2]) to add multiple at once for fromMarkdownExtensions.","message":"For `fromMarkdownExtensions`, the parameter can be a single extension or an array of extensions; other fields only accept a single extension per call.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.2.0':31 '18':71 '2023':34 'ad':18 'add':4,8,44 'append':48 'array':51,62 'current':37 'data':28 'ecosystem':15 'extens':21,49 'frommarkdown':26 'function':45 'handl':47,64 'initi':65 'javascript':91 'manag':20 'manual':59 'markdown':80,90 'mdast':77,87 'mdast-util-from-markdown':86 'mdast-util-to-markdown':76 'micromark':24,82 'micromark-util-typ':81 'node.js':70 'object':29 'plugin':103 'provid':41 'push':60 'rehyp':100 'releas':32 'remark':98,102 'remark-plugin':101 'requir':69 'retext':99 'ship':54 'simplifi':17 'singl':43 'stabl':38 'tomarkdown':23 'type':57,84 'typescript':56,104 'unifi':14,75 'unist':2,6,92,94 'unist-util':93 'unist-util-add':1,5 'unlik':58 'util':3,7,11,78,83,88,95,96,97 'valid':67 'version':30,39 'work':73","created_at":"2026-06-04T18:56:02.612584+00:00","updated_at":"2026-06-04T18:56:02.612584+00:00","problems":[{"fix":"Use import { add } from 'unist-util-add' or ensure your project is configured for ESM.","cause":"Trying to import using CommonJS require on an ESM-only package.","error":"TypeError: add is not a function"},{"fix":"Run npm install unist-util-add and ensure tsconfig.json includes 'node_modules/unist-util-add' or has 'moduleResolution': 'node'.","cause":"TypeScript cannot find types because the package is not installed or types are not recognized.","error":"Cannot find module 'unist-util-add' or its corresponding type declarations."},{"fix":"Ensure the extension object matches the expected type for the field: toMarkdownExtensions, micromarkExtensions, or fromMarkdownExtensions.","cause":"Passing an extension of the wrong type to a field that expects a different type.","error":"Argument of type 'X' is not assignable to parameter of type 'ToMarkdownExtension | MicromarkExtension | FromMarkdownExtension | FromMarkdownExtension[]'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/shlroland/unist-util-add#readme","github":"https://github.com/shlroland/unist-util-add","docs":null,"changelog":null,"pypi":null,"npm":"unist-util-add","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}