change-case

repository·main·Indexed 25 days ago

https://github.com/blakeembrey/change-case

A monorepo of pure ESM utilities for transforming strings between casing formats. Includes the core change-case library for standard transformations (camelCase, snake_case, PascalCase, etc.), sponge-case for random capitalization, swap-case for swapping character cases, and title-case for English title-style formatting. All packages include TypeScript definitions and support custom options for delimiters, locales, and word splitting.

Tokens
4.4K
Snippets
13
Records
40
Agent score
80%

What's inside change-case

  1. Overview of Change Case packages

    main

    The change-case monorepo provides a suite of tools for transforming strings between various formats such as camelCase, PascalCase, Capital Case, snake_case, param-case, and CONSTANT_CASE.

    The monorepo is split into several specialized packages:

    • change-case: The core package for standard case transformations.
    • sponge-case: Specialized case transformations.
    • swap-case: For swapping character cases.
    • title-case: For title-style formatting.
  2. Compatibility requirements for Change Case packages

    main

    All packages in this monorepo are pure ESM packages and include TypeScript definitions.

    Important Constraints:

    • You cannot use require() to import these packages.
    • They cannot be used with legacy Node.js module resolution in TypeScript. Ensure your project is configured for ESM (ECMAScript Modules).
  3. Transform strings with change-case methods

    main

    The core library provides several methods to transform strings between different casing formats. You can import all methods as a namespace to access them.

    Note: change-case is designed for programming cases. It does not retain punctuation or sensitivities. For generic title or sentence casing, use the title-case package instead.

    import * as changeCase from "change-case";
    
    changeCase.camelCase("TEST_VALUE"); //=> "testValue"
  4. Configure case transformation options

    main

    All case transformation methods accept an options object as a second argument to customize behavior:

    • delimiter?: string: The character to use between words. Default depends on the method (e.g., _ in snakeCase).
    • locale?: string[] | string | false: Specifies the locale for lower/upper casing. Defaults to the host environment. Set to false to disable.
    • split?: (value: string) => string[]: A function to define how the input is split into words. Defaults to the internal split utility.
    • prefixCharacters?: string: Characters to retain at the beginning of the string. Defaults to "".
    • suffixCharacters?: string: Characters to retain at the end of the string. Defaults to "".

    Ambiguous Characters: By default, pascalCase and snakeCase separate ambiguous characters with _ (e.g., V1.2 becomes V1_2). You can use mergeAmbiguousCharacters: true in the options to merge them instead.