Skip to content

Commit

Permalink
feat: introduce Object.isPromise
Browse files Browse the repository at this point in the history
Detect thenables
  • Loading branch information
medikoo committed May 15, 2017
1 parent 0cc6a7b commit 27aecc8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
isNumberValue: require('./is-number-value'),
isObject: require('./is-object'),
isPlainObject: require('./is-plain-object'),
isPromise: require('./is-promise'),
isValue: require('./is-value'),
keyOf: require('./key-of'),
keys: require('./keys'),
Expand Down
6 changes: 6 additions & 0 deletions object/is-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

var isCallable = require('./is-callable')
, isObject = require('./is-object');

module.exports = function (value) { return isObject(value) && isCallable(value.then); };
17 changes: 17 additions & 0 deletions test/object/is-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

module.exports = function (t, a) {
var promise;
a(t(), false);
a(t(null), false);
a(t("promise"), false);
a(t({}), false);
a(t(function () {}), false);
a(t({ then: {} }), false);
a(t({ then: function () {} }), true);
promise = function () {};
promise.then = {};
a(t(promise), false);
promise.then = function () {};
a(t(promise), true);
};

0 comments on commit 27aecc8

Please sign in to comment.