Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathunderscore.js
More file actions
Latest commit
2077 lines (1848 loc) · 68 KB
/
Copy pathunderscore.js
File metadata and controls
2077 lines (1848 loc) · 68 KB
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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(global,factory){
typeofexports==='object'&&typeofmodule!=='undefined' ? module.exports=factory() :
typeofdefine==='function'&&define.amd ? define('underscore',factory) :
(global=typeofglobalThis!=='undefined' ? globalThis : global||self,(function(){
varcurrent=global._;
varexports=global._=factory();
exports.noConflict=function(){global._=current;returnexports;};
}()));
}(this,(function(){
// Underscore.js 1.13.8
// https://underscorejs.org
// (c) 2009-2026 Jeremy Ashkenas, Julian Gonggrijp, and DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.
// Current version.
varVERSION='1.13.8';
// Establish the root object, `window` (`self`) in the browser, `global`
// on the server, or `this` in some virtual machines. We use `self`
// instead of `window` for `WebWorker` support.
varroot=(typeofself=='object'&&self.self===self&&self)||
(typeofglobal=='object'&&global.global===global&&global)||
Function('return this')()||
{};
// Save bytes in the minified (but not gzipped) version:
varArrayProto=Array.prototype,ObjProto=Object.prototype;
varSymbolProto=typeofSymbol!=='undefined' ? Symbol.prototype : null;
// Create quick reference variables for speed access to core prototypes.
varpush=ArrayProto.push,
slice=ArrayProto.slice,
toString=ObjProto.toString,
hasOwnProperty=ObjProto.hasOwnProperty;
// Modern feature detection.
varsupportsArrayBuffer=typeofArrayBuffer!=='undefined',
supportsDataView=typeofDataView!=='undefined';
// All **ECMAScript 5+** native function implementations that we hope to use
// are declared here.
varnativeIsArray=Array.isArray,
nativeKeys=Object.keys,
nativeCreate=Object.create,
nativeIsView=supportsArrayBuffer&&ArrayBuffer.isView;
// Create references to these builtin functions because we override them.
var_isNaN=isNaN,
_isFinite=isFinite;
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
varhasEnumBug=!{toString: null}.propertyIsEnumerable('toString');
varnonEnumerableProps=['valueOf','isPrototypeOf','toString',
'propertyIsEnumerable','hasOwnProperty','toLocaleString'];
// The largest integer that can be represented exactly.
varMAX_ARRAY_INDEX=Math.pow(2,53)-1;
// Some functions take a variable number of arguments, or a few expected
// arguments at the beginning and then a variable number of values to operate
// on. This helper accumulates all remaining arguments past the function’s
// argument length (or an explicit `startIndex`), into an array that becomes
// the last argument. Similar to ES6’s "rest parameter".
functionrestArguments(func,startIndex){
startIndex=startIndex==null ? func.length-1 : +startIndex;
returnfunction(){
varlength=Math.max(arguments.length-startIndex,0),
rest=Array(length),
index=0;
for(;index<length;index++){
rest[index]=arguments[index+startIndex];
}
switch(startIndex){
case0: returnfunc.call(this,rest);
case1: returnfunc.call(this,arguments[0],rest);
case2: returnfunc.call(this,arguments[0],arguments[1],rest);
}
varargs=Array(startIndex+1);
for(index=0;index<startIndex;index++){
args[index]=arguments[index];
}
args[startIndex]=rest;
returnfunc.apply(this,args);
};
}
// Is a given variable an object?
functionisObject(obj){
vartype=typeofobj;
returntype==='function'||(type==='object'&&!!obj);
}
// Is a given value equal to null?
functionisNull(obj){
returnobj===null;
}
// Is a given variable undefined?
functionisUndefined(obj){
returnobj===void0;
}
// Is a given value a boolean?
functionisBoolean(obj){
returnobj===true||obj===false||toString.call(obj)==='[object Boolean]';
}
// Is a given value a DOM element?
functionisElement(obj){
return!!(obj&&obj.nodeType===1);
}
// Internal function for creating a `toString`-based type tester.
functiontagTester(name){
vartag='[object '+name+']';
returnfunction(obj){
returntoString.call(obj)===tag;
};
}
varisString=tagTester('String');
varisNumber=tagTester('Number');
varisDate=tagTester('Date');
varisRegExp=tagTester('RegExp');
varisError=tagTester('Error');
varisSymbol=tagTester('Symbol');
varisArrayBuffer=tagTester('ArrayBuffer');
varisFunction=tagTester('Function');
// Optimize `isFunction` if appropriate. Work around some `typeof` bugs in old
// v8, IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
varnodelist=root.document&&root.document.childNodes;
if(typeof/./!='function'&&typeofInt8Array!='object'&&typeofnodelist!='function'){
isFunction=function(obj){
returntypeofobj=='function'||false;
};
}
varisFunction$1=isFunction;
varhasObjectTag=tagTester('Object');
// In IE 10 - Edge 13, `DataView` has string tag `'[object Object]'`.
// In IE 11, the most common among them, this problem also applies to
// `Map`, `WeakMap` and `Set`.
// Also, there are cases where an application can override the native
// `DataView` object, in cases like that we can't use the constructor
// safely and should just rely on alternate `DataView` checks
varhasDataViewBug=(
supportsDataView&&(!/\[nativecode\]/.test(String(DataView))||hasObjectTag(newDataView(newArrayBuffer(8))))
),
isIE11=(typeofMap!=='undefined'&&hasObjectTag(newMap));
varisDataView=tagTester('DataView');
// In IE 10 - Edge 13, we need a different heuristic
// to determine whether an object is a `DataView`.
// Also, in cases where the native `DataView` is
// overridden we can't rely on the tag itself.
functionalternateIsDataView(obj){
returnobj!=null&&isFunction$1(obj.getInt8)&&isArrayBuffer(obj.buffer);
}
varisDataView$1=(hasDataViewBug ? alternateIsDataView : isDataView);
// Is a given value an array?
// Delegates to ECMA5's native `Array.isArray`.
varisArray=nativeIsArray||tagTester('Array');
// Internal function to check whether `key` is an own property name of `obj`.
functionhas$1(obj,key){
returnobj!=null&&hasOwnProperty.call(obj,key);
}
varisArguments=tagTester('Arguments');
// Define a fallback version of the method in browsers (ahem, IE < 9), where
// there isn't any inspectable "Arguments" type.
(function(){
if(!isArguments(arguments)){
isArguments=function(obj){
returnhas$1(obj,'callee');
};
}
}());
varisArguments$1=isArguments;
// Is a given object a finite number?
functionisFinite$1(obj){
return!isSymbol(obj)&&_isFinite(obj)&&!isNaN(parseFloat(obj));
}
// Is the given value `NaN`?
functionisNaN$1(obj){
returnisNumber(obj)&&_isNaN(obj);
}
// Predicate-generating function. Often useful outside of Underscore.
functionconstant(value){
returnfunction(){
returnvalue;
};
}
// Common internal logic for `isArrayLike` and `isBufferLike`.
functioncreateSizePropertyCheck(getSizeProperty){
returnfunction(collection){
varsizeProperty=getSizeProperty(collection);
returntypeofsizeProperty=='number'&&sizeProperty>=0&&sizeProperty<=MAX_ARRAY_INDEX;
}
}
// Internal helper to generate a function to obtain property `key` from `obj`.
functionshallowProperty(key){
returnfunction(obj){
returnobj==null ? void0 : obj[key];
};
}
// Internal helper to obtain the `byteLength` property of an object.
vargetByteLength=shallowProperty('byteLength');
// Internal helper to determine whether we should spend extensive checks against
// `ArrayBuffer` et al.
varisBufferLike=createSizePropertyCheck(getByteLength);
// Is a given value a typed array?
vartypedArrayPattern=/\[object((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;
functionisTypedArray(obj){
// `ArrayBuffer.isView` is the most future-proof, so use it when available.
// Otherwise, fall back on the above regular expression.
returnnativeIsView ? (nativeIsView(obj)&&!isDataView$1(obj)) :
isBufferLike(obj)&&typedArrayPattern.test(toString.call(obj));
}
varisTypedArray$1=supportsArrayBuffer ? isTypedArray : constant(false);
// Internal helper to obtain the `length` property of an object.
vargetLength=shallowProperty('length');
// Internal helper to create a simple lookup structure.
// `collectNonEnumProps` used to depend on `_.contains`, but this led to
// circular imports. `emulatedSet` is a one-off solution that only works for
// arrays of strings.
functionemulatedSet(keys){
varhash={};
for(varl=keys.length,i=0;i<l;++i)hash[keys[i]]=true;
return{
contains: function(key){returnhash[key]===true;},
push: function(key){
hash[key]=true;
returnkeys.push(key);
}
};
}
// Internal helper. Checks `keys` for the presence of keys in IE < 9 that won't
// be iterated by `for key in ...` and thus missed. Extends `keys` in place if
// needed.
functioncollectNonEnumProps(obj,keys){
keys=emulatedSet(keys);
varnonEnumIdx=nonEnumerableProps.length;
varconstructor=obj.constructor;
varproto=(isFunction$1(constructor)&&constructor.prototype)||ObjProto;
// Constructor is a special case.
varprop='constructor';
if(has$1(obj,prop)&&!keys.contains(prop))keys.push(prop);
while(nonEnumIdx--){
prop=nonEnumerableProps[nonEnumIdx];
if(propinobj&&obj[prop]!==proto[prop]&&!keys.contains(prop)){
keys.push(prop);
}
}
}
// Retrieve the names of an object's own properties.
// Delegates to **ECMAScript 5**'s native `Object.keys`.
functionkeys(obj){
if(!isObject(obj))return[];
if(nativeKeys)returnnativeKeys(obj);
varkeys=[];
for(varkeyinobj)if(has$1(obj,key))keys.push(key);
// Ahem, IE < 9.
if(hasEnumBug)collectNonEnumProps(obj,keys);
returnkeys;
}
// Is a given array, string, or object empty?
// An "empty" object has no enumerable own-properties.
functionisEmpty(obj){
if(obj==null)returntrue;
// Skip the more expensive `toString`-based type checks if `obj` has no
// `.length`.
varlength=getLength(obj);
if(typeoflength=='number'&&(
isArray(obj)||isString(obj)||isArguments$1(obj)
))returnlength===0;
returngetLength(keys(obj))===0;
}
// Returns whether an object has a given set of `key:value` pairs.
functionisMatch(object,attrs){
var_keys=keys(attrs),length=_keys.length;
if(object==null)return!length;
varobj=Object(object);
for(vari=0;i<length;i++){
varkey=_keys[i];
if(attrs[key]!==obj[key]||!(keyinobj))returnfalse;
}
returntrue;
}
// If Underscore is called as a function, it returns a wrapped object that can
// be used OO-style. This wrapper holds altered versions of all functions added
// through `_.mixin`. Wrapped objects may be chained.
function_$1(obj){
if(objinstanceof_$1)returnobj;
if(!(thisinstanceof_$1))returnnew_$1(obj);
this._wrapped=obj;
}
_$1.VERSION=VERSION;
// Extracts the result from a wrapped and chained object.
_$1.prototype.value=function(){
returnthis._wrapped;
};
// Provide unwrapping proxies for some methods used in engine operations
// such as arithmetic and JSON stringification.
_$1.prototype.valueOf=_$1.prototype.toJSON=_$1.prototype.value;
_$1.prototype.toString=function(){
returnString(this._wrapped);
};
// Internal function to wrap or shallow-copy an ArrayBuffer,
// typed array or DataView to a new view, reusing the buffer.
functiontoBufferView(bufferSource){
returnnewUint8Array(
bufferSource.buffer||bufferSource,
bufferSource.byteOffset||0,
getByteLength(bufferSource)
);
}
// We use this string twice, so give it a name for minification.
vartagDataView='[object DataView]';
// Perform a deep comparison to check if two objects are equal.
functionisEqual(a,b){
// Keep track of which pairs of values need to be compared. We will be
// trampolining on this stack instead of using function recursion.
// (CVE-2026-27601)
vartodo=[{a: a,b: b}];
// Initializing stacks of traversed objects for cycle detection.
varaStack=[],bStack=[];
// Keep traversing pairs until there is nothing left to compare.
while(todo.length){
varframe=todo.pop();
// As a special case, a single `true` on the todo means that we can
// unwind the cycle detection stacks.
if(frame===true){
// Remove the first object from the stack of traversed objects.
aStack.pop();
bStack.pop();
continue;
}
a=frame.a;
b=frame.b;
// Identical objects are equal. `0 === -0`, but they aren't identical.
// See the [Harmony `egal` proposal](https://wiki.ecmascript.org/doku.php?id=harmony:egal).
if(a===b){
if(a!==0||1/a===1/b)continue;
returnfalse;
}
// `null` or `undefined` only equal to itself (strict comparison).
if(a==null||b==null)returnfalse;
// `NaN`s are equivalent, but non-reflexive.
if(a!==a){
if(b!==b)continue;
returnfalse;
}
// Exhaust primitive checks
vartype=typeofa;
if(type!=='function'&&type!=='object'&&typeofb!='object')returnfalse;
// Unwrap any wrapped objects.
if(ainstanceof_$1)a=a._wrapped;
if(binstanceof_$1)b=b._wrapped;
// Compare `[[Class]]` names.
varclassName=toString.call(a);
if(className!==toString.call(b))returnfalse;
// Work around a bug in IE 10 - Edge 13.
if(hasDataViewBug&&className=='[object Object]'&&isDataView$1(a)){
if(!isDataView$1(b))returnfalse;
className=tagDataView;
}
switch(className){
// These types are compared by value.
case'[object RegExp]':
// RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
case'[object String]':
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
// equivalent to `new String("5")`.
if(''+a===''+b)continue;
returnfalse;
case'[object Number]':
todo.push({a: +a,b: +b});
continue;
case'[object Date]':
case'[object Boolean]':
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
// millisecond representations. Note that invalid dates with millisecond representations
// of `NaN` are not equivalent.
if(+a===+b)continue;
returnfalse;
case'[object Symbol]':
if(SymbolProto.valueOf.call(a)===SymbolProto.valueOf.call(b))continue;
returnfalse;
case'[object ArrayBuffer]':
casetagDataView:
// Coerce to typed array so we can fall through.
todo.push({a: toBufferView(a),b: toBufferView(b)});
continue;
}
varareArrays=className==='[object Array]';
if(!areArrays&&isTypedArray$1(a)){
varbyteLength=getByteLength(a);
if(byteLength!==getByteLength(b))returnfalse;
if(a.buffer===b.buffer&&a.byteOffset===b.byteOffset)continue;
areArrays=true;
}
if(!areArrays){
if(typeofa!='object'||typeofb!='object')returnfalse;
// Objects with different constructors are not equivalent, but `Object`s or `Array`s
// from different frames are.
varaCtor=a.constructor,bCtor=b.constructor;
if(aCtor!==bCtor&&!(isFunction$1(aCtor)&&aCtorinstanceofaCtor&&
isFunction$1(bCtor)&&bCtorinstanceofbCtor)
&&('constructor'ina&&'constructor'inb)){
returnfalse;
}
}
// Assume equality for cyclic structures. The algorithm for detecting cyclic
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
varlength=aStack.length;
while(length--){
// Linear search. Performance is inversely proportional to the number of
// unique nested structures.
if(aStack[length]===a){
// Cycle detected. Break out of the inner loop and continue the outer
// loop. Step 1:
if(bStack[length]===b)break;
returnfalse;
}
}
// Step 2, use `length` to verify whether we detected a cycle:
if(length>=0)continue;
// Add the first object to the stack of traversed objects.
aStack.push(a);
bStack.push(b);
// Remember to remove them again after the recursion below.
todo.push(true);
// Recursively compare objects and arrays.
if(areArrays){
// Compare array lengths to determine if a deep comparison is necessary.
length=a.length;
if(length!==b.length)returnfalse;
// Deep compare the contents, ignoring non-numeric properties.
while(length--){
todo.push({a: a[length],b: b[length]});
}
}else{
// Deep compare objects.
var_keys=keys(a),key;
length=_keys.length;
// Ensure that both objects contain the same number of properties before comparing deep equality.
if(keys(b).length!==length)returnfalse;
while(length--){
// Deep compare each member
key=_keys[length];
if(!has$1(b,key))returnfalse;
todo.push({a: a[key],b: b[key]});
}
}
}
// We made it to the end and found no differences.
returntrue;
}
// Retrieve all the enumerable property names of an object.
functionallKeys(obj){
if(!isObject(obj))return[];
varkeys=[];
for(varkeyinobj)keys.push(key);
// Ahem, IE < 9.
if(hasEnumBug)collectNonEnumProps(obj,keys);
returnkeys;
}
// Since the regular `Object.prototype.toString` type tests don't work for
// some types in IE 11, we use a fingerprinting heuristic instead, based
// on the methods. It's not great, but it's the best we got.
// The fingerprint method lists are defined below.
functionie11fingerprint(methods){
varlength=getLength(methods);
returnfunction(obj){
if(obj==null)returnfalse;
// `Map`, `WeakMap` and `Set` have no enumerable keys.
varkeys=allKeys(obj);
if(getLength(keys))returnfalse;
for(vari=0;i<length;i++){
if(!isFunction$1(obj[methods[i]]))returnfalse;
}
// If we are testing against `WeakMap`, we need to ensure that
// `obj` doesn't have a `forEach` method in order to distinguish
// it from a regular `Map`.
returnmethods!==weakMapMethods||!isFunction$1(obj[forEachName]);
};
}
// In the interest of compact minification, we write
// each string in the fingerprints only once.
varforEachName='forEach',
hasName='has',
commonInit=['clear','delete'],
mapTail=['get',hasName,'set'];
// `Map`, `WeakMap` and `Set` each have slightly different
// combinations of the above sublists.
varmapMethods=commonInit.concat(forEachName,mapTail),
weakMapMethods=commonInit.concat(mapTail),
setMethods=['add'].concat(commonInit,forEachName,hasName);
varisMap=isIE11 ? ie11fingerprint(mapMethods) : tagTester('Map');
varisWeakMap=isIE11 ? ie11fingerprint(weakMapMethods) : tagTester('WeakMap');
varisSet=isIE11 ? ie11fingerprint(setMethods) : tagTester('Set');
varisWeakSet=tagTester('WeakSet');
// Retrieve the values of an object's properties.
functionvalues(obj){
var_keys=keys(obj);
varlength=_keys.length;
varvalues=Array(length);
for(vari=0;i<length;i++){
values[i]=obj[_keys[i]];
}
returnvalues;
}
// Convert an object into a list of `[key, value]` pairs.
// The opposite of `_.object` with one argument.
functionpairs(obj){
var_keys=keys(obj);
varlength=_keys.length;
varpairs=Array(length);
for(vari=0;i<length;i++){
pairs[i]=[_keys[i],obj[_keys[i]]];
}
returnpairs;
}
// Invert the keys and values of an object. The values must be serializable.
functioninvert(obj){
varresult={};
var_keys=keys(obj);
for(vari=0,length=_keys.length;i<length;i++){
result[obj[_keys[i]]]=_keys[i];
}
returnresult;
}
// Return a sorted list of the function names available on the object.
functionfunctions(obj){
varnames=[];
for(varkeyinobj){
if(isFunction$1(obj[key]))names.push(key);
}
returnnames.sort();
}
// An internal function for creating assigner functions.
functioncreateAssigner(keysFunc,defaults){
returnfunction(obj){
varlength=arguments.length;
if(defaults)obj=Object(obj);
if(length<2||obj==null)returnobj;
for(varindex=1;index<length;index++){
varsource=arguments[index],
keys=keysFunc(source),
l=keys.length;
for(vari=0;i<l;i++){
varkey=keys[i];
if(!defaults||obj[key]===void0)obj[key]=source[key];
}
}
returnobj;
};
}
// Extend a given object with all the properties in passed-in object(s).
varextend=createAssigner(allKeys);
// Assigns a given object with all the own properties in the passed-in
// object(s).
// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
varextendOwn=createAssigner(keys);
// Fill in a given object with default properties.
vardefaults=createAssigner(allKeys,true);
// Create a naked function reference for surrogate-prototype-swapping.
functionctor(){
returnfunction(){};
}
// An internal function for creating a new object that inherits from another.
functionbaseCreate(prototype){
if(!isObject(prototype))return{};
if(nativeCreate)returnnativeCreate(prototype);
varCtor=ctor();
Ctor.prototype=prototype;
varresult=newCtor;
Ctor.prototype=null;
returnresult;
}
// Creates an object that inherits from the given prototype object.
// If additional properties are provided then they will be added to the
// created object.
functioncreate(prototype,props){
varresult=baseCreate(prototype);
if(props)extendOwn(result,props);
returnresult;
}
// Create a (shallow-cloned) duplicate of an object.
functionclone(obj){
if(!isObject(obj))returnobj;
returnisArray(obj) ? obj.slice() : extend({},obj);
}
// Invokes `interceptor` with the `obj` and then returns `obj`.
// The primary purpose of this method is to "tap into" a method chain, in
// order to perform operations on intermediate results within the chain.
functiontap(obj,interceptor){
interceptor(obj);
returnobj;
}
// Normalize a (deep) property `path` to array.
// Like `_.iteratee`, this function can be customized.
functiontoPath$1(path){
returnisArray(path) ? path : [path];
}
_$1.toPath=toPath$1;
// Internal wrapper for `_.toPath` to enable minification.
// Similar to `cb` for `_.iteratee`.
functiontoPath(path){
return_$1.toPath(path);
}
// Internal function to obtain a nested property in `obj` along `path`.
functiondeepGet(obj,path){
varlength=path.length;
for(vari=0;i<length;i++){
if(obj==null)returnvoid0;
obj=obj[path[i]];
}
returnlength ? obj : void0;
}
// Get the value of the (deep) property on `path` from `object`.
// If any property in `path` does not exist or if the value is
// `undefined`, return `defaultValue` instead.
// The `path` is normalized through `_.toPath`.
functionget(object,path,defaultValue){
varvalue=deepGet(object,toPath(path));
returnisUndefined(value) ? defaultValue : value;
}
// Shortcut function for checking if an object has a given property directly on
// itself (in other words, not on a prototype). Unlike the internal `has`
// function, this public version can also traverse nested properties.
functionhas(obj,path){
path=toPath(path);
varlength=path.length;
for(vari=0;i<length;i++){
varkey=path[i];
if(!has$1(obj,key))returnfalse;
obj=obj[key];
}
return!!length;
}
// Keep the identity function around for default iteratees.
functionidentity(value){
returnvalue;
}
// Returns a predicate for checking whether an object has a given set of
// `key:value` pairs.
functionmatcher(attrs){
attrs=extendOwn({},attrs);
returnfunction(obj){
returnisMatch(obj,attrs);
};
}
// Creates a function that, when passed an object, will traverse that object’s
// properties down the given `path`, specified as an array of keys or indices.
functionproperty(path){
path=toPath(path);
returnfunction(obj){
returndeepGet(obj,path);
};
}
// Internal function that returns an efficient (for current engines) version
// of the passed-in callback, to be repeatedly applied in other Underscore
// functions.
functionoptimizeCb(func,context,argCount){
if(context===void0)returnfunc;
switch(argCount==null ? 3 : argCount){
case1: returnfunction(value){
returnfunc.call(context,value);
};
// The 2-argument case is omitted because we’re not using it.
case3: returnfunction(value,index,collection){
returnfunc.call(context,value,index,collection);
};
case4: returnfunction(accumulator,value,index,collection){
returnfunc.call(context,accumulator,value,index,collection);
};
}
returnfunction(){
returnfunc.apply(context,arguments);
};
}
// An internal function to generate callbacks that can be applied to each
// element in a collection, returning the desired result — either `_.identity`,
// an arbitrary callback, a property matcher, or a property accessor.
functionbaseIteratee(value,context,argCount){
if(value==null)returnidentity;
if(isFunction$1(value))returnoptimizeCb(value,context,argCount);
if(isObject(value)&&!isArray(value))returnmatcher(value);
returnproperty(value);
}
// External wrapper for our callback generator. Users may customize
// `_.iteratee` if they want additional predicate/iteratee shorthand styles.
// This abstraction hides the internal-only `argCount` argument.
functioniteratee(value,context){
returnbaseIteratee(value,context,Infinity);
}
_$1.iteratee=iteratee;
// The function we call internally to generate a callback. It invokes
// `_.iteratee` if overridden, otherwise `baseIteratee`.
functioncb(value,context,argCount){
if(_$1.iteratee!==iteratee)return_$1.iteratee(value,context);
returnbaseIteratee(value,context,argCount);
}
// Returns the results of applying the `iteratee` to each element of `obj`.
// In contrast to `_.map` it returns an object.
functionmapObject(obj,iteratee,context){
iteratee=cb(iteratee,context);
var_keys=keys(obj),
length=_keys.length,
results={};
for(varindex=0;index<length;index++){
varcurrentKey=_keys[index];
results[currentKey]=iteratee(obj[currentKey],currentKey,obj);
}
returnresults;
}
// Predicate-generating function. Often useful outside of Underscore.
functionnoop(){}
// Generates a function for a given object that returns a given property.
functionpropertyOf(obj){
if(obj==null)returnnoop;
returnfunction(path){
returnget(obj,path);
};
}
// Run a function **n** times.
functiontimes(n,iteratee,context){
varaccum=Array(Math.max(0,n));
iteratee=optimizeCb(iteratee,context,1);
for(vari=0;i<n;i++)accum[i]=iteratee(i);
returnaccum;
}
// Return a random integer between `min` and `max` (inclusive).
functionrandom(min,max){
if(max==null){
max=min;
min=0;
}
returnmin+Math.floor(Math.random()*(max-min+1));
}
// A (possibly faster) way to get the current timestamp as an integer.
varnow=Date.now||function(){
returnnewDate().getTime();
};
// Internal helper to generate functions for escaping and unescaping strings
// to/from HTML interpolation.
functioncreateEscaper(map){
varescaper=function(match){
returnmap[match];
};
// Regexes for identifying a key that needs to be escaped.
varsource='(?:'+keys(map).join('|')+')';
vartestRegexp=RegExp(source);
varreplaceRegexp=RegExp(source,'g');
returnfunction(string){
string=string==null ? '' : ''+string;
returntestRegexp.test(string) ? string.replace(replaceRegexp,escaper) : string;
};
}
// Internal list of HTML entities for escaping.
varescapeMap={
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'`': '`'
};
// Function for escaping strings to HTML interpolation.
var_escape=createEscaper(escapeMap);
// Internal list of HTML entities for unescaping.
varunescapeMap=invert(escapeMap);
// Function for unescaping strings from HTML interpolation.
var_unescape=createEscaper(unescapeMap);
// By default, Underscore uses ERB-style template delimiters. Change the
// following template settings to use alternative delimiters.
vartemplateSettings=_$1.templateSettings={
evaluate: /<%([\s\S]+?)%>/g,
interpolate: /<%=([\s\S]+?)%>/g,
escape: /<%-([\s\S]+?)%>/g
};
// When customizing `_.templateSettings`, if you don't want to define an
// interpolation, evaluation or escaping regex, we need one that is
// guaranteed not to match.
varnoMatch=/(.)^/;
// Certain characters need to be escaped so that they can be put into a
// string literal.
varescapes={
"'": "'",
'\\': '\\',
'\r': 'r',
'\n': 'n',
'\u2028': 'u2028',
'\u2029': 'u2029'
};
varescapeRegExp=/\\|'|\r|\n|\u2028|\u2029/g;
functionescapeChar(match){
return'\\'+escapes[match];
}
// In order to prevent third-party code injection through
// `_.templateSettings.variable`, we test it against the following regular
// expression. It is intentionally a bit more liberal than just matching valid
// identifiers, but still prevents possible loopholes through defaults or
// destructuring assignment.
varbareIdentifier=/^\s*(\w|\$)+\s*$/;
// JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
// NB: `oldSettings` only exists for backwards compatibility.
functiontemplate(text,settings,oldSettings){
if(!settings&&oldSettings)settings=oldSettings;
settings=defaults({},settings,_$1.templateSettings);
// Combine delimiters into one regular expression via alternation.
varmatcher=RegExp([
(settings.escape||noMatch).source,
(settings.interpolate||noMatch).source,
(settings.evaluate||noMatch).source
].join('|')+'|$','g');
// Compile the template source, escaping string literals appropriately.
varindex=0;
varsource="__p+='";
text.replace(matcher,function(match,escape,interpolate,evaluate,offset){
source+=text.slice(index,offset).replace(escapeRegExp,escapeChar);
index=offset+match.length;
if(escape){
source+="'+\n((__t=("+escape+"))==null?'':_.escape(__t))+\n'";
}elseif(interpolate){
source+="'+\n((__t=("+interpolate+"))==null?'':__t)+\n'";
}elseif(evaluate){
source+="';\n"+evaluate+"\n__p+='";
}
// Adobe VMs need the match returned to produce the correct offset.
returnmatch;
});
source+="';\n";
varargument=settings.variable;
if(argument){
// Insure against third-party code injection. (CVE-2021-23358)
if(!bareIdentifier.test(argument))thrownewError(
'variable is not a bare identifier: '+argument
);
}else{
// If a variable is not specified, place data values in local scope.
source='with(obj||{}){\n'+source+'}\n';
argument='obj';
}
source="var __t,__p='',__j=Array.prototype.join,"+
"print=function(){__p+=__j.call(arguments,'');};\n"+
source+'return __p;\n';
varrender;
try{
render=newFunction(argument,'_',source);
}catch(e){
e.source=source;
throwe;
}
vartemplate=function(data){
returnrender.call(this,data,_$1);
};
// Provide the compiled source as a convenience for precompilation.
template.source='function('+argument+'){\n'+source+'}';
returntemplate;
}
// Traverses the children of `obj` along `path`. If a child is a function, it
// is invoked with its parent as context. Returns the value of the final
// child, or `fallback` if any child is undefined.
functionresult(obj,path,fallback){
path=toPath(path);
varlength=path.length;
if(!length){
returnisFunction$1(fallback) ? fallback.call(obj) : fallback;
}
for(vari=0;i<length;i++){
varprop=obj==null ? void0 : obj[path[i]];
if(prop===void0){
prop=fallback;
i=length;// Ensure we don't continue iterating.
}
obj=isFunction$1(prop) ? prop.call(obj) : prop;
}
returnobj;
}
// Generate a unique integer id (unique within the entire client session).
// Useful for temporary DOM ids.
varidCounter=0;
functionuniqueId(prefix){