{"id":19560683,"url":"https://github.com/zoubin/tree-iterator","last_synced_at":"2025-06-12T08:32:56.305Z","repository":{"id":57379505,"uuid":"34935720","full_name":"zoubin/tree-iterator","owner":"zoubin","description":"Iterator for walking trees","archived":false,"fork":false,"pushed_at":"2015-05-09T10:14:02.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T21:23:17.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoubin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-02T04:35:04.000Z","updated_at":"2015-05-04T06:57:45.000Z","dependencies_parsed_at":"2022-09-02T20:22:18.813Z","dependency_job_id":null,"html_url":"https://github.com/zoubin/tree-iterator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zoubin/tree-iterator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ftree-iterator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ftree-iterator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ftree-iterator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ftree-iterator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/tree-iterator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ftree-iterator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259429899,"owners_count":22856141,"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","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":[],"created_at":"2024-11-11T05:08:27.857Z","updated_at":"2025-06-12T08:32:56.287Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tree-iterator\nIterator for post-order-walking trees\n\n## Usage\n\n```javascript\nvar PostOrderTree = require('tree-iterator');\n```\n\n### iterable = PostOrderTree(root, getsuccessors, visited)\n\n* `root`: *String|Number*. It is the root (key) of tree.\n* `getsuccessors`: *Function*. It accepts a node (key), and returns its successors, which can either be `Array`, or somthing `Iterable`;\n* `visited`: *Object*. Used to avoid revisiting the same node in [graph walking](https://github.com/zoubin/deps-iterator). Visited nodes are excluded from later paths.\n* `iterable`: *Iterable*.\n\n### for (var node of iterable)\n\n### iter = iterable\\[Symbol.iterator\\]()\n\n### iterable.on('cycle', cb)\n\n## Examples\n\n**for..of**\n\n```javascript\nvar PostOrderTree = require('tree-iterator');\nvar tree = {\n    0: [1, 2],\n    2: [3]\n};\nvar ordered = [];\nvar nodes = PostOrderTree(0, function (node) {\n    return tree[node];\n});\nfor (var n of nodes) {\n    ordered.push(n);\n}\nconsole.log('ordered:', ordered);\n\n```\n\noutput:\n\n```\n⌘ node examples/no-cycle.js\nordered: [ 1, 3, 2, 0  ]\n```\n\n**.on('cycle', cb)**\n\n```javascript\nvar PostOrderTree = require('tree-iterator');\nvar tree = {\n    0: [1],\n    1: [2],\n    2: [3, 0]\n};\nvar nodes = PostOrderTree(0, function (node) {\n    return tree[node];\n});\nvar ordered = [];\nnodes.on('cycle', function (cycle) {\n    // cycle detected: [0, 1, 2, 0]\n    console.log('cycle detected:', cycle);\n});\nfor (var n of nodes) {\n    ordered.push(n);\n}\n// [3, 2, 1, 0]\nconsole.log('ordered:', ordered);\n\n```\n\noutput:\n\n```\n⌘ node examples/cycle.js\nordered: [ 3, 2, 1, 0  ]\ncycle detected: [ 0, 1, 2, 0  ]\n```\n\n**iterable\\[Symbol.iterator\\]()**\n\n```javascript\nvar PostOrderTree = require('tree-iterator');\nvar tree = {\n    0: [1],\n    1: [2],\n    2: [3]\n};\nvar nodes = PostOrderTree(0, function (node) {\n    return tree[node];\n});\nvar iter = nodes[Symbol.iterator]();\n\nconsole.log(iter.next()); // { value: 3, done: false  }\nconsole.log(iter.next()); // { value: 2, done: false  }\nconsole.log(iter.next()); // { value: 1, done: false  }\nconsole.log(iter.next()); // { value: 0, done: false  }\nconsole.log(iter.next()); // { value: undefined, done: true  }\n\n```\n\noutput:\n\n```\n⌘ node examples/iter.js\n{ value: 3, done: false  }\n{ value: 2, done: false  }\n{ value: 1, done: false  }\n{ value: 0, done: false  }\n{ value: undefined, done: true  }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Ftree-iterator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Ftree-iterator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Ftree-iterator/lists"}