colorless-green-ipsum
Version:
A philosophical nonsense text generator inspired by Chomsky's famous sentence
512 lines (508 loc) • 14 kB
JavaScript
"use strict";
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);
// pkg/index.ts
var index_exports = {};
__export(index_exports, {
ColorlessGreenIpsumGenerator: () => ColorlessGreenIpsumGenerator,
default: () => index_default
});
module.exports = __toCommonJS(index_exports);
// pkg/generator.ts
var ColorlessGreenIpsumGenerator = class {
constructor(initialStyle = "erudite") {
// Style-specific word banks
this.styleWordBanks = {
common: {
adjectives: [
"colorless",
"green",
"abstract",
"invisible",
"dormant",
"transparent",
"conceptual",
"intangible",
"fragmented",
"synthetic",
"quiet",
"hollow",
"vague",
"undefined",
"theoretical",
"complex",
"virtual",
"potential",
"symbolic"
],
nouns: [
"ideas",
"concepts",
"notions",
"theories",
"thoughts",
"abstractions",
"principles",
"constructs",
"hypotheses",
"frameworks",
"methods",
"systems",
"structures",
"functions"
],
adverbs: [
"silently",
"rapidly",
"gradually",
"peacefully",
"quietly",
"slowly",
"clearly",
"barely",
"simply",
"directly",
"suddenly",
"plainly",
"easily",
"nearly",
"basically",
"practically"
],
verbs: [
"sleep",
"move",
"shift",
"change",
"appear",
"remain",
"develop",
"continue",
"exist",
"persist",
"evolve",
"emerge",
"grow",
"form",
"dissolve",
"expand",
"shrink"
],
conjunctions: [
"while",
"although",
"yet",
"and",
"but",
"however",
"meanwhile",
"therefore",
"besides",
"still",
"then"
]
},
erudite: {
adjectives: [
"epistemological",
"ontological",
"phenomenological",
"hermeneutic",
"dialectical",
"teleological",
"metaphysical",
"transcendental",
"existential",
"apophatic",
"axiomatic",
"liminal",
"ineffable",
"solipsistic",
"quiescent",
"noumenal",
"categorical",
"heuristic",
"apodictic",
"antinomical",
"hegelian",
"aristotelian",
"kantian"
],
nouns: [
"qualia",
"phenomena",
"antinomies",
"dichotomies",
"aporia",
"axioms",
"monads",
"syllogisms",
"heuristics",
"noumena",
"isomorphisms",
"ontologies",
"epistemologies",
"teleologies",
"dialectics",
"hermeneutics",
"propositions",
"quiddities",
"essences",
"entelechy",
"teleologies",
"nomologies"
],
adverbs: [
"ontologically",
"dialectically",
"teleologically",
"axiomatically",
"phenomenologically",
"hermeneutically",
"epistemologically",
"apodictically",
"heuristically",
"categorically",
"ineffably",
"noumenally",
"antinomically",
"solipsistically",
"quiescently",
"a priori",
"a posteriori",
"sui generis",
"ipso facto"
],
verbs: [
"reify",
"dialectize",
"instantiate",
"substantiate",
"subsume",
"interpenetrate",
"particularize",
"universalize",
"contextualize",
"problematize",
"delineate",
"presuppose",
"systematize",
"essentialize",
"deterritorialize",
"actualize",
"ontologize",
"phenomenologize",
"disembed",
"deconstruct",
"synthesize"
],
conjunctions: [
"nevertheless",
"notwithstanding",
"consequently",
"conversely",
"ergo",
"henceforth",
"wherefore",
"qua",
"insofar as",
"vis-\xE0-vis",
"a fortiori",
"mutatis mutandis",
"ceteris paribus",
"ex hypothesi",
"pace",
"per se"
]
},
whimsical: {
adjectives: [
"fluffy",
"bouncy",
"twirling",
"dancing",
"giggling",
"bubbling",
"sparkling",
"silly",
"zigzagging",
"floating",
"wobbling",
"topsy-turvy",
"squiggly",
"loopy",
"upside-down",
"inside-out",
"ticklish",
"wiggly",
"whirling",
"buzzing",
"fizzy",
"squishy"
],
nouns: [
"daydreams",
"giggles",
"whispers",
"bubbles",
"rainbows",
"clouds",
"sparkles",
"noodles",
"kittens",
"hiccups",
"snowflakes",
"tidbits",
"doodles",
"wiggles",
"sprinkles",
"butterflies",
"cupcakes",
"twinkles",
"ponies",
"confetti"
],
adverbs: [
"gleefully",
"merrily",
"playfully",
"cheerfully",
"joyfully",
"whimsically",
"topsy-turvily",
"helter-skelter",
"willy-nilly",
"higgledy-piggledy",
"dizzily",
"twirly",
"bubbly",
"bouncily",
"squiggly",
"giggly",
"wiggly",
"wobblily",
"floatingly"
],
verbs: [
"frolic",
"dance",
"twirl",
"bounce",
"flutter",
"giggle",
"bubble",
"wiggle",
"whoosh",
"zoom",
"shimmer",
"sparkle",
"whirl",
"swirl",
"tumble",
"jiggle",
"hiccup",
"tiptoe",
"cartwheel",
"hopscotch",
"pirouette",
"somersault",
"skip"
],
conjunctions: [
"wibble",
"meanwhile",
"topsy-turvily",
"in a jiffy",
"lo and behold",
"believe it or not",
"by the way",
"before you can say 'abracadabra'",
"in a flash",
"ta-da",
"whoosh",
"surprise surprise",
"hooray"
]
}
};
// Array to keep track of available styles
this.availableStyles = ["common", "erudite", "whimsical"];
// Current style
this.style = "erudite";
this.style = initialStyle;
}
// Get all available styles
getAvailableStyles() {
return [...this.availableStyles];
}
// Method to add a new custom style
addCustomStyle(styleName, wordBank) {
if (this.availableStyles.includes(styleName)) {
return false;
}
const baseStyle = this.styleWordBanks["erudite"];
this.styleWordBanks[styleName] = {
adjectives: wordBank.adjectives || [...baseStyle.adjectives],
nouns: wordBank.nouns || [...baseStyle.nouns],
adverbs: wordBank.adverbs || [...baseStyle.adverbs],
verbs: wordBank.verbs || [...baseStyle.verbs],
conjunctions: wordBank.conjunctions || [...baseStyle.conjunctions]
};
this.availableStyles.push(styleName);
return true;
}
// Method to remove a custom style
removeCustomStyle(styleName) {
if (["common", "erudite", "whimsical"].includes(styleName)) {
return false;
}
if (!this.availableStyles.includes(styleName)) {
return false;
}
if (this.style === styleName) {
this.style = "erudite";
}
delete this.styleWordBanks[styleName];
this.availableStyles = this.availableStyles.filter(
(s) => s !== styleName
);
return true;
}
// Get current word banks based on style
get currentWordBank() {
return this.styleWordBanks[this.style] || this.styleWordBanks["erudite"];
}
// Individual word bank getters
get adjectives() {
return this.currentWordBank.adjectives;
}
get nouns() {
return this.currentWordBank.nouns;
}
get adverbs() {
return this.currentWordBank.adverbs;
}
get verbs() {
return this.currentWordBank.verbs;
}
get conjunctions() {
return this.currentWordBank.conjunctions;
}
// Method to change the style
setStyle(style) {
if (this.availableStyles.includes(style)) {
this.style = style;
return true;
}
return false;
}
// Get current style
getStyle() {
return this.style;
}
getRandomElement(array) {
return array[Math.floor(Math.random() * array.length)];
}
capitalizeFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
generateSentence() {
const patterns = [
// Colorless green ideas sleep furiously pattern
() => {
const adj1 = this.getRandomElement(this.adjectives);
const adj2 = this.getRandomElement(
this.adjectives.filter((a) => a !== adj1)
);
const noun = this.getRandomElement(this.nouns);
const verb = this.getRandomElement(this.verbs);
const adverb = this.getRandomElement(this.adverbs);
return `${this.capitalizeFirstLetter(adj1)} ${adj2} ${noun} ${verb} ${adverb}.`;
},
// Alternative pattern with conjunction
() => {
const adj1 = this.getRandomElement(this.adjectives);
const noun1 = this.getRandomElement(this.nouns);
const verb1 = this.getRandomElement(this.verbs);
const conjunction = this.getRandomElement(this.conjunctions);
const adj2 = this.getRandomElement(this.adjectives);
const noun2 = this.getRandomElement(this.nouns);
const verb2 = this.getRandomElement(this.verbs);
const adverb = this.getRandomElement(this.adverbs);
return `${this.capitalizeFirstLetter(adj1)} ${noun1} ${verb1}, ${conjunction} ${adj2} ${noun2} ${verb2} ${adverb}.`;
},
// Inverted adverb pattern
() => {
const adverb = this.getRandomElement(this.adverbs);
const adj = this.getRandomElement(this.adjectives);
const noun = this.getRandomElement(this.nouns);
const verb = this.getRandomElement(this.verbs);
return `${this.capitalizeFirstLetter(adverb)}, ${adj} ${noun} ${verb}.`;
},
// Philosophical predication pattern
() => {
const adj = this.getRandomElement(this.adjectives);
const noun1 = this.getRandomElement(this.nouns);
const verb = this.getRandomElement(this.verbs);
const noun2 = this.getRandomElement(
this.nouns.filter((n) => n !== noun1)
);
return `${this.capitalizeFirstLetter(adj)} ${noun1} ${verb} the ${noun2} of being.`;
},
// Nested abstractions pattern
() => {
const adj1 = this.getRandomElement(this.adjectives);
const adj2 = this.getRandomElement(
this.adjectives.filter((a) => a !== adj1)
);
const noun1 = this.getRandomElement(this.nouns);
const noun2 = this.getRandomElement(
this.nouns.filter((n) => n !== noun1)
);
const verb = this.getRandomElement(this.verbs);
return `${this.capitalizeFirstLetter(adj1)} ${noun1} of ${adj2} ${noun2} ${verb} intrinsically.`;
}
];
return this.getRandomElement(patterns)();
}
generateParagraph(sentenceCount = 5) {
const sentences = [];
for (let i = 0; i < sentenceCount; i++) {
sentences.push(this.generateSentence());
}
return sentences.join(" ");
}
generateIpsum(paragraphCount = 3, sentencesPerParagraph = 5) {
const paragraphs = [];
for (let i = 0; i < paragraphCount; i++) {
paragraphs.push(this.generateParagraph(sentencesPerParagraph));
}
return paragraphs.join("\n\n");
}
// Alias method to match the name used in the README example
generate(paragraphCount = 3, sentencesPerParagraph = 5) {
return this.generateIpsum(paragraphCount, sentencesPerParagraph);
}
};
// pkg/index.ts
var defaultGenerator = new ColorlessGreenIpsumGenerator();
var index_default = {
generate: (paragraphs = 3, sentencesPerParagraph = 4) => defaultGenerator.generateIpsum(paragraphs, sentencesPerParagraph),
generateParagraph: (sentences = 4) => defaultGenerator.generateParagraph(sentences),
generateSentence: () => defaultGenerator.generateSentence()
};