23 lines
478 B
JavaScript
23 lines
478 B
JavaScript
|
class Utils {
|
||
|
static async mapSeries(iterable, action) {
|
||
|
for (const x of iterable) {
|
||
|
await action(x);
|
||
|
}
|
||
|
return Promise.resolve();
|
||
|
}
|
||
|
|
||
|
static wait(duration) {
|
||
|
return new Promise((resolve) => {
|
||
|
setTimeout(resolve, duration);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
static parseTemplate(template, data) {
|
||
|
return Object.keys(data).reduce((str, key) => {
|
||
|
return str.replace(new RegExp(`{${key}}`, 'gi'), data[key]);
|
||
|
}, template);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = Utils;
|