{"id":20349000,"url":"https://github.com/here-be/snapdragon-util","last_synced_at":"2025-08-21T07:32:49.160Z","repository":{"id":57147275,"uuid":"79436138","full_name":"here-be/snapdragon-util","owner":"here-be","description":"Utilities for the snapdragon parser/compiler.","archived":false,"fork":false,"pushed_at":"2020-08-12T02:34:38.000Z","size":56,"stargazers_count":17,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-27T02:27:38.370Z","etag":null,"topics":["ast","compiler","javascript","node","nodejs","parser","snapdragon","utils"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/here-be.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-19T09:15:38.000Z","updated_at":"2022-08-26T02:06:07.000Z","dependencies_parsed_at":"2022-08-29T08:50:38.012Z","dependency_job_id":null,"html_url":"https://github.com/here-be/snapdragon-util","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/here-be/snapdragon-util","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/here-be%2Fsnapdragon-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/here-be%2Fsnapdragon-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/here-be%2Fsnapdragon-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/here-be%2Fsnapdragon-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/here-be","download_url":"https://codeload.github.com/here-be/snapdragon-util/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/here-be%2Fsnapdragon-util/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268480024,"owners_count":24256901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","compiler","javascript","node","nodejs","parser","snapdragon","utils"],"created_at":"2024-11-14T22:23:34.581Z","updated_at":"2025-08-21T07:32:48.824Z","avatar_url":"https://github.com/here-be.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snapdragon-util [![NPM version](https://img.shields.io/npm/v/snapdragon-util.svg?style=flat)](https://www.npmjs.com/package/snapdragon-util) [![NPM monthly downloads](https://img.shields.io/npm/dm/snapdragon-util.svg?style=flat)](https://npmjs.org/package/snapdragon-util) [![NPM total downloads](https://img.shields.io/npm/dt/snapdragon-util.svg?style=flat)](https://npmjs.org/package/snapdragon-util) [![Linux Build Status](https://img.shields.io/travis/here-be/snapdragon-util.svg?style=flat\u0026label=Travis)](https://travis-ci.org/here-be/snapdragon-util)\n\n\u003e Utilities for the snapdragon parser/compiler.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save snapdragon-util\n```\n\n## Usage\n\n```js\nvar util = require('snapdragon-util');\n```\n\n## API\n\n### [.isNode](index.js#L20)\n\nReturns true if the given value is a node.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar node = new Node({type: 'foo'});\nconsole.log(utils.isNode(node)); //=\u003e true\nconsole.log(utils.isNode({})); //=\u003e false\n```\n\n### [.noop](index.js#L36)\n\nEmit an empty string for the given `node`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{undefined}**\n\n**Example**\n\n```js\n// do nothing for beginning-of-string\nsnapdragon.compiler.set('bos', utils.noop);\n```\n\n### [.value](index.js#L54)\n\nReturns `node.value` or `node.val`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{String}**: returns\n\n**Example**\n\n```js\nconst star = new Node({type: 'star', value: '*'});\nconst slash = new Node({type: 'slash', val: '/'});\nconsole.log(utils.value(star)) //=\u003e '*'\nconsole.log(utils.value(slash)) //=\u003e '/'\n```\n\n### [.identity](index.js#L72)\n\nAppend `node.value` to `compiler.output`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{undefined}**\n\n**Example**\n\n```js\nsnapdragon.compiler.set('text', utils.identity);\n```\n\n### [.append](index.js#L95)\n\nPreviously named `.emit`, this method appends the given `value` to `compiler.output` for the given node. Useful when you know what value should be appended advance, regardless of the actual value of `node.value`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Function}**: Returns a compiler middleware function.\n\n**Example**\n\n```js\nsnapdragon.compiler\n  .set('i', function(node) {\n    this.mapVisit(node);\n  })\n  .set('i.open', utils.append('\u003ci\u003e'))\n  .set('i.close', utils.append('\u003c/i\u003e'))\n```\n\n### [.toNoop](index.js#L118)\n\nUsed in compiler middleware, this onverts an AST node into an empty `text` node and deletes `node.nodes` if it exists. The advantage of this method is that, as opposed to completely removing the node, indices will not need to be re-calculated in sibling nodes, and nothing is appended to the output.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `nodes` **{Array}**: Optionally pass a new `nodes` value, to replace the existing `node.nodes` array.\n\n**Example**\n\n```js\nutils.toNoop(node);\n// convert `node.nodes` to the given value instead of deleting it\nutils.toNoop(node, []);\n```\n\n### [.visit](index.js#L147)\n\nVisit `node` with the given `fn`. The built-in `.visit` method in snapdragon automatically calls registered compilers, this allows you to pass a visitor function.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `fn` **{Function}**\n* `returns` **{Object}**: returns the node after recursively visiting all child nodes.\n\n**Example**\n\n```js\nsnapdragon.compiler.set('i', function(node) {\n  utils.visit(node, function(childNode) {\n    // do stuff with \"childNode\"\n    return childNode;\n  });\n});\n```\n\n### [.mapVisit](index.js#L174)\n\nMap [visit](#visit) the given `fn` over `node.nodes`. This is called by [visit](#visit), use this method if you do not want `fn` to be called on the first node.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `options` **{Object}**\n* `fn` **{Function}**\n* `returns` **{Object}**: returns the node\n\n**Example**\n\n```js\nsnapdragon.compiler.set('i', function(node) {\n  utils.mapVisit(node, function(childNode) {\n    // do stuff with \"childNode\"\n    return childNode;\n  });\n});\n```\n\n### [.addOpen](index.js#L213)\n\nUnshift an `*.open` node onto `node.nodes`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `Node` **{Function}**: (required) Node constructor function from [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node).\n* `filter` **{Function}**: Optionaly specify a filter function to exclude the node.\n* `returns` **{Object}**: Returns the created opening node.\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nsnapdragon.parser.set('brace', function(node) {\n  var match = this.match(/^{/);\n  if (match) {\n    var parent = new Node({type: 'brace'});\n    utils.addOpen(parent, Node);\n    console.log(parent.nodes[0]):\n    // { type: 'brace.open', value: '' };\n\n    // push the parent \"brace\" node onto the stack\n    this.push(parent);\n\n    // return the parent node, so it's also added to the AST\n    return brace;\n  }\n});\n```\n\n### [.addClose](index.js#L263)\n\nPush a `*.close` node onto `node.nodes`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `Node` **{Function}**: (required) Node constructor function from [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node).\n* `filter` **{Function}**: Optionaly specify a filter function to exclude the node.\n* `returns` **{Object}**: Returns the created closing node.\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nsnapdragon.parser.set('brace', function(node) {\n  var match = this.match(/^}/);\n  if (match) {\n    var parent = this.parent();\n    if (parent.type !== 'brace') {\n      throw new Error('missing opening: ' + '}');\n    }\n\n    utils.addClose(parent, Node);\n    console.log(parent.nodes[parent.nodes.length - 1]):\n    // { type: 'brace.close', value: '' };\n\n    // no need to return a node, since the parent\n    // was already added to the AST\n    return;\n  }\n});\n```\n\n### [.wrapNodes](index.js#L293)\n\nWraps the given `node` with `*.open` and `*.close` nodes.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `Node` **{Function}**: (required) Node constructor function from [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node).\n* `filter` **{Function}**: Optionaly specify a filter function to exclude the node.\n* `returns` **{Object}**: Returns the node\n\n### [.pushNode](index.js#L318)\n\nPush the given `node` onto `parent.nodes`, and set `parent` as `node.parent.\n\n**Params**\n\n* `parent` **{Object}**\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Object}**: Returns the child node\n\n**Example**\n\n```js\nvar parent = new Node({type: 'foo'});\nvar node = new Node({type: 'bar'});\nutils.pushNode(parent, node);\nconsole.log(parent.nodes[0].type) // 'bar'\nconsole.log(node.parent.type) // 'foo'\n```\n\n### [.unshiftNode](index.js#L348)\n\nUnshift `node` onto `parent.nodes`, and set `parent` as `node.parent.\n\n**Params**\n\n* `parent` **{Object}**\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{undefined}**\n\n**Example**\n\n```js\nvar parent = new Node({type: 'foo'});\nvar node = new Node({type: 'bar'});\nutils.unshiftNode(parent, node);\nconsole.log(parent.nodes[0].type) // 'bar'\nconsole.log(node.parent.type) // 'foo'\n```\n\n### [.popNode](index.js#L381)\n\nPop the last `node` off of `parent.nodes`. The advantage of using this method is that it checks for `node.nodes` and works with any version of `snapdragon-node`.\n\n**Params**\n\n* `parent` **{Object}**\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Number|Undefined}**: Returns the length of `node.nodes` or undefined.\n\n**Example**\n\n```js\nvar parent = new Node({type: 'foo'});\nutils.pushNode(parent, new Node({type: 'foo'}));\nutils.pushNode(parent, new Node({type: 'bar'}));\nutils.pushNode(parent, new Node({type: 'baz'}));\nconsole.log(parent.nodes.length); //=\u003e 3\nutils.popNode(parent);\nconsole.log(parent.nodes.length); //=\u003e 2\n```\n\n### [.shiftNode](index.js#L409)\n\nShift the first `node` off of `parent.nodes`. The advantage of using this method is that it checks for `node.nodes` and works with any version of `snapdragon-node`.\n\n**Params**\n\n* `parent` **{Object}**\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Number|Undefined}**: Returns the length of `node.nodes` or undefined.\n\n**Example**\n\n```js\nvar parent = new Node({type: 'foo'});\nutils.pushNode(parent, new Node({type: 'foo'}));\nutils.pushNode(parent, new Node({type: 'bar'}));\nutils.pushNode(parent, new Node({type: 'baz'}));\nconsole.log(parent.nodes.length); //=\u003e 3\nutils.shiftNode(parent);\nconsole.log(parent.nodes.length); //=\u003e 2\n```\n\n### [.removeNode](index.js#L436)\n\nRemove the specified `node` from `parent.nodes`.\n\n**Params**\n\n* `parent` **{Object}**\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Object|undefined}**: Returns the removed node, if successful, or undefined if it does not exist on `parent.nodes`.\n\n**Example**\n\n```js\nvar parent = new Node({type: 'abc'});\nvar foo = new Node({type: 'foo'});\nutils.pushNode(parent, foo);\nutils.pushNode(parent, new Node({type: 'bar'}));\nutils.pushNode(parent, new Node({type: 'baz'}));\nconsole.log(parent.nodes.length); //=\u003e 3\nutils.removeNode(parent, foo);\nconsole.log(parent.nodes.length); //=\u003e 2\n```\n\n### [.isType](index.js#L467)\n\nReturns true if `node.type` matches the given `type`. Throws a `TypeError` if `node` is not an instance of `Node`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `type` **{String}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar node = new Node({type: 'foo'});\nconsole.log(utils.isType(node, 'foo')); // false\nconsole.log(utils.isType(node, 'bar')); // true\n```\n\n### [.hasType](index.js#L509)\n\nReturns true if the given `node` has the given `type` in `node.nodes`. Throws a `TypeError` if `node` is not an instance of `Node`.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `type` **{String}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar node = new Node({\n  type: 'foo',\n  nodes: [\n    new Node({type: 'bar'}),\n    new Node({type: 'baz'})\n  ]\n});\nconsole.log(utils.hasType(node, 'xyz')); // false\nconsole.log(utils.hasType(node, 'baz')); // true\n```\n\n### [.firstOfType](index.js#L542)\n\nReturns the first node from `node.nodes` of the given `type`\n\n**Params**\n\n* `nodes` **{Array}**\n* `type` **{String}**\n* `returns` **{Object|undefined}**: Returns the first matching node or undefined.\n\n**Example**\n\n```js\nvar node = new Node({\n  type: 'foo',\n  nodes: [\n    new Node({type: 'text', value: 'abc'}),\n    new Node({type: 'text', value: 'xyz'})\n  ]\n});\n\nvar textNode = utils.firstOfType(node.nodes, 'text');\nconsole.log(textNode.value);\n//=\u003e 'abc'\n```\n\n### [.findNode](index.js#L578)\n\nReturns the node at the specified index, or the first node of the given `type` from `node.nodes`.\n\n**Params**\n\n* `nodes` **{Array}**\n* `type` **{String|Number}**: Node type or index.\n* `returns` **{Object}**: Returns a node or undefined.\n\n**Example**\n\n```js\nvar node = new Node({\n  type: 'foo',\n  nodes: [\n    new Node({type: 'text', value: 'abc'}),\n    new Node({type: 'text', value: 'xyz'})\n  ]\n});\n\nvar nodeOne = utils.findNode(node.nodes, 'text');\nconsole.log(nodeOne.value);\n//=\u003e 'abc'\n\nvar nodeTwo = utils.findNode(node.nodes, 1);\nconsole.log(nodeTwo.value);\n//=\u003e 'xyz'\n```\n\n### [.isOpen](index.js#L602)\n\nReturns true if the given node is an \"*.open\" node.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar brace = new Node({type: 'brace'});\nvar open = new Node({type: 'brace.open'});\nvar close = new Node({type: 'brace.close'});\n\nconsole.log(utils.isOpen(brace)); // false\nconsole.log(utils.isOpen(open)); // true\nconsole.log(utils.isOpen(close)); // false\n```\n\n### [.isClose](index.js#L631)\n\nReturns true if the given node is a \"*.close\" node.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar brace = new Node({type: 'brace'});\nvar open = new Node({type: 'brace.open'});\nvar close = new Node({type: 'brace.close'});\n\nconsole.log(utils.isClose(brace)); // false\nconsole.log(utils.isClose(open)); // false\nconsole.log(utils.isClose(close)); // true\n```\n\n### [.isBlock](index.js#L662)\n\nReturns true if the given node is an \"*.open\" node.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar brace = new Node({type: 'brace'});\nvar open = new Node({type: 'brace.open', value: '{'});\nvar inner = new Node({type: 'text', value: 'a,b,c'});\nvar close = new Node({type: 'brace.close', value: '}'});\nbrace.push(open);\nbrace.push(inner);\nbrace.push(close);\n\nconsole.log(utils.isBlock(brace)); // true\n```\n\n### [.hasNode](index.js#L691)\n\nReturns true if `parent.nodes` has the given `node`.\n\n**Params**\n\n* `type` **{String}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nconst foo = new Node({type: 'foo'});\nconst bar = new Node({type: 'bar'});\ncosole.log(util.hasNode(foo, bar)); // false\nfoo.push(bar);\ncosole.log(util.hasNode(foo, bar)); // true\n```\n\n### [.hasOpen](index.js#L723)\n\nReturns true if `node.nodes` **has** an `.open` node\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar brace = new Node({\n  type: 'brace',\n  nodes: []\n});\n\nvar open = new Node({type: 'brace.open'});\nconsole.log(utils.hasOpen(brace)); // false\n\nbrace.pushNode(open);\nconsole.log(utils.hasOpen(brace)); // true\n```\n\n### [.hasClose](index.js#L754)\n\nReturns true if `node.nodes` **has** a `.close` node\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar brace = new Node({\n  type: 'brace',\n  nodes: []\n});\n\nvar close = new Node({type: 'brace.close'});\nconsole.log(utils.hasClose(brace)); // false\n\nbrace.pushNode(close);\nconsole.log(utils.hasClose(brace)); // true\n```\n\n### [.hasOpenAndClose](index.js#L789)\n\nReturns true if `node.nodes` has both `.open` and `.close` nodes\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar Node = require('snapdragon-node');\nvar brace = new Node({\n  type: 'brace',\n  nodes: []\n});\n\nvar open = new Node({type: 'brace.open'});\nvar close = new Node({type: 'brace.close'});\nconsole.log(utils.hasOpen(brace)); // false\nconsole.log(utils.hasClose(brace)); // false\n\nbrace.pushNode(open);\nbrace.pushNode(close);\nconsole.log(utils.hasOpen(brace)); // true\nconsole.log(utils.hasClose(brace)); // true\n```\n\n### [.addType](index.js#L811)\n\nPush the given `node` onto the `state.inside` array for the given type. This array is used as a specialized \"stack\" for only the given `node.type`.\n\n**Params**\n\n* `state` **{Object}**: The `compiler.state` object or custom state object.\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Array}**: Returns the `state.inside` stack for the given type.\n\n**Example**\n\n```js\nvar state = { inside: {}};\nvar node = new Node({type: 'brace'});\nutils.addType(state, node);\nconsole.log(state.inside);\n//=\u003e { brace: [{type: 'brace'}] }\n```\n\n### [.removeType](index.js#L851)\n\nRemove the given `node` from the `state.inside` array for the given type. This array is used as a specialized \"stack\" for only the given `node.type`.\n\n**Params**\n\n* `state` **{Object}**: The `compiler.state` object or custom state object.\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `returns` **{Array}**: Returns the `state.inside` stack for the given type.\n\n**Example**\n\n```js\nvar state = { inside: {}};\nvar node = new Node({type: 'brace'});\nutils.addType(state, node);\nconsole.log(state.inside);\n//=\u003e { brace: [{type: 'brace'}] }\nutils.removeType(state, node);\n//=\u003e { brace: [] }\n```\n\n### [.isEmpty](index.js#L880)\n\nReturns true if `node.value` is an empty string, or `node.nodes` does not contain any non-empty text nodes.\n\n**Params**\n\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `fn` **{Function}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar node = new Node({type: 'text'});\nutils.isEmpty(node); //=\u003e true\nnode.value = 'foo';\nutils.isEmpty(node); //=\u003e false\n```\n\n### [.isInsideType](index.js#L922)\n\nReturns true if the `state.inside` stack for the given type exists and has one or more nodes on it.\n\n**Params**\n\n* `state` **{Object}**\n* `type` **{String}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar state = { inside: {}};\nvar node = new Node({type: 'brace'});\nconsole.log(utils.isInsideType(state, 'brace')); //=\u003e false\nutils.addType(state, node);\nconsole.log(utils.isInsideType(state, 'brace')); //=\u003e true\nutils.removeType(state, node);\nconsole.log(utils.isInsideType(state, 'brace')); //=\u003e false\n```\n\n### [.isInside](index.js#L956)\n\nReturns true if `node` is either a child or grand-child of the given `type`, or `state.inside[type]` is a non-empty array.\n\n**Params**\n\n* `state` **{Object}**: Either the `compiler.state` object, if it exists, or a user-supplied state object.\n* `node` **{Object}**: Instance of [snapdragon-node](https://github.com/jonschlinkert/snapdragon-node)\n* `type` **{String}**: The `node.type` to check for.\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nvar state = { inside: {}};\nvar node = new Node({type: 'brace'});\nvar open = new Node({type: 'brace.open'});\nconsole.log(utils.isInside(state, open, 'brace')); //=\u003e false\nutils.pushNode(node, open);\nconsole.log(utils.isInside(state, open, 'brace')); //=\u003e true\n```\n\n### [.last](index.js#L1004)\n\nGet the last `n` element from the given `array`. Used for getting\na node from `node.nodes.`\n\n**Params**\n\n* `array` **{Array}**\n* `n` **{Number}**\n* `returns` **{undefined}**\n\n### [.arrayify](index.js#L1028)\n\nCast the given `value` to an array.\n\n**Params**\n\n* `value` **{any}**\n* `returns` **{Array}**\n\n**Example**\n\n```js\nconsole.log(utils.arrayify(''));\n//=\u003e []\nconsole.log(utils.arrayify('foo'));\n//=\u003e ['foo']\nconsole.log(utils.arrayify(['foo']));\n//=\u003e ['foo']\n```\n\n### [.stringify](index.js#L1047)\n\nConvert the given `value` to a string by joining with `,`. Useful\nfor creating a cheerio/CSS/DOM-style selector from a list of strings.\n\n**Params**\n\n* `value` **{any}**\n* `returns` **{Array}**\n\n### [.trim](index.js#L1060)\n\nEnsure that the given value is a string and call `.trim()` on it,\nor return an empty string.\n\n**Params**\n\n* `str` **{String}**\n* `returns` **{String}**\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [snapdragon-node](https://www.npmjs.com/package/snapdragon-node): Snapdragon utility for creating a new AST node in custom code, such as plugins. | [homepage](https://github.com/jonschlinkert/snapdragon-node \"Snapdragon utility for creating a new AST node in custom code, such as plugins.\")\n* [snapdragon-position](https://www.npmjs.com/package/snapdragon-position): Snapdragon util and plugin for patching the position on an AST node. | [homepage](https://github.com/here-be/snapdragon-position \"Snapdragon util and plugin for patching the position on an AST node.\")\n* [snapdragon-token](https://www.npmjs.com/package/snapdragon-token): Create a snapdragon token. Used by the snapdragon lexer, but can also be used by… [more](https://github.com/here-be/snapdragon-token) | [homepage](https://github.com/here-be/snapdragon-token \"Create a snapdragon token. Used by the snapdragon lexer, but can also be used by plugins.\")\n\n### Contributors\n\n| **Commits** | **Contributor** | \n| --- | --- |\n| 43 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 2 | [realityking](https://github.com/realityking) |\n\n### Author\n\n**Jon Schlinkert**\n\n* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on January 11, 2018._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhere-be%2Fsnapdragon-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhere-be%2Fsnapdragon-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhere-be%2Fsnapdragon-util/lists"}