source: frontend/node_modules/underscore/underscore-esm.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 64.4 KB
Line 
1// Underscore.js 1.13.6
2// https://underscorejs.org
3// (c) 2009-2022 Jeremy Ashkenas, Julian Gonggrijp, and DocumentCloud and Investigative Reporters & Editors
4// Underscore may be freely distributed under the MIT license.
5
6// Current version.
7var VERSION = '1.13.6';
8
9// Establish the root object, `window` (`self`) in the browser, `global`
10// on the server, or `this` in some virtual machines. We use `self`
11// instead of `window` for `WebWorker` support.
12var root = (typeof self == 'object' && self.self === self && self) ||
13 (typeof global == 'object' && global.global === global && global) ||
14 Function('return this')() ||
15 {};
16
17// Save bytes in the minified (but not gzipped) version:
18var ArrayProto = Array.prototype, ObjProto = Object.prototype;
19var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
20
21// Create quick reference variables for speed access to core prototypes.
22var push = ArrayProto.push,
23 slice = ArrayProto.slice,
24 toString = ObjProto.toString,
25 hasOwnProperty = ObjProto.hasOwnProperty;
26
27// Modern feature detection.
28var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined',
29 supportsDataView = typeof DataView !== 'undefined';
30
31// All **ECMAScript 5+** native function implementations that we hope to use
32// are declared here.
33var nativeIsArray = Array.isArray,
34 nativeKeys = Object.keys,
35 nativeCreate = Object.create,
36 nativeIsView = supportsArrayBuffer && ArrayBuffer.isView;
37
38// Create references to these builtin functions because we override them.
39var _isNaN = isNaN,
40 _isFinite = isFinite;
41
42// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
43var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
44var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
45 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
46
47// The largest integer that can be represented exactly.
48var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
49
50// Some functions take a variable number of arguments, or a few expected
51// arguments at the beginning and then a variable number of values to operate
52// on. This helper accumulates all remaining arguments past the function’s
53// argument length (or an explicit `startIndex`), into an array that becomes
54// the last argument. Similar to ES6’s "rest parameter".
55function restArguments(func, startIndex) {
56 startIndex = startIndex == null ? func.length - 1 : +startIndex;
57 return function() {
58 var length = Math.max(arguments.length - startIndex, 0),
59 rest = Array(length),
60 index = 0;
61 for (; index < length; index++) {
62 rest[index] = arguments[index + startIndex];
63 }
64 switch (startIndex) {
65 case 0: return func.call(this, rest);
66 case 1: return func.call(this, arguments[0], rest);
67 case 2: return func.call(this, arguments[0], arguments[1], rest);
68 }
69 var args = Array(startIndex + 1);
70 for (index = 0; index < startIndex; index++) {
71 args[index] = arguments[index];
72 }
73 args[startIndex] = rest;
74 return func.apply(this, args);
75 };
76}
77
78// Is a given variable an object?
79function isObject(obj) {
80 var type = typeof obj;
81 return type === 'function' || (type === 'object' && !!obj);
82}
83
84// Is a given value equal to null?
85function isNull(obj) {
86 return obj === null;
87}
88
89// Is a given variable undefined?
90function isUndefined(obj) {
91 return obj === void 0;
92}
93
94// Is a given value a boolean?
95function isBoolean(obj) {
96 return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
97}
98
99// Is a given value a DOM element?
100function isElement(obj) {
101 return !!(obj && obj.nodeType === 1);
102}
103
104// Internal function for creating a `toString`-based type tester.
105function tagTester(name) {
106 var tag = '[object ' + name + ']';
107 return function(obj) {
108 return toString.call(obj) === tag;
109 };
110}
111
112var isString = tagTester('String');
113
114var isNumber = tagTester('Number');
115
116var isDate = tagTester('Date');
117
118var isRegExp = tagTester('RegExp');
119
120var isError = tagTester('Error');
121
122var isSymbol = tagTester('Symbol');
123
124var isArrayBuffer = tagTester('ArrayBuffer');
125
126var isFunction = tagTester('Function');
127
128// Optimize `isFunction` if appropriate. Work around some `typeof` bugs in old
129// v8, IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
130var nodelist = root.document && root.document.childNodes;
131if (typeof /./ != 'function' && typeof Int8Array != 'object' && typeof nodelist != 'function') {
132 isFunction = function(obj) {
133 return typeof obj == 'function' || false;
134 };
135}
136
137var isFunction$1 = isFunction;
138
139var hasObjectTag = tagTester('Object');
140
141// In IE 10 - Edge 13, `DataView` has string tag `'[object Object]'`.
142// In IE 11, the most common among them, this problem also applies to
143// `Map`, `WeakMap` and `Set`.
144var hasStringTagBug = (
145 supportsDataView && hasObjectTag(new DataView(new ArrayBuffer(8)))
146 ),
147 isIE11 = (typeof Map !== 'undefined' && hasObjectTag(new Map));
148
149var isDataView = tagTester('DataView');
150
151// In IE 10 - Edge 13, we need a different heuristic
152// to determine whether an object is a `DataView`.
153function ie10IsDataView(obj) {
154 return obj != null && isFunction$1(obj.getInt8) && isArrayBuffer(obj.buffer);
155}
156
157var isDataView$1 = (hasStringTagBug ? ie10IsDataView : isDataView);
158
159// Is a given value an array?
160// Delegates to ECMA5's native `Array.isArray`.
161var isArray = nativeIsArray || tagTester('Array');
162
163// Internal function to check whether `key` is an own property name of `obj`.
164function has$1(obj, key) {
165 return obj != null && hasOwnProperty.call(obj, key);
166}
167
168var isArguments = tagTester('Arguments');
169
170// Define a fallback version of the method in browsers (ahem, IE < 9), where
171// there isn't any inspectable "Arguments" type.
172(function() {
173 if (!isArguments(arguments)) {
174 isArguments = function(obj) {
175 return has$1(obj, 'callee');
176 };
177 }
178}());
179
180var isArguments$1 = isArguments;
181
182// Is a given object a finite number?
183function isFinite$1(obj) {
184 return !isSymbol(obj) && _isFinite(obj) && !isNaN(parseFloat(obj));
185}
186
187// Is the given value `NaN`?
188function isNaN$1(obj) {
189 return isNumber(obj) && _isNaN(obj);
190}
191
192// Predicate-generating function. Often useful outside of Underscore.
193function constant(value) {
194 return function() {
195 return value;
196 };
197}
198
199// Common internal logic for `isArrayLike` and `isBufferLike`.
200function createSizePropertyCheck(getSizeProperty) {
201 return function(collection) {
202 var sizeProperty = getSizeProperty(collection);
203 return typeof sizeProperty == 'number' && sizeProperty >= 0 && sizeProperty <= MAX_ARRAY_INDEX;
204 }
205}
206
207// Internal helper to generate a function to obtain property `key` from `obj`.
208function shallowProperty(key) {
209 return function(obj) {
210 return obj == null ? void 0 : obj[key];
211 };
212}
213
214// Internal helper to obtain the `byteLength` property of an object.
215var getByteLength = shallowProperty('byteLength');
216
217// Internal helper to determine whether we should spend extensive checks against
218// `ArrayBuffer` et al.
219var isBufferLike = createSizePropertyCheck(getByteLength);
220
221// Is a given value a typed array?
222var typedArrayPattern = /\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;
223function isTypedArray(obj) {
224 // `ArrayBuffer.isView` is the most future-proof, so use it when available.
225 // Otherwise, fall back on the above regular expression.
226 return nativeIsView ? (nativeIsView(obj) && !isDataView$1(obj)) :
227 isBufferLike(obj) && typedArrayPattern.test(toString.call(obj));
228}
229
230var isTypedArray$1 = supportsArrayBuffer ? isTypedArray : constant(false);
231
232// Internal helper to obtain the `length` property of an object.
233var getLength = shallowProperty('length');
234
235// Internal helper to create a simple lookup structure.
236// `collectNonEnumProps` used to depend on `_.contains`, but this led to
237// circular imports. `emulatedSet` is a one-off solution that only works for
238// arrays of strings.
239function emulatedSet(keys) {
240 var hash = {};
241 for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
242 return {
243 contains: function(key) { return hash[key] === true; },
244 push: function(key) {
245 hash[key] = true;
246 return keys.push(key);
247 }
248 };
249}
250
251// Internal helper. Checks `keys` for the presence of keys in IE < 9 that won't
252// be iterated by `for key in ...` and thus missed. Extends `keys` in place if
253// needed.
254function collectNonEnumProps(obj, keys) {
255 keys = emulatedSet(keys);
256 var nonEnumIdx = nonEnumerableProps.length;
257 var constructor = obj.constructor;
258 var proto = (isFunction$1(constructor) && constructor.prototype) || ObjProto;
259
260 // Constructor is a special case.
261 var prop = 'constructor';
262 if (has$1(obj, prop) && !keys.contains(prop)) keys.push(prop);
263
264 while (nonEnumIdx--) {
265 prop = nonEnumerableProps[nonEnumIdx];
266 if (prop in obj && obj[prop] !== proto[prop] && !keys.contains(prop)) {
267 keys.push(prop);
268 }
269 }
270}
271
272// Retrieve the names of an object's own properties.
273// Delegates to **ECMAScript 5**'s native `Object.keys`.
274function keys(obj) {
275 if (!isObject(obj)) return [];
276 if (nativeKeys) return nativeKeys(obj);
277 var keys = [];
278 for (var key in obj) if (has$1(obj, key)) keys.push(key);
279 // Ahem, IE < 9.
280 if (hasEnumBug) collectNonEnumProps(obj, keys);
281 return keys;
282}
283
284// Is a given array, string, or object empty?
285// An "empty" object has no enumerable own-properties.
286function isEmpty(obj) {
287 if (obj == null) return true;
288 // Skip the more expensive `toString`-based type checks if `obj` has no
289 // `.length`.
290 var length = getLength(obj);
291 if (typeof length == 'number' && (
292 isArray(obj) || isString(obj) || isArguments$1(obj)
293 )) return length === 0;
294 return getLength(keys(obj)) === 0;
295}
296
297// Returns whether an object has a given set of `key:value` pairs.
298function isMatch(object, attrs) {
299 var _keys = keys(attrs), length = _keys.length;
300 if (object == null) return !length;
301 var obj = Object(object);
302 for (var i = 0; i < length; i++) {
303 var key = _keys[i];
304 if (attrs[key] !== obj[key] || !(key in obj)) return false;
305 }
306 return true;
307}
308
309// If Underscore is called as a function, it returns a wrapped object that can
310// be used OO-style. This wrapper holds altered versions of all functions added
311// through `_.mixin`. Wrapped objects may be chained.
312function _$1(obj) {
313 if (obj instanceof _$1) return obj;
314 if (!(this instanceof _$1)) return new _$1(obj);
315 this._wrapped = obj;
316}
317
318_$1.VERSION = VERSION;
319
320// Extracts the result from a wrapped and chained object.
321_$1.prototype.value = function() {
322 return this._wrapped;
323};
324
325// Provide unwrapping proxies for some methods used in engine operations
326// such as arithmetic and JSON stringification.
327_$1.prototype.valueOf = _$1.prototype.toJSON = _$1.prototype.value;
328
329_$1.prototype.toString = function() {
330 return String(this._wrapped);
331};
332
333// Internal function to wrap or shallow-copy an ArrayBuffer,
334// typed array or DataView to a new view, reusing the buffer.
335function toBufferView(bufferSource) {
336 return new Uint8Array(
337 bufferSource.buffer || bufferSource,
338 bufferSource.byteOffset || 0,
339 getByteLength(bufferSource)
340 );
341}
342
343// We use this string twice, so give it a name for minification.
344var tagDataView = '[object DataView]';
345
346// Internal recursive comparison function for `_.isEqual`.
347function eq(a, b, aStack, bStack) {
348 // Identical objects are equal. `0 === -0`, but they aren't identical.
349 // See the [Harmony `egal` proposal](https://wiki.ecmascript.org/doku.php?id=harmony:egal).
350 if (a === b) return a !== 0 || 1 / a === 1 / b;
351 // `null` or `undefined` only equal to itself (strict comparison).
352 if (a == null || b == null) return false;
353 // `NaN`s are equivalent, but non-reflexive.
354 if (a !== a) return b !== b;
355 // Exhaust primitive checks
356 var type = typeof a;
357 if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;
358 return deepEq(a, b, aStack, bStack);
359}
360
361// Internal recursive comparison function for `_.isEqual`.
362function deepEq(a, b, aStack, bStack) {
363 // Unwrap any wrapped objects.
364 if (a instanceof _$1) a = a._wrapped;
365 if (b instanceof _$1) b = b._wrapped;
366 // Compare `[[Class]]` names.
367 var className = toString.call(a);
368 if (className !== toString.call(b)) return false;
369 // Work around a bug in IE 10 - Edge 13.
370 if (hasStringTagBug && className == '[object Object]' && isDataView$1(a)) {
371 if (!isDataView$1(b)) return false;
372 className = tagDataView;
373 }
374 switch (className) {
375 // These types are compared by value.
376 case '[object RegExp]':
377 // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
378 case '[object String]':
379 // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
380 // equivalent to `new String("5")`.
381 return '' + a === '' + b;
382 case '[object Number]':
383 // `NaN`s are equivalent, but non-reflexive.
384 // Object(NaN) is equivalent to NaN.
385 if (+a !== +a) return +b !== +b;
386 // An `egal` comparison is performed for other numeric values.
387 return +a === 0 ? 1 / +a === 1 / b : +a === +b;
388 case '[object Date]':
389 case '[object Boolean]':
390 // Coerce dates and booleans to numeric primitive values. Dates are compared by their
391 // millisecond representations. Note that invalid dates with millisecond representations
392 // of `NaN` are not equivalent.
393 return +a === +b;
394 case '[object Symbol]':
395 return SymbolProto.valueOf.call(a) === SymbolProto.valueOf.call(b);
396 case '[object ArrayBuffer]':
397 case tagDataView:
398 // Coerce to typed array so we can fall through.
399 return deepEq(toBufferView(a), toBufferView(b), aStack, bStack);
400 }
401
402 var areArrays = className === '[object Array]';
403 if (!areArrays && isTypedArray$1(a)) {
404 var byteLength = getByteLength(a);
405 if (byteLength !== getByteLength(b)) return false;
406 if (a.buffer === b.buffer && a.byteOffset === b.byteOffset) return true;
407 areArrays = true;
408 }
409 if (!areArrays) {
410 if (typeof a != 'object' || typeof b != 'object') return false;
411
412 // Objects with different constructors are not equivalent, but `Object`s or `Array`s
413 // from different frames are.
414 var aCtor = a.constructor, bCtor = b.constructor;
415 if (aCtor !== bCtor && !(isFunction$1(aCtor) && aCtor instanceof aCtor &&
416 isFunction$1(bCtor) && bCtor instanceof bCtor)
417 && ('constructor' in a && 'constructor' in b)) {
418 return false;
419 }
420 }
421 // Assume equality for cyclic structures. The algorithm for detecting cyclic
422 // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
423
424 // Initializing stack of traversed objects.
425 // It's done here since we only need them for objects and arrays comparison.
426 aStack = aStack || [];
427 bStack = bStack || [];
428 var length = aStack.length;
429 while (length--) {
430 // Linear search. Performance is inversely proportional to the number of
431 // unique nested structures.
432 if (aStack[length] === a) return bStack[length] === b;
433 }
434
435 // Add the first object to the stack of traversed objects.
436 aStack.push(a);
437 bStack.push(b);
438
439 // Recursively compare objects and arrays.
440 if (areArrays) {
441 // Compare array lengths to determine if a deep comparison is necessary.
442 length = a.length;
443 if (length !== b.length) return false;
444 // Deep compare the contents, ignoring non-numeric properties.
445 while (length--) {
446 if (!eq(a[length], b[length], aStack, bStack)) return false;
447 }
448 } else {
449 // Deep compare objects.
450 var _keys = keys(a), key;
451 length = _keys.length;
452 // Ensure that both objects contain the same number of properties before comparing deep equality.
453 if (keys(b).length !== length) return false;
454 while (length--) {
455 // Deep compare each member
456 key = _keys[length];
457 if (!(has$1(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
458 }
459 }
460 // Remove the first object from the stack of traversed objects.
461 aStack.pop();
462 bStack.pop();
463 return true;
464}
465
466// Perform a deep comparison to check if two objects are equal.
467function isEqual(a, b) {
468 return eq(a, b);
469}
470
471// Retrieve all the enumerable property names of an object.
472function allKeys(obj) {
473 if (!isObject(obj)) return [];
474 var keys = [];
475 for (var key in obj) keys.push(key);
476 // Ahem, IE < 9.
477 if (hasEnumBug) collectNonEnumProps(obj, keys);
478 return keys;
479}
480
481// Since the regular `Object.prototype.toString` type tests don't work for
482// some types in IE 11, we use a fingerprinting heuristic instead, based
483// on the methods. It's not great, but it's the best we got.
484// The fingerprint method lists are defined below.
485function ie11fingerprint(methods) {
486 var length = getLength(methods);
487 return function(obj) {
488 if (obj == null) return false;
489 // `Map`, `WeakMap` and `Set` have no enumerable keys.
490 var keys = allKeys(obj);
491 if (getLength(keys)) return false;
492 for (var i = 0; i < length; i++) {
493 if (!isFunction$1(obj[methods[i]])) return false;
494 }
495 // If we are testing against `WeakMap`, we need to ensure that
496 // `obj` doesn't have a `forEach` method in order to distinguish
497 // it from a regular `Map`.
498 return methods !== weakMapMethods || !isFunction$1(obj[forEachName]);
499 };
500}
501
502// In the interest of compact minification, we write
503// each string in the fingerprints only once.
504var forEachName = 'forEach',
505 hasName = 'has',
506 commonInit = ['clear', 'delete'],
507 mapTail = ['get', hasName, 'set'];
508
509// `Map`, `WeakMap` and `Set` each have slightly different
510// combinations of the above sublists.
511var mapMethods = commonInit.concat(forEachName, mapTail),
512 weakMapMethods = commonInit.concat(mapTail),
513 setMethods = ['add'].concat(commonInit, forEachName, hasName);
514
515var isMap = isIE11 ? ie11fingerprint(mapMethods) : tagTester('Map');
516
517var isWeakMap = isIE11 ? ie11fingerprint(weakMapMethods) : tagTester('WeakMap');
518
519var isSet = isIE11 ? ie11fingerprint(setMethods) : tagTester('Set');
520
521var isWeakSet = tagTester('WeakSet');
522
523// Retrieve the values of an object's properties.
524function values(obj) {
525 var _keys = keys(obj);
526 var length = _keys.length;
527 var values = Array(length);
528 for (var i = 0; i < length; i++) {
529 values[i] = obj[_keys[i]];
530 }
531 return values;
532}
533
534// Convert an object into a list of `[key, value]` pairs.
535// The opposite of `_.object` with one argument.
536function pairs(obj) {
537 var _keys = keys(obj);
538 var length = _keys.length;
539 var pairs = Array(length);
540 for (var i = 0; i < length; i++) {
541 pairs[i] = [_keys[i], obj[_keys[i]]];
542 }
543 return pairs;
544}
545
546// Invert the keys and values of an object. The values must be serializable.
547function invert(obj) {
548 var result = {};
549 var _keys = keys(obj);
550 for (var i = 0, length = _keys.length; i < length; i++) {
551 result[obj[_keys[i]]] = _keys[i];
552 }
553 return result;
554}
555
556// Return a sorted list of the function names available on the object.
557function functions(obj) {
558 var names = [];
559 for (var key in obj) {
560 if (isFunction$1(obj[key])) names.push(key);
561 }
562 return names.sort();
563}
564
565// An internal function for creating assigner functions.
566function createAssigner(keysFunc, defaults) {
567 return function(obj) {
568 var length = arguments.length;
569 if (defaults) obj = Object(obj);
570 if (length < 2 || obj == null) return obj;
571 for (var index = 1; index < length; index++) {
572 var source = arguments[index],
573 keys = keysFunc(source),
574 l = keys.length;
575 for (var i = 0; i < l; i++) {
576 var key = keys[i];
577 if (!defaults || obj[key] === void 0) obj[key] = source[key];
578 }
579 }
580 return obj;
581 };
582}
583
584// Extend a given object with all the properties in passed-in object(s).
585var extend = createAssigner(allKeys);
586
587// Assigns a given object with all the own properties in the passed-in
588// object(s).
589// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
590var extendOwn = createAssigner(keys);
591
592// Fill in a given object with default properties.
593var defaults = createAssigner(allKeys, true);
594
595// Create a naked function reference for surrogate-prototype-swapping.
596function ctor() {
597 return function(){};
598}
599
600// An internal function for creating a new object that inherits from another.
601function baseCreate(prototype) {
602 if (!isObject(prototype)) return {};
603 if (nativeCreate) return nativeCreate(prototype);
604 var Ctor = ctor();
605 Ctor.prototype = prototype;
606 var result = new Ctor;
607 Ctor.prototype = null;
608 return result;
609}
610
611// Creates an object that inherits from the given prototype object.
612// If additional properties are provided then they will be added to the
613// created object.
614function create(prototype, props) {
615 var result = baseCreate(prototype);
616 if (props) extendOwn(result, props);
617 return result;
618}
619
620// Create a (shallow-cloned) duplicate of an object.
621function clone(obj) {
622 if (!isObject(obj)) return obj;
623 return isArray(obj) ? obj.slice() : extend({}, obj);
624}
625
626// Invokes `interceptor` with the `obj` and then returns `obj`.
627// The primary purpose of this method is to "tap into" a method chain, in
628// order to perform operations on intermediate results within the chain.
629function tap(obj, interceptor) {
630 interceptor(obj);
631 return obj;
632}
633
634// Normalize a (deep) property `path` to array.
635// Like `_.iteratee`, this function can be customized.
636function toPath$1(path) {
637 return isArray(path) ? path : [path];
638}
639_$1.toPath = toPath$1;
640
641// Internal wrapper for `_.toPath` to enable minification.
642// Similar to `cb` for `_.iteratee`.
643function toPath(path) {
644 return _$1.toPath(path);
645}
646
647// Internal function to obtain a nested property in `obj` along `path`.
648function deepGet(obj, path) {
649 var length = path.length;
650 for (var i = 0; i < length; i++) {
651 if (obj == null) return void 0;
652 obj = obj[path[i]];
653 }
654 return length ? obj : void 0;
655}
656
657// Get the value of the (deep) property on `path` from `object`.
658// If any property in `path` does not exist or if the value is
659// `undefined`, return `defaultValue` instead.
660// The `path` is normalized through `_.toPath`.
661function get(object, path, defaultValue) {
662 var value = deepGet(object, toPath(path));
663 return isUndefined(value) ? defaultValue : value;
664}
665
666// Shortcut function for checking if an object has a given property directly on
667// itself (in other words, not on a prototype). Unlike the internal `has`
668// function, this public version can also traverse nested properties.
669function has(obj, path) {
670 path = toPath(path);
671 var length = path.length;
672 for (var i = 0; i < length; i++) {
673 var key = path[i];
674 if (!has$1(obj, key)) return false;
675 obj = obj[key];
676 }
677 return !!length;
678}
679
680// Keep the identity function around for default iteratees.
681function identity(value) {
682 return value;
683}
684
685// Returns a predicate for checking whether an object has a given set of
686// `key:value` pairs.
687function matcher(attrs) {
688 attrs = extendOwn({}, attrs);
689 return function(obj) {
690 return isMatch(obj, attrs);
691 };
692}
693
694// Creates a function that, when passed an object, will traverse that object’s
695// properties down the given `path`, specified as an array of keys or indices.
696function property(path) {
697 path = toPath(path);
698 return function(obj) {
699 return deepGet(obj, path);
700 };
701}
702
703// Internal function that returns an efficient (for current engines) version
704// of the passed-in callback, to be repeatedly applied in other Underscore
705// functions.
706function optimizeCb(func, context, argCount) {
707 if (context === void 0) return func;
708 switch (argCount == null ? 3 : argCount) {
709 case 1: return function(value) {
710 return func.call(context, value);
711 };
712 // The 2-argument case is omitted because we’re not using it.
713 case 3: return function(value, index, collection) {
714 return func.call(context, value, index, collection);
715 };
716 case 4: return function(accumulator, value, index, collection) {
717 return func.call(context, accumulator, value, index, collection);
718 };
719 }
720 return function() {
721 return func.apply(context, arguments);
722 };
723}
724
725// An internal function to generate callbacks that can be applied to each
726// element in a collection, returning the desired result — either `_.identity`,
727// an arbitrary callback, a property matcher, or a property accessor.
728function baseIteratee(value, context, argCount) {
729 if (value == null) return identity;
730 if (isFunction$1(value)) return optimizeCb(value, context, argCount);
731 if (isObject(value) && !isArray(value)) return matcher(value);
732 return property(value);
733}
734
735// External wrapper for our callback generator. Users may customize
736// `_.iteratee` if they want additional predicate/iteratee shorthand styles.
737// This abstraction hides the internal-only `argCount` argument.
738function iteratee(value, context) {
739 return baseIteratee(value, context, Infinity);
740}
741_$1.iteratee = iteratee;
742
743// The function we call internally to generate a callback. It invokes
744// `_.iteratee` if overridden, otherwise `baseIteratee`.
745function cb(value, context, argCount) {
746 if (_$1.iteratee !== iteratee) return _$1.iteratee(value, context);
747 return baseIteratee(value, context, argCount);
748}
749
750// Returns the results of applying the `iteratee` to each element of `obj`.
751// In contrast to `_.map` it returns an object.
752function mapObject(obj, iteratee, context) {
753 iteratee = cb(iteratee, context);
754 var _keys = keys(obj),
755 length = _keys.length,
756 results = {};
757 for (var index = 0; index < length; index++) {
758 var currentKey = _keys[index];
759 results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
760 }
761 return results;
762}
763
764// Predicate-generating function. Often useful outside of Underscore.
765function noop(){}
766
767// Generates a function for a given object that returns a given property.
768function propertyOf(obj) {
769 if (obj == null) return noop;
770 return function(path) {
771 return get(obj, path);
772 };
773}
774
775// Run a function **n** times.
776function times(n, iteratee, context) {
777 var accum = Array(Math.max(0, n));
778 iteratee = optimizeCb(iteratee, context, 1);
779 for (var i = 0; i < n; i++) accum[i] = iteratee(i);
780 return accum;
781}
782
783// Return a random integer between `min` and `max` (inclusive).
784function random(min, max) {
785 if (max == null) {
786 max = min;
787 min = 0;
788 }
789 return min + Math.floor(Math.random() * (max - min + 1));
790}
791
792// A (possibly faster) way to get the current timestamp as an integer.
793var now = Date.now || function() {
794 return new Date().getTime();
795};
796
797// Internal helper to generate functions for escaping and unescaping strings
798// to/from HTML interpolation.
799function createEscaper(map) {
800 var escaper = function(match) {
801 return map[match];
802 };
803 // Regexes for identifying a key that needs to be escaped.
804 var source = '(?:' + keys(map).join('|') + ')';
805 var testRegexp = RegExp(source);
806 var replaceRegexp = RegExp(source, 'g');
807 return function(string) {
808 string = string == null ? '' : '' + string;
809 return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
810 };
811}
812
813// Internal list of HTML entities for escaping.
814var escapeMap = {
815 '&': '&amp;',
816 '<': '&lt;',
817 '>': '&gt;',
818 '"': '&quot;',
819 "'": '&#x27;',
820 '`': '&#x60;'
821};
822
823// Function for escaping strings to HTML interpolation.
824var _escape = createEscaper(escapeMap);
825
826// Internal list of HTML entities for unescaping.
827var unescapeMap = invert(escapeMap);
828
829// Function for unescaping strings from HTML interpolation.
830var _unescape = createEscaper(unescapeMap);
831
832// By default, Underscore uses ERB-style template delimiters. Change the
833// following template settings to use alternative delimiters.
834var templateSettings = _$1.templateSettings = {
835 evaluate: /<%([\s\S]+?)%>/g,
836 interpolate: /<%=([\s\S]+?)%>/g,
837 escape: /<%-([\s\S]+?)%>/g
838};
839
840// When customizing `_.templateSettings`, if you don't want to define an
841// interpolation, evaluation or escaping regex, we need one that is
842// guaranteed not to match.
843var noMatch = /(.)^/;
844
845// Certain characters need to be escaped so that they can be put into a
846// string literal.
847var escapes = {
848 "'": "'",
849 '\\': '\\',
850 '\r': 'r',
851 '\n': 'n',
852 '\u2028': 'u2028',
853 '\u2029': 'u2029'
854};
855
856var escapeRegExp = /\\|'|\r|\n|\u2028|\u2029/g;
857
858function escapeChar(match) {
859 return '\\' + escapes[match];
860}
861
862// In order to prevent third-party code injection through
863// `_.templateSettings.variable`, we test it against the following regular
864// expression. It is intentionally a bit more liberal than just matching valid
865// identifiers, but still prevents possible loopholes through defaults or
866// destructuring assignment.
867var bareIdentifier = /^\s*(\w|\$)+\s*$/;
868
869// JavaScript micro-templating, similar to John Resig's implementation.
870// Underscore templating handles arbitrary delimiters, preserves whitespace,
871// and correctly escapes quotes within interpolated code.
872// NB: `oldSettings` only exists for backwards compatibility.
873function template(text, settings, oldSettings) {
874 if (!settings && oldSettings) settings = oldSettings;
875 settings = defaults({}, settings, _$1.templateSettings);
876
877 // Combine delimiters into one regular expression via alternation.
878 var matcher = RegExp([
879 (settings.escape || noMatch).source,
880 (settings.interpolate || noMatch).source,
881 (settings.evaluate || noMatch).source
882 ].join('|') + '|$', 'g');
883
884 // Compile the template source, escaping string literals appropriately.
885 var index = 0;
886 var source = "__p+='";
887 text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
888 source += text.slice(index, offset).replace(escapeRegExp, escapeChar);
889 index = offset + match.length;
890
891 if (escape) {
892 source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
893 } else if (interpolate) {
894 source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
895 } else if (evaluate) {
896 source += "';\n" + evaluate + "\n__p+='";
897 }
898
899 // Adobe VMs need the match returned to produce the correct offset.
900 return match;
901 });
902 source += "';\n";
903
904 var argument = settings.variable;
905 if (argument) {
906 // Insure against third-party code injection. (CVE-2021-23358)
907 if (!bareIdentifier.test(argument)) throw new Error(
908 'variable is not a bare identifier: ' + argument
909 );
910 } else {
911 // If a variable is not specified, place data values in local scope.
912 source = 'with(obj||{}){\n' + source + '}\n';
913 argument = 'obj';
914 }
915
916 source = "var __t,__p='',__j=Array.prototype.join," +
917 "print=function(){__p+=__j.call(arguments,'');};\n" +
918 source + 'return __p;\n';
919
920 var render;
921 try {
922 render = new Function(argument, '_', source);
923 } catch (e) {
924 e.source = source;
925 throw e;
926 }
927
928 var template = function(data) {
929 return render.call(this, data, _$1);
930 };
931
932 // Provide the compiled source as a convenience for precompilation.
933 template.source = 'function(' + argument + '){\n' + source + '}';
934
935 return template;
936}
937
938// Traverses the children of `obj` along `path`. If a child is a function, it
939// is invoked with its parent as context. Returns the value of the final
940// child, or `fallback` if any child is undefined.
941function result(obj, path, fallback) {
942 path = toPath(path);
943 var length = path.length;
944 if (!length) {
945 return isFunction$1(fallback) ? fallback.call(obj) : fallback;
946 }
947 for (var i = 0; i < length; i++) {
948 var prop = obj == null ? void 0 : obj[path[i]];
949 if (prop === void 0) {
950 prop = fallback;
951 i = length; // Ensure we don't continue iterating.
952 }
953 obj = isFunction$1(prop) ? prop.call(obj) : prop;
954 }
955 return obj;
956}
957
958// Generate a unique integer id (unique within the entire client session).
959// Useful for temporary DOM ids.
960var idCounter = 0;
961function uniqueId(prefix) {
962 var id = ++idCounter + '';
963 return prefix ? prefix + id : id;
964}
965
966// Start chaining a wrapped Underscore object.
967function chain(obj) {
968 var instance = _$1(obj);
969 instance._chain = true;
970 return instance;
971}
972
973// Internal function to execute `sourceFunc` bound to `context` with optional
974// `args`. Determines whether to execute a function as a constructor or as a
975// normal function.
976function executeBound(sourceFunc, boundFunc, context, callingContext, args) {
977 if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
978 var self = baseCreate(sourceFunc.prototype);
979 var result = sourceFunc.apply(self, args);
980 if (isObject(result)) return result;
981 return self;
982}
983
984// Partially apply a function by creating a version that has had some of its
985// arguments pre-filled, without changing its dynamic `this` context. `_` acts
986// as a placeholder by default, allowing any combination of arguments to be
987// pre-filled. Set `_.partial.placeholder` for a custom placeholder argument.
988var partial = restArguments(function(func, boundArgs) {
989 var placeholder = partial.placeholder;
990 var bound = function() {
991 var position = 0, length = boundArgs.length;
992 var args = Array(length);
993 for (var i = 0; i < length; i++) {
994 args[i] = boundArgs[i] === placeholder ? arguments[position++] : boundArgs[i];
995 }
996 while (position < arguments.length) args.push(arguments[position++]);
997 return executeBound(func, bound, this, this, args);
998 };
999 return bound;
1000});
1001
1002partial.placeholder = _$1;
1003
1004// Create a function bound to a given object (assigning `this`, and arguments,
1005// optionally).
1006var bind = restArguments(function(func, context, args) {
1007 if (!isFunction$1(func)) throw new TypeError('Bind must be called on a function');
1008 var bound = restArguments(function(callArgs) {
1009 return executeBound(func, bound, context, this, args.concat(callArgs));
1010 });
1011 return bound;
1012});
1013
1014// Internal helper for collection methods to determine whether a collection
1015// should be iterated as an array or as an object.
1016// Related: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
1017// Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
1018var isArrayLike = createSizePropertyCheck(getLength);
1019
1020// Internal implementation of a recursive `flatten` function.
1021function flatten$1(input, depth, strict, output) {
1022 output = output || [];
1023 if (!depth && depth !== 0) {
1024 depth = Infinity;
1025 } else if (depth <= 0) {
1026 return output.concat(input);
1027 }
1028 var idx = output.length;
1029 for (var i = 0, length = getLength(input); i < length; i++) {
1030 var value = input[i];
1031 if (isArrayLike(value) && (isArray(value) || isArguments$1(value))) {
1032 // Flatten current level of array or arguments object.
1033 if (depth > 1) {
1034 flatten$1(value, depth - 1, strict, output);
1035 idx = output.length;
1036 } else {
1037 var j = 0, len = value.length;
1038 while (j < len) output[idx++] = value[j++];
1039 }
1040 } else if (!strict) {
1041 output[idx++] = value;
1042 }
1043 }
1044 return output;
1045}
1046
1047// Bind a number of an object's methods to that object. Remaining arguments
1048// are the method names to be bound. Useful for ensuring that all callbacks
1049// defined on an object belong to it.
1050var bindAll = restArguments(function(obj, keys) {
1051 keys = flatten$1(keys, false, false);
1052 var index = keys.length;
1053 if (index < 1) throw new Error('bindAll must be passed function names');
1054 while (index--) {
1055 var key = keys[index];
1056 obj[key] = bind(obj[key], obj);
1057 }
1058 return obj;
1059});
1060
1061// Memoize an expensive function by storing its results.
1062function memoize(func, hasher) {
1063 var memoize = function(key) {
1064 var cache = memoize.cache;
1065 var address = '' + (hasher ? hasher.apply(this, arguments) : key);
1066 if (!has$1(cache, address)) cache[address] = func.apply(this, arguments);
1067 return cache[address];
1068 };
1069 memoize.cache = {};
1070 return memoize;
1071}
1072
1073// Delays a function for the given number of milliseconds, and then calls
1074// it with the arguments supplied.
1075var delay = restArguments(function(func, wait, args) {
1076 return setTimeout(function() {
1077 return func.apply(null, args);
1078 }, wait);
1079});
1080
1081// Defers a function, scheduling it to run after the current call stack has
1082// cleared.
1083var defer = partial(delay, _$1, 1);
1084
1085// Returns a function, that, when invoked, will only be triggered at most once
1086// during a given window of time. Normally, the throttled function will run
1087// as much as it can, without ever going more than once per `wait` duration;
1088// but if you'd like to disable the execution on the leading edge, pass
1089// `{leading: false}`. To disable execution on the trailing edge, ditto.
1090function throttle(func, wait, options) {
1091 var timeout, context, args, result;
1092 var previous = 0;
1093 if (!options) options = {};
1094
1095 var later = function() {
1096 previous = options.leading === false ? 0 : now();
1097 timeout = null;
1098 result = func.apply(context, args);
1099 if (!timeout) context = args = null;
1100 };
1101
1102 var throttled = function() {
1103 var _now = now();
1104 if (!previous && options.leading === false) previous = _now;
1105 var remaining = wait - (_now - previous);
1106 context = this;
1107 args = arguments;
1108 if (remaining <= 0 || remaining > wait) {
1109 if (timeout) {
1110 clearTimeout(timeout);
1111 timeout = null;
1112 }
1113 previous = _now;
1114 result = func.apply(context, args);
1115 if (!timeout) context = args = null;
1116 } else if (!timeout && options.trailing !== false) {
1117 timeout = setTimeout(later, remaining);
1118 }
1119 return result;
1120 };
1121
1122 throttled.cancel = function() {
1123 clearTimeout(timeout);
1124 previous = 0;
1125 timeout = context = args = null;
1126 };
1127
1128 return throttled;
1129}
1130
1131// When a sequence of calls of the returned function ends, the argument
1132// function is triggered. The end of a sequence is defined by the `wait`
1133// parameter. If `immediate` is passed, the argument function will be
1134// triggered at the beginning of the sequence instead of at the end.
1135function debounce(func, wait, immediate) {
1136 var timeout, previous, args, result, context;
1137
1138 var later = function() {
1139 var passed = now() - previous;
1140 if (wait > passed) {
1141 timeout = setTimeout(later, wait - passed);
1142 } else {
1143 timeout = null;
1144 if (!immediate) result = func.apply(context, args);
1145 // This check is needed because `func` can recursively invoke `debounced`.
1146 if (!timeout) args = context = null;
1147 }
1148 };
1149
1150 var debounced = restArguments(function(_args) {
1151 context = this;
1152 args = _args;
1153 previous = now();
1154 if (!timeout) {
1155 timeout = setTimeout(later, wait);
1156 if (immediate) result = func.apply(context, args);
1157 }
1158 return result;
1159 });
1160
1161 debounced.cancel = function() {
1162 clearTimeout(timeout);
1163 timeout = args = context = null;
1164 };
1165
1166 return debounced;
1167}
1168
1169// Returns the first function passed as an argument to the second,
1170// allowing you to adjust arguments, run code before and after, and
1171// conditionally execute the original function.
1172function wrap(func, wrapper) {
1173 return partial(wrapper, func);
1174}
1175
1176// Returns a negated version of the passed-in predicate.
1177function negate(predicate) {
1178 return function() {
1179 return !predicate.apply(this, arguments);
1180 };
1181}
1182
1183// Returns a function that is the composition of a list of functions, each
1184// consuming the return value of the function that follows.
1185function compose() {
1186 var args = arguments;
1187 var start = args.length - 1;
1188 return function() {
1189 var i = start;
1190 var result = args[start].apply(this, arguments);
1191 while (i--) result = args[i].call(this, result);
1192 return result;
1193 };
1194}
1195
1196// Returns a function that will only be executed on and after the Nth call.
1197function after(times, func) {
1198 return function() {
1199 if (--times < 1) {
1200 return func.apply(this, arguments);
1201 }
1202 };
1203}
1204
1205// Returns a function that will only be executed up to (but not including) the
1206// Nth call.
1207function before(times, func) {
1208 var memo;
1209 return function() {
1210 if (--times > 0) {
1211 memo = func.apply(this, arguments);
1212 }
1213 if (times <= 1) func = null;
1214 return memo;
1215 };
1216}
1217
1218// Returns a function that will be executed at most one time, no matter how
1219// often you call it. Useful for lazy initialization.
1220var once = partial(before, 2);
1221
1222// Returns the first key on an object that passes a truth test.
1223function findKey(obj, predicate, context) {
1224 predicate = cb(predicate, context);
1225 var _keys = keys(obj), key;
1226 for (var i = 0, length = _keys.length; i < length; i++) {
1227 key = _keys[i];
1228 if (predicate(obj[key], key, obj)) return key;
1229 }
1230}
1231
1232// Internal function to generate `_.findIndex` and `_.findLastIndex`.
1233function createPredicateIndexFinder(dir) {
1234 return function(array, predicate, context) {
1235 predicate = cb(predicate, context);
1236 var length = getLength(array);
1237 var index = dir > 0 ? 0 : length - 1;
1238 for (; index >= 0 && index < length; index += dir) {
1239 if (predicate(array[index], index, array)) return index;
1240 }
1241 return -1;
1242 };
1243}
1244
1245// Returns the first index on an array-like that passes a truth test.
1246var findIndex = createPredicateIndexFinder(1);
1247
1248// Returns the last index on an array-like that passes a truth test.
1249var findLastIndex = createPredicateIndexFinder(-1);
1250
1251// Use a comparator function to figure out the smallest index at which
1252// an object should be inserted so as to maintain order. Uses binary search.
1253function sortedIndex(array, obj, iteratee, context) {
1254 iteratee = cb(iteratee, context, 1);
1255 var value = iteratee(obj);
1256 var low = 0, high = getLength(array);
1257 while (low < high) {
1258 var mid = Math.floor((low + high) / 2);
1259 if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
1260 }
1261 return low;
1262}
1263
1264// Internal function to generate the `_.indexOf` and `_.lastIndexOf` functions.
1265function createIndexFinder(dir, predicateFind, sortedIndex) {
1266 return function(array, item, idx) {
1267 var i = 0, length = getLength(array);
1268 if (typeof idx == 'number') {
1269 if (dir > 0) {
1270 i = idx >= 0 ? idx : Math.max(idx + length, i);
1271 } else {
1272 length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
1273 }
1274 } else if (sortedIndex && idx && length) {
1275 idx = sortedIndex(array, item);
1276 return array[idx] === item ? idx : -1;
1277 }
1278 if (item !== item) {
1279 idx = predicateFind(slice.call(array, i, length), isNaN$1);
1280 return idx >= 0 ? idx + i : -1;
1281 }
1282 for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
1283 if (array[idx] === item) return idx;
1284 }
1285 return -1;
1286 };
1287}
1288
1289// Return the position of the first occurrence of an item in an array,
1290// or -1 if the item is not included in the array.
1291// If the array is large and already in sort order, pass `true`
1292// for **isSorted** to use binary search.
1293var indexOf = createIndexFinder(1, findIndex, sortedIndex);
1294
1295// Return the position of the last occurrence of an item in an array,
1296// or -1 if the item is not included in the array.
1297var lastIndexOf = createIndexFinder(-1, findLastIndex);
1298
1299// Return the first value which passes a truth test.
1300function find(obj, predicate, context) {
1301 var keyFinder = isArrayLike(obj) ? findIndex : findKey;
1302 var key = keyFinder(obj, predicate, context);
1303 if (key !== void 0 && key !== -1) return obj[key];
1304}
1305
1306// Convenience version of a common use case of `_.find`: getting the first
1307// object containing specific `key:value` pairs.
1308function findWhere(obj, attrs) {
1309 return find(obj, matcher(attrs));
1310}
1311
1312// The cornerstone for collection functions, an `each`
1313// implementation, aka `forEach`.
1314// Handles raw objects in addition to array-likes. Treats all
1315// sparse array-likes as if they were dense.
1316function each(obj, iteratee, context) {
1317 iteratee = optimizeCb(iteratee, context);
1318 var i, length;
1319 if (isArrayLike(obj)) {
1320 for (i = 0, length = obj.length; i < length; i++) {
1321 iteratee(obj[i], i, obj);
1322 }
1323 } else {
1324 var _keys = keys(obj);
1325 for (i = 0, length = _keys.length; i < length; i++) {
1326 iteratee(obj[_keys[i]], _keys[i], obj);
1327 }
1328 }
1329 return obj;
1330}
1331
1332// Return the results of applying the iteratee to each element.
1333function map(obj, iteratee, context) {
1334 iteratee = cb(iteratee, context);
1335 var _keys = !isArrayLike(obj) && keys(obj),
1336 length = (_keys || obj).length,
1337 results = Array(length);
1338 for (var index = 0; index < length; index++) {
1339 var currentKey = _keys ? _keys[index] : index;
1340 results[index] = iteratee(obj[currentKey], currentKey, obj);
1341 }
1342 return results;
1343}
1344
1345// Internal helper to create a reducing function, iterating left or right.
1346function createReduce(dir) {
1347 // Wrap code that reassigns argument variables in a separate function than
1348 // the one that accesses `arguments.length` to avoid a perf hit. (#1991)
1349 var reducer = function(obj, iteratee, memo, initial) {
1350 var _keys = !isArrayLike(obj) && keys(obj),
1351 length = (_keys || obj).length,
1352 index = dir > 0 ? 0 : length - 1;
1353 if (!initial) {
1354 memo = obj[_keys ? _keys[index] : index];
1355 index += dir;
1356 }
1357 for (; index >= 0 && index < length; index += dir) {
1358 var currentKey = _keys ? _keys[index] : index;
1359 memo = iteratee(memo, obj[currentKey], currentKey, obj);
1360 }
1361 return memo;
1362 };
1363
1364 return function(obj, iteratee, memo, context) {
1365 var initial = arguments.length >= 3;
1366 return reducer(obj, optimizeCb(iteratee, context, 4), memo, initial);
1367 };
1368}
1369
1370// **Reduce** builds up a single result from a list of values, aka `inject`,
1371// or `foldl`.
1372var reduce = createReduce(1);
1373
1374// The right-associative version of reduce, also known as `foldr`.
1375var reduceRight = createReduce(-1);
1376
1377// Return all the elements that pass a truth test.
1378function filter(obj, predicate, context) {
1379 var results = [];
1380 predicate = cb(predicate, context);
1381 each(obj, function(value, index, list) {
1382 if (predicate(value, index, list)) results.push(value);
1383 });
1384 return results;
1385}
1386
1387// Return all the elements for which a truth test fails.
1388function reject(obj, predicate, context) {
1389 return filter(obj, negate(cb(predicate)), context);
1390}
1391
1392// Determine whether all of the elements pass a truth test.
1393function every(obj, predicate, context) {
1394 predicate = cb(predicate, context);
1395 var _keys = !isArrayLike(obj) && keys(obj),
1396 length = (_keys || obj).length;
1397 for (var index = 0; index < length; index++) {
1398 var currentKey = _keys ? _keys[index] : index;
1399 if (!predicate(obj[currentKey], currentKey, obj)) return false;
1400 }
1401 return true;
1402}
1403
1404// Determine if at least one element in the object passes a truth test.
1405function some(obj, predicate, context) {
1406 predicate = cb(predicate, context);
1407 var _keys = !isArrayLike(obj) && keys(obj),
1408 length = (_keys || obj).length;
1409 for (var index = 0; index < length; index++) {
1410 var currentKey = _keys ? _keys[index] : index;
1411 if (predicate(obj[currentKey], currentKey, obj)) return true;
1412 }
1413 return false;
1414}
1415
1416// Determine if the array or object contains a given item (using `===`).
1417function contains(obj, item, fromIndex, guard) {
1418 if (!isArrayLike(obj)) obj = values(obj);
1419 if (typeof fromIndex != 'number' || guard) fromIndex = 0;
1420 return indexOf(obj, item, fromIndex) >= 0;
1421}
1422
1423// Invoke a method (with arguments) on every item in a collection.
1424var invoke = restArguments(function(obj, path, args) {
1425 var contextPath, func;
1426 if (isFunction$1(path)) {
1427 func = path;
1428 } else {
1429 path = toPath(path);
1430 contextPath = path.slice(0, -1);
1431 path = path[path.length - 1];
1432 }
1433 return map(obj, function(context) {
1434 var method = func;
1435 if (!method) {
1436 if (contextPath && contextPath.length) {
1437 context = deepGet(context, contextPath);
1438 }
1439 if (context == null) return void 0;
1440 method = context[path];
1441 }
1442 return method == null ? method : method.apply(context, args);
1443 });
1444});
1445
1446// Convenience version of a common use case of `_.map`: fetching a property.
1447function pluck(obj, key) {
1448 return map(obj, property(key));
1449}
1450
1451// Convenience version of a common use case of `_.filter`: selecting only
1452// objects containing specific `key:value` pairs.
1453function where(obj, attrs) {
1454 return filter(obj, matcher(attrs));
1455}
1456
1457// Return the maximum element (or element-based computation).
1458function max(obj, iteratee, context) {
1459 var result = -Infinity, lastComputed = -Infinity,
1460 value, computed;
1461 if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
1462 obj = isArrayLike(obj) ? obj : values(obj);
1463 for (var i = 0, length = obj.length; i < length; i++) {
1464 value = obj[i];
1465 if (value != null && value > result) {
1466 result = value;
1467 }
1468 }
1469 } else {
1470 iteratee = cb(iteratee, context);
1471 each(obj, function(v, index, list) {
1472 computed = iteratee(v, index, list);
1473 if (computed > lastComputed || (computed === -Infinity && result === -Infinity)) {
1474 result = v;
1475 lastComputed = computed;
1476 }
1477 });
1478 }
1479 return result;
1480}
1481
1482// Return the minimum element (or element-based computation).
1483function min(obj, iteratee, context) {
1484 var result = Infinity, lastComputed = Infinity,
1485 value, computed;
1486 if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
1487 obj = isArrayLike(obj) ? obj : values(obj);
1488 for (var i = 0, length = obj.length; i < length; i++) {
1489 value = obj[i];
1490 if (value != null && value < result) {
1491 result = value;
1492 }
1493 }
1494 } else {
1495 iteratee = cb(iteratee, context);
1496 each(obj, function(v, index, list) {
1497 computed = iteratee(v, index, list);
1498 if (computed < lastComputed || (computed === Infinity && result === Infinity)) {
1499 result = v;
1500 lastComputed = computed;
1501 }
1502 });
1503 }
1504 return result;
1505}
1506
1507// Safely create a real, live array from anything iterable.
1508var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
1509function toArray(obj) {
1510 if (!obj) return [];
1511 if (isArray(obj)) return slice.call(obj);
1512 if (isString(obj)) {
1513 // Keep surrogate pair characters together.
1514 return obj.match(reStrSymbol);
1515 }
1516 if (isArrayLike(obj)) return map(obj, identity);
1517 return values(obj);
1518}
1519
1520// Sample **n** random values from a collection using the modern version of the
1521// [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
1522// If **n** is not specified, returns a single random element.
1523// The internal `guard` argument allows it to work with `_.map`.
1524function sample(obj, n, guard) {
1525 if (n == null || guard) {
1526 if (!isArrayLike(obj)) obj = values(obj);
1527 return obj[random(obj.length - 1)];
1528 }
1529 var sample = toArray(obj);
1530 var length = getLength(sample);
1531 n = Math.max(Math.min(n, length), 0);
1532 var last = length - 1;
1533 for (var index = 0; index < n; index++) {
1534 var rand = random(index, last);
1535 var temp = sample[index];
1536 sample[index] = sample[rand];
1537 sample[rand] = temp;
1538 }
1539 return sample.slice(0, n);
1540}
1541
1542// Shuffle a collection.
1543function shuffle(obj) {
1544 return sample(obj, Infinity);
1545}
1546
1547// Sort the object's values by a criterion produced by an iteratee.
1548function sortBy(obj, iteratee, context) {
1549 var index = 0;
1550 iteratee = cb(iteratee, context);
1551 return pluck(map(obj, function(value, key, list) {
1552 return {
1553 value: value,
1554 index: index++,
1555 criteria: iteratee(value, key, list)
1556 };
1557 }).sort(function(left, right) {
1558 var a = left.criteria;
1559 var b = right.criteria;
1560 if (a !== b) {
1561 if (a > b || a === void 0) return 1;
1562 if (a < b || b === void 0) return -1;
1563 }
1564 return left.index - right.index;
1565 }), 'value');
1566}
1567
1568// An internal function used for aggregate "group by" operations.
1569function group(behavior, partition) {
1570 return function(obj, iteratee, context) {
1571 var result = partition ? [[], []] : {};
1572 iteratee = cb(iteratee, context);
1573 each(obj, function(value, index) {
1574 var key = iteratee(value, index, obj);
1575 behavior(result, value, key);
1576 });
1577 return result;
1578 };
1579}
1580
1581// Groups the object's values by a criterion. Pass either a string attribute
1582// to group by, or a function that returns the criterion.
1583var groupBy = group(function(result, value, key) {
1584 if (has$1(result, key)) result[key].push(value); else result[key] = [value];
1585});
1586
1587// Indexes the object's values by a criterion, similar to `_.groupBy`, but for
1588// when you know that your index values will be unique.
1589var indexBy = group(function(result, value, key) {
1590 result[key] = value;
1591});
1592
1593// Counts instances of an object that group by a certain criterion. Pass
1594// either a string attribute to count by, or a function that returns the
1595// criterion.
1596var countBy = group(function(result, value, key) {
1597 if (has$1(result, key)) result[key]++; else result[key] = 1;
1598});
1599
1600// Split a collection into two arrays: one whose elements all pass the given
1601// truth test, and one whose elements all do not pass the truth test.
1602var partition = group(function(result, value, pass) {
1603 result[pass ? 0 : 1].push(value);
1604}, true);
1605
1606// Return the number of elements in a collection.
1607function size(obj) {
1608 if (obj == null) return 0;
1609 return isArrayLike(obj) ? obj.length : keys(obj).length;
1610}
1611
1612// Internal `_.pick` helper function to determine whether `key` is an enumerable
1613// property name of `obj`.
1614function keyInObj(value, key, obj) {
1615 return key in obj;
1616}
1617
1618// Return a copy of the object only containing the allowed properties.
1619var pick = restArguments(function(obj, keys) {
1620 var result = {}, iteratee = keys[0];
1621 if (obj == null) return result;
1622 if (isFunction$1(iteratee)) {
1623 if (keys.length > 1) iteratee = optimizeCb(iteratee, keys[1]);
1624 keys = allKeys(obj);
1625 } else {
1626 iteratee = keyInObj;
1627 keys = flatten$1(keys, false, false);
1628 obj = Object(obj);
1629 }
1630 for (var i = 0, length = keys.length; i < length; i++) {
1631 var key = keys[i];
1632 var value = obj[key];
1633 if (iteratee(value, key, obj)) result[key] = value;
1634 }
1635 return result;
1636});
1637
1638// Return a copy of the object without the disallowed properties.
1639var omit = restArguments(function(obj, keys) {
1640 var iteratee = keys[0], context;
1641 if (isFunction$1(iteratee)) {
1642 iteratee = negate(iteratee);
1643 if (keys.length > 1) context = keys[1];
1644 } else {
1645 keys = map(flatten$1(keys, false, false), String);
1646 iteratee = function(value, key) {
1647 return !contains(keys, key);
1648 };
1649 }
1650 return pick(obj, iteratee, context);
1651});
1652
1653// Returns everything but the last entry of the array. Especially useful on
1654// the arguments object. Passing **n** will return all the values in
1655// the array, excluding the last N.
1656function initial(array, n, guard) {
1657 return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
1658}
1659
1660// Get the first element of an array. Passing **n** will return the first N
1661// values in the array. The **guard** check allows it to work with `_.map`.
1662function first(array, n, guard) {
1663 if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
1664 if (n == null || guard) return array[0];
1665 return initial(array, array.length - n);
1666}
1667
1668// Returns everything but the first entry of the `array`. Especially useful on
1669// the `arguments` object. Passing an **n** will return the rest N values in the
1670// `array`.
1671function rest(array, n, guard) {
1672 return slice.call(array, n == null || guard ? 1 : n);
1673}
1674
1675// Get the last element of an array. Passing **n** will return the last N
1676// values in the array.
1677function last(array, n, guard) {
1678 if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
1679 if (n == null || guard) return array[array.length - 1];
1680 return rest(array, Math.max(0, array.length - n));
1681}
1682
1683// Trim out all falsy values from an array.
1684function compact(array) {
1685 return filter(array, Boolean);
1686}
1687
1688// Flatten out an array, either recursively (by default), or up to `depth`.
1689// Passing `true` or `false` as `depth` means `1` or `Infinity`, respectively.
1690function flatten(array, depth) {
1691 return flatten$1(array, depth, false);
1692}
1693
1694// Take the difference between one array and a number of other arrays.
1695// Only the elements present in just the first array will remain.
1696var difference = restArguments(function(array, rest) {
1697 rest = flatten$1(rest, true, true);
1698 return filter(array, function(value){
1699 return !contains(rest, value);
1700 });
1701});
1702
1703// Return a version of the array that does not contain the specified value(s).
1704var without = restArguments(function(array, otherArrays) {
1705 return difference(array, otherArrays);
1706});
1707
1708// Produce a duplicate-free version of the array. If the array has already
1709// been sorted, you have the option of using a faster algorithm.
1710// The faster algorithm will not work with an iteratee if the iteratee
1711// is not a one-to-one function, so providing an iteratee will disable
1712// the faster algorithm.
1713function uniq(array, isSorted, iteratee, context) {
1714 if (!isBoolean(isSorted)) {
1715 context = iteratee;
1716 iteratee = isSorted;
1717 isSorted = false;
1718 }
1719 if (iteratee != null) iteratee = cb(iteratee, context);
1720 var result = [];
1721 var seen = [];
1722 for (var i = 0, length = getLength(array); i < length; i++) {
1723 var value = array[i],
1724 computed = iteratee ? iteratee(value, i, array) : value;
1725 if (isSorted && !iteratee) {
1726 if (!i || seen !== computed) result.push(value);
1727 seen = computed;
1728 } else if (iteratee) {
1729 if (!contains(seen, computed)) {
1730 seen.push(computed);
1731 result.push(value);
1732 }
1733 } else if (!contains(result, value)) {
1734 result.push(value);
1735 }
1736 }
1737 return result;
1738}
1739
1740// Produce an array that contains the union: each distinct element from all of
1741// the passed-in arrays.
1742var union = restArguments(function(arrays) {
1743 return uniq(flatten$1(arrays, true, true));
1744});
1745
1746// Produce an array that contains every item shared between all the
1747// passed-in arrays.
1748function intersection(array) {
1749 var result = [];
1750 var argsLength = arguments.length;
1751 for (var i = 0, length = getLength(array); i < length; i++) {
1752 var item = array[i];
1753 if (contains(result, item)) continue;
1754 var j;
1755 for (j = 1; j < argsLength; j++) {
1756 if (!contains(arguments[j], item)) break;
1757 }
1758 if (j === argsLength) result.push(item);
1759 }
1760 return result;
1761}
1762
1763// Complement of zip. Unzip accepts an array of arrays and groups
1764// each array's elements on shared indices.
1765function unzip(array) {
1766 var length = (array && max(array, getLength).length) || 0;
1767 var result = Array(length);
1768
1769 for (var index = 0; index < length; index++) {
1770 result[index] = pluck(array, index);
1771 }
1772 return result;
1773}
1774
1775// Zip together multiple lists into a single array -- elements that share
1776// an index go together.
1777var zip = restArguments(unzip);
1778
1779// Converts lists into objects. Pass either a single array of `[key, value]`
1780// pairs, or two parallel arrays of the same length -- one of keys, and one of
1781// the corresponding values. Passing by pairs is the reverse of `_.pairs`.
1782function object(list, values) {
1783 var result = {};
1784 for (var i = 0, length = getLength(list); i < length; i++) {
1785 if (values) {
1786 result[list[i]] = values[i];
1787 } else {
1788 result[list[i][0]] = list[i][1];
1789 }
1790 }
1791 return result;
1792}
1793
1794// Generate an integer Array containing an arithmetic progression. A port of
1795// the native Python `range()` function. See
1796// [the Python documentation](https://docs.python.org/library/functions.html#range).
1797function range(start, stop, step) {
1798 if (stop == null) {
1799 stop = start || 0;
1800 start = 0;
1801 }
1802 if (!step) {
1803 step = stop < start ? -1 : 1;
1804 }
1805
1806 var length = Math.max(Math.ceil((stop - start) / step), 0);
1807 var range = Array(length);
1808
1809 for (var idx = 0; idx < length; idx++, start += step) {
1810 range[idx] = start;
1811 }
1812
1813 return range;
1814}
1815
1816// Chunk a single array into multiple arrays, each containing `count` or fewer
1817// items.
1818function chunk(array, count) {
1819 if (count == null || count < 1) return [];
1820 var result = [];
1821 var i = 0, length = array.length;
1822 while (i < length) {
1823 result.push(slice.call(array, i, i += count));
1824 }
1825 return result;
1826}
1827
1828// Helper function to continue chaining intermediate results.
1829function chainResult(instance, obj) {
1830 return instance._chain ? _$1(obj).chain() : obj;
1831}
1832
1833// Add your own custom functions to the Underscore object.
1834function mixin(obj) {
1835 each(functions(obj), function(name) {
1836 var func = _$1[name] = obj[name];
1837 _$1.prototype[name] = function() {
1838 var args = [this._wrapped];
1839 push.apply(args, arguments);
1840 return chainResult(this, func.apply(_$1, args));
1841 };
1842 });
1843 return _$1;
1844}
1845
1846// Add all mutator `Array` functions to the wrapper.
1847each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
1848 var method = ArrayProto[name];
1849 _$1.prototype[name] = function() {
1850 var obj = this._wrapped;
1851 if (obj != null) {
1852 method.apply(obj, arguments);
1853 if ((name === 'shift' || name === 'splice') && obj.length === 0) {
1854 delete obj[0];
1855 }
1856 }
1857 return chainResult(this, obj);
1858 };
1859});
1860
1861// Add all accessor `Array` functions to the wrapper.
1862each(['concat', 'join', 'slice'], function(name) {
1863 var method = ArrayProto[name];
1864 _$1.prototype[name] = function() {
1865 var obj = this._wrapped;
1866 if (obj != null) obj = method.apply(obj, arguments);
1867 return chainResult(this, obj);
1868 };
1869});
1870
1871// Named Exports
1872
1873var allExports = {
1874 __proto__: null,
1875 VERSION: VERSION,
1876 restArguments: restArguments,
1877 isObject: isObject,
1878 isNull: isNull,
1879 isUndefined: isUndefined,
1880 isBoolean: isBoolean,
1881 isElement: isElement,
1882 isString: isString,
1883 isNumber: isNumber,
1884 isDate: isDate,
1885 isRegExp: isRegExp,
1886 isError: isError,
1887 isSymbol: isSymbol,
1888 isArrayBuffer: isArrayBuffer,
1889 isDataView: isDataView$1,
1890 isArray: isArray,
1891 isFunction: isFunction$1,
1892 isArguments: isArguments$1,
1893 isFinite: isFinite$1,
1894 isNaN: isNaN$1,
1895 isTypedArray: isTypedArray$1,
1896 isEmpty: isEmpty,
1897 isMatch: isMatch,
1898 isEqual: isEqual,
1899 isMap: isMap,
1900 isWeakMap: isWeakMap,
1901 isSet: isSet,
1902 isWeakSet: isWeakSet,
1903 keys: keys,
1904 allKeys: allKeys,
1905 values: values,
1906 pairs: pairs,
1907 invert: invert,
1908 functions: functions,
1909 methods: functions,
1910 extend: extend,
1911 extendOwn: extendOwn,
1912 assign: extendOwn,
1913 defaults: defaults,
1914 create: create,
1915 clone: clone,
1916 tap: tap,
1917 get: get,
1918 has: has,
1919 mapObject: mapObject,
1920 identity: identity,
1921 constant: constant,
1922 noop: noop,
1923 toPath: toPath$1,
1924 property: property,
1925 propertyOf: propertyOf,
1926 matcher: matcher,
1927 matches: matcher,
1928 times: times,
1929 random: random,
1930 now: now,
1931 escape: _escape,
1932 unescape: _unescape,
1933 templateSettings: templateSettings,
1934 template: template,
1935 result: result,
1936 uniqueId: uniqueId,
1937 chain: chain,
1938 iteratee: iteratee,
1939 partial: partial,
1940 bind: bind,
1941 bindAll: bindAll,
1942 memoize: memoize,
1943 delay: delay,
1944 defer: defer,
1945 throttle: throttle,
1946 debounce: debounce,
1947 wrap: wrap,
1948 negate: negate,
1949 compose: compose,
1950 after: after,
1951 before: before,
1952 once: once,
1953 findKey: findKey,
1954 findIndex: findIndex,
1955 findLastIndex: findLastIndex,
1956 sortedIndex: sortedIndex,
1957 indexOf: indexOf,
1958 lastIndexOf: lastIndexOf,
1959 find: find,
1960 detect: find,
1961 findWhere: findWhere,
1962 each: each,
1963 forEach: each,
1964 map: map,
1965 collect: map,
1966 reduce: reduce,
1967 foldl: reduce,
1968 inject: reduce,
1969 reduceRight: reduceRight,
1970 foldr: reduceRight,
1971 filter: filter,
1972 select: filter,
1973 reject: reject,
1974 every: every,
1975 all: every,
1976 some: some,
1977 any: some,
1978 contains: contains,
1979 includes: contains,
1980 include: contains,
1981 invoke: invoke,
1982 pluck: pluck,
1983 where: where,
1984 max: max,
1985 min: min,
1986 shuffle: shuffle,
1987 sample: sample,
1988 sortBy: sortBy,
1989 groupBy: groupBy,
1990 indexBy: indexBy,
1991 countBy: countBy,
1992 partition: partition,
1993 toArray: toArray,
1994 size: size,
1995 pick: pick,
1996 omit: omit,
1997 first: first,
1998 head: first,
1999 take: first,
2000 initial: initial,
2001 last: last,
2002 rest: rest,
2003 tail: rest,
2004 drop: rest,
2005 compact: compact,
2006 flatten: flatten,
2007 without: without,
2008 uniq: uniq,
2009 unique: uniq,
2010 union: union,
2011 intersection: intersection,
2012 difference: difference,
2013 unzip: unzip,
2014 transpose: unzip,
2015 zip: zip,
2016 object: object,
2017 range: range,
2018 chunk: chunk,
2019 mixin: mixin,
2020 'default': _$1
2021};
2022
2023// Default Export
2024
2025// Add all of the Underscore functions to the wrapper object.
2026var _ = mixin(allExports);
2027// Legacy Node.js API.
2028_._ = _;
2029
2030// ESM Exports
2031
2032export default _;
2033export { VERSION, after, every as all, allKeys, some as any, extendOwn as assign, before, bind, bindAll, chain, chunk, clone, map as collect, compact, compose, constant, contains, countBy, create, debounce, defaults, defer, delay, find as detect, difference, rest as drop, each, _escape as escape, every, extend, extendOwn, filter, find, findIndex, findKey, findLastIndex, findWhere, first, flatten, reduce as foldl, reduceRight as foldr, each as forEach, functions, get, groupBy, has, first as head, identity, contains as include, contains as includes, indexBy, indexOf, initial, reduce as inject, intersection, invert, invoke, isArguments$1 as isArguments, isArray, isArrayBuffer, isBoolean, isDataView$1 as isDataView, isDate, isElement, isEmpty, isEqual, isError, isFinite$1 as isFinite, isFunction$1 as isFunction, isMap, isMatch, isNaN$1 as isNaN, isNull, isNumber, isObject, isRegExp, isSet, isString, isSymbol, isTypedArray$1 as isTypedArray, isUndefined, isWeakMap, isWeakSet, iteratee, keys, last, lastIndexOf, map, mapObject, matcher, matcher as matches, max, memoize, functions as methods, min, mixin, negate, noop, now, object, omit, once, pairs, partial, partition, pick, pluck, property, propertyOf, random, range, reduce, reduceRight, reject, rest, restArguments, result, sample, filter as select, shuffle, size, some, sortBy, sortedIndex, rest as tail, first as take, tap, template, templateSettings, throttle, times, toArray, toPath$1 as toPath, unzip as transpose, _unescape as unescape, union, uniq, uniq as unique, uniqueId, unzip, values, where, without, wrap, zip };
2034//# sourceMappingURL=underscore-esm.js.map
Note: See TracBrowser for help on using the repository browser.