Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jerelmiller/dictionary-trie
A dictionary built using trie data structure
https://github.com/jerelmiller/dictionary-trie
algorithm javascript trie
Last synced: 4 days ago
JSON representation
A dictionary built using trie data structure
- Host: GitHub
- URL: https://github.com/jerelmiller/dictionary-trie
- Owner: jerelmiller
- License: mit
- Created: 2017-04-27T02:07:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-29T02:21:21.000Z (over 7 years ago)
- Last Synced: 2024-10-17T15:36:53.129Z (22 days ago)
- Topics: algorithm, javascript, trie
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/dictionary-trie
- Size: 54.7 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/jerelmiller/dictionary-trie.svg?branch=master)](https://travis-ci.org/jerelmiller/dictionary-trie)
# 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.
```javascript
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.
```javascript
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.
```javascript
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