{"_id":"short-tree","_rev":"3290766","name":"short-tree","description":"Keep a tree trimmed from longer-than-necessary branches","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"grantila","email":""}],"time":{"modified":"2024-05-23T06:50:42.000Z","created":"2021-04-01T17:15:27.195Z","3.0.0":"2023-02-02T21:04:44.460Z","2.0.0":"2021-09-13T06:57:05.503Z","1.0.0":"2021-04-01T17:15:27.195Z"},"users":{},"author":{"name":"Gustaf Räntilä"},"repository":{"type":"git","url":"git+https://github.com/grantila/short-tree.git"},"versions":{"3.0.0":{"name":"short-tree","version":"3.0.0","description":"Keep a tree trimmed from longer-than-necessary branches","author":{"name":"Gustaf Räntilä"},"license":"MIT","bugs":{"url":"https://github.com/grantila/short-tree/issues"},"homepage":"https://github.com/grantila/short-tree#readme","exports":"./dist/index.js","main":"./dist/index.js","types":"./dist/index.d.ts","type":"module","sideEffects":false,"engines":{"node":"^14.13.1 || >=16.0.0"},"scripts":{"build":"rimraf dist && tsc -p tsconfig.prod.json","test":"NODE_OPTIONS=--experimental-vm-modules jest --coverage","cz":"git-cz"},"repository":{"type":"git","url":"git+https://github.com/grantila/short-tree.git"},"keywords":["graph","tree","trim"],"devDependencies":{"@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.18.6","@types/jest":"^29.4.0","@types/node":"^18.11.18","cz-conventional-changelog":"^3.3.0","jest":"^29.4.1","rimraf":"^4.1.2","typescript":"^4.9.5"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"dependencies":{"@types/bintrees":"^1.0.3","bintrees":"^1.0.2"},"jest":{"testEnvironment":"node","coverageReporters":["lcov","text","html"]},"packageManager":"yarn@3.2.4","gitHead":"7489f9eaa0767f5c76609e74711afddc0a105549","_id":"short-tree@3.0.0","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"shasum":"f4db4cf9f2d87e9edc5083046c8c0fb59cc4ed1d","size":3565,"noattachment":false,"key":"/short-tree/-/short-tree-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/short-tree/download/short-tree-3.0.0.tgz"},"_npmUser":{"name":"grantila","email":"g.rantila@gmail.com"},"directories":{},"maintainers":[{"name":"grantila","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/short-tree_3.0.0_1675371884273_0.10743281629191159"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-02-02T21:04:44.460Z","publish_time":1675371884460,"_cnpm_publish_time":1675371884460},"2.0.0":{"name":"short-tree","version":"2.0.0","description":"Keep a tree trimmed from longer-than-necessary branches","author":{"name":"Gustaf Räntilä"},"license":"MIT","bugs":{"url":"https://github.com/grantila/short-tree/issues"},"homepage":"https://github.com/grantila/short-tree#readme","exports":"./dist/index.js","main":"./dist/index.js","types":"./dist/index.d.ts","type":"module","sideEffects":false,"engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"build":"rimraf dist && tsc -p tsconfig.prod.json","test":"NODE_OPTIONS=--experimental-vm-modules jest --coverage","cz":"git-cz"},"repository":{"type":"git","url":"git+https://github.com/grantila/short-tree.git"},"keywords":["graph","tree","trim"],"devDependencies":{"@babel/preset-env":"^7.15.6","@babel/preset-typescript":"^7.15.0","@types/jest":"^27.0.1","@types/node":"^16.9.1","cz-conventional-changelog":"^3.1.0","jest":"^27.1.1","rimraf":"^3.0.1","typescript":"^4.4.3"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"dependencies":{"@types/bintrees":"^1.0.3","bintrees":"^1.0.2"},"jest":{"testEnvironment":"node","coverageReporters":["lcov","text","html"]},"gitHead":"16e81adb7c490eaa791cec87d5c2c62b61718f7b","_id":"short-tree@2.0.0","_nodeVersion":"14.17.6","_npmVersion":"6.14.15","dist":{"shasum":"f95821cd5c5a5e13991904ff3046bc57be355779","size":3639,"noattachment":false,"key":"/short-tree/-/short-tree-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/short-tree/download/short-tree-2.0.0.tgz"},"_npmUser":{"name":"grantila","email":"g.rantila@gmail.com"},"directories":{},"maintainers":[{"name":"grantila","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/short-tree_2.0.0_1631516225357_0.841125974685611"},"_hasShrinkwrap":false,"publish_time":1631516225503,"_cnpm_publish_time":1631516225503,"_cnpmcore_publish_time":"2021-12-17T00:21:40.807Z"},"1.0.0":{"name":"short-tree","version":"1.0.0","description":"Keep a tree trimmed from longer-than-necessary branches","author":{"name":"Gustaf Räntilä"},"license":"MIT","bugs":{"url":"https://github.com/grantila/short-tree/issues"},"homepage":"https://github.com/grantila/short-tree#readme","main":"./dist/index.js","types":"./dist/index.d.ts","directories":{},"engines":{"node":">=12"},"scripts":{"build":"rimraf dist && tsc -p tsconfig.prod.json","test":"jest --coverage","cz":"git-cz"},"repository":{"type":"git","url":"git+https://github.com/grantila/short-tree.git"},"keywords":["graph","tree","trim"],"devDependencies":{"@types/jest":"^26.0.20","@types/node":"^14.14.31","cz-conventional-changelog":"^3.1.0","jest":"^26.6.3","rimraf":"^3.0.1","ts-jest":"^26.5.2","typescript":"^4.2.2"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"dependencies":{"@types/bintrees":"^1.0.3","bintrees":"^1.0.2"},"gitHead":"36388bf8797b6db5b632d699e45fc2c706c8ea6e","_id":"short-tree@1.0.0","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"shasum":"bbf31c2f798ecbf48ecf6656b1bd62d202b43759","size":3272,"noattachment":false,"key":"/short-tree/-/short-tree-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/short-tree/download/short-tree-1.0.0.tgz"},"_npmUser":{"name":"grantila","email":"g.rantila@gmail.com"},"maintainers":[{"name":"grantila","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/short-tree_1.0.0_1617297327093_0.7753082416875885"},"_hasShrinkwrap":false,"publish_time":1617297327195,"_cnpm_publish_time":1617297327195,"_cnpmcore_publish_time":"2021-12-17T00:21:41.088Z"}},"readme":"[![npm version][npm-image]][npm-url]\n[![downloads][downloads-image]][npm-url]\n[![build status][build-image]][build-url]\n[![coverage status][coverage-image]][coverage-url]\n[![Node.JS version][node-version]][node-url]\n\n\n# short-tree\n\n`ShortTree` is a class extending `RBTree` from [bintrees][bintrees-npm-url], and **works explicitly on nodes of arrays**.\n\nThe `ShortTree< T >` class extends `RBTree< Array< T > >`.\n\n`insert` is overloaded and behaves differently. When adding a node, it will first check if there is another shorter node being the beginning of the to-be-inserted node, and if so, won't insert. It also checks if there are existing longer nodes which begin with the newly inserted node, and deletes them.\n\nA new function is added `values()` which returns `Array< Array< T > >`, i.e. an array of all nodes (and again, each node is an array of `T`).\n\n\n## Versions\n\n * Since v2 this is a [pure ESM][pure-esm] package, and requires Node.js >=12.20. It cannot be used from CommonJS.\n * Since v3 requires Node.js >= 14.13.1.\n\n\n# Algorithm\n\n\nWhen inserting `[ 'a', 'b', 'c', 'd' ]`, **one** node is inserted with this value.\n\nInserting  `[ 'x', 'y' ]`, will insert **one** new node.\n\nIf later, `[ 'a', 'b', 'c', 'd', 'e' ]` is inserted, it won't be - there's already a \"shorter\" version of this node (the first one inserted).\n\nIf later, `[ 'a', 'b' ]` is inserted, the first node `[ 'a', 'b', 'c', 'd' ]` will be removed (or \"chopped off\" after `b`).\n\n\n# API\n\nConstruct a `ShortTree` by giving the comparison function for `T`.\n\nIf `T` is `number` e.g., this could be `(a, b) => a - b`.\n\n\n## Order\n\nThe order when traversing the values is going to depend on the comparison function provided to the constructor.\n\nE.g. a traditional `(a: string, b: string) => a.localeCompare(b)` will ensure an order for your current locale. You can use `Intl` to define string comparison orders for other situations.\n\nIf the *human friendly* order isn't that important, but speed is critical, use [`fast-string-compare`][fast-string-compare-npm-url].\n\n\n## Example\n\n```ts\nimport { compare } from 'fast-string-compare'\nimport { ShortTree } from 'short-tree'\n\n// T is deduced to {string}\nconst tree = new ShortTree( compare );\n\ntree.insert( [ 'a', 'b', 'c', 'd' ] );\ntree.insert( [ 'x', 'y' ] );\n// This will \"chop off\" (i.e. remove) [ 'a', 'b', 'c', 'd' ]\ntree.insert( [ 'a', 'b' ] );\n\ntree.values( ); // [ [ 'a', 'b' ], [ 'x', 'y' ] ]\n```\n\n\n[npm-image]: https://img.shields.io/npm/v/short-tree.svg\n[npm-url]: https://npmjs.org/package/short-tree\n[downloads-image]: https://img.shields.io/npm/dm/short-tree.svg\n[build-image]: https://img.shields.io/github/actions/workflow/status/grantila/short-tree/master.yml?branch=master\n[build-url]: https://github.com/grantila/short-tree/actions?query=workflow%3AMaster\n[coverage-image]: https://coveralls.io/repos/github/grantila/short-tree/badge.svg?branch=master\n[coverage-url]: https://coveralls.io/github/grantila/short-tree?branch=master\n[node-version]: https://img.shields.io/node/v/short-tree\n[node-url]: https://nodejs.org/en/\n\n[bintrees-npm-url]: https://npmjs.org/package/bintrees\n[fast-string-compare-npm-url]: https://npmjs.org/package/fast-string-compare\n[pure-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n","_attachments":{},"homepage":"https://github.com/grantila/short-tree#readme","bugs":{"url":"https://github.com/grantila/short-tree/issues"},"license":"MIT"}