UNPKG

@jharrilim/madlibs

Version:

randomized madlibs templating engine

31 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const map_weave_1 = require("./map-weave"); const nouns = ['dude', 'cat', 'apple', 'car', 'lamp', 'pidgeon']; const verbsEndingInIng = ['walking', 'talking', 'barking', 'eating', 'sniffing', 'coughing']; const adjectives = ['purple', 'humongous', 'flappy', 'whimsical', 'opaque', 'stinky']; const randItem = (arr) => arr[Math.floor(Math.random() * arr.length)]; class MadLibs { constructor(tagLookup = { noun: nouns, verb: verbsEndingInIng, adjective: adjectives }) { this.tagLookup = tagLookup; } get randomLibs() { return map_weave_1.mapWeave(t => randItem(this.tagLookup[t])); } get compile() { const tagCount = {}; const replacer = (t) => { tagCount[t] = typeof tagCount[t] !== 'undefined' ? ++tagCount[t] : 0; return this.tagLookup[t][tagCount[t]]; }; return map_weave_1.mapWeave(replacer); } ; } exports.MadLibs = MadLibs; exports.default = MadLibs; //# sourceMappingURL=index.js.map