unist-util-map is a utility for the Unist syntax tree ecosystem designed to create a *new* Unist tree by applying a mapping function to every node. Unlike many tree manipulation utilities that mutate the tree in place, `unist-util-map` always returns a completely new, transformed tree, preserving the original structure. The package is currently at version 4.0.0, with a release cadence that includes minor patch updates for bug fixes, documentation improvements, and internal refactors. Major versions are released less frequently, typically when significant breaking changes occur, such as updates to required Node.js versions or shifts to modern module systems. A key differentiator and important consideration for developers is its tree-cloning behavior; while excellent for immutable transformations, this approach can lead to performance overhead on exceptionally large trees. For scenarios involving potentially large trees and relatively few modifications, developers are often advised to consider alternatives like `unist-util-visit` or `unist-util-filter`, which offer different performance characteristics depending on the use case.
npm install unist-util-mapVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to import and use `unist-util-map` to create a new tree where all 'leaf' nodes have their `value` property changed to 'CHANGED', without mutating the original tree.
Migrate your project to ESM or use dynamic `import()` if you must use it within a CommonJS context. Always use `import { map } from 'unist-util-map'`.Ensure your Node.js environment is version 16 or newer. Older Node.js versions will fail to run the package.
Update your `@types/unist` dependency to the latest compatible version (`npm update @types/unist`) if you encounter type-related issues after upgrading `unist-util-map`.
For performance-critical applications with large trees, consider `unist-util-visit` for in-place modifications or `unist-util-filter` for filtering. Profile your application to determine the most efficient approach for your specific use case.
Always import symbols directly from the main package entry point: `import { symbol } from 'unist-util-map'`. Avoid referencing internal paths.Ensure your TypeScript configuration is set up correctly to consume types from `node_modules`. Review your code for any conflicting manual type definitions and remove them in favor of the shipped types.
Update your import statement to use ES Modules syntax: `import { map } from 'unist-util-map';`. Ensure your `package.json` has `"type": "module"` if it's a pure ESM project, or use dynamic import for mixed CJS/ESM projects.Verify your project is configured for ES Modules. If you're in a CommonJS environment, you cannot directly import `unist-util-map`. Consider using a bundler or converting your project to ESM. Ensure you are using `import { map } from 'unist-util-map'`.Upgrade your Node.js runtime to version 16 or newer. You can use a tool like `nvm` (Node Version Manager) to manage multiple Node.js versions.
Ensure your project's `@types/unist` version is compatible with `unist-util-map@4`. Update `@types/unist` to its latest version. If you have custom `Node` definitions, ensure they correctly extend or align with the `unist` types.
No dependency data recorded yet.