583 B
583 B
isPromise
Returns true if an object looks like a Promise, false otherwise.
Check if the object is not null, its typeof matches either object or function and if it has a .then property, which is also a function.
const isPromise = obj =>
obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
isPromise({then:function () {return ''}}); // true
isPromise(null); // false
isPromise({}); // false