trieste
Trie generator.
Installation
NPM:
$ npm install trieste --save
Yarn:
$ yarn add trieste
CDN:
Usage
Module
Import the module:
// CommonJSconst trieste = ; // ES Modules;
Trie
Create a trie instance:
const trie = ;
This can also be done by instantiating the constructor:
const Trie = ;const trie = ;
Options
Options can be set for each instance:
const options = endKey: 'END_OF_STRING_KEY' endValue: 'END_OF_STRING_VALUE';const trie = ;
This can also be achieved with the constructor:
const Trie = ; const trie = endKey: 'END_OF_STRING_KEY' endValue: 'END_OF_STRING_VALUE';
Options are found on the instance's options
property:
trieoptions;
The default options are:
endKey: '$$' endValue: 1
Options have a direct effect on the trie's data and methods like add and get.
Data
Data can be found on the instance's data
property:
triedata;
Data is a POJO (Plain Old JavaScript Object), which means it can be converted to JSON:
JSON;
As an example, the following is the output of trieste().add('a').data
:
a: '$$': 1
Methods
Add
Add a string to the trie:
trie;
Add multiple strings to the trie:
trie;
Add an array of strings to the trie:
trieadd;
Add a string with a value to the trie:
trie;
This is useful if you want to store value(s) other than the default. See method get on how to retrieve a string value.
Since the method returns its own instance, method chaining is possible:
trie;
Arguments that are not type string
will be skipped.
Contains
Check if a string is found in the trie:
trie;
The method returns a boolean
value.
Arguments that are not type string
will return false
.
Get
Get a string value from the trie:
trie;
The value comes from options.endValue
, which is 1
by default:
trie; // 1
The value can be set using the add method:
trie; // 'bar'
The value can also be set in options:
const trie = ;trie; // null
Arguments that are not type string
will return undefined
.
Remove
Remove a string from the trie:
trie;
Remove multiple strings from the trie:
trie;
Remove an array of strings from the trie:
trieremove;
Since the method returns its own instance, method chaining is possible:
trie;
Arguments that are not type string
will be skipped.
Testing
Run tests:
$ npm test
Run tests in watch mode:
$ npm run test:watch
Run tests with coverage:
$ npm run test:coverage
View coverage in browser:
$ npm run test:coverage:report$ open coverage/index.html
Lint files:
$ npm run lint
Fix lint errors:
$ npm run lint:fix
Release
Only collaborators with credentials can release and publish:
$ npm run release$ git push --follow-tags && npm publish