-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently Object.isPromise mirrors it 1:1, but with next major we will also validate its constructor
- Loading branch information
Showing
7 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
var safeToString = require("../safe-to-string") | ||
, isThenable = require("./is-thenable"); | ||
|
||
module.exports = function (value) { | ||
if (!isThenable(value)) throw new TypeError(safeToString(value) + " is not a thenable"); | ||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
"use strict"; | ||
|
||
var isCallable = require("./is-callable") | ||
, isObject = require("./is-object"); | ||
|
||
module.exports = function (value) { | ||
return isObject(value) && isCallable(value.then); | ||
}; | ||
// In next major this check will also confirm on promise constructor | ||
module.exports = require("./is-thenable"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
|
||
var isCallable = require("./is-callable") | ||
, isObject = require("./is-object"); | ||
|
||
module.exports = function (value) { | ||
return isObject(value) && isCallable(value.then); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict"; | ||
|
||
module.exports = function (t, a) { | ||
// Just sanity checks as proper tests are at isThenable | ||
var thenable = { then: function () {} }; | ||
|
||
a.throws(function () { | ||
t({}); | ||
}, TypeError); | ||
a(t(thenable), thenable); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |