Package Exports
- dictionary-trie
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dictionary-trie) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Dictionary Trie
Create and efficiently search a dictionary of words.
Installation
npm:
npm install --save dictionary-trie
yarn:
yarn add dictionary-trie
Usage
Create your dictionary by importing the createDictionary
function.
import createDictionary from 'dictionary-trie'
const words = [
'rat', 'rate', 'music', 'musician', 'flower', 'flow', 'data', 'water',
'wait', 'rain', 'rainer', 'rained', 'raining', 'couch', 'room'
]
const dictionary = createDictionary(words)
You can use this dictionary to determine whether a word is included. Note this is not a partial match.
dictionary.includes('music') // => true
dictionary.includes('rat') // => true
dictionary.includes('rats') // => false
If you would like to partially match and return possiblity, use the search
function.
dictionary.search('ra') // => ['rat', 'rate', 'rain', 'rainer', 'rained', 'raining']
dictionary.search('rai') // => ['rain', 'rainer', 'rained', 'raining']
dictionary.search('rain') // => ['rain', 'rainer', 'rained', 'raining']
dictionary.search('raine') // => ['rainer', 'rained']
dictionary.search('rained') // => ['rained']
dictionary.search('couches') // => []
License
MIT