literal-case

A TypeScript library for word case conversions, using Template Literal Types(TS >= 4.1).

Usage no npm install needed!

<script type="module">
  import literalCase from 'https://cdn.skypack.dev/literal-case';
</script>

README

literal-case

A TypeScript library for word case conversions, using Template Literal Types(TS >= 4.1).

Installation

# NPM
npm install literal-case

# YARN
yarn add literal-case

Case Converters

Case Types

Case Converters

camelCase

const str: "fooBar" = camelCase("foo bar");

pascalCase

const str: "FooBar" = pascalCase("foo bar");

snakeCase

const str: "foo_bar" = snakeCase("foo bar");

constantCase

const str: "FOO_BAR" = constantCase("foo bar");

kebabCase

const str: "foo-bar" = kebabCase("foo bar");

dotCase

const str: "foo.bar" = dotCase("foo bar");

noCase

const str: "foo Bar" = noCase("fooBar");

Case Types

CamelCase<T>

// Expect: "fooBar"
type Result = CamelCase<"foo bar">;

PascalCase<T>

// Expect: "FooBar"
type Result = PascalCase<"foo bar">;

PascalCase<T>

// Expect: "FooBar"
type Result = PascalCase<"foo bar">;

SnakeCase<T>

// Expect: "foo_bar"
type Result = SnakeCase<"foo bar">;

ConstantCase<T>

// Expect: "FOO_BAR"
type Result = ConstantCase<"foo bar">;

KebabCase<T>

// Expect: "foo-bar"
type Result = KebabCase<"foo bar">;

DotCase<T>

// Expect: "foo.bar"
type Result = DotCase<"foo bar">;

NoCase<T,D>

// Expect: "foo Bar"
type Result0 = NoCase<"fooBar">;

// Expect: "foo,Bar"
type Result1 = NoCase<"fooBar", ",">;

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Madono - @MadonoHaru - madonoharu@gmail.com

Project Link: https://github.com/MadonoHaru/literal-case.git