Toolbox-XToolbox-X

Convert String Cases

Converts a string into common case styles (camelCase, snake_case, PascalCase, etc.) with advanced handling.

convertStringCase

The convertStringCase function converts a string into common case styles, including unicode-aware tokenization, preservation of leading/trailing punctuation, and optional acronym preservation.

Function Signature

function convertStringCase(value: string, format: CaseFormat, options?: StringCaseOptions): string

Parameters

  • value (string): The input string to convert.
  • format (CaseFormat): The target case format.
  • options (StringCaseOptions, optional): Customization options.
    • preserveAcronyms (boolean): If true, preserves acronym-like tokens (e.g. API). Defaults to false.

Types

CaseFormat

type CaseFormat =
  | 'camelCase'
  | 'snake_case'
  | 'kebab-case'
  | 'PascalCase'
  | 'Title Case'
  | 'Sentence case'
  | 'UPPERCASE'
  | 'lowercase';

StringCaseOptions

interface StringCaseOptions {
  preserveAcronyms?: boolean;
}

Example Usage

playground.ts

Notes

  • Unicode-aware: Treats letters from any script correctly using Unicode properties.
  • Title Case Rules: Common short words (articles, prepositions, conjunctions) are lowercased unless they appear at the start or end. Dashes (-) are treated as part of words rather than word separators for Title Case.

See Also

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page