-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
55 lines (55 loc) · 1.29 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.kebabCaseToCamelCase = exports.camelCaseToKebabCase = exports.isKebabCase = exports.isCamelCase = void 0;
/**
* Check whether text is camelCase
* @returns {boolean}
*/
function isCamelCase(text) {
if (text === '') {
return true;
}
if (!text) {
return false;
}
return !text.match(/^[A-Z]/) && !text.match(/[-_]/);
}
exports.isCamelCase = isCamelCase;
/**
* Check whether text is kebab-case
* @returns {boolean}
*/
function isKebabCase(text) {
if (text === '') {
return true;
}
if (!text) {
return false;
}
return !text.match(/[_A-Z]/);
}
exports.isKebabCase = isKebabCase;
/**
* Convert camelCase text to kebab-case
* @param {string} text
* @returns {string}
*/
function camelCaseToKebabCase(text) {
if (!text) {
return '';
}
return text.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
exports.camelCaseToKebabCase = camelCaseToKebabCase;
/**
* Convert kebab-case text to camelCase
* @param {string} text
* @returns {string}
*/
function kebabCaseToCamelCase(text) {
if (!text) {
return '';
}
return text.replace(/-([a-z])/g, (s) => s[1].toUpperCase());
}
exports.kebabCaseToCamelCase = kebabCaseToCamelCase;