{"id":16758530,"url":"https://github.com/kessler/node-digital-tree","last_synced_at":"2025-10-09T11:04:32.193Z","repository":{"id":17741185,"uuid":"20582272","full_name":"kessler/node-digital-tree","owner":"kessler","description":"Trie data structure","archived":false,"fork":false,"pushed_at":"2023-02-11T18:01:34.000Z","size":380,"stargazers_count":14,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T07:07:20.822Z","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/kessler.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-06-07T00:51:48.000Z","updated_at":"2023-03-20T18:55:52.000Z","dependencies_parsed_at":"2023-02-18T09:45:17.319Z","dependency_job_id":null,"html_url":"https://github.com/kessler/node-digital-tree","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/kessler/node-digital-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-digital-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-digital-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-digital-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-digital-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kessler","download_url":"https://codeload.github.com/kessler/node-digital-tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fnode-digital-tree/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267015725,"owners_count":24021616,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-13T04:05:35.970Z","updated_at":"2025-10-09T11:04:27.168Z","avatar_url":"https://github.com/kessler.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# digital tree\n\nA trie data structure implementation. \n\n- thorough testing\n- utility: clonable and serializable (to/from json)\n- search values by prefix\n\n## Install\n\n    npm install --save digital-tree\n\n***version 2.0.0 is almost a complete rewrite and mostly not backwards compatible***\n\n## API\n\n### create() / Ctor\n\nusing `create()`` is the recommended way to construct new digital trees:\n\n```javascript\n    const Trie = require('digital-tree')\n    const trie = Trie.create()\n```\n\n### put(key, value)\n\nPut something in the tree\n\n```javascript\n    trie.put(['a', 'path', 'to'], 'something')\n    trie.put(['another', 'thing']) // equivalent to trie.put(['another', 'thing'], true)\n    trie.put('strings also', 'work') // equivalent to trie.put('strings also'.split(''), 'work')\n    \n    // ** this only work with the exact key (reference) **\n    const objectKey = [{ foo: 'bar' }, { bar: 'foo'}]\n    trie.put(objectKey, { some: 'thing'})\n```\n\n### get(key)\n\nGet something from the tree\n\n```javascript\n    const trie = Trie.create()\n    trie.put(['a', 'path', 'to'], 'v1')\n    trie.put('also strings', 'v2')\n\n    console.log(trie.get([])) // prints 'foo'\n    console.log(trie.get(Trie.root)) // prints 'foo'\n    console.log(trie.get(['a', 'path', 'to'])) // prints 'v1'\n    console.log(trie.get('also strings')) // prints 'v2'\n```\n\n### Iteration\n\nA trie is iterable. Iteration order is either [DFS](https://en.wikipedia.org/wiki/Depth-first_search) or [BFS](https://en.wikipedia.org/wiki/Breadth-first_search)\n\n```javascript\n    const Trie = require('digital-tree')\n    const trie = Trie.create()\n    trie.put('abc', 1)\n    trie.put('abd', 2)\n    trie.put('abe', 3)\n\n    for (let value of trie) {\n\n    }\n```\n\n### search(prefix)\n\nSearch and return all the values in the tree that are nested under the provided `prefix`.\n\nThe results will be an Iterator over the matching values. The order of iteration is defined based on the default ordering of the trie (BFS/DFS)\n\n```javascript\n    const trie = Trie.create()\n    trie.put('abc', 1)\n    trie.put('abd', 2)\n    trie.put('abe', 3)\n\n    console.log(Array.from(trie.search('ab'))) // prints [ 3, 2, 1 ]\n    console.log(Array.from(trie.search('ab', { includeKeys: true }))) // prints [ [['a','b','e'], 3 ], [['a','b','d'], 2], [['a','b','c'], 1] ]\n```\n\n### getSubTrie(key, [shallow=false])\n\nObtain either a cloned, or shallow copy of a subtree.\n\n```javascript\ntrie.put('abc', 1)\ntrie.put('abd', 2)\n\nconst subTrie = trie.getSubTrie('ab')\n\nconsole.log(subTrie.get('c')) // prints 1\nconsole.log(subTrie.get('d')) // prints 2\nconsole.log(subTrie.get('ab')) // prints undefined\n```\n*setting `shallow` to `true` will create a view rather than cloning the sub trie*\n\n### remove(key)\n\nRemove something from the tree. This will remove the entire subtree that exists under this specified key and return it\nas a new trie.\n\n```javascript\n    trie.put(['a', 'b'], 'ab')\n    trie.put(['a', 'b', 'c'], 'abc')\n    trie.put(['a', 'b', 'c', 1], 'abc1')\n    trie.put(['a', 'b', 'c', 2], 'abc2')\n\n    const removed = trie.remove(['a', 'b', 'c'])\n    \n    console.log(removed.get([1])) // prints 'abc1'\n    console.log(removed.get([2])) // prints 'abc2'\n\n    console.log(trie.get(['a', 'b', 'c', 1])) // prints 'undefined'\n    console.log(trie.get(['a', 'b'])) // prints 'ab'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fnode-digital-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkessler%2Fnode-digital-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fnode-digital-tree/lists"}