mr-case
v1.0.2
Published
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 mas
Downloads
214
Maintainers
Keywords
Readme
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-case
Usage
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_case
tocamelCase
."hello_world"
→"helloWorld"
toSnake(str: string): string
→ ConvertscamelCase
tounderscore_case
."helloWorld"
→"hello_world"
toPascal(str: string): string
→ Convertssnake_case
orcamelCase
toPascalCase
."hello_world"
→"HelloWorld"
toKebab(str: string): string
→ Convertssnake_case
orcamelCase
tokebab-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_case
strings tocamelCase
.arrToSnake(arr: string[]): string[]
→ Converts an array ofcamelCase
strings 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_case
tocamelCase
.keysToSnake(obj: object): object
→ Converts object keys fromcamelCase
tounderscore_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
→ ConvertscamelCase
back to a readable sentence.snakeToText(str: string): string
→ Convertssnake_case
back to a readable sentence.kebabToText(str: string): string
→ Convertskebab-case
back to a readable sentence.pascalToText(str: string): string
→ ConvertsPascalCase
back 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.