Registry / testing / unist-util-generated

unist-util-generated

JSON →
library3.0.0jsnpmunverified

unist-util-generated is a utility within the unified ecosystem designed to determine if a unist node is 'generated.' A generated node is one that did not originate from the source text of the document but was rather programmatically created or modified, lacking explicit positional information. This is particularly useful for tools like linters, which might want to skip generated content to avoid reporting false positives to human authors. The package is currently stable at version 3.0.0 and adheres to a semantic versioning release cadence, with major versions often coinciding with shifts in Node.js compatibility or module system adoption. Its primary differentiator is its focused role in identifying synthetic content within unist trees, complementing other utilities like unist-util-position for retrieving positional data and unist-util-stringify-position for displaying it.

npm install unist-util-generated
INSTALL
IMPORT
SIG · UNIST-UTIL-GENERAT
U
unist-util-generated
testingjavascriptv3.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.

generated
import { generated } from 'unist-util-generated'
const generated = require('unist-util-generated')
The package is ESM-only since v2.0.0. A named import is required as there is no default export.
generated (via dynamic import)
const { generated } = await import('unist-util-generated')
import generated from 'unist-util-generated'
While direct `import` statements are preferred at the top level, dynamic imports allow for conditional loading. Remember there is no default export.

This quickstart demonstrates how to use `unist-util-generated` to check if various unist nodes are considered 'generated.' It illustrates that nodes lacking any `position` property, or those with empty `start` and `end` position objects, are flagged as generated, while nodes with valid line/column data are not.

import { generated } from 'unist-util-generated' import type { Node } from 'unist' // A completely empty object is considered generated as it lacks positional info. const node1: Node = {} console.log('Node 1 (empty object):', generated(node1)) // A node with empty start/end positions is also generated. const node2: Node = {position: {start: {}, end: {}}} console.log('Node 2 (empty position):', generated(node2)) // A node with complete positional information is NOT generated. const node3: Node = { position: {start: {line: 1, column: 1}, end: {line: 1, column: 2}} } console.log('Node 3 (full position):', generated(node3)) // Example with a typical unist node structure interface TextNode extends Node { type: 'text'; value: string; } const originalTextNode: TextNode = { type: 'text', value: 'Hello', position: { start: {line: 1, column: 1, offset: 0}, end: {line: 1, column: 6, offset: 5} } } console.log('Original text node:', generated(originalTextNode)) const programmaticallyAddedNode: TextNode = { type: 'text', value: 'World' // No position info, so it's generated } console.log('Programmatically added node:', generated(programmaticallyAddedNode))
Debug
Known issues
breakingVersion 3.0.0 updated the minimum required Node.js version to 16. Older Node.js environments will not be supported.
fix
Ensure your project is running on Node.js 16 or newer. Update your Node.js environment if necessary.
affects: >=3.0.0
breakingThe package transitioned to being ESM-only in v2.0.0, which was reinforced by using `export` maps in v3.0.0. This means `require()` statements will no longer work.
fix
Migrate your codebase to use ES Modules (ESM) with `import` statements. For example, `import { generated } from 'unist-util-generated'`.
affects: >=2.0.0
breakingWith the adoption of `export` maps in v3.0.0, direct access to private APIs or internal paths within the package is no longer supported and will likely break.
fix
Always import symbols directly from the main package entry point, e.g., `import { generated } from 'unist-util-generated'`. Avoid referencing internal file paths.
affects: >=3.0.0
gotchaThe `generated` function expects a unist `Node` object. Passing non-object values or objects without a `position` property will lead to unexpected results, typically evaluating as generated.
fix
Ensure the input `node` conforms to the unist `Node` interface, particularly if you expect a specific `generated` outcome based on its positional data. Nodes without a `position` property are considered generated.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require()` to import an ESM-only package.
fix
Change `const { generated } = require('unist-util-generated')` to `import { generated } from 'unist-util-generated'`.
SyntaxError: Named export 'generated' not found. The requested module 'unist-util-generated' does not provide an export named 'default'
Attempting to use a default import for a package that only provides named exports.
fix
Change `import generated from 'unist-util-generated'` to `import { generated } from 'unist-util-generated'`.
TypeError: unist_util_generated_1.generated is not a function
Incorrect CommonJS-style access (e.g., after `require`) or a bundling issue where the named export is not correctly exposed.
fix
Verify that your module system is correctly configured for ESM and that you are using the named import syntax: `import { generated } from 'unist-util-generated'`.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
unist-util-generated — npm install unist-util-generated · libregistry