Registry / serialization / unist-util-find

unist-util-find

JSON →
library3.0.0jsnpmunverified

unist-util-find is a focused utility within the Unist ecosystem (supporting mdast, hast, nlcst, etc.) designed to efficiently locate the first node in a Unist tree that satisfies a given condition. The current stable version is 3.0.0. Maintained by the unified collective, it typically follows Node.js LTS release cycles for major version updates. Its key differentiator lies in its simplicity for finding a single matching node, offering a lightweight alternative to more comprehensive tree-walking utilities like `unist-util-visit` when only the first match is needed. Conditions can be specified as a string, an object, or a predicate function, providing flexible search capabilities.

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

find
import { find } from 'unist-util-find'
const find = require('unist-util-find')
The package is ESM-only since v2.0.0. There is no default export; 'find' is a named export.
TestFn
import type { TestFn } from 'unist-util-find'
TypeScript type for predicate functions used in 'find' conditions.
TestObj
import type { TestObj } from 'unist-util-find'
TypeScript type for object conditions used in 'find'.

This quickstart demonstrates how to use `unist-util-find` with string, object, and function conditions to locate nodes within an mdast tree.

import { fromMarkdown } from 'mdast-util-from-markdown'; import { find } from 'unist-util-find'; const tree = fromMarkdown('Some _emphasis_, **strongness**, and `code`.'); console.log('--- String condition (finds first node with a truthy \'value\') ---'); console.log(find(tree, 'value')); console.log('\n--- Object condition (finds first node with matching properties) ---'); console.log(find(tree, { value: 'emphasis' })); console.log('\n--- Function condition (finds first node where predicate returns true) ---'); console.log( find(tree, (node) => { return node.type === 'inlineCode'; }) );
Debug
Known issues
breakingVersion 3.0.0 of `unist-util-find` requires Node.js 16 or later. Previous versions supported older Node.js runtimes.
fix
Ensure your Node.js environment is version 16 or newer. Update your Node.js runtime if necessary.
affects: >=3.0.0
breakingVersion 2.0.0 switched to being an ESM-only package. This means it can no longer be `require()`-d in CommonJS environments.
fix
Migrate your project to use ES Modules (ESM) by adding `"type": "module"` to your `package.json` and using `import` statements. If you must use CommonJS, you'll need to use an older version (<2.0.0) or dynamically import it.
affects: >=2.0.0
breakingVersion 2.0.0 introduced an `export` map and removed access to private APIs. Relying on internal paths or undocumented exports will break.
fix
Only use the public `find` named export as documented. Avoid importing from deep paths within the package.
affects: >=2.0.0
gotchaThe `find` utility is a named export, not a default export. Attempting to `import find from 'unist-util-find'` will result in `undefined`.
fix
Always use named import syntax: `import { find } from 'unist-util-find'`.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require('unist-util-find')` in an ES Module context or when `unist-util-find` (v2.0.0+) is used in a CJS file.
fix
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) and use `import { find } from 'unist-util-find'`.
TypeError: (0 , unist_util_find__WEBPACK_IMPORTED_MODULE_0__.find) is not a function
This Webpack/Rollup error typically indicates that a named export was treated as a default export or that `find` was undefined.
fix
Verify that `import { find } from 'unist-util-find'` is used for the named export, and not `import find from 'unist-util-find'`.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
unist-util-find — npm install unist-util-find · libregistry