{"id":12291,"library":"unist-util-generated","title":"Unist Generated Node Checker","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/unist-util-generated","tags":["javascript","unist","unist-util","util","utility","position","location","generated","typescript"],"install":[{"cmd":"npm install unist-util-generated","lang":"bash","label":"npm"},{"cmd":"yarn add unist-util-generated","lang":"bash","label":"yarn"},{"cmd":"pnpm add unist-util-generated","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only since v2.0.0. A named import is required as there is no default export.","wrong":"const generated = require('unist-util-generated')","symbol":"generated","correct":"import { generated } from 'unist-util-generated'"},{"note":"While direct `import` statements are preferred at the top level, dynamic imports allow for conditional loading. Remember there is no default export.","wrong":"import generated from 'unist-util-generated'","symbol":"generated (via dynamic import)","correct":"const { generated } = await import('unist-util-generated')"}],"quickstart":{"code":"import { generated } from 'unist-util-generated'\nimport type { Node } from 'unist'\n\n// A completely empty object is considered generated as it lacks positional info.\nconst node1: Node = {}\nconsole.log('Node 1 (empty object):', generated(node1))\n\n// A node with empty start/end positions is also generated.\nconst node2: Node = {position: {start: {}, end: {}}}\nconsole.log('Node 2 (empty position):', generated(node2))\n\n// A node with complete positional information is NOT generated.\nconst node3: Node = {\n  position: {start: {line: 1, column: 1}, end: {line: 1, column: 2}}\n}\nconsole.log('Node 3 (full position):', generated(node3))\n\n// Example with a typical unist node structure\ninterface TextNode extends Node {\n  type: 'text';\n  value: string;\n}\n\nconst originalTextNode: TextNode = {\n  type: 'text',\n  value: 'Hello',\n  position: {\n    start: {line: 1, column: 1, offset: 0},\n    end: {line: 1, column: 6, offset: 5}\n  }\n}\nconsole.log('Original text node:', generated(originalTextNode))\n\nconst programmaticallyAddedNode: TextNode = {\n  type: 'text',\n  value: 'World'\n  // No position info, so it's generated\n}\nconsole.log('Programmatically added node:', generated(programmaticallyAddedNode))","lang":"typescript","description":"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."},"warnings":[{"fix":"Ensure your project is running on Node.js 16 or newer. Update your Node.js environment if necessary.","message":"Version 3.0.0 updated the minimum required Node.js version to 16. Older Node.js environments will not be supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Migrate your codebase to use ES Modules (ESM) with `import` statements. For example, `import { generated } from 'unist-util-generated'`.","message":"The 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always import symbols directly from the main package entry point, e.g., `import { generated } from 'unist-util-generated'`. Avoid referencing internal file paths.","message":"With 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const { generated } = require('unist-util-generated')` to `import { generated } from 'unist-util-generated'`.","cause":"Attempting to use `require()` to import an ESM-only package.","error":"ERR_REQUIRE_ESM"},{"fix":"Change `import generated from 'unist-util-generated'` to `import { generated } from 'unist-util-generated'`.","cause":"Attempting to use a default import for a package that only provides named exports.","error":"SyntaxError: Named export 'generated' not found. The requested module 'unist-util-generated' does not provide an export named 'default'"},{"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'`.","cause":"Incorrect CommonJS-style access (e.g., after `require`) or a bundling issue where the named export is not correctly exposed.","error":"TypeError: unist_util_generated_1.generated is not a function"}],"ecosystem":"npm"}