-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
752 lines (745 loc) · 25.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/**
* @file
* <a href="https://travis-ci.org/Xotic750/is-x"
* title="Travis status">
* <img src="https://travis-ci.org/Xotic750/is-x.svg?branch=master"
* alt="Travis status" height="18">
* </a>
* <a href="https://david-dm.org/Xotic750/is-x"
* title="Dependency status">
* <img src="https://david-dm.org/Xotic750/is-x.svg"
* alt="Dependency status" height="18"/>
* </a>
* <a href="https://david-dm.org/Xotic750/is-x#info=devDependencies"
* title="devDependency status">
* <img src="https://david-dm.org/Xotic750/is-x/dev-status.svg"
* alt="devDependency status" height="18"/>
* </a>
* <a href="https://badge.fury.io/js/is-x" title="npm version">
* <img src="https://badge.fury.io/js/is-x.svg"
* alt="npm version" height="18">
* </a>
*
* A collection of the best JavaScript type testing methods.
*
* <h2>ECMAScript compatibility shims for legacy JavaScript engines</h2>
* `es5-shim.js` monkey-patches a JavaScript context to contain all EcmaScript 5
* methods that can be faithfully emulated with a legacy JavaScript engine.
*
* `es5-sham.js` monkey-patches other ES5 methods as closely as possible.
* For these methods, as closely as possible to ES5 is not very close.
* Many of these shams are intended only to allow code to be written to ES5
* without causing run-time errors in older engines. In many cases,
* this means that these shams cause many ES5 methods to silently fail.
* Decide carefully whether this is what you want. Note: es5-sham.js requires
* es5-shim.js to be able to work properly.
*
* `json3.js` monkey-patches the EcmaScript 5 JSON implimentation faithfully.
*
* `es6.shim.js` provides compatibility shims so that legacy JavaScript engines
* behave as closely as possible to ECMAScript 6 (Harmony).
*
* @version 1.0.12
* @author Xotic750 <Xotic750@gmail.com>
* @copyright Xotic750
* @license {@link <https://opensource.org/licenses/MIT> MIT}
* @see https://github.com/Xotic750/is-x
* @module is-x
*/
/*jslint maxlen:80, es6:true, this:true, white:true */
/*jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, forin:true,
freeze:true, futurehostile:true, latedef:true, newcap:true, nocomma:true,
nonbsp:true, singleGroups:true, strict:true, undef:true, unused:true,
es3:true, esnext:true, plusplus:true, maxparams:4, maxdepth:2,
maxstatements:19, maxcomplexity:11 */
/*global require, module */
;(function () {
'use strict';
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1,
ES = require('es-abstract/es6'),
define = require('define-properties-x'),
hasOwnProperty = require('has-own-property-x'),
toStringTag = require('to-string-tag-x'),
isPrimitive = require('is-primitive'),
isNil = require('is-nil-x'),
isNativeLD = require('lodash.isnative'),
deepEqual = require('deep-equal-x'),
getFunctionName = require('get-function-name-x'),
s = require('white-space-x').ws,
pIsPrototypeOf = Object.prototype.isPrototypeOf,
fToString = Function.prototype.toString,
sReplace = String.prototype.replace,
sMatch = String.prototype.match,
reIsUint = /^(?:0|[1-9]\d*)$/,
FN_STAR = [
new RegExp('^[' + s + ']*function[' + s + ']*(\\*?)[' + s + ']+', 'i')
],
STRIP_COMMENTS = [/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, ' '];
function isSafeInteger(value) {
return ES.IsInteger(value) &&
value >= -MAX_SAFE_INTEGER &&
value <= MAX_SAFE_INTEGER;
}
define.properties(module.exports, {
/**
* Checks if `value` is `null` or `undefined`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is nullish, else `false`.
*/
isNil: isNil,
/**
* Checks if `value` is `null`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is `null`, else `false`.
*/
isNull: require('lodash.isnull'),
/**
* Checks if `value` is `undefined`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is `undefined`, else `false`.
*/
isUndefined: require('validate.io-undefined'),
/**
* Checks if `value1` is `value2` using == equality.
*
* @function
* @param {*} value1 The first value to check.
* @param {*} value2 The second value to check.
* @return {boolean} Returns `true` if `value1` == `value2`, else `false`.
*/
isEqual: function isEqual(value1, value2) {
/*jshint eqeqeq:false */
return value1 == value2;
},
/**
* Checks if `value1` is `value2` using === equality.
*
* @function
* @param {*} value1 The first value to check.
* @param {*} value2 The second value to check.
* @return {boolean} Returns `true` if `value1` === `value2`, else `false`.
*/
isStrictEqual: function isStrictEqual(value1, value2) {
return value1 === value2;
},
/**
* Checks if `value1` is greater than `value2`.
*
* @function
* @param {*} value1 The first value to check.
* @param {*} value2 The second value to check.
* @return {boolean} Returns `true` if `value1` > `value2`, else `false`.
*/
isGt: function isGt(value1, value2) {
return value1 > value2;
},
/**
* Checks if `value1` is greater than or equal to `value2`.
*
* @function
* @param {*} value1 The first value to check.
* @param {*} value2 The second value to check.
* @return {boolean} Returns `true` if `value1` >= `value2`, else `false`.
*/
isGte: function isGt(value1, value2) {
return value1 >= value2;
},
/**
* Checks if `value1` is less than `value2`.
*
* @function
* @param {*} value1 The first value to check.
* @param {*} value2 The second value to check.
* @return {boolean} Returns `true` if `value1` < `value2`, else `false`.
*/
isLt: function isLt(value1, value2) {
return value1 < value2;
},
/**
* Checks if `value1` is less than or equal to `value2`.
*
* @function
* @param {*} value1 The first value to check.
* @param {*} value2 The second value to check.
* @return {boolean} Returns `true` if `value1` <= `value2`, else `false`.
*/
isLte: function isLt(value1, value2) {
return value1 <= value2;
},
/**
* Checks if `value` is likely an `arguments` object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
*/
isArguments: require('is-arguments'),
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
*/
isString: require('is-string'),
/**
* Checks if `value` is classified as a boolean primitive or object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a boolean, else `false`.
*/
isBoolean: require('is-boolean-object'),
/**
* Checks if `value` is classified as a `Number` primitive or object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
*/
isNumber: require('is-number-object'),
/**
* Checks if `value` is classified as a `Date` object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a Date object,
* else `false`.
*/
isDate: require('is-date-object'),
/**
* Checks if `value` is `NaN`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is `NaN`, else `false`.
*/
isNaN: Number.isNaN,
/**
* Checks if `value` is a finite primitive number.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a finite number,
* else `false`.
*/
isFinite: Number.isFinite,
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
*/
isSymbol: require('is-symbol'),
/**
* Checks if `value` is classified as a typed array.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
*/
isTypedArray: require('is-typed-array'),
/**
* Checks if `value` is a primitive.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a primitive,
* else `false`.
*/
isPrimitive: isPrimitive,
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @function
* @return {boolean} Returns `true` if `value` is a plain object,
* else `false`.
*/
isPlainObject: require('lodash.isplainobject'),
/**
* Checks if `value` is a 'Function`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a `Function`,
* else `false`.
*/
isCallable: ES.IsCallable,
/**
* Checks if `value` is a 'constructor`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a `constructor`,
* else `false`.
*/
isConstructor: ES.IsConstructor,
/**
* Checks if `value` is callable.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is callable, else `false`.
*/
isFunction: require('is-function-x'),
/**
* Checks if `value` is classified as a `RegExp` object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is correctly classified,
* else `false`.
*/
isRegExp: ES.IsRegExp,
/**
* Checks if `value` is not a primitive.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is an object, else `false`.
*/
isObject: function isObject(value) {
return !isPrimitive(value);
},
/**
* Checks if `value` is object-like. A value is object-like if it's not a
* primitive and not a function.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is object-like,
* else `false`.
*/
isObjectLike: require('is-object-like-x'),
/**
* Checks if `value`'s string tag is the supplied `stringTag`.
*
* @function
* @param {*} value The value to check.
* @param {string} stringTag The value to check.
* @return {boolean} Returns `true` if `value`'s the string tag matches
* `stringTag`, else `false`.
*/
isStringTag: function isStringTag(value, stringTag) {
return typeof stringTag === 'string' && toStringTag(value) === stringTag;
},
/**
* Checks if `value` is classified as an `Array` object.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is an `Array`, else `false`.
*/
isArray: ES.IsArray,
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is array-like, else `false`.
*/
isArrayLike: require('is-array-like-x'),
/**
* This method allows you to check whether or not an object
* exists within another object's prototype chain.
*
* @function
* @param {*} prototypeObj An object to be tested against each link in the
* prototype chain of the object argument.
* @param {*} object The object whose prototype chain will be searched.
* @return {boolean} Returns `true` if `prototypeObj` is in `object`'s
* prototype chain, else `false`.
*/
isProtoOf: function isProtoOf(prototypeObj, object) {
if (isNil(prototypeObj) || isNil(object)) {
return false;
}
return ES.Call(pIsPrototypeOf, prototypeObj, [object]);
},
/**
* An object is frozen if and only if it is not extensible, all its
* properties are non-configurable, and all its data properties
* (that is, properties which are not accessor properties with getter
* or setter components) are non-writable.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is frozen, else `false`.
*/
isFrozen: Object.isFrozen,
/**
* Returns true if the object is sealed, otherwise false. An object is
* sealed if it is not extensible and if all its properties are
* non-configurable and therefore not removable
* (but not necessarily non-writable).
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is sealed, else `false`.
*/
isSealed: Object.isSealed,
/**
* This method determines whether two values are the same value. Two values
* are the same if one of the following holds:
* - both undefined
* - both null
* - both true or both false
* - both strings of the same length with the same characters
* - both the same object
* - both numbers and
* - both +0
* - both -0
* - both NaN
* - both non-zero and both not NaN and both have the same value
* This is not the same as being equal according to the == operator.
* The == operator applies various coercions to both sides (if they are
* not the same Type) before testing for equality (resulting in such
* behavior as "" == false being true), but Object.is doesn't coerce
* either value.
*
* @function
* @param {*} value1 The first value to compare.
* @param {*} value2 The second value to compare.
* @return {boolean} `true` if the two values are the same value, else
* `false`.
*/
is: ES.SameValue,
/**
* This method determines whether two values are the same value. Two values
* are the same if one of the following holds:
* - both undefined
* - both null
* - both true or both false
* - both strings of the same length with the same characters
* - both the same object
* - both numbers and
* - both 0 regardless of sign
* - both NaN
* - both non-zero and both not NaN and both have the same value
* This is not the same as being equal according to the == operator.
* The == operator applies various coercions to both sides (if they are
* not the same Type) before testing for equality (resulting in such
* behavior as "" == false being true), but `is` doesn't coerce
* either value.
*
* `isSameValueZero` differs from `is` only in its treatment of +0 and -0.
*
* @function
* @param {*} value1 The first value to compare.
* @param {*} value2 The second value to compare.
* @return {boolean} `true` if the two values are the same value, else
* `false`.
*/
isSameValueZero: ES.SameValueZero,
/**
* Determines if an object is `-0`.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is `-0`, else `false`.
*/
isNegativeZero: function isNegativeZero(value) {
return ES.SameValue(value, -0);
},
/**
* Determines if an object is extensible (whether it can have new
* properties added to it).
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is extensible, else `false`.
*/
isExtensible: ES.IsExtensible,
/**
* Checks if `value` is an integer.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is an integer, else `false`.
*/
isInteger: ES.IsInteger,
/**
* Checks if `value` is a safe integer. An integer is safe if it's
* an IEEE-754 double precision number which isn't the result of a rounded
* unsafe integer.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a safe integer,
* else `false`.
*/
isSafeInteger: isSafeInteger,
/**
* The abstract operation IsPropertyKey determines if argument, which must
* be an ECMAScript language value or a Completion Record, is a value that
* may be used as a property key.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a property key,
* else `false`.
*/
isPropertyKey: ES.IsPropertyKey,
/**
* Checks if `value` is a valid array-like length.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a valid length,
* else `false`.
*/
isLength: require('lodash.islength'),
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a valid index,
* else `false`.
*/
isIndex: function isIndex(value) {
var val;
if (typeof value === 'number' || reIsUint.test(value)) {
val = ES.ToNumber(value);
}
return ES.IsInteger(val) && val >= 0 && val < MAX_SAFE_INTEGER;
},
/**
* Checks if `value` is a native function.
*
* @function
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a native function,
* else `false`.
*/
isNative: isNativeLD,
/**
* Tests for deep equality. Primitive values are compared with the equal
* comparison operator ( == ). This only considers enumerable properties.
* It does not test object prototypes, attached symbols, or non-enumerable
* properties. This can lead to some potentially surprising results
*
* @param {*} value1 First comparison object.
* @param {*} value2 Second comparison object.
* @return {boolean} `true` if `actual` and `expected` are deemed equal,
* otherwise `false`. Circular objects will return `false`.
* @see https://nodejs.org/api/assert.html
*/
isDeepEqual: function isDeepEqual(value1, value2) {
try {
return deepEqual(value1, value2);
} catch (ignore) {}
return false;
},
/**
* Tests for deep equality. Primitive values are compared with the equal
* comparison operator ( === ).
*
* @param {*} value1 First comparison object.
* @param {*} value2 Second comparison object.
* @return {boolean} `true` if `actual` and `expected` are deemed equal,
* otherwise `false`. Circular objects will return `false`.
* @see https://nodejs.org/api/assert.html
*/
isStrictDeepEqual: function isStrictDeepEqual(value1, value2) {
try {
return deepEqual(value1, value2, true);
} catch (ignore) {}
return false;
},
/**
* Checks if `value` is likely a DOM element.
*
* @param {*} value The value to check.
* @return {boolean} Returns `true` if `value` is a DOM element,
* else `false`.
*/
isElement: require('lodash.iselement'),
/**
* This method returns `true` if the string indicating the type of the
* unevaluated operand matches `typeOfString`.
*
* @function
* @param {*} value The object to test.
* @param {string} typeOfString The `typeof` string to test.
* @return {boolean} `true` if the `typeof object` string matches
* `typeOfString`, else false`.
*/
isTypeOf: function isTypeOf(value, typeOfString) {
return typeof typeOfString === 'string' && typeof value === typeOfString;
},
/**
* Determine if an `object` is a node's `Buffer` class.
*
* @function
* @param {*} object The object to test.
* @return {boolean} `true` if the `object` is a `Buffer`, else false`.
* @see https://iojs.org/api/buffer.html
*/
isBuffer: require('is-buffer'),
/**
* Determine if an `object` is an `ArrayBuffer`.
*
* @function
* @param {*} object The object to test.
* @return {boolean} `true` if the `object` is an `ArrayBuffer`,
* else false`.
*/
isArrayBuffer: require('is-array-buffer-x'),
/**
* Determine if an `object` is a `DataView`.
*
* @function
* @param {*} object The object to test.
* @return {boolean} `true` if the `object` is a `DataView`,
* else false`.
*/
isDataView: require('is-data-view-x'),
/**
* This method returns `true` if the `object` has the specified `property`.
*
* @function
* @param {*} object The object to test.
* @param {string|Symbol} property The name or Symbol of the property to
* test.
* @return {boolean} `true` if the `object` has the specified `property`,
* else false`.
*/
isOwnPropertyOf: function isOwnPropertyOf(object, property) {
return !isNil(object) &&
ES.IsPropertyKey(property) &&
hasOwnProperty(ES.ToObject(object), property);
},
/**
* This method returns true if the specified `property` is in the specified
* `object`.
*
* @function
* @param {*} object The object to test.
* @param {string|Symbol} property The name or Symbol of the property to
* test.
* @return {boolean} `true` if the property is set on `object`, else
* `false`.
*/
isPropertyOf: function isPropertyOf(object, property) {
return !isNil(object) &&
ES.IsPropertyKey(property) &&
property in ES.ToObject(object);
},
/**
* Tests if the two character arguments combined are a valid UTF-16
* surrogate pair.
*
* @param {*} char1 The first character of a suspected surrogate pair.
* @param {*} char2 The second character of a suspected surrogate pair.
* @return {boolean} Returns true if the two characters create a valid
* UTF-16 surrogate pair; otherwise false.
*/
isSurrogatePair: require('is-surrogate-pair-x'),
/**
* Determine if an `object` is an `Arrow Function`.
*
* @function
* @param {*} object The object to test.
* @return {boolean} `true` if the `object` is an `Arrow Function`,
* else false`.
*/
isArrowFunction: require('is-arrow-function'),
/**
* Determine whether or not a given `value` is an `Error` type.
*
* @function
* @param {*} value The object to be tested.
* @return {boolean} Returns `true` if `value` is an `Error` type,
* else `false`.
*/
isError: require('is-error-x'),
/**
* Determine whether or not a given `value` is a `Map`.
*
* @function
* @param {*} value The object to be tested.
* @return {boolean} Returns `true` if `value` is a `Map`, else `false`.
*/
isMap: require('is-map-x'),
/**
* Determine whether or not a given `value` is a `Set`.
*
* @function
* @param {*} value The object to be tested.
* @return {boolean} Returns `true` if `value` is a `Set`, else `false`.
*/
isSet: require('is-set-x'),
/**
* Determine whether or not a given function is named `name`.
*
* @function
* @param {Function} fn The function to be tested.
* @param {string} name The object to be tested.
* @return {boolean} Returns `true` if function name is a `name`,
* else `false`.
*/
isFunctionName: function isFunctionName(fn, name) {
return ES.IsCallable(fn) &&
typeof name === 'string' &&
getFunctionName(fn) === name;
},
/**
* Determine whether or not a given function is anonymous.
*
* @function
* @param {Function} fn The function to be tested.
* @return {boolean} Returns `true` if function is anonymous, else `false`.
*/
isAnonymous: function isAnonymous(fn) {
return ES.IsCallable(fn) && getFunctionName(fn) === '';
},
/**
* Determine whether or not a given function's arity matches `arity`.
*
* @function
* @param {Function} fn The function to be tested.
* @param {number} arity The `arity` integer to be tested.
* @return {boolean} Returns `true` if the function's arity matched `arity`,
* else `false`.
*/
isArity: function isArity(fn, arity) {
return ES.IsCallable(fn) && isSafeInteger(arity) && fn.length === arity;
},
/**
* Determine whether or not a given function is an ES6 generator function.
*
* @function
* @param {Function} fn The function to be tested.
* @return {boolean} Returns `true` if the function an ES6 generator
* function, else `false`.
*/
isGenerator: function isGenerator(fn) {
var match;
if (!ES.IsCallable(fn)) {
return false;
}
match = ES.Call(
sMatch,
ES.Call(sReplace, ES.Call(fToString, fn), STRIP_COMMENTS),
FN_STAR
);
return !!match && match[1] === '*';
}
});
}());