25 lines
527 B
JavaScript
Raw Normal View History

2021-06-12 00:19:25 -05:00
class Utils {
static async mapSeries(iterable, action) {
const resolved = [];
2021-06-12 00:19:25 -05:00
for (const x of iterable) {
resolved.push(await action(x));
2021-06-12 00:19:25 -05:00
}
return Promise.resolve(resolved);
2021-06-12 00:19:25 -05:00
}
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;