{"_id":"treeverse","_rev":"2948180","name":"treeverse","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"isaacs","email":""}],"time":{"modified":"2023-04-26T08:51:42.000Z","created":"2019-07-30T23:28:51.905Z","3.0.0":"2022-10-14T05:22:35.705Z","2.0.0":"2022-04-05T16:46:53.419Z","1.0.4":"2020-08-25T23:56:43.417Z","1.0.3":"2020-02-03T19:39:15.533Z","1.0.2":"2020-01-17T23:33:14.260Z","1.0.1":"2019-07-30T23:43:02.737Z","1.0.0":"2019-07-30T23:28:51.905Z"},"users":{},"author":{"name":"GitHub Inc."},"repository":{"type":"git","url":"git+https://github.com/npm/treeverse.git"},"versions":{"3.0.0":{"name":"treeverse","version":"3.0.0","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","author":{"name":"GitHub Inc."},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/npm/treeverse.git"},"scripts":{"test":"tap","snap":"tap","lint":"eslint \"**/*.js\"","postlint":"template-oss-check","template-oss-apply":"template-oss-apply --force","lintfix":"npm run lint -- --fix","posttest":"npm run lint"},"tap":{"100":true,"coverage-map":"test/coverage-map.js","nyc-arg":["--exclude","tap-snapshots/**"]},"devDependencies":{"@npmcli/eslint-config":"^3.0.1","@npmcli/template-oss":"4.5.1","tap":"^16.0.1"},"main":"lib/index.js","keywords":["tree","traversal","depth first search","breadth first search"],"engines":{"node":"^14.17.0 || ^16.13.0 || >=18.0.0"},"templateOSS":{"//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten.","version":"4.5.1"},"gitHead":"bdce5a4a448021e04b1aa60ae10803053e579aef","bugs":{"url":"https://github.com/npm/treeverse/issues"},"homepage":"https://github.com/npm/treeverse#readme","_id":"treeverse@3.0.0","_nodeVersion":"18.10.0","_npmVersion":"8.19.2","dist":{"shasum":"dd82de9eb602115c6ebd77a574aae67003cb48c8","size":4636,"noattachment":false,"key":"/treeverse/-/treeverse-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/treeverse/download/treeverse-3.0.0.tgz"},"_npmUser":{"name":"lukekarrys","email":"luke@lukekarrys.com"},"directories":{},"maintainers":[{"name":"isaacs","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/treeverse_3.0.0_1665724955526_0.202118129432715"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-10-19T21:41:45.558Z","publish_time":1665724955705,"_cnpm_publish_time":1665724955705},"2.0.0":{"name":"treeverse","version":"2.0.0","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","author":{"name":"GitHub Inc."},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/npm/treeverse.git"},"scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags","lint":"eslint \"**/*.js\"","postlint":"template-oss-check","template-oss-apply":"template-oss-apply --force","lintfix":"npm run lint -- --fix","prepublishOnly":"git push origin --follow-tags","posttest":"npm run lint"},"tap":{"100":true,"coverage-map":"test/coverage-map.js"},"devDependencies":{"@npmcli/eslint-config":"^3.0.1","@npmcli/template-oss":"3.2.2","tap":"^16.0.1"},"main":"lib/index.js","keywords":["tree","traversal","depth first search","breadth first search"],"engines":{"node":"^12.13.0 || ^14.15.0 || >=16.0.0"},"templateOSS":{"//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten.","version":"3.2.2"},"gitHead":"1080c1fcb6cb08a9be3650258c4b944a67eee5ab","bugs":{"url":"https://github.com/npm/treeverse/issues"},"homepage":"https://github.com/npm/treeverse#readme","_id":"treeverse@2.0.0","_nodeVersion":"16.14.2","_npmVersion":"8.6.0","dist":{"shasum":"036dcef04bc3fd79a9b79a68d4da03e882d8a9ca","size":4643,"noattachment":false,"key":"/treeverse/-/treeverse-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/treeverse/download/treeverse-2.0.0.tgz"},"_npmUser":{"name":"gar","email":"gar+npm@danger.computer"},"directories":{},"maintainers":[{"name":"isaacs","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/treeverse_2.0.0_1649177213270_0.39077193726076764"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-04-05T19:17:01.033Z","publish_time":1649177213419,"_cnpm_publish_time":1649177213419},"1.0.4":{"name":"treeverse","version":"1.0.4","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/npm/treeverse.git"},"scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags"},"tap":{"100":true,"coverage-map":"map.js"},"devDependencies":{"tap":"^14.10.6","tcompare":"^2.3.0"},"main":"index.js","keywords":["tree","traversal","depth first search","breadth first search"],"gitHead":"c6f848b71c22f24c34495e917faf71762f89129e","bugs":{"url":"https://github.com/npm/treeverse/issues"},"homepage":"https://github.com/npm/treeverse#readme","_id":"treeverse@1.0.4","_nodeVersion":"14.8.0","_npmVersion":"7.0.0-beta.7","dist":{"shasum":"a6b0ebf98a1bca6846ddc7ecbc900df08cb9cd5f","size":4450,"noattachment":false,"key":"/treeverse/-/treeverse-1.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/treeverse/download/treeverse-1.0.4.tgz"},"maintainers":[{"name":"isaacs","email":""}],"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/treeverse_1.0.4_1598399803302_0.2716142959689327"},"_hasShrinkwrap":false,"publish_time":1598399803417,"_cnpm_publish_time":1598399803417},"1.0.3":{"name":"treeverse","version":"1.0.3","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/npm/treeverse.git"},"scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags"},"tap":{"100":true,"coverage-map":"map.js"},"devDependencies":{"tap":"^14.10.6","tcompare":"^2.3.0"},"main":"index.js","keywords":["tree","traversal","depth first search","breadth first search"],"gitHead":"b21085d40cc4668f9715482a187957c9b55ce763","bugs":{"url":"https://github.com/npm/treeverse/issues"},"homepage":"https://github.com/npm/treeverse#readme","_id":"treeverse@1.0.3","_nodeVersion":"13.7.0","_npmVersion":"6.13.7","dist":{"shasum":"43ad19831b8b7583988f83cbf4d1eaf428f816ae","size":3811,"noattachment":false,"key":"/treeverse/-/treeverse-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/treeverse/download/treeverse-1.0.3.tgz"},"maintainers":[{"name":"isaacs","email":""}],"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/treeverse_1.0.3_1580758755379_0.5025868193754206"},"_hasShrinkwrap":false,"publish_time":1580758755533,"_cnpm_publish_time":1580758755533},"1.0.2":{"name":"treeverse","version":"1.0.2","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"ISC","scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags"},"tap":{"100":true,"coverage-map":"map.js"},"devDependencies":{"tap":"^14.5.0","tcompare":"^2.3.0"},"main":"index.js","repository":{"type":"git","url":"git+https://github.com/npm/treeverse.git"},"keywords":["tree","traversal","depth first search","breadth first search"],"gitHead":"95abb40f1ac2569d5c92ccba332239498f71ae5d","bugs":{"url":"https://github.com/npm/treeverse/issues"},"homepage":"https://github.com/npm/treeverse#readme","_id":"treeverse@1.0.2","_nodeVersion":"13.4.0","_npmVersion":"6.13.6","dist":{"shasum":"ac0e990a44467b4993a8702764c9e230e570b4e9","size":3812,"noattachment":false,"key":"/treeverse/-/treeverse-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/treeverse/download/treeverse-1.0.2.tgz"},"maintainers":[{"name":"isaacs","email":""}],"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/treeverse_1.0.2_1579303994151_0.29384884527035005"},"_hasShrinkwrap":false,"publish_time":1579303994260,"_cnpm_publish_time":1579303994260},"1.0.1":{"name":"treeverse","version":"1.0.1","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"ISC","scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags"},"tap":{"100":true,"coverage-map":"map.js"},"devDependencies":{"tap":"^14.5.0","tcompare":"^2.3.0"},"gitHead":"7ff1579b03151b308eeed828dfe9945bb3ef637d","_id":"treeverse@1.0.1","_nodeVersion":"12.6.0","_npmVersion":"6.10.2","dist":{"shasum":"218897a9c8d2ad988ca44d202962240f251cd935","size":3685,"noattachment":false,"key":"/treeverse/-/treeverse-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/treeverse/download/treeverse-1.0.1.tgz"},"maintainers":[{"name":"isaacs","email":""}],"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/treeverse_1.0.1_1564530182632_0.9465111860256159"},"_hasShrinkwrap":false,"publish_time":1564530182737,"_cnpm_publish_time":1564530182737},"1.0.0":{"name":"treeverse","version":"1.0.0","description":"Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"ISC","scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags"},"tap":{"100":true,"coverage-map":"map.js"},"devDependencies":{"tap":"^14.5.0","tcompare":"^2.3.0"},"gitHead":"dd74976e5d976372e6cfa40651e9dc2c29e36b71","_id":"treeverse@1.0.0","_nodeVersion":"12.6.0","_npmVersion":"6.10.2","dist":{"shasum":"35cef66afc37c58eb5d9491c5694b2006e0bfe71","size":33364,"noattachment":false,"key":"/treeverse/-/treeverse-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/treeverse/download/treeverse-1.0.0.tgz"},"maintainers":[{"name":"isaacs","email":""}],"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/treeverse_1.0.0_1564529331733_0.8603087666432858"},"_hasShrinkwrap":false,"publish_time":1564529331905,"_cnpm_publish_time":1564529331905}},"readme":"# treeverse\n\nWalk any kind of tree structure depth- or breadth-first. Supports promises\nand advanced map-reduce operations with a very small API.\n\nTreeverse does not care what kind of tree it is, it will traverse it for\nyou just fine.  It does the right thing with functions that return\nPromises, and returns a non-Promise value if your functions don't return\nPromises.\n\nRather than imposing a specific structure, like requiring you to have child\nnodes stored in a `children` array, it calls the supplied `getChildren()`\nfunction, so the children can be anywhere (or not even exist yet!)  This\nmakes it suitable for _creating_ an optimized tree from a set of dependency\nmanifests, for example.\n\n## USAGE\n\n```js\nconst {depth, breadth} = require('treeverse')\n\n// depth-first traversal\n// returns a promise if any visit/leave function returns a promise\n// otherwise returns the result of leave, or visit if no leave function\n// provided.\ndepth({\n  // the root node where we start the traversal\n  tree: rootNode,\n\n  visit (node) {\n    // optional\n    // called upon descent into the node.\n    // return a promise, or a mapped value, or nothing to just leave it\n    // as-is\n  },\n  leave (node, children) {\n    // optional\n    // called as we ascend back to the root of the tree.\n    // return a promise, or a reduced value, or nothing to leave it as is\n    // the children array is a list of the child nodes that have been\n    // visited (and potentially left) already.  If the tree is acyclic,\n    // then leave() will have been called on all of them.  If it has\n    // cycles, then the children may not have been left yet.\n  },\n  getChildren (node, nodeResult) {\n    // required\n    // return an array of child nodes in the tree, if any exist\n    // returning a promise is totally ok, of course.\n    // the first argument is the original value of the node.  The second\n    // argument is the result of visit(node).\n  },\n  filter (node) {\n    // optional\n    // return true if the node should be visited, false otherwise\n    // initial tree is always visited, so this only filters children\n    // note that filtering a node _also_ filters all of its children.\n  },\n})\n\n// breadth first traversal\n// returns a promise if any visit function returns a promise\n// otherwise returns the result of the top-level node.\n// note that only a visit() function is supported here, since a node's\n// children are typically traversed much later in the process.\nbreadth({\n  // the root node where we start the traversal\n  tree: rootNode,\n\n  visit (node) {\n    // optional, but a no-op if not provided.\n    // called when this node is encountered in the traversal.\n    // return a promise, or a mapped value, or nothing to leave as-is.\n  },\n  getChildren (node, nodeResult) {\n    // required, same as depth()\n  },\n  filter (node) {\n    // optional, same as depth()\n  },\n})\n```\n\n## API\n\nBoth functions take a single options object as an argument, and return\neither the result value, or a Promise to the result value if the\nmethods in the options argument ever return a Promise.\n\n* `treeverse.breadth` - Perform a breadth-first traversal.  That is, walk\n  across node siblings before traversing node children.\n* `treeverse.depth` - Perform a depth-first traversal.  That is, walk\n  down into child nodes before traversing siblings.\n\n## OPTIONS\n\nAll function options can return a Promise or actual value.\n\nThe return value is the result of the top level visit function if no leave\nfunction is provided, or leave.  If any method along the way returns a\npromise, then the top level function will return a promise which resolves\nto the result of visiting (and leaving) the top node in the tree.\n\n* `tree` - The initial node where the traversal begins.\n* `visit(node)` - Function to call upon visiting a node.\n* `leave(node, children)` - (Depth only) Function to call upon leaving a\n  node, once all of its children have been visited, and potentially left.\n  `children` is an array of child node visit results.  If the graph is\n  cyclic, then some children _may_ have been visited but not left.\n* `getChildren(node, nodeResult)` - Get an array of child nodes to process.\n* `filter` - Filter out child nodes from the traversal.  Note that this\n  filters the entire branch of the tree, not just that one node.  That is,\n  children of filtered nodes are not traversed either.\n\n## STACK DEPTH WARNING\n\nWhen a `leave` method is specified, then recursion is used, because\nmaintaining state otherwise is challenging.  This means that using `leave`\nwith a synchronous depth first traversal of very deeply nested trees will\nresult in stack overflow errors.\n\nTo avoid this, either make one or more of the functions async, or do all of\nthe work in the `visit` method.\n\nBreadth-first traversal always uses a loop, and is stack-safe.\n\nIt is _possible_ to implement depth first traversal with a leave method\nusing a loop rather than recursion, but maintaining the `leave(node,\n[children])` API surface would be challenging, and is not implemented at\nthis time.\n","_attachments":{},"homepage":"https://github.com/npm/treeverse#readme","bugs":{"url":"https://github.com/npm/treeverse/issues"},"license":"ISC"}