-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
32 lines (26 loc) · 867 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
const { parse, format } = require('date-fns');
function wait(ms) {
return r => new Promise(resolve => setTimeout(() => resolve(r), ms));
}
function allSequential(promiseFns) {
const initPromise = Promise.resolve([]);
return promiseFns.reduce(_chainPromise, initPromise);
function _chainPromise(acc, pFn) {
return acc.then(result => pFn().then(pResult => [...result, pResult]));
}
}
function transformDate(d) {
return format(parse(d, 'MMMM d, yyyy', new Date()), 'dd/MM/yyyy');
}
function createArray(start, end) {
if (start > end) {
throw 'end should be greater than start';
}
return Array(end - start + 1)
.fill(null)
.map((_, i) => start + i);
}
module.exports.wait = wait;
module.exports.allSequential = allSequential;
module.exports.transformDate = transformDate;
module.exports.createArray = createArray;