forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
35 lines (29 loc) · 892 Bytes
/
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
function makeComponentName(str, usePrefix = true) {
const words = str.split('_');
const componentName = words.map(function(word) {
return upperCaseFirstLetter(word);
}).join('');
return `${usePrefix ? 'Eui' : ''}${componentName}`;
}
function lowerCaseFirstLetter(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toLowerCase() + txt.substr(1);
});
}
function upperCaseFirstLetter(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1);
});
}
function addDirectoryToPath(path, dirName, shouldMakeDirectory) {
if (shouldMakeDirectory) {
return path + '/' + dirName;
}
return path;
}
module.exports = {
makeComponentName: makeComponentName,
lowerCaseFirstLetter: lowerCaseFirstLetter,
upperCaseFirstLetter: upperCaseFirstLetter,
addDirectoryToPath: addDirectoryToPath,
};