UNPKG

casetext-transformer

Version:

The ultimate text transformation library with 40+ transformations - from standard case conversions to creative text effects

559 lines (490 loc) โ€ข 17.1 kB
function toCamelCase(word) { return word.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) { return index === 0 ? word.toLowerCase() : word.toUpperCase(); }).replace(/\s+/g, ''); } function toSnakeCase(word) { return word.replace(/([A-Z])/g, '_$1').toLowerCase(); } function toKebabCase(word) { return word.replace(/([A-Z])/g, '-$1').toLowerCase(); } function toPascalCase(word) { return word.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word) { return word.toUpperCase(); }).replace(/\s+/g, ''); } function toTitleCase(word) { return word.replace(/\b\w/g, function(word) { return word.toUpperCase(); }); } function toSentenceCase(word) { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); } function toConstantCase(word) { return word.toUpperCase().replace(/\s+/g, '_'); } function toDotCase(word) { return word.replace(/([A-Z])/g, '.$1').toLowerCase(); } function toPathCase(word) { return word.replace(/([A-Z])/g, '/$1').toLowerCase(); } function toHeaderCase(word) { return toTitleCase(word).replace(/\s+/g, '-'); } function toSlugCase(word) { return word.toLowerCase().replace(/\s+/g, '-'); } // Fun and creative transformations /** * Alternating uppercase and lowercase letters (Mocking SpongeBob meme style) */ function toMockingCase(word) { return word.split('').map((char, index) => index % 2 === 0 ? char.toLowerCase() : char.toUpperCase() ).join(''); } /** * Convert text to UwU speak */ function toUwuCase(word) { return word .replace(/[lr]/g, 'w') .replace(/[LR]/g, 'W') .replace(/n([aeiou])/g, 'ny$1') .replace(/N([AEIOU])/g, 'NY$1') .replace(/ove/g, 'uv') .replace(/(\.|\?|!)$/g, ' uwu$1'); } /** * Convert text to full-width aesthetic vaporwave text */ function toVaporwaveCase(word) { return word.split('').map(char => { const code = char.charCodeAt(0); // Basic ASCII if (code >= 33 && code <= 126) { return String.fromCharCode(code + 0xFEE0); // Shift to full-width } // Space if (code === 32) { return 'ใ€€'; // Full-width space } return char; }).join(''); } /** * Convert text to 1337 (leet) speak */ function toLeetCase(word) { const leetMap = { 'a': '4', 'e': '3', 'i': '1', 'o': '0', 's': '5', 't': '7', 'b': '8', 'g': '9', 'l': '1', 'z': '2' }; return word.toLowerCase().split('').map(char => leetMap[char] || char ).join(''); } /** * Reverse the text */ function toBackwardsCase(word) { return word.split('').reverse().join(''); } /** * Add stutters to the first letter of each word */ function toStutterCase(word) { return word.replace(/\b(\w)/g, '$1-$1-$1'); } /** * Randomly apply upper or lowercase to each letter */ function toRandomCase(word) { return word.split('').map(char => Math.random() > 0.5 ? char.toUpperCase() : char.toLowerCase() ).join(''); } /** * Add "zalgo" text effect (corrupted/glitchy looking text) */ function toZalgoCase(word) { const zalgoUp = [ '\u030d', '\u030e', '\u0304', '\u0305', '\u033f', '\u0311', '\u0306', '\u0310', '\u0352', '\u0357', '\u0351', '\u0307', '\u0308', '\u030a', '\u0342' ]; const zalgoMid = [ '\u0315', '\u031b', '\u0340', '\u0341', '\u0358', '\u0321', '\u0322', '\u0327', '\u0328', '\u0334', '\u0335', '\u0336', '\u034f', '\u035c', '\u035d' ]; const zalgoDown = [ '\u0316', '\u0317', '\u0318', '\u0319', '\u031c', '\u031d', '\u031e', '\u031f', '\u0320', '\u0324', '\u0325', '\u0326', '\u0329', '\u032a', '\u032b' ]; return word.split('').map(char => { let result = char; // Add random zalgo marks const intensity = 3; // Adjustable intensity for (let i = 0; i < Math.floor(Math.random() * intensity); i++) { result += zalgoUp[Math.floor(Math.random() * zalgoUp.length)]; } for (let i = 0; i < Math.floor(Math.random() * intensity); i++) { result += zalgoMid[Math.floor(Math.random() * zalgoMid.length)]; } for (let i = 0; i < Math.floor(Math.random() * intensity); i++) { result += zalgoDown[Math.floor(Math.random() * zalgoDown.length)]; } return result; }).join(''); } /** * Convert text to Morse code */ function toMorseCode(word) { const morseCodeMap = { 'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', 'q': '--.-', 'r': '.-.', 's': '...', 't': '-', 'u': '..-', 'v': '...-', 'w': '.--', 'x': '-..-', 'y': '-.--', 'z': '--..', '0': '-----', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..', '9': '----.', '.': '.-.-.-', ',': '--..--', '?': '..--..', "'": '.----.', '!': '-.-.--', '/': '-..-.', '(': '-.--.', ')': '-.--.-', '&': '.-...', ':': '---...', ';': '-.-.-.', '=': '-...-', '+': '.-.-.', '-': '-....-', '_': '..--.-', '"': '.-..-.', '$': '...-..-', '@': '.--.-.' }; return word.toLowerCase().split('').map(char => { if (char === ' ') return ' '; // 3 spaces between words return morseCodeMap[char] || char; }).join(' '); } /** * Convert text to binary representation */ function toBinaryCase(word) { return word.split('').map(char => char.charCodeAt(0).toString(2).padStart(8, '0') ).join(' '); } /** * Convert text to Pig Latin */ function toPigLatinCase(word) { return word.replace(/\b([aeiou]\w*)\b/gi, '$1way') .replace(/\b([bcdfghjklmnpqrstvwxyz]+)(\w*)\b/gi, '$2$1ay'); } /** * Replace characters with censorship symbols */ function toRedactedCase(word) { return word.replace(/[a-zA-Z0-9]/g, 'โ–ˆ'); } /** * Add clap emoji between each word */ function toClapsCase(word) { return word.replace(/\s+/g, ' ๐Ÿ‘ '); } /** * Convert to hashtag style */ function toHashtagCase(word) { return word.replace(/\b(\w+)\b/g, '#$1'); } /** * Minify text by removing all spaces */ function toMinifyCase(word) { return word.replace(/\s+/g, '').toLowerCase(); } /** * Simple Caesar cipher encryption (ROT13) */ function toROT13Case(word) { return word.replace(/[a-zA-Z]/g, function(char) { const code = char.charCodeAt(0); if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) { const base = code <= 90 ? 65 : 97; return String.fromCharCode(((code - base + 13) % 26) + base); } return char; }); } /** * Convert to small caps using Unicode small capital letters */ function toSmallCapsCase(word) { const smallCapsMap = { 'a': 'แด€', 'b': 'ส™', 'c': 'แด„', 'd': 'แด…', 'e': 'แด‡', 'f': '๊œฐ', 'g': 'ษข', 'h': 'สœ', 'i': 'ษช', 'j': 'แดŠ', 'k': 'แด‹', 'l': 'สŸ', 'm': 'แด', 'n': 'ษด', 'o': 'แด', 'p': 'แด˜', 'q': 'วซ', 'r': 'ส€', 's': 's', 't': 'แด›', 'u': 'แดœ', 'v': 'แด ', 'w': 'แดก', 'x': 'x', 'y': 'ส', 'z': 'แดข' }; return word.replace(/([a-z])/g, char => smallCapsMap[char] || char); } /** * Add spaces between characters */ function toStretchedCase(word) { return word.split('').join(' '); } /** * Format text as a JSON string */ function toJSONCase(word) { return JSON.stringify({ text: word }); } /** * Replace characters with similar-looking alternatives */ function toAlternateCase(word) { const alternateMap = { 'a': 'ฮฑ', 'b': 'ะฒ', 'c': 'ฯฒ', 'd': 'ิ', 'e': 'ะต', 'i': 'ั–', 'j': 'ั˜', 'k': 'ะบ', 'l': 'ำ', 'm': 'ะผ', 'n': 'ีธ', 'o': 'ะพ', 'p': 'ั€', 's': 'ั•', 't': 'ั‚', 'u': 'ฯ…', 'v': 'ฮฝ', 'w': 'ัก', 'x': 'ั…', 'y': 'ัƒ', 'z': 'แดข' }; return word.replace(/([a-z])/gi, function(char) { const lowercase = char.toLowerCase(); if (alternateMap[lowercase]) { return char === lowercase ? alternateMap[lowercase] : alternateMap[lowercase].toUpperCase(); } return char; }); } /** * Convert text to "old English" style */ function toOldEnglishCase(word) { return word .replace(/th/g, 'รพ') .replace(/Th/g, 'รž') .replace(/TH/g, 'รž') .replace(/wh/g, 'ฦฟh') .replace(/Wh/g, 'วทh') .replace(/WH/g, 'ฦฟH') .replace(/w/g, 'ฦฟ') .replace(/W/g, 'วท') .replace(/and/g, '&') .replace(/AND/g, '&') .replace(/you/g, 'thou') .replace(/You/g, 'Thou') .replace(/YOUR/g, 'THOU') .replace(/your/g, 'thy') .replace(/Your/g, 'Thy') .replace(/YOUR/g, 'THY') .replace(/are/g, 'art') .replace(/Are/g, 'Art') .replace(/ARE/g, 'ART') .replace(/is/g, 'ist') .replace(/Is/g, 'Ist') .replace(/IS/g, 'IST'); } /** * Convert text to emojis based on key words */ function toEmojifyCase(word) { const emojiMap = { 'happy': ' ๐Ÿ˜„', 'sad': ' ๐Ÿ˜ข', 'love': ' โค๏ธ', 'heart': ' โค๏ธ', 'laugh': ' ๐Ÿ˜‚', 'eye': ' ๐Ÿ‘๏ธ', 'eyes': ' ๐Ÿ‘€', 'smile': ' ๐Ÿ˜Š', 'cool': ' ๐Ÿ˜Ž', 'fire': ' ๐Ÿ”ฅ', 'hot': ' ๐Ÿ”ฅ', 'star': ' โญ', 'money': ' ๐Ÿ’ฐ', 'cat': ' ๐Ÿฑ', 'dog': ' ๐Ÿถ', 'mouse': ' ๐Ÿญ', 'cow': ' ๐Ÿฎ', 'rabbit': ' ๐Ÿฐ', 'bear': ' ๐Ÿป', 'panda': ' ๐Ÿผ', 'fox': ' ๐ŸฆŠ', 'tiger': ' ๐Ÿฏ', 'lion': ' ๐Ÿฆ', 'horse': ' ๐Ÿด', 'unicorn': ' ๐Ÿฆ„', 'pig': ' ๐Ÿท', 'frog': ' ๐Ÿธ', 'monkey': ' ๐Ÿต', 'chicken': ' ๐Ÿ”', 'penguin': ' ๐Ÿง', 'bird': ' ๐Ÿฆ', 'baby': ' ๐Ÿ‘ถ', 'man': ' ๐Ÿ‘จ', 'woman': ' ๐Ÿ‘ฉ', 'boy': ' ๐Ÿ‘ฆ', 'girl': ' ๐Ÿ‘ง', 'clap': ' ๐Ÿ‘', 'hands': ' ๐Ÿ‘', 'handshake': ' ๐Ÿค', 'thumbs': ' ๐Ÿ‘', 'punch': ' ๐Ÿ‘Š', 'fist': ' โœŠ', 'finger': ' ๐Ÿ‘†', 'hand': ' โœ‹', 'sun': ' โ˜€๏ธ', 'moon': ' ๐ŸŒ™', 'star': ' โญ', 'cloud': ' โ˜๏ธ', 'umbrella': ' โ˜‚๏ธ', 'rain': ' ๐ŸŒง๏ธ', 'snow': ' โ„๏ธ', 'winter': ' โ›„', 'time': ' โŒš', 'clock': ' ๐Ÿ•ฐ๏ธ', 'gift': ' ๐ŸŽ', 'birthday': ' ๐ŸŽ‚', 'party': ' ๐ŸŽ‰', 'christmas': ' ๐ŸŽ„', 'rocket': ' ๐Ÿš€', 'car': ' ๐Ÿš—', 'bike': ' ๐Ÿšฒ', 'plane': ' โœˆ๏ธ', 'ship': ' ๐Ÿšข', 'house': ' ๐Ÿ ', 'building': ' ๐Ÿข', 'school': ' ๐Ÿซ', 'hotel': ' ๐Ÿจ', 'hospital': ' ๐Ÿฅ', 'food': ' ๐Ÿ”', 'pizza': ' ๐Ÿ•', 'hamburger': ' ๐Ÿ”', 'taco': ' ๐ŸŒฎ', 'burrito': ' ๐ŸŒฏ', 'pasta': ' ๐Ÿ', 'popcorn': ' ๐Ÿฟ', 'cake': ' ๐Ÿฐ', 'coffee': ' โ˜•', 'tea': ' ๐Ÿต', 'beer': ' ๐Ÿบ', 'wine': ' ๐Ÿท', 'dog': ' ๐Ÿถ', 'cat': ' ๐Ÿฑ', 'mouse': ' ๐Ÿญ', 'hamster': ' ๐Ÿน', 'bunny': ' ๐Ÿฐ', 'fox': ' ๐ŸฆŠ', 'bear': ' ๐Ÿป', 'panda': ' ๐Ÿผ', 'chicken': ' ๐Ÿ”', 'penguin': ' ๐Ÿง', 'frog': ' ๐Ÿธ', 'monkey': ' ๐Ÿต', 'book': ' ๐Ÿ“š', 'computer': ' ๐Ÿ’ป', 'phone': ' ๐Ÿ“ฑ', 'mail': ' ๐Ÿ“ง', 'music': ' ๐ŸŽต', 'game': ' ๐ŸŽฎ', 'sport': ' โšฝ', 'football': ' ๐Ÿˆ', 'baseball': ' โšพ', 'basketball': ' ๐Ÿ€', 'tennis': ' ๐ŸŽพ', 'rugby': ' ๐Ÿ‰' }; // Case-insensitive replacement for each word in the dictionary Object.keys(emojiMap).forEach(key => { const regex = new RegExp(`\\b${key}\\b`, 'gi'); word = word.replace(regex, match => match + emojiMap[key.toLowerCase()]); }); return word; } /** * Add sparkles around the text โœจ */ function toSparklesCase(word) { return `โœจ ${word} โœจ`; } /** * Create ASCII art blocks with text (box drawing) */ function toBoxedCase(word) { const lines = word.split('\n'); const maxLength = Math.max(...lines.map(line => line.length)); const top = `โ”Œ${'โ”€'.repeat(maxLength + 2)}โ”`; const bottom = `โ””${'โ”€'.repeat(maxLength + 2)}โ”˜`; const paddedLines = lines.map(line => `โ”‚ ${line}${' '.repeat(maxLength - line.length)} โ”‚` ); return `${top}\n${paddedLines.join('\n')}\n${bottom}`; } /** * Mirror text using special Unicode characters */ function toMirrorCase(word) { const mirrorMap = { 'a': 'ษ', 'b': 'q', 'c': 'ษ”', 'd': 'p', 'e': 'ว', 'f': 'ษŸ', 'g': 'ฦƒ', 'h': 'ษฅ', 'i': 'แด‰', 'j': 'ษพ', 'k': 'สž', 'l': 'l', 'm': 'ษฏ', 'n': 'u', 'o': 'o', 'p': 'd', 'q': 'b', 'r': 'ษน', 's': 's', 't': 'ส‡', 'u': 'n', 'v': 'สŒ', 'w': 'ส', 'x': 'x', 'y': 'สŽ', 'z': 'z', 'A': 'โˆ€', 'B': 'B', 'C': 'ฦ†', 'D': 'D', 'E': 'ฦŽ', 'F': 'โ„ฒ', 'G': 'ืค', 'H': 'H', 'I': 'I', 'J': 'ลฟ', 'K': 'สž', 'L': 'หฅ', 'M': 'W', 'N': 'N', 'O': 'O', 'P': 'ิ€', 'Q': 'Q', 'R': 'R', 'S': 'S', 'T': 'โ”ด', 'U': 'โˆฉ', 'V': 'ฮ›', 'W': 'M', 'X': 'X', 'Y': 'โ…„', 'Z': 'Z', '0': '0', '1': 'ฦ–', '2': 'แ„…', '3': 'ฦ', '4': 'ใ„ฃ', '5': 'ฯ›', '6': '9', '7': 'ใ„ฅ', '8': '8', '9': '6', '.': 'ห™', ',': '\'', '\'': ',', '"': 'โ€ž', '`': ',', '?': 'ยฟ', '!': 'ยก', '(': ')', ')': '(', '[': ']', ']': '[', '{': '}', '}': '{', '<': '>', '>': '<', '&': 'โ…‹', '_': 'โ€พ', '^': 'v' }; return word.split('').map(char => mirrorMap[char] || char ).reverse().join(''); } /** * Convert text to bubble letters using Unicode circled characters */ function toBubbleCase(word) { const bubbleMap = { 'a': 'โ“', 'b': 'โ“‘', 'c': 'โ“’', 'd': 'โ““', 'e': 'โ“”', 'f': 'โ“•', 'g': 'โ“–', 'h': 'โ“—', 'i': 'โ“˜', 'j': 'โ“™', 'k': 'โ“š', 'l': 'โ“›', 'm': 'โ“œ', 'n': 'โ“', 'o': 'โ“ž', 'p': 'โ“Ÿ', 'q': 'โ“ ', 'r': 'โ“ก', 's': 'โ“ข', 't': 'โ“ฃ', 'u': 'โ“ค', 'v': 'โ“ฅ', 'w': 'โ“ฆ', 'x': 'โ“ง', 'y': 'โ“จ', 'z': 'โ“ฉ', 'A': 'โ’ถ', 'B': 'โ’ท', 'C': 'โ’ธ', 'D': 'โ’น', 'E': 'โ’บ', 'F': 'โ’ป', 'G': 'โ’ผ', 'H': 'โ’ฝ', 'I': 'โ’พ', 'J': 'โ’ฟ', 'K': 'โ“€', 'L': 'โ“', 'M': 'โ“‚', 'N': 'โ“ƒ', 'O': 'โ“„', 'P': 'โ“…', 'Q': 'โ“†', 'R': 'โ“‡', 'S': 'โ“ˆ', 'T': 'โ“‰', 'U': 'โ“Š', 'V': 'โ“‹', 'W': 'โ“Œ', 'X': 'โ“', 'Y': 'โ“Ž', 'Z': 'โ“', '0': 'โ“ช', '1': 'โ‘ ', '2': 'โ‘ก', '3': 'โ‘ข', '4': 'โ‘ฃ', '5': 'โ‘ค', '6': 'โ‘ฅ', '7': 'โ‘ฆ', '8': 'โ‘ง', '9': 'โ‘จ' }; return word.split('').map(char => bubbleMap[char] || char ).join(''); } /** * Convert text to base64 encoding */ function toBase64Case(word) { if (typeof btoa === 'function') { return btoa(word); // Browser } else { return Buffer.from(word).toString('base64'); // Node.js } } /** * Convert words to scrambled text while keeping first and last letter intact * Based on the Cambridge University effect */ function toScrambledCase(word) { return word.replace(/\b\w{4,}\b/g, function(word) { const first = word.charAt(0); const last = word.charAt(word.length - 1); const middle = word.substring(1, word.length - 1).split(''); // Shuffle the middle characters for (let i = middle.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [middle[i], middle[j]] = [middle[j], middle[i]]; } return first + middle.join('') + last; }); } /** * Convert text to NATO phonetic alphabet */ function toNATOCase(word) { const natoMap = { 'a': 'Alpha', 'b': 'Bravo', 'c': 'Charlie', 'd': 'Delta', 'e': 'Echo', 'f': 'Foxtrot', 'g': 'Golf', 'h': 'Hotel', 'i': 'India', 'j': 'Juliett', 'k': 'Kilo', 'l': 'Lima', 'm': 'Mike', 'n': 'November', 'o': 'Oscar', 'p': 'Papa', 'q': 'Quebec', 'r': 'Romeo', 's': 'Sierra', 't': 'Tango', 'u': 'Uniform', 'v': 'Victor', 'w': 'Whiskey', 'x': 'X-ray', 'y': 'Yankee', 'z': 'Zulu', '0': 'Zero', '1': 'One', '2': 'Two', '3': 'Three', '4': 'Four', '5': 'Five', '6': 'Six', '7': 'Seven', '8': 'Eight', '9': 'Nine' }; return word.toLowerCase().split('').map(char => natoMap[char] ? natoMap[char] : char ).join(' '); } export { toCamelCase, toSnakeCase, toKebabCase, toPascalCase, toTitleCase, toSentenceCase, toConstantCase, toDotCase, toPathCase, toHeaderCase, toSlugCase, // Fun transformations toMockingCase, toUwuCase, toVaporwaveCase, toLeetCase, toBackwardsCase, toStutterCase, toRandomCase, // Additional transformations toZalgoCase, toMorseCode, toBinaryCase, toPigLatinCase, toRedactedCase, toClapsCase, toHashtagCase, toMinifyCase, toROT13Case, toSmallCapsCase, toStretchedCase, toJSONCase, toAlternateCase, toOldEnglishCase, toEmojifyCase, toSparklesCase, toBoxedCase, toMirrorCase, toBubbleCase, toBase64Case, toScrambledCase, toNATOCase }