{"id":17008706,"url":"https://github.com/i-e-b/node-tree-surgeon","last_synced_at":"2026-04-01T22:41:49.113Z","repository":{"id":21076138,"uuid":"24375751","full_name":"i-e-b/node-tree-surgeon","owner":"i-e-b","description":"Tools for editing tree structures using a relational model","archived":false,"fork":false,"pushed_at":"2017-01-31T16:22:58.000Z","size":425,"stargazers_count":5,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-07T08:50:51.449Z","etag":null,"topics":["javascript","manipulation","pojo","production-ready","relational-browsing","tree","working"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i-e-b.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-23T14:52:59.000Z","updated_at":"2023-08-30T13:03:44.000Z","dependencies_parsed_at":"2022-08-02T10:39:51.264Z","dependency_job_id":null,"html_url":"https://github.com/i-e-b/node-tree-surgeon","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/i-e-b/node-tree-surgeon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2Fnode-tree-surgeon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2Fnode-tree-surgeon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2Fnode-tree-surgeon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2Fnode-tree-surgeon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i-e-b","download_url":"https://codeload.github.com/i-e-b/node-tree-surgeon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i-e-b%2Fnode-tree-surgeon/sbom","scorecard":{"id":476063,"data":{"date":"2025-08-11","repo":{"name":"github.com/i-e-b/node-tree-surgeon","commit":"0e7280d4f41969c6a22c28fce09a48e35549b881"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 3-Clause \"New\" or \"Revised\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-19T15:20:22.031Z","repository_id":21076138,"created_at":"2025-08-19T15:20:22.031Z","updated_at":"2025-08-19T15:20:22.031Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31013957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T02:58:54.984Z","status":"ssl_error","status_checked_at":"2026-03-27T02:58:46.993Z","response_time":164,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","manipulation","pojo","production-ready","relational-browsing","tree","working"],"created_at":"2024-10-14T05:29:03.624Z","updated_at":"2026-04-01T22:41:49.094Z","avatar_url":"https://github.com/i-e-b.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-tree-surgeon\n=================\n[![Build Status](https://travis-ci.org/i-e-b/node-tree-surgeon.svg?branch=master)](https://travis-ci.org/i-e-b/node-tree-surgeon) [![Coverage Status](https://coveralls.io/repos/github/i-e-b/node-tree-surgeon/badge.svg?branch=master)](https://coveralls.io/github/i-e-b/node-tree-surgeon?branch=master)\n\nTools for editing tree structures using a relational model.\n\n### General purpose:\n\nTrees are represented internally with two sets: (relational structure)\n\n* Relations: `[{\"Parent\":id, \"Child\":id, \"Kind\":any, ...}, ...]`\n* Nodes: `[{... your data ... }, ...]`\n\nFunctions given to split a POJO into this structure, and merge the structure into a POJO.\n\nNames of object tree parts, as used below:\n```javascript\n{ // this object is the parent, it has one property \"I\" = \"am parent\"\n\n    \"I\" : \"am parent\", // properties (whose values are not objects) remain\n                       //   on the containing object.\n\n    \"Kind\" : // properties (whose values are objects) become relationships.\n             // The key becomes the kind of the relation.\n    {\n        // this object is the child\n        \"Property\" : \"Value\"\n    }\n}\n```\n\nProperties with array values are treated one of two ways:\n```javascript\n{\n    \"JustAProperty\" : [\"hello\", 1,2,3], // first element is NOT an object.\n                                        // Entire array is a single value,\n                                        //   one of the parent's properties\n    \"OneToMany\" : [\n        {\"child\":1}, // First element is an object. All elements are\n                     //   considered children of the parent. Kind is 'OneToMany'\n        {\"child\":2}  // There is no way to express many-to-one, and\n                     //   putting this in the relational structure is not supported.\n    ]\n}\n```\n\n### Operations on POJO structure:\n\nAssuming `var tree = require('tree-surgeon');`\n\n#### Input\n\n- [x] decompose -- turn a normal js object tree into the relational structure\n      \n      `tree.decompose(obj, excludedKinds, relationDecorator, useEmptyRelations);`\n      - `obj` The object to be decomposed for relational operations. This should be a simple object, as returned by `JSON.parse`\n      - `excludedKinds` An array of property names. These properties and their sub-trees will not be decomposed\n      - `relationDecorator` A function to read node as they are decomposed and inject data into the relations table. This data can be used in subsequent operations.\n      - `useEmptyRelations` Bool, default false. If `true`, empty arrays will be treated as object nodes with no children.\n      \n      Returns a relational structure.\n\n### Operations on the relational structure:\n\nAssuming\n```\n    var tree = require('tree-surgeon');\n    var relational = tree.decompose(my_object);\n```\n\n#### Output\n\n- [x] compose -- convert a relational structure back into a plain object. Any manipulations of the relational structure will take effect.\n      \n      `relational.compose()` or `tree.compose(relational)`\n      \n      This is the fastest output function.\n- [x] render -- pass each node through a function, and each kind name through a function and compose tree from the results. Manipulations of the relational structure will take effect, and both property names and object contents can be manipulated during output.\n      \n      `relational.render(renderNodeFunc, renderKindFunc)`\n      - `renderNodeFunc` function that takes (node, path, id) and returns the rendered object contents\n      - `renderKindFunc` function that takes (kind, path) and returns the output property name\n- [x] harvest -- return an object of composed sub-trees by kind, keyed by a parent node value\n      \n      `relational.harvest(kind, idSelector)`\n      - `kind` the target property names to extract\n      - `idSelector` a function that takes the object nodes and returns a unique new property name\n- [x] gather -- return an array of sub-trees\n    - [x] gatherByKind -- subtrees selected by property name\n          \n          `relational.gatherByKind(kind)`\n          - `kind` the target property names to extract\n    - [x] gatherByNode -- subtrees selected by a function\n          \n          `relational.gatherByNode(selector)`\n          - `selector` function that takes a node and returns `bool`. The subtrees of node that result in `true` will be returned.\n\n#### Navigation\n\n- [x] parentIdOf -- get parent ID from child ID, or `null` if not found\n      \n      `relational.parentIdOf(childId)`\n      - `childId` the ID of a node\n      returns the parent ID, or `null` if this was the root node\n- [x] getChildrenOf -- get an array of node IDs for the given parent ID\n      \n      `relational.getChildrenOf(parentId)`\n      - `parentId` the ID of a node\n      returns an array of all child nodes' IDs. Returns empty array if a leaf node was passed.\n- [x] getChildrenByKindOf - get an array of child node IDs for a given parent where the child is a specified type. Kind can be a string, or a `where` predicate on the relationship (an object with exact value matches)\n      \n      `relational.getChildrenByKindOf(parentId, kind)`\n      - `parentId` the ID of a node\n      - `kind` selector for the children to be included\n         - string: pick children with a matching property name\n         - object: pick children whose relation object matches properties on the selector object\n         - function: given the relation object, pick where the function returns `true`\n- [x] getNode -- return the node data for a given ID\n      \n      `relational.getNode(id)`\n      - `id` the ID of a node\n- [x] getPathOf -- give the `Kind` path for a given node ID\n      \n      `relational.getPathOf(nodeId)`\n      - `nodeId` the ID of a node\n- [x] forEachByKind -- given a `Kind` execute the supplied function for all nodes of that kind. Kind can be a string, or a `where` predicate\n      \n      `relational.forEachByKind(kind, actionFunc)`\n      - `kind` selector for the children to be included\n         - string: pick children with a matching property name\n         - object: pick children whose relation object matches properties on the selector object\n         - function: given the relation object, pick where the function returns `true`\n      - `actionFunc` function of `(node, id)` to execute for each matching node. Any return is ignored. Any changes made to the node data is retained.\n\n#### Manipulation\n\n- [x] Normalise -- removes any relationships or nodes that are not reachable from the root, but keeps node and relation indexes consistent.\n      \n      `relational.normalise()`\n- [x] prune -- remove subtrees by relationship kind. Kind can be a string, or a `where` predicate on the relationship (an object with exact value matches)\n      \n      `relational.prune(kind)`\n      - `kind` property name or relation match to remove.\n    - [x] pruneAfter -- remove subtrees by relationship kind, but keep the immediate children. Kind can be a string, or a `where` predicate\n          \n          `relational.pruneAfter(kind)`\n          - `kind` property name or relation match. The children of matches will be removed\n    - [x] pruneAllBut -- remove subtrees that **don't** match a set of kinds. Supports only array of string kinds.\n          \n          `relational.pruneAllBut(kind)`\n          - `kind` property name or relation match. All non-matching relations will be removed\n- [x] chop -- remove subtrees by data predicate\n      \n      `relational.chop(filterFunc)`\n      - `filterFunc` function of `(node, id)`. If this returns a truthy value, node will be removed, else node will be kept\n\n    - [x] chopAfter -- remove subtrees by data predicate, but keep the matched children\n          \n          `relational.chopAfter(filterFunc)`\n          - `filterFunc` function of `(node, id)`. If this returns a truthy value, all children of the matched node will be removed\n\n    - [x] chopByKind -- remove subtrees of a specified 'kind' by data predicate. Kind can be a string, or a `where` predicate\n          \n          `relational.chopByKind(kind, filterFunc)`\n          - `kind` property name or relation match. Matched nodes will be included in the filter\n          - `filterFunc` function of `(node, id)`. If this returns a truthy value, node will be removed, else node will be kept\n    - [x] chopChildless -- remove nodes which have no children (ie. leaves) by data predicate\n          \n          `relational.chopChildless(filterFunc)`\n          - `filterFunc` function of `(node, id)`. All leaf nodes will be passed to this function. If this returns a truthy value, node will be removed.\n    - [x] chopNodesByIds -- remove nodes and their subtrees by their IDs\n          \n          `relational.chopNodesByIds(ids)`\n          - `ids` an array of node ids. All these nodes and their subtrees will be removed.\n\n\n- MergeUp -- remove a relationship and one node by merging data from child to parent. Subtree remains\n    - [x] mergeUpByKind -- select merge targets by relationship kind. Kind can be a string or a `where` predicate\n          \n          `relational.mergeUpByKind(kind)`\n          - `kind` target property or relation match. Matching nodes will be merged into their parents\n    - [x] mergeUpByNode -- select merge targets by applying a predicate to nodes\n          \n          `relational.mergeUpByNode(predFunc)`\n          - `predFunc` function to select nodes. Matching nodes will be merged into their parents\n- MergeDown -- remove a relationship and one node by merging data from parent to child. Subtree remains\n    - [x] mergeDownByKind -- select merge targets by relationship kind. Kind can be a string or a `where` predicate\n          \n          `relational.mergeDownByKind(kind)`\n          - `kind` target property or relation match. Matching nodes' data will be copied into their parents, then the matching node removed.\n\n    - [x] mergeDownByNode -- select merge targets by applying a predicate to nodes\n          \n          `relational.mergeUpByNode(predFunc)`\n          - `predFunc` function to select nodes. Matching nodes' data will be copied into their parents, then the matching node removed.\n\n\n- Fuse -- remove a node by merging into it's parent and child (by supplied function). This is a generalisation of merge up/down.\n    - [x] fuseByNode -- remove a node picked by a predicate on that node\n          \n          `relational.fuseByNode(nodeFunc, pickForParentFunc, pickForChildFunc)`\n          - `nodeFunc` function to pick nodes to fuse\n          - `pickForParentFunc` function that is given node data, and returns the data to copy into the parent node\n          - `pickForChildFunc` function that is given node data, and returns the data to copy into the child node.\n    - [x] fuseByKind -- remove a node picked by kind. Kind can be a string or a `where` predicate\n          \n          `relational.fuseByKind(kind, pickForParentFunc, pickForChildFunc)`\n          - `kind` target property or relation match. Matching nodes will be removed, but sub-trees will remain\n          - `pickForParentFunc` function that is given node data, and returns the data to copy into the parent node\n          - `pickForChildFunc` function that is given node data, and returns the data to copy into the child node.\n\n- [x] flipRelationship -- given a parent kind, a child kind, and an equality function for children; swap parents⇔children, grouping children by equality. The new child kind can be a string or a `where` predicate, but the new parent kind can only be a string.\n      \n      `relational.flipRelationship(newChildKind, newParentKind, newParentHashFunc)`\n      - `newChildKind` property name that is currently the parent node, and should be flipped to being a parent\n      - `newParentKind` property name that is currently the child node, and should be flipped to being a child\n      - `newParentHashFunc` function that takes a node and returns a comparable value (preferable a number)\n\n- [x] reverseByRelation -- make children into parents and parents into children. This is a more complex and powerful version of `flipRelationship`. Have a look in the test cases for examples.\n- [x] reduce -- reduce objects to a single value from inside them, by kind or node predicate (` {a:[{x:1},{x:2}]} -\u003e {a:[1,2]} `)\n- [x] editByKind -- given a `kind` name and an editor function, change all immediate children of that kind. Kind can be a string or a `where` predicate\n- [x] removeEmptyNodes -- recursively remove nodes which contain only `null` or `undefined`. This can remove entire subtrees that contain only empty children\n\n## Unimplemented\n- [ ] graft -- insert new subtrees\n- [ ] disconnect -- the opposite of Fuse, place a new node between a parent and child\n- [ ] fork -- move some of the values of a node into a new or existing sibling\n- [ ] move -- move some of the values of a node into an existing sibling, or do nothing\n- [ ] editPath -- given a path of kinds and a func node→node, replace data at those paths\n- [ ] fuseAway -- remove a node by connecting it's parents to it's children, losing the data in the selected nodes\n- [ ] fuseAwayByNode\n- [ ] fuseAwayByKind\n\nNote:\n* To run istanbul on Windows, use `istanbul cover C:\\Users\\[username]\\AppData\\Roaming\\npm\\node_modules\\mocha\\bin\\_mocha -- -R spec`\n\nTodo:\n* optimisations\n* a good way to find subtrees based on paths, and perform operations based on results\n* bring `.d.ts` file up-to-date with available features\n* syntax should allow chaining of functions\n* extend with `kind` *and* `predicate` functions\n* some way of mutating kind when fusing/merging?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi-e-b%2Fnode-tree-surgeon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi-e-b%2Fnode-tree-surgeon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi-e-b%2Fnode-tree-surgeon/lists"}