0.2.0 • Published 4 years ago

stringtree-js v0.2.0

Weekly downloads
2
License
0BSD
Repository
github
Last release
4 years ago

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 }