Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mr-case

AnshSinghSonkhia25Apache-2.01.0.2

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

case-conversion, camelcase, camel-case, camel case, case, snake_case, snake-case, snake case, underscore-case, underscore case, kebab-case, kebab, pascalcase, pascal, text, text-formatting, formatting, string-utils, string, util, convert-case, convert case, case-transform, camelizer, camelize, humps, to-camelcase, to-camel-case, underscore-to-camelcase, turndown, file-rename, file-rename-utils, file-rename-utility, file-rename-tool, file-rename-toolkit, rename-files, obfuscation, masking, mask, obfuscate, obfuscator, obfuscation-tool, masking-tool, masking-toolkit, masking-utility, obfuscation-utility, obfuscation-toolkit, abbreviation, abbreviate, abbreviator, abbreviation-tool, abbreviation-toolkit, abbreviation-utility, slug generator, slug, slugify, slugify-text, slugify-string, slugify-tool, slugify-toolkit, slugify-utility, string manipulation, string-manipulation, string-manipulator, string-manipulation-tool, string-manipulation-toolkit, string-manipulation-utility

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.

npm License Downloads

📦 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

  1. toCamel(str: string): string → Converts underscore_case to camelCase.
    • "hello_world""helloWorld"
  2. toSnake(str: string): string → Converts camelCase to underscore_case.
    • "helloWorld""hello_world"
  3. toPascal(str: string): string → Converts snake_case or camelCase to PascalCase.
    • "hello_world""HelloWorld"
  4. toKebab(str: string): string → Converts snake_case or camelCase to kebab-case.
    • "hello_world""hello-world"
  5. toTitle(str: string): string → Converts any case to Title Case.
    • "hello world""Hello World"
  6. arrToCamel(arr: string[]): string[] → Converts an array of underscore_case strings to camelCase.
  7. arrToSnake(arr: string[]): string[] → Converts an array of camelCase strings to underscore_case.
  8. arrToPascal(arr: string[]): string[] → Converts an array of strings to PascalCase.
  9. arrToKebab(arr: string[]): string[] → Converts an array of strings to kebab-case.
  10. detectCase(str: string): "camel" | "snake" | "pascal" | "kebab" | "title" | "other" → Detects the case format of a string.

Object Key Conversions

  1. keysToCamel(obj: object): object → Converts object keys from snake_case to camelCase.
  2. keysToSnake(obj: object): object → Converts object keys from camelCase to underscore_case.
  3. keysToPascal(obj: object): object → Converts all object keys to PascalCase.
  4. keysToKebab(obj: object): object → Converts all object keys to kebab-case.
  5. deepCamel(obj: object): object → Converts all nested object keys to camelCase.
  6. deepSnake(obj: object): object → Converts all nested object keys to snake_case.
  7. deepPascal(obj: object): object → Converts all nested object keys to PascalCase.
  8. deepKebab(obj: object): object → Converts all nested object keys to kebab-case.
  9. autoConvert(str: string, target: "camel" | "snake" | "pascal" | "kebab" | "title"): string → Converts text to a specified format.
  10. isCamel(str: string): boolean → Checks if a string is in camelCase.

Text Formatting & Cleaning

  1. isSnake(str: string): boolean → Checks if a string is in snake_case.
  2. capitalize(str: string): string → Capitalizes the first letter.
  3. decapitalize(str: string): string → Converts the first letter to lowercase.
  4. capitalizeWords(str: string): string → Capitalizes the first letter of every word.
  5. decapitalizeWords(str: string): string → Lowercases the first letter of every word.
  6. swapCase(str: string): string → Swaps case of each letter.
  7. sentenceCase(str: string): string → Converts text to sentence case.
  8. randomCase(str: string): string → Randomly capitalizes letters.
  9. removeExtraSpaces(str: string): string → Trims and removes extra spaces.
  10. removeSpecialChars(str: string): string → Removes non-alphanumeric characters (except spaces).

Full-Text Case Conversion

  1. textToCamel(text: string): string → Converts sentences/paragraphs to camelCase.
  2. textToSnake(text: string): string → Converts sentences/paragraphs to snake_case.
  3. textToKebab(text: string): string → Converts sentences/paragraphs to kebab-case.
  4. textToPascal(text: string): string → Converts sentences/paragraphs to PascalCase.
  5. camelToText(str: string): string → Converts camelCase back to a readable sentence.
  6. snakeToText(str: string): string → Converts snake_case back to a readable sentence.
  7. kebabToText(str: string): string → Converts kebab-case back to a readable sentence.
  8. pascalToText(str: string): string → Converts PascalCase back to a readable sentence.
  9. reverseWords(str: string): string → Reverses word order.
  10. reverseString(str: string): string → Reverses the string.

SEO, Validation & Text Processing

  1. generateSlug(str: string): string → Converts a string into an SEO-friendly slug.
  2. extractDomain(url: string): string → Extracts domain from a URL.
  3. extractPath(url: string): string → Extracts the path from a URL.
  4. isPalindrome(str: string): boolean → Checks if a string is a palindrome.
  5. isAnagram(str1: string, str2: string): boolean → Checks if two words are anagrams.
  6. removeNumbers(str: string): string → Removes digits from a string.
  7. keepOnlyNumbers(str: string): string → Removes everything except numbers.
  8. truncate3dots(str: string, length: number): string → Truncates text with "..." if it exceeds length.
  9. shortenText(str: string, limit: number): string → Shortens text without cutting mid-word.
  10. replaceSeparator(str: string, from: string, to: string): string → Replaces a separator in a string.

Security & Privacy

  1. abbreviate(text: string): string → Converts "Machine Learning" to "ML".
  2. initials(name: string): string → Gets initials from a name ("John Doe""J.D.").
  3. obfuscateEmail(email: string): string → Hides part of an email address.
  4. maskString(str: string, visible: number): string → Masks a string while keeping first & last few characters.
  5. shortenText(str: string, limit: number): string → Keeps words within the limit instead of cutting mid-word.