Registry / devops / unist-util-find-between

unist-util-find-between

JSON →
library1.2.2jsnpmunverified

unist utility to find nodes between two nodes or indexes in a parent tree. Current stable version is 1.2.2. This is an ESM-only package for Node.js 16+ that provides two functions: findBetween (excludes start/end nodes) and findBetweenIncluded (includes start/end nodes). It is fully typed with TypeScript and works with test functions from unist-util-is. Unlike general tree traversal utilities, this package specifically targets the common need to extract a slice of children between two points, making it ideal for unified plugin developers who need to select a range of sibling nodes.

npm install unist-util-find-between
INSTALL
IMPORT
SIG · UNIST-UTIL-FIND-BE
U
unist-util-find-between
devopsjavascriptv1.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

findBetween
import {findBetween} from 'unist-util-find-between'
const findBetween = require('unist-util-find-between').findBetween
ESM-only package; CommonJS require() will fail with ERR_REQUIRE_ESM.
findBetweenIncluded
import {findBetweenIncluded} from 'unist-util-find-between'
import findBetweenIncluded from 'unist-util-find-between'
This is a named export, not default. No default export exists.
Test type
import type {Test} from 'unist-util-is'
import {Test} from 'unist-util-find-between'
The Test type is not exported from this package; it comes from unist-util-is.

Demonstrates findBetween and findBetweenIncluded using numeric indexes and a test string, returning filtered children.

import {u} from 'unist-builder'; import {findBetween, findBetweenIncluded} from 'unist-util-find-between'; const tree = u('tree', [ u('leaf', 'leaf 1'), u('parent', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]), u('leaf', 'leaf 4'), u('leaf', 'leaf 5'), u('leaf', 'leaf 6'), u('leaf', 'leaf 7'), ]); // Find leaf nodes between child at index 1 (exclusive) and index 4 (exclusive) const result = findBetween(tree, 1, 4, 'leaf'); console.log(result); // Output: [{type: 'leaf', value: 'leaf 4'}, {type: 'leaf', value: 'leaf 5'}] // Incl. start and end nodes const resultIncl = findBetweenIncluded(tree, 1, 4, 'leaf'); console.log(resultIncl); // Output: [{type: 'leaf', value: 'leaf 4'}, {type: 'leaf', value: 'leaf 5'}, {type: 'leaf', value: 'leaf 6'}]
Debug
Known issues
breakingPackage is ESM only, requires Node.js 16+. CommonJS require() will throw ERR_REQUIRE_ESM.
fix
Use import syntax or dynamic import() if in a CommonJS context.
affects: >=1.0.0
gotchaThe start and end parameters can be Node objects or indexes, but providing a Node that is not a direct child will cause undefined behavior.
fix
Ensure the node argument is a direct child of the parent.
affects: >=1.0.0
gotchaThe test parameter follows unist-util-is conventions: can be string, array, function, or object. Passing null will exclude all nodes.
fix
Use undefined or omit the test argument to include all nodes.
affects: >=1.0.0
deprecatedNo deprecated features known; however, the package may stop receiving updates as it is mature.
fix
Consider if you truly need this utility or can use unist-util-visit with manual filtering.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only package (Node.js version <16 or CommonJS module).
fix
Switch to import syntax: import {findBetween} from 'unist-util-find-between'
TypeError: (intermediate value) is not iterable
Passing a non-array or non-treelike parent node.
fix
Ensure the first argument is a unist Parent node with a children array.
Error: Cannot find module 'unist-util-find-between'
Package not installed or import path incorrect.
fix
Run: npm install unist-util-find-between
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
unist-util-isrequiredrequired for the test parameter (node type, function, or array)
Agent activity
6 hits · last 30 days
node
6
Resources
unist-util-find-between — npm install unist-util-find-between · libregistry