is 2.2.1 → 3.2.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,43 @@
1
+ 3.2.1 / 2017-02-27
2
+ ==================
3
+ * [Fix] `is.fn`: recognize generator and async functions too (#28)
4
+ * [Tests] up to `node` `v7.5`, `v4.7`; improve test matrix
5
+ * [Dev Deps] update `@ljharb/eslint-config`, `eslint`, `tape`
6
+ * [Docs] improve readme formatting (#27)
7
+
8
+ 3.2.0 / 2016-10-24
9
+ ==================
10
+ * [Fix] fix infinite loop when comparing two empty arrays + fix skipping first element (#24, #25)
11
+ * [New] add `is.primitive`
12
+ * [New] Add `is.date.valid` function and tests (#19)
13
+ * [Tests] use `pretest` for `npm run lint`; add `npm run tests-only`
14
+ * [Tests] up to `node` `v4.6`, `v5.12`, `v6.9`; improve test matrix
15
+ * [Tests] fix description (#18)
16
+ * [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config`
17
+
18
+ 3.1.0 / 2015-09-20
19
+ ==================
20
+ * [Enhancement]: `is.array`: Prefer `Array.isArray` when present
21
+ * [Fix] Deprecate `is.boolean`/`is.int` (ES3 syntax errors)
22
+ * [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
23
+ * [Refactor] Don't use yoda conditions
24
+ * [Refactor] `is.equal` can return earlier in some cases (#16)
25
+ * [Tests] Quote "throws" (ES3 syntax error)
26
+ * [Tests] up to `io.js` `v3.3`, up to `node` `v4.1`
27
+ * [Dev Deps] add `npm run eslint`
28
+ * [Dev Deps] update `tape`, `covert`, `jscs`
29
+
30
+ 3.0.1 / 2015-02-22
31
+ ==================
32
+ * Version bump to resolve npm bug with v3.0.0
33
+
34
+ 3.0.0 / 2015-02-21
35
+ ==================
36
+ * is.empty should return true for falsy values ([#13](https://github.com/enricomarino/is/issues/13), [#14](https://github.com/enricomarino/is/issues/14))
37
+ * All grade A-supported `node`/`iojs` versions now ship with an `npm` that understands `^`.
38
+ * Test on `iojs` `v1.2` and `v1.3`, `node` `v0.12`; speed up builds; allow failures on all but two latest minor versions.
39
+ * Update `jscs`
40
+
1
41
  2.2.1 / 2015-02-06
2
42
  ==================
3
43
  * Update `tape`, `jscs`
package/README.md CHANGED
@@ -57,7 +57,8 @@ $ component install enricomarino/is
57
57
 
58
58
  ### boolean
59
59
 
60
- - ``is.boolean`` (value)
60
+ - ``is.bool`` (value)
61
+ - ``is.boolean`` (value) - deprecated, because in ES3 browsers, "boolean" is a reserved word
61
62
  - ``is.false`` (value) - deprecated, because in ES3 browsers, "false" is a reserved word
62
63
  - ``is.true`` (value) - deprecated, because in ES3 browsers, "true" is a reserved word
63
64
 
@@ -71,7 +72,7 @@ $ component install enricomarino/is
71
72
 
72
73
  ### error
73
74
 
74
- - is.error (value)
75
+ - ``is.error`` (value)
75
76
 
76
77
  ### function
77
78
 
@@ -84,7 +85,8 @@ $ component install enricomarino/is
84
85
  - ``is.infinite`` (value)
85
86
  - ``is.decimal`` (value)
86
87
  - ``is.divisibleBy`` (value, n)
87
- - ``is.int`` (value)
88
+ - ``is.integer`` (value)
89
+ - ``is.int`` (value) - deprecated, because in ES3 browsers, "int" is a reserved word
88
90
  - ``is.maximum`` (value, others)
89
91
  - ``is.minimum`` (value, others)
90
92
  - ``is.nan`` (value)
@@ -122,7 +124,7 @@ $ component install enricomarino/is
122
124
  - [Jordan Harband](https://github.com/ljharb)
123
125
 
124
126
  [npm-url]: https://npmjs.org/package/is
125
- [npm-version-svg]: http://vb.teelaun.ch/enricomarino/is.svg
127
+ [npm-version-svg]: http://versionbadg.es/enricomarino/is.svg
126
128
  [travis-svg]: https://travis-ci.org/enricomarino/is.svg
127
129
  [travis-url]: https://travis-ci.org/enricomarino/is
128
130
  [deps-svg]: https://david-dm.org/enricomarino/is.svg
package/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ /* globals window, HTMLElement */
2
+
3
+ 'use strict';
1
4
 
2
5
  /**!
3
6
  * is
@@ -18,7 +21,7 @@ var isActualNaN = function (value) {
18
21
  return value !== value;
19
22
  };
20
23
  var NON_HOST_TYPES = {
21
- boolean: 1,
24
+ 'boolean': 1,
22
25
  number: 1,
23
26
  string: 1,
24
27
  undefined: 1
@@ -31,7 +34,7 @@ var hexRegex = /^[A-Fa-f0-9]+$/;
31
34
  * Expose `is`
32
35
  */
33
36
 
34
- var is = module.exports = {};
37
+ var is = {};
35
38
 
36
39
  /**
37
40
  * Test general.
@@ -77,18 +80,20 @@ is.empty = function (value) {
77
80
  var type = toStr.call(value);
78
81
  var key;
79
82
 
80
- if ('[object Array]' === type || '[object Arguments]' === type || '[object String]' === type) {
83
+ if (type === '[object Array]' || type === '[object Arguments]' || type === '[object String]') {
81
84
  return value.length === 0;
82
85
  }
83
86
 
84
- if ('[object Object]' === type) {
87
+ if (type === '[object Object]') {
85
88
  for (key in value) {
86
- if (owns.call(value, key)) { return false; }
89
+ if (owns.call(value, key)) {
90
+ return false;
91
+ }
87
92
  }
88
93
  return true;
89
94
  }
90
95
 
91
- return false;
96
+ return !value;
92
97
  };
93
98
 
94
99
  /**
@@ -100,9 +105,8 @@ is.empty = function (value) {
100
105
  * @return {Boolean} true if `value` is equal to `other`, false otherwise
101
106
  */
102
107
 
103
- is.equal = function (value, other) {
104
- var strictlyEqual = value === other;
105
- if (strictlyEqual) {
108
+ is.equal = function equal(value, other) {
109
+ if (value === other) {
106
110
  return true;
107
111
  }
108
112
 
@@ -113,7 +117,7 @@ is.equal = function (value, other) {
113
117
  return false;
114
118
  }
115
119
 
116
- if ('[object Object]' === type) {
120
+ if (type === '[object Object]') {
117
121
  for (key in value) {
118
122
  if (!is.equal(value[key], other[key]) || !(key in other)) {
119
123
  return false;
@@ -127,12 +131,12 @@ is.equal = function (value, other) {
127
131
  return true;
128
132
  }
129
133
 
130
- if ('[object Array]' === type) {
134
+ if (type === '[object Array]') {
131
135
  key = value.length;
132
136
  if (key !== other.length) {
133
137
  return false;
134
138
  }
135
- while (--key) {
139
+ while (key--) {
136
140
  if (!is.equal(value[key], other[key])) {
137
141
  return false;
138
142
  }
@@ -140,15 +144,15 @@ is.equal = function (value, other) {
140
144
  return true;
141
145
  }
142
146
 
143
- if ('[object Function]' === type) {
147
+ if (type === '[object Function]') {
144
148
  return value.prototype === other.prototype;
145
149
  }
146
150
 
147
- if ('[object Date]' === type) {
151
+ if (type === '[object Date]') {
148
152
  return value.getTime() === other.getTime();
149
153
  }
150
154
 
151
- return strictlyEqual;
155
+ return false;
152
156
  };
153
157
 
154
158
  /**
@@ -219,7 +223,7 @@ is.undef = is.undefined = function (value) {
219
223
  */
220
224
 
221
225
  is.args = is.arguments = function (value) {
222
- var isStandardArguments = '[object Arguments]' === toStr.call(value);
226
+ var isStandardArguments = toStr.call(value) === '[object Arguments]';
223
227
  var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
224
228
  return isStandardArguments || isOldArguments;
225
229
  };
@@ -237,8 +241,8 @@ is.args = is.arguments = function (value) {
237
241
  * @api public
238
242
  */
239
243
 
240
- is.array = function (value) {
241
- return '[object Array]' === toStr.call(value);
244
+ is.array = Array.isArray || function (value) {
245
+ return toStr.call(value) === '[object Array]';
242
246
  };
243
247
 
244
248
  /**
@@ -275,7 +279,7 @@ is.array.empty = function (value) {
275
279
  */
276
280
 
277
281
  is.arraylike = function (value) {
278
- return !!value && !is.boolean(value)
282
+ return !!value && !is.bool(value)
279
283
  && owns.call(value, 'length')
280
284
  && isFinite(value.length)
281
285
  && is.number(value.length)
@@ -287,7 +291,7 @@ is.arraylike = function (value) {
287
291
  */
288
292
 
289
293
  /**
290
- * is.boolean
294
+ * is.bool
291
295
  * Test if `value` is a boolean.
292
296
  *
293
297
  * @param {Mixed} value value to test
@@ -295,8 +299,8 @@ is.arraylike = function (value) {
295
299
  * @api public
296
300
  */
297
301
 
298
- is.boolean = function (value) {
299
- return '[object Boolean]' === toStr.call(value);
302
+ is.bool = is['boolean'] = function (value) {
303
+ return toStr.call(value) === '[object Boolean]';
300
304
  };
301
305
 
302
306
  /**
@@ -309,7 +313,7 @@ is.boolean = function (value) {
309
313
  */
310
314
 
311
315
  is['false'] = function (value) {
312
- return is.boolean(value) && Boolean(Number(value)) === false;
316
+ return is.bool(value) && Boolean(Number(value)) === false;
313
317
  };
314
318
 
315
319
  /**
@@ -322,7 +326,7 @@ is['false'] = function (value) {
322
326
  */
323
327
 
324
328
  is['true'] = function (value) {
325
- return is.boolean(value) && Boolean(Number(value)) === true;
329
+ return is.bool(value) && Boolean(Number(value)) === true;
326
330
  };
327
331
 
328
332
  /**
@@ -339,7 +343,18 @@ is['true'] = function (value) {
339
343
  */
340
344
 
341
345
  is.date = function (value) {
342
- return '[object Date]' === toStr.call(value);
346
+ return toStr.call(value) === '[object Date]';
347
+ };
348
+
349
+ /**
350
+ * is.date.valid
351
+ * Test if `value` is a valid date.
352
+ *
353
+ * @param {Mixed} value value to test
354
+ * @returns {Boolean} true if `value` is a valid date, false otherwise
355
+ */
356
+ is.date.valid = function (value) {
357
+ return is.date(value) && !isNaN(Number(value));
343
358
  };
344
359
 
345
360
  /**
@@ -376,7 +391,7 @@ is.element = function (value) {
376
391
  */
377
392
 
378
393
  is.error = function (value) {
379
- return '[object Error]' === toStr.call(value);
394
+ return toStr.call(value) === '[object Error]';
380
395
  };
381
396
 
382
397
  /**
@@ -394,7 +409,11 @@ is.error = function (value) {
394
409
 
395
410
  is.fn = is['function'] = function (value) {
396
411
  var isAlert = typeof window !== 'undefined' && value === window.alert;
397
- return isAlert || '[object Function]' === toStr.call(value);
412
+ if (isAlert) {
413
+ return true;
414
+ }
415
+ var str = toStr.call(value);
416
+ return str === '[object Function]' || str === '[object GeneratorFunction]' || str === '[object AsyncFunction]';
398
417
  };
399
418
 
400
419
  /**
@@ -411,7 +430,7 @@ is.fn = is['function'] = function (value) {
411
430
  */
412
431
 
413
432
  is.number = function (value) {
414
- return '[object Number]' === toStr.call(value);
433
+ return toStr.call(value) === '[object Number]';
415
434
  };
416
435
 
417
436
  /**
@@ -457,7 +476,7 @@ is.divisibleBy = function (value, n) {
457
476
  };
458
477
 
459
478
  /**
460
- * is.int
479
+ * is.integer
461
480
  * Test if `value` is an integer.
462
481
  *
463
482
  * @param value to test
@@ -465,7 +484,7 @@ is.divisibleBy = function (value, n) {
465
484
  * @api public
466
485
  */
467
486
 
468
- is.int = function (value) {
487
+ is.integer = is['int'] = function (value) {
469
488
  return is.number(value) && !isActualNaN(value) && value % 1 === 0;
470
489
  };
471
490
 
@@ -662,9 +681,26 @@ is.within = function (value, start, finish) {
662
681
  * @return {Boolean} true if `value` is an object, false otherwise
663
682
  * @api public
664
683
  */
665
-
666
684
  is.object = function (value) {
667
- return '[object Object]' === toStr.call(value);
685
+ return toStr.call(value) === '[object Object]';
686
+ };
687
+
688
+ /**
689
+ * is.primitive
690
+ * Test if `value` is a primitive.
691
+ *
692
+ * @param {Mixed} value value to test
693
+ * @return {Boolean} true if `value` is a primitive, false otherwise
694
+ * @api public
695
+ */
696
+ is.primitive = function isPrimitive(value) {
697
+ if (!value) {
698
+ return true;
699
+ }
700
+ if (typeof value === 'object' || is.object(value) || is.fn(value) || is.array(value)) {
701
+ return false;
702
+ }
703
+ return true;
668
704
  };
669
705
 
670
706
  /**
@@ -694,7 +730,7 @@ is.hash = function (value) {
694
730
  */
695
731
 
696
732
  is.regexp = function (value) {
697
- return '[object RegExp]' === toStr.call(value);
733
+ return toStr.call(value) === '[object RegExp]';
698
734
  };
699
735
 
700
736
  /**
@@ -711,7 +747,7 @@ is.regexp = function (value) {
711
747
  */
712
748
 
713
749
  is.string = function (value) {
714
- return '[object String]' === toStr.call(value);
750
+ return toStr.call(value) === '[object String]';
715
751
  };
716
752
 
717
753
  /**
@@ -761,3 +797,4 @@ is.symbol = function (value) {
761
797
  return typeof Symbol === 'function' && toStr.call(value) === '[object Symbol]' && typeof symbolValueOf.call(value) === 'symbol';
762
798
  };
763
799
 
800
+ module.exports = is;
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "is",
3
- "version": "2.2.1",
3
+ "version": "3.2.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
- "test": "npm run lint && node test/index.js",
6
+ "prepublish": "safe-publish-latest",
7
+ "pretest": "npm run lint",
8
+ "test": "npm run --silent tests-only",
9
+ "tests-only": "node test/index.js",
7
10
  "coverage": "covert test/index.js",
8
11
  "coverage-quiet": "covert test/index.js --quiet",
9
- "lint": "jscs *.js */*.js"
12
+ "lint": "npm run jscs && npm run eslint",
13
+ "jscs": "jscs *.js */*.js",
14
+ "eslint": "eslint *.js */*.js"
10
15
  },
11
16
  "author": {
12
17
  "name": "Enrico Marino",
@@ -32,10 +37,14 @@
32
37
  ],
33
38
  "dependencies": {},
34
39
  "devDependencies": {
35
- "tape": "~3.5.0",
36
- "foreach": "~2.0.5",
37
- "covert": "1.0.0",
38
- "jscs": "~1.10.0"
40
+ "@ljharb/eslint-config": "^11.0.0",
41
+ "covert": "^1.1.0",
42
+ "eslint": "^3.16.1",
43
+ "foreach": "^2.0.5",
44
+ "jscs": "^3.0.7",
45
+ "make-generator-function": "^1.1.0",
46
+ "safe-publish-latest": "^1.1.1",
47
+ "tape": "^4.6.3"
39
48
  },
40
49
  "testling": {
41
50
  "files": "test/index.js",
@@ -58,4 +67,3 @@
58
67
  "node": "*"
59
68
  }
60
69
  }
61
-
package/test/index.js CHANGED
@@ -1,9 +1,15 @@
1
+ /* globals window, document, HTMLElement */
2
+
3
+ 'use strict';
4
+
1
5
  var test = require('tape');
2
6
  var is = require('../index.js');
3
7
 
4
8
  var forEach = require('foreach');
5
9
  var toStr = Object.prototype.toString;
6
10
 
11
+ var genFn = require('make-generator-function');
12
+
7
13
  test('is.type', function (t) {
8
14
  var booleans = [true, false];
9
15
  forEach(booleans, function (boolean) {
@@ -41,19 +47,26 @@ test('is.undef', function (t) {
41
47
  test('is.defined', function (t) {
42
48
  t.notOk(is.defined(), 'undefined is not defined');
43
49
  t.ok(is.defined(null), 'null is defined');
44
- t.ok(is.defined({}), 'object is undefined');
50
+ t.ok(is.defined({}), 'object is defined');
45
51
  t.end();
46
52
  });
47
53
 
48
54
  test('is.empty', function (t) {
49
55
  t.ok(is.empty(''), 'empty string is empty');
50
- t.ok(is.empty(new String()), 'empty String object is empty');
56
+ t.ok(is.empty(Object('')), 'empty String object is empty');
51
57
  t.ok(is.empty([]), 'empty array is empty');
52
58
  t.ok(is.empty({}), 'empty object is empty');
53
- (function () { t.ok(is.empty(arguments), 'empty arguments is empty'); }());
59
+ t.ok(is.empty(null), 'null is empty');
60
+ t.ok(is.empty(), 'undefined is empty');
61
+ t.ok(is.empty(undefined), 'undefined is empty');
62
+ t.ok(is.empty(false), 'false is empty');
63
+ t.ok(is.empty(0), '0 is empty');
64
+ t.ok(is.empty(NaN), 'nan is empty');
65
+ (function () {
66
+ t.ok(is.empty(arguments), 'empty arguments is empty');
67
+ }());
54
68
  t.notOk(is.empty({ a: 1 }), 'nonempty object is not empty');
55
69
  t.notOk(is.empty(true), 'true is not empty');
56
- t.notOk(is.empty(false), 'false is not empty');
57
70
  t.notOk(is.empty(/a/g), 'regex is not empty');
58
71
  t.notOk(is.empty(new Date()), 'date is not empty');
59
72
  t.end();
@@ -72,8 +85,10 @@ test('is.equal', function (t) {
72
85
  t.test('arrays', function (at) {
73
86
  at.ok(is.equal([1, 2, 3], [1, 2, 3]), 'arrays are shallowly equal');
74
87
  at.ok(is.equal([1, 2, [3, 4]], [1, 2, [3, 4]]), 'arrays are deep equal');
88
+ at.notOk(is.equal([1, 2, 3], [5, 2, 3]), 'inequal arrays are not equal');
75
89
  at.notOk(is.equal([1, 2], [2, 3]), 'inequal arrays are not equal');
76
90
  at.notOk(is.equal([1, 2, 3], [2, 3]), 'inequal length arrays are not equal');
91
+ at.ok(is.equal([], []), 'empty arrays are equal');
77
92
 
78
93
  var arr = [1, 2];
79
94
  at.ok(is.equal(arr, arr), 'array is equal to itself');
@@ -88,7 +103,7 @@ test('is.equal', function (t) {
88
103
  setTimeout(function () {
89
104
  dt.notOk(is.equal(now, new Date()), 'two inequal date objects are not equal');
90
105
  dt.end();
91
- }, 1);
106
+ }, 10);
92
107
  });
93
108
 
94
109
  t.test('plain objects', function (ot) {
@@ -170,11 +185,15 @@ test('is.nil', function (t) {
170
185
 
171
186
  test('is.args', function (t) {
172
187
  t.notOk(is.args([]), 'array is not arguments');
173
- (function () { t.ok(is.args(arguments), 'arguments is arguments'); }());
174
- (function () { t.notOk(is.args(Array.prototype.slice.call(arguments)), 'sliced arguments is not arguments'); }());
188
+ (function () {
189
+ t.ok(is.args(arguments), 'arguments is arguments');
190
+ }());
191
+ (function () {
192
+ t.notOk(is.args(Array.prototype.slice.call(arguments)), 'sliced arguments is not arguments');
193
+ }());
175
194
  var fakeOldArguments = {
176
- length: 3,
177
- callee: function () {}
195
+ callee: function () {},
196
+ length: 3
178
197
  };
179
198
  t.ok(is.args(fakeOldArguments), 'old-style arguments object is arguments');
180
199
  t.end();
@@ -182,22 +201,31 @@ test('is.args', function (t) {
182
201
 
183
202
  test('is.args.empty', function (t) {
184
203
  t.notOk(is.args.empty([]), 'empty array is not empty arguments');
185
- (function () { t.ok(is.args.empty(arguments), 'empty arguments is empty arguments'); }());
186
- (function () { t.notOk(is.args.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is not empty arguments'); }());
204
+ (function () {
205
+ t.ok(is.args.empty(arguments), 'empty arguments is empty arguments');
206
+ }());
207
+ (function () {
208
+ t.notOk(is.args.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is not empty arguments');
209
+ }());
187
210
  t.end();
188
211
  });
189
212
 
190
-
191
213
  test('is.array', function (t) {
192
214
  t.ok(is.array([]), 'array is array');
193
- (function () { t.ok(is.array(Array.prototype.slice.call(arguments)), 'sliced arguments is array'); }());
215
+ (function () {
216
+ t.ok(is.array(Array.prototype.slice.call(arguments)), 'sliced arguments is array');
217
+ }());
194
218
  t.end();
195
219
  });
196
220
 
197
221
  test('is.array.empty', function (t) {
198
222
  t.ok(is.array.empty([]), 'empty array is empty array');
199
- (function () { t.notOk(is.array.empty(arguments), 'empty arguments is not empty array'); }());
200
- (function () { t.ok(is.array.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is empty array'); }());
223
+ (function () {
224
+ t.notOk(is.array.empty(arguments), 'empty arguments is not empty array');
225
+ }());
226
+ (function () {
227
+ t.ok(is.array.empty(Array.prototype.slice.call(arguments)), 'empty sliced arguments is empty array');
228
+ }());
201
229
  t.end();
202
230
  });
203
231
 
@@ -213,25 +241,29 @@ test('is.isarraylike', function (t) {
213
241
  t.notOk(is.arraylike({ length: 'foo' }), 'object with string length is not array-like');
214
242
  t.notOk(is.arraylike({ length: '' }), 'object with empty string length is not array-like');
215
243
  t.ok(is.arraylike([]), 'array is array-like');
216
- (function () { t.ok(is.arraylike(arguments), 'empty arguments is array-like'); }());
217
- (function () { t.ok(is.arraylike(arguments), 'nonempty arguments is array-like'); }(1, 2, 3));
244
+ (function () {
245
+ t.ok(is.arraylike(arguments), 'empty arguments is array-like');
246
+ }());
247
+ (function () {
248
+ t.ok(is.arraylike(arguments), 'nonempty arguments is array-like');
249
+ }(1, 2, 3));
218
250
  t.end();
219
251
  });
220
252
 
221
- test('is.boolean', function (t) {
222
- t.ok(is.boolean(true), 'literal true is a boolean');
223
- t.ok(is.boolean(false), 'literal false is a boolean');
224
- t.ok(is.boolean(new Boolean(true)), 'object true is a boolean');
225
- t.ok(is.boolean(new Boolean(false)), 'object false is a boolean');
226
- t.notOk(is.boolean(), 'undefined is not a boolean');
227
- t.notOk(is.boolean(null), 'null is not a boolean');
253
+ test('is.bool', function (t) {
254
+ t.ok(is.bool(true), 'literal true is a boolean');
255
+ t.ok(is.bool(false), 'literal false is a boolean');
256
+ t.ok(is.bool(Object(true)), 'object true is a boolean');
257
+ t.ok(is.bool(Object(false)), 'object false is a boolean');
258
+ t.notOk(is.bool(), 'undefined is not a boolean');
259
+ t.notOk(is.bool(null), 'null is not a boolean');
228
260
  t.end();
229
261
  });
230
262
 
231
263
  test('is.false', function (t) {
232
264
  var isFalse = is['false'];
233
265
  t.ok(isFalse(false), 'false is false');
234
- t.ok(isFalse(new Boolean(false)), 'object false is false');
266
+ t.ok(isFalse(Object(false)), 'object false is false');
235
267
  t.notOk(isFalse(true), 'true is not false');
236
268
  t.notOk(isFalse(), 'undefined is not false');
237
269
  t.notOk(isFalse(null), 'null is not false');
@@ -242,7 +274,7 @@ test('is.false', function (t) {
242
274
  test('is.true', function (t) {
243
275
  var isTrue = is['true'];
244
276
  t.ok(isTrue(true), 'true is true');
245
- t.ok(isTrue(new Boolean(true)), 'object true is true');
277
+ t.ok(isTrue(Object(true)), 'object true is true');
246
278
  t.notOk(isTrue(false), 'false is not true');
247
279
  t.notOk(isTrue(), 'undefined is not true');
248
280
  t.notOk(isTrue(null), 'null is not true');
@@ -263,15 +295,22 @@ test('is.date', function (t) {
263
295
  t.end();
264
296
  });
265
297
 
298
+ test('is.date.valid', function (t) {
299
+ t.ok(is.date.valid(new Date()), 'new Date() is a valid date');
300
+ t.notOk(is.date.valid(new Date('')), 'new Date("") is not a valid date');
301
+ t.end();
302
+ });
303
+
266
304
  test('is.element', function (t) {
267
305
  t.notOk(is.element(), 'undefined is not element');
268
- if (typeof HTMLElement !== 'undefined') {
306
+
307
+ t.test('when HTMLElement exists', { skip: typeof HTMLElement === 'undefined' }, function (st) {
269
308
  var element = document.createElement('div');
270
- t.ok(is.element(element), 'HTMLElement is element');
271
- t.notOk(is.element({ nodeType: 1 }), 'object with nodeType is not element');
272
- } else {
273
- t.ok(true, 'Skipping is.element test in a non-browser environment');
274
- }
309
+ st.ok(is.element(element), 'HTMLElement is element');
310
+ st.notOk(is.element({ nodeType: 1 }), 'object with nodeType is not element');
311
+ st.end();
312
+ });
313
+
275
314
  t.end();
276
315
  });
277
316
 
@@ -279,7 +318,11 @@ test('is.error', function (t) {
279
318
  var err = new Error('foo');
280
319
  t.ok(is.error(err), 'Error is error');
281
320
  t.notOk(is.error({}), 'object is not error');
282
- var objWithErrorToString = { toString: function () { return '[object Error]'; } };
321
+ var objWithErrorToString = {
322
+ toString: function () {
323
+ return '[object Error]';
324
+ }
325
+ };
283
326
  t.equal(String(objWithErrorToString), toStr.call(new Error()), 'obj has Error\'s toString');
284
327
  t.notOk(is.error(objWithErrorToString), 'object with Error\'s toString is not error');
285
328
  t.end();
@@ -288,13 +331,18 @@ test('is.error', function (t) {
288
331
  test('is.fn', function (t) {
289
332
  t.equal(is['function'], is.fn, 'alias works');
290
333
  t.ok(is.fn(function () {}), 'function is function');
291
- t.ok(is.fn(console.log), 'console.log is function');
292
334
  if (typeof window !== 'undefined') {
293
335
  // in IE7/8, typeof alert === 'object'
294
336
  t.ok(is.fn(window.alert), 'window.alert is function');
295
337
  }
296
338
  t.notOk(is.fn({}), 'object is not function');
297
339
  t.notOk(is.fn(null), 'null is not function');
340
+
341
+ t.test('generator functions', { skip: !genFn }, function (st) {
342
+ t.ok(is.fn(genFn), 'generator function is function');
343
+ st.end();
344
+ });
345
+
298
346
  t.end();
299
347
  });
300
348
 
@@ -305,7 +353,7 @@ test('is.number', function (t) {
305
353
  t.ok(is.number(NaN), 'NaN is number');
306
354
  t.ok(is.number(Infinity), 'infinity is number');
307
355
  t.ok(is.number(-Infinity), 'negative infinity is number');
308
- t.ok(is.number(new Number(42)), 'object number is number');
356
+ t.ok(is.number(Object(42)), 'object number is number');
309
357
  t.notOk(is.number(), 'undefined is not number');
310
358
  t.notOk(is.number(null), 'null is not number');
311
359
  t.notOk(is.number(true), 'true is not number');
@@ -344,14 +392,14 @@ test('is.divisibleBy', function (t) {
344
392
  t.end();
345
393
  });
346
394
 
347
- test('is.int', function (t) {
348
- t.ok(is.int(0), '0 is integer');
349
- t.ok(is.int(3), '3 is integer');
350
- t.notOk(is.int(1.1), '1.1 is not integer');
351
- t.notOk(is.int(NaN), 'NaN is not integer');
352
- t.notOk(is.int(Infinity), 'infinity is not integer');
353
- t.notOk(is.int(null), 'null is not integer');
354
- t.notOk(is.int(), 'undefined is not integer');
395
+ test('is.integer', function (t) {
396
+ t.ok(is.integer(0), '0 is integer');
397
+ t.ok(is.integer(3), '3 is integer');
398
+ t.notOk(is.integer(1.1), '1.1 is not integer');
399
+ t.notOk(is.integer(NaN), 'NaN is not integer');
400
+ t.notOk(is.integer(Infinity), 'infinity is not integer');
401
+ t.notOk(is.integer(null), 'null is not integer');
402
+ t.notOk(is.integer(), 'undefined is not integer');
355
403
  t.end();
356
404
  });
357
405
 
@@ -363,11 +411,11 @@ test('is.maximum', function (t) {
363
411
  t.notOk(is.maximum(2, [1, 2, 3]), '2 is not maximum of [1,2,3]');
364
412
 
365
413
  var nanError = new TypeError('NaN is not a valid value');
366
- t.throws(function () { return is.maximum(NaN); }, nanError, 'throws when first value is NaN');
414
+ t['throws'](function () { return is.maximum(NaN); }, nanError, 'throws when first value is NaN');
367
415
 
368
416
  var error = new TypeError('second argument must be array-like');
369
- t.throws(function () { return is.maximum(2, null); }, error, 'throws when second value is not array-like');
370
- t.throws(function () { return is.maximum(2, {}); }, error, 'throws when second value is not array-like');
417
+ t['throws'](function () { return is.maximum(2, null); }, error, 'throws when second value is not array-like');
418
+ t['throws'](function () { return is.maximum(2, {}); }, error, 'throws when second value is not array-like');
371
419
  t.end();
372
420
  });
373
421
 
@@ -378,11 +426,11 @@ test('is.minimum', function (t) {
378
426
  t.notOk(is.minimum(2, [1, 2, 3]), '2 is not minimum of [1,2,3]');
379
427
 
380
428
  var nanError = new TypeError('NaN is not a valid value');
381
- t.throws(function () { return is.minimum(NaN); }, nanError, 'throws when first value is NaN');
429
+ t['throws'](function () { return is.minimum(NaN); }, nanError, 'throws when first value is NaN');
382
430
 
383
431
  var error = new TypeError('second argument must be array-like');
384
- t.throws(function () { return is.minimum(2, null); }, error, 'throws when second value is not array-like');
385
- t.throws(function () { return is.minimum(2, {}); }, error, 'throws when second value is not array-like');
432
+ t['throws'](function () { return is.minimum(2, null); }, error, 'throws when second value is not array-like');
433
+ t['throws'](function () { return is.minimum(2, {}); }, error, 'throws when second value is not array-like');
386
434
  t.end();
387
435
  });
388
436
 
@@ -433,8 +481,8 @@ test('is.ge', function (t) {
433
481
  t.notOk(is.ge(Infinity, 0), 'infinity is not greater than anything');
434
482
  t.notOk(is.ge(0, Infinity), 'anything is not greater than infinity');
435
483
  var error = new TypeError('NaN is not a valid value');
436
- t.throws(function () { return is.ge(NaN, 2); }, error, 'throws when first value is NaN');
437
- t.throws(function () { return is.ge(2, NaN); }, error, 'throws when second value is NaN');
484
+ t['throws'](function () { return is.ge(NaN, 2); }, error, 'throws when first value is NaN');
485
+ t['throws'](function () { return is.ge(2, NaN); }, error, 'throws when second value is NaN');
438
486
  t.end();
439
487
  });
440
488
 
@@ -448,8 +496,8 @@ test('is.gt', function (t) {
448
496
  t.notOk(is.gt(Infinity, 0), 'infinity is not greater than anything');
449
497
  t.notOk(is.gt(0, Infinity), 'anything is not greater than infinity');
450
498
  var error = new TypeError('NaN is not a valid value');
451
- t.throws(function () { return is.gt(NaN, 2); }, error, 'throws when first value is NaN');
452
- t.throws(function () { return is.gt(2, NaN); }, error, 'throws when second value is NaN');
499
+ t['throws'](function () { return is.gt(NaN, 2); }, error, 'throws when first value is NaN');
500
+ t['throws'](function () { return is.gt(2, NaN); }, error, 'throws when second value is NaN');
453
501
  t.end();
454
502
  });
455
503
 
@@ -463,8 +511,8 @@ test('is.le', function (t) {
463
511
  t.notOk(is.le(Infinity, 0), 'infinity is not lesser than or equal to anything');
464
512
  t.notOk(is.le(0, Infinity), 'anything is not lesser than or equal to infinity');
465
513
  var error = new TypeError('NaN is not a valid value');
466
- t.throws(function () { return is.le(NaN, 2); }, error, 'throws when first value is NaN');
467
- t.throws(function () { return is.le(2, NaN); }, error, 'throws when second value is NaN');
514
+ t['throws'](function () { return is.le(NaN, 2); }, error, 'throws when first value is NaN');
515
+ t['throws'](function () { return is.le(2, NaN); }, error, 'throws when second value is NaN');
468
516
  t.end();
469
517
  });
470
518
 
@@ -478,30 +526,36 @@ test('is.lt', function (t) {
478
526
  t.notOk(is.lt(Infinity, 0), 'infinity is not lesser than anything');
479
527
  t.notOk(is.lt(0, Infinity), 'anything is not lesser than infinity');
480
528
  var error = new TypeError('NaN is not a valid value');
481
- t.throws(function () { return is.lt(NaN, 2); }, error, 'throws when first value is NaN');
482
- t.throws(function () { return is.lt(2, NaN); }, error, 'throws when second value is NaN');
529
+ t['throws'](function () { return is.lt(NaN, 2); }, error, 'throws when first value is NaN');
530
+ t['throws'](function () { return is.lt(2, NaN); }, error, 'throws when second value is NaN');
483
531
  t.end();
484
532
  });
485
533
 
486
534
  test('is.within', function (t) {
487
- var nanError = new TypeError('NaN is not a valid value');
488
- t.throws(function () { return is.within(NaN, 0, 0); }, nanError, 'throws when first value is NaN');
489
- t.throws(function () { return is.within(0, NaN, 0); }, nanError, 'throws when second value is NaN');
490
- t.throws(function () { return is.within(0, 0, NaN); }, nanError, 'throws when third value is NaN');
491
-
492
- var error = new TypeError('all arguments must be numbers');
493
- t.throws(function () { return is.within('', 0, 0); }, error, 'throws when first value is string');
494
- t.throws(function () { return is.within(0, '', 0); }, error, 'throws when second value is string');
495
- t.throws(function () { return is.within(0, 0, ''); }, error, 'throws when third value is string');
496
- t.throws(function () { return is.within({}, 0, 0); }, error, 'throws when first value is object');
497
- t.throws(function () { return is.within(0, {}, 0); }, error, 'throws when second value is object');
498
- t.throws(function () { return is.within(0, 0, {}); }, error, 'throws when third value is object');
499
- t.throws(function () { return is.within(null, 0, 0); }, error, 'throws when first value is null');
500
- t.throws(function () { return is.within(0, null, 0); }, error, 'throws when second value is null');
501
- t.throws(function () { return is.within(0, 0, null); }, error, 'throws when third value is null');
502
- t.throws(function () { return is.within(undefined, 0, 0); }, error, 'throws when first value is undefined');
503
- t.throws(function () { return is.within(0, undefined, 0); }, error, 'throws when second value is undefined');
504
- t.throws(function () { return is.within(0, 0, undefined); }, error, 'throws when third value is undefined');
535
+ t.test('throws on NaN', function (st) {
536
+ var nanError = new TypeError('NaN is not a valid value');
537
+ st['throws'](function () { return is.within(NaN, 0, 0); }, nanError, 'throws when first value is NaN');
538
+ st['throws'](function () { return is.within(0, NaN, 0); }, nanError, 'throws when second value is NaN');
539
+ st['throws'](function () { return is.within(0, 0, NaN); }, nanError, 'throws when third value is NaN');
540
+ st.end();
541
+ });
542
+
543
+ t.test('throws on non-number', function (st) {
544
+ var error = new TypeError('all arguments must be numbers');
545
+ st['throws'](function () { return is.within('', 0, 0); }, error, 'throws when first value is string');
546
+ st['throws'](function () { return is.within(0, '', 0); }, error, 'throws when second value is string');
547
+ st['throws'](function () { return is.within(0, 0, ''); }, error, 'throws when third value is string');
548
+ st['throws'](function () { return is.within({}, 0, 0); }, error, 'throws when first value is object');
549
+ st['throws'](function () { return is.within(0, {}, 0); }, error, 'throws when second value is object');
550
+ st['throws'](function () { return is.within(0, 0, {}); }, error, 'throws when third value is object');
551
+ st['throws'](function () { return is.within(null, 0, 0); }, error, 'throws when first value is null');
552
+ st['throws'](function () { return is.within(0, null, 0); }, error, 'throws when second value is null');
553
+ st['throws'](function () { return is.within(0, 0, null); }, error, 'throws when third value is null');
554
+ st['throws'](function () { return is.within(undefined, 0, 0); }, error, 'throws when first value is undefined');
555
+ st['throws'](function () { return is.within(0, undefined, 0); }, error, 'throws when second value is undefined');
556
+ st['throws'](function () { return is.within(0, 0, undefined); }, error, 'throws when third value is undefined');
557
+ st.end();
558
+ });
505
559
 
506
560
  t.ok(is.within(2, 1, 3), '2 is between 1 and 3');
507
561
  t.ok(is.within(0, -1, 1), '0 is between -1 and 1');
@@ -521,6 +575,31 @@ test('is.object', function (t) {
521
575
  t.notOk(is.object(NaN), 'NaN is not an object');
522
576
  t.notOk(is.object(Object), 'object constructor is not an object');
523
577
  t.notOk(is.object(function () {}), 'function is not an object');
578
+
579
+ t.test('Symbols', { skip: typeof Symbol !== 'function' }, function (st) {
580
+ st.notOk(is.object(Symbol('foo')), 'symbol is not an object');
581
+ st.end();
582
+ });
583
+
584
+ t.end();
585
+ });
586
+
587
+ test('is.primitive', function (t) {
588
+ t.notOk(is.primitive({}), 'object literal is not a primitive');
589
+ t.notOk(is.primitive([]), 'array is not a primitive');
590
+ t.ok(is.primitive(), 'undefined is a primitive');
591
+ t.ok(is.primitive(null), 'null is a primitive');
592
+ t.ok(is.primitive(true), 'true is a primitive');
593
+ t.ok(is.primitive(''), 'string is a primitive');
594
+ t.ok(is.primitive(NaN), 'NaN is a primitive');
595
+ t.notOk(is.primitive(Object), 'object constructor is not a primitive');
596
+ t.notOk(is.primitive(function () {}), 'function is not a primitive');
597
+
598
+ t.test('Symbols', { skip: typeof Symbol !== 'function' }, function (st) {
599
+ st.ok(is.primitive(Symbol('foo')), 'symbol is a primitive');
600
+ st.end();
601
+ });
602
+
524
603
  t.end();
525
604
  });
526
605
 
@@ -530,25 +609,33 @@ test('is.hash', function (t) {
530
609
  t.notOk(is.hash(), 'undefined is not a hash');
531
610
  t.notOk(is.hash(null), 'null is not a hash');
532
611
  t.notOk(is.hash(new Date()), 'date is not a hash');
533
- t.notOk(is.hash(new String()), 'string object is not a hash');
612
+ t.notOk(is.hash(Object('')), 'string object is not a hash');
534
613
  t.notOk(is.hash(''), 'string literal is not a hash');
535
- t.notOk(is.hash(new Number()), 'number object is not a hash');
614
+ t.notOk(is.hash(Object(0)), 'number object is not a hash');
536
615
  t.notOk(is.hash(1), 'number literal is not a hash');
537
616
  t.notOk(is.hash(true), 'true is not a hash');
538
617
  t.notOk(is.hash(false), 'false is not a hash');
539
- t.notOk(is.hash(new Boolean()), 'boolean obj is not hash');
618
+ t.notOk(is.hash(Object(false)), 'boolean obj is not hash');
540
619
  t.notOk(is.hash(false), 'literal false is not hash');
541
620
  t.notOk(is.hash(true), 'literal true is not hash');
542
- if (typeof module !== 'undefined') {
543
- t.ok(is.hash(module.exports), 'module.exports is a hash');
544
- }
545
- if (typeof window !== 'undefined') {
546
- t.notOk(is.hash(window), 'window is not a hash');
547
- t.notOk(is.hash(document.createElement('div')), 'element is not a hash');
548
- } else if (typeof process !== 'undefined') {
549
- t.notOk(is.hash(global), 'global is not a hash');
550
- t.notOk(is.hash(process), 'process is not a hash');
551
- }
621
+
622
+ t.test('commonJS environment', { skip: typeof module === 'undefined' }, function (st) {
623
+ st.ok(is.hash(module.exports), 'module.exports is a hash');
624
+ st.end();
625
+ });
626
+
627
+ t.test('browser stuff', { skip: typeof window === 'undefined' }, function (st) {
628
+ st.notOk(is.hash(window), 'window is not a hash');
629
+ st.notOk(is.hash(document.createElement('div')), 'element is not a hash');
630
+ st.end();
631
+ });
632
+
633
+ t.test('node stuff', { skip: typeof process === 'undefined' }, function (st) {
634
+ st.notOk(is.hash(global), 'global is not a hash');
635
+ st.notOk(is.hash(process), 'process is not a hash');
636
+ st.end();
637
+ });
638
+
552
639
  t.end();
553
640
  });
554
641
 
@@ -563,11 +650,11 @@ test('is.regexp', function (t) {
563
650
 
564
651
  test('is.string', function (t) {
565
652
  t.ok(is.string('foo'), 'string literal is string');
566
- t.ok(is.string(new String('foo')), 'string literal is string');
653
+ t.ok(is.string(Object('foo')), 'string object is string');
567
654
  t.notOk(is.string(), 'undefined is not string');
568
655
  t.notOk(is.string(String), 'string constructor is not string');
569
656
  var F = function () {};
570
- F.prototype = new String();
657
+ F.prototype = Object('');
571
658
  t.notOk(is.string(F), 'string subtype is not string');
572
659
  t.end();
573
660
  });
@@ -590,29 +677,28 @@ test('is.hex', function (t) {
590
677
  });
591
678
 
592
679
  test('is.symbol', function (t) {
593
- t.test('not symbols', function (t) {
680
+ t.test('not symbols', function (st) {
594
681
  var notSymbols = [true, false, null, undefined, {}, [], function () {}, 42, NaN, Infinity, /a/g, '', 0, -0, new Error('error')];
595
682
  forEach(notSymbols, function (notSymbol) {
596
- t.notOk(is.symbol(notSymbol), notSymbol + ' is not symbol');
683
+ st.notOk(is.symbol(notSymbol), notSymbol + ' is not symbol');
597
684
  });
598
685
 
599
- t.end();
686
+ st.end();
600
687
  });
601
688
 
602
- t.test('symbols', { skip: typeof Symbol !== 'function' }, function (t) {
603
- t.ok(is.symbol(Symbol('foo')), 'Symbol("foo") is symbol');
689
+ t.test('symbols', { skip: typeof Symbol !== 'function' }, function (st) {
690
+ st.ok(is.symbol(Symbol('foo')), 'Symbol("foo") is symbol');
604
691
 
605
- var notKnownSymbolProperties = ['length', 'name', 'arguments', 'caller', 'prototype', 'for', 'keyFor'];
692
+ var notKnownSymbols = ['length', 'name', 'arguments', 'caller', 'prototype', 'for', 'keyFor'];
606
693
  var symbolKeys = Object.getOwnPropertyNames(Symbol).filter(function (name) {
607
- return notKnownSymbolProperties.indexOf(name) < 0;
694
+ return notKnownSymbols.indexOf(name) < 0;
608
695
  });
609
696
  forEach(symbolKeys, function (symbolKey) {
610
- t.ok(is.symbol(Symbol[symbolKey]), symbolKey + ' is symbol');
697
+ st.ok(is.symbol(Symbol[symbolKey]), symbolKey + ' is symbol');
611
698
  });
612
699
 
613
- t.end();
700
+ st.end();
614
701
  });
615
702
 
616
703
  t.end();
617
704
  });
618
-