{"id":26273930,"url":"https://github.com/hash-bang/tree-tools","last_synced_at":"2025-12-29T15:45:35.951Z","repository":{"id":57379627,"uuid":"66050271","full_name":"hash-bang/tree-tools","owner":"hash-bang","description":"Tools to manage deeply nested collection tree structures","archived":false,"fork":false,"pushed_at":"2019-08-05T07:44:24.000Z","size":88,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T16:49:32.999Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hash-bang.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":"2016-08-19T03:39:09.000Z","updated_at":"2020-07-30T12:36:56.000Z","dependencies_parsed_at":"2022-09-02T20:22:04.970Z","dependency_job_id":null,"html_url":"https://github.com/hash-bang/tree-tools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hash-bang%2Ftree-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hash-bang%2Ftree-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hash-bang%2Ftree-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hash-bang%2Ftree-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hash-bang","download_url":"https://codeload.github.com/hash-bang/tree-tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243414959,"owners_count":20287212,"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":"2025-03-14T09:17:28.455Z","updated_at":"2025-12-29T15:45:35.923Z","avatar_url":"https://github.com/hash-bang.png","language":"JavaScript","readme":"Tree-Tools\n==========\nTools to manage deeply nested collection tree structures.\n\nSee the [API](#api) reference for a full list of functionality.\n\n\nGoals:\n\n* Provide a simple API to manipulate and operate on tree structures\n* Closely mirror [Lodash's](https://lodash.com) API wherever possible to minimize confusion\n* No dependencies (except Lodash)\n\n\nInstall (NodeJS)\n----------------\nInstall via\n\n\tnpm install tree-tools\n\nThen just use as\n\n```javascript\nvar treeTools = require('tree-tools');\n\ntreeTools.flatten(treeTools.find(tree, {path: '/bar/baz'}));\n```\n\nInstall (AngularJS)\n-------------------\n1. Include `dist/ngTreeTools.js` somewhere in your build chain\n2. Add `ngTreeTools` as a module in your main `angular.module('app', [modules])` list\n3. Require the module as `TreeTools` in your controller e.g. `app.controller('myController', function($scope, TreeTools) { // Controller // })`\n\n\nAPI\n===\nIn all the examples below the example tree structure is similar to [the main test case](test/test.js).\n\n\ntreeTools.find(tree, query, options)\n------------------------------------\nFind a single node deeply within a tree structure.\nQuery can be any valid Lodash matching object or a function.\n\n```javascript\ntreeTools.find(tree, {path: '/bar/baz'});\n```\n\nSince this function is really just a convenience wrapper around `parents()` see that function definition for available options.\n\n\ntreeTools.filter(tree, query, options)\n--------------------------------------\nReturn a copy of a tree while filtering nodes.\nQuery can be any valid Lodash matching object or a function.\n\n```javascript\ntreeTools.find(tree, (node, index) =\u003e matchingExpression);\n```\n\nOptions are:\n\n| Option      | Type            | Default      | Description                                                                   |\n|-------------|-----------------|--------------|-------------------------------------------------------------------------------|\n| `childNode` | String or Array | `\"children\"` | How to discover child nodes, can be a single key or an array of keys to check |\n\n\ntreeTools.flatten(tree)\n-----------------------\nReturn all branches of a tree as a flat array.\nThe array is returned as a shallow copy, allowing mutation via `forEach` or `map` iterators.\n\n```javascript\ntreeTools.flatten(treeTools.find(tree, {path: '/bar/baz'}));\n```\n\nOptions are:\n\n| Option      | Type            | Default      | Description                                                                   |\n|-------------|-----------------|--------------|-------------------------------------------------------------------------------|\n| `childNode` | String or Array | `\"children\"` | How to discover child nodes, can be a single key or an array of keys to check |\n\n\ntreeTools.parents(tree, query, options)\n---------------------------------------\nUtility function to deep search a tree structure for a matching query and find parents up to the given query.\nIf found this function will return an array of all generations with the found branch as the last element of the array.\n\n```javascript\ntreeTools.parents(tree, {path: '/bar/baz'})\n```\n\nOptions are:\n\n| Option      | Type            | Default      | Description                                                                   |\n|-------------|-----------------|--------------|-------------------------------------------------------------------------------|\n| `childNode` | String or Array | `\"children\"` | How to discover child nodes, can be a single key or an array of keys to check |\n\n\ntreeTools.children(tree, query, options)\n----------------------------------------\nUtility function to deep search a tree structure for a matching query and find all children after the given query.\nIf found this function will return an array of all child elements NOT including the query element.\n\n```javscript\ntreeTools.children(tree, {path: '/foo'});\n```\n\nOptions are:\n\n| Option      | Type            | Default      | Description                                                                   |\n|-------------|-----------------|--------------|-------------------------------------------------------------------------------|\n| `childNode` | String or Array | `\"children\"` | How to discover child nodes, can be a single key or an array of keys to check |\n\n\ntreeTools.hasChildren(branch, options)\n--------------------------------------\nUtility function to determines whether a given node has children.\n\n```javascript\ntreeTools.hasChildren(someBranch); // Returns a boolean\n```\n\nOptions are:\n\n| Option      | Type            | Default      | Description                                                                   |\n|-------------|-----------------|--------------|-------------------------------------------------------------------------------|\n| `childNode` | String or Array | `\"children\"` | How to discover child nodes, can be a single key or an array of keys to check |\n\n\ntreeTools.hasSome(tree, query)\n------------------------------\nUtility function to determine if an item matching query exists deep within a given tree.\n\n```javascript\ntreeTools.hasSome(tree, {someKey: someValue});\ntreeTools.hasSome(tree, (v, k) =\u003e { ... });\n```\n\n\ntreeTools.resolve(tree, options)\n--------------------------------\nRecursively walk a tree evaluating all functions (promise compatible) and inserting their values.\nShould a node return a promise it will be waited on before evaluating it along with its children, recursively.\n\n```javascript\ntreeTools.resolve(complexTreeWithPromises)\n\t.then(tree =\u003e {...})\n```\n\nOptions are:\n\n| Option        | Type              | Default           | Description                                                                                                                                  |\n|---------------|-------------------|-------------------| ---------------------------------------------------------------------------------------------------------------------------------------------|\n| `childNode`   | String or Array   | `\"children\"`      | How to discover child nodes, can be a single key or an array of keys to check                                                                |\n| `clone`       | Boolean           | `false`           | Clone the tree before resolving it, this keeps the original intact but costs some time while cloning, without this the input will be mutated |\n| `attempts`    | Number            | `5`               | How many times to recurse when resolving promises-within-promises                                                                            |\n| `isPromise`   | Function          | `_.isFunction`    | Function used to recognise a promise-like return when recursing into promises                                                                |\n| `isSplice`    | Function          | See code          | Support splicing arrays (arrays are collapsed into their parents rather than returned as is)                                                 |\n| `wrapper`     | Function          | `Promise.resolve` | Wrap the promise in this function before resolving. Called as `(nodeFunction, path, tree)`                                                   |\n\n\ntreeTools.sortBy(tree, propertyName)\n------------------------------------\nUtility function to sort tree by specific property or an array of properties.\n`propertyName` can be a string or an array of strings.\n\n```javascript\n// Sort an outer array of families with all children in `name` order\ntreeTools.sortBy(families, 'name');\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhash-bang%2Ftree-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhash-bang%2Ftree-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhash-bang%2Ftree-tools/lists"}