1.1.0 • Published 1 year ago
suggestion-machine v1.1.0
suggestion-machine
Spits out suggestions from a sequence of values.
Installation
npm install suggestion-machine
Usage
import SuggestionMachine from 'suggestion-machine';
// Start with an array to serve as the seed values.
// In the below example we split a string into an array of words.
const tokens = 'the greatest example text ever written by the greatest person.'.split(' ');
// Create a new tree
const machine = new SuggestionMachine(tokens);
// Returns either 'example' or 'person', randomly
machine.suggestFor(['the', 'greatest']);
// Returns ['example', 'person']
machine.getAllSuggestionsFor(['the', 'greatest']);
// Returns ['ever', 'written', 'by', 'the']
machine.suggestSequenceFor(['example', 'text'], 4);
// Returns 'written'
machine.suggestFor(['ever']);
// Serialize as JSON string
const stringified = machine.toJSONString();
// De-serialize
const deStringified = SuggestionMachine.parseJSON(stringified);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.