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