README
Case anything 🐫
npm i case-anything
14 case changing functions: camelCase, kebab-case, PascalCase and more...
A simple integration with nano package size. (SMALL footprint!)
Motivation
I created this package because most other packages that do simple case changing are so big...
Some features I focused on: |
Case anything is used in... |
Usage
case-anything supports tree-shaking and is side-effect free!
// just import the functions you need like so:
import { camelCase, kebabCase } from 'case-anything'
case-anything has different behaviour if the string you pass has spaces or not.
- Without spaces it will split and format on every "part" it can detect
- With spaces it will split and format on every "word" based on those spaces
Strings without spaces
Name | Input example | Output example |
---|---|---|
🐪 camelCase | camelCase('$catDog') |
catDog |
🐫 PascalCase UpperCamelCase |
pascalCase('$catDog') upperCamelCase('$catDog') |
CatDog |
🥙 kebab-case | kebabCase('$catDog') |
cat-dog |
🐍 snake_case | snakeCase('$catDog') |
cat_dog |
📣 CONSTANT_CASE | constantCase('$catDog') |
CAT_DOG |
🚂 Train-Case | trainCase('$catDog') |
Cat-Dog |
🕊 Ada_Case | adaCase('$catDog') |
Cat_Dog |
👔 COBOL-CASE | cobolCase('$catDog') |
CAT-DOG |
📍 Dot.notation | dotNotation('$catDog') |
cat.Dog |
📂 Path/case | pathCase('$catDog') |
$cat/Dog |
🛰 Space case | spaceCase('$catDog') |
$cat Dog |
🏛 Capital Case | capitalCase('$catDog') |
$Cat Dog |
🔡 lower case | lowerCase('$catDog') |
$cat dog |
🔠 UPPER CASE | upperCase('$catDog') |
$CAT DOG |
Special Characters
You can see that most functions by default remove special characters, and some functions keep special characters.
functions that remove special characters* | functions that keep special characters* |
---|---|
|
|
*You can control wether or not to keep or remove special characters like so:
// default:
camelCase('$catDog') === 'catDog'
// force keeping special characters:
camelCase('$catDog', { keepSpecialCharacters: true }) === '$catDog'
// default:
pathCase('$catDog') === '$cat/Dog'
// force removing special characters:
pathCase('$catDog', { keepSpecialCharacters: false }) === 'cat/Dog'
Case Changing
These cases do not change the casing of the words:
- dotNotation
- pathCase
- spaceCase
// default:
dotNotation('$catDog') === 'cat.Dog'
// force lower case:
dotNotation('$catDog').toLowerCase() === 'cat.dog'
Strings with spaces
As soon as there is a space in the target string, it will regard the input as a sentence and only split each part at the spaces.
Name | Input example | Output example |
---|---|---|
🐪 camelCase | camelCase("I'm O.K.!") |
imOk |
🐫 PascalCase UpperCamelCase |
pascalCase("I'm O.K.!") upperCamelCase("I'm O.K.!") |
ImOk |
🥙 kebab-case | kebabCase("I'm O.K.!") |
im-ok |
🐍 snake_case | snakeCase("I'm O.K.!") |
im_ok |
📣 CONSTANT_CASE | constantCase("I'm O.K.!") |
IM_OK |
🚂 Train-Case | trainCase("I'm O.K.!") |
Im-Ok |
🕊 Ada_Case | adaCase("I'm O.K.!") |
Im_Ok |
👔 COBOL-CASE | cobolCase("I'm O.K.!") |
IM-OK |
📍 Dot.notation | dotNotation("I'm O.K.!") |
Im.OK |
📂 Path/case | pathCase("I'm O.K.!") |
I'm/O.K.! |
🛰 Space case | spaceCase("I'm O.K.!") |
I'm O.K.! |
🏛 Capital Case | capitalCase("I'm O.K.!") |
I'm O.k.! |
🔡 lower case | lowerCase("I'm O.K.!") |
i'm o.k.! |
🔠 UPPER CASE | upperCase("I'm O.K.!") |
I'M O.K.! |
Also note, that multiple sequential spaces are treated as one space.
Keep only certain special characters
Instead of removing all special characters, you can opt to keep some special characters.
In the example below we see:
- input:
$cat-dog
- desired output:
$CatDog
pascalCase('$cat-dog', { keepSpecialCharacters: false })
// CatDog → not what we want
pascalCase('$cat-dog', { keepSpecialCharacters: true })
// $Cat-Dog → not what we want
pascalCase('$cat-dog', { keep: ['