blob: 074b9dbe9b494f0ba264ceb80c4b710cb27746ec [file] [log] [blame]
{
"name": "js-select",
"description": "Traverse and modify objects with JSONSelect selectors",
"version": "0.6.0",
"author": {
"name": "Heather Arthur",
"email": "fayearthur@gmail.com"
},
"repository": {
"type": "git",
"url": "http://github.com/harthur/js-select.git"
},
"main": "./index",
"dependencies": {
"traverse": "0.4.x",
"JSONSelect": "0.2.1"
},
"devDependencies": {
"nomnom": "0.6.x",
"color": "0.3.x"
},
"keywords": [
"json"
],
"readme": "# js-select\n\njs-select uses [js-traverse](https://github.com/substack/js-traverse) to traverse and modify JavaScript object nodes that match [JSONSelect](http://jsonselect.org/) selectors.\n\n```javascript\nvar people = {\n george: {\n age : 35,\n movie: \"Repo Man\"\n },\n mary: {\n age: 15,\n movie: \"Twilight\"\n }\n};\n```\n\n### .forEach(fn)\n\nIterates over all matching nodes in the object. The callback gets a special `this` context. See [js-traverse](https://github.com/substack/js-traverse) for all the things you can do to modify and inspect the node with this context. In addition, js-select adds a `this.matches()` which will test if the node matches a selector:\n\n```javascript\nselect(people).forEach(function(node) {\n if (this.matches(\".mary > .movie\")) {\n this.remove();\n }\n});\n```\n\n### .nodes()\n\nReturns all matching nodes from the object.\n\n```javascript\nselect(people, \".age\").nodes(); // [35, 15]\n```\n\n### .remove()\n\nRemoves matching elements from the original object.\n\n```javascript\nselect(people, \".age\").remove();\n```\n\n### .update(fn)\n\nUpdates all matching nodes using the given callback.\n\n```javascript\nselect(people, \".age\").update(function(age) {\n return age - 5;\n});\n```\n\n### .condense()\n\nReduces the original object down to only the matching elements (the hierarchy is maintained).\n\n```javascript\nselect(people, \".age\").condense();\n```\n\n```javascript\n{\n george: { age: 35 },\n mary: { age: 15 }\n}\n```\n\n## Selectors\n\njs-select supports the following [JSONSelect](http://jsonselect.org/) selectors:\n\n```\n*\ntype\n.key\nancestor selector\nparent > selector\nsibling ~ selector\nselector1, selector2\n:root\n:nth-child(n)\n:nth-child(even)\n:nth-child(odd)\n:nth-last-child(n)\n:first-child\n:last-child\n:only-child\n:has(selector)\n:val(\"string\")\n:contains(\"substring\")\n```\n\nSee [details](http://jsonselect.org/#docs/overview) on each selector, and [try them](http://jsonselect.org/#tryit) out on the JSONSelect website.\n\n## Install\n\nFor [node](http://nodejs.org), install with [npm](http://npmjs.org):\n\n```bash\nnpm install js-select\n```\n\nFor the browser, download the select.js file or fetch the latest version from [npm](http://npmjs.org) and build a browser file using [browserify](https://github.com/substack/node-browserify):\n\n```bash\nnpm install browserify -g\nnpm install js-select\n\nbrowserify --require js-select --outfile select.js\n```\nthis will build a browser file with `require('js-select')` available.\n\n## Propers\n\nHuge thanks to [@substack](http://github.com/substack) for the ingenious [js-traverse](https://github.com/substack/js-traverse) and [@lloyd](https://github.com/lloyd) for the ingenious [JSONSelect spec](http://http://jsonselect.org/) and [selector parser](http://search.npmjs.org/#/JSONSelect).",
"readmeFilename": "README.md",
"_id": "js-select@0.6.0",
"dist": {
"shasum": "c284e22824d5927aec962dcdf247174aefb0d190",
"tarball": "http://registry.npmjs.org/js-select/-/js-select-0.6.0.tgz"
},
"_from": "js-select@~0.6.0",
"_npmVersion": "1.2.14",
"_npmUser": {
"name": "harth",
"email": "fayearthur@gmail.com"
},
"maintainers": [
{
"name": "harth",
"email": "fayearthur@gmail.com"
}
],
"directories": {},
"_shasum": "c284e22824d5927aec962dcdf247174aefb0d190",
"_resolved": "https://registry.npmjs.org/js-select/-/js-select-0.6.0.tgz",
"bugs": {
"url": "https://github.com/harthur/js-select/issues"
},
"homepage": "https://github.com/harthur/js-select"
}