is 3.2.1 → 3.3.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/index.js CHANGED
@@ -1,800 +1,818 @@
1
- /* globals window, HTMLElement */
2
-
3
- 'use strict';
4
-
5
- /**!
6
- * is
7
- * the definitive JavaScript type testing library
8
- *
9
- * @copyright 2013-2014 Enrico Marino / Jordan Harband
10
- * @license MIT
11
- */
12
-
13
- var objProto = Object.prototype;
14
- var owns = objProto.hasOwnProperty;
15
- var toStr = objProto.toString;
16
- var symbolValueOf;
17
- if (typeof Symbol === 'function') {
18
- symbolValueOf = Symbol.prototype.valueOf;
19
- }
20
- var isActualNaN = function (value) {
21
- return value !== value;
22
- };
23
- var NON_HOST_TYPES = {
24
- 'boolean': 1,
25
- number: 1,
26
- string: 1,
27
- undefined: 1
28
- };
29
-
30
- var base64Regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/;
31
- var hexRegex = /^[A-Fa-f0-9]+$/;
32
-
33
- /**
34
- * Expose `is`
35
- */
36
-
37
- var is = {};
38
-
39
- /**
40
- * Test general.
41
- */
42
-
43
- /**
44
- * is.type
45
- * Test if `value` is a type of `type`.
46
- *
47
- * @param {Mixed} value value to test
48
- * @param {String} type type
49
- * @return {Boolean} true if `value` is a type of `type`, false otherwise
50
- * @api public
51
- */
52
-
53
- is.a = is.type = function (value, type) {
54
- return typeof value === type;
55
- };
56
-
57
- /**
58
- * is.defined
59
- * Test if `value` is defined.
60
- *
61
- * @param {Mixed} value value to test
62
- * @return {Boolean} true if 'value' is defined, false otherwise
63
- * @api public
64
- */
65
-
66
- is.defined = function (value) {
67
- return typeof value !== 'undefined';
68
- };
69
-
70
- /**
71
- * is.empty
72
- * Test if `value` is empty.
73
- *
74
- * @param {Mixed} value value to test
75
- * @return {Boolean} true if `value` is empty, false otherwise
76
- * @api public
77
- */
78
-
79
- is.empty = function (value) {
80
- var type = toStr.call(value);
81
- var key;
82
-
83
- if (type === '[object Array]' || type === '[object Arguments]' || type === '[object String]') {
84
- return value.length === 0;
85
- }
86
-
87
- if (type === '[object Object]') {
88
- for (key in value) {
89
- if (owns.call(value, key)) {
90
- return false;
91
- }
92
- }
93
- return true;
94
- }
95
-
96
- return !value;
97
- };
98
-
99
- /**
100
- * is.equal
101
- * Test if `value` is equal to `other`.
102
- *
103
- * @param {Mixed} value value to test
104
- * @param {Mixed} other value to compare with
105
- * @return {Boolean} true if `value` is equal to `other`, false otherwise
106
- */
107
-
108
- is.equal = function equal(value, other) {
109
- if (value === other) {
110
- return true;
111
- }
112
-
113
- var type = toStr.call(value);
114
- var key;
115
-
116
- if (type !== toStr.call(other)) {
117
- return false;
118
- }
119
-
120
- if (type === '[object Object]') {
121
- for (key in value) {
122
- if (!is.equal(value[key], other[key]) || !(key in other)) {
123
- return false;
124
- }
125
- }
126
- for (key in other) {
127
- if (!is.equal(value[key], other[key]) || !(key in value)) {
128
- return false;
129
- }
130
- }
131
- return true;
132
- }
133
-
134
- if (type === '[object Array]') {
135
- key = value.length;
136
- if (key !== other.length) {
137
- return false;
138
- }
139
- while (key--) {
140
- if (!is.equal(value[key], other[key])) {
141
- return false;
142
- }
143
- }
144
- return true;
145
- }
146
-
147
- if (type === '[object Function]') {
148
- return value.prototype === other.prototype;
149
- }
150
-
151
- if (type === '[object Date]') {
152
- return value.getTime() === other.getTime();
153
- }
154
-
155
- return false;
156
- };
157
-
158
- /**
159
- * is.hosted
160
- * Test if `value` is hosted by `host`.
161
- *
162
- * @param {Mixed} value to test
163
- * @param {Mixed} host host to test with
164
- * @return {Boolean} true if `value` is hosted by `host`, false otherwise
165
- * @api public
166
- */
167
-
168
- is.hosted = function (value, host) {
169
- var type = typeof host[value];
170
- return type === 'object' ? !!host[value] : !NON_HOST_TYPES[type];
171
- };
172
-
173
- /**
174
- * is.instance
175
- * Test if `value` is an instance of `constructor`.
176
- *
177
- * @param {Mixed} value value to test
178
- * @return {Boolean} true if `value` is an instance of `constructor`
179
- * @api public
180
- */
181
-
182
- is.instance = is['instanceof'] = function (value, constructor) {
183
- return value instanceof constructor;
184
- };
185
-
186
- /**
187
- * is.nil / is.null
188
- * Test if `value` is null.
189
- *
190
- * @param {Mixed} value value to test
191
- * @return {Boolean} true if `value` is null, false otherwise
192
- * @api public
193
- */
194
-
195
- is.nil = is['null'] = function (value) {
196
- return value === null;
197
- };
198
-
199
- /**
200
- * is.undef / is.undefined
201
- * Test if `value` is undefined.
202
- *
203
- * @param {Mixed} value value to test
204
- * @return {Boolean} true if `value` is undefined, false otherwise
205
- * @api public
206
- */
207
-
208
- is.undef = is.undefined = function (value) {
209
- return typeof value === 'undefined';
210
- };
211
-
212
- /**
213
- * Test arguments.
214
- */
215
-
216
- /**
217
- * is.args
218
- * Test if `value` is an arguments object.
219
- *
220
- * @param {Mixed} value value to test
221
- * @return {Boolean} true if `value` is an arguments object, false otherwise
222
- * @api public
223
- */
224
-
225
- is.args = is.arguments = function (value) {
226
- var isStandardArguments = toStr.call(value) === '[object Arguments]';
227
- var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
228
- return isStandardArguments || isOldArguments;
229
- };
230
-
231
- /**
232
- * Test array.
233
- */
234
-
235
- /**
236
- * is.array
237
- * Test if 'value' is an array.
238
- *
239
- * @param {Mixed} value value to test
240
- * @return {Boolean} true if `value` is an array, false otherwise
241
- * @api public
242
- */
243
-
244
- is.array = Array.isArray || function (value) {
245
- return toStr.call(value) === '[object Array]';
246
- };
247
-
248
- /**
249
- * is.arguments.empty
250
- * Test if `value` is an empty arguments object.
251
- *
252
- * @param {Mixed} value value to test
253
- * @return {Boolean} true if `value` is an empty arguments object, false otherwise
254
- * @api public
255
- */
256
- is.args.empty = function (value) {
257
- return is.args(value) && value.length === 0;
258
- };
259
-
260
- /**
261
- * is.array.empty
262
- * Test if `value` is an empty array.
263
- *
264
- * @param {Mixed} value value to test
265
- * @return {Boolean} true if `value` is an empty array, false otherwise
266
- * @api public
267
- */
268
- is.array.empty = function (value) {
269
- return is.array(value) && value.length === 0;
270
- };
271
-
272
- /**
273
- * is.arraylike
274
- * Test if `value` is an arraylike object.
275
- *
276
- * @param {Mixed} value value to test
277
- * @return {Boolean} true if `value` is an arguments object, false otherwise
278
- * @api public
279
- */
280
-
281
- is.arraylike = function (value) {
282
- return !!value && !is.bool(value)
283
- && owns.call(value, 'length')
284
- && isFinite(value.length)
285
- && is.number(value.length)
286
- && value.length >= 0;
287
- };
288
-
289
- /**
290
- * Test boolean.
291
- */
292
-
293
- /**
294
- * is.bool
295
- * Test if `value` is a boolean.
296
- *
297
- * @param {Mixed} value value to test
298
- * @return {Boolean} true if `value` is a boolean, false otherwise
299
- * @api public
300
- */
301
-
302
- is.bool = is['boolean'] = function (value) {
303
- return toStr.call(value) === '[object Boolean]';
304
- };
305
-
306
- /**
307
- * is.false
308
- * Test if `value` is false.
309
- *
310
- * @param {Mixed} value value to test
311
- * @return {Boolean} true if `value` is false, false otherwise
312
- * @api public
313
- */
314
-
315
- is['false'] = function (value) {
316
- return is.bool(value) && Boolean(Number(value)) === false;
317
- };
318
-
319
- /**
320
- * is.true
321
- * Test if `value` is true.
322
- *
323
- * @param {Mixed} value value to test
324
- * @return {Boolean} true if `value` is true, false otherwise
325
- * @api public
326
- */
327
-
328
- is['true'] = function (value) {
329
- return is.bool(value) && Boolean(Number(value)) === true;
330
- };
331
-
332
- /**
333
- * Test date.
334
- */
335
-
336
- /**
337
- * is.date
338
- * Test if `value` is a date.
339
- *
340
- * @param {Mixed} value value to test
341
- * @return {Boolean} true if `value` is a date, false otherwise
342
- * @api public
343
- */
344
-
345
- is.date = function (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));
358
- };
359
-
360
- /**
361
- * Test element.
362
- */
363
-
364
- /**
365
- * is.element
366
- * Test if `value` is an html element.
367
- *
368
- * @param {Mixed} value value to test
369
- * @return {Boolean} true if `value` is an HTML Element, false otherwise
370
- * @api public
371
- */
372
-
373
- is.element = function (value) {
374
- return value !== undefined
375
- && typeof HTMLElement !== 'undefined'
376
- && value instanceof HTMLElement
377
- && value.nodeType === 1;
378
- };
379
-
380
- /**
381
- * Test error.
382
- */
383
-
384
- /**
385
- * is.error
386
- * Test if `value` is an error object.
387
- *
388
- * @param {Mixed} value value to test
389
- * @return {Boolean} true if `value` is an error object, false otherwise
390
- * @api public
391
- */
392
-
393
- is.error = function (value) {
394
- return toStr.call(value) === '[object Error]';
395
- };
396
-
397
- /**
398
- * Test function.
399
- */
400
-
401
- /**
402
- * is.fn / is.function (deprecated)
403
- * Test if `value` is a function.
404
- *
405
- * @param {Mixed} value value to test
406
- * @return {Boolean} true if `value` is a function, false otherwise
407
- * @api public
408
- */
409
-
410
- is.fn = is['function'] = function (value) {
411
- var isAlert = typeof window !== 'undefined' && value === window.alert;
412
- if (isAlert) {
413
- return true;
414
- }
415
- var str = toStr.call(value);
416
- return str === '[object Function]' || str === '[object GeneratorFunction]' || str === '[object AsyncFunction]';
417
- };
418
-
419
- /**
420
- * Test number.
421
- */
422
-
423
- /**
424
- * is.number
425
- * Test if `value` is a number.
426
- *
427
- * @param {Mixed} value value to test
428
- * @return {Boolean} true if `value` is a number, false otherwise
429
- * @api public
430
- */
431
-
432
- is.number = function (value) {
433
- return toStr.call(value) === '[object Number]';
434
- };
435
-
436
- /**
437
- * is.infinite
438
- * Test if `value` is positive or negative infinity.
439
- *
440
- * @param {Mixed} value value to test
441
- * @return {Boolean} true if `value` is positive or negative Infinity, false otherwise
442
- * @api public
443
- */
444
- is.infinite = function (value) {
445
- return value === Infinity || value === -Infinity;
446
- };
447
-
448
- /**
449
- * is.decimal
450
- * Test if `value` is a decimal number.
451
- *
452
- * @param {Mixed} value value to test
453
- * @return {Boolean} true if `value` is a decimal number, false otherwise
454
- * @api public
455
- */
456
-
457
- is.decimal = function (value) {
458
- return is.number(value) && !isActualNaN(value) && !is.infinite(value) && value % 1 !== 0;
459
- };
460
-
461
- /**
462
- * is.divisibleBy
463
- * Test if `value` is divisible by `n`.
464
- *
465
- * @param {Number} value value to test
466
- * @param {Number} n dividend
467
- * @return {Boolean} true if `value` is divisible by `n`, false otherwise
468
- * @api public
469
- */
470
-
471
- is.divisibleBy = function (value, n) {
472
- var isDividendInfinite = is.infinite(value);
473
- var isDivisorInfinite = is.infinite(n);
474
- var isNonZeroNumber = is.number(value) && !isActualNaN(value) && is.number(n) && !isActualNaN(n) && n !== 0;
475
- return isDividendInfinite || isDivisorInfinite || (isNonZeroNumber && value % n === 0);
476
- };
477
-
478
- /**
479
- * is.integer
480
- * Test if `value` is an integer.
481
- *
482
- * @param value to test
483
- * @return {Boolean} true if `value` is an integer, false otherwise
484
- * @api public
485
- */
486
-
487
- is.integer = is['int'] = function (value) {
488
- return is.number(value) && !isActualNaN(value) && value % 1 === 0;
489
- };
490
-
491
- /**
492
- * is.maximum
493
- * Test if `value` is greater than 'others' values.
494
- *
495
- * @param {Number} value value to test
496
- * @param {Array} others values to compare with
497
- * @return {Boolean} true if `value` is greater than `others` values
498
- * @api public
499
- */
500
-
501
- is.maximum = function (value, others) {
502
- if (isActualNaN(value)) {
503
- throw new TypeError('NaN is not a valid value');
504
- } else if (!is.arraylike(others)) {
505
- throw new TypeError('second argument must be array-like');
506
- }
507
- var len = others.length;
508
-
509
- while (--len >= 0) {
510
- if (value < others[len]) {
511
- return false;
512
- }
513
- }
514
-
515
- return true;
516
- };
517
-
518
- /**
519
- * is.minimum
520
- * Test if `value` is less than `others` values.
521
- *
522
- * @param {Number} value value to test
523
- * @param {Array} others values to compare with
524
- * @return {Boolean} true if `value` is less than `others` values
525
- * @api public
526
- */
527
-
528
- is.minimum = function (value, others) {
529
- if (isActualNaN(value)) {
530
- throw new TypeError('NaN is not a valid value');
531
- } else if (!is.arraylike(others)) {
532
- throw new TypeError('second argument must be array-like');
533
- }
534
- var len = others.length;
535
-
536
- while (--len >= 0) {
537
- if (value > others[len]) {
538
- return false;
539
- }
540
- }
541
-
542
- return true;
543
- };
544
-
545
- /**
546
- * is.nan
547
- * Test if `value` is not a number.
548
- *
549
- * @param {Mixed} value value to test
550
- * @return {Boolean} true if `value` is not a number, false otherwise
551
- * @api public
552
- */
553
-
554
- is.nan = function (value) {
555
- return !is.number(value) || value !== value;
556
- };
557
-
558
- /**
559
- * is.even
560
- * Test if `value` is an even number.
561
- *
562
- * @param {Number} value value to test
563
- * @return {Boolean} true if `value` is an even number, false otherwise
564
- * @api public
565
- */
566
-
567
- is.even = function (value) {
568
- return is.infinite(value) || (is.number(value) && value === value && value % 2 === 0);
569
- };
570
-
571
- /**
572
- * is.odd
573
- * Test if `value` is an odd number.
574
- *
575
- * @param {Number} value value to test
576
- * @return {Boolean} true if `value` is an odd number, false otherwise
577
- * @api public
578
- */
579
-
580
- is.odd = function (value) {
581
- return is.infinite(value) || (is.number(value) && value === value && value % 2 !== 0);
582
- };
583
-
584
- /**
585
- * is.ge
586
- * Test if `value` is greater than or equal to `other`.
587
- *
588
- * @param {Number} value value to test
589
- * @param {Number} other value to compare with
590
- * @return {Boolean}
591
- * @api public
592
- */
593
-
594
- is.ge = function (value, other) {
595
- if (isActualNaN(value) || isActualNaN(other)) {
596
- throw new TypeError('NaN is not a valid value');
597
- }
598
- return !is.infinite(value) && !is.infinite(other) && value >= other;
599
- };
600
-
601
- /**
602
- * is.gt
603
- * Test if `value` is greater than `other`.
604
- *
605
- * @param {Number} value value to test
606
- * @param {Number} other value to compare with
607
- * @return {Boolean}
608
- * @api public
609
- */
610
-
611
- is.gt = function (value, other) {
612
- if (isActualNaN(value) || isActualNaN(other)) {
613
- throw new TypeError('NaN is not a valid value');
614
- }
615
- return !is.infinite(value) && !is.infinite(other) && value > other;
616
- };
617
-
618
- /**
619
- * is.le
620
- * Test if `value` is less than or equal to `other`.
621
- *
622
- * @param {Number} value value to test
623
- * @param {Number} other value to compare with
624
- * @return {Boolean} if 'value' is less than or equal to 'other'
625
- * @api public
626
- */
627
-
628
- is.le = function (value, other) {
629
- if (isActualNaN(value) || isActualNaN(other)) {
630
- throw new TypeError('NaN is not a valid value');
631
- }
632
- return !is.infinite(value) && !is.infinite(other) && value <= other;
633
- };
634
-
635
- /**
636
- * is.lt
637
- * Test if `value` is less than `other`.
638
- *
639
- * @param {Number} value value to test
640
- * @param {Number} other value to compare with
641
- * @return {Boolean} if `value` is less than `other`
642
- * @api public
643
- */
644
-
645
- is.lt = function (value, other) {
646
- if (isActualNaN(value) || isActualNaN(other)) {
647
- throw new TypeError('NaN is not a valid value');
648
- }
649
- return !is.infinite(value) && !is.infinite(other) && value < other;
650
- };
651
-
652
- /**
653
- * is.within
654
- * Test if `value` is within `start` and `finish`.
655
- *
656
- * @param {Number} value value to test
657
- * @param {Number} start lower bound
658
- * @param {Number} finish upper bound
659
- * @return {Boolean} true if 'value' is is within 'start' and 'finish'
660
- * @api public
661
- */
662
- is.within = function (value, start, finish) {
663
- if (isActualNaN(value) || isActualNaN(start) || isActualNaN(finish)) {
664
- throw new TypeError('NaN is not a valid value');
665
- } else if (!is.number(value) || !is.number(start) || !is.number(finish)) {
666
- throw new TypeError('all arguments must be numbers');
667
- }
668
- var isAnyInfinite = is.infinite(value) || is.infinite(start) || is.infinite(finish);
669
- return isAnyInfinite || (value >= start && value <= finish);
670
- };
671
-
672
- /**
673
- * Test object.
674
- */
675
-
676
- /**
677
- * is.object
678
- * Test if `value` is an object.
679
- *
680
- * @param {Mixed} value value to test
681
- * @return {Boolean} true if `value` is an object, false otherwise
682
- * @api public
683
- */
684
- is.object = function (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;
704
- };
705
-
706
- /**
707
- * is.hash
708
- * Test if `value` is a hash - a plain object literal.
709
- *
710
- * @param {Mixed} value value to test
711
- * @return {Boolean} true if `value` is a hash, false otherwise
712
- * @api public
713
- */
714
-
715
- is.hash = function (value) {
716
- return is.object(value) && value.constructor === Object && !value.nodeType && !value.setInterval;
717
- };
718
-
719
- /**
720
- * Test regexp.
721
- */
722
-
723
- /**
724
- * is.regexp
725
- * Test if `value` is a regular expression.
726
- *
727
- * @param {Mixed} value value to test
728
- * @return {Boolean} true if `value` is a regexp, false otherwise
729
- * @api public
730
- */
731
-
732
- is.regexp = function (value) {
733
- return toStr.call(value) === '[object RegExp]';
734
- };
735
-
736
- /**
737
- * Test string.
738
- */
739
-
740
- /**
741
- * is.string
742
- * Test if `value` is a string.
743
- *
744
- * @param {Mixed} value value to test
745
- * @return {Boolean} true if 'value' is a string, false otherwise
746
- * @api public
747
- */
748
-
749
- is.string = function (value) {
750
- return toStr.call(value) === '[object String]';
751
- };
752
-
753
- /**
754
- * Test base64 string.
755
- */
756
-
757
- /**
758
- * is.base64
759
- * Test if `value` is a valid base64 encoded string.
760
- *
761
- * @param {Mixed} value value to test
762
- * @return {Boolean} true if 'value' is a base64 encoded string, false otherwise
763
- * @api public
764
- */
765
-
766
- is.base64 = function (value) {
767
- return is.string(value) && (!value.length || base64Regex.test(value));
768
- };
769
-
770
- /**
771
- * Test base64 string.
772
- */
773
-
774
- /**
775
- * is.hex
776
- * Test if `value` is a valid hex encoded string.
777
- *
778
- * @param {Mixed} value value to test
779
- * @return {Boolean} true if 'value' is a hex encoded string, false otherwise
780
- * @api public
781
- */
782
-
783
- is.hex = function (value) {
784
- return is.string(value) && (!value.length || hexRegex.test(value));
785
- };
786
-
787
- /**
788
- * is.symbol
789
- * Test if `value` is an ES6 Symbol
790
- *
791
- * @param {Mixed} value value to test
792
- * @return {Boolean} true if `value` is a Symbol, false otherise
793
- * @api public
794
- */
795
-
796
- is.symbol = function (value) {
797
- return typeof Symbol === 'function' && toStr.call(value) === '[object Symbol]' && typeof symbolValueOf.call(value) === 'symbol';
798
- };
799
-
800
- module.exports = is;
1
+ /* globals window, HTMLElement */
2
+
3
+ 'use strict';
4
+
5
+ /**!
6
+ * is
7
+ * the definitive JavaScript type testing library
8
+ *
9
+ * @copyright 2013-2014 Enrico Marino / Jordan Harband
10
+ * @license MIT
11
+ */
12
+
13
+ var objProto = Object.prototype;
14
+ var owns = objProto.hasOwnProperty;
15
+ var toStr = objProto.toString;
16
+ var symbolValueOf;
17
+ if (typeof Symbol === 'function') {
18
+ symbolValueOf = Symbol.prototype.valueOf;
19
+ }
20
+ var bigIntValueOf;
21
+ if (typeof BigInt === 'function') {
22
+ bigIntValueOf = BigInt.prototype.valueOf;
23
+ }
24
+ var isActualNaN = function (value) {
25
+ return value !== value;
26
+ };
27
+ var NON_HOST_TYPES = {
28
+ 'boolean': 1,
29
+ number: 1,
30
+ string: 1,
31
+ undefined: 1
32
+ };
33
+
34
+ var base64Regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/;
35
+ var hexRegex = /^[A-Fa-f0-9]+$/;
36
+
37
+ /**
38
+ * Expose `is`
39
+ */
40
+
41
+ var is = {};
42
+
43
+ /**
44
+ * Test general.
45
+ */
46
+
47
+ /**
48
+ * is.type
49
+ * Test if `value` is a type of `type`.
50
+ *
51
+ * @param {*} value value to test
52
+ * @param {String} type type
53
+ * @return {Boolean} true if `value` is a type of `type`, false otherwise
54
+ * @api public
55
+ */
56
+
57
+ is.a = is.type = function (value, type) {
58
+ return typeof value === type;
59
+ };
60
+
61
+ /**
62
+ * is.defined
63
+ * Test if `value` is defined.
64
+ *
65
+ * @param {*} value value to test
66
+ * @return {Boolean} true if 'value' is defined, false otherwise
67
+ * @api public
68
+ */
69
+
70
+ is.defined = function (value) {
71
+ return typeof value !== 'undefined';
72
+ };
73
+
74
+ /**
75
+ * is.empty
76
+ * Test if `value` is empty.
77
+ *
78
+ * @param {*} value value to test
79
+ * @return {Boolean} true if `value` is empty, false otherwise
80
+ * @api public
81
+ */
82
+
83
+ is.empty = function (value) {
84
+ var type = toStr.call(value);
85
+ var key;
86
+
87
+ if (type === '[object Array]' || type === '[object Arguments]' || type === '[object String]') {
88
+ return value.length === 0;
89
+ }
90
+
91
+ if (type === '[object Object]') {
92
+ for (key in value) {
93
+ if (owns.call(value, key)) {
94
+ return false;
95
+ }
96
+ }
97
+ return true;
98
+ }
99
+
100
+ return !value;
101
+ };
102
+
103
+ /**
104
+ * is.equal
105
+ * Test if `value` is equal to `other`.
106
+ *
107
+ * @param {*} value value to test
108
+ * @param {*} other value to compare with
109
+ * @return {Boolean} true if `value` is equal to `other`, false otherwise
110
+ */
111
+
112
+ is.equal = function equal(value, other) {
113
+ if (value === other) {
114
+ return true;
115
+ }
116
+
117
+ var type = toStr.call(value);
118
+ var key;
119
+
120
+ if (type !== toStr.call(other)) {
121
+ return false;
122
+ }
123
+
124
+ if (type === '[object Object]') {
125
+ for (key in value) {
126
+ if (!is.equal(value[key], other[key]) || !(key in other)) {
127
+ return false;
128
+ }
129
+ }
130
+ for (key in other) {
131
+ if (!is.equal(value[key], other[key]) || !(key in value)) {
132
+ return false;
133
+ }
134
+ }
135
+ return true;
136
+ }
137
+
138
+ if (type === '[object Array]') {
139
+ key = value.length;
140
+ if (key !== other.length) {
141
+ return false;
142
+ }
143
+ while (key--) {
144
+ if (!is.equal(value[key], other[key])) {
145
+ return false;
146
+ }
147
+ }
148
+ return true;
149
+ }
150
+
151
+ if (type === '[object Function]') {
152
+ return value.prototype === other.prototype;
153
+ }
154
+
155
+ if (type === '[object Date]') {
156
+ return value.getTime() === other.getTime();
157
+ }
158
+
159
+ return false;
160
+ };
161
+
162
+ /**
163
+ * is.hosted
164
+ * Test if `value` is hosted by `host`.
165
+ *
166
+ * @param {*} value to test
167
+ * @param {*} host host to test with
168
+ * @return {Boolean} true if `value` is hosted by `host`, false otherwise
169
+ * @api public
170
+ */
171
+
172
+ is.hosted = function (value, host) {
173
+ var type = typeof host[value];
174
+ return type === 'object' ? !!host[value] : !NON_HOST_TYPES[type];
175
+ };
176
+
177
+ /**
178
+ * is.instance
179
+ * Test if `value` is an instance of `constructor`.
180
+ *
181
+ * @param {*} value value to test
182
+ * @return {Boolean} true if `value` is an instance of `constructor`
183
+ * @api public
184
+ */
185
+
186
+ is.instance = is['instanceof'] = function (value, constructor) {
187
+ return value instanceof constructor;
188
+ };
189
+
190
+ /**
191
+ * is.nil / is.null
192
+ * Test if `value` is null.
193
+ *
194
+ * @param {*} value value to test
195
+ * @return {Boolean} true if `value` is null, false otherwise
196
+ * @api public
197
+ */
198
+
199
+ is.nil = is['null'] = function (value) {
200
+ return value === null;
201
+ };
202
+
203
+ /**
204
+ * is.undef / is.undefined
205
+ * Test if `value` is undefined.
206
+ *
207
+ * @param {*} value value to test
208
+ * @return {Boolean} true if `value` is undefined, false otherwise
209
+ * @api public
210
+ */
211
+
212
+ is.undef = is.undefined = function (value) {
213
+ return typeof value === 'undefined';
214
+ };
215
+
216
+ /**
217
+ * Test arguments.
218
+ */
219
+
220
+ /**
221
+ * is.args
222
+ * Test if `value` is an arguments object.
223
+ *
224
+ * @param {*} value value to test
225
+ * @return {Boolean} true if `value` is an arguments object, false otherwise
226
+ * @api public
227
+ */
228
+
229
+ is.args = is.arguments = function (value) {
230
+ var isStandardArguments = toStr.call(value) === '[object Arguments]';
231
+ var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
232
+ return isStandardArguments || isOldArguments;
233
+ };
234
+
235
+ /**
236
+ * Test array.
237
+ */
238
+
239
+ /**
240
+ * is.array
241
+ * Test if 'value' is an array.
242
+ *
243
+ * @param {*} value value to test
244
+ * @return {Boolean} true if `value` is an array, false otherwise
245
+ * @api public
246
+ */
247
+
248
+ is.array = Array.isArray || function (value) {
249
+ return toStr.call(value) === '[object Array]';
250
+ };
251
+
252
+ /**
253
+ * is.arguments.empty
254
+ * Test if `value` is an empty arguments object.
255
+ *
256
+ * @param {*} value value to test
257
+ * @return {Boolean} true if `value` is an empty arguments object, false otherwise
258
+ * @api public
259
+ */
260
+ is.args.empty = function (value) {
261
+ return is.args(value) && value.length === 0;
262
+ };
263
+
264
+ /**
265
+ * is.array.empty
266
+ * Test if `value` is an empty array.
267
+ *
268
+ * @param {*} value value to test
269
+ * @return {Boolean} true if `value` is an empty array, false otherwise
270
+ * @api public
271
+ */
272
+ is.array.empty = function (value) {
273
+ return is.array(value) && value.length === 0;
274
+ };
275
+
276
+ /**
277
+ * is.arraylike
278
+ * Test if `value` is an arraylike object.
279
+ *
280
+ * @param {*} value value to test
281
+ * @return {Boolean} true if `value` is an arguments object, false otherwise
282
+ * @api public
283
+ */
284
+
285
+ is.arraylike = function (value) {
286
+ return !!value && !is.bool(value)
287
+ && owns.call(value, 'length')
288
+ && isFinite(value.length)
289
+ && is.number(value.length)
290
+ && value.length >= 0;
291
+ };
292
+
293
+ /**
294
+ * Test boolean.
295
+ */
296
+
297
+ /**
298
+ * is.bool
299
+ * Test if `value` is a boolean.
300
+ *
301
+ * @param {*} value value to test
302
+ * @return {Boolean} true if `value` is a boolean, false otherwise
303
+ * @api public
304
+ */
305
+
306
+ is.bool = is['boolean'] = function (value) {
307
+ return toStr.call(value) === '[object Boolean]';
308
+ };
309
+
310
+ /**
311
+ * is.false
312
+ * Test if `value` is false.
313
+ *
314
+ * @param {*} value value to test
315
+ * @return {Boolean} true if `value` is false, false otherwise
316
+ * @api public
317
+ */
318
+
319
+ is['false'] = function (value) {
320
+ return is.bool(value) && Boolean(Number(value)) === false;
321
+ };
322
+
323
+ /**
324
+ * is.true
325
+ * Test if `value` is true.
326
+ *
327
+ * @param {*} value value to test
328
+ * @return {Boolean} true if `value` is true, false otherwise
329
+ * @api public
330
+ */
331
+
332
+ is['true'] = function (value) {
333
+ return is.bool(value) && Boolean(Number(value)) === true;
334
+ };
335
+
336
+ /**
337
+ * Test date.
338
+ */
339
+
340
+ /**
341
+ * is.date
342
+ * Test if `value` is a date.
343
+ *
344
+ * @param {*} value value to test
345
+ * @return {Boolean} true if `value` is a date, false otherwise
346
+ * @api public
347
+ */
348
+
349
+ is.date = function (value) {
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));
362
+ };
363
+
364
+ /**
365
+ * Test element.
366
+ */
367
+
368
+ /**
369
+ * is.element
370
+ * Test if `value` is an html element.
371
+ *
372
+ * @param {*} value value to test
373
+ * @return {Boolean} true if `value` is an HTML Element, false otherwise
374
+ * @api public
375
+ */
376
+
377
+ is.element = function (value) {
378
+ return value !== undefined
379
+ && typeof HTMLElement !== 'undefined'
380
+ && value instanceof HTMLElement
381
+ && value.nodeType === 1;
382
+ };
383
+
384
+ /**
385
+ * Test error.
386
+ */
387
+
388
+ /**
389
+ * is.error
390
+ * Test if `value` is an error object.
391
+ *
392
+ * @param {*} value value to test
393
+ * @return {Boolean} true if `value` is an error object, false otherwise
394
+ * @api public
395
+ */
396
+
397
+ is.error = function (value) {
398
+ return toStr.call(value) === '[object Error]';
399
+ };
400
+
401
+ /**
402
+ * Test function.
403
+ */
404
+
405
+ /**
406
+ * is.fn / is.function (deprecated)
407
+ * Test if `value` is a function.
408
+ *
409
+ * @param {*} value value to test
410
+ * @return {Boolean} true if `value` is a function, false otherwise
411
+ * @api public
412
+ */
413
+
414
+ is.fn = is['function'] = function (value) {
415
+ var isAlert = typeof window !== 'undefined' && value === window.alert;
416
+ if (isAlert) {
417
+ return true;
418
+ }
419
+ var str = toStr.call(value);
420
+ return str === '[object Function]' || str === '[object GeneratorFunction]' || str === '[object AsyncFunction]';
421
+ };
422
+
423
+ /**
424
+ * Test number.
425
+ */
426
+
427
+ /**
428
+ * is.number
429
+ * Test if `value` is a number.
430
+ *
431
+ * @param {*} value value to test
432
+ * @return {Boolean} true if `value` is a number, false otherwise
433
+ * @api public
434
+ */
435
+
436
+ is.number = function (value) {
437
+ return toStr.call(value) === '[object Number]';
438
+ };
439
+
440
+ /**
441
+ * is.infinite
442
+ * Test if `value` is positive or negative infinity.
443
+ *
444
+ * @param {*} value value to test
445
+ * @return {Boolean} true if `value` is positive or negative Infinity, false otherwise
446
+ * @api public
447
+ */
448
+ is.infinite = function (value) {
449
+ return value === Infinity || value === -Infinity;
450
+ };
451
+
452
+ /**
453
+ * is.decimal
454
+ * Test if `value` is a decimal number.
455
+ *
456
+ * @param {*} value value to test
457
+ * @return {Boolean} true if `value` is a decimal number, false otherwise
458
+ * @api public
459
+ */
460
+
461
+ is.decimal = function (value) {
462
+ return is.number(value) && !isActualNaN(value) && !is.infinite(value) && value % 1 !== 0;
463
+ };
464
+
465
+ /**
466
+ * is.divisibleBy
467
+ * Test if `value` is divisible by `n`.
468
+ *
469
+ * @param {Number} value value to test
470
+ * @param {Number} n dividend
471
+ * @return {Boolean} true if `value` is divisible by `n`, false otherwise
472
+ * @api public
473
+ */
474
+
475
+ is.divisibleBy = function (value, n) {
476
+ var isDividendInfinite = is.infinite(value);
477
+ var isDivisorInfinite = is.infinite(n);
478
+ var isNonZeroNumber = is.number(value) && !isActualNaN(value) && is.number(n) && !isActualNaN(n) && n !== 0;
479
+ return isDividendInfinite || isDivisorInfinite || (isNonZeroNumber && value % n === 0);
480
+ };
481
+
482
+ /**
483
+ * is.integer
484
+ * Test if `value` is an integer.
485
+ *
486
+ * @param value to test
487
+ * @return {Boolean} true if `value` is an integer, false otherwise
488
+ * @api public
489
+ */
490
+
491
+ is.integer = is['int'] = function (value) {
492
+ return is.number(value) && !isActualNaN(value) && value % 1 === 0;
493
+ };
494
+
495
+ /**
496
+ * is.maximum
497
+ * Test if `value` is greater than 'others' values.
498
+ *
499
+ * @param {Number} value value to test
500
+ * @param {Array} others values to compare with
501
+ * @return {Boolean} true if `value` is greater than `others` values
502
+ * @api public
503
+ */
504
+
505
+ is.maximum = function (value, others) {
506
+ if (isActualNaN(value)) {
507
+ throw new TypeError('NaN is not a valid value');
508
+ } else if (!is.arraylike(others)) {
509
+ throw new TypeError('second argument must be array-like');
510
+ }
511
+ var len = others.length;
512
+
513
+ while (--len >= 0) {
514
+ if (value < others[len]) {
515
+ return false;
516
+ }
517
+ }
518
+
519
+ return true;
520
+ };
521
+
522
+ /**
523
+ * is.minimum
524
+ * Test if `value` is less than `others` values.
525
+ *
526
+ * @param {Number} value value to test
527
+ * @param {Array} others values to compare with
528
+ * @return {Boolean} true if `value` is less than `others` values
529
+ * @api public
530
+ */
531
+
532
+ is.minimum = function (value, others) {
533
+ if (isActualNaN(value)) {
534
+ throw new TypeError('NaN is not a valid value');
535
+ } else if (!is.arraylike(others)) {
536
+ throw new TypeError('second argument must be array-like');
537
+ }
538
+ var len = others.length;
539
+
540
+ while (--len >= 0) {
541
+ if (value > others[len]) {
542
+ return false;
543
+ }
544
+ }
545
+
546
+ return true;
547
+ };
548
+
549
+ /**
550
+ * is.nan
551
+ * Test if `value` is not a number.
552
+ *
553
+ * @param {*} value value to test
554
+ * @return {Boolean} true if `value` is not a number, false otherwise
555
+ * @api public
556
+ */
557
+
558
+ is.nan = function (value) {
559
+ return !is.number(value) || value !== value;
560
+ };
561
+
562
+ /**
563
+ * is.even
564
+ * Test if `value` is an even number.
565
+ *
566
+ * @param {Number} value value to test
567
+ * @return {Boolean} true if `value` is an even number, false otherwise
568
+ * @api public
569
+ */
570
+
571
+ is.even = function (value) {
572
+ return is.infinite(value) || (is.number(value) && value === value && value % 2 === 0);
573
+ };
574
+
575
+ /**
576
+ * is.odd
577
+ * Test if `value` is an odd number.
578
+ *
579
+ * @param {Number} value value to test
580
+ * @return {Boolean} true if `value` is an odd number, false otherwise
581
+ * @api public
582
+ */
583
+
584
+ is.odd = function (value) {
585
+ return is.infinite(value) || (is.number(value) && value === value && value % 2 !== 0);
586
+ };
587
+
588
+ /**
589
+ * is.ge
590
+ * Test if `value` is greater than or equal to `other`.
591
+ *
592
+ * @param {Number} value value to test
593
+ * @param {Number} other value to compare with
594
+ * @return {Boolean}
595
+ * @api public
596
+ */
597
+
598
+ is.ge = function (value, other) {
599
+ if (isActualNaN(value) || isActualNaN(other)) {
600
+ throw new TypeError('NaN is not a valid value');
601
+ }
602
+ return !is.infinite(value) && !is.infinite(other) && value >= other;
603
+ };
604
+
605
+ /**
606
+ * is.gt
607
+ * Test if `value` is greater than `other`.
608
+ *
609
+ * @param {Number} value value to test
610
+ * @param {Number} other value to compare with
611
+ * @return {Boolean}
612
+ * @api public
613
+ */
614
+
615
+ is.gt = function (value, other) {
616
+ if (isActualNaN(value) || isActualNaN(other)) {
617
+ throw new TypeError('NaN is not a valid value');
618
+ }
619
+ return !is.infinite(value) && !is.infinite(other) && value > other;
620
+ };
621
+
622
+ /**
623
+ * is.le
624
+ * Test if `value` is less than or equal to `other`.
625
+ *
626
+ * @param {Number} value value to test
627
+ * @param {Number} other value to compare with
628
+ * @return {Boolean} if 'value' is less than or equal to 'other'
629
+ * @api public
630
+ */
631
+
632
+ is.le = function (value, other) {
633
+ if (isActualNaN(value) || isActualNaN(other)) {
634
+ throw new TypeError('NaN is not a valid value');
635
+ }
636
+ return !is.infinite(value) && !is.infinite(other) && value <= other;
637
+ };
638
+
639
+ /**
640
+ * is.lt
641
+ * Test if `value` is less than `other`.
642
+ *
643
+ * @param {Number} value value to test
644
+ * @param {Number} other value to compare with
645
+ * @return {Boolean} if `value` is less than `other`
646
+ * @api public
647
+ */
648
+
649
+ is.lt = function (value, other) {
650
+ if (isActualNaN(value) || isActualNaN(other)) {
651
+ throw new TypeError('NaN is not a valid value');
652
+ }
653
+ return !is.infinite(value) && !is.infinite(other) && value < other;
654
+ };
655
+
656
+ /**
657
+ * is.within
658
+ * Test if `value` is within `start` and `finish`.
659
+ *
660
+ * @param {Number} value value to test
661
+ * @param {Number} start lower bound
662
+ * @param {Number} finish upper bound
663
+ * @return {Boolean} true if 'value' is is within 'start' and 'finish'
664
+ * @api public
665
+ */
666
+ is.within = function (value, start, finish) {
667
+ if (isActualNaN(value) || isActualNaN(start) || isActualNaN(finish)) {
668
+ throw new TypeError('NaN is not a valid value');
669
+ } else if (!is.number(value) || !is.number(start) || !is.number(finish)) {
670
+ throw new TypeError('all arguments must be numbers');
671
+ }
672
+ var isAnyInfinite = is.infinite(value) || is.infinite(start) || is.infinite(finish);
673
+ return isAnyInfinite || (value >= start && value <= finish);
674
+ };
675
+
676
+ /**
677
+ * Test object.
678
+ */
679
+
680
+ /**
681
+ * is.object
682
+ * Test if `value` is an object.
683
+ *
684
+ * @param {*} value value to test
685
+ * @return {Boolean} true if `value` is an object, false otherwise
686
+ * @api public
687
+ */
688
+ is.object = function (value) {
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;
708
+ };
709
+
710
+ /**
711
+ * is.hash
712
+ * Test if `value` is a hash - a plain object literal.
713
+ *
714
+ * @param {*} value value to test
715
+ * @return {Boolean} true if `value` is a hash, false otherwise
716
+ * @api public
717
+ */
718
+
719
+ is.hash = function (value) {
720
+ return is.object(value) && value.constructor === Object && !value.nodeType && !value.setInterval;
721
+ };
722
+
723
+ /**
724
+ * Test regexp.
725
+ */
726
+
727
+ /**
728
+ * is.regexp
729
+ * Test if `value` is a regular expression.
730
+ *
731
+ * @param {*} value value to test
732
+ * @return {Boolean} true if `value` is a regexp, false otherwise
733
+ * @api public
734
+ */
735
+
736
+ is.regexp = function (value) {
737
+ return toStr.call(value) === '[object RegExp]';
738
+ };
739
+
740
+ /**
741
+ * Test string.
742
+ */
743
+
744
+ /**
745
+ * is.string
746
+ * Test if `value` is a string.
747
+ *
748
+ * @param {*} value value to test
749
+ * @return {Boolean} true if 'value' is a string, false otherwise
750
+ * @api public
751
+ */
752
+
753
+ is.string = function (value) {
754
+ return toStr.call(value) === '[object String]';
755
+ };
756
+
757
+ /**
758
+ * Test base64 string.
759
+ */
760
+
761
+ /**
762
+ * is.base64
763
+ * Test if `value` is a valid base64 encoded string.
764
+ *
765
+ * @param {*} value value to test
766
+ * @return {Boolean} true if 'value' is a base64 encoded string, false otherwise
767
+ * @api public
768
+ */
769
+
770
+ is.base64 = function (value) {
771
+ return is.string(value) && (!value.length || base64Regex.test(value));
772
+ };
773
+
774
+ /**
775
+ * Test base64 string.
776
+ */
777
+
778
+ /**
779
+ * is.hex
780
+ * Test if `value` is a valid hex encoded string.
781
+ *
782
+ * @param {*} value value to test
783
+ * @return {Boolean} true if 'value' is a hex encoded string, false otherwise
784
+ * @api public
785
+ */
786
+
787
+ is.hex = function (value) {
788
+ return is.string(value) && (!value.length || hexRegex.test(value));
789
+ };
790
+
791
+ /**
792
+ * is.symbol
793
+ * Test if `value` is an ES6 Symbol
794
+ *
795
+ * @param {*} value value to test
796
+ * @return {Boolean} true if `value` is a Symbol, false otherise
797
+ * @api public
798
+ */
799
+
800
+ is.symbol = function (value) {
801
+ return typeof Symbol === 'function' && toStr.call(value) === '[object Symbol]' && typeof symbolValueOf.call(value) === 'symbol';
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;