naming-style
中文
One lightly library contains a series of methods for converting one string or text to different kind of naming style, such as camelCase, PascalCase, hyphen-case, CONSTANT_CASE, etc.
Install
yarn add naming-style
or
npm i naming-style
Quick Start
import {
style,
camel,
pascal,
hyphen,
constant,
snake,
underscore,
setence,
} from 'naming-style';
style('iAm24YearsOld');
style('--naming-style -loves you');
camel('--naming-style -loves you');
pascal('--naming-style -loves you');
hyphen('--naming-style -loves you');
constant('--naming-style -loves you');
snake('--naming-style -loves you');
sentence('--naming-style -loves you');
underscore('--naming-style -loves you');
Features
1. Methods
2. Available styles for converting to
-
This library provides 7 naming styles you can convert to, including camel
, pascal
, hyphen
, constant
, snake
, sentence
and underscore
.
-
The first 6 styles are the basic styles, which the last one underscore
is derived from them.
Example:
camel --> 'iAm24YearsOld'
pascal --> 'IAm24YearsOld'
hyphen --> 'i-am-24-years-old'
constant --> 'I_AM_24_YEARS_OLD'
snake --> 'i_am_24_years_old'
sentence --> 'I am 24 years old'
underscore --> 'i_am_24_years_old'
3. Basic methods are reversible by each other
- If the input belongs to the basic styles, you can use corresponding methods of them to convert your text reversibly.
Example:
import { style, camel, snake } from 'naming-style';
const origin = 'i_am_24_years_old';
const namingStyle = style(origin);
console.log(namingStyle);
const camelCase = camel(origin);
const snake_case = snake(camelCase);
const newCamelCase = camel(snake_case);
console.log(camelCase === newCamelCase);
4. Other regular input
- If the naming style of the input does not belong to any style from library, the result returned by the
style
method is 'other'
.
Example:
import { style } from 'naming-style';
style('--naming-style -loves you');