<!--BEGIN HEADER-->
<div id="top" align="center">
  <h1>typed-case</h1>
  <a href="https://npmjs.com/package/typed-case">
    <img alt="NPM" src="https://img.shields.io/npm/v/typed-case.svg">
  </a>
  <a href="https://github.com/bconnorwhite/typed-case">
    <img alt="TypeScript" src="https://img.shields.io/github/languages/top/bconnorwhite/typed-case.svg">
  </a>
  <a href="https://coveralls.io/github/bconnorwhite/typed-case?branch=main">
    <img alt="Coverage Status" src="https://coveralls.io/repos/github/bconnorwhite/typed-case/badge.svg?branch=main" />
  </a>
</div>

<br />

<blockquote align="center">Convert between type-safe string casings.</blockquote>


---
<!--END HEADER-->

## About

A zero-dependency package for converting between string casings in a type-safe way.

### Supported Casings
| Name                 |
| -------------------- |
| camelCase            |
| PascalCase           |
| kebab-case           |
| snake_case           |
| Train-Case           |
| CONSTANT_CASE        |
| Title Case           |
| UPPER CASE           |
| lower case           |

## Installation

<details open>
  <summary>
    <a href="https://www.npmjs.com/package/typed-case">
      <img src="https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=white" alt="NPM" />
    </a>
  </summary>

```sh
npm install typed-case
```

</details>

<details>
  <summary>
    <a href="https://yarnpkg.com/package/typed-case">
      <img src="https://img.shields.io/badge/yarn-2C8EBB?logo=yarn&logoColor=white" alt="Yarn" />
    </a>
  </summary>

```sh
yarn add typed-case
```

</details>

<details>
  <summary>
    <img src="https://img.shields.io/badge/pnpm-F69220?logo=pnpm&logoColor=white" alt="PNPM" />
  </summary>

```sh
pnpm add typed-case
```

</details>

<details>
  <summary>
    <img src="https://img.shields.io/badge/bun-EE81C3?logo=bun&logoColor=white" alt="Bun" />
  </summary>

```sh
bun add typed-case
```

</details>


## Contents

- [Usage](#usage)
  - [CamelCase](#camelcase)
  - [PascalCase](#pascalcase)
  - [TrainCase](#traincase)
  - [KebabCase](#kebabcase)
  - [SnakeCase](#snakecase)
  - [ConstantCase](#constantcase)
  - [Title Case](#title-case)
  - [UpperCase, LowerCase](#uppercase-lowercase)
  - [Capitalize, Uncapitalize](#capitalize-uncapitalize)
- [License](#license)

## Usage

### CamelCase
```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", { preserveConsecutiveUppercase: false }); // "helloWorld"
```

### PascalCase

```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", { preserveConsecutiveUppercase: false }); // "HelloWorld"
```

### TrainCase

```ts
import { toTrainCase, TrainCase } from "typed-case";

toTrainCase("hello world"); // "Hello-World"
toTrainCase("hello_world"); // "Hello-World"
toTrainCase("hello-world"); // "Hello-World"
```

### TitleCase

```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
toTitleCase("hello WORLD"); // "Hello WORLD"
toTitleCase("hello WORLD", { preserveConsecutiveUppercase: false }); // "Hello World"
```

### KebabCase

```ts
import { toKebabCase, KebabCase } from "typed-case";

toKebabCase("hello world"); // "hello-world"
toKebabCase("hello_world"); // "hello-world"
toKebabCase("hello-world"); // "hello-world"
```

### SnakeCase

```ts
import { toSnakeCase, SnakeCase } from "typed-case";

toSnakeCase("hello world"); // "hello_world"
toSnakeCase("hello_world"); // "hello_world"
toSnakeCase("hello-world"); // "hello_world"
```

### ConstantCase

```ts
import { toConstantCase, ConstantCase } from "typed-case";

toConstantCase("hello world"); // "HELLO_WORLD"
toConstantCase("hello_world"); // "HELLO_WORLD"
toConstantCase("hello-world"); // "HELLO_WORLD"
```

### UpperCase, LowerCase

```ts
import { toUpperCase, toLowerCase, UpperCase, LowerCase } from "typed-case";

toUpperCase("hello world"); // "HELLO WORLD"
toLowerCase("HELLO WORLD"); // "hello world"
```

### Capitalize, Uncapitalize

```ts
import { capitalize, uncapitalize } from "typed-case";

capitalize("hello world"); // "Hello world"
uncapitalize("Hello world"); // "hello world"
```

<!--BEGIN FOOTER-->
<h2 id="license">License <a href="https://opensource.org/licenses/MIT"><img align="right" alt="license" src="https://img.shields.io/npm/l/typed-case.svg"></a></h2>

[MIT](https://opensource.org/licenses/MIT) - _MIT License_
<!--END FOOTER-->
