-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
40 lines (31 loc) · 904 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
36
37
38
39
40
module.exports = {
removeLastChar: removeLastChar,
each: each,
addLeadingZeroSingle: addLeadingZeroSingle,
addLeadingZeroRange: addLeadingZeroRange
};
function removeLastChar(str) {
return str.substring(0, str.length - 1);
}
function each(arr, func) {
// check if we have array or object
if (Array.isArray(arr)) {
for (let i = 0; i < arr.length; i++) {
// pass [current el, i]
func(arr[i], i);
}
return;
}
if (typeof arr === 'object' && arr !== null && !Array.isArray(arr)) {
Object.keys(arr).forEach(function (key) {
func(arr[key], key);
});
}
}
function addLeadingZeroSingle(time) {
return time.length === 1 ? '0' + time : time;
}
function addLeadingZeroRange(time) {
let t = time.split(':');
return addLeadingZeroSingle(t[0]) + ':' + addLeadingZeroSingle(t[1]);
}