Registry / data / unist-util-find-all-before

unist-util-find-all-before

JSON →
library5.0.0jsnpmunverified

unist-util-find-all-before is a specialized utility within the unified ecosystem, designed to locate all nodes that appear before a specific child node or a given index within a parent node. It offers an optional `test` function, compatible with `unist-util-is`, to filter the results based on node properties. The current stable version is 5.0.0, which is ESM-only and requires Node.js 16 or newer. This package follows semver for its releases, with frequent updates addressing bug fixes, performance improvements, and keeping pace with Node.js and TypeScript advancements. Its key differentiator lies in its focused functionality for collecting multiple preceding nodes, making it a complementary tool for more general tree traversal utilities like `unist-util-visit` when precise positional node discovery is needed.

npm install unist-util-find-all-before
INSTALL
IMPORT
SIG · UNIST-UTIL-FIND-AL
U
unist-util-find-all-before
datajavascriptv5.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.

findAllBefore
import { findAllBefore } from 'unist-util-find-all-before'
const findAllBefore = require('unist-util-find-all-before')
This package is ESM-only since v4.0.0. CommonJS `require` is not supported. Additionally, v5.0.0 requires Node.js 16+.
Node (type)
import type { Node } from 'unist'
While `unist-util-find-all-before` itself exports no types, its core function operates on `Node` objects, typically imported from the `unist` package if working with TypeScript.
Test (type)
import type { Test } from 'unist-util-is'
The optional `test` parameter uses a type defined by `unist-util-is`, which should be imported separately when using TypeScript.

Demonstrates how to import and use `findAllBefore` to retrieve specific nodes before a target node or index, optionally filtered by type.

import {u} from 'unist-builder' import {findAllBefore} from 'unist-util-find-all-before' 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') ]) const leaf6 = tree.children[4] // Find all 'leaf' nodes before 'leaf 6' const result = findAllBefore(tree, leaf6, 'leaf') console.log(JSON.stringify(result, null, 2)) // Find all nodes before index 3 const allBeforeIndex3 = findAllBefore(tree, 3) console.log('\nAll nodes before index 3:') console.log(JSON.stringify(allBeforeIndex3, null, 2))
Debug
Known issues
breakingVersion 5.0.0 changed to require 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 must support older Node.js, pin to `unist-util-find-all-before@^4`.
affects: >=5.0.0
breakingThe package transitioned to ESM-only starting from version 4.0.0. CommonJS `require()` statements will no longer work.
fix
Update your import statements to use ES Modules (`import ... from '...'`). Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
affects: >=4.0.0
breakingVersion 5.0.0 changed to use an `export` map. While this typically improves module resolution, it can break direct 'deep imports' to internal paths that were not explicitly exposed.
fix
Only import from the main package entry point (`unist-util-find-all-before`). Avoid relying on internal or undocumented paths within the package structure.
affects: >=5.0.0
breakingVersion 4.0.0 introduced a fix that inverted the result order. This means that if you relied on the previous order of returned nodes, your logic might be affected.
fix
Review any code that processes the array returned by `findAllBefore` and adjust for the inverted order, or explicitly sort the array if a specific order is required.
affects: >=4.0.0
breakingSignificant type definition updates occurred in versions 3.0.0 and 5.0.0, potentially causing TypeScript compilation errors if your project or its dependencies relied on older, incompatible type signatures.
fix
Update `@types/unist` and `unist-util-is` to their latest compatible versions. Adjust your TypeScript code to match the new type signatures, particularly around `Node` and `Test` definitions.
affects: >=3.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/unist-util-find-all-before/index.js from ... not supported.
Attempting to import an ESM-only package using CommonJS `require()` syntax.
fix
Change your import statement to `import { findAllBefore } from 'unist-util-find-all-before'`. Ensure your project's `package.json` specifies `"type": "module"` or you are using `.mjs` files for ESM.
TypeError: findAllBefore is not a function
Incorrect import statement (e.g., default import for a named export, or module resolution issue), or attempting to run on an unsupported Node.js version.
fix
Verify that you are using `import { findAllBefore } from 'unist-util-find-all-before'`. Confirm your Node.js version is 16 or higher if using `unist-util-find-all-before@^5`.
SyntaxError: Cannot use import statement outside a module
Using `import` syntax in a JavaScript file that is being interpreted as a CommonJS module (e.g., a `.js` file without `"type": "module"` in `package.json`).
fix
Add `"type": "module"` to your project's `package.json` file, or rename your file to use the `.mjs` extension for explicit ESM treatment.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
unist-util-isrequiredUsed for the optional `test` parameter to filter nodes.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
unist-util-find-all-before — npm install unist-util-find-all-before · libregistry