Registry / serialization / unist-util-find-after

unist-util-find-after

JSON →
library5.0.0jsnpmunverified

This package, `unist-util-find-after`, provides a lightweight utility for navigating unist (Universal Syntax Tree) trees by locating a node immediately following a specified node or index within a parent. Currently at stable version 5.0.0, it adheres to semantic versioning with major releases introducing breaking changes, and maintains active development within the unified collective. A key differentiator is its seamless integration with other `unist` and `unified` ecosystem tools, simplifying tree manipulation tasks that could otherwise be implemented manually. It is explicitly an ESM-only package, requiring Node.js 16 or newer, and ships with full TypeScript type definitions to ensure robust development.

npm install unist-util-find-after
INSTALL
IMPORT
SIG · UNIST-UTIL-FIND-AF
U
unist-util-find-after
serializationjavascriptv5.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

findAfter
import { findAfter } from 'unist-util-find-after'
const findAfter = require('unist-util-find-after')
Package is ESM-only since v4.0.0; CommonJS `require` is not supported.
findAfter
import { findAfter } from 'https://esm.sh/unist-util-find-after@5'
For Deno or browser environments using esm.sh, ensure to specify the major version in the URL.
Node
import type { Node } from 'unist'
While `unist-util-find-after` ships types, core Unist types like `Node` are imported from the `unist` package.

Demonstrates how to use `findAfter` to locate a node based on an index or a reference node, with an optional test, within a Unist tree.

import { u } from 'unist-builder'; import { findAfter } from 'unist-util-find-after'; // Example Unist tree structure const tree = u('tree', [ u('leaf', 'leaf 1'), u('parent', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]), u('leaf', 'leaf 4'), u('parent', [u('leaf', 'leaf 5')]), u('leaf', 'leaf 6'), u('empty'), u('leaf', 'leaf 7') ]); // Find the first 'parent' node after the node at index 1 (which is 'parent' with 'leaf 2', 'leaf 3') console.log('Finding parent after index 1:', findAfter(tree, 1, 'parent')); // Expected output: { type: 'parent', children: [{ type: 'leaf', value: 'leaf 5' }]} // Find the first 'leaf' node after 'leaf 4' (which is at index 2) const leaf4 = tree.children[2]; console.log('Finding leaf after "leaf 4":', findAfter(tree, leaf4, 'leaf')); // Expected output: { type: 'leaf', value: 'leaf 6' } // Find a node after 'leaf 7' (the last child) - should be undefined const leaf7 = tree.children[6]; console.log('Finding node after "leaf 7":', findAfter(tree, leaf7)); // Expected output: undefined
Debug
Known issues
breakingVersion 5.0.0 changed the minimum Node.js requirement to Node.js 16 or higher. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or newer. For projects that require older Node.js versions, pin `unist-util-find-after` to `<5.0.0`.
affects: >=5.0.0
breakingSince version 4.0.0, this package is ESM-only. CommonJS `require()` statements will fail, leading to `ERR_REQUIRE_ESM` errors.
fix
Migrate your codebase to use ECMAScript Modules (ESM) `import` syntax. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
affects: >=4.0.0
breakingIn version 5.0.0, the `findAfter` function now explicitly yields `undefined` when no matching node is found, instead of `null`. While `null` and `undefined` are often treated similarly, this is a distinct change in return type behavior.
fix
Update your code to expect and handle `undefined` as a possible return value from `findAfter` when no node is found.
affects: >=5.0.0
breakingVersion 5.0.0 changed to use `exports` map. If you were previously relying on direct deep imports to private APIs, those paths are no longer guaranteed and may be broken.
fix
Only use the public `findAfter` export directly from the package's root. Avoid relying on internal or private file paths.
affects: >=5.0.0
breakingVersion 3.0.0 updated its dependency on `unist-util-is`, which could be a breaking change for TypeScript users if the types for `Test` predicates have changed significantly.
fix
Review the `unist-util-is` changelog for `4.0.0` and update your `unist-util-is`-compatible `Test` functions and their types accordingly. Update `@types/unist` as well if necessary.
affects: >=3.0.0 <4.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module .../node_modules/unist-util-find-after/index.js from .../your-file.js not supported.
Attempting to use CommonJS `require()` to import `unist-util-find-after` after it transitioned to ESM-only.
fix
Change your import statement to `import { findAfter } from 'unist-util-find-after';` and ensure your project is configured for ESM.
TypeError: (0 , unist_util_find_after_1.findAfter) is not a function
Incorrect ESM import syntax, often when attempting to import a named export as a default, or when transpilng ESM to CJS incorrectly.
fix
Ensure you are using named imports: `import { findAfter } from 'unist-util-find-after';`. Do not attempt `import findAfter from 'unist-util-find-after';` as there is no default export.
Property 'children' does not exist on type 'Node<Data>'. Did you mean 'options'?
Attempting to access `children` on a non-parent `Node` type. `parent` in `findAfter` must be a `Parent` node (e.g., `Root`, `Element`).
fix
Ensure the first argument passed to `findAfter` is a `Parent` node type that has a `children` property, such as a `Root` or `Parent` node from `unist-builder` or a parsed AST.
Node.js process exits with code 1 due to unsupported API 'exports' map.
Running `unist-util-find-after@5.x` on a Node.js version older than 16, which does not fully support the 'exports' field in `package.json`.
fix
Upgrade your Node.js environment to version 16 or higher. Alternatively, downgrade `unist-util-find-after` to a version compatible with your Node.js environment (e.g., `npm install unist-util-find-after@^4`).
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
unist-util-isrequiredUsed internally for the 'test' function parameter, defining compatibility and behavior for node predicate functions.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
unist-util-find-after — npm install unist-util-find-after · libregistry