is 3.0.1 → 3.3.0
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 +36 -0
- package/README.md +9 -5
- package/index.js +122 -66
- package/package.json +15 -7
- package/test/index.js +204 -97
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
3.3.0 / 2018-12-14
|
|
2
|
+
==================
|
|
3
|
+
* [New] add `is.bigint` (#36)
|
|
4
|
+
* [Docs] change jsdoc comments "Mixed" to wildcards (#34)
|
|
5
|
+
* [Tests] up to `node` `v11.4`, `v10.14`, `v9.11`, `v8.14`, `v7.10`, `v6.15`, `v4.9`; use `nvm install-latest-npm`
|
|
6
|
+
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `tape`
|
|
7
|
+
|
|
8
|
+
3.2.1 / 2017-02-27
|
|
9
|
+
==================
|
|
10
|
+
* [Fix] `is.fn`: recognize generator and async functions too (#28)
|
|
11
|
+
* [Tests] up to `node` `v7.5`, `v4.7`; improve test matrix
|
|
12
|
+
* [Dev Deps] update `@ljharb/eslint-config`, `eslint`, `tape`
|
|
13
|
+
* [Docs] improve readme formatting (#27)
|
|
14
|
+
|
|
15
|
+
3.2.0 / 2016-10-24
|
|
16
|
+
==================
|
|
17
|
+
* [Fix] fix infinite loop when comparing two empty arrays + fix skipping first element (#24, #25)
|
|
18
|
+
* [New] add `is.primitive`
|
|
19
|
+
* [New] Add `is.date.valid` function and tests (#19)
|
|
20
|
+
* [Tests] use `pretest` for `npm run lint`; add `npm run tests-only`
|
|
21
|
+
* [Tests] up to `node` `v4.6`, `v5.12`, `v6.9`; improve test matrix
|
|
22
|
+
* [Tests] fix description (#18)
|
|
23
|
+
* [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config`
|
|
24
|
+
|
|
25
|
+
3.1.0 / 2015-09-20
|
|
26
|
+
==================
|
|
27
|
+
* [Enhancement]: `is.array`: Prefer `Array.isArray` when present
|
|
28
|
+
* [Fix] Deprecate `is.boolean`/`is.int` (ES3 syntax errors)
|
|
29
|
+
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
|
|
30
|
+
* [Refactor] Don't use yoda conditions
|
|
31
|
+
* [Refactor] `is.equal` can return earlier in some cases (#16)
|
|
32
|
+
* [Tests] Quote "throws" (ES3 syntax error)
|
|
33
|
+
* [Tests] up to `io.js` `v3.3`, up to `node` `v4.1`
|
|
34
|
+
* [Dev Deps] add `npm run eslint`
|
|
35
|
+
* [Dev Deps] update `tape`, `covert`, `jscs`
|
|
36
|
+
|
|
1
37
|
3.0.1 / 2015-02-22
|
|
2
38
|
==================
|
|
3
39
|
* Version bump to resolve npm bug with v3.0.0
|
package/README.md
CHANGED
|
@@ -57,7 +57,8 @@ $ component install enricomarino/is
|
|
|
57
57
|
|
|
58
58
|
### boolean
|
|
59
59
|
|
|
60
|
-
- ``is.
|
|
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.
|
|
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)
|
|
@@ -113,16 +115,18 @@ $ component install enricomarino/is
|
|
|
113
115
|
- ``is.base64`` (value)
|
|
114
116
|
- ``is.hex`` (value)
|
|
115
117
|
|
|
116
|
-
###
|
|
118
|
+
### Symbols
|
|
117
119
|
- ``is.symbol`` (value)
|
|
118
120
|
|
|
121
|
+
### BigInts
|
|
122
|
+
- ``is.bigint`` (value)
|
|
119
123
|
|
|
120
124
|
## Contributors
|
|
121
125
|
|
|
122
126
|
- [Jordan Harband](https://github.com/ljharb)
|
|
123
127
|
|
|
124
128
|
[npm-url]: https://npmjs.org/package/is
|
|
125
|
-
[npm-version-svg]: http://
|
|
129
|
+
[npm-version-svg]: http://versionbadg.es/enricomarino/is.svg
|
|
126
130
|
[travis-svg]: https://travis-ci.org/enricomarino/is.svg
|
|
127
131
|
[travis-url]: https://travis-ci.org/enricomarino/is
|
|
128
132
|
[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
|
|
@@ -14,11 +17,15 @@ var symbolValueOf;
|
|
|
14
17
|
if (typeof Symbol === 'function') {
|
|
15
18
|
symbolValueOf = Symbol.prototype.valueOf;
|
|
16
19
|
}
|
|
20
|
+
var bigIntValueOf;
|
|
21
|
+
if (typeof BigInt === 'function') {
|
|
22
|
+
bigIntValueOf = BigInt.prototype.valueOf;
|
|
23
|
+
}
|
|
17
24
|
var isActualNaN = function (value) {
|
|
18
25
|
return value !== value;
|
|
19
26
|
};
|
|
20
27
|
var NON_HOST_TYPES = {
|
|
21
|
-
boolean: 1,
|
|
28
|
+
'boolean': 1,
|
|
22
29
|
number: 1,
|
|
23
30
|
string: 1,
|
|
24
31
|
undefined: 1
|
|
@@ -31,7 +38,7 @@ var hexRegex = /^[A-Fa-f0-9]+$/;
|
|
|
31
38
|
* Expose `is`
|
|
32
39
|
*/
|
|
33
40
|
|
|
34
|
-
var is =
|
|
41
|
+
var is = {};
|
|
35
42
|
|
|
36
43
|
/**
|
|
37
44
|
* Test general.
|
|
@@ -41,7 +48,7 @@ var is = module.exports = {};
|
|
|
41
48
|
* is.type
|
|
42
49
|
* Test if `value` is a type of `type`.
|
|
43
50
|
*
|
|
44
|
-
* @param {
|
|
51
|
+
* @param {*} value value to test
|
|
45
52
|
* @param {String} type type
|
|
46
53
|
* @return {Boolean} true if `value` is a type of `type`, false otherwise
|
|
47
54
|
* @api public
|
|
@@ -55,7 +62,7 @@ is.a = is.type = function (value, type) {
|
|
|
55
62
|
* is.defined
|
|
56
63
|
* Test if `value` is defined.
|
|
57
64
|
*
|
|
58
|
-
* @param {
|
|
65
|
+
* @param {*} value value to test
|
|
59
66
|
* @return {Boolean} true if 'value' is defined, false otherwise
|
|
60
67
|
* @api public
|
|
61
68
|
*/
|
|
@@ -68,7 +75,7 @@ is.defined = function (value) {
|
|
|
68
75
|
* is.empty
|
|
69
76
|
* Test if `value` is empty.
|
|
70
77
|
*
|
|
71
|
-
* @param {
|
|
78
|
+
* @param {*} value value to test
|
|
72
79
|
* @return {Boolean} true if `value` is empty, false otherwise
|
|
73
80
|
* @api public
|
|
74
81
|
*/
|
|
@@ -77,13 +84,15 @@ is.empty = function (value) {
|
|
|
77
84
|
var type = toStr.call(value);
|
|
78
85
|
var key;
|
|
79
86
|
|
|
80
|
-
if ('[object Array]'
|
|
87
|
+
if (type === '[object Array]' || type === '[object Arguments]' || type === '[object String]') {
|
|
81
88
|
return value.length === 0;
|
|
82
89
|
}
|
|
83
90
|
|
|
84
|
-
if ('[object Object]'
|
|
91
|
+
if (type === '[object Object]') {
|
|
85
92
|
for (key in value) {
|
|
86
|
-
if (owns.call(value, key)) {
|
|
93
|
+
if (owns.call(value, key)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
87
96
|
}
|
|
88
97
|
return true;
|
|
89
98
|
}
|
|
@@ -95,14 +104,13 @@ is.empty = function (value) {
|
|
|
95
104
|
* is.equal
|
|
96
105
|
* Test if `value` is equal to `other`.
|
|
97
106
|
*
|
|
98
|
-
* @param {
|
|
99
|
-
* @param {
|
|
107
|
+
* @param {*} value value to test
|
|
108
|
+
* @param {*} other value to compare with
|
|
100
109
|
* @return {Boolean} true if `value` is equal to `other`, false otherwise
|
|
101
110
|
*/
|
|
102
111
|
|
|
103
|
-
is.equal = function (value, other) {
|
|
104
|
-
|
|
105
|
-
if (strictlyEqual) {
|
|
112
|
+
is.equal = function equal(value, other) {
|
|
113
|
+
if (value === other) {
|
|
106
114
|
return true;
|
|
107
115
|
}
|
|
108
116
|
|
|
@@ -113,7 +121,7 @@ is.equal = function (value, other) {
|
|
|
113
121
|
return false;
|
|
114
122
|
}
|
|
115
123
|
|
|
116
|
-
if ('[object Object]'
|
|
124
|
+
if (type === '[object Object]') {
|
|
117
125
|
for (key in value) {
|
|
118
126
|
if (!is.equal(value[key], other[key]) || !(key in other)) {
|
|
119
127
|
return false;
|
|
@@ -127,12 +135,12 @@ is.equal = function (value, other) {
|
|
|
127
135
|
return true;
|
|
128
136
|
}
|
|
129
137
|
|
|
130
|
-
if ('[object Array]'
|
|
138
|
+
if (type === '[object Array]') {
|
|
131
139
|
key = value.length;
|
|
132
140
|
if (key !== other.length) {
|
|
133
141
|
return false;
|
|
134
142
|
}
|
|
135
|
-
while (--
|
|
143
|
+
while (key--) {
|
|
136
144
|
if (!is.equal(value[key], other[key])) {
|
|
137
145
|
return false;
|
|
138
146
|
}
|
|
@@ -140,23 +148,23 @@ is.equal = function (value, other) {
|
|
|
140
148
|
return true;
|
|
141
149
|
}
|
|
142
150
|
|
|
143
|
-
if ('[object Function]'
|
|
151
|
+
if (type === '[object Function]') {
|
|
144
152
|
return value.prototype === other.prototype;
|
|
145
153
|
}
|
|
146
154
|
|
|
147
|
-
if ('[object Date]'
|
|
155
|
+
if (type === '[object Date]') {
|
|
148
156
|
return value.getTime() === other.getTime();
|
|
149
157
|
}
|
|
150
158
|
|
|
151
|
-
return
|
|
159
|
+
return false;
|
|
152
160
|
};
|
|
153
161
|
|
|
154
162
|
/**
|
|
155
163
|
* is.hosted
|
|
156
164
|
* Test if `value` is hosted by `host`.
|
|
157
165
|
*
|
|
158
|
-
* @param {
|
|
159
|
-
* @param {
|
|
166
|
+
* @param {*} value to test
|
|
167
|
+
* @param {*} host host to test with
|
|
160
168
|
* @return {Boolean} true if `value` is hosted by `host`, false otherwise
|
|
161
169
|
* @api public
|
|
162
170
|
*/
|
|
@@ -170,7 +178,7 @@ is.hosted = function (value, host) {
|
|
|
170
178
|
* is.instance
|
|
171
179
|
* Test if `value` is an instance of `constructor`.
|
|
172
180
|
*
|
|
173
|
-
* @param {
|
|
181
|
+
* @param {*} value value to test
|
|
174
182
|
* @return {Boolean} true if `value` is an instance of `constructor`
|
|
175
183
|
* @api public
|
|
176
184
|
*/
|
|
@@ -183,7 +191,7 @@ is.instance = is['instanceof'] = function (value, constructor) {
|
|
|
183
191
|
* is.nil / is.null
|
|
184
192
|
* Test if `value` is null.
|
|
185
193
|
*
|
|
186
|
-
* @param {
|
|
194
|
+
* @param {*} value value to test
|
|
187
195
|
* @return {Boolean} true if `value` is null, false otherwise
|
|
188
196
|
* @api public
|
|
189
197
|
*/
|
|
@@ -196,7 +204,7 @@ is.nil = is['null'] = function (value) {
|
|
|
196
204
|
* is.undef / is.undefined
|
|
197
205
|
* Test if `value` is undefined.
|
|
198
206
|
*
|
|
199
|
-
* @param {
|
|
207
|
+
* @param {*} value value to test
|
|
200
208
|
* @return {Boolean} true if `value` is undefined, false otherwise
|
|
201
209
|
* @api public
|
|
202
210
|
*/
|
|
@@ -213,13 +221,13 @@ is.undef = is.undefined = function (value) {
|
|
|
213
221
|
* is.args
|
|
214
222
|
* Test if `value` is an arguments object.
|
|
215
223
|
*
|
|
216
|
-
* @param {
|
|
224
|
+
* @param {*} value value to test
|
|
217
225
|
* @return {Boolean} true if `value` is an arguments object, false otherwise
|
|
218
226
|
* @api public
|
|
219
227
|
*/
|
|
220
228
|
|
|
221
229
|
is.args = is.arguments = function (value) {
|
|
222
|
-
var isStandardArguments = '[object Arguments]'
|
|
230
|
+
var isStandardArguments = toStr.call(value) === '[object Arguments]';
|
|
223
231
|
var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
|
|
224
232
|
return isStandardArguments || isOldArguments;
|
|
225
233
|
};
|
|
@@ -232,20 +240,20 @@ is.args = is.arguments = function (value) {
|
|
|
232
240
|
* is.array
|
|
233
241
|
* Test if 'value' is an array.
|
|
234
242
|
*
|
|
235
|
-
* @param {
|
|
243
|
+
* @param {*} value value to test
|
|
236
244
|
* @return {Boolean} true if `value` is an array, false otherwise
|
|
237
245
|
* @api public
|
|
238
246
|
*/
|
|
239
247
|
|
|
240
|
-
is.array = function (value) {
|
|
241
|
-
return '[object Array]'
|
|
248
|
+
is.array = Array.isArray || function (value) {
|
|
249
|
+
return toStr.call(value) === '[object Array]';
|
|
242
250
|
};
|
|
243
251
|
|
|
244
252
|
/**
|
|
245
253
|
* is.arguments.empty
|
|
246
254
|
* Test if `value` is an empty arguments object.
|
|
247
255
|
*
|
|
248
|
-
* @param {
|
|
256
|
+
* @param {*} value value to test
|
|
249
257
|
* @return {Boolean} true if `value` is an empty arguments object, false otherwise
|
|
250
258
|
* @api public
|
|
251
259
|
*/
|
|
@@ -257,7 +265,7 @@ is.args.empty = function (value) {
|
|
|
257
265
|
* is.array.empty
|
|
258
266
|
* Test if `value` is an empty array.
|
|
259
267
|
*
|
|
260
|
-
* @param {
|
|
268
|
+
* @param {*} value value to test
|
|
261
269
|
* @return {Boolean} true if `value` is an empty array, false otherwise
|
|
262
270
|
* @api public
|
|
263
271
|
*/
|
|
@@ -269,13 +277,13 @@ is.array.empty = function (value) {
|
|
|
269
277
|
* is.arraylike
|
|
270
278
|
* Test if `value` is an arraylike object.
|
|
271
279
|
*
|
|
272
|
-
* @param {
|
|
280
|
+
* @param {*} value value to test
|
|
273
281
|
* @return {Boolean} true if `value` is an arguments object, false otherwise
|
|
274
282
|
* @api public
|
|
275
283
|
*/
|
|
276
284
|
|
|
277
285
|
is.arraylike = function (value) {
|
|
278
|
-
return !!value && !is.
|
|
286
|
+
return !!value && !is.bool(value)
|
|
279
287
|
&& owns.call(value, 'length')
|
|
280
288
|
&& isFinite(value.length)
|
|
281
289
|
&& is.number(value.length)
|
|
@@ -287,42 +295,42 @@ is.arraylike = function (value) {
|
|
|
287
295
|
*/
|
|
288
296
|
|
|
289
297
|
/**
|
|
290
|
-
* is.
|
|
298
|
+
* is.bool
|
|
291
299
|
* Test if `value` is a boolean.
|
|
292
300
|
*
|
|
293
|
-
* @param {
|
|
301
|
+
* @param {*} value value to test
|
|
294
302
|
* @return {Boolean} true if `value` is a boolean, false otherwise
|
|
295
303
|
* @api public
|
|
296
304
|
*/
|
|
297
305
|
|
|
298
|
-
is.boolean = function (value) {
|
|
299
|
-
return '[object Boolean]'
|
|
306
|
+
is.bool = is['boolean'] = function (value) {
|
|
307
|
+
return toStr.call(value) === '[object Boolean]';
|
|
300
308
|
};
|
|
301
309
|
|
|
302
310
|
/**
|
|
303
311
|
* is.false
|
|
304
312
|
* Test if `value` is false.
|
|
305
313
|
*
|
|
306
|
-
* @param {
|
|
314
|
+
* @param {*} value value to test
|
|
307
315
|
* @return {Boolean} true if `value` is false, false otherwise
|
|
308
316
|
* @api public
|
|
309
317
|
*/
|
|
310
318
|
|
|
311
319
|
is['false'] = function (value) {
|
|
312
|
-
return is.
|
|
320
|
+
return is.bool(value) && Boolean(Number(value)) === false;
|
|
313
321
|
};
|
|
314
322
|
|
|
315
323
|
/**
|
|
316
324
|
* is.true
|
|
317
325
|
* Test if `value` is true.
|
|
318
326
|
*
|
|
319
|
-
* @param {
|
|
327
|
+
* @param {*} value value to test
|
|
320
328
|
* @return {Boolean} true if `value` is true, false otherwise
|
|
321
329
|
* @api public
|
|
322
330
|
*/
|
|
323
331
|
|
|
324
332
|
is['true'] = function (value) {
|
|
325
|
-
return is.
|
|
333
|
+
return is.bool(value) && Boolean(Number(value)) === true;
|
|
326
334
|
};
|
|
327
335
|
|
|
328
336
|
/**
|
|
@@ -333,13 +341,24 @@ is['true'] = function (value) {
|
|
|
333
341
|
* is.date
|
|
334
342
|
* Test if `value` is a date.
|
|
335
343
|
*
|
|
336
|
-
* @param {
|
|
344
|
+
* @param {*} value value to test
|
|
337
345
|
* @return {Boolean} true if `value` is a date, false otherwise
|
|
338
346
|
* @api public
|
|
339
347
|
*/
|
|
340
348
|
|
|
341
349
|
is.date = function (value) {
|
|
342
|
-
return '[object Date]'
|
|
350
|
+
return toStr.call(value) === '[object Date]';
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* is.date.valid
|
|
355
|
+
* Test if `value` is a valid date.
|
|
356
|
+
*
|
|
357
|
+
* @param {*} value value to test
|
|
358
|
+
* @returns {Boolean} true if `value` is a valid date, false otherwise
|
|
359
|
+
*/
|
|
360
|
+
is.date.valid = function (value) {
|
|
361
|
+
return is.date(value) && !isNaN(Number(value));
|
|
343
362
|
};
|
|
344
363
|
|
|
345
364
|
/**
|
|
@@ -350,7 +369,7 @@ is.date = function (value) {
|
|
|
350
369
|
* is.element
|
|
351
370
|
* Test if `value` is an html element.
|
|
352
371
|
*
|
|
353
|
-
* @param {
|
|
372
|
+
* @param {*} value value to test
|
|
354
373
|
* @return {Boolean} true if `value` is an HTML Element, false otherwise
|
|
355
374
|
* @api public
|
|
356
375
|
*/
|
|
@@ -370,13 +389,13 @@ is.element = function (value) {
|
|
|
370
389
|
* is.error
|
|
371
390
|
* Test if `value` is an error object.
|
|
372
391
|
*
|
|
373
|
-
* @param {
|
|
392
|
+
* @param {*} value value to test
|
|
374
393
|
* @return {Boolean} true if `value` is an error object, false otherwise
|
|
375
394
|
* @api public
|
|
376
395
|
*/
|
|
377
396
|
|
|
378
397
|
is.error = function (value) {
|
|
379
|
-
return '[object Error]'
|
|
398
|
+
return toStr.call(value) === '[object Error]';
|
|
380
399
|
};
|
|
381
400
|
|
|
382
401
|
/**
|
|
@@ -387,14 +406,18 @@ is.error = function (value) {
|
|
|
387
406
|
* is.fn / is.function (deprecated)
|
|
388
407
|
* Test if `value` is a function.
|
|
389
408
|
*
|
|
390
|
-
* @param {
|
|
409
|
+
* @param {*} value value to test
|
|
391
410
|
* @return {Boolean} true if `value` is a function, false otherwise
|
|
392
411
|
* @api public
|
|
393
412
|
*/
|
|
394
413
|
|
|
395
414
|
is.fn = is['function'] = function (value) {
|
|
396
415
|
var isAlert = typeof window !== 'undefined' && value === window.alert;
|
|
397
|
-
|
|
416
|
+
if (isAlert) {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
var str = toStr.call(value);
|
|
420
|
+
return str === '[object Function]' || str === '[object GeneratorFunction]' || str === '[object AsyncFunction]';
|
|
398
421
|
};
|
|
399
422
|
|
|
400
423
|
/**
|
|
@@ -405,20 +428,20 @@ is.fn = is['function'] = function (value) {
|
|
|
405
428
|
* is.number
|
|
406
429
|
* Test if `value` is a number.
|
|
407
430
|
*
|
|
408
|
-
* @param {
|
|
431
|
+
* @param {*} value value to test
|
|
409
432
|
* @return {Boolean} true if `value` is a number, false otherwise
|
|
410
433
|
* @api public
|
|
411
434
|
*/
|
|
412
435
|
|
|
413
436
|
is.number = function (value) {
|
|
414
|
-
return '[object Number]'
|
|
437
|
+
return toStr.call(value) === '[object Number]';
|
|
415
438
|
};
|
|
416
439
|
|
|
417
440
|
/**
|
|
418
441
|
* is.infinite
|
|
419
442
|
* Test if `value` is positive or negative infinity.
|
|
420
443
|
*
|
|
421
|
-
* @param {
|
|
444
|
+
* @param {*} value value to test
|
|
422
445
|
* @return {Boolean} true if `value` is positive or negative Infinity, false otherwise
|
|
423
446
|
* @api public
|
|
424
447
|
*/
|
|
@@ -430,7 +453,7 @@ is.infinite = function (value) {
|
|
|
430
453
|
* is.decimal
|
|
431
454
|
* Test if `value` is a decimal number.
|
|
432
455
|
*
|
|
433
|
-
* @param {
|
|
456
|
+
* @param {*} value value to test
|
|
434
457
|
* @return {Boolean} true if `value` is a decimal number, false otherwise
|
|
435
458
|
* @api public
|
|
436
459
|
*/
|
|
@@ -457,7 +480,7 @@ is.divisibleBy = function (value, n) {
|
|
|
457
480
|
};
|
|
458
481
|
|
|
459
482
|
/**
|
|
460
|
-
* is.
|
|
483
|
+
* is.integer
|
|
461
484
|
* Test if `value` is an integer.
|
|
462
485
|
*
|
|
463
486
|
* @param value to test
|
|
@@ -465,7 +488,7 @@ is.divisibleBy = function (value, n) {
|
|
|
465
488
|
* @api public
|
|
466
489
|
*/
|
|
467
490
|
|
|
468
|
-
is.int = function (value) {
|
|
491
|
+
is.integer = is['int'] = function (value) {
|
|
469
492
|
return is.number(value) && !isActualNaN(value) && value % 1 === 0;
|
|
470
493
|
};
|
|
471
494
|
|
|
@@ -527,7 +550,7 @@ is.minimum = function (value, others) {
|
|
|
527
550
|
* is.nan
|
|
528
551
|
* Test if `value` is not a number.
|
|
529
552
|
*
|
|
530
|
-
* @param {
|
|
553
|
+
* @param {*} value value to test
|
|
531
554
|
* @return {Boolean} true if `value` is not a number, false otherwise
|
|
532
555
|
* @api public
|
|
533
556
|
*/
|
|
@@ -658,20 +681,37 @@ is.within = function (value, start, finish) {
|
|
|
658
681
|
* is.object
|
|
659
682
|
* Test if `value` is an object.
|
|
660
683
|
*
|
|
661
|
-
* @param {
|
|
684
|
+
* @param {*} value value to test
|
|
662
685
|
* @return {Boolean} true if `value` is an object, false otherwise
|
|
663
686
|
* @api public
|
|
664
687
|
*/
|
|
665
|
-
|
|
666
688
|
is.object = function (value) {
|
|
667
|
-
return '[object Object]'
|
|
689
|
+
return toStr.call(value) === '[object Object]';
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* is.primitive
|
|
694
|
+
* Test if `value` is a primitive.
|
|
695
|
+
*
|
|
696
|
+
* @param {*} value value to test
|
|
697
|
+
* @return {Boolean} true if `value` is a primitive, false otherwise
|
|
698
|
+
* @api public
|
|
699
|
+
*/
|
|
700
|
+
is.primitive = function isPrimitive(value) {
|
|
701
|
+
if (!value) {
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
if (typeof value === 'object' || is.object(value) || is.fn(value) || is.array(value)) {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
return true;
|
|
668
708
|
};
|
|
669
709
|
|
|
670
710
|
/**
|
|
671
711
|
* is.hash
|
|
672
712
|
* Test if `value` is a hash - a plain object literal.
|
|
673
713
|
*
|
|
674
|
-
* @param {
|
|
714
|
+
* @param {*} value value to test
|
|
675
715
|
* @return {Boolean} true if `value` is a hash, false otherwise
|
|
676
716
|
* @api public
|
|
677
717
|
*/
|
|
@@ -688,13 +728,13 @@ is.hash = function (value) {
|
|
|
688
728
|
* is.regexp
|
|
689
729
|
* Test if `value` is a regular expression.
|
|
690
730
|
*
|
|
691
|
-
* @param {
|
|
731
|
+
* @param {*} value value to test
|
|
692
732
|
* @return {Boolean} true if `value` is a regexp, false otherwise
|
|
693
733
|
* @api public
|
|
694
734
|
*/
|
|
695
735
|
|
|
696
736
|
is.regexp = function (value) {
|
|
697
|
-
return '[object RegExp]'
|
|
737
|
+
return toStr.call(value) === '[object RegExp]';
|
|
698
738
|
};
|
|
699
739
|
|
|
700
740
|
/**
|
|
@@ -705,13 +745,13 @@ is.regexp = function (value) {
|
|
|
705
745
|
* is.string
|
|
706
746
|
* Test if `value` is a string.
|
|
707
747
|
*
|
|
708
|
-
* @param {
|
|
748
|
+
* @param {*} value value to test
|
|
709
749
|
* @return {Boolean} true if 'value' is a string, false otherwise
|
|
710
750
|
* @api public
|
|
711
751
|
*/
|
|
712
752
|
|
|
713
753
|
is.string = function (value) {
|
|
714
|
-
return '[object String]'
|
|
754
|
+
return toStr.call(value) === '[object String]';
|
|
715
755
|
};
|
|
716
756
|
|
|
717
757
|
/**
|
|
@@ -722,7 +762,7 @@ is.string = function (value) {
|
|
|
722
762
|
* is.base64
|
|
723
763
|
* Test if `value` is a valid base64 encoded string.
|
|
724
764
|
*
|
|
725
|
-
* @param {
|
|
765
|
+
* @param {*} value value to test
|
|
726
766
|
* @return {Boolean} true if 'value' is a base64 encoded string, false otherwise
|
|
727
767
|
* @api public
|
|
728
768
|
*/
|
|
@@ -739,7 +779,7 @@ is.base64 = function (value) {
|
|
|
739
779
|
* is.hex
|
|
740
780
|
* Test if `value` is a valid hex encoded string.
|
|
741
781
|
*
|
|
742
|
-
* @param {
|
|
782
|
+
* @param {*} value value to test
|
|
743
783
|
* @return {Boolean} true if 'value' is a hex encoded string, false otherwise
|
|
744
784
|
* @api public
|
|
745
785
|
*/
|
|
@@ -752,7 +792,7 @@ is.hex = function (value) {
|
|
|
752
792
|
* is.symbol
|
|
753
793
|
* Test if `value` is an ES6 Symbol
|
|
754
794
|
*
|
|
755
|
-
* @param {
|
|
795
|
+
* @param {*} value value to test
|
|
756
796
|
* @return {Boolean} true if `value` is a Symbol, false otherise
|
|
757
797
|
* @api public
|
|
758
798
|
*/
|
|
@@ -760,3 +800,19 @@ is.hex = function (value) {
|
|
|
760
800
|
is.symbol = function (value) {
|
|
761
801
|
return typeof Symbol === 'function' && toStr.call(value) === '[object Symbol]' && typeof symbolValueOf.call(value) === 'symbol';
|
|
762
802
|
};
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* is.bigint
|
|
806
|
+
* Test if `value` is an ES-proposed BigInt
|
|
807
|
+
*
|
|
808
|
+
* @param {*} value value to test
|
|
809
|
+
* @return {Boolean} true if `value` is a BigInt, false otherise
|
|
810
|
+
* @api public
|
|
811
|
+
*/
|
|
812
|
+
|
|
813
|
+
is.bigint = function (value) {
|
|
814
|
+
// eslint-disable-next-line valid-typeof
|
|
815
|
+
return typeof BigInt === 'function' && toStr.call(value) === '[object BigInt]' && typeof bigIntValueOf.call(value) === 'bigint';
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
module.exports = is;
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "is",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"
|
|
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
|
|
12
|
+
"lint": "npm run jscs && npm run eslint",
|
|
13
|
+
"jscs": "jscs *.js */*.js",
|
|
14
|
+
"eslint": "eslint ."
|
|
10
15
|
},
|
|
11
16
|
"author": {
|
|
12
17
|
"name": "Enrico Marino",
|
|
@@ -32,10 +37,14 @@
|
|
|
32
37
|
],
|
|
33
38
|
"dependencies": {},
|
|
34
39
|
"devDependencies": {
|
|
35
|
-
"
|
|
40
|
+
"@ljharb/eslint-config": "^13.0.0",
|
|
41
|
+
"covert": "^1.1.0",
|
|
42
|
+
"eslint": "^5.10.0",
|
|
36
43
|
"foreach": "^2.0.5",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
44
|
+
"jscs": "^3.0.7",
|
|
45
|
+
"make-generator-function": "^1.1.0",
|
|
46
|
+
"safe-publish-latest": "^1.1.2",
|
|
47
|
+
"tape": "^4.9.1"
|
|
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,13 +47,13 @@ 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
|
|
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(
|
|
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
59
|
t.ok(is.empty(null), 'null is empty');
|
|
@@ -56,7 +62,9 @@ test('is.empty', function (t) {
|
|
|
56
62
|
t.ok(is.empty(false), 'false is empty');
|
|
57
63
|
t.ok(is.empty(0), '0 is empty');
|
|
58
64
|
t.ok(is.empty(NaN), 'nan is empty');
|
|
59
|
-
(function () {
|
|
65
|
+
(function () {
|
|
66
|
+
t.ok(is.empty(arguments), 'empty arguments is empty');
|
|
67
|
+
}());
|
|
60
68
|
t.notOk(is.empty({ a: 1 }), 'nonempty object is not empty');
|
|
61
69
|
t.notOk(is.empty(true), 'true is not empty');
|
|
62
70
|
t.notOk(is.empty(/a/g), 'regex is not empty');
|
|
@@ -77,8 +85,10 @@ test('is.equal', function (t) {
|
|
|
77
85
|
t.test('arrays', function (at) {
|
|
78
86
|
at.ok(is.equal([1, 2, 3], [1, 2, 3]), 'arrays are shallowly equal');
|
|
79
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');
|
|
80
89
|
at.notOk(is.equal([1, 2], [2, 3]), 'inequal arrays are not equal');
|
|
81
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');
|
|
82
92
|
|
|
83
93
|
var arr = [1, 2];
|
|
84
94
|
at.ok(is.equal(arr, arr), 'array is equal to itself');
|
|
@@ -175,11 +185,15 @@ test('is.nil', function (t) {
|
|
|
175
185
|
|
|
176
186
|
test('is.args', function (t) {
|
|
177
187
|
t.notOk(is.args([]), 'array is not arguments');
|
|
178
|
-
(function () {
|
|
179
|
-
|
|
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
|
+
}());
|
|
180
194
|
var fakeOldArguments = {
|
|
181
|
-
|
|
182
|
-
|
|
195
|
+
callee: function () {},
|
|
196
|
+
length: 3
|
|
183
197
|
};
|
|
184
198
|
t.ok(is.args(fakeOldArguments), 'old-style arguments object is arguments');
|
|
185
199
|
t.end();
|
|
@@ -187,22 +201,31 @@ test('is.args', function (t) {
|
|
|
187
201
|
|
|
188
202
|
test('is.args.empty', function (t) {
|
|
189
203
|
t.notOk(is.args.empty([]), 'empty array is not empty arguments');
|
|
190
|
-
(function () {
|
|
191
|
-
|
|
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
|
+
}());
|
|
192
210
|
t.end();
|
|
193
211
|
});
|
|
194
212
|
|
|
195
|
-
|
|
196
213
|
test('is.array', function (t) {
|
|
197
214
|
t.ok(is.array([]), 'array is array');
|
|
198
|
-
(function () {
|
|
215
|
+
(function () {
|
|
216
|
+
t.ok(is.array(Array.prototype.slice.call(arguments)), 'sliced arguments is array');
|
|
217
|
+
}());
|
|
199
218
|
t.end();
|
|
200
219
|
});
|
|
201
220
|
|
|
202
221
|
test('is.array.empty', function (t) {
|
|
203
222
|
t.ok(is.array.empty([]), 'empty array is empty array');
|
|
204
|
-
(function () {
|
|
205
|
-
|
|
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
|
+
}());
|
|
206
229
|
t.end();
|
|
207
230
|
});
|
|
208
231
|
|
|
@@ -218,25 +241,29 @@ test('is.isarraylike', function (t) {
|
|
|
218
241
|
t.notOk(is.arraylike({ length: 'foo' }), 'object with string length is not array-like');
|
|
219
242
|
t.notOk(is.arraylike({ length: '' }), 'object with empty string length is not array-like');
|
|
220
243
|
t.ok(is.arraylike([]), 'array is array-like');
|
|
221
|
-
(function () {
|
|
222
|
-
|
|
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));
|
|
223
250
|
t.end();
|
|
224
251
|
});
|
|
225
252
|
|
|
226
|
-
test('is.
|
|
227
|
-
t.ok(is.
|
|
228
|
-
t.ok(is.
|
|
229
|
-
t.ok(is.
|
|
230
|
-
t.ok(is.
|
|
231
|
-
t.notOk(is.
|
|
232
|
-
t.notOk(is.
|
|
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');
|
|
233
260
|
t.end();
|
|
234
261
|
});
|
|
235
262
|
|
|
236
263
|
test('is.false', function (t) {
|
|
237
264
|
var isFalse = is['false'];
|
|
238
265
|
t.ok(isFalse(false), 'false is false');
|
|
239
|
-
t.ok(isFalse(
|
|
266
|
+
t.ok(isFalse(Object(false)), 'object false is false');
|
|
240
267
|
t.notOk(isFalse(true), 'true is not false');
|
|
241
268
|
t.notOk(isFalse(), 'undefined is not false');
|
|
242
269
|
t.notOk(isFalse(null), 'null is not false');
|
|
@@ -247,7 +274,7 @@ test('is.false', function (t) {
|
|
|
247
274
|
test('is.true', function (t) {
|
|
248
275
|
var isTrue = is['true'];
|
|
249
276
|
t.ok(isTrue(true), 'true is true');
|
|
250
|
-
t.ok(isTrue(
|
|
277
|
+
t.ok(isTrue(Object(true)), 'object true is true');
|
|
251
278
|
t.notOk(isTrue(false), 'false is not true');
|
|
252
279
|
t.notOk(isTrue(), 'undefined is not true');
|
|
253
280
|
t.notOk(isTrue(null), 'null is not true');
|
|
@@ -268,15 +295,22 @@ test('is.date', function (t) {
|
|
|
268
295
|
t.end();
|
|
269
296
|
});
|
|
270
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
|
+
|
|
271
304
|
test('is.element', function (t) {
|
|
272
305
|
t.notOk(is.element(), 'undefined is not element');
|
|
273
|
-
|
|
306
|
+
|
|
307
|
+
t.test('when HTMLElement exists', { skip: typeof HTMLElement === 'undefined' }, function (st) {
|
|
274
308
|
var element = document.createElement('div');
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
|
|
280
314
|
t.end();
|
|
281
315
|
});
|
|
282
316
|
|
|
@@ -284,7 +318,11 @@ test('is.error', function (t) {
|
|
|
284
318
|
var err = new Error('foo');
|
|
285
319
|
t.ok(is.error(err), 'Error is error');
|
|
286
320
|
t.notOk(is.error({}), 'object is not error');
|
|
287
|
-
var objWithErrorToString = {
|
|
321
|
+
var objWithErrorToString = {
|
|
322
|
+
toString: function () {
|
|
323
|
+
return '[object Error]';
|
|
324
|
+
}
|
|
325
|
+
};
|
|
288
326
|
t.equal(String(objWithErrorToString), toStr.call(new Error()), 'obj has Error\'s toString');
|
|
289
327
|
t.notOk(is.error(objWithErrorToString), 'object with Error\'s toString is not error');
|
|
290
328
|
t.end();
|
|
@@ -293,13 +331,18 @@ test('is.error', function (t) {
|
|
|
293
331
|
test('is.fn', function (t) {
|
|
294
332
|
t.equal(is['function'], is.fn, 'alias works');
|
|
295
333
|
t.ok(is.fn(function () {}), 'function is function');
|
|
296
|
-
t.ok(is.fn(console.log), 'console.log is function');
|
|
297
334
|
if (typeof window !== 'undefined') {
|
|
298
335
|
// in IE7/8, typeof alert === 'object'
|
|
299
336
|
t.ok(is.fn(window.alert), 'window.alert is function');
|
|
300
337
|
}
|
|
301
338
|
t.notOk(is.fn({}), 'object is not function');
|
|
302
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
|
+
|
|
303
346
|
t.end();
|
|
304
347
|
});
|
|
305
348
|
|
|
@@ -310,7 +353,7 @@ test('is.number', function (t) {
|
|
|
310
353
|
t.ok(is.number(NaN), 'NaN is number');
|
|
311
354
|
t.ok(is.number(Infinity), 'infinity is number');
|
|
312
355
|
t.ok(is.number(-Infinity), 'negative infinity is number');
|
|
313
|
-
t.ok(is.number(
|
|
356
|
+
t.ok(is.number(Object(42)), 'object number is number');
|
|
314
357
|
t.notOk(is.number(), 'undefined is not number');
|
|
315
358
|
t.notOk(is.number(null), 'null is not number');
|
|
316
359
|
t.notOk(is.number(true), 'true is not number');
|
|
@@ -349,14 +392,14 @@ test('is.divisibleBy', function (t) {
|
|
|
349
392
|
t.end();
|
|
350
393
|
});
|
|
351
394
|
|
|
352
|
-
test('is.
|
|
353
|
-
t.ok(is.
|
|
354
|
-
t.ok(is.
|
|
355
|
-
t.notOk(is.
|
|
356
|
-
t.notOk(is.
|
|
357
|
-
t.notOk(is.
|
|
358
|
-
t.notOk(is.
|
|
359
|
-
t.notOk(is.
|
|
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');
|
|
360
403
|
t.end();
|
|
361
404
|
});
|
|
362
405
|
|
|
@@ -368,11 +411,11 @@ test('is.maximum', function (t) {
|
|
|
368
411
|
t.notOk(is.maximum(2, [1, 2, 3]), '2 is not maximum of [1,2,3]');
|
|
369
412
|
|
|
370
413
|
var nanError = new TypeError('NaN is not a valid value');
|
|
371
|
-
t
|
|
414
|
+
t['throws'](function () { return is.maximum(NaN); }, nanError, 'throws when first value is NaN');
|
|
372
415
|
|
|
373
416
|
var error = new TypeError('second argument must be array-like');
|
|
374
|
-
t
|
|
375
|
-
t
|
|
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');
|
|
376
419
|
t.end();
|
|
377
420
|
});
|
|
378
421
|
|
|
@@ -383,11 +426,11 @@ test('is.minimum', function (t) {
|
|
|
383
426
|
t.notOk(is.minimum(2, [1, 2, 3]), '2 is not minimum of [1,2,3]');
|
|
384
427
|
|
|
385
428
|
var nanError = new TypeError('NaN is not a valid value');
|
|
386
|
-
t
|
|
429
|
+
t['throws'](function () { return is.minimum(NaN); }, nanError, 'throws when first value is NaN');
|
|
387
430
|
|
|
388
431
|
var error = new TypeError('second argument must be array-like');
|
|
389
|
-
t
|
|
390
|
-
t
|
|
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');
|
|
391
434
|
t.end();
|
|
392
435
|
});
|
|
393
436
|
|
|
@@ -438,8 +481,8 @@ test('is.ge', function (t) {
|
|
|
438
481
|
t.notOk(is.ge(Infinity, 0), 'infinity is not greater than anything');
|
|
439
482
|
t.notOk(is.ge(0, Infinity), 'anything is not greater than infinity');
|
|
440
483
|
var error = new TypeError('NaN is not a valid value');
|
|
441
|
-
t
|
|
442
|
-
t
|
|
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');
|
|
443
486
|
t.end();
|
|
444
487
|
});
|
|
445
488
|
|
|
@@ -453,8 +496,8 @@ test('is.gt', function (t) {
|
|
|
453
496
|
t.notOk(is.gt(Infinity, 0), 'infinity is not greater than anything');
|
|
454
497
|
t.notOk(is.gt(0, Infinity), 'anything is not greater than infinity');
|
|
455
498
|
var error = new TypeError('NaN is not a valid value');
|
|
456
|
-
t
|
|
457
|
-
t
|
|
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');
|
|
458
501
|
t.end();
|
|
459
502
|
});
|
|
460
503
|
|
|
@@ -468,8 +511,8 @@ test('is.le', function (t) {
|
|
|
468
511
|
t.notOk(is.le(Infinity, 0), 'infinity is not lesser than or equal to anything');
|
|
469
512
|
t.notOk(is.le(0, Infinity), 'anything is not lesser than or equal to infinity');
|
|
470
513
|
var error = new TypeError('NaN is not a valid value');
|
|
471
|
-
t
|
|
472
|
-
t
|
|
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');
|
|
473
516
|
t.end();
|
|
474
517
|
});
|
|
475
518
|
|
|
@@ -483,30 +526,36 @@ test('is.lt', function (t) {
|
|
|
483
526
|
t.notOk(is.lt(Infinity, 0), 'infinity is not lesser than anything');
|
|
484
527
|
t.notOk(is.lt(0, Infinity), 'anything is not lesser than infinity');
|
|
485
528
|
var error = new TypeError('NaN is not a valid value');
|
|
486
|
-
t
|
|
487
|
-
t
|
|
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');
|
|
488
531
|
t.end();
|
|
489
532
|
});
|
|
490
533
|
|
|
491
534
|
test('is.within', function (t) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
t.throws
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
+
});
|
|
510
559
|
|
|
511
560
|
t.ok(is.within(2, 1, 3), '2 is between 1 and 3');
|
|
512
561
|
t.ok(is.within(0, -1, 1), '0 is between -1 and 1');
|
|
@@ -526,6 +575,31 @@ test('is.object', function (t) {
|
|
|
526
575
|
t.notOk(is.object(NaN), 'NaN is not an object');
|
|
527
576
|
t.notOk(is.object(Object), 'object constructor is not an object');
|
|
528
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
|
+
|
|
529
603
|
t.end();
|
|
530
604
|
});
|
|
531
605
|
|
|
@@ -535,25 +609,33 @@ test('is.hash', function (t) {
|
|
|
535
609
|
t.notOk(is.hash(), 'undefined is not a hash');
|
|
536
610
|
t.notOk(is.hash(null), 'null is not a hash');
|
|
537
611
|
t.notOk(is.hash(new Date()), 'date is not a hash');
|
|
538
|
-
t.notOk(is.hash(
|
|
612
|
+
t.notOk(is.hash(Object('')), 'string object is not a hash');
|
|
539
613
|
t.notOk(is.hash(''), 'string literal is not a hash');
|
|
540
|
-
t.notOk(is.hash(
|
|
614
|
+
t.notOk(is.hash(Object(0)), 'number object is not a hash');
|
|
541
615
|
t.notOk(is.hash(1), 'number literal is not a hash');
|
|
542
616
|
t.notOk(is.hash(true), 'true is not a hash');
|
|
543
617
|
t.notOk(is.hash(false), 'false is not a hash');
|
|
544
|
-
t.notOk(is.hash(
|
|
618
|
+
t.notOk(is.hash(Object(false)), 'boolean obj is not hash');
|
|
545
619
|
t.notOk(is.hash(false), 'literal false is not hash');
|
|
546
620
|
t.notOk(is.hash(true), 'literal true is not hash');
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
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
|
+
|
|
557
639
|
t.end();
|
|
558
640
|
});
|
|
559
641
|
|
|
@@ -568,11 +650,11 @@ test('is.regexp', function (t) {
|
|
|
568
650
|
|
|
569
651
|
test('is.string', function (t) {
|
|
570
652
|
t.ok(is.string('foo'), 'string literal is string');
|
|
571
|
-
t.ok(is.string(
|
|
653
|
+
t.ok(is.string(Object('foo')), 'string object is string');
|
|
572
654
|
t.notOk(is.string(), 'undefined is not string');
|
|
573
655
|
t.notOk(is.string(String), 'string constructor is not string');
|
|
574
656
|
var F = function () {};
|
|
575
|
-
F.prototype =
|
|
657
|
+
F.prototype = Object('');
|
|
576
658
|
t.notOk(is.string(F), 'string subtype is not string');
|
|
577
659
|
t.end();
|
|
578
660
|
});
|
|
@@ -595,27 +677,52 @@ test('is.hex', function (t) {
|
|
|
595
677
|
});
|
|
596
678
|
|
|
597
679
|
test('is.symbol', function (t) {
|
|
598
|
-
t.test('not symbols', function (
|
|
680
|
+
t.test('not symbols', function (st) {
|
|
599
681
|
var notSymbols = [true, false, null, undefined, {}, [], function () {}, 42, NaN, Infinity, /a/g, '', 0, -0, new Error('error')];
|
|
600
682
|
forEach(notSymbols, function (notSymbol) {
|
|
601
|
-
|
|
683
|
+
st.notOk(is.symbol(notSymbol), notSymbol + ' is not symbol');
|
|
602
684
|
});
|
|
603
685
|
|
|
604
|
-
|
|
686
|
+
st.end();
|
|
605
687
|
});
|
|
606
688
|
|
|
607
|
-
t.test('symbols', { skip: typeof Symbol !== 'function' }, function (
|
|
608
|
-
|
|
689
|
+
t.test('symbols', { skip: typeof Symbol !== 'function' }, function (st) {
|
|
690
|
+
st.ok(is.symbol(Symbol('foo')), 'Symbol("foo") is symbol');
|
|
609
691
|
|
|
610
|
-
var
|
|
692
|
+
var notKnownSymbols = ['length', 'name', 'arguments', 'caller', 'prototype', 'for', 'keyFor'];
|
|
611
693
|
var symbolKeys = Object.getOwnPropertyNames(Symbol).filter(function (name) {
|
|
612
|
-
return
|
|
694
|
+
return notKnownSymbols.indexOf(name) < 0;
|
|
613
695
|
});
|
|
614
696
|
forEach(symbolKeys, function (symbolKey) {
|
|
615
|
-
|
|
697
|
+
st.ok(is.symbol(Symbol[symbolKey]), symbolKey + ' is symbol');
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
st.end();
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
t.end();
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
test('is.bigint', function (t) {
|
|
707
|
+
t.test('not bigints', function (st) {
|
|
708
|
+
var notBigints = [true, false, null, undefined, {}, [], function () {}, 42, NaN, Infinity, /a/g, '', 0, -0, new Error('error')];
|
|
709
|
+
forEach(notBigints, function (notBigint) {
|
|
710
|
+
st.notOk(is.bigint(notBigint), notBigint + ' is not bigint');
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
st.end();
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
t.test('bigints', { skip: typeof BigInt !== 'function' }, function (st) {
|
|
717
|
+
var bigInts = [
|
|
718
|
+
Function('return 42n')(), // eslint-disable-line no-new-func
|
|
719
|
+
BigInt(42)
|
|
720
|
+
];
|
|
721
|
+
forEach(bigInts, function (bigInt) {
|
|
722
|
+
st.ok(is.bigint(bigInt), bigInt + ' is bigint');
|
|
616
723
|
});
|
|
617
724
|
|
|
618
|
-
|
|
725
|
+
st.end();
|
|
619
726
|
});
|
|
620
727
|
|
|
621
728
|
t.end();
|