{"id":12288,"library":"unist-util-find-all-after","title":"Find all Unist Nodes After a Specific Point","description":"unist-util-find-all-after is a utility from the unified collective designed to locate all unist (Universal Syntax Tree) nodes that appear after a specified child node or index within a parent node. Its current stable version is 5.0.0, which requires Node.js 16 or higher and is ESM-only. The unified collective typically ties major releases to Node.js LTS cycles, providing stable maintenance. This package differentiates itself as a highly focused, lightweight utility for tree traversal, intended for integration within the broader unified ecosystem, offering a small, composable piece of functionality rather than a comprehensive tree manipulation library. It's fully typed with TypeScript and works alongside other `unist-util-*` packages like `unist-util-is` for node testing.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/unist-util-find-all-after","tags":["javascript","unist","unist-util","util","utility","tree","node","find","after","typescript"],"install":[{"cmd":"npm install unist-util-find-all-after","lang":"bash","label":"npm"},{"cmd":"yarn add unist-util-find-all-after","lang":"bash","label":"yarn"},{"cmd":"pnpm add unist-util-find-all-after","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for node testing functionality when a `test` parameter is provided.","package":"unist-util-is","optional":false},{"reason":"Provides core unist type definitions, crucial for TypeScript development and ensuring type compatibility with other unist utilities.","package":"@types/unist","optional":false}],"imports":[{"note":"This package is ESM-only since v4.0.0 and requires Node.js 16+ since v5.0.0. There is no default export; always use named imports. For browser usage via esm.sh, you can import from `https://esm.sh/unist-util-find-all-after@5`.","wrong":"const findAllAfter = require('unist-util-find-all-after')","symbol":"findAllAfter","correct":"import { findAllAfter } from 'unist-util-find-all-after'"}],"quickstart":{"code":"import { u } from 'unist-builder';\nimport { findAllAfter } from 'unist-util-find-all-after';\n\nconst tree = u('tree', [\n  u('leaf', 'leaf 1'),\n  u('parent', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]),\n  u('leaf', 'leaf 4'),\n  u('parent', [u('leaf', 'leaf 5')]),\n  u('leaf', 'leaf 6'),\n  u('empty'),\n  u('leaf', 'leaf 7')\n]);\n\n// Find all 'leaf' nodes after the node at index 1 (which is a 'parent' node)\nconst result = findAllAfter(tree, 1, 'leaf');\n\nconsole.log(JSON.stringify(result, null, 2));\n/*\nExpected output:\n[\n  {\n    \"type\": \"leaf\",\n    \"value\": \"leaf 4\"\n  },\n  {\n    \"type\": \"leaf\",\n    \"value\": \"leaf 6\"\n  },\n  {\n    \"type\": \"leaf\",\n    \"value\": \"leaf 7\"\n  }\n]\n*/","lang":"typescript","description":"Demonstrates how to import and use `findAllAfter` to find specific 'leaf' nodes occurring after a given index within a unist tree structure, using `unist-builder` to construct the tree."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or later to ensure compatibility and access to the latest features.","message":"Version 5.0.0 changed to require Node.js 16 or higher. Older Node.js versions are no longer supported, impacting runtime compatibility.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Migrate your project to use ES modules (`import`/`export`) or stick to an older major version (e.g., `^3.0.0`). Ensure your `package.json` includes `\"type\": \"module\"` if using `.js` files for ESM.","message":"Since version 4.0.0, the package is ESM-only. CommonJS `require()` syntax is no longer supported for importing this package.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Always import directly from the package name: `import { findAllAfter } from 'unist-util-find-all-after'`. Avoid referencing internal directory structures.","message":"Version 5.0.0 introduced an `export` map, restricting direct imports from internal paths (e.g., `pkg/lib/index.js`).","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Update `@types/unist` to the latest compatible version and ensure your TypeScript project configuration is correctly set up to consume the package's types.","message":"Type definitions were significantly improved and added since v3.0.0 and updated in v5.0.0. This might cause TypeScript compilation issues if your project relies on older `@types/unist` or incompatible type definitions.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review and update any code that performs string comparisons against error messages. It is generally recommended to rely on error types or properties rather than the exact message content.","message":"Error messages were updated in version 3.0.0. If your code relies on exact string matching for error messages, this will break your tests or error handling.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `require('unist-util-find-all-after')` to `import { findAllAfter } from 'unist-util-find-all-after'` and ensure your project is configured for ES modules (e.g., by adding `\"type\": \"module\"` to `package.json` or using the `.mjs` file extension).","cause":"Attempting to `require()` an ESM-only package in a CommonJS context.","error":"ERR_REQUIRE_ESM"},{"fix":"Ensure you are using named import: `import { findAllAfter } from 'unist-util-find-all-after'`. This package does not have a default export. If transpiling to CJS, verify your transpiler correctly handles ESM named exports.","cause":"Incorrect import syntax for an ESM-only module that uses named exports, often encountered when TypeScript transpiles to CommonJS or due to incorrect CJS interop.","error":"TypeError: unist_util_find_all_after_1.findAllAfter is not a function"},{"fix":"Always import from the package name directly: `import { findAllAfter } from 'unist-util-find-all-after'`. Avoid referencing internal directory structures.","cause":"Attempting to import from internal paths or specific files within the package instead of its primary entry point, which is restricted by the `export` map introduced in v5.0.0.","error":"Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '.../node_modules/unist-util-find-all-after/lib' is not supported"},{"fix":"To use `import` statements, your file must be part of an ES module. This can be achieved by adding `\"type\": \"module\"` to your nearest `package.json` file, or by renaming your module file to use the `.mjs` extension.","cause":"Using an ES `import` statement in a JavaScript file that is being interpreted as a CommonJS module.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}