UNPKG

promise-shall

Version:

Small helper function to automatically call a function with the data from the previous promise passed through or just to return a promise.

17 lines (15 loc) 383 B
'use strict'; module.exports = function shall(p, opts) { opts = opts || { through: true }; var isPromise = typeof p.then !== 'undefined'; var isCallable = typeof p === 'function'; return function (/* ... */) { if (isCallable) { return p.apply(p, opts.through ? arguments : []); } else if (isPromise) { return p; } else { return p; } }; }