demotivator
Version:
A TypeScript library containing 500+ hand-curated insults organized into themed packs, along with utilities to generate, search, and transform them.
232 lines • 7.17 kB
JavaScript
/**
* @license
* Copyright 2024, PorkyProductions, and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { insults, profaneInsults, halloweenInsults, christmasInsults, valentinesInsults, stPatricksInsults, insultPacks, insultPackList } from './insults';
import generateInsult, { insultAt, searchInsults } from './generateinsult';
import { purify, packInfo, porkify, makeAngry } from './texttools';
export { insults, profaneInsults, halloweenInsults, christmasInsults, valentinesInsults, stPatricksInsults, insultPacks, insultPackList, generateInsult, insultAt, searchInsults, purify, packInfo, porkify, makeAngry };
/**
* createArray is a new function introduced in version 12 that creates a custom insult array based on a configuration you provide.
* @param {CreateArrayConfig} configuration an object with the `packs` field containing insult pack IDs.
* @since 12.0.0
* @see CreateArrayConfig
* @returns {Insult[]} an array of insults
*/
export const createArray = (configuration) => {
const selectedPackKeys = new Set(configuration.packs);
const selectedInsults = [];
for (const selectedPackKey of selectedPackKeys) {
const selectedPack = insultPacks[selectedPackKey];
if (!selectedPack) {
continue;
}
selectedInsults.push(...selectedPack.insults);
}
if (configuration.customPacks) {
const seenKeys = new Set();
for (const cp of configuration.customPacks) {
if (!seenKeys.has(cp.key)) {
seenKeys.add(cp.key);
selectedInsults.push(...cp.insults);
}
}
}
return selectedInsults;
};
/**
* An identity-function helper for defining a custom insult pack with full TypeScript inference.
* @param pack The custom pack object to define.
* @returns The same pack object, typed as `InsultPack`.
* @since 13.0.0
*/
export const defineCustomPack = (pack) => pack;
/**
* The main deMotivator object.
* Contains all the functions and properties of the deMotivator.
* @date 6/15/2023 - 11:37:58 AM
* @export
* @type {__DeMotivator}
*/
export const deMotivator = {
insults: insults,
profaneInsults: profaneInsults,
halloweenInsults: halloweenInsults,
christmasInsults: christmasInsults,
valentinesInsults: valentinesInsults,
stPatricksInsults: stPatricksInsults,
insultPacks: insultPacks,
insultPackList: insultPackList,
createArray: createArray,
defineCustomPack: defineCustomPack,
generateInsult: generateInsult,
insultAt: insultAt,
searchInsults: searchInsults,
purify: purify,
packInfo: packInfo,
porkify: porkify,
makeAngry: makeAngry
};
export default deMotivator;
/**
* A class version of the `deMotivator` object
* @see deMotivator
* @export
* @class DeMotivator
* @implements {__DeMotivator}
*/
export class DeMotivator {
/**
* The entire insults array
* @date 6/15/2023 - 11:39:04 AM
*
* @type {Insult[]}
*/
insults = insults;
/**
* All the profane insults
* @date 6/15/2023 - 11:39:04 AM
*
* @type {Insult[]}
*/
profaneInsults = profaneInsults;
/**
* All the Halloween insults
* @date 2/23/2026 - 11:19:35 PM
*/
halloweenInsults = halloweenInsults;
/**
* All the Christmas insults
* @date 2/23/2026 - 11:41:23 PM
*/
christmasInsults = christmasInsults;
/**
* All the Valentine's Day insults
* @date 3/14/2026
*/
valentinesInsults = valentinesInsults;
/**
* All the St. Patrick's Day insults
* @date 3/16/2026
*/
stPatricksInsults = stPatricksInsults;
/**
* A map of all available insult packs by key.
* @date 2/19/2026
*
* @type {InsultPackMap}
*/
insultPacks = insultPacks;
/**
* A list of all available insult packs.
* @date 2/19/2026
*
* @type {InsultPack[]}
*/
insultPackList = insultPackList;
/**
* Creates a basic array of insults.
* @date 6/15/2023 - 11:39:04 AM
* @internal
* @private
* @returns {Insult[]}
*/
__createBasicArray() {
return createArray({ packs: ['original'] });
}
/**
* Creates a custom insult array based on a configuration you provide.
* @date 6/15/2023 - 11:39:04 AM
* @external
* @public
* @param {CreateArrayConfig} configuration
* @returns {Insult[]}
*/
createArray(configuration) {
return createArray(configuration);
}
/**
* Returns its argument typed as `InsultPack`. An identity helper for TypeScript inference.
* @public
* @param {InsultPack} pack
* @returns {InsultPack}
*/
defineCustomPack(pack) {
return defineCustomPack(pack);
}
/**
* Grabs a random insult from the insults array.
* @date 6/15/2023 - 11:39:04 AM
*
* @public
* @param {Insult[]} [array=this.__createBasicArray()]
* @returns {Insult}
*/
generateInsult(array = this.__createBasicArray()) {
return generateInsult(array);
}
/**
* Gets an insult at a specific position in the insults array.
* @date 6/15/2023 - 11:39:04 AM
*
* @public
* @param {number} position
* @param {Insult[]} [array=this.__createBasicArray()]
* @returns {Insult}
*/
insultAt(position, array = this.__createBasicArray()) {
return insultAt(position, array);
}
searchInsults(term, array = this.__createBasicArray(), withPosition = false) {
return searchInsults(term, array, withPosition);
}
/**
* Masks profane words in an insult using a selected replacement symbol.
* @param {Insult} insult
* @param {string} [symbol='*']
* @returns {Insult}
*/
purify(insult, symbol = '*') {
return purify(insult, symbol);
}
packInfo(input, array = this.__createBasicArray()) {
if (typeof input === 'string') {
return packInfo(input);
}
if (typeof input === 'number') {
return packInfo(input, array);
}
return packInfo(input, array);
}
/**
* Inserts the word "Porky" into random positions in an insult.
* @param {Insult} insult
* @param {number} [amount=1]
* @returns {Insult}
*/
porkify(insult, amount = 1) {
return porkify(insult, amount);
}
/**
* Uppercases an insult, strips trailing punctuation, and appends exclamation marks.
* @param {Insult} insult
* @param {number} [exclamationCount=3]
* @returns {Insult}
*/
makeAngry(insult, exclamationCount = 3) {
return makeAngry(insult, exclamationCount);
}
}
//# sourceMappingURL=index.js.map