asksuite-core
Version:
31 lines (27 loc) • 788 B
JavaScript
const Promise = require('bluebird');
const _ = require('lodash');
const asyncMapDeep = (array, key, mapFn, ignoreBranches) =>
Promise.map(
array,
value =>
_.isObject(value) || _.isArray(value)
? asyncMapValuesDeep(value, mapFn, ignoreBranches)
: mapFn(value, key),
{ concurrency: 100 },
);
const asyncMapValuesDeep = (object, mapFn, ignoreBranches) =>
Promise.props(
_.mapValues(object, (value, key) => {
if (_.includes(ignoreBranches, key)) {
return value;
}
return _.isArray(value)
? asyncMapDeep(value, key, mapFn, ignoreBranches)
: _.isObject(value)
? asyncMapValuesDeep(value, mapFn, ignoreBranches)
: mapFn(value, key);
}),
);
module.exports = {
asyncMapValuesDeep,
};