"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; } }); };