All files / lib FriendlyPhrase.js

94.29% Statements 33/35
89.47% Branches 17/19
100% Functions 8/8
96.77% Lines 30/31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72  2x 2x   2x 2x 2x 2x 2x                   23x 23x 23x 23x 23x 22x   23x 22x     1x       2x   4x   2x   2x   2x         2x 22x           2x 23x           2x 23x           2x 68x 68x    
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var seed_random_1 = __importDefault(require("seed-random"));
var adjectives_1 = require("./words/adjectives");
var animals_1 = require("./words/animals");
var colors_1 = require("./words/colors");
/**
 * @Method: Returns a three-word passphrase with a separator string
 * between each word - order is adjective-color-animal
 * @param {string} [sep = ' '] - The separator charatcter
 * @param {string} [prevent = ''] - a matching string used
 * to prevent (very unlikely) duplicate results
 * @returns {string}
 */
function phrase(sep, prevent, short) {
    if (sep === void 0) { sep = ' '; }
    if (prevent === void 0) { prevent = ''; }
    if (short === void 0) { short = false; }
    var result = "" + color() + sep + animal();
    if (!short) {
        result = "" + adjective() + sep + result;
    }
    if (result !== prevent) {
        return String(result);
    }
    else {
        return phrase(sep, prevent);
    }
    throw new Error('shut up, compiler');
}
exports.phrase = phrase;
function setSeed(seedString) {
    seed_random_1.default(seedString, { global: true });
}
exports.setSeed = setSeed;
function resetSeed() {
    seed_random_1.default.resetGlobal();
}
exports.resetSeed = resetSeed;
/**
 * @Method: Returns a random adjective from the words list.
 * @returns {string}
 */
var adjective = function () {
    return adjectives_1.adjectives[random(adjectives_1.adjectives.length)];
};
/**
 * @Method: Returns a random color from the words list.
 * @returns {string}
 */
var color = function () {
    return colors_1.colors[random(colors_1.colors.length)];
};
/**
 * @Method: Returns a random animal from the words list.
 * @returns {string}
 */
var animal = function () {
    return animals_1.animals[random(animals_1.animals.length)];
};
/**
 * @Method: Returns a random number between 0 and max
 * @returns {number}
 */
var random = function (max) {
    Iif (max === void 0) { max = 1; }
    return Math.floor(Math.random() * max);
};
//# sourceMappingURL=FriendlyPhrase.js.map