1.0.0 • Published 8 years ago
sentence-builder v1.0.0
Sentence Builder
Build a sentence with variability
let sentence = [
['Hello', 'Hi'],
['World!', 'Earth!']
];
sentenceBuilder.build(sentence);
// Hi World!
sentenceBuilder.combos(sentence);
// ['Hello World!', 'Hi World!', 'Hello Earth!', 'Hi Earth!']Installation
- Install the package:
npm install --save sentence-builder- Require it in your project:
const sentenceBuilder = require('sentence-builder');Usage
build()
Build a sentence:
let sentence = [
['Hello', 'Hi'],
['World!', 'Earth!']
];
sentenceBuilder.build(sentence);
// Hi World!All methods take a second parameter, exclude, which can be given as a single string or an array of strings.
sentenceBuilder.build(sentence, 'Hi World!');
// Hi Earth!Pass true as a third parameter to get output as an array.
sentenceBuilder.build(sentence, null, true);
// ['Hi', 'World!']combos()
Effectively returns the Cartesian product.
sentenceBuilder.combos(sentence);
// ['Hello World!', 'Hi World!', 'Hello Earth!', 'Hi Earth!']Also takes the exclude parameter.
sentenceBuilder.combos(sentence, ['Hi World!', 'Hello Earth!']);
// ['Hello World!', 'Hi Earth!']Takes a third parameter, limit, which limits the results.
sentenceBuilder.combos(sentence, null, 3);
// ['Hello World!', 'Hi World!', 'Hello Earth!']numCombos()
Returns the number of possible combinations.
sentenceBuilder.numCombos(sentence);
// 4
sentenceBuilder.numCombos(sentence, 'Hi World!');
// 31.0.0
8 years ago