-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.js
More file actions
77 lines (64 loc) · 1.51 KB
/
Utils.js
File metadata and controls
77 lines (64 loc) · 1.51 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
65
66
67
68
69
70
71
72
73
74
75
76
77
const Utils = {
addTime(argDate, value, unit) {
const date = new Date(argDate);
// eslint-disable-next-line default-case
switch (unit) {
case 'seconds':
date.setUTCSeconds(date.getUTCSeconds() + value);
break;
case 'minutes':
date.setUTCMinutes(date.getUTCMinutes() + value);
break;
case 'hours':
date.setUTCHours(date.getUTCHours() + value);
break;
case 'days':
date.setUTCDate(date.getUTCDate() + value);
break;
case 'weeks':
date.setUTCDate(date.getUTCDate() + value * 7);
break;
case 'months':
date.setUTCMonth(date.getUTCMonth() + value);
break;
case 'years':
date.setUTCFullYear(date.getUTCFullYear() + value);
break;
}
return date.toISOString();
},
};
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const Str = {
substring(a, start, end) {
return a.substring(start, end);
},
replace(a, pattern, replace) {
return a.replace(pattern, replace);
},
replaceAll(a, find, replace) {
return a.replace(new RegExp(escapeRegExp(find), 'g'), replace);
},
concat(a, b) {
return a.concat(b);
},
toLowerCase(a) {
return a.toLowerCase();
},
toUpperCase(a) {
return a.toUpperCase();
},
trim(a) {
return a.trim();
},
trimStart(a) {
return a.trimStart();
},
trimEnd(a) {
return a.trimEnd();
},
};
module.exports.Utils = Utils;
module.exports.Str = Str;