trie-prefix-tree
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -87,2 +87,4 @@ 'use strict'; | ||
getPrefix: function getPrefix(strPrefix) { | ||
var sorted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
if (typeof strPrefix !== 'string' || strPrefix === '') { | ||
@@ -92,2 +94,6 @@ throw 'Expected string prefix, received ' + (typeof strPrefix === 'undefined' ? 'undefined' : _typeof(strPrefix)); | ||
if (typeof sorted !== 'boolean') { | ||
throw 'Expected sort parameter as boolean, received ' + (typeof sorted === 'undefined' ? 'undefined' : _typeof(sorted)); | ||
} | ||
if (!this.isPrefix(strPrefix)) { | ||
@@ -100,3 +106,3 @@ return []; | ||
return (0, _recursePrefix2.default)(prefixNode, strPrefix); | ||
return (0, _recursePrefix2.default)(prefixNode, strPrefix, sorted); | ||
}, | ||
@@ -121,3 +127,8 @@ | ||
getWords: function getWords() { | ||
return (0, _recursePrefix2.default)(trie, ''); | ||
var sorted = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
if (typeof sorted !== 'boolean') { | ||
throw 'Expected sort parameter as boolean, received ' + (typeof sorted === 'undefined' ? 'undefined' : _typeof(sorted)); | ||
} | ||
return (0, _recursePrefix2.default)(trie, '', sorted); | ||
}, | ||
@@ -124,0 +135,0 @@ |
@@ -31,4 +31,4 @@ 'use strict'; | ||
function recursePrefix(node, prefix) { | ||
var prefixes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
function recursePrefix(node, prefix, sorted) { | ||
var prefixes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; | ||
@@ -39,6 +39,10 @@ var word = prefix; | ||
if (branch === _config2.default.END_WORD) { | ||
pushInOrder(word, prefixes); | ||
if (sorted) { | ||
pushInOrder(word, prefixes); | ||
} else { | ||
prefixes.push(word); | ||
} | ||
word = ''; | ||
} | ||
recursePrefix(node[branch], prefix + branch, prefixes); | ||
recursePrefix(node[branch], prefix + branch, sorted, prefixes); | ||
} | ||
@@ -45,0 +49,0 @@ |
{ | ||
"name": "trie-prefix-tree", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Create and modify trie prefix structures, extract word lists including anagrams and sub-anagrams", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
18638
326