New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

trie-prefix-tree

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trie-prefix-tree - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

2

package.json
{
"name": "trie-prefix-tree",
"version": "1.2.0",
"version": "1.3.0",
"description": "Create and modify trie prefix structures, extract word lists including anagrams and sub-anagrams",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -62,6 +62,6 @@ # Trie Prefix Tree

```
```javascript
var trie = require('trie-prefix-tree');
// es6
// using ES2015 Modules
import trie from 'trie-prefix-tree';

@@ -72,38 +72,65 @@ ```

```javascript
var myTrie = trie(['cat', 'cats', 'dogs', 'elephant', 'tiger']);
```
var myTrie = trie(['cat', 'cats', 'dogs', 'elephant', 'tiger'];
```
Trie options:
Trie functionality:
```javascript
// retrieve a stringified dump of the Trie object
myTrie.dump(); // { c: { a: { t: $: 1 }, s: 1 ... }}
// optionally pass in spacer parameter to format the output string
myTrie.dump(2); // equivalent of JSON.stringify(obj, null, 2);
```
// retrive a dump of the Trie object
myTrie.dump();
```javascript
// add a new word to the Trie
myTrie.addWord('lion');
```
```javascript
// remove an existing word from the Trie
myTrie.removeWord('dogs');
```
Adding and removing words can be chained:
```javascript
myTrie.addWord('hello').removeWord('hello');
```
```javascript
// check if a prefix exists:
myTrie.isPrefix('do'); // true
myTrie.isPrefix('z'); // false
```
```javascript
// count prefixes
myTrie.countPrefix('c'); // 2
```
```javascript
// get an array of words with the passed in prefix
myTrie.getPrefix('c'); // ['cat', 'cats']
```
```javascript
// retrieve a full list of words in the Trie
myTrie.getWords(); // ['cat', 'cats', 'elephant', 'lion', 'tiger'];
```
```javascript
// check if a word exists in the Trie
myTrie.hasword('elephant'); // true
myTrie.hasWord('zoo'); // false
```
```javascript
// generate a list of valid anagrams from the given letters
myTrie.getAnagrams('act'); // ['cat'];
```
```javascript
// generate a list of valid sub-anagrams from the given letters

@@ -110,0 +137,0 @@ myTrie.getSubAnagrams('ctalion'); ['cat', 'cats', 'lion'];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc