-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
64 lines (53 loc) · 1.54 KB
/
Copy pathhelper.js
File metadata and controls
64 lines (53 loc) · 1.54 KB
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
56
57
58
59
60
61
62
63
64
const capitalizeFirstLetter = (inputString) => {
if (typeof inputString == 'string') {
return inputString.charAt(0).toUpperCase() + inputString.slice(1);
} else {
return inputString;
}
};
const deCapitalizeFirstLetter = (inputString) => {
if (typeof inputString == 'string') {
return inputString.charAt(0).toLowerCase() + inputString.slice(1);
} else {
return inputString;
}
};
const removeQuotes = (inputString) => {
if (typeof inputString == 'string') {
return inputString.replace(/^"(.+)"$/, '$1');
} else {
return inputString;
}
};
const removeSpaces = (inputString) => inputString.replace(/ /g, '');
const checkBool = (bool) => {
return typeof bool === 'boolean' ||
(typeof bool === 'object' &&
bool !== null &&
typeof bool.value === 'boolean');
};
const getMapKeyByValue = (map, searchValue) => {
for (let [key, value] of map.entries()) {
if (value === searchValue) {
return key;
}
}
};
const getObjKeyByValue = (obj, value) => Object.keys(obj).find(key => obj[key] === value);
const isNumeric = value => /^\d+$/.test(value);
const isEmpty = obj => Object.getOwnPropertyNames(obj).length === 0;
const getFirstOrAll = map => map.size === 1 ? map.values().next().value : Array.from(map.values());
const countOccurrences = (str, find) => (str.split(find)).length - 1;
module.exports = {
capitalizeFirstLetter,
deCapitalizeFirstLetter,
removeQuotes,
removeSpaces,
checkBool,
getMapKeyByValue,
getObjKeyByValue,
isNumeric,
isEmpty,
getFirstOrAll,
countOccurrences,
};