Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. const pipeData = function(fn) {
  2. return function(data) {
  3. return Promise.resolve(fn(data)).then(function(res) {
  4. if (res === void 0) {
  5. return data;
  6. }
  7. const keys = Object.keys(res).filter(function(prop) {
  8. return res.hasOwnProperty(prop);
  9. });
  10. return Promise.all(keys.map(function(prop) {
  11. return res[prop];
  12. })).then(function(vals) {
  13. keys.forEach(function(prop, i) {
  14. data[prop] = vals[i];
  15. });
  16. return data;
  17. });
  18. });
  19. };
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement