0.3.1 • Published 12 months ago

@sil/case v0.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

Case

Installation

npm install @sil/case

Usage

import { kebabCase } from "@sil/case";

const myString = "This Is My STRING";

const myStringKebabCase = kebabCase(myString); // result: this-is-my-string

Functions

PascalCase

Convert a string to pascalCase

example:

My String > MyString

camelCase

Convert a string to pascalCase

example:

My string > myString

kebabCase

Convert a string to kebabCase

example:

My string > my-string

snakeCase

Convert a string to snakeCase

example:

My string > my_string

upperSnakeCase

Convert a string to upperSnakeCase

example:

My string > MY_STRING

slugCase

Convert a string to slugCase aka kebabCase

example:

My string > my-string

constCase

Constants usually use an upperSnakeCase, but don't allow the string to start with a number. constCase does exactly that. It adds an _ at the beginning of a string whenever it starts with a number.

example:

My string > MY_STRING
1 String > _1_STRING

sentenceCase

Converts any string to a sentence case, which means just lowercase letters and spaces. Starting with a capital letter. This function is helpful to make const variables etc look nice in headers.

example:

MY_STRING > My string
my-string > My string