1.0.0-rc.2 • Published 4 years ago

caesar-caser v1.0.0-rc.2

Weekly downloads
52
License
MIT
Repository
github
Last release
4 years ago

Caesar Caser ⚔

Simple but powerful utility for case style detection and converting.

Install

npm install caesar-caser --save

or if you use Yarn

yarn add caesar-caser

Usage

const caser = require('caesar-caser');

// Converts string from one specific case to another
caser('fooBarBaz').convert('camel', 'constant'); // => FOO_BAR_BAZ

// Converts string to specific case with autodetection
caser('fooBarBaz').convertTo('pascal'); // => FooBarBaz
caser('FOO_BAR_BAZ').convertTo('kebab'); // => foo-bar-baz
caser('foo_bar_baz').convertTo('sentence'); // => Foo bar baz

// Detects case and return its name
caser('fooBarBaz').detect(); // => camel
caser('FOO_BAR_BAZ').detect(); // => constant
caser('Foo Bar Baz').detect(); // => cap-sentence

// Also you can specify priority case name if passed string is unobvious
// For example string 'foo' can be in camel, kebab, snake and other cases
caser('foo').detect(); // => camel
caser('foo').detect('snake'); // => snake
// But if caser detects exact case this argument will be omitted
caser('fooBarBaz').detect('snake'); // => camel

// Normalizes given string by splitting it to array of lowercased chunks
caser('fooBarBaz').normalize('camel'); // => ['foo', 'bar', 'baz']

Available case rules

NameExampleDescription
'camel'fooBarBazCamel case
'pascal'FooBarBazPascal case (sometimes called upper camel or bumpy case)
'kebab'foo-bar-bazKebab case (also known as dash case)
'train'FOO-BAR-BAZTrain case
'snake'foo_bar_bazSnake case (may also be called pothole case)
'constant'FOO_BAR_BAZConstant case (also known as screaming snake case)
'dot'foo.bar.bazDot case
'upper-dot'FOO.BAR.BAZUpper dot case
'sentence'Foo bar bazSentence case
'cap-sentence'Foo Bar BazLike the sentence case but every word is capitalized
'upper-sentence'FOO BAR BAZLike the sentence case but every word is in uppercase
'lower-sentence'foo bar bazLike the sentence case but every word is in lowercase

Maintainers

Igor Sebelev

License

MIT