is 0.2.3 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +30 -28
- package/package.json +4 -4
- package/test/index.js +288 -276
package/index.js
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* @license MIT
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
var owns =
|
|
12
|
-
var toString =
|
|
10
|
+
var objProto = Object.prototype;
|
|
11
|
+
var owns = objProto.hasOwnProperty;
|
|
12
|
+
var toString = objProto.toString;
|
|
13
13
|
var isActualNaN = function (value) {
|
|
14
|
-
return
|
|
14
|
+
return value !== value;
|
|
15
15
|
};
|
|
16
16
|
var NON_HOST_TYPES = {
|
|
17
17
|
"boolean": 1,
|
|
@@ -205,7 +205,9 @@ is.undefined = function (value) {
|
|
|
205
205
|
*/
|
|
206
206
|
|
|
207
207
|
is.arguments = function (value) {
|
|
208
|
-
|
|
208
|
+
var isStandardArguments = '[object Arguments]' === toString.call(value);
|
|
209
|
+
var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
|
|
210
|
+
return isStandardArguments || isOldArguments;
|
|
209
211
|
};
|
|
210
212
|
|
|
211
213
|
/**
|
|
@@ -343,7 +345,6 @@ is.element = function (value) {
|
|
|
343
345
|
return value !== undefined
|
|
344
346
|
&& typeof HTMLElement !== 'undefined'
|
|
345
347
|
&& value instanceof HTMLElement
|
|
346
|
-
&& owns.call(value, 'nodeType')
|
|
347
348
|
&& value.nodeType === 1;
|
|
348
349
|
};
|
|
349
350
|
|
|
@@ -377,8 +378,9 @@ is.error = function (value) {
|
|
|
377
378
|
* @api public
|
|
378
379
|
*/
|
|
379
380
|
|
|
380
|
-
is.fn = is['function'] = function(value) {
|
|
381
|
-
|
|
381
|
+
is.fn = is['function'] = function (value) {
|
|
382
|
+
var isAlert = typeof window !== 'undefined' && value === window.alert;
|
|
383
|
+
return isAlert || '[object Function]' === toString.call(value);
|
|
382
384
|
};
|
|
383
385
|
|
|
384
386
|
/**
|
|
@@ -420,7 +422,7 @@ is.infinite = function (value) {
|
|
|
420
422
|
*/
|
|
421
423
|
|
|
422
424
|
is.decimal = function (value) {
|
|
423
|
-
return is.number(value) && !isActualNaN(value) && value % 1 !== 0;
|
|
425
|
+
return is.number(value) && !isActualNaN(value) && !is.infinite(value) && value % 1 !== 0;
|
|
424
426
|
};
|
|
425
427
|
|
|
426
428
|
/**
|
|
@@ -558,7 +560,7 @@ is.odd = function (value) {
|
|
|
558
560
|
|
|
559
561
|
is.ge = function (value, other) {
|
|
560
562
|
if (isActualNaN(value) || isActualNaN(other)) {
|
|
561
|
-
throw new TypeError('NaN is not a
|
|
563
|
+
throw new TypeError('NaN is not a valid value');
|
|
562
564
|
}
|
|
563
565
|
return !is.infinite(value) && !is.infinite(other) && value >= other;
|
|
564
566
|
};
|
|
@@ -575,7 +577,7 @@ is.ge = function (value, other) {
|
|
|
575
577
|
|
|
576
578
|
is.gt = function (value, other) {
|
|
577
579
|
if (isActualNaN(value) || isActualNaN(other)) {
|
|
578
|
-
throw new TypeError('NaN is not a
|
|
580
|
+
throw new TypeError('NaN is not a valid value');
|
|
579
581
|
}
|
|
580
582
|
return !is.infinite(value) && !is.infinite(other) && value > other;
|
|
581
583
|
};
|
|
@@ -592,7 +594,7 @@ is.gt = function (value, other) {
|
|
|
592
594
|
|
|
593
595
|
is.le = function (value, other) {
|
|
594
596
|
if (isActualNaN(value) || isActualNaN(other)) {
|
|
595
|
-
throw new TypeError('NaN is not a
|
|
597
|
+
throw new TypeError('NaN is not a valid value');
|
|
596
598
|
}
|
|
597
599
|
return !is.infinite(value) && !is.infinite(other) && value <= other;
|
|
598
600
|
};
|
|
@@ -609,7 +611,7 @@ is.le = function (value, other) {
|
|
|
609
611
|
|
|
610
612
|
is.lt = function (value, other) {
|
|
611
613
|
if (isActualNaN(value) || isActualNaN(other)) {
|
|
612
|
-
throw new TypeError('NaN is not a
|
|
614
|
+
throw new TypeError('NaN is not a valid value');
|
|
613
615
|
}
|
|
614
616
|
return !is.infinite(value) && !is.infinite(other) && value < other;
|
|
615
617
|
};
|
|
@@ -626,7 +628,7 @@ is.lt = function (value, other) {
|
|
|
626
628
|
*/
|
|
627
629
|
is.within = function (value, start, finish) {
|
|
628
630
|
if (isActualNaN(value) || isActualNaN(start) || isActualNaN(finish)) {
|
|
629
|
-
throw new TypeError('NaN is not a
|
|
631
|
+
throw new TypeError('NaN is not a valid value');
|
|
630
632
|
} else if (!is.number(value) || !is.number(start) || !is.number(finish)) {
|
|
631
633
|
throw new TypeError('all arguments must be numbers');
|
|
632
634
|
}
|
|
@@ -648,7 +650,20 @@ is.within = function (value, start, finish) {
|
|
|
648
650
|
*/
|
|
649
651
|
|
|
650
652
|
is.object = function (value) {
|
|
651
|
-
return '[object Object]' === toString.call(value);
|
|
653
|
+
return value && '[object Object]' === toString.call(value);
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* is.hash
|
|
658
|
+
* Test if `value` is a hash - a plain object literal.
|
|
659
|
+
*
|
|
660
|
+
* @param {Mixed} value value to test
|
|
661
|
+
* @return {Boolean} true if `value` is a hash, false otherwise
|
|
662
|
+
* @api public
|
|
663
|
+
*/
|
|
664
|
+
|
|
665
|
+
is.hash = function (value) {
|
|
666
|
+
return is.object(value) && value.constructor === Object && !value.nodeType && !value.setInterval;
|
|
652
667
|
};
|
|
653
668
|
|
|
654
669
|
/**
|
|
@@ -685,16 +700,3 @@ is.string = function (value) {
|
|
|
685
700
|
return '[object String]' === toString.call(value);
|
|
686
701
|
};
|
|
687
702
|
|
|
688
|
-
/**
|
|
689
|
-
* is.hash
|
|
690
|
-
* Test if `value` is a plain object, ie a hash.
|
|
691
|
-
*
|
|
692
|
-
* @param {Mixed} value value to test
|
|
693
|
-
* @return {Boolean} true if `value` is a hash, false otherwise
|
|
694
|
-
* @api public
|
|
695
|
-
*/
|
|
696
|
-
|
|
697
|
-
is.hash = function (value) {
|
|
698
|
-
return is.object(value) && value.constructor === Object && !value.nodeType && !value.setInterval;
|
|
699
|
-
};
|
|
700
|
-
|
package/package.json
CHANGED
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"url": "git://github.com/enricomarino/is.git"
|
|
24
24
|
},
|
|
25
25
|
"main": "index.js",
|
|
26
|
-
"version": "0.2.
|
|
26
|
+
"version": "0.2.7",
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "node test/index.js"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"tape": "~
|
|
32
|
-
"foreach": "~2.0.
|
|
31
|
+
"tape": "~2.3.2",
|
|
32
|
+
"foreach": "~2.0.4"
|
|
33
33
|
},
|
|
34
34
|
"testling": {
|
|
35
|
-
"files": "test.js",
|
|
35
|
+
"files": "test/index.js",
|
|
36
36
|
"browsers": [
|
|
37
37
|
"iexplore/6.0..latest",
|
|
38
38
|
"firefox/3.0",
|
package/test/index.js
CHANGED
|
@@ -2,469 +2,481 @@ var test = require('tape');
|
|
|
2
2
|
var is = require('../index.js');
|
|
3
3
|
|
|
4
4
|
var forEach = require('foreach');
|
|
5
|
+
var now = Date.now || function () { return +new Date(); };
|
|
5
6
|
|
|
6
7
|
test('is.type', function (t) {
|
|
7
8
|
var booleans = [true, false];
|
|
8
9
|
forEach(booleans, function (boolean) {
|
|
9
|
-
t.
|
|
10
|
+
t.ok(is.type(boolean, 'boolean'), '"' + boolean + '" is a boolean');
|
|
10
11
|
});
|
|
11
12
|
|
|
12
13
|
var numbers = [1, 0 / 1, 0 / -1, NaN, Infinity, -Infinity];
|
|
13
14
|
forEach(numbers, function (number) {
|
|
14
|
-
t.
|
|
15
|
+
t.ok(is.type(number, 'number'), '"' + number + '" is a number');
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
var objects = [{}, null, new Date()];
|
|
18
19
|
forEach(objects, function (object) {
|
|
19
|
-
t.
|
|
20
|
+
t.ok(is.type(object, 'object'), '"' + object + '" is an object');
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
var strings = ['', 'abc'];
|
|
23
24
|
forEach(strings, function (string) {
|
|
24
|
-
t.
|
|
25
|
+
t.ok(is.type(string, 'string'), '"' + string + '" is a string');
|
|
25
26
|
});
|
|
26
27
|
|
|
27
|
-
t.
|
|
28
|
+
t.ok(is.type(undefined, 'undefined'), 'undefined is undefined');
|
|
28
29
|
|
|
29
30
|
t.end();
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
test('is.undefined', function (t) {
|
|
33
|
-
t.
|
|
34
|
-
t.
|
|
35
|
-
t.
|
|
34
|
+
t.ok(is.undefined(), 'undefined is undefined');
|
|
35
|
+
t.notOk(is.undefined(null), 'null is not undefined');
|
|
36
|
+
t.notOk(is.undefined({}), 'object is not undefined');
|
|
36
37
|
t.end();
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
test('is.defined', function (t) {
|
|
40
|
-
t.
|
|
41
|
-
t.
|
|
42
|
-
t.
|
|
41
|
+
t.notOk(is.defined(), 'undefined is not defined');
|
|
42
|
+
t.ok(is.defined(null), 'null is defined');
|
|
43
|
+
t.ok(is.defined({}), 'object is undefined');
|
|
43
44
|
t.end();
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
test('is.empty', function (t) {
|
|
47
|
-
t.
|
|
48
|
-
t.
|
|
49
|
-
t.
|
|
50
|
-
(function () { t.
|
|
48
|
+
t.ok(is.empty(''), 'empty string is empty');
|
|
49
|
+
t.ok(is.empty([]), 'empty array is empty');
|
|
50
|
+
t.ok(is.empty({}), 'empty object is empty');
|
|
51
|
+
(function () { t.ok(is.empty(arguments), 'empty arguments is empty'); }());
|
|
51
52
|
t.end();
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
test('is.equal', function (t) {
|
|
55
|
-
t.
|
|
56
|
-
t.
|
|
57
|
-
t.
|
|
58
|
-
t.
|
|
59
|
-
var
|
|
60
|
-
t.
|
|
56
|
+
t.ok(is.equal([1, 2, 3], [1, 2, 3]), 'arrays are shallowly equal');
|
|
57
|
+
t.ok(is.equal([1, 2, [3, 4]], [1, 2, [3, 4]]), 'arrays are deep equal');
|
|
58
|
+
t.ok(is.equal({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 }), 'objects are shallowly equal');
|
|
59
|
+
t.ok(is.equal({ a: { b: 1 } }, { a: { b: 1 } }), 'objects are deep equal');
|
|
60
|
+
var nowTS = now();
|
|
61
|
+
t.ok(is.equal(new Date(nowTS), new Date(nowTS)), 'two equal date objects are equal');
|
|
61
62
|
|
|
62
63
|
var F = function () {};
|
|
63
64
|
F.prototype = {};
|
|
64
|
-
t.
|
|
65
|
+
t.ok(is.equal(new F(), new F()), 'two object instances are equal when the prototype is the same');
|
|
65
66
|
t.end();
|
|
66
67
|
});
|
|
67
68
|
|
|
68
69
|
test('is.hosted', function (t) {
|
|
69
|
-
t.
|
|
70
|
-
t.
|
|
71
|
-
t.
|
|
72
|
-
t.
|
|
73
|
-
t.
|
|
74
|
-
t.
|
|
75
|
-
t.
|
|
76
|
-
t.
|
|
77
|
-
t.
|
|
70
|
+
t.ok(is.hosted('a', { a: {} }), 'object is hosted');
|
|
71
|
+
t.ok(is.hosted('a', { a: [] }), 'array is hosted');
|
|
72
|
+
t.ok(is.hosted('a', { a: function () {} }), 'function is hosted');
|
|
73
|
+
t.notOk(is.hosted('a', { a: true }), 'boolean value is not hosted');
|
|
74
|
+
t.notOk(is.hosted('a', { a: false }), 'boolean value is not hosted');
|
|
75
|
+
t.notOk(is.hosted('a', { a: 3 }), 'number value is not hosted');
|
|
76
|
+
t.notOk(is.hosted('a', { a: undefined }), 'undefined value is not hosted');
|
|
77
|
+
t.notOk(is.hosted('a', { a: 'abc' }), 'string value is not hosted');
|
|
78
|
+
t.notOk(is.hosted('a', { a: null }), 'null value is not hosted');
|
|
78
79
|
t.end();
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
test('is.instance', function (t) {
|
|
82
|
-
t.
|
|
83
|
+
t.ok(is.instance(new Date(), Date), 'new Date is instanceof Date');
|
|
83
84
|
var F = function () {};
|
|
84
|
-
t.
|
|
85
|
+
t.ok(is.instance(new F(), F), 'new constructor is instanceof constructor');
|
|
85
86
|
t.end();
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
test('is.null', function (t) {
|
|
89
90
|
var isNull = is['null'];
|
|
90
|
-
t.
|
|
91
|
-
t.
|
|
92
|
-
t.
|
|
91
|
+
t.ok(isNull(null), 'null is null');
|
|
92
|
+
t.notOk(isNull(undefined), 'undefined is not null');
|
|
93
|
+
t.notOk(isNull({}), 'object is not null');
|
|
93
94
|
t.end();
|
|
94
95
|
});
|
|
95
96
|
|
|
96
97
|
test('is.arguments', function (t) {
|
|
97
|
-
t.
|
|
98
|
-
(function () { t.
|
|
99
|
-
(function () { t.
|
|
98
|
+
t.notOk(is.arguments([]), 'array is not arguments');
|
|
99
|
+
(function () { t.ok(is.arguments(arguments), 'arguments is arguments'); }());
|
|
100
|
+
(function () { t.notOk(is.arguments(Array.prototype.slice.call(arguments)), 'sliced arguments is not arguments'); }());
|
|
100
101
|
t.end();
|
|
101
102
|
});
|
|
102
103
|
|
|
103
104
|
test('is.array', function (t) {
|
|
104
|
-
t.
|
|
105
|
-
(function () { t.
|
|
105
|
+
t.ok(is.array([]), 'array is array');
|
|
106
|
+
(function () { t.ok(is.array(Array.prototype.slice.call(arguments)), 'sliced arguments is array'); }());
|
|
106
107
|
t.end();
|
|
107
108
|
});
|
|
108
109
|
|
|
109
110
|
test('is.array.empty', function (t) {
|
|
110
|
-
t.
|
|
111
|
-
(function () { t.
|
|
112
|
-
(function () { t.
|
|
111
|
+
t.ok(is.array.empty([]), 'empty array is empty array');
|
|
112
|
+
(function () { t.notOk(is.array.empty(arguments), 'empty arguments is not empty array'); }());
|
|
113
|
+
(function () { t.ok(is.array.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is empty array'); }());
|
|
113
114
|
t.end();
|
|
114
115
|
});
|
|
115
116
|
|
|
116
117
|
test('is.arguments.empty', function (t) {
|
|
117
|
-
t.
|
|
118
|
-
(function () { t.
|
|
119
|
-
(function () { t.
|
|
118
|
+
t.notOk(is.arguments.empty([]), 'empty array is not empty arguments');
|
|
119
|
+
(function () { t.ok(is.arguments.empty(arguments), 'empty arguments is empty arguments'); }());
|
|
120
|
+
(function () { t.notOk(is.arguments.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is not empty arguments'); }());
|
|
120
121
|
t.end();
|
|
121
122
|
});
|
|
122
123
|
|
|
123
124
|
test('is.isarraylike', function (t) {
|
|
124
|
-
t.
|
|
125
|
-
t.
|
|
126
|
-
t.
|
|
127
|
-
t.
|
|
128
|
-
t.
|
|
129
|
-
t.
|
|
130
|
-
t.
|
|
131
|
-
t.
|
|
132
|
-
t.
|
|
133
|
-
t.
|
|
134
|
-
t.
|
|
135
|
-
(function () { t.
|
|
136
|
-
(function () { t.
|
|
125
|
+
t.notOk(is.arraylike(), 'undefined is not array-like');
|
|
126
|
+
t.notOk(is.arraylike(null), 'null is not array-like');
|
|
127
|
+
t.notOk(is.arraylike(false), 'false is not array-like');
|
|
128
|
+
t.notOk(is.arraylike(true), 'true is not array-like');
|
|
129
|
+
t.ok(is.arraylike({ length: 0 }), 'object with zero length is array-like');
|
|
130
|
+
t.ok(is.arraylike({ length: 1 }), 'object with positive length is array-like');
|
|
131
|
+
t.notOk(is.arraylike({ length: -1 }), 'object with negative length is not array-like');
|
|
132
|
+
t.notOk(is.arraylike({ length: NaN }), 'object with NaN length is not array-like');
|
|
133
|
+
t.notOk(is.arraylike({ length: 'foo' }), 'object with string length is not array-like');
|
|
134
|
+
t.notOk(is.arraylike({ length: '' }), 'object with empty string length is not array-like');
|
|
135
|
+
t.ok(is.arraylike([]), 'array is array-like');
|
|
136
|
+
(function () { t.ok(is.arraylike(arguments), 'empty arguments is array-like'); }());
|
|
137
|
+
(function () { t.ok(is.arraylike(arguments), 'nonempty arguments is array-like'); }(1, 2, 3));
|
|
137
138
|
t.end();
|
|
138
139
|
});
|
|
139
140
|
|
|
140
141
|
test('is.boolean', function (t) {
|
|
141
|
-
t.
|
|
142
|
-
t.
|
|
143
|
-
t.
|
|
144
|
-
t.
|
|
145
|
-
t.
|
|
146
|
-
t.
|
|
142
|
+
t.ok(is.boolean(true), 'literal true is a boolean');
|
|
143
|
+
t.ok(is.boolean(false), 'literal false is a boolean');
|
|
144
|
+
t.ok(is.boolean(new Boolean(true)), 'object true is a boolean');
|
|
145
|
+
t.ok(is.boolean(new Boolean(false)), 'object false is a boolean');
|
|
146
|
+
t.notOk(is.boolean(), 'undefined is not a boolean');
|
|
147
|
+
t.notOk(is.boolean(null), 'null is not a boolean');
|
|
147
148
|
t.end();
|
|
148
149
|
});
|
|
149
150
|
|
|
150
151
|
test('is.false', function (t) {
|
|
151
152
|
var isFalse = is['false'];
|
|
152
|
-
t.
|
|
153
|
-
t.
|
|
154
|
-
t.
|
|
155
|
-
t.
|
|
156
|
-
t.
|
|
157
|
-
t.
|
|
153
|
+
t.ok(isFalse(false), 'false is false');
|
|
154
|
+
t.ok(isFalse(new Boolean(false)), 'object false is false');
|
|
155
|
+
t.notOk(isFalse(true), 'true is not false');
|
|
156
|
+
t.notOk(isFalse(), 'undefined is not false');
|
|
157
|
+
t.notOk(isFalse(null), 'null is not false');
|
|
158
|
+
t.notOk(isFalse(''), 'empty string is not false');
|
|
158
159
|
t.end();
|
|
159
160
|
});
|
|
160
161
|
|
|
161
162
|
test('is.true', function (t) {
|
|
162
163
|
var isTrue = is['true'];
|
|
163
|
-
t.
|
|
164
|
-
t.
|
|
165
|
-
t.
|
|
166
|
-
t.
|
|
167
|
-
t.
|
|
168
|
-
t.
|
|
164
|
+
t.ok(isTrue(true), 'true is true');
|
|
165
|
+
t.ok(isTrue(new Boolean(true)), 'object true is true');
|
|
166
|
+
t.notOk(isTrue(false), 'false is not true');
|
|
167
|
+
t.notOk(isTrue(), 'undefined is not true');
|
|
168
|
+
t.notOk(isTrue(null), 'null is not true');
|
|
169
|
+
t.notOk(isTrue(''), 'empty string is not true');
|
|
169
170
|
t.end();
|
|
170
171
|
});
|
|
171
172
|
|
|
172
173
|
test('is.date', function (t) {
|
|
173
|
-
t.
|
|
174
|
-
t.
|
|
175
|
-
t.
|
|
176
|
-
t.
|
|
177
|
-
t.
|
|
174
|
+
t.ok(is.date(new Date()), 'new Date is date');
|
|
175
|
+
t.notOk(is.date(), 'undefined is not date');
|
|
176
|
+
t.notOk(is.date(null), 'null is not date');
|
|
177
|
+
t.notOk(is.date(''), 'empty string is not date');
|
|
178
|
+
t.notOk(is.date(now()), 'timestamp is not date');
|
|
178
179
|
var F = function () {};
|
|
179
180
|
F.prototype = new Date();
|
|
180
|
-
t.
|
|
181
|
+
t.notOk(is.date(new F()), 'Date subtype is not date');
|
|
181
182
|
t.end();
|
|
182
183
|
});
|
|
183
184
|
|
|
184
185
|
test('is.element', function (t) {
|
|
185
186
|
if (typeof HTMLElement !== 'undefined') {
|
|
186
187
|
var element = document.createElement('div');
|
|
187
|
-
t.
|
|
188
|
-
t.
|
|
188
|
+
t.ok(is.element(element), 'HTMLElement is element');
|
|
189
|
+
t.notOk(is.element({ nodeType: 1 }), 'object with nodeType is not element');
|
|
189
190
|
} else {
|
|
190
|
-
t.
|
|
191
|
+
t.ok(true, 'Skipping is.element test in a non-browser environment');
|
|
191
192
|
}
|
|
192
193
|
t.end();
|
|
193
194
|
});
|
|
194
195
|
|
|
195
196
|
test('is.error', function (t) {
|
|
196
197
|
var err = new Error('foo');
|
|
197
|
-
t.
|
|
198
|
-
t.
|
|
199
|
-
t.
|
|
198
|
+
t.ok(is.error(err), 'Error is error');
|
|
199
|
+
t.notOk(is.error({}), 'object is not error');
|
|
200
|
+
t.notOk(is.error({ toString: function () { return '[object Error]'; } }), 'object with error\'s toString is not error');
|
|
200
201
|
t.end();
|
|
201
202
|
});
|
|
202
203
|
|
|
203
204
|
test('is.fn', function (t) {
|
|
204
205
|
t.equal(is['function'], is.fn, 'alias works');
|
|
205
|
-
t.
|
|
206
|
-
t.
|
|
206
|
+
t.ok(is.fn(function () {}), 'function is function');
|
|
207
|
+
t.ok(is.fn(console.log), 'console.log is function');
|
|
207
208
|
if (typeof window !== 'undefined') {
|
|
208
209
|
// in IE7/8, typeof alert === 'object'
|
|
209
|
-
t.
|
|
210
|
+
t.ok(is.fn(window.alert), 'window.alert is function');
|
|
210
211
|
}
|
|
211
|
-
t.
|
|
212
|
-
t.
|
|
212
|
+
t.notOk(is.fn({}), 'object is not function');
|
|
213
|
+
t.notOk(is.fn(null), 'null is not function');
|
|
213
214
|
t.end();
|
|
214
215
|
});
|
|
215
216
|
|
|
216
217
|
test('is.number', function (t) {
|
|
217
|
-
t.
|
|
218
|
-
t.
|
|
219
|
-
t.
|
|
220
|
-
t.
|
|
221
|
-
t.
|
|
222
|
-
t.
|
|
223
|
-
t.
|
|
224
|
-
t.
|
|
225
|
-
t.
|
|
226
|
-
t.
|
|
218
|
+
t.ok(is.number(0), 'positive zero is number');
|
|
219
|
+
t.ok(is.number(0 / -1), 'negative zero is number');
|
|
220
|
+
t.ok(is.number(3), 'three is number');
|
|
221
|
+
t.ok(is.number(NaN), 'NaN is number');
|
|
222
|
+
t.ok(is.number(Infinity), 'infinity is number');
|
|
223
|
+
t.ok(is.number(-Infinity), 'negative infinity is number');
|
|
224
|
+
t.ok(is.number(new Number(42)), 'object number is number');
|
|
225
|
+
t.notOk(is.number(), 'undefined is not number');
|
|
226
|
+
t.notOk(is.number(null), 'null is not number');
|
|
227
|
+
t.notOk(is.number(true), 'true is not number');
|
|
227
228
|
t.end();
|
|
228
229
|
});
|
|
229
230
|
|
|
230
231
|
test('is.infinite', function (t) {
|
|
231
|
-
t.
|
|
232
|
-
t.
|
|
233
|
-
t.
|
|
234
|
-
t.
|
|
232
|
+
t.ok(is.infinite(Infinity), 'positive infinity is infinite');
|
|
233
|
+
t.ok(is.infinite(-Infinity), 'negative infinity is infinite');
|
|
234
|
+
t.notOk(is.infinite(NaN), 'NaN is not infinite');
|
|
235
|
+
t.notOk(is.infinite(0), 'a number is not infinite');
|
|
235
236
|
t.end();
|
|
236
237
|
});
|
|
237
238
|
|
|
238
239
|
test('is.decimal', function (t) {
|
|
239
|
-
t.
|
|
240
|
-
t.
|
|
241
|
-
t.
|
|
242
|
-
t.
|
|
240
|
+
t.ok(is.decimal(1.1), 'decimal is decimal');
|
|
241
|
+
t.notOk(is.decimal(0), 'zero is not decimal');
|
|
242
|
+
t.notOk(is.decimal(1), 'integer is not decimal');
|
|
243
|
+
t.notOk(is.decimal(NaN), 'NaN is not decimal');
|
|
244
|
+
t.notOk(is.decimal(Infinity), 'Infinity is not decimal');
|
|
243
245
|
t.end();
|
|
244
246
|
});
|
|
245
247
|
|
|
246
248
|
test('is.divisibleBy', function (t) {
|
|
247
|
-
t.
|
|
248
|
-
t.
|
|
249
|
-
t.
|
|
250
|
-
t.
|
|
251
|
-
t.
|
|
252
|
-
t.
|
|
253
|
-
t.
|
|
254
|
-
t.
|
|
255
|
-
t.
|
|
256
|
-
t.
|
|
257
|
-
t.
|
|
249
|
+
t.ok(is.divisibleBy(4, 2), '4 is divisible by 2');
|
|
250
|
+
t.ok(is.divisibleBy(4, 2), '4 is divisible by 2');
|
|
251
|
+
t.ok(is.divisibleBy(0, 1), '0 is divisible by 1');
|
|
252
|
+
t.ok(is.divisibleBy(Infinity, 1), 'infinity is divisible by anything');
|
|
253
|
+
t.ok(is.divisibleBy(1, Infinity), 'anything is divisible by infinity');
|
|
254
|
+
t.ok(is.divisibleBy(Infinity, Infinity), 'infinity is divisible by infinity');
|
|
255
|
+
t.notOk(is.divisibleBy(1, 0), '1 is not divisible by 0');
|
|
256
|
+
t.notOk(is.divisibleBy(NaN, 1), 'NaN is not divisible by 1');
|
|
257
|
+
t.notOk(is.divisibleBy(1, NaN), '1 is not divisible by NaN');
|
|
258
|
+
t.notOk(is.divisibleBy(NaN, NaN), 'NaN is not divisible by NaN');
|
|
259
|
+
t.notOk(is.divisibleBy(1, 3), '1 is not divisible by 3');
|
|
258
260
|
t.end();
|
|
259
261
|
});
|
|
260
262
|
|
|
261
263
|
test('is.int', function (t) {
|
|
262
|
-
t.
|
|
263
|
-
t.
|
|
264
|
-
t.
|
|
265
|
-
t.
|
|
266
|
-
t.
|
|
267
|
-
t.
|
|
268
|
-
t.
|
|
264
|
+
t.ok(is.int(0), '0 is integer');
|
|
265
|
+
t.ok(is.int(3), '3 is integer');
|
|
266
|
+
t.notOk(is.int(1.1), '1.1 is not integer');
|
|
267
|
+
t.notOk(is.int(NaN), 'NaN is not integer');
|
|
268
|
+
t.notOk(is.int(Infinity), 'infinity is not integer');
|
|
269
|
+
t.notOk(is.int(null), 'null is not integer');
|
|
270
|
+
t.notOk(is.int(), 'undefined is not integer');
|
|
269
271
|
t.end();
|
|
270
272
|
});
|
|
271
273
|
|
|
272
274
|
test('is.maximum', function (t) {
|
|
273
|
-
t.
|
|
274
|
-
t.
|
|
275
|
-
t.
|
|
276
|
-
t.
|
|
277
|
-
t.
|
|
278
|
-
|
|
279
|
-
t.throws(function () { return is.maximum(2,
|
|
275
|
+
t.ok(is.maximum(3, [3, 2, 1]), '3 is maximum of [3,2,1]');
|
|
276
|
+
t.ok(is.maximum(3, [1, 2, 3]), '3 is maximum of [1,2,3]');
|
|
277
|
+
t.ok(is.maximum(4, [1, 2, 3]), '4 is maximum of [1,2,3]');
|
|
278
|
+
t.ok(is.maximum('c', ['a', 'b', 'c']), 'c is maximum of [a,b,c]');
|
|
279
|
+
t.notOk(is.maximum(2, [1, 2, 3]), '2 is not maximum of [1,2,3]');
|
|
280
|
+
var error = new TypeError('second argument must be array-like');
|
|
281
|
+
t.throws(function () { return is.maximum(2, null); }, error, 'throws when second value is not array-like');
|
|
282
|
+
t.throws(function () { return is.maximum(2, {}); }, error, 'throws when second value is not array-like');
|
|
280
283
|
t.end();
|
|
281
284
|
});
|
|
282
285
|
|
|
283
286
|
test('is.minimum', function (t) {
|
|
284
|
-
t.
|
|
285
|
-
t.
|
|
286
|
-
t.
|
|
287
|
-
t.
|
|
288
|
-
|
|
289
|
-
t.throws(function () { return is.minimum(2,
|
|
287
|
+
t.ok(is.minimum(1, [1, 2, 3]), '1 is minimum of [1,2,3]');
|
|
288
|
+
t.ok(is.minimum(0, [1, 2, 3]), '0 is minimum of [1,2,3]');
|
|
289
|
+
t.ok(is.minimum('a', ['a', 'b', 'c']), 'a is minimum of [a,b,c]');
|
|
290
|
+
t.notOk(is.minimum(2, [1, 2, 3]), '2 is not minimum of [1,2,3]');
|
|
291
|
+
var error = new TypeError('second argument must be array-like');
|
|
292
|
+
t.throws(function () { return is.minimum(2, null); }, error, 'throws when second value is not array-like');
|
|
293
|
+
t.throws(function () { return is.minimum(2, {}); }, error, 'throws when second value is not array-like');
|
|
290
294
|
t.end();
|
|
291
295
|
});
|
|
292
296
|
|
|
293
297
|
test('is.nan', function (t) {
|
|
294
|
-
t.
|
|
295
|
-
t.
|
|
296
|
-
t.
|
|
297
|
-
t.
|
|
298
|
-
t.
|
|
299
|
-
t.
|
|
300
|
-
t.
|
|
301
|
-
t.
|
|
302
|
-
t.
|
|
303
|
-
t.
|
|
298
|
+
t.ok(is.nan(NaN), 'NaN is not a number');
|
|
299
|
+
t.ok(is.nan('abc'), 'string is not a number');
|
|
300
|
+
t.ok(is.nan(true), 'boolean is not a number');
|
|
301
|
+
t.ok(is.nan({}), 'object is not a number');
|
|
302
|
+
t.ok(is.nan([]), 'array is not a number');
|
|
303
|
+
t.ok(is.nan(function () {}), 'function is not a number');
|
|
304
|
+
t.notOk(is.nan(0), 'zero is a number');
|
|
305
|
+
t.notOk(is.nan(3), 'three is a number');
|
|
306
|
+
t.notOk(is.nan(1.1), '1.1 is a number');
|
|
307
|
+
t.notOk(is.nan(Infinity), 'infinity is a number');
|
|
304
308
|
t.end();
|
|
305
309
|
});
|
|
306
310
|
|
|
307
311
|
test('is.even', function (t) {
|
|
308
|
-
t.
|
|
309
|
-
t.
|
|
310
|
-
t.
|
|
311
|
-
t.
|
|
312
|
-
t.
|
|
313
|
-
t.
|
|
314
|
-
t.
|
|
312
|
+
t.ok(is.even(0), 'zero is even');
|
|
313
|
+
t.ok(is.even(2), 'two is even');
|
|
314
|
+
t.ok(is.even(Infinity), 'infinity is even');
|
|
315
|
+
t.notOk(is.even(1), '1 is not even');
|
|
316
|
+
t.notOk(is.even(), 'undefined is not even');
|
|
317
|
+
t.notOk(is.even(null), 'null is not even');
|
|
318
|
+
t.notOk(is.even(NaN), 'NaN is not even');
|
|
315
319
|
t.end();
|
|
316
320
|
});
|
|
317
321
|
|
|
318
322
|
test('is.odd', function (t) {
|
|
319
|
-
t.
|
|
320
|
-
t.
|
|
321
|
-
t.
|
|
322
|
-
t.
|
|
323
|
-
t.
|
|
324
|
-
t.
|
|
325
|
-
t.
|
|
326
|
-
t.
|
|
323
|
+
t.ok(is.odd(1), 'zero is odd');
|
|
324
|
+
t.ok(is.odd(3), 'two is odd');
|
|
325
|
+
t.ok(is.odd(Infinity), 'infinity is odd');
|
|
326
|
+
t.notOk(is.odd(0), '0 is not odd');
|
|
327
|
+
t.notOk(is.odd(2), '2 is not odd');
|
|
328
|
+
t.notOk(is.odd(), 'undefined is not odd');
|
|
329
|
+
t.notOk(is.odd(null), 'null is not odd');
|
|
330
|
+
t.notOk(is.odd(NaN), 'NaN is not odd');
|
|
327
331
|
t.end();
|
|
328
332
|
});
|
|
329
333
|
|
|
330
334
|
test('is.ge', function (t) {
|
|
331
|
-
t.
|
|
332
|
-
t.
|
|
333
|
-
t.
|
|
334
|
-
t.
|
|
335
|
-
t.
|
|
336
|
-
t.
|
|
337
|
-
t.
|
|
338
|
-
t.
|
|
339
|
-
|
|
340
|
-
t.throws(function () { return is.ge(
|
|
335
|
+
t.ok(is.ge(3, 2), '3 is greater than 2');
|
|
336
|
+
t.notOk(is.ge(2, 3), '2 is not greater than 3');
|
|
337
|
+
t.ok(is.ge(3, 3), '3 is greater than or equal to 3');
|
|
338
|
+
t.ok(is.ge('abc', 'a'), 'abc is greater than a');
|
|
339
|
+
t.ok(is.ge('abc', 'abc'), 'abc is greater than or equal to abc');
|
|
340
|
+
t.notOk(is.ge('a', 'abc'), 'a is not greater than abc');
|
|
341
|
+
t.notOk(is.ge(Infinity, 0), 'infinity is not greater than anything');
|
|
342
|
+
t.notOk(is.ge(0, Infinity), 'anything is not greater than infinity');
|
|
343
|
+
var error = new TypeError('NaN is not a valid value');
|
|
344
|
+
t.throws(function () { return is.ge(NaN, 2); }, error, 'throws when first value is NaN');
|
|
345
|
+
t.throws(function () { return is.ge(2, NaN); }, error, 'throws when second value is NaN');
|
|
341
346
|
t.end();
|
|
342
347
|
});
|
|
343
348
|
|
|
344
349
|
test('is.gt', function (t) {
|
|
345
|
-
t.
|
|
346
|
-
t.
|
|
347
|
-
t.
|
|
348
|
-
t.
|
|
349
|
-
t.
|
|
350
|
-
t.
|
|
351
|
-
t.
|
|
352
|
-
t.
|
|
353
|
-
|
|
354
|
-
t.throws(function () { return is.gt(
|
|
350
|
+
t.ok(is.gt(3, 2), '3 is greater than 2');
|
|
351
|
+
t.notOk(is.gt(2, 3), '2 is not greater than 3');
|
|
352
|
+
t.notOk(is.gt(3, 3), '3 is not greater than 3');
|
|
353
|
+
t.ok(is.gt('abc', 'a'), 'abc is greater than a');
|
|
354
|
+
t.notOk(is.gt('abc', 'abc'), 'abc is not greater than abc');
|
|
355
|
+
t.notOk(is.gt('a', 'abc'), 'a is not greater than abc');
|
|
356
|
+
t.notOk(is.gt(Infinity, 0), 'infinity is not greater than anything');
|
|
357
|
+
t.notOk(is.gt(0, Infinity), 'anything is not greater than infinity');
|
|
358
|
+
var error = new TypeError('NaN is not a valid value');
|
|
359
|
+
t.throws(function () { return is.gt(NaN, 2); }, error, 'throws when first value is NaN');
|
|
360
|
+
t.throws(function () { return is.gt(2, NaN); }, error, 'throws when second value is NaN');
|
|
355
361
|
t.end();
|
|
356
362
|
});
|
|
357
363
|
|
|
358
364
|
test('is.le', function (t) {
|
|
359
|
-
t.
|
|
360
|
-
t.
|
|
361
|
-
t.
|
|
362
|
-
t.
|
|
363
|
-
t.
|
|
364
|
-
t.
|
|
365
|
-
t.
|
|
366
|
-
t.
|
|
367
|
-
|
|
368
|
-
t.throws(function () { return is.le(
|
|
365
|
+
t.ok(is.le(2, 3), '2 is lesser than or equal to 3');
|
|
366
|
+
t.notOk(is.le(3, 2), '3 is not lesser than or equal to 2');
|
|
367
|
+
t.ok(is.le(3, 3), '3 is lesser than or equal to 3');
|
|
368
|
+
t.ok(is.le('a', 'abc'), 'a is lesser than or equal to abc');
|
|
369
|
+
t.ok(is.le('abc', 'abc'), 'abc is lesser than or equal to abc');
|
|
370
|
+
t.notOk(is.le('abc', 'a'), 'abc is not lesser than or equal to a');
|
|
371
|
+
t.notOk(is.le(Infinity, 0), 'infinity is not lesser than or equal to anything');
|
|
372
|
+
t.notOk(is.le(0, Infinity), 'anything is not lesser than or equal to infinity');
|
|
373
|
+
var error = new TypeError('NaN is not a valid value');
|
|
374
|
+
t.throws(function () { return is.le(NaN, 2); }, error, 'throws when first value is NaN');
|
|
375
|
+
t.throws(function () { return is.le(2, NaN); }, error, 'throws when second value is NaN');
|
|
369
376
|
t.end();
|
|
370
377
|
});
|
|
371
378
|
|
|
372
379
|
test('is.lt', function (t) {
|
|
373
|
-
t.
|
|
374
|
-
t.
|
|
375
|
-
t.
|
|
376
|
-
t.
|
|
377
|
-
t.
|
|
378
|
-
t.
|
|
379
|
-
t.
|
|
380
|
-
t.
|
|
381
|
-
|
|
382
|
-
t.throws(function () { return is.lt(
|
|
380
|
+
t.ok(is.lt(2, 3), '2 is lesser than 3');
|
|
381
|
+
t.notOk(is.lt(3, 2), '3 is not lesser than 2');
|
|
382
|
+
t.notOk(is.lt(3, 3), '3 is not lesser than 3');
|
|
383
|
+
t.ok(is.lt('a', 'abc'), 'a is lesser than abc');
|
|
384
|
+
t.notOk(is.lt('abc', 'abc'), 'abc is not lesser than abc');
|
|
385
|
+
t.notOk(is.lt('abc', 'a'), 'abc is not lesser than a');
|
|
386
|
+
t.notOk(is.lt(Infinity, 0), 'infinity is not lesser than anything');
|
|
387
|
+
t.notOk(is.lt(0, Infinity), 'anything is not lesser than infinity');
|
|
388
|
+
var error = new TypeError('NaN is not a valid value');
|
|
389
|
+
t.throws(function () { return is.lt(NaN, 2); }, error, 'throws when first value is NaN');
|
|
390
|
+
t.throws(function () { return is.lt(2, NaN); }, error, 'throws when second value is NaN');
|
|
383
391
|
t.end();
|
|
384
392
|
});
|
|
385
393
|
|
|
386
394
|
test('is.within', function (t) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
t.
|
|
407
|
-
t.
|
|
408
|
-
t.
|
|
409
|
-
t.
|
|
410
|
-
t.
|
|
395
|
+
var nanError = new TypeError('NaN is not a valid value');
|
|
396
|
+
t.throws(function () { return is.within(NaN, 0, 0); }, nanError, 'throws when first value is NaN');
|
|
397
|
+
t.throws(function () { return is.within(0, NaN, 0); }, nanError, 'throws when second value is NaN');
|
|
398
|
+
t.throws(function () { return is.within(0, 0, NaN); }, nanError, 'throws when third value is NaN');
|
|
399
|
+
|
|
400
|
+
var error = new TypeError('all arguments must be numbers');
|
|
401
|
+
t.throws(function () { return is.within('', 0, 0); }, error, 'throws when first value is string');
|
|
402
|
+
t.throws(function () { return is.within(0, '', 0); }, error, 'throws when second value is string');
|
|
403
|
+
t.throws(function () { return is.within(0, 0, ''); }, error, 'throws when third value is string');
|
|
404
|
+
t.throws(function () { return is.within({}, 0, 0); }, error, 'throws when first value is object');
|
|
405
|
+
t.throws(function () { return is.within(0, {}, 0); }, error, 'throws when second value is object');
|
|
406
|
+
t.throws(function () { return is.within(0, 0, {}); }, error, 'throws when third value is object');
|
|
407
|
+
t.throws(function () { return is.within(null, 0, 0); }, error, 'throws when first value is null');
|
|
408
|
+
t.throws(function () { return is.within(0, null, 0); }, error, 'throws when second value is null');
|
|
409
|
+
t.throws(function () { return is.within(0, 0, null); }, error, 'throws when third value is null');
|
|
410
|
+
t.throws(function () { return is.within(undefined, 0, 0); }, error, 'throws when first value is undefined');
|
|
411
|
+
t.throws(function () { return is.within(0, undefined, 0); }, error, 'throws when second value is undefined');
|
|
412
|
+
t.throws(function () { return is.within(0, 0, undefined); }, error, 'throws when third value is undefined');
|
|
413
|
+
|
|
414
|
+
t.ok(is.within(2, 1, 3), '2 is between 1 and 3');
|
|
415
|
+
t.ok(is.within(0, -1, 1), '0 is between -1 and 1');
|
|
416
|
+
t.ok(is.within(2, 0, Infinity), 'infinity always returns true');
|
|
417
|
+
t.ok(is.within(2, Infinity, 2), 'infinity always returns true');
|
|
418
|
+
t.ok(is.within(Infinity, 0, 1), 'infinity always returns true');
|
|
419
|
+
t.notOk(is.within(2, -1, -1), '2 is not between -1 and 1');
|
|
411
420
|
t.end();
|
|
412
421
|
});
|
|
413
422
|
|
|
414
423
|
test('is.object', function (t) {
|
|
415
|
-
t.
|
|
416
|
-
t.
|
|
417
|
-
t.
|
|
418
|
-
t.
|
|
419
|
-
t.
|
|
420
|
-
t.
|
|
421
|
-
t.
|
|
422
|
-
t.
|
|
424
|
+
t.ok(is.object({}), 'object literal is object');
|
|
425
|
+
t.notOk(is.object(), 'undefined is not an object');
|
|
426
|
+
t.notOk(is.object(null), 'null is not an object');
|
|
427
|
+
t.notOk(is.object(true), 'true is not an object');
|
|
428
|
+
t.notOk(is.object(''), 'string is not an object');
|
|
429
|
+
t.notOk(is.object(NaN), 'NaN is not an object');
|
|
430
|
+
t.notOk(is.object(Object), 'object constructor is not an object');
|
|
431
|
+
t.notOk(is.object(function () {}), 'function is not an object');
|
|
432
|
+
t.end();
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test('is.hash', function (t) {
|
|
436
|
+
t.ok(is.hash({}), 'empty object literal is hash');
|
|
437
|
+
t.ok(is.hash({ 1: 2, a: "b" }), 'object literal is hash');
|
|
438
|
+
t.notOk(is.hash(), 'undefined is not a hash');
|
|
439
|
+
t.notOk(is.hash(null), 'null is not a hash');
|
|
440
|
+
t.notOk(is.hash(new Date()), 'date is not a hash');
|
|
441
|
+
t.notOk(is.hash(new String()), 'string object is not a hash');
|
|
442
|
+
t.notOk(is.hash(''), 'string literal is not a hash');
|
|
443
|
+
t.notOk(is.hash(new Number()), 'number object is not a hash');
|
|
444
|
+
t.notOk(is.hash(1), 'number literal is not a hash');
|
|
445
|
+
t.notOk(is.hash(true), 'true is not a hash');
|
|
446
|
+
t.notOk(is.hash(false), 'false is not a hash');
|
|
447
|
+
t.notOk(is.hash(new Boolean()), 'boolean obj is not hash');
|
|
448
|
+
t.notOk(is.hash(false), 'literal false is not hash');
|
|
449
|
+
t.notOk(is.hash(true), 'literal true is not hash');
|
|
450
|
+
if (typeof module !== 'undefined') {
|
|
451
|
+
t.ok(is.hash(module.exports), 'module.exports is a hash');
|
|
452
|
+
}
|
|
453
|
+
if (typeof window !== 'undefined') {
|
|
454
|
+
t.notOk(is.hash(window), 'window is not a hash');
|
|
455
|
+
t.notOk(is.hash(document.createElement('div')), 'element is not a hash');
|
|
456
|
+
} else if (typeof process !== 'undefined') {
|
|
457
|
+
t.notOk(is.hash(global), 'global is not a hash');
|
|
458
|
+
t.notOk(is.hash(process), 'process is not a hash');
|
|
459
|
+
}
|
|
423
460
|
t.end();
|
|
424
461
|
});
|
|
425
462
|
|
|
426
463
|
test('is.regexp', function (t) {
|
|
427
|
-
t.
|
|
428
|
-
t.
|
|
429
|
-
t.
|
|
430
|
-
t.
|
|
431
|
-
t.
|
|
464
|
+
t.ok(is.regexp(/a/g), 'regex literal is regex');
|
|
465
|
+
t.ok(is.regexp(new RegExp('a', 'g')), 'regex object is regex');
|
|
466
|
+
t.notOk(is.regexp(), 'undefined is not regex');
|
|
467
|
+
t.notOk(is.regexp(function () {}), 'function is not regex');
|
|
468
|
+
t.notOk(is.regexp('/a/g'), 'string regex is not regex');
|
|
432
469
|
t.end();
|
|
433
470
|
});
|
|
434
471
|
|
|
435
472
|
test('is.string', function (t) {
|
|
436
|
-
t.
|
|
437
|
-
t.
|
|
438
|
-
t.
|
|
439
|
-
t.
|
|
473
|
+
t.ok(is.string('foo'), 'string literal is string');
|
|
474
|
+
t.ok(is.string(new String('foo')), 'string literal is string');
|
|
475
|
+
t.notOk(is.string(), 'undefined is not string');
|
|
476
|
+
t.notOk(is.string(String), 'string constructor is not string');
|
|
440
477
|
var F = function () {};
|
|
441
478
|
F.prototype = new String();
|
|
442
|
-
t.
|
|
443
|
-
t.end();
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
test('is.hash', function (t) {
|
|
447
|
-
t.true(is.hash({}), 'empty object literal is hash');
|
|
448
|
-
t.true(is.hash({ 1: 2, a: "b" }), 'object literal is hash');
|
|
449
|
-
t.false(is.hash(), 'undefined is not a hash');
|
|
450
|
-
t.false(is.hash(null), 'null is not a hash');
|
|
451
|
-
t.false(is.hash(new Date()), 'date is not a hash');
|
|
452
|
-
t.false(is.hash(new String()), 'string object is not a hash');
|
|
453
|
-
t.false(is.hash(''), 'string literal is not a hash');
|
|
454
|
-
t.false(is.hash(new Number()), 'number object is not a hash');
|
|
455
|
-
t.false(is.hash(1), 'number literal is not a hash');
|
|
456
|
-
t.false(is.hash(true), 'true is not a hash');
|
|
457
|
-
t.false(is.hash(false), 'false is not a hash');
|
|
458
|
-
if (typeof module !== 'undefined') {
|
|
459
|
-
t.true(is.hash(module.exports), 'module.exports is a hash');
|
|
460
|
-
}
|
|
461
|
-
if (typeof window !== 'undefined') {
|
|
462
|
-
t.false(is.hash(window), 'window is not a hash');
|
|
463
|
-
t.false(is.hash(document.createElement('div')), 'element is not a hash');
|
|
464
|
-
} else if (typeof process !== 'undefined') {
|
|
465
|
-
t.false(is.hash(global), 'global is not a hash');
|
|
466
|
-
t.false(is.hash(process), 'process is not a hash');
|
|
467
|
-
}
|
|
479
|
+
t.notOk(is.string(F), 'string subtype is not string');
|
|
468
480
|
t.end();
|
|
469
481
|
});
|
|
470
482
|
|