|
@@ -5,8 +5,10 @@
|
|
|
* @author mightyplow
|
|
|
*/
|
|
|
|
|
|
-const DEFAULT_MIN_WORDS_PER_SENTENCE = 3;
|
|
|
-const DEFAULT_MAX_WORDS_PER_SENTENCE = 9;
|
|
|
+const defaultOptions = {
|
|
|
+ minWords: 3,
|
|
|
+ maxWords: 9
|
|
|
+};
|
|
|
|
|
|
const availableWords = [
|
|
|
'post', 'emensos', 'insuperabilis', 'expeditionis', 'eventus', 'languentibus',
|
|
@@ -101,7 +103,7 @@ function getRandomArrayValue (source) {
|
|
|
const getRandomPunctuationMark = getRandomArrayValue.bind(null, punctuationMarks);
|
|
|
const getRandomWord = getRandomArrayValue.bind(null, availableWords);
|
|
|
|
|
|
-function createSentence (minWords = DEFAULT_MIN_WORDS_PER_SENTENCE, maxWords = DEFAULT_MAX_WORDS_PER_SENTENCE) {
|
|
|
+function createSentence ({ minWords, maxWords }) {
|
|
|
const numWords = randomInt(minWords, maxWords);
|
|
|
const sentenceWords = [];
|
|
|
|
|
@@ -132,16 +134,17 @@ const UnitFunction = {
|
|
|
[Unit.WORD]: getRandomWord
|
|
|
};
|
|
|
|
|
|
-function createText (num, unit = Unit.WORD) {
|
|
|
+function createText (num, unit = Unit.WORD, options) {
|
|
|
if (!UnitFunction.hasOwnProperty(unit)) {
|
|
|
throw Error('Invalid unit parameter');
|
|
|
}
|
|
|
|
|
|
+ const creatorOptions = Object.assign({}, options, defaultOptions);
|
|
|
const unitCreator = UnitFunction[unit];
|
|
|
const texts = [];
|
|
|
|
|
|
for (let i = 0; i < num; i += 1) {
|
|
|
- texts.push(unitCreator());
|
|
|
+ texts.push(unitCreator(creatorOptions));
|
|
|
}
|
|
|
|
|
|
return texts.join(' ');
|