case.js

1.0.1 • Public • Published

case.js Build status

🔠 A lightweight library for converting between different cases, such as camel, kebab, snake, pascal and others.

Case.js is a small library that allows you to convert strings between different cases.

Install

With npm:

$ npm install case.js

With Yarn:

$ yarn add case.js

Usage

Converting

To convert between cases, just call the target case's method, supplying the string to be converted as an argument.

import cs from 'case.js';

cs.camel('THIS_IS_AN_EXAMPLE_PHRASE'); // => 'thisIsAnExamplePhrase'
cs.camel('this-is-an-example-phrase'); // => 'thisIsAnExamplePhrase'
cs.camel('this is an example phrase'); // => 'thisIsAnExamplePhrase'

cs.constant('thisIsAnExamplePhrase'); // => 'THIS_IS_AN_EXAMPLE_PHRASE'
cs.constant('this-is-an-example-phrase'); // => 'THIS_IS_AN_EXAMPLE_PHRASE'
cs.constant('this_is_an_example_phrase'); // => 'THIS_IS_AN_EXAMPLE_PHRASE'

cs.dot('THIS_IS_AN_EXAMPLE_PHRASE'); // => 'this.is.an.example.phrase'
cs.dot('ThisIsAnExamplePhrase'); // => 'this.is.an.example.phrase'
cs.dot('this is an example phrase'); // => 'this.is.an.example.phrase'

cs.kebab('ThisIsAnExamplePhrase'); // => 'this-is-an-example-phrase'
cs.kebab('this_is_an_example_phrase'); // => 'this-is-an-example-phrase'
cs.kebab('this is an example phrase'); // => 'this-is-an-example-phrase'

cs.pascal('thisIsAnExamplePhrase'); // => 'ThisIsAnExamplePhrase'
cs.pascal('THIS_IS_AN_EXAMPLE_PHRASE'); // => 'ThisIsAnExamplePhrase'
cs.pascal('this.is.an.example.phrase'); // => 'ThisIsAnExamplePhrase'

cs.snake('thisIsAnExamplePhrase'); // => 'this_is_an_example_phrase'
cs.snake('THIS_IS_AN_EXAMPLE_PHRASE'); // => 'this_is_an_example_phrase'
cs.snake('this is an example phrase'); // => 'this_is_an_example_phrase'

cs.space('this.is.an.example.phrase'); // => 'this is an example phrase'
cs.space('this-is-an-example-phrase'); // => 'this is an example phrase'
cs.space('this_is_an_example_phrase'); // => 'this is an example phrase'

Detecting

You can check whether a string is of a certain case in two different ways:

import cs from 'case.js';

cs.is.camel('thisIsAnExamplePhrase');
cs.is.constant('THIS_IS_AN_EXAMPLE_PHRASE');
cs.is.dot('this.is.an.example.phrase');
cs.is.kebab('this-is-an-example-phrase');
cs.is.pascal('ThisIsAnExamplePhrase');
cs.is.snake('this_is_an_example_phrase');
cs.is.space('this is an example phrase');

Or:

import cs from 'case.js';

cs.is('thisIsAnExamplePhrase', 'camel');
cs.is('THIS_IS_AN_EXAMPLE_PHRASE', 'constant');
cs.is('this.is.an.example.phrase', 'dot');
cs.is('this-is-an-example-phrase', 'kebab');
cs.is('ThisIsAnExamplePhrase', 'pascal');
cs.is('this_is_an_example_phrase', 'snake');
cs.is('this is an example phrase', 'space');

Author

Alcides Queiroz Aguiar

License

This code is free to use under the terms of the MIT License.

Dependents (0)

Package Sidebar

Install

npm i case.js

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

9.49 kB

Total Files

13

Last publish

Collaborators

  • alcidesqueiroz