@ts-series/case
v1.1.1
Published
Platform-agnostic utility for converting strings between different casing styles.
Maintainers
Readme
Case.ts
Case.ts is a small, dependency-free library for converting strings between casing styles. It uses only standard JavaScript and runs unmodified in browsers, Deno and Node.js.
Installation
deno add jsr:@ts-series/casenpm install @ts-series/caseIn the browser, the package can be imported from a CDN such as esm.sh, jsDelivr or unpkg:
<script type="module">
import { toCamelCase } from 'https://esm.sh/@ts-series/case';
</script>Usage
import { toCamelCase, toKebabCase, toSlug } from '@ts-series/case';
toCamelCase('hello world');
toKebabCase('helloWorld');
toSlug('Hello, World!');The results are 'helloWorld', 'hello-world' and 'hello-world'. All functions accept string | null | undefined and never throw on unvalidated input.
Features
- Word splitting:
toWordssplits text at separators and camelCase boundaries, with full Unicode support. All other conversions are built on it. - Identifier styles: camelCase, PascalCase, snake_case and kebab-case, plus
toIdandtoIdCapitalized, which preserve acronyms such as currency codes. - Readable text styles: Title Case and Sentence case for identifiers.
- URL slugs:
toSlugproduces lowercase, percent-encoded slugs with optional transliteration. - Object keys:
convertKeysreturns a copy of an object or array with all keys transformed, optionally recursive. - Free text: The
TextCaseinterface provides a frame for defining capitalization and ASCII spelling rules for any language and plugging them into your own processing flow. English and German are included.
See REFERENCE.md for the complete API.
License
Released into the public domain under the Unlicense.
