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