-
Notifications
You must be signed in to change notification settings - Fork 22
/
util.js
38 lines (32 loc) · 942 Bytes
/
util.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
module.exports = {
isPrimitiveValue(value) {
if (typeof value == 'string') return true;
if (typeof value == 'number' && isFinite(value)) return true;
if (typeof value == 'boolean') return true;
return false;
},
looksLikeNumber(value) {
if (!isNaN(+value)) return true;
return false;
},
isObject(obj) {
return obj?.constructor === Object;
},
isEmptyObject(obj) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
return false;
}
}
return true;
},
escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
},
isNoValue(value) {
return value === undefined || value === null || value === '';
},
camelize(str) {
return (str + '').replace(/[_](\w|$)/g, (_, firstLetter) => firstLetter.toUpperCase());
},
};