{"id":17034511,"url":"https://github.com/caub/ktree","last_synced_at":"2026-03-11T14:34:13.865Z","repository":{"id":57203304,"uuid":"129325341","full_name":"caub/ktree","owner":"caub","description":":evergreen_tree: Efficient search structure in k dimensions Quadtree, Octree, ...","archived":false,"fork":false,"pushed_at":"2018-07-23T19:24:51.000Z","size":69,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T13:13:12.181Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/caub.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":"2018-04-13T00:17:50.000Z","updated_at":"2023-04-17T18:27:07.000Z","dependencies_parsed_at":"2022-09-17T00:51:38.704Z","dependency_job_id":null,"html_url":"https://github.com/caub/ktree","commit_stats":null,"previous_names":["caub/color-octree"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fktree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fktree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fktree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fktree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caub","download_url":"https://codeload.github.com/caub/ktree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571863,"owners_count":21126522,"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-10-14T08:43:50.427Z","updated_at":"2026-03-11T14:34:13.832Z","avatar_url":"https://github.com/caub.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Find efficiently in k-dimensional data\n\n[![npm version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![coverage status][codecov-image]][codecov-url]\n\n### API\n\n- `new Octree/new Quadtree(array\u003c{[key]}\u003e, \u003c{key?: string = 'coords', transform?: function = x =\u003e x, depth?: number = 4}\u003e)`\n- `add(array\u003c{[key]}\u003e)`: Add an array of items\n- `closest(value)`: Search for the closest item by `key` value\n- `remove(value)`: Remove an item from the tree by `key` value\n\n```js\nimport colorNames from 'color-names';\nimport { Octree } from 'ktree'; // colors are 3-dimensional, so use Octree\n\n// simple hex-to-rgb (assuming no short formats, else see https://unpkg.com/color-tf/hexToRgb.js)\nconst hexToRgb = s =\u003e [s.slice(-6, -4), s.slice(-4, -2), s.slice(-2)].map(x =\u003e parseInt(x, 16));\n\nconst colors = Object.entries(colorNames).map(([hex, name]) =\u003e ({ name, hex }));\n\n// Octree constructor needs an array of {[key], ...} objects, where key is configurable\n// We'll use 'hex' here, and add a 'transform' property to map those 'hex' values to 3D coordinates\nconst tree = new Octree(colors, { key: 'hex', transform: hexToRgb });\nconsole.log(tree.closest('5544df')); // { name: 'Majorelle Blue', hex: '#6050dc', d2: 273 }\ntree.remove('#6050dc');\nconsole.log(tree.closest('5544df')); // { name: 'Iris', hex: '#5a4fcf', d2: 402 }\n```\n\n[npm-image]: https://img.shields.io/npm/v/ktree.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/ktree\n[travis-image]: https://img.shields.io/travis/caub/ktree.svg?style=flat-square\n[travis-url]: https://travis-ci.org/caub/ktree\n[codecov-image]: https://img.shields.io/codecov/c/github/caub/ktree.svg?style=flat-square\n[codecov-url]: https://codecov.io/gh/caub/ktree\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaub%2Fktree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaub%2Fktree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaub%2Fktree/lists"}