fiction-word
Version:
A random word generator.
45 lines (44 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeParagraph = exports.makeSentence = void 0;
var fiction_word_1 = require("./fiction-word");
var tools_1 = require("./tools");
var word_length_1 = require("./word-length");
/**
* @description Generates a sentence with a given length or a normally distributed number.
* @param length - The given length of the sentence in words.
* @returns The generated sentence.
*/
var makeSentence = function (options) {
var length = typeof options === "number" ? options : options === null || options === void 0 ? void 0 : options.length;
var distribution = (typeof options === "object" && options.wordDistribution) ||
(0, word_length_1.generateDistribution)("corpus");
var bottom = (0, tools_1.budgeByOdds)(15, 10, "down");
var top = (0, tools_1.budgeByOdds)(20, 10, "up");
length = Math.max(1, length || (0, tools_1.range)(bottom, top));
var sentence = "".concat((0, tools_1.capitalizeFirstLetter)((0, fiction_word_1.makeWord)({ distribution: distribution })), " ");
for (var i = 1; i < length; i++) {
sentence += "".concat((0, fiction_word_1.makeWord)({ distribution: distribution }), " ");
}
return "".concat(sentence.trim(), ".");
};
exports.makeSentence = makeSentence;
/**
* @description Generates a paragraph with a given length or a normally distributed number.
* @param length - The given length of the paragraph in sentences.
* @returns The generated paragraph.
*/
var makeParagraph = function (options) {
var length = typeof options === "number" ? options : options === null || options === void 0 ? void 0 : options.length;
var wordDistribution = (typeof options === "object" && options.wordDistribution) ||
(0, word_length_1.generateDistribution)("corpus");
var bottom = (0, tools_1.budgeByOdds)(2, 5, "down");
var top = (0, tools_1.budgeByOdds)(6, 10, "up");
length = Math.max(1, length || (0, tools_1.range)(bottom, top));
var paragraph = "";
for (var i = 0; i < length; i++) {
paragraph += "".concat((0, exports.makeSentence)({ wordDistribution: wordDistribution }), " ");
}
return paragraph.trim();
};
exports.makeParagraph = makeParagraph;