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