{"library":"snapdragon-util","title":"Snapdragon Utilities","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install snapdragon-util"],"cli":null},"imports":["import util from 'snapdragon-util';","const util = require('snapdragon-util');\nconst isNode = util.isNode;","const util = require('snapdragon-util');\nconst append = util.append;"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/here-be/snapdragon-util","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/snapdragon-util","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const util = require('snapdragon-util');\nconst Node = require('snapdragon-node');\n\n// Create a simple AST node\nconst textNode = new Node({ type: 'text', value: 'Hello' });\nconst wildcardNode = new Node({ type: 'star', val: '*' });\n\n// Use isNode to check node type\nconsole.log('Is textNode a Snapdragon Node?', util.isNode(textNode));\nconsole.log('Is a plain object a Snapdragon Node?', util.isNode({}));\n\n// Extract value using the value utility\nconsole.log('Value of textNode:', util.value(textNode));\nconsole.log('Value of wildcardNode:', util.value(wildcardNode));\n\n// Example of using 'append' for a compiler (conceptual)\n// In a real snapdragon compiler, you'd set this as middleware\nconst mockCompiler = { output: '' };\nconst appendGreeting = util.append('Hello World');\n\n// Simulate calling the append middleware with a node and a compiler context\nappendGreeting.call(mockCompiler, { type: 'greeting' });\nconsole.log('Mock compiler output after append:', mockCompiler.output);","lang":"javascript","description":"Demonstrates basic usage of `snapdragon-util` including node identification, value extraction, and conceptual use of the `append` compiler middleware.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}