is 3.3.0 → 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,818 +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 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;
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;