mr-case 🤓
mr-case is a powerful and lightweight JavaScript utility library for case conversion, string formatting, and text manipulation. It provides a rich set of 55 functions to seamlessly transform strings, arrays, and object keys between different cases (camelCase, snake_case, kebab-case, PascalCase, Title Case, and more), clean and format text, extract URL components, and perform common text operations like masking, obfuscation, and abbreviation.
Whether you're dealing with API responses, filenames, database fields, SEO-friendly slugs, or user-generated content, mr-case makes string manipulation effortless and efficient.
📦 Installation
Install via npm
npm i mr-caseUsage
const mrCase = require('mr-case');
console.log(mrCase.toCamel('hello_world')); // "helloWorld"
console.log(mrCase.generateSlug('My Blog Post!')); // "my-blog-post"API Reference (55 Functions)
Core Case Conversions
toCamel(str: string): string→ Convertsunderscore_casetocamelCase."hello_world"→"helloWorld"
toSnake(str: string): string→ ConvertscamelCasetounderscore_case."helloWorld"→"hello_world"
toPascal(str: string): string→ Convertssnake_caseorcamelCasetoPascalCase."hello_world"→"HelloWorld"
toKebab(str: string): string→ Convertssnake_caseorcamelCasetokebab-case."hello_world"→"hello-world"
toTitle(str: string): string→ Converts any case to Title Case."hello world"→"Hello World"
arrToCamel(arr: string[]): string[]→ Converts an array ofunderscore_casestrings tocamelCase.arrToSnake(arr: string[]): string[]→ Converts an array ofcamelCasestrings tounderscore_case.arrToPascal(arr: string[]): string[]→ Converts an array of strings toPascalCase.arrToKebab(arr: string[]): string[]→ Converts an array of strings tokebab-case.detectCase(str: string): "camel" | "snake" | "pascal" | "kebab" | "title" | "other"→ Detects the case format of a string.
Object Key Conversions
keysToCamel(obj: object): object→ Converts object keys fromsnake_casetocamelCase.keysToSnake(obj: object): object→ Converts object keys fromcamelCasetounderscore_case.keysToPascal(obj: object): object→ Converts all object keys toPascalCase.keysToKebab(obj: object): object→ Converts all object keys tokebab-case.deepCamel(obj: object): object→ Converts all nested object keys tocamelCase.deepSnake(obj: object): object→ Converts all nested object keys tosnake_case.deepPascal(obj: object): object→ Converts all nested object keys toPascalCase.deepKebab(obj: object): object→ Converts all nested object keys tokebab-case.autoConvert(str: string, target: "camel" | "snake" | "pascal" | "kebab" | "title"): string→ Converts text to a specified format.isCamel(str: string): boolean→ Checks if a string is incamelCase.
Text Formatting & Cleaning
isSnake(str: string): boolean→ Checks if a string is insnake_case.capitalize(str: string): string→ Capitalizes the first letter.decapitalize(str: string): string→ Converts the first letter to lowercase.capitalizeWords(str: string): string→ Capitalizes the first letter of every word.decapitalizeWords(str: string): string→ Lowercases the first letter of every word.swapCase(str: string): string→ Swaps case of each letter.sentenceCase(str: string): string→ Converts text to sentence case.randomCase(str: string): string→ Randomly capitalizes letters.removeExtraSpaces(str: string): string→ Trims and removes extra spaces.removeSpecialChars(str: string): string→ Removes non-alphanumeric characters (except spaces).
Full-Text Case Conversion
textToCamel(text: string): string→ Converts sentences/paragraphs tocamelCase.textToSnake(text: string): string→ Converts sentences/paragraphs tosnake_case.textToKebab(text: string): string→ Converts sentences/paragraphs tokebab-case.textToPascal(text: string): string→ Converts sentences/paragraphs toPascalCase.camelToText(str: string): string→ ConvertscamelCaseback to a readable sentence.snakeToText(str: string): string→ Convertssnake_caseback to a readable sentence.kebabToText(str: string): string→ Convertskebab-caseback to a readable sentence.pascalToText(str: string): string→ ConvertsPascalCaseback to a readable sentence.reverseWords(str: string): string→ Reverses word order.reverseString(str: string): string→ Reverses the string.
SEO, Validation & Text Processing
generateSlug(str: string): string→ Converts a string into an SEO-friendly slug.extractDomain(url: string): string→ Extracts domain from a URL.extractPath(url: string): string→ Extracts the path from a URL.isPalindrome(str: string): boolean→ Checks if a string is a palindrome.isAnagram(str1: string, str2: string): boolean→ Checks if two words are anagrams.removeNumbers(str: string): string→ Removes digits from a string.keepOnlyNumbers(str: string): string→ Removes everything except numbers.truncate3dots(str: string, length: number): string→ Truncates text with"..."if it exceeds length.shortenText(str: string, limit: number): string→ Shortens text without cutting mid-word.replaceSeparator(str: string, from: string, to: string): string→ Replaces a separator in a string.
Security & Privacy
abbreviate(text: string): string→ Converts"Machine Learning"to"ML".initials(name: string): string→ Gets initials from a name ("John Doe"→"J.D.").obfuscateEmail(email: string): string→ Hides part of an email address.maskString(str: string, visible: number): string→ Masks a string while keeping first & last few characters.shortenText(str: string, limit: number): string→ Keeps words within the limit instead of cutting mid-word.