{"_id":"query-ast","_rev":"385956","name":"query-ast","description":"A library to traverse/modify an AST","dist-tags":{"latest":"1.0.4"},"maintainers":[{"name":"npm:salesforce-ux","email":""}],"time":{"modified":"2021-08-04T03:21:23.000Z","created":"2016-04-25T14:09:26.192Z","1.0.4":"2021-07-09T19:14:32.444Z","1.0.3":"2020-02-04T04:52:22.798Z","1.0.2":"2019-01-16T22:51:19.249Z","1.0.1":"2017-02-23T19:57:23.835Z","1.0.0":"2016-04-25T14:09:26.192Z"},"users":{},"repository":{"type":"git","url":"git+ssh://git@github.com/salesforce-ux/query-ast.git"},"versions":{"1.0.4":{"name":"query-ast","version":"1.0.4","description":"A library to traverse/modify an AST","main":"dist/index.js","license":"BSD-3-Clause","repository":{"type":"git","url":"git+ssh://git@github.com/salesforce-ux/query-ast.git"},"bugs":{"url":"https://github.com/salesforce-ux/query-ast/issues"},"homepage":"https://github.com/salesforce-ux/query-ast","scripts":{"start":"node lib/index.js","test":"mocha lib/**/*.js test/**/*.js --reporter min --recursives","lint":"standard","build":"babel lib --out-dir dist --presets es2015","doc":"jsdoc -c jsdoc.json && mv doc/query-ast/* doc/ && rm -rf doc/query-ast","prepublish":"npm run build"},"dependencies":{"invariant":"2.2.4"},"devDependencies":{"babel-cli":"^6.26.0","babel-preset-es2015":"^6.24.1","chai":"^4.2.0","jsdoc":"^3.6.7","minami":"1.2.3","mocha":"^7.1.1","scss-parser":"^1.0.5","standard":"^14.3.1"},"standard":{"ignore":["node_modules/**/*"]},"gitHead":"b58823e30baffe7c921108925aca628b93f8b910","_id":"query-ast@1.0.4","_nodeVersion":"14.17.1","_npmVersion":"7.19.0","dist":{"shasum":"efa832e1270cc3e0ab42291716f73a7de1928c2a","size":8827,"noattachment":false,"key":"/query-ast/-/query-ast-1.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/query-ast/download/query-ast-1.0.4.tgz"},"_npmUser":{"name":"salesforce-ux","email":"salesforce-ux-npm@salesforce.com"},"directories":{},"maintainers":[{"name":"npm:salesforce-ux","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/query-ast_1.0.4_1625858072301_0.5183716290330265"},"_hasShrinkwrap":false,"publish_time":1625858072444,"_cnpm_publish_time":1625858072444},"1.0.3":{"name":"query-ast","version":"1.0.3","description":"A library to traverse/modify an AST","main":"dist/index.js","license":"BSD-3-Clause","repository":{"type":"git","url":"git+ssh://git@github.com/salesforce-ux/query-ast.git"},"bugs":{"url":"https://github.com/salesforce-ux/query-ast/issues"},"homepage":"https://github.com/salesforce-ux/query-ast","scripts":{"start":"node lib/index.js","test":"mocha lib/**/*.js test/**/*.js --reporter min --recursives","lint":"standard","build":"babel lib --out-dir dist --presets es2015","doc":"jsdoc -c jsdoc.json && mv doc/query-ast/* doc/ && rm -rf doc/query-ast","prepublish":"npm run build"},"dependencies":{"invariant":"2.2.2","lodash":"^4.17.15"},"devDependencies":{"babel-cli":"6.26.0","babel-preset-es2015":"6.24.1","chai":"4.2.0","jsdoc":"^3.6.3","minami":"1.2.3","mocha":"7.0.1","scss-parser":"1.0.3","standard":"14.3.0"},"standard":{"ignore":["node_modules/**/*"]},"gitHead":"4e8bd390e86720790229e2da9277c1fbf7dbe691","_id":"query-ast@1.0.3","_nodeVersion":"10.18.1","_npmVersion":"6.13.4","dist":{"shasum":"4a18374950fa80cbf9b03d7b945bbac8bb4250bf","size":8627,"noattachment":false,"key":"/query-ast/-/query-ast-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/query-ast/download/query-ast-1.0.3.tgz"},"maintainers":[{"name":"npm:salesforce-ux","email":""}],"_npmUser":{"name":"salesforce-ux","email":"salesforce-ux-npm@salesforce.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/query-ast_1.0.3_1580791942674_0.4950732842377825"},"_hasShrinkwrap":false,"publish_time":1580791942798,"_cnpm_publish_time":1580791942798},"1.0.2":{"name":"query-ast","version":"1.0.2","description":"A library to traverse/modify an AST","main":"dist/index.js","license":"BSD-3-Clause","repository":{"type":"git","url":"git+ssh://git@github.com/salesforce-ux/query-ast.git"},"bugs":{"url":"https://github.com/salesforce-ux/query-ast/issues"},"homepage":"https://github.com/salesforce-ux/query-ast","scripts":{"start":"node lib/index.js","test":"mocha lib/**/*.js test/**/*.js --reporter min --recursives","lint":"standard","build":"babel lib --out-dir dist --presets es2015","doc":"jsdoc -c jsdoc.json && mv doc/query-ast/* doc/ && rm -rf doc/query-ast","prepublish":"npm run build"},"dependencies":{"invariant":"2.2.2","lodash":"^4.17.4"},"devDependencies":{"babel-cli":"6.23.0","babel-preset-es2015":"6.22.0","chai":"3.5.0","jsdoc":"3.4.3","minami":"1.1.1","mocha":"^5.2.0","scss-parser":"^1.0.1","standard":"8.6.0"},"standard":{"ignore":["node_modules/**/*"]},"gitHead":"ddef93f10b44fde94cb2a2fa4391316f2c57e12c","_id":"query-ast@1.0.2","_npmVersion":"6.4.1","_nodeVersion":"10.14.0","_npmUser":{"name":"salesforce-ux","email":"salesforce-ux-npm@salesforce.com"},"dist":{"shasum":"efc59271addc2699a1ed563be9a7cc61fed590c0","size":8533,"noattachment":false,"key":"/query-ast/-/query-ast-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/query-ast/download/query-ast-1.0.2.tgz"},"maintainers":[{"name":"npm:salesforce-ux","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/query-ast_1.0.2_1547679079150_0.33077423287659835"},"_hasShrinkwrap":false,"publish_time":1547679079249,"_cnpm_publish_time":1547679079249},"1.0.1":{"name":"query-ast","version":"1.0.1","description":"A library to traverse/modify an AST","main":"dist/index.js","license":"BSD-3-Clause","repository":{"type":"git","url":"git+ssh://git@github.com/salesforce-ux/query-ast.git"},"bugs":{"url":"https://github.com/salesforce-ux/query-ast/issues"},"homepage":"https://github.com/salesforce-ux/query-ast","scripts":{"start":"node lib/index.js","test":"mocha lib/**/*.js test/**/*.js --reporter min --recursives","lint":"standard","build":"babel lib --out-dir dist --presets es2015","doc":"jsdoc -c jsdoc.json && mv doc/query-ast/* doc/ && rm -rf doc/query-ast","prepublish":"npm run build"},"dependencies":{"invariant":"2.2.2","lodash":"4.17.4"},"devDependencies":{"babel-cli":"6.23.0","babel-preset-es2015":"6.22.0","chai":"3.5.0","jsdoc":"3.4.3","minami":"1.1.1","mocha":"3.2.0","scss-parser":"1.0.0","standard":"8.6.0"},"standard":{"ignore":["node_modules/**/*"]},"gitHead":"cff8de91bb6d6a24dbcd581e106d6e882a523c1e","_id":"query-ast@1.0.1","_shasum":"6bb4ea8b7731cc5e90208e79c41bc9c3f09c52aa","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.9.5","_npmUser":{"name":"salesforce-ux","email":"salesforce-ux-npm@salesforce.com"},"dist":{"shasum":"6bb4ea8b7731cc5e90208e79c41bc9c3f09c52aa","size":9674,"noattachment":false,"key":"/query-ast/-/query-ast-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/query-ast/download/query-ast-1.0.1.tgz"},"maintainers":[{"name":"npm:salesforce-ux","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/query-ast-1.0.1.tgz_1487879842046_0.07911416282877326"},"directories":{},"publish_time":1487879843835,"_cnpm_publish_time":1487879843835,"_hasShrinkwrap":false},"1.0.0":{"name":"query-ast","version":"1.0.0","description":"A library to traverse/modify an AST","main":"dist/index.js","scripts":{"start":"node --harmony_destructuring --harmony_rest_parameters lib/index.js","test":"mocha lib/**/*.js test/**/*.js --reporter min --recursive --harmony_destructuring --harmony_rest_parameters","lint":"standard","build":"babel lib --out-dir dist --presets es2015","doc":"jsdoc -c jsdoc.json && mv doc/query-ast/* doc/ && rm -rf doc/query-ast","prepublish":"npm run build"},"dependencies":{"invariant":"2.2.1","lodash":"4.6.1"},"devDependencies":{"babel-cli":"6.6.5","babel-preset-es2015":"6.6.0","chai":"3.5.0","jsdoc":"3.4.0","minami":"1.1.1","mocha":"2.4.5","scss-parser":"1.0.0","standard":"6.0.8"},"standard":{"ignore":["node_modules/**/*"]},"gitHead":"45339450084a88686103080f1c9688b679d3a8f7","_id":"query-ast@1.0.0","_shasum":"2ffda33386da5ff0a65f65f1b909b9018098995f","_from":".","_npmVersion":"3.7.3","_nodeVersion":"5.9.1","_npmUser":{"name":"salesforce-ux","email":"salesforce-ux-npm@salesforce.com"},"dist":{"shasum":"2ffda33386da5ff0a65f65f1b909b9018098995f","size":13352,"noattachment":false,"key":"/query-ast/-/query-ast-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/query-ast/download/query-ast-1.0.0.tgz"},"maintainers":[{"name":"npm:salesforce-ux","email":""}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/query-ast-1.0.0.tgz_1461593364256_0.2893717794213444"},"directories":{},"publish_time":1461593366192,"_cnpm_publish_time":1461593366192,"_hasShrinkwrap":false}},"readme":"# QueryAST\n\n[![Build Status][travis-image]][travis-url]\n[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=salesforce-ux/query-ast)](https://dependabot.com)\n[![NPM version][npm-image]][npm-url]\n\nA library to traverse/modify an AST\n\n## Documentation\n\nRead the [API documentation](https://salesforce-ux.github.io/query-ast/doc/1.0.0)\n\n## Usage\n\n```javascript\nlet createQueryWrapper = require('query-ast')\nlet $ = createQueryWrapper(ast, options)\n```\n\n## Getting Started\n\nQueryAST aims to provide a jQuery like API for traversing an AST.\n\n```javascript\nlet ast = {\n  type: 'program',\n  value: [{\n    type: 'item_container',\n    value: [{\n      type: 'item',\n      value: 'a'\n    }]\n  }, {\n    type: 'item_container',\n    value: []\n  }, {\n    type: 'item',\n    value: 'b'\n  }]\n}\n\n// Create a QueryWrapper that will be used to traverse/modify an AST\nlet $ = createQueryWrapper(ast)\n\n// By default, the QueryWrapper is scoped to the root node\n$('item').length() // 2\n\n// The QueryWrapper can also be scoped to a NodeWrapper or array of NodeWrappers\n$('item_container').filter((n) => {\n  return $(n).has('item')\n}).length() // 1\n```\n\n### Selectors\n\nMost of the traversal functions take an optional `QueryWrapper~Selector` argument that will\nbe use to filter the results.\n\nA selector can be 1 of 3 types:\n- `string` that is compared against the return value of `options.getType()`\n- `regexp` that is compared against the return value of `options.getType()`\n- `function` that will be passed a `NodeWrapper` and expected to return a `boolean`\n\n```javascript\nlet ast = {\n  type: 'program',\n  value: [{\n    type: 'item_container',\n    value: [{\n      type: 'item',\n      value: 'a'\n    }]\n  }, {\n    type: 'item',\n    value: 'b'\n  }]\n}\n\nlet $ = createQueryWrapper(ast)\n\n// String\n$('item').length() // 2\n\n// RegExp\n$(/item/).length() // 3\n\n// Function\n$((n) => n.node.value === 'a').length() // 1\n```\n\n### Default format\n\nBy default, QueryAST assumes that an AST will be formatted as a node tree\nwhere each node has a `type` key and a `value` key that either contains the\nstring value of the node or an array of child nodes.\n\n```javascript\nlet ast = {\n  type: 'program',\n  value: [{\n    type: 'item',\n    value: 'a'\n  }]\n}\n```\n\n## Alternate formats\n\nNot every AST follows the same format, so QueryAST also provides a way\nto traverse any tree structure. Below are the default options used to\nhandle the above AST structure.\n\n```javascript\nlet options = {\n  /**\n   * Return true if the node has children\n   *\n   * @param {object} node\n   * @returns {boolean}\n   */\n  hasChildren: (node) => Array.isArray(node.value),\n  /**\n   * Return an array of child nodes\n   *\n   * @param {object} node\n   * @returns {object[]}\n   */\n  getChildren: (node) => node.value,\n  /**\n   * Return a string representation of the node's type\n   *\n   * @param {object} node\n   * @returns {string}\n   */\n  getType: (node) => node.type,\n  /**\n   * Convert the node back to JSON. This usually just means merging the\n   * children back into the node\n   *\n   * @param {object} node\n   * @param {object[]} [children]\n   * @returns {string}\n   */\n  toJSON: (node, children) => {\n    return Object.assign({}, node, {\n      value: children ? children : node.value\n    })\n  },\n  /**\n   * Convert the node to a string\n   *\n   * @param {object} node\n   * @returns {string}\n   */\n  toString: (node) => {\n    return typeof node.value === 'string' ? node.value : ''\n  }\n}\n```\n\n## Running tests\n\nClone the repository, then:\n\n```bash\nnpm install\n# requires node >= 6.0.0\nnpm test\n```\n\n## Generate Documentation\n\n```bash\nnpm run doc\n```\n\n[npm-url]: https://npmjs.org/package/query-ast\n[npm-image]: http://img.shields.io/npm/v/query-ast.svg\n\n[travis-url]: https://travis-ci.org/salesforce-ux/query-ast\n[travis-image]: https://travis-ci.org/salesforce-ux/query-ast.svg?branch=master\n","_attachments":{},"homepage":"https://github.com/salesforce-ux/query-ast","bugs":{"url":"https://github.com/salesforce-ux/query-ast/issues"},"license":"BSD-3-Clause"}