Convert between typesafe string casings
npm install typed-caseConvert between typesafe string casings.
_If I should maintain this repo, please ⭐️_
_DM me on Twitter if you have questions or suggestions._
---
A zero-dependency package for converting between string casings in a type-safe way.
``sh`
yarn add typed-case
`sh`
npm install typed-case
`sh`
pnpm add typed-case
- Usage
- CamelCase
- PascalCase
- TrainCase
- KebabCase
- SnakeCase
- ConstantCase
- Title Case
- UpperCase, LowerCase
- Capitalize, Uncapitalize
- License
ts
import { toCamelCase, CamelCase } from "typed-case";toCamelCase("hello world"); // "helloWorld"
toCamelCase("hello_world"); // "helloWorld"
toCamelCase("hello-world"); // "helloWorld"
`#### Preserve UpperCase
`ts
toCamelCase("hello WORLD"); // "helloWORLD"
toCamelCase("hello WORLD", { preserveUpperCase: false }); // "helloWorld"
`$3
`ts
import { toPascalCase, PascalCase } from "typed-case";toPascalCase("hello world"); // "HelloWorld"
toPascalCase("hello_world"); // "HelloWorld"
toPascalCase("hello-world"); // "HelloWorld"
`#### Preserve UpperCase
`ts
toPascalCase("hello WORLD"); // "HelloWORLD"
toPascalCase("hello WORLD", { preserveUpperCase: false }); // "HelloWorld"
`$3
`ts
import { toTrainCase, TrainCase } from "typed-case";toTrainCase("hello world"); // "Hello-World"
toTrainCase("hello_world"); // "Hello-World"
toTrainCase("hello-world"); // "Hello-World"
`$3
`ts
import { toTitleCase, TitleCase } from "typed-case";
toTitleCase("hello world"); // "Hello World"
toTitleCase("hello_world"); // "Hello World"
toTitleCase("hello-world"); // "Hello World"
`#### Preserve UpperCase
`ts
toTrainCase("hello WORLD"); // "Hello-WORLD"
toTrainCase("hello WORLD", { preserveUpperCase: false }); // "Hello-World"
`$3
`ts
import { toKebabCase, KebabCase } from "typed-case";toKebabCase("hello world"); // "hello-world"
toKebabCase("hello_world"); // "hello-world"
toKebabCase("hello-world"); // "hello-world"
`$3
`ts
import { toSnakeCase, SnakeCase } from "typed-case";toSnakeCase("hello world"); // "hello_world"
toSnakeCase("hello_world"); // "hello_world"
toSnakeCase("hello-world"); // "hello_world"
`$3
`ts
import { toConstantCase, ConstantCase } from "typed-case";toConstantCase("hello world"); // "HELLO_WORLD"
toConstantCase("hello_world"); // "HELLO_WORLD"
toConstantCase("hello-world"); // "HELLO_WORLD"
`$3
`ts
import { toUpperCase, toLowerCase, UpperCase, LowerCase } from "typed-case";toUpperCase("hello world"); // "HELLO WORLD"
toLowerCase("HELLO WORLD"); // "hello world"
`$3
`ts
import { capitalize, uncapitalize } from "typed-case";capitalize("hello world"); // "Hello world"
uncapitalize("Hello world"); // "hello world"
``