short-tree
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ShortTree = void 0; | ||
const bintrees_1 = require("bintrees"); | ||
import { RBTree } from 'bintrees'; | ||
function makeArrayCompare(cmp) { | ||
@@ -31,3 +28,3 @@ return function (a, b) { | ||
} | ||
class ShortTree extends bintrees_1.RBTree { | ||
export class ShortTree extends RBTree { | ||
constructor(cmp, arrayCmp = makeArrayCompare(cmp)) { | ||
@@ -78,2 +75,1 @@ super(arrayCmp); | ||
} | ||
exports.ShortTree = ShortTree; |
{ | ||
"name": "short-tree", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Keep a tree trimmed from longer-than-necessary branches", | ||
@@ -11,7 +11,9 @@ "author": "Gustaf Räntilä", | ||
"homepage": "https://github.com/grantila/short-tree#readme", | ||
"exports": "./dist/index.js", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"directories": {}, | ||
"type": "module", | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=12" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -23,3 +25,3 @@ "files": [ | ||
"build": "rimraf dist && tsc -p tsconfig.prod.json", | ||
"test": "jest --coverage", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest --coverage", | ||
"cz": "git-cz" | ||
@@ -37,9 +39,10 @@ }, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.31", | ||
"@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": "^26.6.3", | ||
"jest": "^27.1.1", | ||
"rimraf": "^3.0.1", | ||
"ts-jest": "^26.5.2", | ||
"typescript": "^4.2.2" | ||
"typescript": "^4.4.3" | ||
}, | ||
@@ -54,3 +57,11 @@ "config": { | ||
"bintrees": "^1.0.2" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"coverageReporters": [ | ||
"lcov", | ||
"text", | ||
"html" | ||
] | ||
} | ||
} |
@@ -20,2 +20,7 @@ [![npm version][npm-image]][npm-url] | ||
## Versions | ||
* Since v2 this is a [pure ESM][pure-esm] package, and requires Node.js >=12.20. It cannot be used from CommonJS. | ||
# Algorithm | ||
@@ -40,9 +45,19 @@ | ||
## Order | ||
The order when traversing the values is going to depend on the comparison function provided to the constructor. | ||
E.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. | ||
If the *human friendly* order isn't that important, but speed is critical, use [`fast-string-compare`][fast-string-compare-npm-url]. | ||
## Example | ||
```ts | ||
import { compare } from 'fast-string-compare' | ||
import { ShortTree } from 'short-tree' | ||
// T is deduced to {string} | ||
const tree = new ShortTree( ( a: string, b: string ) => a.localeCompare( b ) ); | ||
const tree = new ShortTree( compare ); | ||
@@ -71,1 +86,3 @@ tree.insert( [ 'a', 'b', 'c', 'd' ] ); | ||
[bintrees-npm-url]: https://npmjs.org/package/bintrees | ||
[fast-string-compare-npm-url]: https://npmjs.org/package/fast-string-compare | ||
[pure-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c |
8494
86
Yes
8
84