index.js
2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// --------------------
// is-bluebird module
// --------------------
// exports
/**
* Identifies whether input is a bluebird promise.
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird promise, false if not
*/
var isBluebird = function(promise) {
return isObject(promise) && isBluebird.ctor(promise.constructor);
};
/**
* Identifies whether input is a bluebird promise constructor.
* @param {*} Promise - Input to be tested
* @returns {boolean} - true if is bluebird promise constructor, false if not
*/
isBluebird.ctor = function(Promise) {
return typeof Promise == 'function' && !!Promise.prototype && typeof Promise.prototype._addCallbacks == 'function';
};
/**
* Identifies whether input is a bluebird v2 promise.
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v2 promise, false if not
*/
isBluebird.v2 = function(promise) {
return isObject(promise) && isBluebird.v2.ctor(promise.constructor);
};
/**
* Identifies whether input is bluebird v2 promise constructor.
* @alias isBluebird.ctor.v2
*
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v2 promise, false if not
*/
isBluebird.v2.ctor = function(Promise) {
return isBluebird.ctor(Promise) && Promise.prototype._addCallbacks.length == 6;
};
isBluebird.ctor.v2 = isBluebird.v2.ctor;
/**
* Identifies whether input is a bluebird v3 promise.
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v3 promise, false if not
*/
isBluebird.v3 = function(promise) {
return isObject(promise) && isBluebird.v3.ctor(promise.constructor);
};
/**
* Identifies whether input is bluebird v3 promise constructor.
* @alias isBluebird.ctor.v3
*
* @param {*} promise - Input to be tested
* @returns {boolean} - true if is a bluebird v3 promise, false if not
*/
isBluebird.v3.ctor = function(Promise) {
return isBluebird.ctor(Promise) && Promise.prototype._addCallbacks.length == 5;
};
isBluebird.ctor.v3 = isBluebird.v3.ctor;
/**
* Check if input is an object.
* @param {*} obj - Input to be tested
* @returns {boolean} - true if is an object, false if not
*/
function isObject(obj) {
return !!obj && typeof obj == 'object';
}
// export isBluebird
module.exports = isBluebird;