Comparing version 1.0.0 to 1.0.1
@@ -51,7 +51,11 @@ /** Node in Trie. */ | ||
delete(path: ReadonlyArray<Key>): void; | ||
/** Clears the trie: remove all nodes from the trie. */ | ||
clear(): void; | ||
/** | ||
* Returns a count of all child nodes (any depth) with non-undefined | ||
* values under the `path` including the node pointed by the path. | ||
* values under the `path` including the node pointed by the path if `mode` is `node-and-children`. | ||
* | ||
* A call with no arguments will return a total count of all values in the trie. | ||
*/ | ||
count(path?: Array<Key>): number; | ||
count(path?: Array<Key>, mode?: 'node-and-children' | 'children-only'): number; | ||
/** Returns true if the trie has no nodes with non-undefined values. */ | ||
@@ -58,0 +62,0 @@ get isEmpty(): boolean; |
@@ -61,9 +61,18 @@ "use strict"; | ||
} | ||
/** Clears the trie: remove all nodes from the trie. */ | ||
clear() { | ||
this.delete([]); | ||
} | ||
/** | ||
* Returns a count of all child nodes (any depth) with non-undefined | ||
* values under the `path` including the node pointed by the path. | ||
* values under the `path` including the node pointed by the path if `mode` is `node-and-children`. | ||
* | ||
* A call with no arguments will return a total count of all values in the trie. | ||
*/ | ||
count(path = []) { | ||
count(path = [], mode = 'node-and-children') { | ||
const node = this.getNode(path); | ||
return node === undefined ? 0 : node.childrenWithValue + (node.value === undefined ? 0 : 1); | ||
if (node === undefined) { | ||
return 0; | ||
} | ||
return node.childrenWithValue + (mode === 'node-and-children' && node.value !== undefined ? 1 : 0); | ||
} | ||
@@ -70,0 +79,0 @@ /** Returns true if the trie has no nodes with non-undefined values. */ |
{ | ||
"name": "ptrie", | ||
"description": "Lightweight Path Trie for TypeScript and JavaScript", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"license": "Apache-2.0", | ||
@@ -16,8 +16,8 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^6.4.0", | ||
"@typescript-eslint/parser": "^6.4.0", | ||
"eslint": "^8.47.0", | ||
"@typescript-eslint/eslint-plugin": "^6.6.0", | ||
"@typescript-eslint/parser": "^6.6.0", | ||
"eslint": "^8.49.0", | ||
"rimraf": "^5.0.1", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.1.6" | ||
"typescript": "^5.2.2" | ||
}, | ||
@@ -24,0 +24,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34347
354