{"_id":"@atc-group/js-traverse","name":"@atc-group/js-traverse","dist-tags":{"latest":"0.6.6"},"versions":{"0.6.6":{"name":"@atc-group/js-traverse","version":"0.6.6","description":"traverse and transform objects by visiting every node on a recursive walk","main":"index.js","directories":{"example":"example","test":"test"},"devDependencies":{"tape":"~1.0.4"},"scripts":{"test":"tape test/*.js"},"testling":{"files":"test/*.js","browsers":{"iexplore":["6.0","7.0","8.0","9.0"],"chrome":["10.0","20.0"],"firefox":["10.0","15.0"],"safari":["5.1"],"opera":["12.0"]}},"repository":{"type":"git","url":"git://github.com/substack/js-traverse.git"},"homepage":"https://github.com/substack/js-traverse","keywords":["traverse","walk","recursive","map","forEach","deep","clone"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","publishConfig":{"access":"public"},"_id":"@atc-group/js-traverse@0.6.6","gitHead":"4066a8a9ecd3ff379f4b151a0058f7dbae75d5cd","bugs":{"url":"https://github.com/substack/js-traverse/issues"},"_nodeVersion":"23.7.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-e2Ei1ZYFAvDTDvYqwoK+enReq03UzoB19Df1/xEFjQ8b1KrVlbafs0eVid0WQmd0rs0HknhTDUCAcIfIeu51VQ==","shasum":"d72aa322c0c4b33ee76c964f71434f139cffa700","tarball":"https://registry.npmjs.org/@atc-group/js-traverse/-/js-traverse-0.6.6.tgz","fileCount":29,"unpackedSize":47297,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCWOnupyaV40n0a4t1CebEnXxk53ffDz3Hw605rusArkQIhAMmuwOgBhBJkBH/20fbvmuq/vHNOHuVgpfmYsQMjxMe9"}]},"_npmUser":{"name":"toanzzz","email":"me@toan.io"},"maintainers":[{"name":"atcgroupdev","email":"atcgroupdev@gmail.com"},{"name":"toanzzz","email":"me@toan.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/js-traverse_0.6.6_1739217740528_0.163239506923901"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-10T20:02:20.413Z","0.6.6":"2025-02-10T20:02:20.702Z","modified":"2025-02-10T20:02:21.070Z"},"maintainers":[{"name":"atcgroupdev","email":"atcgroupdev@gmail.com"},{"name":"toanzzz","email":"me@toan.io"}],"description":"traverse and transform objects by visiting every node on a recursive walk","homepage":"https://github.com/substack/js-traverse","keywords":["traverse","walk","recursive","map","forEach","deep","clone"],"repository":{"type":"git","url":"git://github.com/substack/js-traverse.git"},"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"bugs":{"url":"https://github.com/substack/js-traverse/issues"},"license":"MIT","readme":"# traverse\n\nTraverse and transform objects by visiting every node on a recursive walk.\n\n[![browser support](http://ci.testling.com/substack/js-traverse.png)](http://ci.testling.com/substack/js-traverse)\n\n[![build status](https://secure.travis-ci.org/substack/js-traverse.png)](http://travis-ci.org/substack/js-traverse)\n\n# examples\n\n## transform negative numbers in-place\n\nnegative.js\n\n````javascript\nvar traverse = require('traverse');\nvar obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];\n\ntraverse(obj).forEach(function (x) {\n    if (x < 0) this.update(x + 128);\n});\n\nconsole.dir(obj);\n````\n\nOutput:\n\n    [ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ]\n\n## collect leaf nodes\n\nleaves.js\n\n````javascript\nvar traverse = require('traverse');\n\nvar obj = {\n    a : [1,2,3],\n    b : 4,\n    c : [5,6],\n    d : { e : [7,8], f : 9 },\n};\n\nvar leaves = traverse(obj).reduce(function (acc, x) {\n    if (this.isLeaf) acc.push(x);\n    return acc;\n}, []);\n\nconsole.dir(leaves);\n````\n\nOutput:\n\n    [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]\n\n## scrub circular references\n\nscrub.js:\n\n````javascript\nvar traverse = require('traverse');\n\nvar obj = { a : 1, b : 2, c : [ 3, 4 ] };\nobj.c.push(obj);\n\nvar scrubbed = traverse(obj).map(function (x) {\n    if (this.circular) this.remove()\n});\nconsole.dir(scrubbed);\n````\n\noutput:\n\n    { a: 1, b: 2, c: [ 3, 4 ] }\n\n# methods\n\nEach method that takes an `fn` uses the context documented below in the context\nsection.\n\n## .map(fn)\n\nExecute `fn` for each node in the object and return a new object with the\nresults of the walk. To update nodes in the result use `this.update(value)`.\n\n## .forEach(fn)\n\nExecute `fn` for each node in the object but unlike `.map()`, when\n`this.update()` is called it updates the object in-place.\n\n## .reduce(fn, acc)\n\nFor each node in the object, perform a\n[left-fold](http://en.wikipedia.org/wiki/Fold_(higher-order_function))\nwith the return value of `fn(acc, node)`.\n\nIf `acc` isn't specified, `acc` is set to the root object for the first step\nand the root element is skipped.\n\n## .paths()\n\nReturn an `Array` of every possible non-cyclic path in the object.\nPaths are `Array`s of string keys.\n\n## .nodes()\n\nReturn an `Array` of every node in the object.\n\n## .clone()\n\nCreate a deep clone of the object.\n\n## .get(path)\n\nGet the element at the array `path`.\n\n## .set(path, value)\n\nSet the element at the array `path` to `value`.\n\n## .has(path)\n\nReturn whether the element at the array `path` exists.\n\n# context\n\nEach method that takes a callback has a context (its `this` object) with these\nattributes:\n\n## this.node\n\nThe present node on the recursive walk\n\n## this.path\n\nAn array of string keys from the root to the present node\n\n## this.parent\n\nThe context of the node's parent.\nThis is `undefined` for the root node.\n\n## this.key\n\nThe name of the key of the present node in its parent.\nThis is `undefined` for the root node.\n\n## this.isRoot, this.notRoot\n\nWhether the present node is the root node\n\n## this.isLeaf, this.notLeaf\n\nWhether or not the present node is a leaf node (has no children)\n\n## this.level\n\nDepth of the node within the traversal\n\n## this.circular\n\nIf the node equals one of its parents, the `circular` attribute is set to the\ncontext of that parent and the traversal progresses no deeper.\n\n## this.update(value, stopHere=false)\n\nSet a new value for the present node.\n\nAll the elements in `value` will be recursively traversed unless `stopHere` is\ntrue.\n\n## this.remove(stopHere=false)\n\nRemove the current element from the output. If the node is in an Array it will\nbe spliced off. Otherwise it will be deleted from its parent.\n\n## this.delete(stopHere=false)\n\nDelete the current element from its parent in the output. Calls `delete` even on\nArrays.\n\n## this.before(fn)\n\nCall this function before any of the children are traversed.\n\nYou can assign into `this.keys` here to traverse in a custom order.\n\n## this.after(fn)\n\nCall this function after any of the children are traversed.\n\n## this.pre(fn)\n\nCall this function before each of the children are traversed.\n\n## this.post(fn)\n\nCall this function after each of the children are traversed.\n\n\n# install\n\nUsing [npm](http://npmjs.org) do:\n\n    $ npm install traverse\n\n# license\n\nMIT\n","readmeFilename":"readme.markdown"}