1 | import camelCase from 'lodash.camelcase';
|
2 | import kebabCase from 'lodash.kebabcase';
|
3 | import snakeCase from 'lodash.snakecase';
|
4 | import upperFirst from 'lodash.upperfirst';
|
5 | import startCase from 'lodash.startcase';
|
6 | export default function toCase(input, target) {
|
7 | switch (target) {
|
8 | case 'camel-case':
|
9 | return camelCase(input);
|
10 | case 'kebab-case':
|
11 | return kebabCase(input);
|
12 | case 'snake-case':
|
13 | return snakeCase(input);
|
14 | case 'pascal-case':
|
15 | return upperFirst(camelCase(input));
|
16 | case 'start-case':
|
17 | return startCase(input);
|
18 | case 'upper-case':
|
19 | case 'uppercase':
|
20 | return input.toUpperCase();
|
21 | case 'sentence-case':
|
22 | case 'sentencecase':
|
23 | return upperFirst(input);
|
24 | case 'lower-case':
|
25 | case 'lowercase':
|
26 | case 'lowerCase':
|
27 | return input.toLowerCase();
|
28 | default:
|
29 | throw new TypeError(`to-case: Unknown target case "${target}"`);
|
30 | }
|
31 | }
|
32 |
|
\ | No newline at end of file |