/stringtree-js

StringTree in NodeJS

Primary LanguageJavaScriptBSD Zero Clause License0BSD

stringtree

Build Status Coverage Status NPM version

stringtree is a package to enable fast, forward only parsing of text, partial matches, typeahead search, and other functionality by building a prefix tree or trie from a set of key/value pairs.

Installation

npm install stringtree-js

Examples

const { StringTree } = require('stringtree')

var st = new StringTree()

// Loading The Tree
st.set('relief',10)
st.set('sentence',20)
st.set('expect',20)
st.set('fisherman',30)
st.set('avenue',40)
st.set('path',50)
st.set('expected',60)
st.set('expectation',70)

// Simple Search
console.log('fisherman',st.get('fisherman'))
// > fisherman 30

// Prefix Search (typeahead)
console.log('fish',st.prefix('fish'))
console.log('exp',st.prefix('exp'))
// > fish { fisherman: 30 }
// > exp { expect: 20, expected: 60, expectation: 70 }