snapdragon-util provides a focused collection of utility functions designed to interact with the Abstract Syntax Tree (AST) nodes generated or consumed by the `snapdragon` parser/compiler ecosystem. Key functionalities include robust node type checking (`isNode`), efficient value extraction from nodes (`value`), and critical compiler middleware helpers such as `noop` (for ignoring nodes), `identity` (for direct value appending), `append` (for custom value appending), and `toNoop` (for transforming nodes into empty text nodes without re-indexing). The package is currently at version `5.0.1` and is part of a stable, actively maintained ecosystem primarily targeting Node.js environments. Its core differentiation lies in its tight integration with `snapdragon-node` instances, making it indispensable for extending or customizing `snapdragon`-based parsers and compilers.
npm install snapdragon-utilVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `snapdragon-util` including node identification, value extraction, and conceptual use of the `append` compiler middleware.
Replace all calls to `util.emit(node, value)` with `util.append(value)(node)` (if it's a curried function) or simply `util.append(node, value)` depending on how `emit` was used. The new `append` returns a curried function for compiler middleware.
Use the CommonJS `require` syntax (`const util = require('snapdragon-util');`) or the default ESM import (`import util from 'snapdragon-util';`) and access utilities as properties of the `util` object (e.g., `util.isNode`).Ensure that arguments passed to `snapdragon-util` functions are valid `snapdragon-node` instances, typically created with `new Node(...)` from the `snapdragon-node` package.
Ensure you are using `const util = require('snapdragon-util');` and accessing functions like `util.isNode`. If using ESM, use `import util from 'snapdragon-util';` and then `util.isNode`.Add `const Node = require('snapdragon-node');` at the top of your file before attempting to create `new Node(...)` instances.