UNPKG

complimentr

Version:
434 lines (422 loc) 10.6 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { generateCompliment: () => generateCompliment }); module.exports = __toCommonJS(index_exports); // src/data/sentence-templates.ts var sentenceTemplates = [ "{adjective}", "{adverb} {adjective}", "You're doing {adjective}", "Oh my gosh, that was {adjective}", "Oh my gosh, that was {adverb} {adjective}", "{adjective} quality", "So {adjective}", "So {adverb} {adjective}", "How {adjective}", "How {adverb} {adjective}", "Who knew anyone could be so {adjective}", "Who knew anyone could be so {adverb} {adjective}", "You are a {adjective} {noun}", "You are a {adverb} {adjective} {noun}", "That was {adjective}", "That was {adverb} {adjective}", "how {adjective}", "how {adverb} {adjective}", "That was so {adverb} {adjective}, I am {emotion}", "That was so {adjective}, I am {emotion}", "You are the {noun}", "You are such a {noun}", "You are such a {adjective} {noun}", "You are such a {adverb} {adjective} {noun}", "How {adjective}, you are a {noun}", "How {adverb} {adjective}, you are a {noun}", "I feel {emotion}", "I feel {adverb} {emotion}", "Hey! I hope you know that you're {adverb} {adjective}. A real {noun}", "Hey! I hope you know that you're {adjective}. A real {adjective} {noun}", "Hey! I hope you know that you're {adjective}. A real {adverb} {adjective} {noun}", "You {noun}", "You {adjective} {noun}", "You {adverb} {adjective} {noun}", "I just had to let you know that you're {adjective}", "I just had to let you know that you're {adverb} {adjective}", "{adjective}, {adjective}, {adjective}" ]; // src/data/nouns.ts var nouns = [ "winner", "champion", "go-getter", "master", "cool guy", "pro", "hot item", "hit", "virtuoso", "wizard", "chart-buster", "champ", "victor", "hero", "conqueror", "emperor", "top dog", "good person", "unicorn", "comrade", "champ", "delight", "dream", "dynamo", "enthusiast", "expert", "favourite", "genius", "gift", "glamour", "grace", "jackpot", "knockout", "phenom", "sparkle", "talent", "treasure", "MVP" ]; // src/data/adjectives.ts var adjectives = [ "great", "amazing", "fantastic", "brilliant", "memorable", "incredible", "fanciful", "astonishing", "dreamy", "engaging", "exhilarating", "skillful", "masterful", "life-affirming", "quality", "talented", "wonderful", "admirable", "accomplished", "authentic", "astonishing", "adorable", "beaming", "breathtaking", "capable", "charming", "committed", "confident", "courageous", "creative", "dazzling", "dedicated", "dependable", "dignified", "disciplined", "divine", "dreamy", "dynamite", "earnest", "effective", "efficient", "effortless", "elegant", "eminent", "endearing", "enjoyable", "enthusiastic", "epic", "esteemed", "euphoric", "excellent", "exceptional", "experienced", "exquisite", "exuberant", "fabulous", "famous", "fascinating", "fearless", "fierce", "flawless", "fortunate", "fresh", "fulfilling", "fun", "funny", "generous", "genuine", "gifted", "glamorous", "absolute", "gorgeous", "handsome", "hardworking", "harmonious", "helpful", "honourable", "idyllic", "imaginative", "immaculate", "impeccable", "impressive", "incomparable", "indispensable", "inspirational", "inspiring", "irresistible", "kind", "kind-hearted", "knightly", "knowledgeable", "legendary", "lucky", "magical", "majestic", "marvelous", "mighty", "motivated", "natural", "noble", "optimum", "opulent", "outstanding", "positive", "passionate", "perfect", "phenomenal", "powerful", "premium", "prodigious", "qualified", "radiant", "resilient", "restorative", "sensational", "sharp", "sophisticated", "sparkly", "stunning", "superb", "tenacious", "timeless", "triumphant", "trustworthy", "unbeatable", "unbelievable", "unforgettable", "unstoppable", "valiant", "virtuous", "wholesome", "wise", "worthy", "zesty" ]; // src/data/adverbs.ts var adverbs = [ "flippin'", "superbly", "incredibly", "awesomely", "admirably", "impeccably", "flawlessly", "exquisitely", "supremely", "wonderfully", "absolutely", "stunningly", "amazingly", "unbelievably", "unforgettably", "fantastically", "brilliantly", "memorably", "astonishingly", "engagingly", "masterfully", "authentically", "adorably", "breathtakingly", "capably", "confidently", "courageously", "dazzlingly", "dependably", "divinely", "earnestly", "elegantly", "eminently", "endearingly", "enjoyably", "enthusiastically", "epically", "excellently", "exceptionally", "exuberantly", "fabulously", "famously", "fascinatingly", "fearlessly", "fortunately", "generously", "genuinely", "immaculately", "impeccably", "impressively", "incomparably", "irresistibly", "knowledgeably", "legendarily", "magically", "marvelously", "naturally", "outstandingly", "positively", "perfectly", "powerfully", "prodigiously", "radiantly", "sensationally", "triumphantly", "virtuously", "wholesomely", "wisely" ]; // src/data/emotions.ts var emotions = [ "euphoric", "exhilarated", "joyful", "overjoyed", "happy", "ecstatic", "elated", "delighted", "festive", "gladsome", "satisfied", "pleased", "overjoyed", "enraptured" ]; // src/data/emojis.ts var emojis = [ "\u{1F389}", "\u2764\uFE0F", "\u{1F973}", "\u{1F381}", "\u{1F382}", "\u{1F984}", "\u2728", "\u{1F970}", "\u{1F44F}", "\u{1F31F}", "\u{1F308}", "\u{1FAF6}", "\u{1F60E}", "\u270C\uFE0F", "\u{1F33B}", "\u{1F396}\uFE0F" ]; // src/utils/array-utils.ts var randomChoice = (array) => { const index = Math.floor(Math.random() * array.length); return array[index]; }; // src/utils/filters.ts var byLength = (a, b) => b.length - a.length; // src/utils/template-string-utils.ts var replaceAllOfType = (template, toReplace, candidates) => { let updatedTemplate = template; while (updatedTemplate.includes(toReplace)) { const replacement = randomChoice(candidates); updatedTemplate = updatedTemplate.replace(toReplace, replacement); } return updatedTemplate; }; var addFinalPunctuation = (template, candidates, weight) => { const toAppend = randomChoice(candidates); return Math.random() < weight ? `${template} ${toAppend}` : `${template}!`; }; var filterTemplatesOnMaxLength = (templates, maxLength, inputs) => { const applicableTemplates = maxLength === void 0 ? templates : templates.filter((t) => templateMaxLength(t, inputs) <= maxLength); if (applicableTemplates.length === 0) throw new RangeError("No applicable templates found for given maxLength."); return applicableTemplates; }; var updateIndefiniteArticles = (template) => { return template.replace(/ a ([aeiou])/g, " an $1").replace(/^a ([aeiou])/g, "an $1").replace(/ A ([aeiou])/g, " An $1").replace(/^A ([aeiou])/g, "An $1"); }; var templateMaxLength = (template, inputs) => { const longestNoun = inputs.nouns.sort(byLength)[0]; const longestAdjective = inputs.adjectives.sort(byLength)[0]; const longestQualifier = inputs.adverbs.sort(byLength)[0]; const longestEmotion = inputs.emotions.sort(byLength)[0]; const longestEmoji = inputs.emojiWeight <= 0 ? "!" : " \u{1F60E}"; let longestVersionOfTemplate = replaceAllOfType(template, "{noun}", [longestNoun]); longestVersionOfTemplate = replaceAllOfType(longestVersionOfTemplate, "{adjective}", [longestAdjective]); longestVersionOfTemplate = replaceAllOfType(longestVersionOfTemplate, "{adverb}", [longestQualifier]); longestVersionOfTemplate = replaceAllOfType(longestVersionOfTemplate, "{emotion}", [longestEmotion]); longestVersionOfTemplate = `${longestVersionOfTemplate}${longestEmoji}`; return longestVersionOfTemplate.length; }; var capitaliseFirstLetter = (template) => { return `${template[0].toUpperCase()}${template.slice(1)}`; }; var fillTemplate = (template, inputs) => { const withNouns = replaceAllOfType(template, "{noun}", inputs.nouns); const withAdjectives = replaceAllOfType(withNouns, "{adjective}", inputs.adjectives); const withQualifiers = replaceAllOfType(withAdjectives, "{adverb}", inputs.adverbs); const withEmotions = replaceAllOfType(withQualifiers, "{emotion}", inputs.emotions); const withFinalPunctuation = addFinalPunctuation(withEmotions, inputs.emojis, inputs.emojiWeight ?? 0.5); const withCapitalisedFirstLetter = capitaliseFirstLetter(withFinalPunctuation); const withUpdatedArticles = updateIndefiniteArticles(withCapitalisedFirstLetter); return withUpdatedArticles; }; // src/index.ts var generateCompliment = (options = {}) => { const allTemplates = [...options.templates ?? sentenceTemplates, ...options.additionalTemplates ?? []]; const inputs = { nouns: [...options.nouns ?? nouns, ...options.additionalNouns ?? []], adjectives: [...options.adjectives ?? adjectives, ...options.additionalAdjectives ?? []], adverbs: [...options.adverbs ?? adverbs, ...options.additionalQualifiers ?? []], emotions: [...options.emotions ?? emotions, ...options.additionalEmotions ?? []], emojis: [...options.emojis ?? emojis, ...options.additionalEmojis ?? []], emojiWeight: options.emojiWeight ?? 0.5 }; const applicableTemplates = filterTemplatesOnMaxLength(allTemplates, options.maxLength, inputs); const chosenTemplate = randomChoice(applicableTemplates); const filledTemplate = fillTemplate(chosenTemplate, inputs); return filledTemplate; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { generateCompliment });