friendly-word-slug
Version:
Generate a friendly slug
37 lines • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.words = void 0;
const lodash_1 = require("lodash");
const words_1 = require("./words");
function words(n, type) {
function generateRandomWord() {
return words_1.default[randInt(words_1.default.length)];
}
function randInt(lessThan) {
return Math.floor(Math.random() * lessThan);
}
if (typeof n === "number" && typeof type === "string") {
let slug = "";
for (let i = 0; i < n; i++) {
slug = slug + " " + generateRandomWord();
}
switch (type) {
case "camelCase":
return lodash_1.camelCase(slug);
case "kebabCase":
return lodash_1.kebabCase(slug);
case "snakeCase":
return lodash_1.snakeCase(slug);
default:
throw new Error(`Incompatible type provided.
Acceptable Types: "camelCase" | "kebabCase" | "snakeCase"`);
}
}
if (n === undefined) {
//base functionality
return generateRandomWord();
}
throw new Error("Incorrect Function Usage");
}
exports.words = words;
//# sourceMappingURL=index.js.map