1.1.0 • Published 1 year ago

suggestion-machine v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.

License

MIT

1.1.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago