You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
540 B
JavaScript

"use strict";
// TODO: Replace this with an implementation that doesn't use treecutter? As treecutter is pretty hacky
const Promise = require("bluebird");
const treecutter = require("../treecutter");
module.exports = function treeMapAsync(tree, mapper, returnBoth = false) {
return Promise.map(treecutter.flatten(tree), (item) => {
return mapper(item);
}).then((items) => {
let newTree = treecutter.rebuild(items);
if (returnBoth) {
return {
tree: newTree,
list: items
};
} else {
return newTree;
}
});
};