[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /** 2 * @license 3 * Lodash <https://lodash.com/> 4 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/> 5 * Released under MIT license <https://lodash.com/license> 6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> 7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors 8 */ 9 ;(function() { 10 11 /** Used as a safe reference for `undefined` in pre-ES5 environments. */ 12 var undefined; 13 14 /** Used as the semantic version number. */ 15 var VERSION = '4.17.21'; 16 17 /** Used as the size to enable large array optimizations. */ 18 var LARGE_ARRAY_SIZE = 200; 19 20 /** Error message constants. */ 21 var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.', 22 FUNC_ERROR_TEXT = 'Expected a function', 23 INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`'; 24 25 /** Used to stand-in for `undefined` hash values. */ 26 var HASH_UNDEFINED = '__lodash_hash_undefined__'; 27 28 /** Used as the maximum memoize cache size. */ 29 var MAX_MEMOIZE_SIZE = 500; 30 31 /** Used as the internal argument placeholder. */ 32 var PLACEHOLDER = '__lodash_placeholder__'; 33 34 /** Used to compose bitmasks for cloning. */ 35 var CLONE_DEEP_FLAG = 1, 36 CLONE_FLAT_FLAG = 2, 37 CLONE_SYMBOLS_FLAG = 4; 38 39 /** Used to compose bitmasks for value comparisons. */ 40 var COMPARE_PARTIAL_FLAG = 1, 41 COMPARE_UNORDERED_FLAG = 2; 42 43 /** Used to compose bitmasks for function metadata. */ 44 var WRAP_BIND_FLAG = 1, 45 WRAP_BIND_KEY_FLAG = 2, 46 WRAP_CURRY_BOUND_FLAG = 4, 47 WRAP_CURRY_FLAG = 8, 48 WRAP_CURRY_RIGHT_FLAG = 16, 49 WRAP_PARTIAL_FLAG = 32, 50 WRAP_PARTIAL_RIGHT_FLAG = 64, 51 WRAP_ARY_FLAG = 128, 52 WRAP_REARG_FLAG = 256, 53 WRAP_FLIP_FLAG = 512; 54 55 /** Used as default options for `_.truncate`. */ 56 var DEFAULT_TRUNC_LENGTH = 30, 57 DEFAULT_TRUNC_OMISSION = '...'; 58 59 /** Used to detect hot functions by number of calls within a span of milliseconds. */ 60 var HOT_COUNT = 800, 61 HOT_SPAN = 16; 62 63 /** Used to indicate the type of lazy iteratees. */ 64 var LAZY_FILTER_FLAG = 1, 65 LAZY_MAP_FLAG = 2, 66 LAZY_WHILE_FLAG = 3; 67 68 /** Used as references for various `Number` constants. */ 69 var INFINITY = 1 / 0, 70 MAX_SAFE_INTEGER = 9007199254740991, 71 MAX_INTEGER = 1.7976931348623157e+308, 72 NAN = 0 / 0; 73 74 /** Used as references for the maximum length and index of an array. */ 75 var MAX_ARRAY_LENGTH = 4294967295, 76 MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, 77 HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; 78 79 /** Used to associate wrap methods with their bit flags. */ 80 var wrapFlags = [ 81 ['ary', WRAP_ARY_FLAG], 82 ['bind', WRAP_BIND_FLAG], 83 ['bindKey', WRAP_BIND_KEY_FLAG], 84 ['curry', WRAP_CURRY_FLAG], 85 ['curryRight', WRAP_CURRY_RIGHT_FLAG], 86 ['flip', WRAP_FLIP_FLAG], 87 ['partial', WRAP_PARTIAL_FLAG], 88 ['partialRight', WRAP_PARTIAL_RIGHT_FLAG], 89 ['rearg', WRAP_REARG_FLAG] 90 ]; 91 92 /** `Object#toString` result references. */ 93 var argsTag = '[object Arguments]', 94 arrayTag = '[object Array]', 95 asyncTag = '[object AsyncFunction]', 96 boolTag = '[object Boolean]', 97 dateTag = '[object Date]', 98 domExcTag = '[object DOMException]', 99 errorTag = '[object Error]', 100 funcTag = '[object Function]', 101 genTag = '[object GeneratorFunction]', 102 mapTag = '[object Map]', 103 numberTag = '[object Number]', 104 nullTag = '[object Null]', 105 objectTag = '[object Object]', 106 promiseTag = '[object Promise]', 107 proxyTag = '[object Proxy]', 108 regexpTag = '[object RegExp]', 109 setTag = '[object Set]', 110 stringTag = '[object String]', 111 symbolTag = '[object Symbol]', 112 undefinedTag = '[object Undefined]', 113 weakMapTag = '[object WeakMap]', 114 weakSetTag = '[object WeakSet]'; 115 116 var arrayBufferTag = '[object ArrayBuffer]', 117 dataViewTag = '[object DataView]', 118 float32Tag = '[object Float32Array]', 119 float64Tag = '[object Float64Array]', 120 int8Tag = '[object Int8Array]', 121 int16Tag = '[object Int16Array]', 122 int32Tag = '[object Int32Array]', 123 uint8Tag = '[object Uint8Array]', 124 uint8ClampedTag = '[object Uint8ClampedArray]', 125 uint16Tag = '[object Uint16Array]', 126 uint32Tag = '[object Uint32Array]'; 127 128 /** Used to match empty string literals in compiled template source. */ 129 var reEmptyStringLeading = /\b__p \+= '';/g, 130 reEmptyStringMiddle = /\b(__p \+=) '' \+/g, 131 reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; 132 133 /** Used to match HTML entities and HTML characters. */ 134 var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, 135 reUnescapedHtml = /[&<>"']/g, 136 reHasEscapedHtml = RegExp(reEscapedHtml.source), 137 reHasUnescapedHtml = RegExp(reUnescapedHtml.source); 138 139 /** Used to match template delimiters. */ 140 var reEscape = /<%-([\s\S]+?)%>/g, 141 reEvaluate = /<%([\s\S]+?)%>/g, 142 reInterpolate = /<%=([\s\S]+?)%>/g; 143 144 /** Used to match property names within property paths. */ 145 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, 146 reIsPlainProp = /^\w*$/, 147 rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; 148 149 /** 150 * Used to match `RegExp` 151 * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). 152 */ 153 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, 154 reHasRegExpChar = RegExp(reRegExpChar.source); 155 156 /** Used to match leading whitespace. */ 157 var reTrimStart = /^\s+/; 158 159 /** Used to match a single whitespace character. */ 160 var reWhitespace = /\s/; 161 162 /** Used to match wrap detail comments. */ 163 var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, 164 reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, 165 reSplitDetails = /,? & /; 166 167 /** Used to match words composed of alphanumeric characters. */ 168 var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; 169 170 /** 171 * Used to validate the `validate` option in `_.template` variable. 172 * 173 * Forbids characters which could potentially change the meaning of the function argument definition: 174 * - "()," (modification of function parameters) 175 * - "=" (default value) 176 * - "[]{}" (destructuring of function parameters) 177 * - "/" (beginning of a comment) 178 * - whitespace 179 */ 180 var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/; 181 182 /** Used to match backslashes in property paths. */ 183 var reEscapeChar = /\\(\\)?/g; 184 185 /** 186 * Used to match 187 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). 188 */ 189 var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; 190 191 /** Used to match `RegExp` flags from their coerced string values. */ 192 var reFlags = /\w*$/; 193 194 /** Used to detect bad signed hexadecimal string values. */ 195 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; 196 197 /** Used to detect binary string values. */ 198 var reIsBinary = /^0b[01]+$/i; 199 200 /** Used to detect host constructors (Safari). */ 201 var reIsHostCtor = /^\[object .+?Constructor\]$/; 202 203 /** Used to detect octal string values. */ 204 var reIsOctal = /^0o[0-7]+$/i; 205 206 /** Used to detect unsigned integer values. */ 207 var reIsUint = /^(?:0|[1-9]\d*)$/; 208 209 /** Used to match Latin Unicode letters (excluding mathematical operators). */ 210 var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; 211 212 /** Used to ensure capturing order of template delimiters. */ 213 var reNoMatch = /($^)/; 214 215 /** Used to match unescaped characters in compiled string literals. */ 216 var reUnescapedString = /['\n\r\u2028\u2029\\]/g; 217 218 /** Used to compose unicode character classes. */ 219 var rsAstralRange = '\\ud800-\\udfff', 220 rsComboMarksRange = '\\u0300-\\u036f', 221 reComboHalfMarksRange = '\\ufe20-\\ufe2f', 222 rsComboSymbolsRange = '\\u20d0-\\u20ff', 223 rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, 224 rsDingbatRange = '\\u2700-\\u27bf', 225 rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', 226 rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', 227 rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', 228 rsPunctuationRange = '\\u2000-\\u206f', 229 rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', 230 rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', 231 rsVarRange = '\\ufe0e\\ufe0f', 232 rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; 233 234 /** Used to compose unicode capture groups. */ 235 var rsApos = "['\u2019]", 236 rsAstral = '[' + rsAstralRange + ']', 237 rsBreak = '[' + rsBreakRange + ']', 238 rsCombo = '[' + rsComboRange + ']', 239 rsDigits = '\\d+', 240 rsDingbat = '[' + rsDingbatRange + ']', 241 rsLower = '[' + rsLowerRange + ']', 242 rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', 243 rsFitz = '\\ud83c[\\udffb-\\udfff]', 244 rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', 245 rsNonAstral = '[^' + rsAstralRange + ']', 246 rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', 247 rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', 248 rsUpper = '[' + rsUpperRange + ']', 249 rsZWJ = '\\u200d'; 250 251 /** Used to compose unicode regexes. */ 252 var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', 253 rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', 254 rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', 255 rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', 256 reOptMod = rsModifier + '?', 257 rsOptVar = '[' + rsVarRange + ']?', 258 rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', 259 rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', 260 rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', 261 rsSeq = rsOptVar + reOptMod + rsOptJoin, 262 rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, 263 rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; 264 265 /** Used to match apostrophes. */ 266 var reApos = RegExp(rsApos, 'g'); 267 268 /** 269 * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and 270 * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). 271 */ 272 var reComboMark = RegExp(rsCombo, 'g'); 273 274 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ 275 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); 276 277 /** Used to match complex or compound words. */ 278 var reUnicodeWord = RegExp([ 279 rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', 280 rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', 281 rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, 282 rsUpper + '+' + rsOptContrUpper, 283 rsOrdUpper, 284 rsOrdLower, 285 rsDigits, 286 rsEmoji 287 ].join('|'), 'g'); 288 289 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ 290 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); 291 292 /** Used to detect strings that need a more robust regexp to match words. */ 293 var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; 294 295 /** Used to assign default `context` object properties. */ 296 var contextProps = [ 297 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', 298 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', 299 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', 300 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', 301 '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' 302 ]; 303 304 /** Used to make template sourceURLs easier to identify. */ 305 var templateCounter = -1; 306 307 /** Used to identify `toStringTag` values of typed arrays. */ 308 var typedArrayTags = {}; 309 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = 310 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = 311 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = 312 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = 313 typedArrayTags[uint32Tag] = true; 314 typedArrayTags[argsTag] = typedArrayTags[arrayTag] = 315 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = 316 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = 317 typedArrayTags[errorTag] = typedArrayTags[funcTag] = 318 typedArrayTags[mapTag] = typedArrayTags[numberTag] = 319 typedArrayTags[objectTag] = typedArrayTags[regexpTag] = 320 typedArrayTags[setTag] = typedArrayTags[stringTag] = 321 typedArrayTags[weakMapTag] = false; 322 323 /** Used to identify `toStringTag` values supported by `_.clone`. */ 324 var cloneableTags = {}; 325 cloneableTags[argsTag] = cloneableTags[arrayTag] = 326 cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = 327 cloneableTags[boolTag] = cloneableTags[dateTag] = 328 cloneableTags[float32Tag] = cloneableTags[float64Tag] = 329 cloneableTags[int8Tag] = cloneableTags[int16Tag] = 330 cloneableTags[int32Tag] = cloneableTags[mapTag] = 331 cloneableTags[numberTag] = cloneableTags[objectTag] = 332 cloneableTags[regexpTag] = cloneableTags[setTag] = 333 cloneableTags[stringTag] = cloneableTags[symbolTag] = 334 cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = 335 cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; 336 cloneableTags[errorTag] = cloneableTags[funcTag] = 337 cloneableTags[weakMapTag] = false; 338 339 /** Used to map Latin Unicode letters to basic Latin letters. */ 340 var deburredLetters = { 341 // Latin-1 Supplement block. 342 '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', 343 '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', 344 '\xc7': 'C', '\xe7': 'c', 345 '\xd0': 'D', '\xf0': 'd', 346 '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', 347 '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', 348 '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', 349 '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', 350 '\xd1': 'N', '\xf1': 'n', 351 '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', 352 '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', 353 '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', 354 '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', 355 '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', 356 '\xc6': 'Ae', '\xe6': 'ae', 357 '\xde': 'Th', '\xfe': 'th', 358 '\xdf': 'ss', 359 // Latin Extended-A block. 360 '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', 361 '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', 362 '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', 363 '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', 364 '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', 365 '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', 366 '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', 367 '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', 368 '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', 369 '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', 370 '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', 371 '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', 372 '\u0134': 'J', '\u0135': 'j', 373 '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', 374 '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', 375 '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', 376 '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', 377 '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', 378 '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', 379 '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', 380 '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', 381 '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', 382 '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', 383 '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', 384 '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', 385 '\u0163': 't', '\u0165': 't', '\u0167': 't', 386 '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', 387 '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', 388 '\u0174': 'W', '\u0175': 'w', 389 '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', 390 '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', 391 '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', 392 '\u0132': 'IJ', '\u0133': 'ij', 393 '\u0152': 'Oe', '\u0153': 'oe', 394 '\u0149': "'n", '\u017f': 's' 395 }; 396 397 /** Used to map characters to HTML entities. */ 398 var htmlEscapes = { 399 '&': '&', 400 '<': '<', 401 '>': '>', 402 '"': '"', 403 "'": ''' 404 }; 405 406 /** Used to map HTML entities to characters. */ 407 var htmlUnescapes = { 408 '&': '&', 409 '<': '<', 410 '>': '>', 411 '"': '"', 412 ''': "'" 413 }; 414 415 /** Used to escape characters for inclusion in compiled string literals. */ 416 var stringEscapes = { 417 '\\': '\\', 418 "'": "'", 419 '\n': 'n', 420 '\r': 'r', 421 '\u2028': 'u2028', 422 '\u2029': 'u2029' 423 }; 424 425 /** Built-in method references without a dependency on `root`. */ 426 var freeParseFloat = parseFloat, 427 freeParseInt = parseInt; 428 429 /** Detect free variable `global` from Node.js. */ 430 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; 431 432 /** Detect free variable `self`. */ 433 var freeSelf = typeof self == 'object' && self && self.Object === Object && self; 434 435 /** Used as a reference to the global object. */ 436 var root = freeGlobal || freeSelf || Function('return this')(); 437 438 /** Detect free variable `exports`. */ 439 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; 440 441 /** Detect free variable `module`. */ 442 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; 443 444 /** Detect the popular CommonJS extension `module.exports`. */ 445 var moduleExports = freeModule && freeModule.exports === freeExports; 446 447 /** Detect free variable `process` from Node.js. */ 448 var freeProcess = moduleExports && freeGlobal.process; 449 450 /** Used to access faster Node.js helpers. */ 451 var nodeUtil = (function() { 452 try { 453 // Use `util.types` for Node.js 10+. 454 var types = freeModule && freeModule.require && freeModule.require('util').types; 455 456 if (types) { 457 return types; 458 } 459 460 // Legacy `process.binding('util')` for Node.js < 10. 461 return freeProcess && freeProcess.binding && freeProcess.binding('util'); 462 } catch (e) {} 463 }()); 464 465 /* Node.js helper references. */ 466 var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, 467 nodeIsDate = nodeUtil && nodeUtil.isDate, 468 nodeIsMap = nodeUtil && nodeUtil.isMap, 469 nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, 470 nodeIsSet = nodeUtil && nodeUtil.isSet, 471 nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; 472 473 /*--------------------------------------------------------------------------*/ 474 475 /** 476 * A faster alternative to `Function#apply`, this function invokes `func` 477 * with the `this` binding of `thisArg` and the arguments of `args`. 478 * 479 * @private 480 * @param {Function} func The function to invoke. 481 * @param {*} thisArg The `this` binding of `func`. 482 * @param {Array} args The arguments to invoke `func` with. 483 * @returns {*} Returns the result of `func`. 484 */ 485 function apply(func, thisArg, args) { 486 switch (args.length) { 487 case 0: return func.call(thisArg); 488 case 1: return func.call(thisArg, args[0]); 489 case 2: return func.call(thisArg, args[0], args[1]); 490 case 3: return func.call(thisArg, args[0], args[1], args[2]); 491 } 492 return func.apply(thisArg, args); 493 } 494 495 /** 496 * A specialized version of `baseAggregator` for arrays. 497 * 498 * @private 499 * @param {Array} [array] The array to iterate over. 500 * @param {Function} setter The function to set `accumulator` values. 501 * @param {Function} iteratee The iteratee to transform keys. 502 * @param {Object} accumulator The initial aggregated object. 503 * @returns {Function} Returns `accumulator`. 504 */ 505 function arrayAggregator(array, setter, iteratee, accumulator) { 506 var index = -1, 507 length = array == null ? 0 : array.length; 508 509 while (++index < length) { 510 var value = array[index]; 511 setter(accumulator, value, iteratee(value), array); 512 } 513 return accumulator; 514 } 515 516 /** 517 * A specialized version of `_.forEach` for arrays without support for 518 * iteratee shorthands. 519 * 520 * @private 521 * @param {Array} [array] The array to iterate over. 522 * @param {Function} iteratee The function invoked per iteration. 523 * @returns {Array} Returns `array`. 524 */ 525 function arrayEach(array, iteratee) { 526 var index = -1, 527 length = array == null ? 0 : array.length; 528 529 while (++index < length) { 530 if (iteratee(array[index], index, array) === false) { 531 break; 532 } 533 } 534 return array; 535 } 536 537 /** 538 * A specialized version of `_.forEachRight` for arrays without support for 539 * iteratee shorthands. 540 * 541 * @private 542 * @param {Array} [array] The array to iterate over. 543 * @param {Function} iteratee The function invoked per iteration. 544 * @returns {Array} Returns `array`. 545 */ 546 function arrayEachRight(array, iteratee) { 547 var length = array == null ? 0 : array.length; 548 549 while (length--) { 550 if (iteratee(array[length], length, array) === false) { 551 break; 552 } 553 } 554 return array; 555 } 556 557 /** 558 * A specialized version of `_.every` for arrays without support for 559 * iteratee shorthands. 560 * 561 * @private 562 * @param {Array} [array] The array to iterate over. 563 * @param {Function} predicate The function invoked per iteration. 564 * @returns {boolean} Returns `true` if all elements pass the predicate check, 565 * else `false`. 566 */ 567 function arrayEvery(array, predicate) { 568 var index = -1, 569 length = array == null ? 0 : array.length; 570 571 while (++index < length) { 572 if (!predicate(array[index], index, array)) { 573 return false; 574 } 575 } 576 return true; 577 } 578 579 /** 580 * A specialized version of `_.filter` for arrays without support for 581 * iteratee shorthands. 582 * 583 * @private 584 * @param {Array} [array] The array to iterate over. 585 * @param {Function} predicate The function invoked per iteration. 586 * @returns {Array} Returns the new filtered array. 587 */ 588 function arrayFilter(array, predicate) { 589 var index = -1, 590 length = array == null ? 0 : array.length, 591 resIndex = 0, 592 result = []; 593 594 while (++index < length) { 595 var value = array[index]; 596 if (predicate(value, index, array)) { 597 result[resIndex++] = value; 598 } 599 } 600 return result; 601 } 602 603 /** 604 * A specialized version of `_.includes` for arrays without support for 605 * specifying an index to search from. 606 * 607 * @private 608 * @param {Array} [array] The array to inspect. 609 * @param {*} target The value to search for. 610 * @returns {boolean} Returns `true` if `target` is found, else `false`. 611 */ 612 function arrayIncludes(array, value) { 613 var length = array == null ? 0 : array.length; 614 return !!length && baseIndexOf(array, value, 0) > -1; 615 } 616 617 /** 618 * This function is like `arrayIncludes` except that it accepts a comparator. 619 * 620 * @private 621 * @param {Array} [array] The array to inspect. 622 * @param {*} target The value to search for. 623 * @param {Function} comparator The comparator invoked per element. 624 * @returns {boolean} Returns `true` if `target` is found, else `false`. 625 */ 626 function arrayIncludesWith(array, value, comparator) { 627 var index = -1, 628 length = array == null ? 0 : array.length; 629 630 while (++index < length) { 631 if (comparator(value, array[index])) { 632 return true; 633 } 634 } 635 return false; 636 } 637 638 /** 639 * A specialized version of `_.map` for arrays without support for iteratee 640 * shorthands. 641 * 642 * @private 643 * @param {Array} [array] The array to iterate over. 644 * @param {Function} iteratee The function invoked per iteration. 645 * @returns {Array} Returns the new mapped array. 646 */ 647 function arrayMap(array, iteratee) { 648 var index = -1, 649 length = array == null ? 0 : array.length, 650 result = Array(length); 651 652 while (++index < length) { 653 result[index] = iteratee(array[index], index, array); 654 } 655 return result; 656 } 657 658 /** 659 * Appends the elements of `values` to `array`. 660 * 661 * @private 662 * @param {Array} array The array to modify. 663 * @param {Array} values The values to append. 664 * @returns {Array} Returns `array`. 665 */ 666 function arrayPush(array, values) { 667 var index = -1, 668 length = values.length, 669 offset = array.length; 670 671 while (++index < length) { 672 array[offset + index] = values[index]; 673 } 674 return array; 675 } 676 677 /** 678 * A specialized version of `_.reduce` for arrays without support for 679 * iteratee shorthands. 680 * 681 * @private 682 * @param {Array} [array] The array to iterate over. 683 * @param {Function} iteratee The function invoked per iteration. 684 * @param {*} [accumulator] The initial value. 685 * @param {boolean} [initAccum] Specify using the first element of `array` as 686 * the initial value. 687 * @returns {*} Returns the accumulated value. 688 */ 689 function arrayReduce(array, iteratee, accumulator, initAccum) { 690 var index = -1, 691 length = array == null ? 0 : array.length; 692 693 if (initAccum && length) { 694 accumulator = array[++index]; 695 } 696 while (++index < length) { 697 accumulator = iteratee(accumulator, array[index], index, array); 698 } 699 return accumulator; 700 } 701 702 /** 703 * A specialized version of `_.reduceRight` for arrays without support for 704 * iteratee shorthands. 705 * 706 * @private 707 * @param {Array} [array] The array to iterate over. 708 * @param {Function} iteratee The function invoked per iteration. 709 * @param {*} [accumulator] The initial value. 710 * @param {boolean} [initAccum] Specify using the last element of `array` as 711 * the initial value. 712 * @returns {*} Returns the accumulated value. 713 */ 714 function arrayReduceRight(array, iteratee, accumulator, initAccum) { 715 var length = array == null ? 0 : array.length; 716 if (initAccum && length) { 717 accumulator = array[--length]; 718 } 719 while (length--) { 720 accumulator = iteratee(accumulator, array[length], length, array); 721 } 722 return accumulator; 723 } 724 725 /** 726 * A specialized version of `_.some` for arrays without support for iteratee 727 * shorthands. 728 * 729 * @private 730 * @param {Array} [array] The array to iterate over. 731 * @param {Function} predicate The function invoked per iteration. 732 * @returns {boolean} Returns `true` if any element passes the predicate check, 733 * else `false`. 734 */ 735 function arraySome(array, predicate) { 736 var index = -1, 737 length = array == null ? 0 : array.length; 738 739 while (++index < length) { 740 if (predicate(array[index], index, array)) { 741 return true; 742 } 743 } 744 return false; 745 } 746 747 /** 748 * Gets the size of an ASCII `string`. 749 * 750 * @private 751 * @param {string} string The string inspect. 752 * @returns {number} Returns the string size. 753 */ 754 var asciiSize = baseProperty('length'); 755 756 /** 757 * Converts an ASCII `string` to an array. 758 * 759 * @private 760 * @param {string} string The string to convert. 761 * @returns {Array} Returns the converted array. 762 */ 763 function asciiToArray(string) { 764 return string.split(''); 765 } 766 767 /** 768 * Splits an ASCII `string` into an array of its words. 769 * 770 * @private 771 * @param {string} The string to inspect. 772 * @returns {Array} Returns the words of `string`. 773 */ 774 function asciiWords(string) { 775 return string.match(reAsciiWord) || []; 776 } 777 778 /** 779 * The base implementation of methods like `_.findKey` and `_.findLastKey`, 780 * without support for iteratee shorthands, which iterates over `collection` 781 * using `eachFunc`. 782 * 783 * @private 784 * @param {Array|Object} collection The collection to inspect. 785 * @param {Function} predicate The function invoked per iteration. 786 * @param {Function} eachFunc The function to iterate over `collection`. 787 * @returns {*} Returns the found element or its key, else `undefined`. 788 */ 789 function baseFindKey(collection, predicate, eachFunc) { 790 var result; 791 eachFunc(collection, function(value, key, collection) { 792 if (predicate(value, key, collection)) { 793 result = key; 794 return false; 795 } 796 }); 797 return result; 798 } 799 800 /** 801 * The base implementation of `_.findIndex` and `_.findLastIndex` without 802 * support for iteratee shorthands. 803 * 804 * @private 805 * @param {Array} array The array to inspect. 806 * @param {Function} predicate The function invoked per iteration. 807 * @param {number} fromIndex The index to search from. 808 * @param {boolean} [fromRight] Specify iterating from right to left. 809 * @returns {number} Returns the index of the matched value, else `-1`. 810 */ 811 function baseFindIndex(array, predicate, fromIndex, fromRight) { 812 var length = array.length, 813 index = fromIndex + (fromRight ? 1 : -1); 814 815 while ((fromRight ? index-- : ++index < length)) { 816 if (predicate(array[index], index, array)) { 817 return index; 818 } 819 } 820 return -1; 821 } 822 823 /** 824 * The base implementation of `_.indexOf` without `fromIndex` bounds checks. 825 * 826 * @private 827 * @param {Array} array The array to inspect. 828 * @param {*} value The value to search for. 829 * @param {number} fromIndex The index to search from. 830 * @returns {number} Returns the index of the matched value, else `-1`. 831 */ 832 function baseIndexOf(array, value, fromIndex) { 833 return value === value 834 ? strictIndexOf(array, value, fromIndex) 835 : baseFindIndex(array, baseIsNaN, fromIndex); 836 } 837 838 /** 839 * This function is like `baseIndexOf` except that it accepts a comparator. 840 * 841 * @private 842 * @param {Array} array The array to inspect. 843 * @param {*} value The value to search for. 844 * @param {number} fromIndex The index to search from. 845 * @param {Function} comparator The comparator invoked per element. 846 * @returns {number} Returns the index of the matched value, else `-1`. 847 */ 848 function baseIndexOfWith(array, value, fromIndex, comparator) { 849 var index = fromIndex - 1, 850 length = array.length; 851 852 while (++index < length) { 853 if (comparator(array[index], value)) { 854 return index; 855 } 856 } 857 return -1; 858 } 859 860 /** 861 * The base implementation of `_.isNaN` without support for number objects. 862 * 863 * @private 864 * @param {*} value The value to check. 865 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. 866 */ 867 function baseIsNaN(value) { 868 return value !== value; 869 } 870 871 /** 872 * The base implementation of `_.mean` and `_.meanBy` without support for 873 * iteratee shorthands. 874 * 875 * @private 876 * @param {Array} array The array to iterate over. 877 * @param {Function} iteratee The function invoked per iteration. 878 * @returns {number} Returns the mean. 879 */ 880 function baseMean(array, iteratee) { 881 var length = array == null ? 0 : array.length; 882 return length ? (baseSum(array, iteratee) / length) : NAN; 883 } 884 885 /** 886 * The base implementation of `_.property` without support for deep paths. 887 * 888 * @private 889 * @param {string} key The key of the property to get. 890 * @returns {Function} Returns the new accessor function. 891 */ 892 function baseProperty(key) { 893 return function(object) { 894 return object == null ? undefined : object[key]; 895 }; 896 } 897 898 /** 899 * The base implementation of `_.propertyOf` without support for deep paths. 900 * 901 * @private 902 * @param {Object} object The object to query. 903 * @returns {Function} Returns the new accessor function. 904 */ 905 function basePropertyOf(object) { 906 return function(key) { 907 return object == null ? undefined : object[key]; 908 }; 909 } 910 911 /** 912 * The base implementation of `_.reduce` and `_.reduceRight`, without support 913 * for iteratee shorthands, which iterates over `collection` using `eachFunc`. 914 * 915 * @private 916 * @param {Array|Object} collection The collection to iterate over. 917 * @param {Function} iteratee The function invoked per iteration. 918 * @param {*} accumulator The initial value. 919 * @param {boolean} initAccum Specify using the first or last element of 920 * `collection` as the initial value. 921 * @param {Function} eachFunc The function to iterate over `collection`. 922 * @returns {*} Returns the accumulated value. 923 */ 924 function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { 925 eachFunc(collection, function(value, index, collection) { 926 accumulator = initAccum 927 ? (initAccum = false, value) 928 : iteratee(accumulator, value, index, collection); 929 }); 930 return accumulator; 931 } 932 933 /** 934 * The base implementation of `_.sortBy` which uses `comparer` to define the 935 * sort order of `array` and replaces criteria objects with their corresponding 936 * values. 937 * 938 * @private 939 * @param {Array} array The array to sort. 940 * @param {Function} comparer The function to define sort order. 941 * @returns {Array} Returns `array`. 942 */ 943 function baseSortBy(array, comparer) { 944 var length = array.length; 945 946 array.sort(comparer); 947 while (length--) { 948 array[length] = array[length].value; 949 } 950 return array; 951 } 952 953 /** 954 * The base implementation of `_.sum` and `_.sumBy` without support for 955 * iteratee shorthands. 956 * 957 * @private 958 * @param {Array} array The array to iterate over. 959 * @param {Function} iteratee The function invoked per iteration. 960 * @returns {number} Returns the sum. 961 */ 962 function baseSum(array, iteratee) { 963 var result, 964 index = -1, 965 length = array.length; 966 967 while (++index < length) { 968 var current = iteratee(array[index]); 969 if (current !== undefined) { 970 result = result === undefined ? current : (result + current); 971 } 972 } 973 return result; 974 } 975 976 /** 977 * The base implementation of `_.times` without support for iteratee shorthands 978 * or max array length checks. 979 * 980 * @private 981 * @param {number} n The number of times to invoke `iteratee`. 982 * @param {Function} iteratee The function invoked per iteration. 983 * @returns {Array} Returns the array of results. 984 */ 985 function baseTimes(n, iteratee) { 986 var index = -1, 987 result = Array(n); 988 989 while (++index < n) { 990 result[index] = iteratee(index); 991 } 992 return result; 993 } 994 995 /** 996 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array 997 * of key-value pairs for `object` corresponding to the property names of `props`. 998 * 999 * @private 1000 * @param {Object} object The object to query. 1001 * @param {Array} props The property names to get values for. 1002 * @returns {Object} Returns the key-value pairs. 1003 */ 1004 function baseToPairs(object, props) { 1005 return arrayMap(props, function(key) { 1006 return [key, object[key]]; 1007 }); 1008 } 1009 1010 /** 1011 * The base implementation of `_.trim`. 1012 * 1013 * @private 1014 * @param {string} string The string to trim. 1015 * @returns {string} Returns the trimmed string. 1016 */ 1017 function baseTrim(string) { 1018 return string 1019 ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') 1020 : string; 1021 } 1022 1023 /** 1024 * The base implementation of `_.unary` without support for storing metadata. 1025 * 1026 * @private 1027 * @param {Function} func The function to cap arguments for. 1028 * @returns {Function} Returns the new capped function. 1029 */ 1030 function baseUnary(func) { 1031 return function(value) { 1032 return func(value); 1033 }; 1034 } 1035 1036 /** 1037 * The base implementation of `_.values` and `_.valuesIn` which creates an 1038 * array of `object` property values corresponding to the property names 1039 * of `props`. 1040 * 1041 * @private 1042 * @param {Object} object The object to query. 1043 * @param {Array} props The property names to get values for. 1044 * @returns {Object} Returns the array of property values. 1045 */ 1046 function baseValues(object, props) { 1047 return arrayMap(props, function(key) { 1048 return object[key]; 1049 }); 1050 } 1051 1052 /** 1053 * Checks if a `cache` value for `key` exists. 1054 * 1055 * @private 1056 * @param {Object} cache The cache to query. 1057 * @param {string} key The key of the entry to check. 1058 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 1059 */ 1060 function cacheHas(cache, key) { 1061 return cache.has(key); 1062 } 1063 1064 /** 1065 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol 1066 * that is not found in the character symbols. 1067 * 1068 * @private 1069 * @param {Array} strSymbols The string symbols to inspect. 1070 * @param {Array} chrSymbols The character symbols to find. 1071 * @returns {number} Returns the index of the first unmatched string symbol. 1072 */ 1073 function charsStartIndex(strSymbols, chrSymbols) { 1074 var index = -1, 1075 length = strSymbols.length; 1076 1077 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} 1078 return index; 1079 } 1080 1081 /** 1082 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol 1083 * that is not found in the character symbols. 1084 * 1085 * @private 1086 * @param {Array} strSymbols The string symbols to inspect. 1087 * @param {Array} chrSymbols The character symbols to find. 1088 * @returns {number} Returns the index of the last unmatched string symbol. 1089 */ 1090 function charsEndIndex(strSymbols, chrSymbols) { 1091 var index = strSymbols.length; 1092 1093 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} 1094 return index; 1095 } 1096 1097 /** 1098 * Gets the number of `placeholder` occurrences in `array`. 1099 * 1100 * @private 1101 * @param {Array} array The array to inspect. 1102 * @param {*} placeholder The placeholder to search for. 1103 * @returns {number} Returns the placeholder count. 1104 */ 1105 function countHolders(array, placeholder) { 1106 var length = array.length, 1107 result = 0; 1108 1109 while (length--) { 1110 if (array[length] === placeholder) { 1111 ++result; 1112 } 1113 } 1114 return result; 1115 } 1116 1117 /** 1118 * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A 1119 * letters to basic Latin letters. 1120 * 1121 * @private 1122 * @param {string} letter The matched letter to deburr. 1123 * @returns {string} Returns the deburred letter. 1124 */ 1125 var deburrLetter = basePropertyOf(deburredLetters); 1126 1127 /** 1128 * Used by `_.escape` to convert characters to HTML entities. 1129 * 1130 * @private 1131 * @param {string} chr The matched character to escape. 1132 * @returns {string} Returns the escaped character. 1133 */ 1134 var escapeHtmlChar = basePropertyOf(htmlEscapes); 1135 1136 /** 1137 * Used by `_.template` to escape characters for inclusion in compiled string literals. 1138 * 1139 * @private 1140 * @param {string} chr The matched character to escape. 1141 * @returns {string} Returns the escaped character. 1142 */ 1143 function escapeStringChar(chr) { 1144 return '\\' + stringEscapes[chr]; 1145 } 1146 1147 /** 1148 * Gets the value at `key` of `object`. 1149 * 1150 * @private 1151 * @param {Object} [object] The object to query. 1152 * @param {string} key The key of the property to get. 1153 * @returns {*} Returns the property value. 1154 */ 1155 function getValue(object, key) { 1156 return object == null ? undefined : object[key]; 1157 } 1158 1159 /** 1160 * Checks if `string` contains Unicode symbols. 1161 * 1162 * @private 1163 * @param {string} string The string to inspect. 1164 * @returns {boolean} Returns `true` if a symbol is found, else `false`. 1165 */ 1166 function hasUnicode(string) { 1167 return reHasUnicode.test(string); 1168 } 1169 1170 /** 1171 * Checks if `string` contains a word composed of Unicode symbols. 1172 * 1173 * @private 1174 * @param {string} string The string to inspect. 1175 * @returns {boolean} Returns `true` if a word is found, else `false`. 1176 */ 1177 function hasUnicodeWord(string) { 1178 return reHasUnicodeWord.test(string); 1179 } 1180 1181 /** 1182 * Converts `iterator` to an array. 1183 * 1184 * @private 1185 * @param {Object} iterator The iterator to convert. 1186 * @returns {Array} Returns the converted array. 1187 */ 1188 function iteratorToArray(iterator) { 1189 var data, 1190 result = []; 1191 1192 while (!(data = iterator.next()).done) { 1193 result.push(data.value); 1194 } 1195 return result; 1196 } 1197 1198 /** 1199 * Converts `map` to its key-value pairs. 1200 * 1201 * @private 1202 * @param {Object} map The map to convert. 1203 * @returns {Array} Returns the key-value pairs. 1204 */ 1205 function mapToArray(map) { 1206 var index = -1, 1207 result = Array(map.size); 1208 1209 map.forEach(function(value, key) { 1210 result[++index] = [key, value]; 1211 }); 1212 return result; 1213 } 1214 1215 /** 1216 * Creates a unary function that invokes `func` with its argument transformed. 1217 * 1218 * @private 1219 * @param {Function} func The function to wrap. 1220 * @param {Function} transform The argument transform. 1221 * @returns {Function} Returns the new function. 1222 */ 1223 function overArg(func, transform) { 1224 return function(arg) { 1225 return func(transform(arg)); 1226 }; 1227 } 1228 1229 /** 1230 * Replaces all `placeholder` elements in `array` with an internal placeholder 1231 * and returns an array of their indexes. 1232 * 1233 * @private 1234 * @param {Array} array The array to modify. 1235 * @param {*} placeholder The placeholder to replace. 1236 * @returns {Array} Returns the new array of placeholder indexes. 1237 */ 1238 function replaceHolders(array, placeholder) { 1239 var index = -1, 1240 length = array.length, 1241 resIndex = 0, 1242 result = []; 1243 1244 while (++index < length) { 1245 var value = array[index]; 1246 if (value === placeholder || value === PLACEHOLDER) { 1247 array[index] = PLACEHOLDER; 1248 result[resIndex++] = index; 1249 } 1250 } 1251 return result; 1252 } 1253 1254 /** 1255 * Converts `set` to an array of its values. 1256 * 1257 * @private 1258 * @param {Object} set The set to convert. 1259 * @returns {Array} Returns the values. 1260 */ 1261 function setToArray(set) { 1262 var index = -1, 1263 result = Array(set.size); 1264 1265 set.forEach(function(value) { 1266 result[++index] = value; 1267 }); 1268 return result; 1269 } 1270 1271 /** 1272 * Converts `set` to its value-value pairs. 1273 * 1274 * @private 1275 * @param {Object} set The set to convert. 1276 * @returns {Array} Returns the value-value pairs. 1277 */ 1278 function setToPairs(set) { 1279 var index = -1, 1280 result = Array(set.size); 1281 1282 set.forEach(function(value) { 1283 result[++index] = [value, value]; 1284 }); 1285 return result; 1286 } 1287 1288 /** 1289 * A specialized version of `_.indexOf` which performs strict equality 1290 * comparisons of values, i.e. `===`. 1291 * 1292 * @private 1293 * @param {Array} array The array to inspect. 1294 * @param {*} value The value to search for. 1295 * @param {number} fromIndex The index to search from. 1296 * @returns {number} Returns the index of the matched value, else `-1`. 1297 */ 1298 function strictIndexOf(array, value, fromIndex) { 1299 var index = fromIndex - 1, 1300 length = array.length; 1301 1302 while (++index < length) { 1303 if (array[index] === value) { 1304 return index; 1305 } 1306 } 1307 return -1; 1308 } 1309 1310 /** 1311 * A specialized version of `_.lastIndexOf` which performs strict equality 1312 * comparisons of values, i.e. `===`. 1313 * 1314 * @private 1315 * @param {Array} array The array to inspect. 1316 * @param {*} value The value to search for. 1317 * @param {number} fromIndex The index to search from. 1318 * @returns {number} Returns the index of the matched value, else `-1`. 1319 */ 1320 function strictLastIndexOf(array, value, fromIndex) { 1321 var index = fromIndex + 1; 1322 while (index--) { 1323 if (array[index] === value) { 1324 return index; 1325 } 1326 } 1327 return index; 1328 } 1329 1330 /** 1331 * Gets the number of symbols in `string`. 1332 * 1333 * @private 1334 * @param {string} string The string to inspect. 1335 * @returns {number} Returns the string size. 1336 */ 1337 function stringSize(string) { 1338 return hasUnicode(string) 1339 ? unicodeSize(string) 1340 : asciiSize(string); 1341 } 1342 1343 /** 1344 * Converts `string` to an array. 1345 * 1346 * @private 1347 * @param {string} string The string to convert. 1348 * @returns {Array} Returns the converted array. 1349 */ 1350 function stringToArray(string) { 1351 return hasUnicode(string) 1352 ? unicodeToArray(string) 1353 : asciiToArray(string); 1354 } 1355 1356 /** 1357 * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace 1358 * character of `string`. 1359 * 1360 * @private 1361 * @param {string} string The string to inspect. 1362 * @returns {number} Returns the index of the last non-whitespace character. 1363 */ 1364 function trimmedEndIndex(string) { 1365 var index = string.length; 1366 1367 while (index-- && reWhitespace.test(string.charAt(index))) {} 1368 return index; 1369 } 1370 1371 /** 1372 * Used by `_.unescape` to convert HTML entities to characters. 1373 * 1374 * @private 1375 * @param {string} chr The matched character to unescape. 1376 * @returns {string} Returns the unescaped character. 1377 */ 1378 var unescapeHtmlChar = basePropertyOf(htmlUnescapes); 1379 1380 /** 1381 * Gets the size of a Unicode `string`. 1382 * 1383 * @private 1384 * @param {string} string The string inspect. 1385 * @returns {number} Returns the string size. 1386 */ 1387 function unicodeSize(string) { 1388 var result = reUnicode.lastIndex = 0; 1389 while (reUnicode.test(string)) { 1390 ++result; 1391 } 1392 return result; 1393 } 1394 1395 /** 1396 * Converts a Unicode `string` to an array. 1397 * 1398 * @private 1399 * @param {string} string The string to convert. 1400 * @returns {Array} Returns the converted array. 1401 */ 1402 function unicodeToArray(string) { 1403 return string.match(reUnicode) || []; 1404 } 1405 1406 /** 1407 * Splits a Unicode `string` into an array of its words. 1408 * 1409 * @private 1410 * @param {string} The string to inspect. 1411 * @returns {Array} Returns the words of `string`. 1412 */ 1413 function unicodeWords(string) { 1414 return string.match(reUnicodeWord) || []; 1415 } 1416 1417 /*--------------------------------------------------------------------------*/ 1418 1419 /** 1420 * Create a new pristine `lodash` function using the `context` object. 1421 * 1422 * @static 1423 * @memberOf _ 1424 * @since 1.1.0 1425 * @category Util 1426 * @param {Object} [context=root] The context object. 1427 * @returns {Function} Returns a new `lodash` function. 1428 * @example 1429 * 1430 * _.mixin({ 'foo': _.constant('foo') }); 1431 * 1432 * var lodash = _.runInContext(); 1433 * lodash.mixin({ 'bar': lodash.constant('bar') }); 1434 * 1435 * _.isFunction(_.foo); 1436 * // => true 1437 * _.isFunction(_.bar); 1438 * // => false 1439 * 1440 * lodash.isFunction(lodash.foo); 1441 * // => false 1442 * lodash.isFunction(lodash.bar); 1443 * // => true 1444 * 1445 * // Create a suped-up `defer` in Node.js. 1446 * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; 1447 */ 1448 var runInContext = (function runInContext(context) { 1449 context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps)); 1450 1451 /** Built-in constructor references. */ 1452 var Array = context.Array, 1453 Date = context.Date, 1454 Error = context.Error, 1455 Function = context.Function, 1456 Math = context.Math, 1457 Object = context.Object, 1458 RegExp = context.RegExp, 1459 String = context.String, 1460 TypeError = context.TypeError; 1461 1462 /** Used for built-in method references. */ 1463 var arrayProto = Array.prototype, 1464 funcProto = Function.prototype, 1465 objectProto = Object.prototype; 1466 1467 /** Used to detect overreaching core-js shims. */ 1468 var coreJsData = context['__core-js_shared__']; 1469 1470 /** Used to resolve the decompiled source of functions. */ 1471 var funcToString = funcProto.toString; 1472 1473 /** Used to check objects for own properties. */ 1474 var hasOwnProperty = objectProto.hasOwnProperty; 1475 1476 /** Used to generate unique IDs. */ 1477 var idCounter = 0; 1478 1479 /** Used to detect methods masquerading as native. */ 1480 var maskSrcKey = (function() { 1481 var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); 1482 return uid ? ('Symbol(src)_1.' + uid) : ''; 1483 }()); 1484 1485 /** 1486 * Used to resolve the 1487 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) 1488 * of values. 1489 */ 1490 var nativeObjectToString = objectProto.toString; 1491 1492 /** Used to infer the `Object` constructor. */ 1493 var objectCtorString = funcToString.call(Object); 1494 1495 /** Used to restore the original `_` reference in `_.noConflict`. */ 1496 var oldDash = root._; 1497 1498 /** Used to detect if a method is native. */ 1499 var reIsNative = RegExp('^' + 1500 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') 1501 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' 1502 ); 1503 1504 /** Built-in value references. */ 1505 var Buffer = moduleExports ? context.Buffer : undefined, 1506 Symbol = context.Symbol, 1507 Uint8Array = context.Uint8Array, 1508 allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined, 1509 getPrototype = overArg(Object.getPrototypeOf, Object), 1510 objectCreate = Object.create, 1511 propertyIsEnumerable = objectProto.propertyIsEnumerable, 1512 splice = arrayProto.splice, 1513 spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined, 1514 symIterator = Symbol ? Symbol.iterator : undefined, 1515 symToStringTag = Symbol ? Symbol.toStringTag : undefined; 1516 1517 var defineProperty = (function() { 1518 try { 1519 var func = getNative(Object, 'defineProperty'); 1520 func({}, '', {}); 1521 return func; 1522 } catch (e) {} 1523 }()); 1524 1525 /** Mocked built-ins. */ 1526 var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, 1527 ctxNow = Date && Date.now !== root.Date.now && Date.now, 1528 ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout; 1529 1530 /* Built-in method references for those with the same name as other `lodash` methods. */ 1531 var nativeCeil = Math.ceil, 1532 nativeFloor = Math.floor, 1533 nativeGetSymbols = Object.getOwnPropertySymbols, 1534 nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined, 1535 nativeIsFinite = context.isFinite, 1536 nativeJoin = arrayProto.join, 1537 nativeKeys = overArg(Object.keys, Object), 1538 nativeMax = Math.max, 1539 nativeMin = Math.min, 1540 nativeNow = Date.now, 1541 nativeParseInt = context.parseInt, 1542 nativeRandom = Math.random, 1543 nativeReverse = arrayProto.reverse; 1544 1545 /* Built-in method references that are verified to be native. */ 1546 var DataView = getNative(context, 'DataView'), 1547 Map = getNative(context, 'Map'), 1548 Promise = getNative(context, 'Promise'), 1549 Set = getNative(context, 'Set'), 1550 WeakMap = getNative(context, 'WeakMap'), 1551 nativeCreate = getNative(Object, 'create'); 1552 1553 /** Used to store function metadata. */ 1554 var metaMap = WeakMap && new WeakMap; 1555 1556 /** Used to lookup unminified function names. */ 1557 var realNames = {}; 1558 1559 /** Used to detect maps, sets, and weakmaps. */ 1560 var dataViewCtorString = toSource(DataView), 1561 mapCtorString = toSource(Map), 1562 promiseCtorString = toSource(Promise), 1563 setCtorString = toSource(Set), 1564 weakMapCtorString = toSource(WeakMap); 1565 1566 /** Used to convert symbols to primitives and strings. */ 1567 var symbolProto = Symbol ? Symbol.prototype : undefined, 1568 symbolValueOf = symbolProto ? symbolProto.valueOf : undefined, 1569 symbolToString = symbolProto ? symbolProto.toString : undefined; 1570 1571 /*------------------------------------------------------------------------*/ 1572 1573 /** 1574 * Creates a `lodash` object which wraps `value` to enable implicit method 1575 * chain sequences. Methods that operate on and return arrays, collections, 1576 * and functions can be chained together. Methods that retrieve a single value 1577 * or may return a primitive value will automatically end the chain sequence 1578 * and return the unwrapped value. Otherwise, the value must be unwrapped 1579 * with `_#value`. 1580 * 1581 * Explicit chain sequences, which must be unwrapped with `_#value`, may be 1582 * enabled using `_.chain`. 1583 * 1584 * The execution of chained methods is lazy, that is, it's deferred until 1585 * `_#value` is implicitly or explicitly called. 1586 * 1587 * Lazy evaluation allows several methods to support shortcut fusion. 1588 * Shortcut fusion is an optimization to merge iteratee calls; this avoids 1589 * the creation of intermediate arrays and can greatly reduce the number of 1590 * iteratee executions. Sections of a chain sequence qualify for shortcut 1591 * fusion if the section is applied to an array and iteratees accept only 1592 * one argument. The heuristic for whether a section qualifies for shortcut 1593 * fusion is subject to change. 1594 * 1595 * Chaining is supported in custom builds as long as the `_#value` method is 1596 * directly or indirectly included in the build. 1597 * 1598 * In addition to lodash methods, wrappers have `Array` and `String` methods. 1599 * 1600 * The wrapper `Array` methods are: 1601 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` 1602 * 1603 * The wrapper `String` methods are: 1604 * `replace` and `split` 1605 * 1606 * The wrapper methods that support shortcut fusion are: 1607 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, 1608 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, 1609 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` 1610 * 1611 * The chainable wrapper methods are: 1612 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, 1613 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, 1614 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, 1615 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, 1616 * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, 1617 * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, 1618 * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, 1619 * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, 1620 * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, 1621 * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, 1622 * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, 1623 * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, 1624 * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, 1625 * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, 1626 * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, 1627 * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, 1628 * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, 1629 * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, 1630 * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, 1631 * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, 1632 * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, 1633 * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, 1634 * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, 1635 * `zipObject`, `zipObjectDeep`, and `zipWith` 1636 * 1637 * The wrapper methods that are **not** chainable by default are: 1638 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, 1639 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, 1640 * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, 1641 * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, 1642 * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`, 1643 * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, 1644 * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, 1645 * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, 1646 * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, 1647 * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, 1648 * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, 1649 * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, 1650 * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, 1651 * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, 1652 * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, 1653 * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`, 1654 * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, 1655 * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, 1656 * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, 1657 * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`, 1658 * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`, 1659 * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`, 1660 * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, 1661 * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, 1662 * `upperFirst`, `value`, and `words` 1663 * 1664 * @name _ 1665 * @constructor 1666 * @category Seq 1667 * @param {*} value The value to wrap in a `lodash` instance. 1668 * @returns {Object} Returns the new `lodash` wrapper instance. 1669 * @example 1670 * 1671 * function square(n) { 1672 * return n * n; 1673 * } 1674 * 1675 * var wrapped = _([1, 2, 3]); 1676 * 1677 * // Returns an unwrapped value. 1678 * wrapped.reduce(_.add); 1679 * // => 6 1680 * 1681 * // Returns a wrapped value. 1682 * var squares = wrapped.map(square); 1683 * 1684 * _.isArray(squares); 1685 * // => false 1686 * 1687 * _.isArray(squares.value()); 1688 * // => true 1689 */ 1690 function lodash(value) { 1691 if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { 1692 if (value instanceof LodashWrapper) { 1693 return value; 1694 } 1695 if (hasOwnProperty.call(value, '__wrapped__')) { 1696 return wrapperClone(value); 1697 } 1698 } 1699 return new LodashWrapper(value); 1700 } 1701 1702 /** 1703 * The base implementation of `_.create` without support for assigning 1704 * properties to the created object. 1705 * 1706 * @private 1707 * @param {Object} proto The object to inherit from. 1708 * @returns {Object} Returns the new object. 1709 */ 1710 var baseCreate = (function() { 1711 function object() {} 1712 return function(proto) { 1713 if (!isObject(proto)) { 1714 return {}; 1715 } 1716 if (objectCreate) { 1717 return objectCreate(proto); 1718 } 1719 object.prototype = proto; 1720 var result = new object; 1721 object.prototype = undefined; 1722 return result; 1723 }; 1724 }()); 1725 1726 /** 1727 * The function whose prototype chain sequence wrappers inherit from. 1728 * 1729 * @private 1730 */ 1731 function baseLodash() { 1732 // No operation performed. 1733 } 1734 1735 /** 1736 * The base constructor for creating `lodash` wrapper objects. 1737 * 1738 * @private 1739 * @param {*} value The value to wrap. 1740 * @param {boolean} [chainAll] Enable explicit method chain sequences. 1741 */ 1742 function LodashWrapper(value, chainAll) { 1743 this.__wrapped__ = value; 1744 this.__actions__ = []; 1745 this.__chain__ = !!chainAll; 1746 this.__index__ = 0; 1747 this.__values__ = undefined; 1748 } 1749 1750 /** 1751 * By default, the template delimiters used by lodash are like those in 1752 * embedded Ruby (ERB) as well as ES2015 template strings. Change the 1753 * following template settings to use alternative delimiters. 1754 * 1755 * @static 1756 * @memberOf _ 1757 * @type {Object} 1758 */ 1759 lodash.templateSettings = { 1760 1761 /** 1762 * Used to detect `data` property values to be HTML-escaped. 1763 * 1764 * @memberOf _.templateSettings 1765 * @type {RegExp} 1766 */ 1767 'escape': reEscape, 1768 1769 /** 1770 * Used to detect code to be evaluated. 1771 * 1772 * @memberOf _.templateSettings 1773 * @type {RegExp} 1774 */ 1775 'evaluate': reEvaluate, 1776 1777 /** 1778 * Used to detect `data` property values to inject. 1779 * 1780 * @memberOf _.templateSettings 1781 * @type {RegExp} 1782 */ 1783 'interpolate': reInterpolate, 1784 1785 /** 1786 * Used to reference the data object in the template text. 1787 * 1788 * @memberOf _.templateSettings 1789 * @type {string} 1790 */ 1791 'variable': '', 1792 1793 /** 1794 * Used to import variables into the compiled template. 1795 * 1796 * @memberOf _.templateSettings 1797 * @type {Object} 1798 */ 1799 'imports': { 1800 1801 /** 1802 * A reference to the `lodash` function. 1803 * 1804 * @memberOf _.templateSettings.imports 1805 * @type {Function} 1806 */ 1807 '_': lodash 1808 } 1809 }; 1810 1811 // Ensure wrappers are instances of `baseLodash`. 1812 lodash.prototype = baseLodash.prototype; 1813 lodash.prototype.constructor = lodash; 1814 1815 LodashWrapper.prototype = baseCreate(baseLodash.prototype); 1816 LodashWrapper.prototype.constructor = LodashWrapper; 1817 1818 /*------------------------------------------------------------------------*/ 1819 1820 /** 1821 * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. 1822 * 1823 * @private 1824 * @constructor 1825 * @param {*} value The value to wrap. 1826 */ 1827 function LazyWrapper(value) { 1828 this.__wrapped__ = value; 1829 this.__actions__ = []; 1830 this.__dir__ = 1; 1831 this.__filtered__ = false; 1832 this.__iteratees__ = []; 1833 this.__takeCount__ = MAX_ARRAY_LENGTH; 1834 this.__views__ = []; 1835 } 1836 1837 /** 1838 * Creates a clone of the lazy wrapper object. 1839 * 1840 * @private 1841 * @name clone 1842 * @memberOf LazyWrapper 1843 * @returns {Object} Returns the cloned `LazyWrapper` object. 1844 */ 1845 function lazyClone() { 1846 var result = new LazyWrapper(this.__wrapped__); 1847 result.__actions__ = copyArray(this.__actions__); 1848 result.__dir__ = this.__dir__; 1849 result.__filtered__ = this.__filtered__; 1850 result.__iteratees__ = copyArray(this.__iteratees__); 1851 result.__takeCount__ = this.__takeCount__; 1852 result.__views__ = copyArray(this.__views__); 1853 return result; 1854 } 1855 1856 /** 1857 * Reverses the direction of lazy iteration. 1858 * 1859 * @private 1860 * @name reverse 1861 * @memberOf LazyWrapper 1862 * @returns {Object} Returns the new reversed `LazyWrapper` object. 1863 */ 1864 function lazyReverse() { 1865 if (this.__filtered__) { 1866 var result = new LazyWrapper(this); 1867 result.__dir__ = -1; 1868 result.__filtered__ = true; 1869 } else { 1870 result = this.clone(); 1871 result.__dir__ *= -1; 1872 } 1873 return result; 1874 } 1875 1876 /** 1877 * Extracts the unwrapped value from its lazy wrapper. 1878 * 1879 * @private 1880 * @name value 1881 * @memberOf LazyWrapper 1882 * @returns {*} Returns the unwrapped value. 1883 */ 1884 function lazyValue() { 1885 var array = this.__wrapped__.value(), 1886 dir = this.__dir__, 1887 isArr = isArray(array), 1888 isRight = dir < 0, 1889 arrLength = isArr ? array.length : 0, 1890 view = getView(0, arrLength, this.__views__), 1891 start = view.start, 1892 end = view.end, 1893 length = end - start, 1894 index = isRight ? end : (start - 1), 1895 iteratees = this.__iteratees__, 1896 iterLength = iteratees.length, 1897 resIndex = 0, 1898 takeCount = nativeMin(length, this.__takeCount__); 1899 1900 if (!isArr || (!isRight && arrLength == length && takeCount == length)) { 1901 return baseWrapperValue(array, this.__actions__); 1902 } 1903 var result = []; 1904 1905 outer: 1906 while (length-- && resIndex < takeCount) { 1907 index += dir; 1908 1909 var iterIndex = -1, 1910 value = array[index]; 1911 1912 while (++iterIndex < iterLength) { 1913 var data = iteratees[iterIndex], 1914 iteratee = data.iteratee, 1915 type = data.type, 1916 computed = iteratee(value); 1917 1918 if (type == LAZY_MAP_FLAG) { 1919 value = computed; 1920 } else if (!computed) { 1921 if (type == LAZY_FILTER_FLAG) { 1922 continue outer; 1923 } else { 1924 break outer; 1925 } 1926 } 1927 } 1928 result[resIndex++] = value; 1929 } 1930 return result; 1931 } 1932 1933 // Ensure `LazyWrapper` is an instance of `baseLodash`. 1934 LazyWrapper.prototype = baseCreate(baseLodash.prototype); 1935 LazyWrapper.prototype.constructor = LazyWrapper; 1936 1937 /*------------------------------------------------------------------------*/ 1938 1939 /** 1940 * Creates a hash object. 1941 * 1942 * @private 1943 * @constructor 1944 * @param {Array} [entries] The key-value pairs to cache. 1945 */ 1946 function Hash(entries) { 1947 var index = -1, 1948 length = entries == null ? 0 : entries.length; 1949 1950 this.clear(); 1951 while (++index < length) { 1952 var entry = entries[index]; 1953 this.set(entry[0], entry[1]); 1954 } 1955 } 1956 1957 /** 1958 * Removes all key-value entries from the hash. 1959 * 1960 * @private 1961 * @name clear 1962 * @memberOf Hash 1963 */ 1964 function hashClear() { 1965 this.__data__ = nativeCreate ? nativeCreate(null) : {}; 1966 this.size = 0; 1967 } 1968 1969 /** 1970 * Removes `key` and its value from the hash. 1971 * 1972 * @private 1973 * @name delete 1974 * @memberOf Hash 1975 * @param {Object} hash The hash to modify. 1976 * @param {string} key The key of the value to remove. 1977 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 1978 */ 1979 function hashDelete(key) { 1980 var result = this.has(key) && delete this.__data__[key]; 1981 this.size -= result ? 1 : 0; 1982 return result; 1983 } 1984 1985 /** 1986 * Gets the hash value for `key`. 1987 * 1988 * @private 1989 * @name get 1990 * @memberOf Hash 1991 * @param {string} key The key of the value to get. 1992 * @returns {*} Returns the entry value. 1993 */ 1994 function hashGet(key) { 1995 var data = this.__data__; 1996 if (nativeCreate) { 1997 var result = data[key]; 1998 return result === HASH_UNDEFINED ? undefined : result; 1999 } 2000 return hasOwnProperty.call(data, key) ? data[key] : undefined; 2001 } 2002 2003 /** 2004 * Checks if a hash value for `key` exists. 2005 * 2006 * @private 2007 * @name has 2008 * @memberOf Hash 2009 * @param {string} key The key of the entry to check. 2010 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 2011 */ 2012 function hashHas(key) { 2013 var data = this.__data__; 2014 return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key); 2015 } 2016 2017 /** 2018 * Sets the hash `key` to `value`. 2019 * 2020 * @private 2021 * @name set 2022 * @memberOf Hash 2023 * @param {string} key The key of the value to set. 2024 * @param {*} value The value to set. 2025 * @returns {Object} Returns the hash instance. 2026 */ 2027 function hashSet(key, value) { 2028 var data = this.__data__; 2029 this.size += this.has(key) ? 0 : 1; 2030 data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; 2031 return this; 2032 } 2033 2034 // Add methods to `Hash`. 2035 Hash.prototype.clear = hashClear; 2036 Hash.prototype['delete'] = hashDelete; 2037 Hash.prototype.get = hashGet; 2038 Hash.prototype.has = hashHas; 2039 Hash.prototype.set = hashSet; 2040 2041 /*------------------------------------------------------------------------*/ 2042 2043 /** 2044 * Creates an list cache object. 2045 * 2046 * @private 2047 * @constructor 2048 * @param {Array} [entries] The key-value pairs to cache. 2049 */ 2050 function ListCache(entries) { 2051 var index = -1, 2052 length = entries == null ? 0 : entries.length; 2053 2054 this.clear(); 2055 while (++index < length) { 2056 var entry = entries[index]; 2057 this.set(entry[0], entry[1]); 2058 } 2059 } 2060 2061 /** 2062 * Removes all key-value entries from the list cache. 2063 * 2064 * @private 2065 * @name clear 2066 * @memberOf ListCache 2067 */ 2068 function listCacheClear() { 2069 this.__data__ = []; 2070 this.size = 0; 2071 } 2072 2073 /** 2074 * Removes `key` and its value from the list cache. 2075 * 2076 * @private 2077 * @name delete 2078 * @memberOf ListCache 2079 * @param {string} key The key of the value to remove. 2080 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 2081 */ 2082 function listCacheDelete(key) { 2083 var data = this.__data__, 2084 index = assocIndexOf(data, key); 2085 2086 if (index < 0) { 2087 return false; 2088 } 2089 var lastIndex = data.length - 1; 2090 if (index == lastIndex) { 2091 data.pop(); 2092 } else { 2093 splice.call(data, index, 1); 2094 } 2095 --this.size; 2096 return true; 2097 } 2098 2099 /** 2100 * Gets the list cache value for `key`. 2101 * 2102 * @private 2103 * @name get 2104 * @memberOf ListCache 2105 * @param {string} key The key of the value to get. 2106 * @returns {*} Returns the entry value. 2107 */ 2108 function listCacheGet(key) { 2109 var data = this.__data__, 2110 index = assocIndexOf(data, key); 2111 2112 return index < 0 ? undefined : data[index][1]; 2113 } 2114 2115 /** 2116 * Checks if a list cache value for `key` exists. 2117 * 2118 * @private 2119 * @name has 2120 * @memberOf ListCache 2121 * @param {string} key The key of the entry to check. 2122 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 2123 */ 2124 function listCacheHas(key) { 2125 return assocIndexOf(this.__data__, key) > -1; 2126 } 2127 2128 /** 2129 * Sets the list cache `key` to `value`. 2130 * 2131 * @private 2132 * @name set 2133 * @memberOf ListCache 2134 * @param {string} key The key of the value to set. 2135 * @param {*} value The value to set. 2136 * @returns {Object} Returns the list cache instance. 2137 */ 2138 function listCacheSet(key, value) { 2139 var data = this.__data__, 2140 index = assocIndexOf(data, key); 2141 2142 if (index < 0) { 2143 ++this.size; 2144 data.push([key, value]); 2145 } else { 2146 data[index][1] = value; 2147 } 2148 return this; 2149 } 2150 2151 // Add methods to `ListCache`. 2152 ListCache.prototype.clear = listCacheClear; 2153 ListCache.prototype['delete'] = listCacheDelete; 2154 ListCache.prototype.get = listCacheGet; 2155 ListCache.prototype.has = listCacheHas; 2156 ListCache.prototype.set = listCacheSet; 2157 2158 /*------------------------------------------------------------------------*/ 2159 2160 /** 2161 * Creates a map cache object to store key-value pairs. 2162 * 2163 * @private 2164 * @constructor 2165 * @param {Array} [entries] The key-value pairs to cache. 2166 */ 2167 function MapCache(entries) { 2168 var index = -1, 2169 length = entries == null ? 0 : entries.length; 2170 2171 this.clear(); 2172 while (++index < length) { 2173 var entry = entries[index]; 2174 this.set(entry[0], entry[1]); 2175 } 2176 } 2177 2178 /** 2179 * Removes all key-value entries from the map. 2180 * 2181 * @private 2182 * @name clear 2183 * @memberOf MapCache 2184 */ 2185 function mapCacheClear() { 2186 this.size = 0; 2187 this.__data__ = { 2188 'hash': new Hash, 2189 'map': new (Map || ListCache), 2190 'string': new Hash 2191 }; 2192 } 2193 2194 /** 2195 * Removes `key` and its value from the map. 2196 * 2197 * @private 2198 * @name delete 2199 * @memberOf MapCache 2200 * @param {string} key The key of the value to remove. 2201 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 2202 */ 2203 function mapCacheDelete(key) { 2204 var result = getMapData(this, key)['delete'](key); 2205 this.size -= result ? 1 : 0; 2206 return result; 2207 } 2208 2209 /** 2210 * Gets the map value for `key`. 2211 * 2212 * @private 2213 * @name get 2214 * @memberOf MapCache 2215 * @param {string} key The key of the value to get. 2216 * @returns {*} Returns the entry value. 2217 */ 2218 function mapCacheGet(key) { 2219 return getMapData(this, key).get(key); 2220 } 2221 2222 /** 2223 * Checks if a map value for `key` exists. 2224 * 2225 * @private 2226 * @name has 2227 * @memberOf MapCache 2228 * @param {string} key The key of the entry to check. 2229 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 2230 */ 2231 function mapCacheHas(key) { 2232 return getMapData(this, key).has(key); 2233 } 2234 2235 /** 2236 * Sets the map `key` to `value`. 2237 * 2238 * @private 2239 * @name set 2240 * @memberOf MapCache 2241 * @param {string} key The key of the value to set. 2242 * @param {*} value The value to set. 2243 * @returns {Object} Returns the map cache instance. 2244 */ 2245 function mapCacheSet(key, value) { 2246 var data = getMapData(this, key), 2247 size = data.size; 2248 2249 data.set(key, value); 2250 this.size += data.size == size ? 0 : 1; 2251 return this; 2252 } 2253 2254 // Add methods to `MapCache`. 2255 MapCache.prototype.clear = mapCacheClear; 2256 MapCache.prototype['delete'] = mapCacheDelete; 2257 MapCache.prototype.get = mapCacheGet; 2258 MapCache.prototype.has = mapCacheHas; 2259 MapCache.prototype.set = mapCacheSet; 2260 2261 /*------------------------------------------------------------------------*/ 2262 2263 /** 2264 * 2265 * Creates an array cache object to store unique values. 2266 * 2267 * @private 2268 * @constructor 2269 * @param {Array} [values] The values to cache. 2270 */ 2271 function SetCache(values) { 2272 var index = -1, 2273 length = values == null ? 0 : values.length; 2274 2275 this.__data__ = new MapCache; 2276 while (++index < length) { 2277 this.add(values[index]); 2278 } 2279 } 2280 2281 /** 2282 * Adds `value` to the array cache. 2283 * 2284 * @private 2285 * @name add 2286 * @memberOf SetCache 2287 * @alias push 2288 * @param {*} value The value to cache. 2289 * @returns {Object} Returns the cache instance. 2290 */ 2291 function setCacheAdd(value) { 2292 this.__data__.set(value, HASH_UNDEFINED); 2293 return this; 2294 } 2295 2296 /** 2297 * Checks if `value` is in the array cache. 2298 * 2299 * @private 2300 * @name has 2301 * @memberOf SetCache 2302 * @param {*} value The value to search for. 2303 * @returns {number} Returns `true` if `value` is found, else `false`. 2304 */ 2305 function setCacheHas(value) { 2306 return this.__data__.has(value); 2307 } 2308 2309 // Add methods to `SetCache`. 2310 SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; 2311 SetCache.prototype.has = setCacheHas; 2312 2313 /*------------------------------------------------------------------------*/ 2314 2315 /** 2316 * Creates a stack cache object to store key-value pairs. 2317 * 2318 * @private 2319 * @constructor 2320 * @param {Array} [entries] The key-value pairs to cache. 2321 */ 2322 function Stack(entries) { 2323 var data = this.__data__ = new ListCache(entries); 2324 this.size = data.size; 2325 } 2326 2327 /** 2328 * Removes all key-value entries from the stack. 2329 * 2330 * @private 2331 * @name clear 2332 * @memberOf Stack 2333 */ 2334 function stackClear() { 2335 this.__data__ = new ListCache; 2336 this.size = 0; 2337 } 2338 2339 /** 2340 * Removes `key` and its value from the stack. 2341 * 2342 * @private 2343 * @name delete 2344 * @memberOf Stack 2345 * @param {string} key The key of the value to remove. 2346 * @returns {boolean} Returns `true` if the entry was removed, else `false`. 2347 */ 2348 function stackDelete(key) { 2349 var data = this.__data__, 2350 result = data['delete'](key); 2351 2352 this.size = data.size; 2353 return result; 2354 } 2355 2356 /** 2357 * Gets the stack value for `key`. 2358 * 2359 * @private 2360 * @name get 2361 * @memberOf Stack 2362 * @param {string} key The key of the value to get. 2363 * @returns {*} Returns the entry value. 2364 */ 2365 function stackGet(key) { 2366 return this.__data__.get(key); 2367 } 2368 2369 /** 2370 * Checks if a stack value for `key` exists. 2371 * 2372 * @private 2373 * @name has 2374 * @memberOf Stack 2375 * @param {string} key The key of the entry to check. 2376 * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 2377 */ 2378 function stackHas(key) { 2379 return this.__data__.has(key); 2380 } 2381 2382 /** 2383 * Sets the stack `key` to `value`. 2384 * 2385 * @private 2386 * @name set 2387 * @memberOf Stack 2388 * @param {string} key The key of the value to set. 2389 * @param {*} value The value to set. 2390 * @returns {Object} Returns the stack cache instance. 2391 */ 2392 function stackSet(key, value) { 2393 var data = this.__data__; 2394 if (data instanceof ListCache) { 2395 var pairs = data.__data__; 2396 if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { 2397 pairs.push([key, value]); 2398 this.size = ++data.size; 2399 return this; 2400 } 2401 data = this.__data__ = new MapCache(pairs); 2402 } 2403 data.set(key, value); 2404 this.size = data.size; 2405 return this; 2406 } 2407 2408 // Add methods to `Stack`. 2409 Stack.prototype.clear = stackClear; 2410 Stack.prototype['delete'] = stackDelete; 2411 Stack.prototype.get = stackGet; 2412 Stack.prototype.has = stackHas; 2413 Stack.prototype.set = stackSet; 2414 2415 /*------------------------------------------------------------------------*/ 2416 2417 /** 2418 * Creates an array of the enumerable property names of the array-like `value`. 2419 * 2420 * @private 2421 * @param {*} value The value to query. 2422 * @param {boolean} inherited Specify returning inherited property names. 2423 * @returns {Array} Returns the array of property names. 2424 */ 2425 function arrayLikeKeys(value, inherited) { 2426 var isArr = isArray(value), 2427 isArg = !isArr && isArguments(value), 2428 isBuff = !isArr && !isArg && isBuffer(value), 2429 isType = !isArr && !isArg && !isBuff && isTypedArray(value), 2430 skipIndexes = isArr || isArg || isBuff || isType, 2431 result = skipIndexes ? baseTimes(value.length, String) : [], 2432 length = result.length; 2433 2434 for (var key in value) { 2435 if ((inherited || hasOwnProperty.call(value, key)) && 2436 !(skipIndexes && ( 2437 // Safari 9 has enumerable `arguments.length` in strict mode. 2438 key == 'length' || 2439 // Node.js 0.10 has enumerable non-index properties on buffers. 2440 (isBuff && (key == 'offset' || key == 'parent')) || 2441 // PhantomJS 2 has enumerable non-index properties on typed arrays. 2442 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || 2443 // Skip index properties. 2444 isIndex(key, length) 2445 ))) { 2446 result.push(key); 2447 } 2448 } 2449 return result; 2450 } 2451 2452 /** 2453 * A specialized version of `_.sample` for arrays. 2454 * 2455 * @private 2456 * @param {Array} array The array to sample. 2457 * @returns {*} Returns the random element. 2458 */ 2459 function arraySample(array) { 2460 var length = array.length; 2461 return length ? array[baseRandom(0, length - 1)] : undefined; 2462 } 2463 2464 /** 2465 * A specialized version of `_.sampleSize` for arrays. 2466 * 2467 * @private 2468 * @param {Array} array The array to sample. 2469 * @param {number} n The number of elements to sample. 2470 * @returns {Array} Returns the random elements. 2471 */ 2472 function arraySampleSize(array, n) { 2473 return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); 2474 } 2475 2476 /** 2477 * A specialized version of `_.shuffle` for arrays. 2478 * 2479 * @private 2480 * @param {Array} array The array to shuffle. 2481 * @returns {Array} Returns the new shuffled array. 2482 */ 2483 function arrayShuffle(array) { 2484 return shuffleSelf(copyArray(array)); 2485 } 2486 2487 /** 2488 * This function is like `assignValue` except that it doesn't assign 2489 * `undefined` values. 2490 * 2491 * @private 2492 * @param {Object} object The object to modify. 2493 * @param {string} key The key of the property to assign. 2494 * @param {*} value The value to assign. 2495 */ 2496 function assignMergeValue(object, key, value) { 2497 if ((value !== undefined && !eq(object[key], value)) || 2498 (value === undefined && !(key in object))) { 2499 baseAssignValue(object, key, value); 2500 } 2501 } 2502 2503 /** 2504 * Assigns `value` to `key` of `object` if the existing value is not equivalent 2505 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 2506 * for equality comparisons. 2507 * 2508 * @private 2509 * @param {Object} object The object to modify. 2510 * @param {string} key The key of the property to assign. 2511 * @param {*} value The value to assign. 2512 */ 2513 function assignValue(object, key, value) { 2514 var objValue = object[key]; 2515 if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || 2516 (value === undefined && !(key in object))) { 2517 baseAssignValue(object, key, value); 2518 } 2519 } 2520 2521 /** 2522 * Gets the index at which the `key` is found in `array` of key-value pairs. 2523 * 2524 * @private 2525 * @param {Array} array The array to inspect. 2526 * @param {*} key The key to search for. 2527 * @returns {number} Returns the index of the matched value, else `-1`. 2528 */ 2529 function assocIndexOf(array, key) { 2530 var length = array.length; 2531 while (length--) { 2532 if (eq(array[length][0], key)) { 2533 return length; 2534 } 2535 } 2536 return -1; 2537 } 2538 2539 /** 2540 * Aggregates elements of `collection` on `accumulator` with keys transformed 2541 * by `iteratee` and values set by `setter`. 2542 * 2543 * @private 2544 * @param {Array|Object} collection The collection to iterate over. 2545 * @param {Function} setter The function to set `accumulator` values. 2546 * @param {Function} iteratee The iteratee to transform keys. 2547 * @param {Object} accumulator The initial aggregated object. 2548 * @returns {Function} Returns `accumulator`. 2549 */ 2550 function baseAggregator(collection, setter, iteratee, accumulator) { 2551 baseEach(collection, function(value, key, collection) { 2552 setter(accumulator, value, iteratee(value), collection); 2553 }); 2554 return accumulator; 2555 } 2556 2557 /** 2558 * The base implementation of `_.assign` without support for multiple sources 2559 * or `customizer` functions. 2560 * 2561 * @private 2562 * @param {Object} object The destination object. 2563 * @param {Object} source The source object. 2564 * @returns {Object} Returns `object`. 2565 */ 2566 function baseAssign(object, source) { 2567 return object && copyObject(source, keys(source), object); 2568 } 2569 2570 /** 2571 * The base implementation of `_.assignIn` without support for multiple sources 2572 * or `customizer` functions. 2573 * 2574 * @private 2575 * @param {Object} object The destination object. 2576 * @param {Object} source The source object. 2577 * @returns {Object} Returns `object`. 2578 */ 2579 function baseAssignIn(object, source) { 2580 return object && copyObject(source, keysIn(source), object); 2581 } 2582 2583 /** 2584 * The base implementation of `assignValue` and `assignMergeValue` without 2585 * value checks. 2586 * 2587 * @private 2588 * @param {Object} object The object to modify. 2589 * @param {string} key The key of the property to assign. 2590 * @param {*} value The value to assign. 2591 */ 2592 function baseAssignValue(object, key, value) { 2593 if (key == '__proto__' && defineProperty) { 2594 defineProperty(object, key, { 2595 'configurable': true, 2596 'enumerable': true, 2597 'value': value, 2598 'writable': true 2599 }); 2600 } else { 2601 object[key] = value; 2602 } 2603 } 2604 2605 /** 2606 * The base implementation of `_.at` without support for individual paths. 2607 * 2608 * @private 2609 * @param {Object} object The object to iterate over. 2610 * @param {string[]} paths The property paths to pick. 2611 * @returns {Array} Returns the picked elements. 2612 */ 2613 function baseAt(object, paths) { 2614 var index = -1, 2615 length = paths.length, 2616 result = Array(length), 2617 skip = object == null; 2618 2619 while (++index < length) { 2620 result[index] = skip ? undefined : get(object, paths[index]); 2621 } 2622 return result; 2623 } 2624 2625 /** 2626 * The base implementation of `_.clamp` which doesn't coerce arguments. 2627 * 2628 * @private 2629 * @param {number} number The number to clamp. 2630 * @param {number} [lower] The lower bound. 2631 * @param {number} upper The upper bound. 2632 * @returns {number} Returns the clamped number. 2633 */ 2634 function baseClamp(number, lower, upper) { 2635 if (number === number) { 2636 if (upper !== undefined) { 2637 number = number <= upper ? number : upper; 2638 } 2639 if (lower !== undefined) { 2640 number = number >= lower ? number : lower; 2641 } 2642 } 2643 return number; 2644 } 2645 2646 /** 2647 * The base implementation of `_.clone` and `_.cloneDeep` which tracks 2648 * traversed objects. 2649 * 2650 * @private 2651 * @param {*} value The value to clone. 2652 * @param {boolean} bitmask The bitmask flags. 2653 * 1 - Deep clone 2654 * 2 - Flatten inherited properties 2655 * 4 - Clone symbols 2656 * @param {Function} [customizer] The function to customize cloning. 2657 * @param {string} [key] The key of `value`. 2658 * @param {Object} [object] The parent object of `value`. 2659 * @param {Object} [stack] Tracks traversed objects and their clone counterparts. 2660 * @returns {*} Returns the cloned value. 2661 */ 2662 function baseClone(value, bitmask, customizer, key, object, stack) { 2663 var result, 2664 isDeep = bitmask & CLONE_DEEP_FLAG, 2665 isFlat = bitmask & CLONE_FLAT_FLAG, 2666 isFull = bitmask & CLONE_SYMBOLS_FLAG; 2667 2668 if (customizer) { 2669 result = object ? customizer(value, key, object, stack) : customizer(value); 2670 } 2671 if (result !== undefined) { 2672 return result; 2673 } 2674 if (!isObject(value)) { 2675 return value; 2676 } 2677 var isArr = isArray(value); 2678 if (isArr) { 2679 result = initCloneArray(value); 2680 if (!isDeep) { 2681 return copyArray(value, result); 2682 } 2683 } else { 2684 var tag = getTag(value), 2685 isFunc = tag == funcTag || tag == genTag; 2686 2687 if (isBuffer(value)) { 2688 return cloneBuffer(value, isDeep); 2689 } 2690 if (tag == objectTag || tag == argsTag || (isFunc && !object)) { 2691 result = (isFlat || isFunc) ? {} : initCloneObject(value); 2692 if (!isDeep) { 2693 return isFlat 2694 ? copySymbolsIn(value, baseAssignIn(result, value)) 2695 : copySymbols(value, baseAssign(result, value)); 2696 } 2697 } else { 2698 if (!cloneableTags[tag]) { 2699 return object ? value : {}; 2700 } 2701 result = initCloneByTag(value, tag, isDeep); 2702 } 2703 } 2704 // Check for circular references and return its corresponding clone. 2705 stack || (stack = new Stack); 2706 var stacked = stack.get(value); 2707 if (stacked) { 2708 return stacked; 2709 } 2710 stack.set(value, result); 2711 2712 if (isSet(value)) { 2713 value.forEach(function(subValue) { 2714 result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)); 2715 }); 2716 } else if (isMap(value)) { 2717 value.forEach(function(subValue, key) { 2718 result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)); 2719 }); 2720 } 2721 2722 var keysFunc = isFull 2723 ? (isFlat ? getAllKeysIn : getAllKeys) 2724 : (isFlat ? keysIn : keys); 2725 2726 var props = isArr ? undefined : keysFunc(value); 2727 arrayEach(props || value, function(subValue, key) { 2728 if (props) { 2729 key = subValue; 2730 subValue = value[key]; 2731 } 2732 // Recursively populate clone (susceptible to call stack limits). 2733 assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack)); 2734 }); 2735 return result; 2736 } 2737 2738 /** 2739 * The base implementation of `_.conforms` which doesn't clone `source`. 2740 * 2741 * @private 2742 * @param {Object} source The object of property predicates to conform to. 2743 * @returns {Function} Returns the new spec function. 2744 */ 2745 function baseConforms(source) { 2746 var props = keys(source); 2747 return function(object) { 2748 return baseConformsTo(object, source, props); 2749 }; 2750 } 2751 2752 /** 2753 * The base implementation of `_.conformsTo` which accepts `props` to check. 2754 * 2755 * @private 2756 * @param {Object} object The object to inspect. 2757 * @param {Object} source The object of property predicates to conform to. 2758 * @returns {boolean} Returns `true` if `object` conforms, else `false`. 2759 */ 2760 function baseConformsTo(object, source, props) { 2761 var length = props.length; 2762 if (object == null) { 2763 return !length; 2764 } 2765 object = Object(object); 2766 while (length--) { 2767 var key = props[length], 2768 predicate = source[key], 2769 value = object[key]; 2770 2771 if ((value === undefined && !(key in object)) || !predicate(value)) { 2772 return false; 2773 } 2774 } 2775 return true; 2776 } 2777 2778 /** 2779 * The base implementation of `_.delay` and `_.defer` which accepts `args` 2780 * to provide to `func`. 2781 * 2782 * @private 2783 * @param {Function} func The function to delay. 2784 * @param {number} wait The number of milliseconds to delay invocation. 2785 * @param {Array} args The arguments to provide to `func`. 2786 * @returns {number|Object} Returns the timer id or timeout object. 2787 */ 2788 function baseDelay(func, wait, args) { 2789 if (typeof func != 'function') { 2790 throw new TypeError(FUNC_ERROR_TEXT); 2791 } 2792 return setTimeout(function() { func.apply(undefined, args); }, wait); 2793 } 2794 2795 /** 2796 * The base implementation of methods like `_.difference` without support 2797 * for excluding multiple arrays or iteratee shorthands. 2798 * 2799 * @private 2800 * @param {Array} array The array to inspect. 2801 * @param {Array} values The values to exclude. 2802 * @param {Function} [iteratee] The iteratee invoked per element. 2803 * @param {Function} [comparator] The comparator invoked per element. 2804 * @returns {Array} Returns the new array of filtered values. 2805 */ 2806 function baseDifference(array, values, iteratee, comparator) { 2807 var index = -1, 2808 includes = arrayIncludes, 2809 isCommon = true, 2810 length = array.length, 2811 result = [], 2812 valuesLength = values.length; 2813 2814 if (!length) { 2815 return result; 2816 } 2817 if (iteratee) { 2818 values = arrayMap(values, baseUnary(iteratee)); 2819 } 2820 if (comparator) { 2821 includes = arrayIncludesWith; 2822 isCommon = false; 2823 } 2824 else if (values.length >= LARGE_ARRAY_SIZE) { 2825 includes = cacheHas; 2826 isCommon = false; 2827 values = new SetCache(values); 2828 } 2829 outer: 2830 while (++index < length) { 2831 var value = array[index], 2832 computed = iteratee == null ? value : iteratee(value); 2833 2834 value = (comparator || value !== 0) ? value : 0; 2835 if (isCommon && computed === computed) { 2836 var valuesIndex = valuesLength; 2837 while (valuesIndex--) { 2838 if (values[valuesIndex] === computed) { 2839 continue outer; 2840 } 2841 } 2842 result.push(value); 2843 } 2844 else if (!includes(values, computed, comparator)) { 2845 result.push(value); 2846 } 2847 } 2848 return result; 2849 } 2850 2851 /** 2852 * The base implementation of `_.forEach` without support for iteratee shorthands. 2853 * 2854 * @private 2855 * @param {Array|Object} collection The collection to iterate over. 2856 * @param {Function} iteratee The function invoked per iteration. 2857 * @returns {Array|Object} Returns `collection`. 2858 */ 2859 var baseEach = createBaseEach(baseForOwn); 2860 2861 /** 2862 * The base implementation of `_.forEachRight` without support for iteratee shorthands. 2863 * 2864 * @private 2865 * @param {Array|Object} collection The collection to iterate over. 2866 * @param {Function} iteratee The function invoked per iteration. 2867 * @returns {Array|Object} Returns `collection`. 2868 */ 2869 var baseEachRight = createBaseEach(baseForOwnRight, true); 2870 2871 /** 2872 * The base implementation of `_.every` without support for iteratee shorthands. 2873 * 2874 * @private 2875 * @param {Array|Object} collection The collection to iterate over. 2876 * @param {Function} predicate The function invoked per iteration. 2877 * @returns {boolean} Returns `true` if all elements pass the predicate check, 2878 * else `false` 2879 */ 2880 function baseEvery(collection, predicate) { 2881 var result = true; 2882 baseEach(collection, function(value, index, collection) { 2883 result = !!predicate(value, index, collection); 2884 return result; 2885 }); 2886 return result; 2887 } 2888 2889 /** 2890 * The base implementation of methods like `_.max` and `_.min` which accepts a 2891 * `comparator` to determine the extremum value. 2892 * 2893 * @private 2894 * @param {Array} array The array to iterate over. 2895 * @param {Function} iteratee The iteratee invoked per iteration. 2896 * @param {Function} comparator The comparator used to compare values. 2897 * @returns {*} Returns the extremum value. 2898 */ 2899 function baseExtremum(array, iteratee, comparator) { 2900 var index = -1, 2901 length = array.length; 2902 2903 while (++index < length) { 2904 var value = array[index], 2905 current = iteratee(value); 2906 2907 if (current != null && (computed === undefined 2908 ? (current === current && !isSymbol(current)) 2909 : comparator(current, computed) 2910 )) { 2911 var computed = current, 2912 result = value; 2913 } 2914 } 2915 return result; 2916 } 2917 2918 /** 2919 * The base implementation of `_.fill` without an iteratee call guard. 2920 * 2921 * @private 2922 * @param {Array} array The array to fill. 2923 * @param {*} value The value to fill `array` with. 2924 * @param {number} [start=0] The start position. 2925 * @param {number} [end=array.length] The end position. 2926 * @returns {Array} Returns `array`. 2927 */ 2928 function baseFill(array, value, start, end) { 2929 var length = array.length; 2930 2931 start = toInteger(start); 2932 if (start < 0) { 2933 start = -start > length ? 0 : (length + start); 2934 } 2935 end = (end === undefined || end > length) ? length : toInteger(end); 2936 if (end < 0) { 2937 end += length; 2938 } 2939 end = start > end ? 0 : toLength(end); 2940 while (start < end) { 2941 array[start++] = value; 2942 } 2943 return array; 2944 } 2945 2946 /** 2947 * The base implementation of `_.filter` without support for iteratee shorthands. 2948 * 2949 * @private 2950 * @param {Array|Object} collection The collection to iterate over. 2951 * @param {Function} predicate The function invoked per iteration. 2952 * @returns {Array} Returns the new filtered array. 2953 */ 2954 function baseFilter(collection, predicate) { 2955 var result = []; 2956 baseEach(collection, function(value, index, collection) { 2957 if (predicate(value, index, collection)) { 2958 result.push(value); 2959 } 2960 }); 2961 return result; 2962 } 2963 2964 /** 2965 * The base implementation of `_.flatten` with support for restricting flattening. 2966 * 2967 * @private 2968 * @param {Array} array The array to flatten. 2969 * @param {number} depth The maximum recursion depth. 2970 * @param {boolean} [predicate=isFlattenable] The function invoked per iteration. 2971 * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. 2972 * @param {Array} [result=[]] The initial result value. 2973 * @returns {Array} Returns the new flattened array. 2974 */ 2975 function baseFlatten(array, depth, predicate, isStrict, result) { 2976 var index = -1, 2977 length = array.length; 2978 2979 predicate || (predicate = isFlattenable); 2980 result || (result = []); 2981 2982 while (++index < length) { 2983 var value = array[index]; 2984 if (depth > 0 && predicate(value)) { 2985 if (depth > 1) { 2986 // Recursively flatten arrays (susceptible to call stack limits). 2987 baseFlatten(value, depth - 1, predicate, isStrict, result); 2988 } else { 2989 arrayPush(result, value); 2990 } 2991 } else if (!isStrict) { 2992 result[result.length] = value; 2993 } 2994 } 2995 return result; 2996 } 2997 2998 /** 2999 * The base implementation of `baseForOwn` which iterates over `object` 3000 * properties returned by `keysFunc` and invokes `iteratee` for each property. 3001 * Iteratee functions may exit iteration early by explicitly returning `false`. 3002 * 3003 * @private 3004 * @param {Object} object The object to iterate over. 3005 * @param {Function} iteratee The function invoked per iteration. 3006 * @param {Function} keysFunc The function to get the keys of `object`. 3007 * @returns {Object} Returns `object`. 3008 */ 3009 var baseFor = createBaseFor(); 3010 3011 /** 3012 * This function is like `baseFor` except that it iterates over properties 3013 * in the opposite order. 3014 * 3015 * @private 3016 * @param {Object} object The object to iterate over. 3017 * @param {Function} iteratee The function invoked per iteration. 3018 * @param {Function} keysFunc The function to get the keys of `object`. 3019 * @returns {Object} Returns `object`. 3020 */ 3021 var baseForRight = createBaseFor(true); 3022 3023 /** 3024 * The base implementation of `_.forOwn` without support for iteratee shorthands. 3025 * 3026 * @private 3027 * @param {Object} object The object to iterate over. 3028 * @param {Function} iteratee The function invoked per iteration. 3029 * @returns {Object} Returns `object`. 3030 */ 3031 function baseForOwn(object, iteratee) { 3032 return object && baseFor(object, iteratee, keys); 3033 } 3034 3035 /** 3036 * The base implementation of `_.forOwnRight` without support for iteratee shorthands. 3037 * 3038 * @private 3039 * @param {Object} object The object to iterate over. 3040 * @param {Function} iteratee The function invoked per iteration. 3041 * @returns {Object} Returns `object`. 3042 */ 3043 function baseForOwnRight(object, iteratee) { 3044 return object && baseForRight(object, iteratee, keys); 3045 } 3046 3047 /** 3048 * The base implementation of `_.functions` which creates an array of 3049 * `object` function property names filtered from `props`. 3050 * 3051 * @private 3052 * @param {Object} object The object to inspect. 3053 * @param {Array} props The property names to filter. 3054 * @returns {Array} Returns the function names. 3055 */ 3056 function baseFunctions(object, props) { 3057 return arrayFilter(props, function(key) { 3058 return isFunction(object[key]); 3059 }); 3060 } 3061 3062 /** 3063 * The base implementation of `_.get` without support for default values. 3064 * 3065 * @private 3066 * @param {Object} object The object to query. 3067 * @param {Array|string} path The path of the property to get. 3068 * @returns {*} Returns the resolved value. 3069 */ 3070 function baseGet(object, path) { 3071 path = castPath(path, object); 3072 3073 var index = 0, 3074 length = path.length; 3075 3076 while (object != null && index < length) { 3077 object = object[toKey(path[index++])]; 3078 } 3079 return (index && index == length) ? object : undefined; 3080 } 3081 3082 /** 3083 * The base implementation of `getAllKeys` and `getAllKeysIn` which uses 3084 * `keysFunc` and `symbolsFunc` to get the enumerable property names and 3085 * symbols of `object`. 3086 * 3087 * @private 3088 * @param {Object} object The object to query. 3089 * @param {Function} keysFunc The function to get the keys of `object`. 3090 * @param {Function} symbolsFunc The function to get the symbols of `object`. 3091 * @returns {Array} Returns the array of property names and symbols. 3092 */ 3093 function baseGetAllKeys(object, keysFunc, symbolsFunc) { 3094 var result = keysFunc(object); 3095 return isArray(object) ? result : arrayPush(result, symbolsFunc(object)); 3096 } 3097 3098 /** 3099 * The base implementation of `getTag` without fallbacks for buggy environments. 3100 * 3101 * @private 3102 * @param {*} value The value to query. 3103 * @returns {string} Returns the `toStringTag`. 3104 */ 3105 function baseGetTag(value) { 3106 if (value == null) { 3107 return value === undefined ? undefinedTag : nullTag; 3108 } 3109 return (symToStringTag && symToStringTag in Object(value)) 3110 ? getRawTag(value) 3111 : objectToString(value); 3112 } 3113 3114 /** 3115 * The base implementation of `_.gt` which doesn't coerce arguments. 3116 * 3117 * @private 3118 * @param {*} value The value to compare. 3119 * @param {*} other The other value to compare. 3120 * @returns {boolean} Returns `true` if `value` is greater than `other`, 3121 * else `false`. 3122 */ 3123 function baseGt(value, other) { 3124 return value > other; 3125 } 3126 3127 /** 3128 * The base implementation of `_.has` without support for deep paths. 3129 * 3130 * @private 3131 * @param {Object} [object] The object to query. 3132 * @param {Array|string} key The key to check. 3133 * @returns {boolean} Returns `true` if `key` exists, else `false`. 3134 */ 3135 function baseHas(object, key) { 3136 return object != null && hasOwnProperty.call(object, key); 3137 } 3138 3139 /** 3140 * The base implementation of `_.hasIn` without support for deep paths. 3141 * 3142 * @private 3143 * @param {Object} [object] The object to query. 3144 * @param {Array|string} key The key to check. 3145 * @returns {boolean} Returns `true` if `key` exists, else `false`. 3146 */ 3147 function baseHasIn(object, key) { 3148 return object != null && key in Object(object); 3149 } 3150 3151 /** 3152 * The base implementation of `_.inRange` which doesn't coerce arguments. 3153 * 3154 * @private 3155 * @param {number} number The number to check. 3156 * @param {number} start The start of the range. 3157 * @param {number} end The end of the range. 3158 * @returns {boolean} Returns `true` if `number` is in the range, else `false`. 3159 */ 3160 function baseInRange(number, start, end) { 3161 return number >= nativeMin(start, end) && number < nativeMax(start, end); 3162 } 3163 3164 /** 3165 * The base implementation of methods like `_.intersection`, without support 3166 * for iteratee shorthands, that accepts an array of arrays to inspect. 3167 * 3168 * @private 3169 * @param {Array} arrays The arrays to inspect. 3170 * @param {Function} [iteratee] The iteratee invoked per element. 3171 * @param {Function} [comparator] The comparator invoked per element. 3172 * @returns {Array} Returns the new array of shared values. 3173 */ 3174 function baseIntersection(arrays, iteratee, comparator) { 3175 var includes = comparator ? arrayIncludesWith : arrayIncludes, 3176 length = arrays[0].length, 3177 othLength = arrays.length, 3178 othIndex = othLength, 3179 caches = Array(othLength), 3180 maxLength = Infinity, 3181 result = []; 3182 3183 while (othIndex--) { 3184 var array = arrays[othIndex]; 3185 if (othIndex && iteratee) { 3186 array = arrayMap(array, baseUnary(iteratee)); 3187 } 3188 maxLength = nativeMin(array.length, maxLength); 3189 caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) 3190 ? new SetCache(othIndex && array) 3191 : undefined; 3192 } 3193 array = arrays[0]; 3194 3195 var index = -1, 3196 seen = caches[0]; 3197 3198 outer: 3199 while (++index < length && result.length < maxLength) { 3200 var value = array[index], 3201 computed = iteratee ? iteratee(value) : value; 3202 3203 value = (comparator || value !== 0) ? value : 0; 3204 if (!(seen 3205 ? cacheHas(seen, computed) 3206 : includes(result, computed, comparator) 3207 )) { 3208 othIndex = othLength; 3209 while (--othIndex) { 3210 var cache = caches[othIndex]; 3211 if (!(cache 3212 ? cacheHas(cache, computed) 3213 : includes(arrays[othIndex], computed, comparator)) 3214 ) { 3215 continue outer; 3216 } 3217 } 3218 if (seen) { 3219 seen.push(computed); 3220 } 3221 result.push(value); 3222 } 3223 } 3224 return result; 3225 } 3226 3227 /** 3228 * The base implementation of `_.invert` and `_.invertBy` which inverts 3229 * `object` with values transformed by `iteratee` and set by `setter`. 3230 * 3231 * @private 3232 * @param {Object} object The object to iterate over. 3233 * @param {Function} setter The function to set `accumulator` values. 3234 * @param {Function} iteratee The iteratee to transform values. 3235 * @param {Object} accumulator The initial inverted object. 3236 * @returns {Function} Returns `accumulator`. 3237 */ 3238 function baseInverter(object, setter, iteratee, accumulator) { 3239 baseForOwn(object, function(value, key, object) { 3240 setter(accumulator, iteratee(value), key, object); 3241 }); 3242 return accumulator; 3243 } 3244 3245 /** 3246 * The base implementation of `_.invoke` without support for individual 3247 * method arguments. 3248 * 3249 * @private 3250 * @param {Object} object The object to query. 3251 * @param {Array|string} path The path of the method to invoke. 3252 * @param {Array} args The arguments to invoke the method with. 3253 * @returns {*} Returns the result of the invoked method. 3254 */ 3255 function baseInvoke(object, path, args) { 3256 path = castPath(path, object); 3257 object = parent(object, path); 3258 var func = object == null ? object : object[toKey(last(path))]; 3259 return func == null ? undefined : apply(func, object, args); 3260 } 3261 3262 /** 3263 * The base implementation of `_.isArguments`. 3264 * 3265 * @private 3266 * @param {*} value The value to check. 3267 * @returns {boolean} Returns `true` if `value` is an `arguments` object, 3268 */ 3269 function baseIsArguments(value) { 3270 return isObjectLike(value) && baseGetTag(value) == argsTag; 3271 } 3272 3273 /** 3274 * The base implementation of `_.isArrayBuffer` without Node.js optimizations. 3275 * 3276 * @private 3277 * @param {*} value The value to check. 3278 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. 3279 */ 3280 function baseIsArrayBuffer(value) { 3281 return isObjectLike(value) && baseGetTag(value) == arrayBufferTag; 3282 } 3283 3284 /** 3285 * The base implementation of `_.isDate` without Node.js optimizations. 3286 * 3287 * @private 3288 * @param {*} value The value to check. 3289 * @returns {boolean} Returns `true` if `value` is a date object, else `false`. 3290 */ 3291 function baseIsDate(value) { 3292 return isObjectLike(value) && baseGetTag(value) == dateTag; 3293 } 3294 3295 /** 3296 * The base implementation of `_.isEqual` which supports partial comparisons 3297 * and tracks traversed objects. 3298 * 3299 * @private 3300 * @param {*} value The value to compare. 3301 * @param {*} other The other value to compare. 3302 * @param {boolean} bitmask The bitmask flags. 3303 * 1 - Unordered comparison 3304 * 2 - Partial comparison 3305 * @param {Function} [customizer] The function to customize comparisons. 3306 * @param {Object} [stack] Tracks traversed `value` and `other` objects. 3307 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 3308 */ 3309 function baseIsEqual(value, other, bitmask, customizer, stack) { 3310 if (value === other) { 3311 return true; 3312 } 3313 if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) { 3314 return value !== value && other !== other; 3315 } 3316 return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack); 3317 } 3318 3319 /** 3320 * A specialized version of `baseIsEqual` for arrays and objects which performs 3321 * deep comparisons and tracks traversed objects enabling objects with circular 3322 * references to be compared. 3323 * 3324 * @private 3325 * @param {Object} object The object to compare. 3326 * @param {Object} other The other object to compare. 3327 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 3328 * @param {Function} customizer The function to customize comparisons. 3329 * @param {Function} equalFunc The function to determine equivalents of values. 3330 * @param {Object} [stack] Tracks traversed `object` and `other` objects. 3331 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. 3332 */ 3333 function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { 3334 var objIsArr = isArray(object), 3335 othIsArr = isArray(other), 3336 objTag = objIsArr ? arrayTag : getTag(object), 3337 othTag = othIsArr ? arrayTag : getTag(other); 3338 3339 objTag = objTag == argsTag ? objectTag : objTag; 3340 othTag = othTag == argsTag ? objectTag : othTag; 3341 3342 var objIsObj = objTag == objectTag, 3343 othIsObj = othTag == objectTag, 3344 isSameTag = objTag == othTag; 3345 3346 if (isSameTag && isBuffer(object)) { 3347 if (!isBuffer(other)) { 3348 return false; 3349 } 3350 objIsArr = true; 3351 objIsObj = false; 3352 } 3353 if (isSameTag && !objIsObj) { 3354 stack || (stack = new Stack); 3355 return (objIsArr || isTypedArray(object)) 3356 ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) 3357 : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack); 3358 } 3359 if (!(bitmask & COMPARE_PARTIAL_FLAG)) { 3360 var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), 3361 othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); 3362 3363 if (objIsWrapped || othIsWrapped) { 3364 var objUnwrapped = objIsWrapped ? object.value() : object, 3365 othUnwrapped = othIsWrapped ? other.value() : other; 3366 3367 stack || (stack = new Stack); 3368 return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack); 3369 } 3370 } 3371 if (!isSameTag) { 3372 return false; 3373 } 3374 stack || (stack = new Stack); 3375 return equalObjects(object, other, bitmask, customizer, equalFunc, stack); 3376 } 3377 3378 /** 3379 * The base implementation of `_.isMap` without Node.js optimizations. 3380 * 3381 * @private 3382 * @param {*} value The value to check. 3383 * @returns {boolean} Returns `true` if `value` is a map, else `false`. 3384 */ 3385 function baseIsMap(value) { 3386 return isObjectLike(value) && getTag(value) == mapTag; 3387 } 3388 3389 /** 3390 * The base implementation of `_.isMatch` without support for iteratee shorthands. 3391 * 3392 * @private 3393 * @param {Object} object The object to inspect. 3394 * @param {Object} source The object of property values to match. 3395 * @param {Array} matchData The property names, values, and compare flags to match. 3396 * @param {Function} [customizer] The function to customize comparisons. 3397 * @returns {boolean} Returns `true` if `object` is a match, else `false`. 3398 */ 3399 function baseIsMatch(object, source, matchData, customizer) { 3400 var index = matchData.length, 3401 length = index, 3402 noCustomizer = !customizer; 3403 3404 if (object == null) { 3405 return !length; 3406 } 3407 object = Object(object); 3408 while (index--) { 3409 var data = matchData[index]; 3410 if ((noCustomizer && data[2]) 3411 ? data[1] !== object[data[0]] 3412 : !(data[0] in object) 3413 ) { 3414 return false; 3415 } 3416 } 3417 while (++index < length) { 3418 data = matchData[index]; 3419 var key = data[0], 3420 objValue = object[key], 3421 srcValue = data[1]; 3422 3423 if (noCustomizer && data[2]) { 3424 if (objValue === undefined && !(key in object)) { 3425 return false; 3426 } 3427 } else { 3428 var stack = new Stack; 3429 if (customizer) { 3430 var result = customizer(objValue, srcValue, key, object, source, stack); 3431 } 3432 if (!(result === undefined 3433 ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) 3434 : result 3435 )) { 3436 return false; 3437 } 3438 } 3439 } 3440 return true; 3441 } 3442 3443 /** 3444 * The base implementation of `_.isNative` without bad shim checks. 3445 * 3446 * @private 3447 * @param {*} value The value to check. 3448 * @returns {boolean} Returns `true` if `value` is a native function, 3449 * else `false`. 3450 */ 3451 function baseIsNative(value) { 3452 if (!isObject(value) || isMasked(value)) { 3453 return false; 3454 } 3455 var pattern = isFunction(value) ? reIsNative : reIsHostCtor; 3456 return pattern.test(toSource(value)); 3457 } 3458 3459 /** 3460 * The base implementation of `_.isRegExp` without Node.js optimizations. 3461 * 3462 * @private 3463 * @param {*} value The value to check. 3464 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. 3465 */ 3466 function baseIsRegExp(value) { 3467 return isObjectLike(value) && baseGetTag(value) == regexpTag; 3468 } 3469 3470 /** 3471 * The base implementation of `_.isSet` without Node.js optimizations. 3472 * 3473 * @private 3474 * @param {*} value The value to check. 3475 * @returns {boolean} Returns `true` if `value` is a set, else `false`. 3476 */ 3477 function baseIsSet(value) { 3478 return isObjectLike(value) && getTag(value) == setTag; 3479 } 3480 3481 /** 3482 * The base implementation of `_.isTypedArray` without Node.js optimizations. 3483 * 3484 * @private 3485 * @param {*} value The value to check. 3486 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. 3487 */ 3488 function baseIsTypedArray(value) { 3489 return isObjectLike(value) && 3490 isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; 3491 } 3492 3493 /** 3494 * The base implementation of `_.iteratee`. 3495 * 3496 * @private 3497 * @param {*} [value=_.identity] The value to convert to an iteratee. 3498 * @returns {Function} Returns the iteratee. 3499 */ 3500 function baseIteratee(value) { 3501 // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. 3502 // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. 3503 if (typeof value == 'function') { 3504 return value; 3505 } 3506 if (value == null) { 3507 return identity; 3508 } 3509 if (typeof value == 'object') { 3510 return isArray(value) 3511 ? baseMatchesProperty(value[0], value[1]) 3512 : baseMatches(value); 3513 } 3514 return property(value); 3515 } 3516 3517 /** 3518 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. 3519 * 3520 * @private 3521 * @param {Object} object The object to query. 3522 * @returns {Array} Returns the array of property names. 3523 */ 3524 function baseKeys(object) { 3525 if (!isPrototype(object)) { 3526 return nativeKeys(object); 3527 } 3528 var result = []; 3529 for (var key in Object(object)) { 3530 if (hasOwnProperty.call(object, key) && key != 'constructor') { 3531 result.push(key); 3532 } 3533 } 3534 return result; 3535 } 3536 3537 /** 3538 * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense. 3539 * 3540 * @private 3541 * @param {Object} object The object to query. 3542 * @returns {Array} Returns the array of property names. 3543 */ 3544 function baseKeysIn(object) { 3545 if (!isObject(object)) { 3546 return nativeKeysIn(object); 3547 } 3548 var isProto = isPrototype(object), 3549 result = []; 3550 3551 for (var key in object) { 3552 if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { 3553 result.push(key); 3554 } 3555 } 3556 return result; 3557 } 3558 3559 /** 3560 * The base implementation of `_.lt` which doesn't coerce arguments. 3561 * 3562 * @private 3563 * @param {*} value The value to compare. 3564 * @param {*} other The other value to compare. 3565 * @returns {boolean} Returns `true` if `value` is less than `other`, 3566 * else `false`. 3567 */ 3568 function baseLt(value, other) { 3569 return value < other; 3570 } 3571 3572 /** 3573 * The base implementation of `_.map` without support for iteratee shorthands. 3574 * 3575 * @private 3576 * @param {Array|Object} collection The collection to iterate over. 3577 * @param {Function} iteratee The function invoked per iteration. 3578 * @returns {Array} Returns the new mapped array. 3579 */ 3580 function baseMap(collection, iteratee) { 3581 var index = -1, 3582 result = isArrayLike(collection) ? Array(collection.length) : []; 3583 3584 baseEach(collection, function(value, key, collection) { 3585 result[++index] = iteratee(value, key, collection); 3586 }); 3587 return result; 3588 } 3589 3590 /** 3591 * The base implementation of `_.matches` which doesn't clone `source`. 3592 * 3593 * @private 3594 * @param {Object} source The object of property values to match. 3595 * @returns {Function} Returns the new spec function. 3596 */ 3597 function baseMatches(source) { 3598 var matchData = getMatchData(source); 3599 if (matchData.length == 1 && matchData[0][2]) { 3600 return matchesStrictComparable(matchData[0][0], matchData[0][1]); 3601 } 3602 return function(object) { 3603 return object === source || baseIsMatch(object, source, matchData); 3604 }; 3605 } 3606 3607 /** 3608 * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. 3609 * 3610 * @private 3611 * @param {string} path The path of the property to get. 3612 * @param {*} srcValue The value to match. 3613 * @returns {Function} Returns the new spec function. 3614 */ 3615 function baseMatchesProperty(path, srcValue) { 3616 if (isKey(path) && isStrictComparable(srcValue)) { 3617 return matchesStrictComparable(toKey(path), srcValue); 3618 } 3619 return function(object) { 3620 var objValue = get(object, path); 3621 return (objValue === undefined && objValue === srcValue) 3622 ? hasIn(object, path) 3623 : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG); 3624 }; 3625 } 3626 3627 /** 3628 * The base implementation of `_.merge` without support for multiple sources. 3629 * 3630 * @private 3631 * @param {Object} object The destination object. 3632 * @param {Object} source The source object. 3633 * @param {number} srcIndex The index of `source`. 3634 * @param {Function} [customizer] The function to customize merged values. 3635 * @param {Object} [stack] Tracks traversed source values and their merged 3636 * counterparts. 3637 */ 3638 function baseMerge(object, source, srcIndex, customizer, stack) { 3639 if (object === source) { 3640 return; 3641 } 3642 baseFor(source, function(srcValue, key) { 3643 stack || (stack = new Stack); 3644 if (isObject(srcValue)) { 3645 baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); 3646 } 3647 else { 3648 var newValue = customizer 3649 ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) 3650 : undefined; 3651 3652 if (newValue === undefined) { 3653 newValue = srcValue; 3654 } 3655 assignMergeValue(object, key, newValue); 3656 } 3657 }, keysIn); 3658 } 3659 3660 /** 3661 * A specialized version of `baseMerge` for arrays and objects which performs 3662 * deep merges and tracks traversed objects enabling objects with circular 3663 * references to be merged. 3664 * 3665 * @private 3666 * @param {Object} object The destination object. 3667 * @param {Object} source The source object. 3668 * @param {string} key The key of the value to merge. 3669 * @param {number} srcIndex The index of `source`. 3670 * @param {Function} mergeFunc The function to merge values. 3671 * @param {Function} [customizer] The function to customize assigned values. 3672 * @param {Object} [stack] Tracks traversed source values and their merged 3673 * counterparts. 3674 */ 3675 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { 3676 var objValue = safeGet(object, key), 3677 srcValue = safeGet(source, key), 3678 stacked = stack.get(srcValue); 3679 3680 if (stacked) { 3681 assignMergeValue(object, key, stacked); 3682 return; 3683 } 3684 var newValue = customizer 3685 ? customizer(objValue, srcValue, (key + ''), object, source, stack) 3686 : undefined; 3687 3688 var isCommon = newValue === undefined; 3689 3690 if (isCommon) { 3691 var isArr = isArray(srcValue), 3692 isBuff = !isArr && isBuffer(srcValue), 3693 isTyped = !isArr && !isBuff && isTypedArray(srcValue); 3694 3695 newValue = srcValue; 3696 if (isArr || isBuff || isTyped) { 3697 if (isArray(objValue)) { 3698 newValue = objValue; 3699 } 3700 else if (isArrayLikeObject(objValue)) { 3701 newValue = copyArray(objValue); 3702 } 3703 else if (isBuff) { 3704 isCommon = false; 3705 newValue = cloneBuffer(srcValue, true); 3706 } 3707 else if (isTyped) { 3708 isCommon = false; 3709 newValue = cloneTypedArray(srcValue, true); 3710 } 3711 else { 3712 newValue = []; 3713 } 3714 } 3715 else if (isPlainObject(srcValue) || isArguments(srcValue)) { 3716 newValue = objValue; 3717 if (isArguments(objValue)) { 3718 newValue = toPlainObject(objValue); 3719 } 3720 else if (!isObject(objValue) || isFunction(objValue)) { 3721 newValue = initCloneObject(srcValue); 3722 } 3723 } 3724 else { 3725 isCommon = false; 3726 } 3727 } 3728 if (isCommon) { 3729 // Recursively merge objects and arrays (susceptible to call stack limits). 3730 stack.set(srcValue, newValue); 3731 mergeFunc(newValue, srcValue, srcIndex, customizer, stack); 3732 stack['delete'](srcValue); 3733 } 3734 assignMergeValue(object, key, newValue); 3735 } 3736 3737 /** 3738 * The base implementation of `_.nth` which doesn't coerce arguments. 3739 * 3740 * @private 3741 * @param {Array} array The array to query. 3742 * @param {number} n The index of the element to return. 3743 * @returns {*} Returns the nth element of `array`. 3744 */ 3745 function baseNth(array, n) { 3746 var length = array.length; 3747 if (!length) { 3748 return; 3749 } 3750 n += n < 0 ? length : 0; 3751 return isIndex(n, length) ? array[n] : undefined; 3752 } 3753 3754 /** 3755 * The base implementation of `_.orderBy` without param guards. 3756 * 3757 * @private 3758 * @param {Array|Object} collection The collection to iterate over. 3759 * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. 3760 * @param {string[]} orders The sort orders of `iteratees`. 3761 * @returns {Array} Returns the new sorted array. 3762 */ 3763 function baseOrderBy(collection, iteratees, orders) { 3764 if (iteratees.length) { 3765 iteratees = arrayMap(iteratees, function(iteratee) { 3766 if (isArray(iteratee)) { 3767 return function(value) { 3768 return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee); 3769 } 3770 } 3771 return iteratee; 3772 }); 3773 } else { 3774 iteratees = [identity]; 3775 } 3776 3777 var index = -1; 3778 iteratees = arrayMap(iteratees, baseUnary(getIteratee())); 3779 3780 var result = baseMap(collection, function(value, key, collection) { 3781 var criteria = arrayMap(iteratees, function(iteratee) { 3782 return iteratee(value); 3783 }); 3784 return { 'criteria': criteria, 'index': ++index, 'value': value }; 3785 }); 3786 3787 return baseSortBy(result, function(object, other) { 3788 return compareMultiple(object, other, orders); 3789 }); 3790 } 3791 3792 /** 3793 * The base implementation of `_.pick` without support for individual 3794 * property identifiers. 3795 * 3796 * @private 3797 * @param {Object} object The source object. 3798 * @param {string[]} paths The property paths to pick. 3799 * @returns {Object} Returns the new object. 3800 */ 3801 function basePick(object, paths) { 3802 return basePickBy(object, paths, function(value, path) { 3803 return hasIn(object, path); 3804 }); 3805 } 3806 3807 /** 3808 * The base implementation of `_.pickBy` without support for iteratee shorthands. 3809 * 3810 * @private 3811 * @param {Object} object The source object. 3812 * @param {string[]} paths The property paths to pick. 3813 * @param {Function} predicate The function invoked per property. 3814 * @returns {Object} Returns the new object. 3815 */ 3816 function basePickBy(object, paths, predicate) { 3817 var index = -1, 3818 length = paths.length, 3819 result = {}; 3820 3821 while (++index < length) { 3822 var path = paths[index], 3823 value = baseGet(object, path); 3824 3825 if (predicate(value, path)) { 3826 baseSet(result, castPath(path, object), value); 3827 } 3828 } 3829 return result; 3830 } 3831 3832 /** 3833 * A specialized version of `baseProperty` which supports deep paths. 3834 * 3835 * @private 3836 * @param {Array|string} path The path of the property to get. 3837 * @returns {Function} Returns the new accessor function. 3838 */ 3839 function basePropertyDeep(path) { 3840 return function(object) { 3841 return baseGet(object, path); 3842 }; 3843 } 3844 3845 /** 3846 * The base implementation of `_.pullAllBy` without support for iteratee 3847 * shorthands. 3848 * 3849 * @private 3850 * @param {Array} array The array to modify. 3851 * @param {Array} values The values to remove. 3852 * @param {Function} [iteratee] The iteratee invoked per element. 3853 * @param {Function} [comparator] The comparator invoked per element. 3854 * @returns {Array} Returns `array`. 3855 */ 3856 function basePullAll(array, values, iteratee, comparator) { 3857 var indexOf = comparator ? baseIndexOfWith : baseIndexOf, 3858 index = -1, 3859 length = values.length, 3860 seen = array; 3861 3862 if (array === values) { 3863 values = copyArray(values); 3864 } 3865 if (iteratee) { 3866 seen = arrayMap(array, baseUnary(iteratee)); 3867 } 3868 while (++index < length) { 3869 var fromIndex = 0, 3870 value = values[index], 3871 computed = iteratee ? iteratee(value) : value; 3872 3873 while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { 3874 if (seen !== array) { 3875 splice.call(seen, fromIndex, 1); 3876 } 3877 splice.call(array, fromIndex, 1); 3878 } 3879 } 3880 return array; 3881 } 3882 3883 /** 3884 * The base implementation of `_.pullAt` without support for individual 3885 * indexes or capturing the removed elements. 3886 * 3887 * @private 3888 * @param {Array} array The array to modify. 3889 * @param {number[]} indexes The indexes of elements to remove. 3890 * @returns {Array} Returns `array`. 3891 */ 3892 function basePullAt(array, indexes) { 3893 var length = array ? indexes.length : 0, 3894 lastIndex = length - 1; 3895 3896 while (length--) { 3897 var index = indexes[length]; 3898 if (length == lastIndex || index !== previous) { 3899 var previous = index; 3900 if (isIndex(index)) { 3901 splice.call(array, index, 1); 3902 } else { 3903 baseUnset(array, index); 3904 } 3905 } 3906 } 3907 return array; 3908 } 3909 3910 /** 3911 * The base implementation of `_.random` without support for returning 3912 * floating-point numbers. 3913 * 3914 * @private 3915 * @param {number} lower The lower bound. 3916 * @param {number} upper The upper bound. 3917 * @returns {number} Returns the random number. 3918 */ 3919 function baseRandom(lower, upper) { 3920 return lower + nativeFloor(nativeRandom() * (upper - lower + 1)); 3921 } 3922 3923 /** 3924 * The base implementation of `_.range` and `_.rangeRight` which doesn't 3925 * coerce arguments. 3926 * 3927 * @private 3928 * @param {number} start The start of the range. 3929 * @param {number} end The end of the range. 3930 * @param {number} step The value to increment or decrement by. 3931 * @param {boolean} [fromRight] Specify iterating from right to left. 3932 * @returns {Array} Returns the range of numbers. 3933 */ 3934 function baseRange(start, end, step, fromRight) { 3935 var index = -1, 3936 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), 3937 result = Array(length); 3938 3939 while (length--) { 3940 result[fromRight ? length : ++index] = start; 3941 start += step; 3942 } 3943 return result; 3944 } 3945 3946 /** 3947 * The base implementation of `_.repeat` which doesn't coerce arguments. 3948 * 3949 * @private 3950 * @param {string} string The string to repeat. 3951 * @param {number} n The number of times to repeat the string. 3952 * @returns {string} Returns the repeated string. 3953 */ 3954 function baseRepeat(string, n) { 3955 var result = ''; 3956 if (!string || n < 1 || n > MAX_SAFE_INTEGER) { 3957 return result; 3958 } 3959 // Leverage the exponentiation by squaring algorithm for a faster repeat. 3960 // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. 3961 do { 3962 if (n % 2) { 3963 result += string; 3964 } 3965 n = nativeFloor(n / 2); 3966 if (n) { 3967 string += string; 3968 } 3969 } while (n); 3970 3971 return result; 3972 } 3973 3974 /** 3975 * The base implementation of `_.rest` which doesn't validate or coerce arguments. 3976 * 3977 * @private 3978 * @param {Function} func The function to apply a rest parameter to. 3979 * @param {number} [start=func.length-1] The start position of the rest parameter. 3980 * @returns {Function} Returns the new function. 3981 */ 3982 function baseRest(func, start) { 3983 return setToString(overRest(func, start, identity), func + ''); 3984 } 3985 3986 /** 3987 * The base implementation of `_.sample`. 3988 * 3989 * @private 3990 * @param {Array|Object} collection The collection to sample. 3991 * @returns {*} Returns the random element. 3992 */ 3993 function baseSample(collection) { 3994 return arraySample(values(collection)); 3995 } 3996 3997 /** 3998 * The base implementation of `_.sampleSize` without param guards. 3999 * 4000 * @private 4001 * @param {Array|Object} collection The collection to sample. 4002 * @param {number} n The number of elements to sample. 4003 * @returns {Array} Returns the random elements. 4004 */ 4005 function baseSampleSize(collection, n) { 4006 var array = values(collection); 4007 return shuffleSelf(array, baseClamp(n, 0, array.length)); 4008 } 4009 4010 /** 4011 * The base implementation of `_.set`. 4012 * 4013 * @private 4014 * @param {Object} object The object to modify. 4015 * @param {Array|string} path The path of the property to set. 4016 * @param {*} value The value to set. 4017 * @param {Function} [customizer] The function to customize path creation. 4018 * @returns {Object} Returns `object`. 4019 */ 4020 function baseSet(object, path, value, customizer) { 4021 if (!isObject(object)) { 4022 return object; 4023 } 4024 path = castPath(path, object); 4025 4026 var index = -1, 4027 length = path.length, 4028 lastIndex = length - 1, 4029 nested = object; 4030 4031 while (nested != null && ++index < length) { 4032 var key = toKey(path[index]), 4033 newValue = value; 4034 4035 if (key === '__proto__' || key === 'constructor' || key === 'prototype') { 4036 return object; 4037 } 4038 4039 if (index != lastIndex) { 4040 var objValue = nested[key]; 4041 newValue = customizer ? customizer(objValue, key, nested) : undefined; 4042 if (newValue === undefined) { 4043 newValue = isObject(objValue) 4044 ? objValue 4045 : (isIndex(path[index + 1]) ? [] : {}); 4046 } 4047 } 4048 assignValue(nested, key, newValue); 4049 nested = nested[key]; 4050 } 4051 return object; 4052 } 4053 4054 /** 4055 * The base implementation of `setData` without support for hot loop shorting. 4056 * 4057 * @private 4058 * @param {Function} func The function to associate metadata with. 4059 * @param {*} data The metadata. 4060 * @returns {Function} Returns `func`. 4061 */ 4062 var baseSetData = !metaMap ? identity : function(func, data) { 4063 metaMap.set(func, data); 4064 return func; 4065 }; 4066 4067 /** 4068 * The base implementation of `setToString` without support for hot loop shorting. 4069 * 4070 * @private 4071 * @param {Function} func The function to modify. 4072 * @param {Function} string The `toString` result. 4073 * @returns {Function} Returns `func`. 4074 */ 4075 var baseSetToString = !defineProperty ? identity : function(func, string) { 4076 return defineProperty(func, 'toString', { 4077 'configurable': true, 4078 'enumerable': false, 4079 'value': constant(string), 4080 'writable': true 4081 }); 4082 }; 4083 4084 /** 4085 * The base implementation of `_.shuffle`. 4086 * 4087 * @private 4088 * @param {Array|Object} collection The collection to shuffle. 4089 * @returns {Array} Returns the new shuffled array. 4090 */ 4091 function baseShuffle(collection) { 4092 return shuffleSelf(values(collection)); 4093 } 4094 4095 /** 4096 * The base implementation of `_.slice` without an iteratee call guard. 4097 * 4098 * @private 4099 * @param {Array} array The array to slice. 4100 * @param {number} [start=0] The start position. 4101 * @param {number} [end=array.length] The end position. 4102 * @returns {Array} Returns the slice of `array`. 4103 */ 4104 function baseSlice(array, start, end) { 4105 var index = -1, 4106 length = array.length; 4107 4108 if (start < 0) { 4109 start = -start > length ? 0 : (length + start); 4110 } 4111 end = end > length ? length : end; 4112 if (end < 0) { 4113 end += length; 4114 } 4115 length = start > end ? 0 : ((end - start) >>> 0); 4116 start >>>= 0; 4117 4118 var result = Array(length); 4119 while (++index < length) { 4120 result[index] = array[index + start]; 4121 } 4122 return result; 4123 } 4124 4125 /** 4126 * The base implementation of `_.some` without support for iteratee shorthands. 4127 * 4128 * @private 4129 * @param {Array|Object} collection The collection to iterate over. 4130 * @param {Function} predicate The function invoked per iteration. 4131 * @returns {boolean} Returns `true` if any element passes the predicate check, 4132 * else `false`. 4133 */ 4134 function baseSome(collection, predicate) { 4135 var result; 4136 4137 baseEach(collection, function(value, index, collection) { 4138 result = predicate(value, index, collection); 4139 return !result; 4140 }); 4141 return !!result; 4142 } 4143 4144 /** 4145 * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which 4146 * performs a binary search of `array` to determine the index at which `value` 4147 * should be inserted into `array` in order to maintain its sort order. 4148 * 4149 * @private 4150 * @param {Array} array The sorted array to inspect. 4151 * @param {*} value The value to evaluate. 4152 * @param {boolean} [retHighest] Specify returning the highest qualified index. 4153 * @returns {number} Returns the index at which `value` should be inserted 4154 * into `array`. 4155 */ 4156 function baseSortedIndex(array, value, retHighest) { 4157 var low = 0, 4158 high = array == null ? low : array.length; 4159 4160 if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { 4161 while (low < high) { 4162 var mid = (low + high) >>> 1, 4163 computed = array[mid]; 4164 4165 if (computed !== null && !isSymbol(computed) && 4166 (retHighest ? (computed <= value) : (computed < value))) { 4167 low = mid + 1; 4168 } else { 4169 high = mid; 4170 } 4171 } 4172 return high; 4173 } 4174 return baseSortedIndexBy(array, value, identity, retHighest); 4175 } 4176 4177 /** 4178 * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy` 4179 * which invokes `iteratee` for `value` and each element of `array` to compute 4180 * their sort ranking. The iteratee is invoked with one argument; (value). 4181 * 4182 * @private 4183 * @param {Array} array The sorted array to inspect. 4184 * @param {*} value The value to evaluate. 4185 * @param {Function} iteratee The iteratee invoked per element. 4186 * @param {boolean} [retHighest] Specify returning the highest qualified index. 4187 * @returns {number} Returns the index at which `value` should be inserted 4188 * into `array`. 4189 */ 4190 function baseSortedIndexBy(array, value, iteratee, retHighest) { 4191 var low = 0, 4192 high = array == null ? 0 : array.length; 4193 if (high === 0) { 4194 return 0; 4195 } 4196 4197 value = iteratee(value); 4198 var valIsNaN = value !== value, 4199 valIsNull = value === null, 4200 valIsSymbol = isSymbol(value), 4201 valIsUndefined = value === undefined; 4202 4203 while (low < high) { 4204 var mid = nativeFloor((low + high) / 2), 4205 computed = iteratee(array[mid]), 4206 othIsDefined = computed !== undefined, 4207 othIsNull = computed === null, 4208 othIsReflexive = computed === computed, 4209 othIsSymbol = isSymbol(computed); 4210 4211 if (valIsNaN) { 4212 var setLow = retHighest || othIsReflexive; 4213 } else if (valIsUndefined) { 4214 setLow = othIsReflexive && (retHighest || othIsDefined); 4215 } else if (valIsNull) { 4216 setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull); 4217 } else if (valIsSymbol) { 4218 setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol); 4219 } else if (othIsNull || othIsSymbol) { 4220 setLow = false; 4221 } else { 4222 setLow = retHighest ? (computed <= value) : (computed < value); 4223 } 4224 if (setLow) { 4225 low = mid + 1; 4226 } else { 4227 high = mid; 4228 } 4229 } 4230 return nativeMin(high, MAX_ARRAY_INDEX); 4231 } 4232 4233 /** 4234 * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without 4235 * support for iteratee shorthands. 4236 * 4237 * @private 4238 * @param {Array} array The array to inspect. 4239 * @param {Function} [iteratee] The iteratee invoked per element. 4240 * @returns {Array} Returns the new duplicate free array. 4241 */ 4242 function baseSortedUniq(array, iteratee) { 4243 var index = -1, 4244 length = array.length, 4245 resIndex = 0, 4246 result = []; 4247 4248 while (++index < length) { 4249 var value = array[index], 4250 computed = iteratee ? iteratee(value) : value; 4251 4252 if (!index || !eq(computed, seen)) { 4253 var seen = computed; 4254 result[resIndex++] = value === 0 ? 0 : value; 4255 } 4256 } 4257 return result; 4258 } 4259 4260 /** 4261 * The base implementation of `_.toNumber` which doesn't ensure correct 4262 * conversions of binary, hexadecimal, or octal string values. 4263 * 4264 * @private 4265 * @param {*} value The value to process. 4266 * @returns {number} Returns the number. 4267 */ 4268 function baseToNumber(value) { 4269 if (typeof value == 'number') { 4270 return value; 4271 } 4272 if (isSymbol(value)) { 4273 return NAN; 4274 } 4275 return +value; 4276 } 4277 4278 /** 4279 * The base implementation of `_.toString` which doesn't convert nullish 4280 * values to empty strings. 4281 * 4282 * @private 4283 * @param {*} value The value to process. 4284 * @returns {string} Returns the string. 4285 */ 4286 function baseToString(value) { 4287 // Exit early for strings to avoid a performance hit in some environments. 4288 if (typeof value == 'string') { 4289 return value; 4290 } 4291 if (isArray(value)) { 4292 // Recursively convert values (susceptible to call stack limits). 4293 return arrayMap(value, baseToString) + ''; 4294 } 4295 if (isSymbol(value)) { 4296 return symbolToString ? symbolToString.call(value) : ''; 4297 } 4298 var result = (value + ''); 4299 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; 4300 } 4301 4302 /** 4303 * The base implementation of `_.uniqBy` without support for iteratee shorthands. 4304 * 4305 * @private 4306 * @param {Array} array The array to inspect. 4307 * @param {Function} [iteratee] The iteratee invoked per element. 4308 * @param {Function} [comparator] The comparator invoked per element. 4309 * @returns {Array} Returns the new duplicate free array. 4310 */ 4311 function baseUniq(array, iteratee, comparator) { 4312 var index = -1, 4313 includes = arrayIncludes, 4314 length = array.length, 4315 isCommon = true, 4316 result = [], 4317 seen = result; 4318 4319 if (comparator) { 4320 isCommon = false; 4321 includes = arrayIncludesWith; 4322 } 4323 else if (length >= LARGE_ARRAY_SIZE) { 4324 var set = iteratee ? null : createSet(array); 4325 if (set) { 4326 return setToArray(set); 4327 } 4328 isCommon = false; 4329 includes = cacheHas; 4330 seen = new SetCache; 4331 } 4332 else { 4333 seen = iteratee ? [] : result; 4334 } 4335 outer: 4336 while (++index < length) { 4337 var value = array[index], 4338 computed = iteratee ? iteratee(value) : value; 4339 4340 value = (comparator || value !== 0) ? value : 0; 4341 if (isCommon && computed === computed) { 4342 var seenIndex = seen.length; 4343 while (seenIndex--) { 4344 if (seen[seenIndex] === computed) { 4345 continue outer; 4346 } 4347 } 4348 if (iteratee) { 4349 seen.push(computed); 4350 } 4351 result.push(value); 4352 } 4353 else if (!includes(seen, computed, comparator)) { 4354 if (seen !== result) { 4355 seen.push(computed); 4356 } 4357 result.push(value); 4358 } 4359 } 4360 return result; 4361 } 4362 4363 /** 4364 * The base implementation of `_.unset`. 4365 * 4366 * @private 4367 * @param {Object} object The object to modify. 4368 * @param {Array|string} path The property path to unset. 4369 * @returns {boolean} Returns `true` if the property is deleted, else `false`. 4370 */ 4371 function baseUnset(object, path) { 4372 path = castPath(path, object); 4373 object = parent(object, path); 4374 return object == null || delete object[toKey(last(path))]; 4375 } 4376 4377 /** 4378 * The base implementation of `_.update`. 4379 * 4380 * @private 4381 * @param {Object} object The object to modify. 4382 * @param {Array|string} path The path of the property to update. 4383 * @param {Function} updater The function to produce the updated value. 4384 * @param {Function} [customizer] The function to customize path creation. 4385 * @returns {Object} Returns `object`. 4386 */ 4387 function baseUpdate(object, path, updater, customizer) { 4388 return baseSet(object, path, updater(baseGet(object, path)), customizer); 4389 } 4390 4391 /** 4392 * The base implementation of methods like `_.dropWhile` and `_.takeWhile` 4393 * without support for iteratee shorthands. 4394 * 4395 * @private 4396 * @param {Array} array The array to query. 4397 * @param {Function} predicate The function invoked per iteration. 4398 * @param {boolean} [isDrop] Specify dropping elements instead of taking them. 4399 * @param {boolean} [fromRight] Specify iterating from right to left. 4400 * @returns {Array} Returns the slice of `array`. 4401 */ 4402 function baseWhile(array, predicate, isDrop, fromRight) { 4403 var length = array.length, 4404 index = fromRight ? length : -1; 4405 4406 while ((fromRight ? index-- : ++index < length) && 4407 predicate(array[index], index, array)) {} 4408 4409 return isDrop 4410 ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) 4411 : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)); 4412 } 4413 4414 /** 4415 * The base implementation of `wrapperValue` which returns the result of 4416 * performing a sequence of actions on the unwrapped `value`, where each 4417 * successive action is supplied the return value of the previous. 4418 * 4419 * @private 4420 * @param {*} value The unwrapped value. 4421 * @param {Array} actions Actions to perform to resolve the unwrapped value. 4422 * @returns {*} Returns the resolved value. 4423 */ 4424 function baseWrapperValue(value, actions) { 4425 var result = value; 4426 if (result instanceof LazyWrapper) { 4427 result = result.value(); 4428 } 4429 return arrayReduce(actions, function(result, action) { 4430 return action.func.apply(action.thisArg, arrayPush([result], action.args)); 4431 }, result); 4432 } 4433 4434 /** 4435 * The base implementation of methods like `_.xor`, without support for 4436 * iteratee shorthands, that accepts an array of arrays to inspect. 4437 * 4438 * @private 4439 * @param {Array} arrays The arrays to inspect. 4440 * @param {Function} [iteratee] The iteratee invoked per element. 4441 * @param {Function} [comparator] The comparator invoked per element. 4442 * @returns {Array} Returns the new array of values. 4443 */ 4444 function baseXor(arrays, iteratee, comparator) { 4445 var length = arrays.length; 4446 if (length < 2) { 4447 return length ? baseUniq(arrays[0]) : []; 4448 } 4449 var index = -1, 4450 result = Array(length); 4451 4452 while (++index < length) { 4453 var array = arrays[index], 4454 othIndex = -1; 4455 4456 while (++othIndex < length) { 4457 if (othIndex != index) { 4458 result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator); 4459 } 4460 } 4461 } 4462 return baseUniq(baseFlatten(result, 1), iteratee, comparator); 4463 } 4464 4465 /** 4466 * This base implementation of `_.zipObject` which assigns values using `assignFunc`. 4467 * 4468 * @private 4469 * @param {Array} props The property identifiers. 4470 * @param {Array} values The property values. 4471 * @param {Function} assignFunc The function to assign values. 4472 * @returns {Object} Returns the new object. 4473 */ 4474 function baseZipObject(props, values, assignFunc) { 4475 var index = -1, 4476 length = props.length, 4477 valsLength = values.length, 4478 result = {}; 4479 4480 while (++index < length) { 4481 var value = index < valsLength ? values[index] : undefined; 4482 assignFunc(result, props[index], value); 4483 } 4484 return result; 4485 } 4486 4487 /** 4488 * Casts `value` to an empty array if it's not an array like object. 4489 * 4490 * @private 4491 * @param {*} value The value to inspect. 4492 * @returns {Array|Object} Returns the cast array-like object. 4493 */ 4494 function castArrayLikeObject(value) { 4495 return isArrayLikeObject(value) ? value : []; 4496 } 4497 4498 /** 4499 * Casts `value` to `identity` if it's not a function. 4500 * 4501 * @private 4502 * @param {*} value The value to inspect. 4503 * @returns {Function} Returns cast function. 4504 */ 4505 function castFunction(value) { 4506 return typeof value == 'function' ? value : identity; 4507 } 4508 4509 /** 4510 * Casts `value` to a path array if it's not one. 4511 * 4512 * @private 4513 * @param {*} value The value to inspect. 4514 * @param {Object} [object] The object to query keys on. 4515 * @returns {Array} Returns the cast property path array. 4516 */ 4517 function castPath(value, object) { 4518 if (isArray(value)) { 4519 return value; 4520 } 4521 return isKey(value, object) ? [value] : stringToPath(toString(value)); 4522 } 4523 4524 /** 4525 * A `baseRest` alias which can be replaced with `identity` by module 4526 * replacement plugins. 4527 * 4528 * @private 4529 * @type {Function} 4530 * @param {Function} func The function to apply a rest parameter to. 4531 * @returns {Function} Returns the new function. 4532 */ 4533 var castRest = baseRest; 4534 4535 /** 4536 * Casts `array` to a slice if it's needed. 4537 * 4538 * @private 4539 * @param {Array} array The array to inspect. 4540 * @param {number} start The start position. 4541 * @param {number} [end=array.length] The end position. 4542 * @returns {Array} Returns the cast slice. 4543 */ 4544 function castSlice(array, start, end) { 4545 var length = array.length; 4546 end = end === undefined ? length : end; 4547 return (!start && end >= length) ? array : baseSlice(array, start, end); 4548 } 4549 4550 /** 4551 * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout). 4552 * 4553 * @private 4554 * @param {number|Object} id The timer id or timeout object of the timer to clear. 4555 */ 4556 var clearTimeout = ctxClearTimeout || function(id) { 4557 return root.clearTimeout(id); 4558 }; 4559 4560 /** 4561 * Creates a clone of `buffer`. 4562 * 4563 * @private 4564 * @param {Buffer} buffer The buffer to clone. 4565 * @param {boolean} [isDeep] Specify a deep clone. 4566 * @returns {Buffer} Returns the cloned buffer. 4567 */ 4568 function cloneBuffer(buffer, isDeep) { 4569 if (isDeep) { 4570 return buffer.slice(); 4571 } 4572 var length = buffer.length, 4573 result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); 4574 4575 buffer.copy(result); 4576 return result; 4577 } 4578 4579 /** 4580 * Creates a clone of `arrayBuffer`. 4581 * 4582 * @private 4583 * @param {ArrayBuffer} arrayBuffer The array buffer to clone. 4584 * @returns {ArrayBuffer} Returns the cloned array buffer. 4585 */ 4586 function cloneArrayBuffer(arrayBuffer) { 4587 var result = new arrayBuffer.constructor(arrayBuffer.byteLength); 4588 new Uint8Array(result).set(new Uint8Array(arrayBuffer)); 4589 return result; 4590 } 4591 4592 /** 4593 * Creates a clone of `dataView`. 4594 * 4595 * @private 4596 * @param {Object} dataView The data view to clone. 4597 * @param {boolean} [isDeep] Specify a deep clone. 4598 * @returns {Object} Returns the cloned data view. 4599 */ 4600 function cloneDataView(dataView, isDeep) { 4601 var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; 4602 return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); 4603 } 4604 4605 /** 4606 * Creates a clone of `regexp`. 4607 * 4608 * @private 4609 * @param {Object} regexp The regexp to clone. 4610 * @returns {Object} Returns the cloned regexp. 4611 */ 4612 function cloneRegExp(regexp) { 4613 var result = new regexp.constructor(regexp.source, reFlags.exec(regexp)); 4614 result.lastIndex = regexp.lastIndex; 4615 return result; 4616 } 4617 4618 /** 4619 * Creates a clone of the `symbol` object. 4620 * 4621 * @private 4622 * @param {Object} symbol The symbol object to clone. 4623 * @returns {Object} Returns the cloned symbol object. 4624 */ 4625 function cloneSymbol(symbol) { 4626 return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {}; 4627 } 4628 4629 /** 4630 * Creates a clone of `typedArray`. 4631 * 4632 * @private 4633 * @param {Object} typedArray The typed array to clone. 4634 * @param {boolean} [isDeep] Specify a deep clone. 4635 * @returns {Object} Returns the cloned typed array. 4636 */ 4637 function cloneTypedArray(typedArray, isDeep) { 4638 var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer; 4639 return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length); 4640 } 4641 4642 /** 4643 * Compares values to sort them in ascending order. 4644 * 4645 * @private 4646 * @param {*} value The value to compare. 4647 * @param {*} other The other value to compare. 4648 * @returns {number} Returns the sort order indicator for `value`. 4649 */ 4650 function compareAscending(value, other) { 4651 if (value !== other) { 4652 var valIsDefined = value !== undefined, 4653 valIsNull = value === null, 4654 valIsReflexive = value === value, 4655 valIsSymbol = isSymbol(value); 4656 4657 var othIsDefined = other !== undefined, 4658 othIsNull = other === null, 4659 othIsReflexive = other === other, 4660 othIsSymbol = isSymbol(other); 4661 4662 if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || 4663 (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || 4664 (valIsNull && othIsDefined && othIsReflexive) || 4665 (!valIsDefined && othIsReflexive) || 4666 !valIsReflexive) { 4667 return 1; 4668 } 4669 if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || 4670 (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || 4671 (othIsNull && valIsDefined && valIsReflexive) || 4672 (!othIsDefined && valIsReflexive) || 4673 !othIsReflexive) { 4674 return -1; 4675 } 4676 } 4677 return 0; 4678 } 4679 4680 /** 4681 * Used by `_.orderBy` to compare multiple properties of a value to another 4682 * and stable sort them. 4683 * 4684 * If `orders` is unspecified, all values are sorted in ascending order. Otherwise, 4685 * specify an order of "desc" for descending or "asc" for ascending sort order 4686 * of corresponding values. 4687 * 4688 * @private 4689 * @param {Object} object The object to compare. 4690 * @param {Object} other The other object to compare. 4691 * @param {boolean[]|string[]} orders The order to sort by for each property. 4692 * @returns {number} Returns the sort order indicator for `object`. 4693 */ 4694 function compareMultiple(object, other, orders) { 4695 var index = -1, 4696 objCriteria = object.criteria, 4697 othCriteria = other.criteria, 4698 length = objCriteria.length, 4699 ordersLength = orders.length; 4700 4701 while (++index < length) { 4702 var result = compareAscending(objCriteria[index], othCriteria[index]); 4703 if (result) { 4704 if (index >= ordersLength) { 4705 return result; 4706 } 4707 var order = orders[index]; 4708 return result * (order == 'desc' ? -1 : 1); 4709 } 4710 } 4711 // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications 4712 // that causes it, under certain circumstances, to provide the same value for 4713 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 4714 // for more details. 4715 // 4716 // This also ensures a stable sort in V8 and other engines. 4717 // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. 4718 return object.index - other.index; 4719 } 4720 4721 /** 4722 * Creates an array that is the composition of partially applied arguments, 4723 * placeholders, and provided arguments into a single array of arguments. 4724 * 4725 * @private 4726 * @param {Array} args The provided arguments. 4727 * @param {Array} partials The arguments to prepend to those provided. 4728 * @param {Array} holders The `partials` placeholder indexes. 4729 * @params {boolean} [isCurried] Specify composing for a curried function. 4730 * @returns {Array} Returns the new array of composed arguments. 4731 */ 4732 function composeArgs(args, partials, holders, isCurried) { 4733 var argsIndex = -1, 4734 argsLength = args.length, 4735 holdersLength = holders.length, 4736 leftIndex = -1, 4737 leftLength = partials.length, 4738 rangeLength = nativeMax(argsLength - holdersLength, 0), 4739 result = Array(leftLength + rangeLength), 4740 isUncurried = !isCurried; 4741 4742 while (++leftIndex < leftLength) { 4743 result[leftIndex] = partials[leftIndex]; 4744 } 4745 while (++argsIndex < holdersLength) { 4746 if (isUncurried || argsIndex < argsLength) { 4747 result[holders[argsIndex]] = args[argsIndex]; 4748 } 4749 } 4750 while (rangeLength--) { 4751 result[leftIndex++] = args[argsIndex++]; 4752 } 4753 return result; 4754 } 4755 4756 /** 4757 * This function is like `composeArgs` except that the arguments composition 4758 * is tailored for `_.partialRight`. 4759 * 4760 * @private 4761 * @param {Array} args The provided arguments. 4762 * @param {Array} partials The arguments to append to those provided. 4763 * @param {Array} holders The `partials` placeholder indexes. 4764 * @params {boolean} [isCurried] Specify composing for a curried function. 4765 * @returns {Array} Returns the new array of composed arguments. 4766 */ 4767 function composeArgsRight(args, partials, holders, isCurried) { 4768 var argsIndex = -1, 4769 argsLength = args.length, 4770 holdersIndex = -1, 4771 holdersLength = holders.length, 4772 rightIndex = -1, 4773 rightLength = partials.length, 4774 rangeLength = nativeMax(argsLength - holdersLength, 0), 4775 result = Array(rangeLength + rightLength), 4776 isUncurried = !isCurried; 4777 4778 while (++argsIndex < rangeLength) { 4779 result[argsIndex] = args[argsIndex]; 4780 } 4781 var offset = argsIndex; 4782 while (++rightIndex < rightLength) { 4783 result[offset + rightIndex] = partials[rightIndex]; 4784 } 4785 while (++holdersIndex < holdersLength) { 4786 if (isUncurried || argsIndex < argsLength) { 4787 result[offset + holders[holdersIndex]] = args[argsIndex++]; 4788 } 4789 } 4790 return result; 4791 } 4792 4793 /** 4794 * Copies the values of `source` to `array`. 4795 * 4796 * @private 4797 * @param {Array} source The array to copy values from. 4798 * @param {Array} [array=[]] The array to copy values to. 4799 * @returns {Array} Returns `array`. 4800 */ 4801 function copyArray(source, array) { 4802 var index = -1, 4803 length = source.length; 4804 4805 array || (array = Array(length)); 4806 while (++index < length) { 4807 array[index] = source[index]; 4808 } 4809 return array; 4810 } 4811 4812 /** 4813 * Copies properties of `source` to `object`. 4814 * 4815 * @private 4816 * @param {Object} source The object to copy properties from. 4817 * @param {Array} props The property identifiers to copy. 4818 * @param {Object} [object={}] The object to copy properties to. 4819 * @param {Function} [customizer] The function to customize copied values. 4820 * @returns {Object} Returns `object`. 4821 */ 4822 function copyObject(source, props, object, customizer) { 4823 var isNew = !object; 4824 object || (object = {}); 4825 4826 var index = -1, 4827 length = props.length; 4828 4829 while (++index < length) { 4830 var key = props[index]; 4831 4832 var newValue = customizer 4833 ? customizer(object[key], source[key], key, object, source) 4834 : undefined; 4835 4836 if (newValue === undefined) { 4837 newValue = source[key]; 4838 } 4839 if (isNew) { 4840 baseAssignValue(object, key, newValue); 4841 } else { 4842 assignValue(object, key, newValue); 4843 } 4844 } 4845 return object; 4846 } 4847 4848 /** 4849 * Copies own symbols of `source` to `object`. 4850 * 4851 * @private 4852 * @param {Object} source The object to copy symbols from. 4853 * @param {Object} [object={}] The object to copy symbols to. 4854 * @returns {Object} Returns `object`. 4855 */ 4856 function copySymbols(source, object) { 4857 return copyObject(source, getSymbols(source), object); 4858 } 4859 4860 /** 4861 * Copies own and inherited symbols of `source` to `object`. 4862 * 4863 * @private 4864 * @param {Object} source The object to copy symbols from. 4865 * @param {Object} [object={}] The object to copy symbols to. 4866 * @returns {Object} Returns `object`. 4867 */ 4868 function copySymbolsIn(source, object) { 4869 return copyObject(source, getSymbolsIn(source), object); 4870 } 4871 4872 /** 4873 * Creates a function like `_.groupBy`. 4874 * 4875 * @private 4876 * @param {Function} setter The function to set accumulator values. 4877 * @param {Function} [initializer] The accumulator object initializer. 4878 * @returns {Function} Returns the new aggregator function. 4879 */ 4880 function createAggregator(setter, initializer) { 4881 return function(collection, iteratee) { 4882 var func = isArray(collection) ? arrayAggregator : baseAggregator, 4883 accumulator = initializer ? initializer() : {}; 4884 4885 return func(collection, setter, getIteratee(iteratee, 2), accumulator); 4886 }; 4887 } 4888 4889 /** 4890 * Creates a function like `_.assign`. 4891 * 4892 * @private 4893 * @param {Function} assigner The function to assign values. 4894 * @returns {Function} Returns the new assigner function. 4895 */ 4896 function createAssigner(assigner) { 4897 return baseRest(function(object, sources) { 4898 var index = -1, 4899 length = sources.length, 4900 customizer = length > 1 ? sources[length - 1] : undefined, 4901 guard = length > 2 ? sources[2] : undefined; 4902 4903 customizer = (assigner.length > 3 && typeof customizer == 'function') 4904 ? (length--, customizer) 4905 : undefined; 4906 4907 if (guard && isIterateeCall(sources[0], sources[1], guard)) { 4908 customizer = length < 3 ? undefined : customizer; 4909 length = 1; 4910 } 4911 object = Object(object); 4912 while (++index < length) { 4913 var source = sources[index]; 4914 if (source) { 4915 assigner(object, source, index, customizer); 4916 } 4917 } 4918 return object; 4919 }); 4920 } 4921 4922 /** 4923 * Creates a `baseEach` or `baseEachRight` function. 4924 * 4925 * @private 4926 * @param {Function} eachFunc The function to iterate over a collection. 4927 * @param {boolean} [fromRight] Specify iterating from right to left. 4928 * @returns {Function} Returns the new base function. 4929 */ 4930 function createBaseEach(eachFunc, fromRight) { 4931 return function(collection, iteratee) { 4932 if (collection == null) { 4933 return collection; 4934 } 4935 if (!isArrayLike(collection)) { 4936 return eachFunc(collection, iteratee); 4937 } 4938 var length = collection.length, 4939 index = fromRight ? length : -1, 4940 iterable = Object(collection); 4941 4942 while ((fromRight ? index-- : ++index < length)) { 4943 if (iteratee(iterable[index], index, iterable) === false) { 4944 break; 4945 } 4946 } 4947 return collection; 4948 }; 4949 } 4950 4951 /** 4952 * Creates a base function for methods like `_.forIn` and `_.forOwn`. 4953 * 4954 * @private 4955 * @param {boolean} [fromRight] Specify iterating from right to left. 4956 * @returns {Function} Returns the new base function. 4957 */ 4958 function createBaseFor(fromRight) { 4959 return function(object, iteratee, keysFunc) { 4960 var index = -1, 4961 iterable = Object(object), 4962 props = keysFunc(object), 4963 length = props.length; 4964 4965 while (length--) { 4966 var key = props[fromRight ? length : ++index]; 4967 if (iteratee(iterable[key], key, iterable) === false) { 4968 break; 4969 } 4970 } 4971 return object; 4972 }; 4973 } 4974 4975 /** 4976 * Creates a function that wraps `func` to invoke it with the optional `this` 4977 * binding of `thisArg`. 4978 * 4979 * @private 4980 * @param {Function} func The function to wrap. 4981 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 4982 * @param {*} [thisArg] The `this` binding of `func`. 4983 * @returns {Function} Returns the new wrapped function. 4984 */ 4985 function createBind(func, bitmask, thisArg) { 4986 var isBind = bitmask & WRAP_BIND_FLAG, 4987 Ctor = createCtor(func); 4988 4989 function wrapper() { 4990 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; 4991 return fn.apply(isBind ? thisArg : this, arguments); 4992 } 4993 return wrapper; 4994 } 4995 4996 /** 4997 * Creates a function like `_.lowerFirst`. 4998 * 4999 * @private 5000 * @param {string} methodName The name of the `String` case method to use. 5001 * @returns {Function} Returns the new case function. 5002 */ 5003 function createCaseFirst(methodName) { 5004 return function(string) { 5005 string = toString(string); 5006 5007 var strSymbols = hasUnicode(string) 5008 ? stringToArray(string) 5009 : undefined; 5010 5011 var chr = strSymbols 5012 ? strSymbols[0] 5013 : string.charAt(0); 5014 5015 var trailing = strSymbols 5016 ? castSlice(strSymbols, 1).join('') 5017 : string.slice(1); 5018 5019 return chr[methodName]() + trailing; 5020 }; 5021 } 5022 5023 /** 5024 * Creates a function like `_.camelCase`. 5025 * 5026 * @private 5027 * @param {Function} callback The function to combine each word. 5028 * @returns {Function} Returns the new compounder function. 5029 */ 5030 function createCompounder(callback) { 5031 return function(string) { 5032 return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); 5033 }; 5034 } 5035 5036 /** 5037 * Creates a function that produces an instance of `Ctor` regardless of 5038 * whether it was invoked as part of a `new` expression or by `call` or `apply`. 5039 * 5040 * @private 5041 * @param {Function} Ctor The constructor to wrap. 5042 * @returns {Function} Returns the new wrapped function. 5043 */ 5044 function createCtor(Ctor) { 5045 return function() { 5046 // Use a `switch` statement to work with class constructors. See 5047 // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist 5048 // for more details. 5049 var args = arguments; 5050 switch (args.length) { 5051 case 0: return new Ctor; 5052 case 1: return new Ctor(args[0]); 5053 case 2: return new Ctor(args[0], args[1]); 5054 case 3: return new Ctor(args[0], args[1], args[2]); 5055 case 4: return new Ctor(args[0], args[1], args[2], args[3]); 5056 case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); 5057 case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); 5058 case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); 5059 } 5060 var thisBinding = baseCreate(Ctor.prototype), 5061 result = Ctor.apply(thisBinding, args); 5062 5063 // Mimic the constructor's `return` behavior. 5064 // See https://es5.github.io/#x13.2.2 for more details. 5065 return isObject(result) ? result : thisBinding; 5066 }; 5067 } 5068 5069 /** 5070 * Creates a function that wraps `func` to enable currying. 5071 * 5072 * @private 5073 * @param {Function} func The function to wrap. 5074 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 5075 * @param {number} arity The arity of `func`. 5076 * @returns {Function} Returns the new wrapped function. 5077 */ 5078 function createCurry(func, bitmask, arity) { 5079 var Ctor = createCtor(func); 5080 5081 function wrapper() { 5082 var length = arguments.length, 5083 args = Array(length), 5084 index = length, 5085 placeholder = getHolder(wrapper); 5086 5087 while (index--) { 5088 args[index] = arguments[index]; 5089 } 5090 var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) 5091 ? [] 5092 : replaceHolders(args, placeholder); 5093 5094 length -= holders.length; 5095 if (length < arity) { 5096 return createRecurry( 5097 func, bitmask, createHybrid, wrapper.placeholder, undefined, 5098 args, holders, undefined, undefined, arity - length); 5099 } 5100 var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; 5101 return apply(fn, this, args); 5102 } 5103 return wrapper; 5104 } 5105 5106 /** 5107 * Creates a `_.find` or `_.findLast` function. 5108 * 5109 * @private 5110 * @param {Function} findIndexFunc The function to find the collection index. 5111 * @returns {Function} Returns the new find function. 5112 */ 5113 function createFind(findIndexFunc) { 5114 return function(collection, predicate, fromIndex) { 5115 var iterable = Object(collection); 5116 if (!isArrayLike(collection)) { 5117 var iteratee = getIteratee(predicate, 3); 5118 collection = keys(collection); 5119 predicate = function(key) { return iteratee(iterable[key], key, iterable); }; 5120 } 5121 var index = findIndexFunc(collection, predicate, fromIndex); 5122 return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; 5123 }; 5124 } 5125 5126 /** 5127 * Creates a `_.flow` or `_.flowRight` function. 5128 * 5129 * @private 5130 * @param {boolean} [fromRight] Specify iterating from right to left. 5131 * @returns {Function} Returns the new flow function. 5132 */ 5133 function createFlow(fromRight) { 5134 return flatRest(function(funcs) { 5135 var length = funcs.length, 5136 index = length, 5137 prereq = LodashWrapper.prototype.thru; 5138 5139 if (fromRight) { 5140 funcs.reverse(); 5141 } 5142 while (index--) { 5143 var func = funcs[index]; 5144 if (typeof func != 'function') { 5145 throw new TypeError(FUNC_ERROR_TEXT); 5146 } 5147 if (prereq && !wrapper && getFuncName(func) == 'wrapper') { 5148 var wrapper = new LodashWrapper([], true); 5149 } 5150 } 5151 index = wrapper ? index : length; 5152 while (++index < length) { 5153 func = funcs[index]; 5154 5155 var funcName = getFuncName(func), 5156 data = funcName == 'wrapper' ? getData(func) : undefined; 5157 5158 if (data && isLaziable(data[0]) && 5159 data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) && 5160 !data[4].length && data[9] == 1 5161 ) { 5162 wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); 5163 } else { 5164 wrapper = (func.length == 1 && isLaziable(func)) 5165 ? wrapper[funcName]() 5166 : wrapper.thru(func); 5167 } 5168 } 5169 return function() { 5170 var args = arguments, 5171 value = args[0]; 5172 5173 if (wrapper && args.length == 1 && isArray(value)) { 5174 return wrapper.plant(value).value(); 5175 } 5176 var index = 0, 5177 result = length ? funcs[index].apply(this, args) : value; 5178 5179 while (++index < length) { 5180 result = funcs[index].call(this, result); 5181 } 5182 return result; 5183 }; 5184 }); 5185 } 5186 5187 /** 5188 * Creates a function that wraps `func` to invoke it with optional `this` 5189 * binding of `thisArg`, partial application, and currying. 5190 * 5191 * @private 5192 * @param {Function|string} func The function or method name to wrap. 5193 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 5194 * @param {*} [thisArg] The `this` binding of `func`. 5195 * @param {Array} [partials] The arguments to prepend to those provided to 5196 * the new function. 5197 * @param {Array} [holders] The `partials` placeholder indexes. 5198 * @param {Array} [partialsRight] The arguments to append to those provided 5199 * to the new function. 5200 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes. 5201 * @param {Array} [argPos] The argument positions of the new function. 5202 * @param {number} [ary] The arity cap of `func`. 5203 * @param {number} [arity] The arity of `func`. 5204 * @returns {Function} Returns the new wrapped function. 5205 */ 5206 function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { 5207 var isAry = bitmask & WRAP_ARY_FLAG, 5208 isBind = bitmask & WRAP_BIND_FLAG, 5209 isBindKey = bitmask & WRAP_BIND_KEY_FLAG, 5210 isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), 5211 isFlip = bitmask & WRAP_FLIP_FLAG, 5212 Ctor = isBindKey ? undefined : createCtor(func); 5213 5214 function wrapper() { 5215 var length = arguments.length, 5216 args = Array(length), 5217 index = length; 5218 5219 while (index--) { 5220 args[index] = arguments[index]; 5221 } 5222 if (isCurried) { 5223 var placeholder = getHolder(wrapper), 5224 holdersCount = countHolders(args, placeholder); 5225 } 5226 if (partials) { 5227 args = composeArgs(args, partials, holders, isCurried); 5228 } 5229 if (partialsRight) { 5230 args = composeArgsRight(args, partialsRight, holdersRight, isCurried); 5231 } 5232 length -= holdersCount; 5233 if (isCurried && length < arity) { 5234 var newHolders = replaceHolders(args, placeholder); 5235 return createRecurry( 5236 func, bitmask, createHybrid, wrapper.placeholder, thisArg, 5237 args, newHolders, argPos, ary, arity - length 5238 ); 5239 } 5240 var thisBinding = isBind ? thisArg : this, 5241 fn = isBindKey ? thisBinding[func] : func; 5242 5243 length = args.length; 5244 if (argPos) { 5245 args = reorder(args, argPos); 5246 } else if (isFlip && length > 1) { 5247 args.reverse(); 5248 } 5249 if (isAry && ary < length) { 5250 args.length = ary; 5251 } 5252 if (this && this !== root && this instanceof wrapper) { 5253 fn = Ctor || createCtor(fn); 5254 } 5255 return fn.apply(thisBinding, args); 5256 } 5257 return wrapper; 5258 } 5259 5260 /** 5261 * Creates a function like `_.invertBy`. 5262 * 5263 * @private 5264 * @param {Function} setter The function to set accumulator values. 5265 * @param {Function} toIteratee The function to resolve iteratees. 5266 * @returns {Function} Returns the new inverter function. 5267 */ 5268 function createInverter(setter, toIteratee) { 5269 return function(object, iteratee) { 5270 return baseInverter(object, setter, toIteratee(iteratee), {}); 5271 }; 5272 } 5273 5274 /** 5275 * Creates a function that performs a mathematical operation on two values. 5276 * 5277 * @private 5278 * @param {Function} operator The function to perform the operation. 5279 * @param {number} [defaultValue] The value used for `undefined` arguments. 5280 * @returns {Function} Returns the new mathematical operation function. 5281 */ 5282 function createMathOperation(operator, defaultValue) { 5283 return function(value, other) { 5284 var result; 5285 if (value === undefined && other === undefined) { 5286 return defaultValue; 5287 } 5288 if (value !== undefined) { 5289 result = value; 5290 } 5291 if (other !== undefined) { 5292 if (result === undefined) { 5293 return other; 5294 } 5295 if (typeof value == 'string' || typeof other == 'string') { 5296 value = baseToString(value); 5297 other = baseToString(other); 5298 } else { 5299 value = baseToNumber(value); 5300 other = baseToNumber(other); 5301 } 5302 result = operator(value, other); 5303 } 5304 return result; 5305 }; 5306 } 5307 5308 /** 5309 * Creates a function like `_.over`. 5310 * 5311 * @private 5312 * @param {Function} arrayFunc The function to iterate over iteratees. 5313 * @returns {Function} Returns the new over function. 5314 */ 5315 function createOver(arrayFunc) { 5316 return flatRest(function(iteratees) { 5317 iteratees = arrayMap(iteratees, baseUnary(getIteratee())); 5318 return baseRest(function(args) { 5319 var thisArg = this; 5320 return arrayFunc(iteratees, function(iteratee) { 5321 return apply(iteratee, thisArg, args); 5322 }); 5323 }); 5324 }); 5325 } 5326 5327 /** 5328 * Creates the padding for `string` based on `length`. The `chars` string 5329 * is truncated if the number of characters exceeds `length`. 5330 * 5331 * @private 5332 * @param {number} length The padding length. 5333 * @param {string} [chars=' '] The string used as padding. 5334 * @returns {string} Returns the padding for `string`. 5335 */ 5336 function createPadding(length, chars) { 5337 chars = chars === undefined ? ' ' : baseToString(chars); 5338 5339 var charsLength = chars.length; 5340 if (charsLength < 2) { 5341 return charsLength ? baseRepeat(chars, length) : chars; 5342 } 5343 var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); 5344 return hasUnicode(chars) 5345 ? castSlice(stringToArray(result), 0, length).join('') 5346 : result.slice(0, length); 5347 } 5348 5349 /** 5350 * Creates a function that wraps `func` to invoke it with the `this` binding 5351 * of `thisArg` and `partials` prepended to the arguments it receives. 5352 * 5353 * @private 5354 * @param {Function} func The function to wrap. 5355 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 5356 * @param {*} thisArg The `this` binding of `func`. 5357 * @param {Array} partials The arguments to prepend to those provided to 5358 * the new function. 5359 * @returns {Function} Returns the new wrapped function. 5360 */ 5361 function createPartial(func, bitmask, thisArg, partials) { 5362 var isBind = bitmask & WRAP_BIND_FLAG, 5363 Ctor = createCtor(func); 5364 5365 function wrapper() { 5366 var argsIndex = -1, 5367 argsLength = arguments.length, 5368 leftIndex = -1, 5369 leftLength = partials.length, 5370 args = Array(leftLength + argsLength), 5371 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; 5372 5373 while (++leftIndex < leftLength) { 5374 args[leftIndex] = partials[leftIndex]; 5375 } 5376 while (argsLength--) { 5377 args[leftIndex++] = arguments[++argsIndex]; 5378 } 5379 return apply(fn, isBind ? thisArg : this, args); 5380 } 5381 return wrapper; 5382 } 5383 5384 /** 5385 * Creates a `_.range` or `_.rangeRight` function. 5386 * 5387 * @private 5388 * @param {boolean} [fromRight] Specify iterating from right to left. 5389 * @returns {Function} Returns the new range function. 5390 */ 5391 function createRange(fromRight) { 5392 return function(start, end, step) { 5393 if (step && typeof step != 'number' && isIterateeCall(start, end, step)) { 5394 end = step = undefined; 5395 } 5396 // Ensure the sign of `-0` is preserved. 5397 start = toFinite(start); 5398 if (end === undefined) { 5399 end = start; 5400 start = 0; 5401 } else { 5402 end = toFinite(end); 5403 } 5404 step = step === undefined ? (start < end ? 1 : -1) : toFinite(step); 5405 return baseRange(start, end, step, fromRight); 5406 }; 5407 } 5408 5409 /** 5410 * Creates a function that performs a relational operation on two values. 5411 * 5412 * @private 5413 * @param {Function} operator The function to perform the operation. 5414 * @returns {Function} Returns the new relational operation function. 5415 */ 5416 function createRelationalOperation(operator) { 5417 return function(value, other) { 5418 if (!(typeof value == 'string' && typeof other == 'string')) { 5419 value = toNumber(value); 5420 other = toNumber(other); 5421 } 5422 return operator(value, other); 5423 }; 5424 } 5425 5426 /** 5427 * Creates a function that wraps `func` to continue currying. 5428 * 5429 * @private 5430 * @param {Function} func The function to wrap. 5431 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 5432 * @param {Function} wrapFunc The function to create the `func` wrapper. 5433 * @param {*} placeholder The placeholder value. 5434 * @param {*} [thisArg] The `this` binding of `func`. 5435 * @param {Array} [partials] The arguments to prepend to those provided to 5436 * the new function. 5437 * @param {Array} [holders] The `partials` placeholder indexes. 5438 * @param {Array} [argPos] The argument positions of the new function. 5439 * @param {number} [ary] The arity cap of `func`. 5440 * @param {number} [arity] The arity of `func`. 5441 * @returns {Function} Returns the new wrapped function. 5442 */ 5443 function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { 5444 var isCurry = bitmask & WRAP_CURRY_FLAG, 5445 newHolders = isCurry ? holders : undefined, 5446 newHoldersRight = isCurry ? undefined : holders, 5447 newPartials = isCurry ? partials : undefined, 5448 newPartialsRight = isCurry ? undefined : partials; 5449 5450 bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); 5451 bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); 5452 5453 if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) { 5454 bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG); 5455 } 5456 var newData = [ 5457 func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, 5458 newHoldersRight, argPos, ary, arity 5459 ]; 5460 5461 var result = wrapFunc.apply(undefined, newData); 5462 if (isLaziable(func)) { 5463 setData(result, newData); 5464 } 5465 result.placeholder = placeholder; 5466 return setWrapToString(result, func, bitmask); 5467 } 5468 5469 /** 5470 * Creates a function like `_.round`. 5471 * 5472 * @private 5473 * @param {string} methodName The name of the `Math` method to use when rounding. 5474 * @returns {Function} Returns the new round function. 5475 */ 5476 function createRound(methodName) { 5477 var func = Math[methodName]; 5478 return function(number, precision) { 5479 number = toNumber(number); 5480 precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); 5481 if (precision && nativeIsFinite(number)) { 5482 // Shift with exponential notation to avoid floating-point issues. 5483 // See [MDN](https://mdn.io/round#Examples) for more details. 5484 var pair = (toString(number) + 'e').split('e'), 5485 value = func(pair[0] + 'e' + (+pair[1] + precision)); 5486 5487 pair = (toString(value) + 'e').split('e'); 5488 return +(pair[0] + 'e' + (+pair[1] - precision)); 5489 } 5490 return func(number); 5491 }; 5492 } 5493 5494 /** 5495 * Creates a set object of `values`. 5496 * 5497 * @private 5498 * @param {Array} values The values to add to the set. 5499 * @returns {Object} Returns the new set. 5500 */ 5501 var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { 5502 return new Set(values); 5503 }; 5504 5505 /** 5506 * Creates a `_.toPairs` or `_.toPairsIn` function. 5507 * 5508 * @private 5509 * @param {Function} keysFunc The function to get the keys of a given object. 5510 * @returns {Function} Returns the new pairs function. 5511 */ 5512 function createToPairs(keysFunc) { 5513 return function(object) { 5514 var tag = getTag(object); 5515 if (tag == mapTag) { 5516 return mapToArray(object); 5517 } 5518 if (tag == setTag) { 5519 return setToPairs(object); 5520 } 5521 return baseToPairs(object, keysFunc(object)); 5522 }; 5523 } 5524 5525 /** 5526 * Creates a function that either curries or invokes `func` with optional 5527 * `this` binding and partially applied arguments. 5528 * 5529 * @private 5530 * @param {Function|string} func The function or method name to wrap. 5531 * @param {number} bitmask The bitmask flags. 5532 * 1 - `_.bind` 5533 * 2 - `_.bindKey` 5534 * 4 - `_.curry` or `_.curryRight` of a bound function 5535 * 8 - `_.curry` 5536 * 16 - `_.curryRight` 5537 * 32 - `_.partial` 5538 * 64 - `_.partialRight` 5539 * 128 - `_.rearg` 5540 * 256 - `_.ary` 5541 * 512 - `_.flip` 5542 * @param {*} [thisArg] The `this` binding of `func`. 5543 * @param {Array} [partials] The arguments to be partially applied. 5544 * @param {Array} [holders] The `partials` placeholder indexes. 5545 * @param {Array} [argPos] The argument positions of the new function. 5546 * @param {number} [ary] The arity cap of `func`. 5547 * @param {number} [arity] The arity of `func`. 5548 * @returns {Function} Returns the new wrapped function. 5549 */ 5550 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { 5551 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG; 5552 if (!isBindKey && typeof func != 'function') { 5553 throw new TypeError(FUNC_ERROR_TEXT); 5554 } 5555 var length = partials ? partials.length : 0; 5556 if (!length) { 5557 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG); 5558 partials = holders = undefined; 5559 } 5560 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0); 5561 arity = arity === undefined ? arity : toInteger(arity); 5562 length -= holders ? holders.length : 0; 5563 5564 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) { 5565 var partialsRight = partials, 5566 holdersRight = holders; 5567 5568 partials = holders = undefined; 5569 } 5570 var data = isBindKey ? undefined : getData(func); 5571 5572 var newData = [ 5573 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, 5574 argPos, ary, arity 5575 ]; 5576 5577 if (data) { 5578 mergeData(newData, data); 5579 } 5580 func = newData[0]; 5581 bitmask = newData[1]; 5582 thisArg = newData[2]; 5583 partials = newData[3]; 5584 holders = newData[4]; 5585 arity = newData[9] = newData[9] === undefined 5586 ? (isBindKey ? 0 : func.length) 5587 : nativeMax(newData[9] - length, 0); 5588 5589 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) { 5590 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG); 5591 } 5592 if (!bitmask || bitmask == WRAP_BIND_FLAG) { 5593 var result = createBind(func, bitmask, thisArg); 5594 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) { 5595 result = createCurry(func, bitmask, arity); 5596 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) { 5597 result = createPartial(func, bitmask, thisArg, partials); 5598 } else { 5599 result = createHybrid.apply(undefined, newData); 5600 } 5601 var setter = data ? baseSetData : setData; 5602 return setWrapToString(setter(result, newData), func, bitmask); 5603 } 5604 5605 /** 5606 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties 5607 * of source objects to the destination object for all destination properties 5608 * that resolve to `undefined`. 5609 * 5610 * @private 5611 * @param {*} objValue The destination value. 5612 * @param {*} srcValue The source value. 5613 * @param {string} key The key of the property to assign. 5614 * @param {Object} object The parent object of `objValue`. 5615 * @returns {*} Returns the value to assign. 5616 */ 5617 function customDefaultsAssignIn(objValue, srcValue, key, object) { 5618 if (objValue === undefined || 5619 (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { 5620 return srcValue; 5621 } 5622 return objValue; 5623 } 5624 5625 /** 5626 * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source 5627 * objects into destination objects that are passed thru. 5628 * 5629 * @private 5630 * @param {*} objValue The destination value. 5631 * @param {*} srcValue The source value. 5632 * @param {string} key The key of the property to merge. 5633 * @param {Object} object The parent object of `objValue`. 5634 * @param {Object} source The parent object of `srcValue`. 5635 * @param {Object} [stack] Tracks traversed source values and their merged 5636 * counterparts. 5637 * @returns {*} Returns the value to assign. 5638 */ 5639 function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { 5640 if (isObject(objValue) && isObject(srcValue)) { 5641 // Recursively merge objects and arrays (susceptible to call stack limits). 5642 stack.set(srcValue, objValue); 5643 baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack); 5644 stack['delete'](srcValue); 5645 } 5646 return objValue; 5647 } 5648 5649 /** 5650 * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain 5651 * objects. 5652 * 5653 * @private 5654 * @param {*} value The value to inspect. 5655 * @param {string} key The key of the property to inspect. 5656 * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`. 5657 */ 5658 function customOmitClone(value) { 5659 return isPlainObject(value) ? undefined : value; 5660 } 5661 5662 /** 5663 * A specialized version of `baseIsEqualDeep` for arrays with support for 5664 * partial deep comparisons. 5665 * 5666 * @private 5667 * @param {Array} array The array to compare. 5668 * @param {Array} other The other array to compare. 5669 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 5670 * @param {Function} customizer The function to customize comparisons. 5671 * @param {Function} equalFunc The function to determine equivalents of values. 5672 * @param {Object} stack Tracks traversed `array` and `other` objects. 5673 * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. 5674 */ 5675 function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { 5676 var isPartial = bitmask & COMPARE_PARTIAL_FLAG, 5677 arrLength = array.length, 5678 othLength = other.length; 5679 5680 if (arrLength != othLength && !(isPartial && othLength > arrLength)) { 5681 return false; 5682 } 5683 // Check that cyclic values are equal. 5684 var arrStacked = stack.get(array); 5685 var othStacked = stack.get(other); 5686 if (arrStacked && othStacked) { 5687 return arrStacked == other && othStacked == array; 5688 } 5689 var index = -1, 5690 result = true, 5691 seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined; 5692 5693 stack.set(array, other); 5694 stack.set(other, array); 5695 5696 // Ignore non-index properties. 5697 while (++index < arrLength) { 5698 var arrValue = array[index], 5699 othValue = other[index]; 5700 5701 if (customizer) { 5702 var compared = isPartial 5703 ? customizer(othValue, arrValue, index, other, array, stack) 5704 : customizer(arrValue, othValue, index, array, other, stack); 5705 } 5706 if (compared !== undefined) { 5707 if (compared) { 5708 continue; 5709 } 5710 result = false; 5711 break; 5712 } 5713 // Recursively compare arrays (susceptible to call stack limits). 5714 if (seen) { 5715 if (!arraySome(other, function(othValue, othIndex) { 5716 if (!cacheHas(seen, othIndex) && 5717 (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { 5718 return seen.push(othIndex); 5719 } 5720 })) { 5721 result = false; 5722 break; 5723 } 5724 } else if (!( 5725 arrValue === othValue || 5726 equalFunc(arrValue, othValue, bitmask, customizer, stack) 5727 )) { 5728 result = false; 5729 break; 5730 } 5731 } 5732 stack['delete'](array); 5733 stack['delete'](other); 5734 return result; 5735 } 5736 5737 /** 5738 * A specialized version of `baseIsEqualDeep` for comparing objects of 5739 * the same `toStringTag`. 5740 * 5741 * **Note:** This function only supports comparing values with tags of 5742 * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. 5743 * 5744 * @private 5745 * @param {Object} object The object to compare. 5746 * @param {Object} other The other object to compare. 5747 * @param {string} tag The `toStringTag` of the objects to compare. 5748 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 5749 * @param {Function} customizer The function to customize comparisons. 5750 * @param {Function} equalFunc The function to determine equivalents of values. 5751 * @param {Object} stack Tracks traversed `object` and `other` objects. 5752 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. 5753 */ 5754 function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { 5755 switch (tag) { 5756 case dataViewTag: 5757 if ((object.byteLength != other.byteLength) || 5758 (object.byteOffset != other.byteOffset)) { 5759 return false; 5760 } 5761 object = object.buffer; 5762 other = other.buffer; 5763 5764 case arrayBufferTag: 5765 if ((object.byteLength != other.byteLength) || 5766 !equalFunc(new Uint8Array(object), new Uint8Array(other))) { 5767 return false; 5768 } 5769 return true; 5770 5771 case boolTag: 5772 case dateTag: 5773 case numberTag: 5774 // Coerce booleans to `1` or `0` and dates to milliseconds. 5775 // Invalid dates are coerced to `NaN`. 5776 return eq(+object, +other); 5777 5778 case errorTag: 5779 return object.name == other.name && object.message == other.message; 5780 5781 case regexpTag: 5782 case stringTag: 5783 // Coerce regexes to strings and treat strings, primitives and objects, 5784 // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring 5785 // for more details. 5786 return object == (other + ''); 5787 5788 case mapTag: 5789 var convert = mapToArray; 5790 5791 case setTag: 5792 var isPartial = bitmask & COMPARE_PARTIAL_FLAG; 5793 convert || (convert = setToArray); 5794 5795 if (object.size != other.size && !isPartial) { 5796 return false; 5797 } 5798 // Assume cyclic values are equal. 5799 var stacked = stack.get(object); 5800 if (stacked) { 5801 return stacked == other; 5802 } 5803 bitmask |= COMPARE_UNORDERED_FLAG; 5804 5805 // Recursively compare objects (susceptible to call stack limits). 5806 stack.set(object, other); 5807 var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack); 5808 stack['delete'](object); 5809 return result; 5810 5811 case symbolTag: 5812 if (symbolValueOf) { 5813 return symbolValueOf.call(object) == symbolValueOf.call(other); 5814 } 5815 } 5816 return false; 5817 } 5818 5819 /** 5820 * A specialized version of `baseIsEqualDeep` for objects with support for 5821 * partial deep comparisons. 5822 * 5823 * @private 5824 * @param {Object} object The object to compare. 5825 * @param {Object} other The other object to compare. 5826 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. 5827 * @param {Function} customizer The function to customize comparisons. 5828 * @param {Function} equalFunc The function to determine equivalents of values. 5829 * @param {Object} stack Tracks traversed `object` and `other` objects. 5830 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. 5831 */ 5832 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { 5833 var isPartial = bitmask & COMPARE_PARTIAL_FLAG, 5834 objProps = getAllKeys(object), 5835 objLength = objProps.length, 5836 othProps = getAllKeys(other), 5837 othLength = othProps.length; 5838 5839 if (objLength != othLength && !isPartial) { 5840 return false; 5841 } 5842 var index = objLength; 5843 while (index--) { 5844 var key = objProps[index]; 5845 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { 5846 return false; 5847 } 5848 } 5849 // Check that cyclic values are equal. 5850 var objStacked = stack.get(object); 5851 var othStacked = stack.get(other); 5852 if (objStacked && othStacked) { 5853 return objStacked == other && othStacked == object; 5854 } 5855 var result = true; 5856 stack.set(object, other); 5857 stack.set(other, object); 5858 5859 var skipCtor = isPartial; 5860 while (++index < objLength) { 5861 key = objProps[index]; 5862 var objValue = object[key], 5863 othValue = other[key]; 5864 5865 if (customizer) { 5866 var compared = isPartial 5867 ? customizer(othValue, objValue, key, other, object, stack) 5868 : customizer(objValue, othValue, key, object, other, stack); 5869 } 5870 // Recursively compare objects (susceptible to call stack limits). 5871 if (!(compared === undefined 5872 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) 5873 : compared 5874 )) { 5875 result = false; 5876 break; 5877 } 5878 skipCtor || (skipCtor = key == 'constructor'); 5879 } 5880 if (result && !skipCtor) { 5881 var objCtor = object.constructor, 5882 othCtor = other.constructor; 5883 5884 // Non `Object` object instances with different constructors are not equal. 5885 if (objCtor != othCtor && 5886 ('constructor' in object && 'constructor' in other) && 5887 !(typeof objCtor == 'function' && objCtor instanceof objCtor && 5888 typeof othCtor == 'function' && othCtor instanceof othCtor)) { 5889 result = false; 5890 } 5891 } 5892 stack['delete'](object); 5893 stack['delete'](other); 5894 return result; 5895 } 5896 5897 /** 5898 * A specialized version of `baseRest` which flattens the rest array. 5899 * 5900 * @private 5901 * @param {Function} func The function to apply a rest parameter to. 5902 * @returns {Function} Returns the new function. 5903 */ 5904 function flatRest(func) { 5905 return setToString(overRest(func, undefined, flatten), func + ''); 5906 } 5907 5908 /** 5909 * Creates an array of own enumerable property names and symbols of `object`. 5910 * 5911 * @private 5912 * @param {Object} object The object to query. 5913 * @returns {Array} Returns the array of property names and symbols. 5914 */ 5915 function getAllKeys(object) { 5916 return baseGetAllKeys(object, keys, getSymbols); 5917 } 5918 5919 /** 5920 * Creates an array of own and inherited enumerable property names and 5921 * symbols of `object`. 5922 * 5923 * @private 5924 * @param {Object} object The object to query. 5925 * @returns {Array} Returns the array of property names and symbols. 5926 */ 5927 function getAllKeysIn(object) { 5928 return baseGetAllKeys(object, keysIn, getSymbolsIn); 5929 } 5930 5931 /** 5932 * Gets metadata for `func`. 5933 * 5934 * @private 5935 * @param {Function} func The function to query. 5936 * @returns {*} Returns the metadata for `func`. 5937 */ 5938 var getData = !metaMap ? noop : function(func) { 5939 return metaMap.get(func); 5940 }; 5941 5942 /** 5943 * Gets the name of `func`. 5944 * 5945 * @private 5946 * @param {Function} func The function to query. 5947 * @returns {string} Returns the function name. 5948 */ 5949 function getFuncName(func) { 5950 var result = (func.name + ''), 5951 array = realNames[result], 5952 length = hasOwnProperty.call(realNames, result) ? array.length : 0; 5953 5954 while (length--) { 5955 var data = array[length], 5956 otherFunc = data.func; 5957 if (otherFunc == null || otherFunc == func) { 5958 return data.name; 5959 } 5960 } 5961 return result; 5962 } 5963 5964 /** 5965 * Gets the argument placeholder value for `func`. 5966 * 5967 * @private 5968 * @param {Function} func The function to inspect. 5969 * @returns {*} Returns the placeholder value. 5970 */ 5971 function getHolder(func) { 5972 var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func; 5973 return object.placeholder; 5974 } 5975 5976 /** 5977 * Gets the appropriate "iteratee" function. If `_.iteratee` is customized, 5978 * this function returns the custom method, otherwise it returns `baseIteratee`. 5979 * If arguments are provided, the chosen function is invoked with them and 5980 * its result is returned. 5981 * 5982 * @private 5983 * @param {*} [value] The value to convert to an iteratee. 5984 * @param {number} [arity] The arity of the created iteratee. 5985 * @returns {Function} Returns the chosen function or its result. 5986 */ 5987 function getIteratee() { 5988 var result = lodash.iteratee || iteratee; 5989 result = result === iteratee ? baseIteratee : result; 5990 return arguments.length ? result(arguments[0], arguments[1]) : result; 5991 } 5992 5993 /** 5994 * Gets the data for `map`. 5995 * 5996 * @private 5997 * @param {Object} map The map to query. 5998 * @param {string} key The reference key. 5999 * @returns {*} Returns the map data. 6000 */ 6001 function getMapData(map, key) { 6002 var data = map.__data__; 6003 return isKeyable(key) 6004 ? data[typeof key == 'string' ? 'string' : 'hash'] 6005 : data.map; 6006 } 6007 6008 /** 6009 * Gets the property names, values, and compare flags of `object`. 6010 * 6011 * @private 6012 * @param {Object} object The object to query. 6013 * @returns {Array} Returns the match data of `object`. 6014 */ 6015 function getMatchData(object) { 6016 var result = keys(object), 6017 length = result.length; 6018 6019 while (length--) { 6020 var key = result[length], 6021 value = object[key]; 6022 6023 result[length] = [key, value, isStrictComparable(value)]; 6024 } 6025 return result; 6026 } 6027 6028 /** 6029 * Gets the native function at `key` of `object`. 6030 * 6031 * @private 6032 * @param {Object} object The object to query. 6033 * @param {string} key The key of the method to get. 6034 * @returns {*} Returns the function if it's native, else `undefined`. 6035 */ 6036 function getNative(object, key) { 6037 var value = getValue(object, key); 6038 return baseIsNative(value) ? value : undefined; 6039 } 6040 6041 /** 6042 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. 6043 * 6044 * @private 6045 * @param {*} value The value to query. 6046 * @returns {string} Returns the raw `toStringTag`. 6047 */ 6048 function getRawTag(value) { 6049 var isOwn = hasOwnProperty.call(value, symToStringTag), 6050 tag = value[symToStringTag]; 6051 6052 try { 6053 value[symToStringTag] = undefined; 6054 var unmasked = true; 6055 } catch (e) {} 6056 6057 var result = nativeObjectToString.call(value); 6058 if (unmasked) { 6059 if (isOwn) { 6060 value[symToStringTag] = tag; 6061 } else { 6062 delete value[symToStringTag]; 6063 } 6064 } 6065 return result; 6066 } 6067 6068 /** 6069 * Creates an array of the own enumerable symbols of `object`. 6070 * 6071 * @private 6072 * @param {Object} object The object to query. 6073 * @returns {Array} Returns the array of symbols. 6074 */ 6075 var getSymbols = !nativeGetSymbols ? stubArray : function(object) { 6076 if (object == null) { 6077 return []; 6078 } 6079 object = Object(object); 6080 return arrayFilter(nativeGetSymbols(object), function(symbol) { 6081 return propertyIsEnumerable.call(object, symbol); 6082 }); 6083 }; 6084 6085 /** 6086 * Creates an array of the own and inherited enumerable symbols of `object`. 6087 * 6088 * @private 6089 * @param {Object} object The object to query. 6090 * @returns {Array} Returns the array of symbols. 6091 */ 6092 var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) { 6093 var result = []; 6094 while (object) { 6095 arrayPush(result, getSymbols(object)); 6096 object = getPrototype(object); 6097 } 6098 return result; 6099 }; 6100 6101 /** 6102 * Gets the `toStringTag` of `value`. 6103 * 6104 * @private 6105 * @param {*} value The value to query. 6106 * @returns {string} Returns the `toStringTag`. 6107 */ 6108 var getTag = baseGetTag; 6109 6110 // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. 6111 if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || 6112 (Map && getTag(new Map) != mapTag) || 6113 (Promise && getTag(Promise.resolve()) != promiseTag) || 6114 (Set && getTag(new Set) != setTag) || 6115 (WeakMap && getTag(new WeakMap) != weakMapTag)) { 6116 getTag = function(value) { 6117 var result = baseGetTag(value), 6118 Ctor = result == objectTag ? value.constructor : undefined, 6119 ctorString = Ctor ? toSource(Ctor) : ''; 6120 6121 if (ctorString) { 6122 switch (ctorString) { 6123 case dataViewCtorString: return dataViewTag; 6124 case mapCtorString: return mapTag; 6125 case promiseCtorString: return promiseTag; 6126 case setCtorString: return setTag; 6127 case weakMapCtorString: return weakMapTag; 6128 } 6129 } 6130 return result; 6131 }; 6132 } 6133 6134 /** 6135 * Gets the view, applying any `transforms` to the `start` and `end` positions. 6136 * 6137 * @private 6138 * @param {number} start The start of the view. 6139 * @param {number} end The end of the view. 6140 * @param {Array} transforms The transformations to apply to the view. 6141 * @returns {Object} Returns an object containing the `start` and `end` 6142 * positions of the view. 6143 */ 6144 function getView(start, end, transforms) { 6145 var index = -1, 6146 length = transforms.length; 6147 6148 while (++index < length) { 6149 var data = transforms[index], 6150 size = data.size; 6151 6152 switch (data.type) { 6153 case 'drop': start += size; break; 6154 case 'dropRight': end -= size; break; 6155 case 'take': end = nativeMin(end, start + size); break; 6156 case 'takeRight': start = nativeMax(start, end - size); break; 6157 } 6158 } 6159 return { 'start': start, 'end': end }; 6160 } 6161 6162 /** 6163 * Extracts wrapper details from the `source` body comment. 6164 * 6165 * @private 6166 * @param {string} source The source to inspect. 6167 * @returns {Array} Returns the wrapper details. 6168 */ 6169 function getWrapDetails(source) { 6170 var match = source.match(reWrapDetails); 6171 return match ? match[1].split(reSplitDetails) : []; 6172 } 6173 6174 /** 6175 * Checks if `path` exists on `object`. 6176 * 6177 * @private 6178 * @param {Object} object The object to query. 6179 * @param {Array|string} path The path to check. 6180 * @param {Function} hasFunc The function to check properties. 6181 * @returns {boolean} Returns `true` if `path` exists, else `false`. 6182 */ 6183 function hasPath(object, path, hasFunc) { 6184 path = castPath(path, object); 6185 6186 var index = -1, 6187 length = path.length, 6188 result = false; 6189 6190 while (++index < length) { 6191 var key = toKey(path[index]); 6192 if (!(result = object != null && hasFunc(object, key))) { 6193 break; 6194 } 6195 object = object[key]; 6196 } 6197 if (result || ++index != length) { 6198 return result; 6199 } 6200 length = object == null ? 0 : object.length; 6201 return !!length && isLength(length) && isIndex(key, length) && 6202 (isArray(object) || isArguments(object)); 6203 } 6204 6205 /** 6206 * Initializes an array clone. 6207 * 6208 * @private 6209 * @param {Array} array The array to clone. 6210 * @returns {Array} Returns the initialized clone. 6211 */ 6212 function initCloneArray(array) { 6213 var length = array.length, 6214 result = new array.constructor(length); 6215 6216 // Add properties assigned by `RegExp#exec`. 6217 if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { 6218 result.index = array.index; 6219 result.input = array.input; 6220 } 6221 return result; 6222 } 6223 6224 /** 6225 * Initializes an object clone. 6226 * 6227 * @private 6228 * @param {Object} object The object to clone. 6229 * @returns {Object} Returns the initialized clone. 6230 */ 6231 function initCloneObject(object) { 6232 return (typeof object.constructor == 'function' && !isPrototype(object)) 6233 ? baseCreate(getPrototype(object)) 6234 : {}; 6235 } 6236 6237 /** 6238 * Initializes an object clone based on its `toStringTag`. 6239 * 6240 * **Note:** This function only supports cloning values with tags of 6241 * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. 6242 * 6243 * @private 6244 * @param {Object} object The object to clone. 6245 * @param {string} tag The `toStringTag` of the object to clone. 6246 * @param {boolean} [isDeep] Specify a deep clone. 6247 * @returns {Object} Returns the initialized clone. 6248 */ 6249 function initCloneByTag(object, tag, isDeep) { 6250 var Ctor = object.constructor; 6251 switch (tag) { 6252 case arrayBufferTag: 6253 return cloneArrayBuffer(object); 6254 6255 case boolTag: 6256 case dateTag: 6257 return new Ctor(+object); 6258 6259 case dataViewTag: 6260 return cloneDataView(object, isDeep); 6261 6262 case float32Tag: case float64Tag: 6263 case int8Tag: case int16Tag: case int32Tag: 6264 case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: 6265 return cloneTypedArray(object, isDeep); 6266 6267 case mapTag: 6268 return new Ctor; 6269 6270 case numberTag: 6271 case stringTag: 6272 return new Ctor(object); 6273 6274 case regexpTag: 6275 return cloneRegExp(object); 6276 6277 case setTag: 6278 return new Ctor; 6279 6280 case symbolTag: 6281 return cloneSymbol(object); 6282 } 6283 } 6284 6285 /** 6286 * Inserts wrapper `details` in a comment at the top of the `source` body. 6287 * 6288 * @private 6289 * @param {string} source The source to modify. 6290 * @returns {Array} details The details to insert. 6291 * @returns {string} Returns the modified source. 6292 */ 6293 function insertWrapDetails(source, details) { 6294 var length = details.length; 6295 if (!length) { 6296 return source; 6297 } 6298 var lastIndex = length - 1; 6299 details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; 6300 details = details.join(length > 2 ? ', ' : ' '); 6301 return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); 6302 } 6303 6304 /** 6305 * Checks if `value` is a flattenable `arguments` object or array. 6306 * 6307 * @private 6308 * @param {*} value The value to check. 6309 * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. 6310 */ 6311 function isFlattenable(value) { 6312 return isArray(value) || isArguments(value) || 6313 !!(spreadableSymbol && value && value[spreadableSymbol]); 6314 } 6315 6316 /** 6317 * Checks if `value` is a valid array-like index. 6318 * 6319 * @private 6320 * @param {*} value The value to check. 6321 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. 6322 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. 6323 */ 6324 function isIndex(value, length) { 6325 var type = typeof value; 6326 length = length == null ? MAX_SAFE_INTEGER : length; 6327 6328 return !!length && 6329 (type == 'number' || 6330 (type != 'symbol' && reIsUint.test(value))) && 6331 (value > -1 && value % 1 == 0 && value < length); 6332 } 6333 6334 /** 6335 * Checks if the given arguments are from an iteratee call. 6336 * 6337 * @private 6338 * @param {*} value The potential iteratee value argument. 6339 * @param {*} index The potential iteratee index or key argument. 6340 * @param {*} object The potential iteratee object argument. 6341 * @returns {boolean} Returns `true` if the arguments are from an iteratee call, 6342 * else `false`. 6343 */ 6344 function isIterateeCall(value, index, object) { 6345 if (!isObject(object)) { 6346 return false; 6347 } 6348 var type = typeof index; 6349 if (type == 'number' 6350 ? (isArrayLike(object) && isIndex(index, object.length)) 6351 : (type == 'string' && index in object) 6352 ) { 6353 return eq(object[index], value); 6354 } 6355 return false; 6356 } 6357 6358 /** 6359 * Checks if `value` is a property name and not a property path. 6360 * 6361 * @private 6362 * @param {*} value The value to check. 6363 * @param {Object} [object] The object to query keys on. 6364 * @returns {boolean} Returns `true` if `value` is a property name, else `false`. 6365 */ 6366 function isKey(value, object) { 6367 if (isArray(value)) { 6368 return false; 6369 } 6370 var type = typeof value; 6371 if (type == 'number' || type == 'symbol' || type == 'boolean' || 6372 value == null || isSymbol(value)) { 6373 return true; 6374 } 6375 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || 6376 (object != null && value in Object(object)); 6377 } 6378 6379 /** 6380 * Checks if `value` is suitable for use as unique object key. 6381 * 6382 * @private 6383 * @param {*} value The value to check. 6384 * @returns {boolean} Returns `true` if `value` is suitable, else `false`. 6385 */ 6386 function isKeyable(value) { 6387 var type = typeof value; 6388 return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') 6389 ? (value !== '__proto__') 6390 : (value === null); 6391 } 6392 6393 /** 6394 * Checks if `func` has a lazy counterpart. 6395 * 6396 * @private 6397 * @param {Function} func The function to check. 6398 * @returns {boolean} Returns `true` if `func` has a lazy counterpart, 6399 * else `false`. 6400 */ 6401 function isLaziable(func) { 6402 var funcName = getFuncName(func), 6403 other = lodash[funcName]; 6404 6405 if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) { 6406 return false; 6407 } 6408 if (func === other) { 6409 return true; 6410 } 6411 var data = getData(other); 6412 return !!data && func === data[0]; 6413 } 6414 6415 /** 6416 * Checks if `func` has its source masked. 6417 * 6418 * @private 6419 * @param {Function} func The function to check. 6420 * @returns {boolean} Returns `true` if `func` is masked, else `false`. 6421 */ 6422 function isMasked(func) { 6423 return !!maskSrcKey && (maskSrcKey in func); 6424 } 6425 6426 /** 6427 * Checks if `func` is capable of being masked. 6428 * 6429 * @private 6430 * @param {*} value The value to check. 6431 * @returns {boolean} Returns `true` if `func` is maskable, else `false`. 6432 */ 6433 var isMaskable = coreJsData ? isFunction : stubFalse; 6434 6435 /** 6436 * Checks if `value` is likely a prototype object. 6437 * 6438 * @private 6439 * @param {*} value The value to check. 6440 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. 6441 */ 6442 function isPrototype(value) { 6443 var Ctor = value && value.constructor, 6444 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; 6445 6446 return value === proto; 6447 } 6448 6449 /** 6450 * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. 6451 * 6452 * @private 6453 * @param {*} value The value to check. 6454 * @returns {boolean} Returns `true` if `value` if suitable for strict 6455 * equality comparisons, else `false`. 6456 */ 6457 function isStrictComparable(value) { 6458 return value === value && !isObject(value); 6459 } 6460 6461 /** 6462 * A specialized version of `matchesProperty` for source values suitable 6463 * for strict equality comparisons, i.e. `===`. 6464 * 6465 * @private 6466 * @param {string} key The key of the property to get. 6467 * @param {*} srcValue The value to match. 6468 * @returns {Function} Returns the new spec function. 6469 */ 6470 function matchesStrictComparable(key, srcValue) { 6471 return function(object) { 6472 if (object == null) { 6473 return false; 6474 } 6475 return object[key] === srcValue && 6476 (srcValue !== undefined || (key in Object(object))); 6477 }; 6478 } 6479 6480 /** 6481 * A specialized version of `_.memoize` which clears the memoized function's 6482 * cache when it exceeds `MAX_MEMOIZE_SIZE`. 6483 * 6484 * @private 6485 * @param {Function} func The function to have its output memoized. 6486 * @returns {Function} Returns the new memoized function. 6487 */ 6488 function memoizeCapped(func) { 6489 var result = memoize(func, function(key) { 6490 if (cache.size === MAX_MEMOIZE_SIZE) { 6491 cache.clear(); 6492 } 6493 return key; 6494 }); 6495 6496 var cache = result.cache; 6497 return result; 6498 } 6499 6500 /** 6501 * Merges the function metadata of `source` into `data`. 6502 * 6503 * Merging metadata reduces the number of wrappers used to invoke a function. 6504 * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` 6505 * may be applied regardless of execution order. Methods like `_.ary` and 6506 * `_.rearg` modify function arguments, making the order in which they are 6507 * executed important, preventing the merging of metadata. However, we make 6508 * an exception for a safe combined case where curried functions have `_.ary` 6509 * and or `_.rearg` applied. 6510 * 6511 * @private 6512 * @param {Array} data The destination metadata. 6513 * @param {Array} source The source metadata. 6514 * @returns {Array} Returns `data`. 6515 */ 6516 function mergeData(data, source) { 6517 var bitmask = data[1], 6518 srcBitmask = source[1], 6519 newBitmask = bitmask | srcBitmask, 6520 isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG); 6521 6522 var isCombo = 6523 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) || 6524 ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) || 6525 ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG)); 6526 6527 // Exit early if metadata can't be merged. 6528 if (!(isCommon || isCombo)) { 6529 return data; 6530 } 6531 // Use source `thisArg` if available. 6532 if (srcBitmask & WRAP_BIND_FLAG) { 6533 data[2] = source[2]; 6534 // Set when currying a bound function. 6535 newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG; 6536 } 6537 // Compose partial arguments. 6538 var value = source[3]; 6539 if (value) { 6540 var partials = data[3]; 6541 data[3] = partials ? composeArgs(partials, value, source[4]) : value; 6542 data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; 6543 } 6544 // Compose partial right arguments. 6545 value = source[5]; 6546 if (value) { 6547 partials = data[5]; 6548 data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; 6549 data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; 6550 } 6551 // Use source `argPos` if available. 6552 value = source[7]; 6553 if (value) { 6554 data[7] = value; 6555 } 6556 // Use source `ary` if it's smaller. 6557 if (srcBitmask & WRAP_ARY_FLAG) { 6558 data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); 6559 } 6560 // Use source `arity` if one is not provided. 6561 if (data[9] == null) { 6562 data[9] = source[9]; 6563 } 6564 // Use source `func` and merge bitmasks. 6565 data[0] = source[0]; 6566 data[1] = newBitmask; 6567 6568 return data; 6569 } 6570 6571 /** 6572 * This function is like 6573 * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) 6574 * except that it includes inherited enumerable properties. 6575 * 6576 * @private 6577 * @param {Object} object The object to query. 6578 * @returns {Array} Returns the array of property names. 6579 */ 6580 function nativeKeysIn(object) { 6581 var result = []; 6582 if (object != null) { 6583 for (var key in Object(object)) { 6584 result.push(key); 6585 } 6586 } 6587 return result; 6588 } 6589 6590 /** 6591 * Converts `value` to a string using `Object.prototype.toString`. 6592 * 6593 * @private 6594 * @param {*} value The value to convert. 6595 * @returns {string} Returns the converted string. 6596 */ 6597 function objectToString(value) { 6598 return nativeObjectToString.call(value); 6599 } 6600 6601 /** 6602 * A specialized version of `baseRest` which transforms the rest array. 6603 * 6604 * @private 6605 * @param {Function} func The function to apply a rest parameter to. 6606 * @param {number} [start=func.length-1] The start position of the rest parameter. 6607 * @param {Function} transform The rest array transform. 6608 * @returns {Function} Returns the new function. 6609 */ 6610 function overRest(func, start, transform) { 6611 start = nativeMax(start === undefined ? (func.length - 1) : start, 0); 6612 return function() { 6613 var args = arguments, 6614 index = -1, 6615 length = nativeMax(args.length - start, 0), 6616 array = Array(length); 6617 6618 while (++index < length) { 6619 array[index] = args[start + index]; 6620 } 6621 index = -1; 6622 var otherArgs = Array(start + 1); 6623 while (++index < start) { 6624 otherArgs[index] = args[index]; 6625 } 6626 otherArgs[start] = transform(array); 6627 return apply(func, this, otherArgs); 6628 }; 6629 } 6630 6631 /** 6632 * Gets the parent value at `path` of `object`. 6633 * 6634 * @private 6635 * @param {Object} object The object to query. 6636 * @param {Array} path The path to get the parent value of. 6637 * @returns {*} Returns the parent value. 6638 */ 6639 function parent(object, path) { 6640 return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1)); 6641 } 6642 6643 /** 6644 * Reorder `array` according to the specified indexes where the element at 6645 * the first index is assigned as the first element, the element at 6646 * the second index is assigned as the second element, and so on. 6647 * 6648 * @private 6649 * @param {Array} array The array to reorder. 6650 * @param {Array} indexes The arranged array indexes. 6651 * @returns {Array} Returns `array`. 6652 */ 6653 function reorder(array, indexes) { 6654 var arrLength = array.length, 6655 length = nativeMin(indexes.length, arrLength), 6656 oldArray = copyArray(array); 6657 6658 while (length--) { 6659 var index = indexes[length]; 6660 array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined; 6661 } 6662 return array; 6663 } 6664 6665 /** 6666 * Gets the value at `key`, unless `key` is "__proto__" or "constructor". 6667 * 6668 * @private 6669 * @param {Object} object The object to query. 6670 * @param {string} key The key of the property to get. 6671 * @returns {*} Returns the property value. 6672 */ 6673 function safeGet(object, key) { 6674 if (key === 'constructor' && typeof object[key] === 'function') { 6675 return; 6676 } 6677 6678 if (key == '__proto__') { 6679 return; 6680 } 6681 6682 return object[key]; 6683 } 6684 6685 /** 6686 * Sets metadata for `func`. 6687 * 6688 * **Note:** If this function becomes hot, i.e. is invoked a lot in a short 6689 * period of time, it will trip its breaker and transition to an identity 6690 * function to avoid garbage collection pauses in V8. See 6691 * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070) 6692 * for more details. 6693 * 6694 * @private 6695 * @param {Function} func The function to associate metadata with. 6696 * @param {*} data The metadata. 6697 * @returns {Function} Returns `func`. 6698 */ 6699 var setData = shortOut(baseSetData); 6700 6701 /** 6702 * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout). 6703 * 6704 * @private 6705 * @param {Function} func The function to delay. 6706 * @param {number} wait The number of milliseconds to delay invocation. 6707 * @returns {number|Object} Returns the timer id or timeout object. 6708 */ 6709 var setTimeout = ctxSetTimeout || function(func, wait) { 6710 return root.setTimeout(func, wait); 6711 }; 6712 6713 /** 6714 * Sets the `toString` method of `func` to return `string`. 6715 * 6716 * @private 6717 * @param {Function} func The function to modify. 6718 * @param {Function} string The `toString` result. 6719 * @returns {Function} Returns `func`. 6720 */ 6721 var setToString = shortOut(baseSetToString); 6722 6723 /** 6724 * Sets the `toString` method of `wrapper` to mimic the source of `reference` 6725 * with wrapper details in a comment at the top of the source body. 6726 * 6727 * @private 6728 * @param {Function} wrapper The function to modify. 6729 * @param {Function} reference The reference function. 6730 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 6731 * @returns {Function} Returns `wrapper`. 6732 */ 6733 function setWrapToString(wrapper, reference, bitmask) { 6734 var source = (reference + ''); 6735 return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask))); 6736 } 6737 6738 /** 6739 * Creates a function that'll short out and invoke `identity` instead 6740 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` 6741 * milliseconds. 6742 * 6743 * @private 6744 * @param {Function} func The function to restrict. 6745 * @returns {Function} Returns the new shortable function. 6746 */ 6747 function shortOut(func) { 6748 var count = 0, 6749 lastCalled = 0; 6750 6751 return function() { 6752 var stamp = nativeNow(), 6753 remaining = HOT_SPAN - (stamp - lastCalled); 6754 6755 lastCalled = stamp; 6756 if (remaining > 0) { 6757 if (++count >= HOT_COUNT) { 6758 return arguments[0]; 6759 } 6760 } else { 6761 count = 0; 6762 } 6763 return func.apply(undefined, arguments); 6764 }; 6765 } 6766 6767 /** 6768 * A specialized version of `_.shuffle` which mutates and sets the size of `array`. 6769 * 6770 * @private 6771 * @param {Array} array The array to shuffle. 6772 * @param {number} [size=array.length] The size of `array`. 6773 * @returns {Array} Returns `array`. 6774 */ 6775 function shuffleSelf(array, size) { 6776 var index = -1, 6777 length = array.length, 6778 lastIndex = length - 1; 6779 6780 size = size === undefined ? length : size; 6781 while (++index < size) { 6782 var rand = baseRandom(index, lastIndex), 6783 value = array[rand]; 6784 6785 array[rand] = array[index]; 6786 array[index] = value; 6787 } 6788 array.length = size; 6789 return array; 6790 } 6791 6792 /** 6793 * Converts `string` to a property path array. 6794 * 6795 * @private 6796 * @param {string} string The string to convert. 6797 * @returns {Array} Returns the property path array. 6798 */ 6799 var stringToPath = memoizeCapped(function(string) { 6800 var result = []; 6801 if (string.charCodeAt(0) === 46 /* . */) { 6802 result.push(''); 6803 } 6804 string.replace(rePropName, function(match, number, quote, subString) { 6805 result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); 6806 }); 6807 return result; 6808 }); 6809 6810 /** 6811 * Converts `value` to a string key if it's not a string or symbol. 6812 * 6813 * @private 6814 * @param {*} value The value to inspect. 6815 * @returns {string|symbol} Returns the key. 6816 */ 6817 function toKey(value) { 6818 if (typeof value == 'string' || isSymbol(value)) { 6819 return value; 6820 } 6821 var result = (value + ''); 6822 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; 6823 } 6824 6825 /** 6826 * Converts `func` to its source code. 6827 * 6828 * @private 6829 * @param {Function} func The function to convert. 6830 * @returns {string} Returns the source code. 6831 */ 6832 function toSource(func) { 6833 if (func != null) { 6834 try { 6835 return funcToString.call(func); 6836 } catch (e) {} 6837 try { 6838 return (func + ''); 6839 } catch (e) {} 6840 } 6841 return ''; 6842 } 6843 6844 /** 6845 * Updates wrapper `details` based on `bitmask` flags. 6846 * 6847 * @private 6848 * @returns {Array} details The details to modify. 6849 * @param {number} bitmask The bitmask flags. See `createWrap` for more details. 6850 * @returns {Array} Returns `details`. 6851 */ 6852 function updateWrapDetails(details, bitmask) { 6853 arrayEach(wrapFlags, function(pair) { 6854 var value = '_.' + pair[0]; 6855 if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { 6856 details.push(value); 6857 } 6858 }); 6859 return details.sort(); 6860 } 6861 6862 /** 6863 * Creates a clone of `wrapper`. 6864 * 6865 * @private 6866 * @param {Object} wrapper The wrapper to clone. 6867 * @returns {Object} Returns the cloned wrapper. 6868 */ 6869 function wrapperClone(wrapper) { 6870 if (wrapper instanceof LazyWrapper) { 6871 return wrapper.clone(); 6872 } 6873 var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); 6874 result.__actions__ = copyArray(wrapper.__actions__); 6875 result.__index__ = wrapper.__index__; 6876 result.__values__ = wrapper.__values__; 6877 return result; 6878 } 6879 6880 /*------------------------------------------------------------------------*/ 6881 6882 /** 6883 * Creates an array of elements split into groups the length of `size`. 6884 * If `array` can't be split evenly, the final chunk will be the remaining 6885 * elements. 6886 * 6887 * @static 6888 * @memberOf _ 6889 * @since 3.0.0 6890 * @category Array 6891 * @param {Array} array The array to process. 6892 * @param {number} [size=1] The length of each chunk 6893 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 6894 * @returns {Array} Returns the new array of chunks. 6895 * @example 6896 * 6897 * _.chunk(['a', 'b', 'c', 'd'], 2); 6898 * // => [['a', 'b'], ['c', 'd']] 6899 * 6900 * _.chunk(['a', 'b', 'c', 'd'], 3); 6901 * // => [['a', 'b', 'c'], ['d']] 6902 */ 6903 function chunk(array, size, guard) { 6904 if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) { 6905 size = 1; 6906 } else { 6907 size = nativeMax(toInteger(size), 0); 6908 } 6909 var length = array == null ? 0 : array.length; 6910 if (!length || size < 1) { 6911 return []; 6912 } 6913 var index = 0, 6914 resIndex = 0, 6915 result = Array(nativeCeil(length / size)); 6916 6917 while (index < length) { 6918 result[resIndex++] = baseSlice(array, index, (index += size)); 6919 } 6920 return result; 6921 } 6922 6923 /** 6924 * Creates an array with all falsey values removed. The values `false`, `null`, 6925 * `0`, `""`, `undefined`, and `NaN` are falsey. 6926 * 6927 * @static 6928 * @memberOf _ 6929 * @since 0.1.0 6930 * @category Array 6931 * @param {Array} array The array to compact. 6932 * @returns {Array} Returns the new array of filtered values. 6933 * @example 6934 * 6935 * _.compact([0, 1, false, 2, '', 3]); 6936 * // => [1, 2, 3] 6937 */ 6938 function compact(array) { 6939 var index = -1, 6940 length = array == null ? 0 : array.length, 6941 resIndex = 0, 6942 result = []; 6943 6944 while (++index < length) { 6945 var value = array[index]; 6946 if (value) { 6947 result[resIndex++] = value; 6948 } 6949 } 6950 return result; 6951 } 6952 6953 /** 6954 * Creates a new array concatenating `array` with any additional arrays 6955 * and/or values. 6956 * 6957 * @static 6958 * @memberOf _ 6959 * @since 4.0.0 6960 * @category Array 6961 * @param {Array} array The array to concatenate. 6962 * @param {...*} [values] The values to concatenate. 6963 * @returns {Array} Returns the new concatenated array. 6964 * @example 6965 * 6966 * var array = [1]; 6967 * var other = _.concat(array, 2, [3], [[4]]); 6968 * 6969 * console.log(other); 6970 * // => [1, 2, 3, [4]] 6971 * 6972 * console.log(array); 6973 * // => [1] 6974 */ 6975 function concat() { 6976 var length = arguments.length; 6977 if (!length) { 6978 return []; 6979 } 6980 var args = Array(length - 1), 6981 array = arguments[0], 6982 index = length; 6983 6984 while (index--) { 6985 args[index - 1] = arguments[index]; 6986 } 6987 return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); 6988 } 6989 6990 /** 6991 * Creates an array of `array` values not included in the other given arrays 6992 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 6993 * for equality comparisons. The order and references of result values are 6994 * determined by the first array. 6995 * 6996 * **Note:** Unlike `_.pullAll`, this method returns a new array. 6997 * 6998 * @static 6999 * @memberOf _ 7000 * @since 0.1.0 7001 * @category Array 7002 * @param {Array} array The array to inspect. 7003 * @param {...Array} [values] The values to exclude. 7004 * @returns {Array} Returns the new array of filtered values. 7005 * @see _.without, _.xor 7006 * @example 7007 * 7008 * _.difference([2, 1], [2, 3]); 7009 * // => [1] 7010 */ 7011 var difference = baseRest(function(array, values) { 7012 return isArrayLikeObject(array) 7013 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) 7014 : []; 7015 }); 7016 7017 /** 7018 * This method is like `_.difference` except that it accepts `iteratee` which 7019 * is invoked for each element of `array` and `values` to generate the criterion 7020 * by which they're compared. The order and references of result values are 7021 * determined by the first array. The iteratee is invoked with one argument: 7022 * (value). 7023 * 7024 * **Note:** Unlike `_.pullAllBy`, this method returns a new array. 7025 * 7026 * @static 7027 * @memberOf _ 7028 * @since 4.0.0 7029 * @category Array 7030 * @param {Array} array The array to inspect. 7031 * @param {...Array} [values] The values to exclude. 7032 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 7033 * @returns {Array} Returns the new array of filtered values. 7034 * @example 7035 * 7036 * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); 7037 * // => [1.2] 7038 * 7039 * // The `_.property` iteratee shorthand. 7040 * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); 7041 * // => [{ 'x': 2 }] 7042 */ 7043 var differenceBy = baseRest(function(array, values) { 7044 var iteratee = last(values); 7045 if (isArrayLikeObject(iteratee)) { 7046 iteratee = undefined; 7047 } 7048 return isArrayLikeObject(array) 7049 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) 7050 : []; 7051 }); 7052 7053 /** 7054 * This method is like `_.difference` except that it accepts `comparator` 7055 * which is invoked to compare elements of `array` to `values`. The order and 7056 * references of result values are determined by the first array. The comparator 7057 * is invoked with two arguments: (arrVal, othVal). 7058 * 7059 * **Note:** Unlike `_.pullAllWith`, this method returns a new array. 7060 * 7061 * @static 7062 * @memberOf _ 7063 * @since 4.0.0 7064 * @category Array 7065 * @param {Array} array The array to inspect. 7066 * @param {...Array} [values] The values to exclude. 7067 * @param {Function} [comparator] The comparator invoked per element. 7068 * @returns {Array} Returns the new array of filtered values. 7069 * @example 7070 * 7071 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 7072 * 7073 * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); 7074 * // => [{ 'x': 2, 'y': 1 }] 7075 */ 7076 var differenceWith = baseRest(function(array, values) { 7077 var comparator = last(values); 7078 if (isArrayLikeObject(comparator)) { 7079 comparator = undefined; 7080 } 7081 return isArrayLikeObject(array) 7082 ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator) 7083 : []; 7084 }); 7085 7086 /** 7087 * Creates a slice of `array` with `n` elements dropped from the beginning. 7088 * 7089 * @static 7090 * @memberOf _ 7091 * @since 0.5.0 7092 * @category Array 7093 * @param {Array} array The array to query. 7094 * @param {number} [n=1] The number of elements to drop. 7095 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 7096 * @returns {Array} Returns the slice of `array`. 7097 * @example 7098 * 7099 * _.drop([1, 2, 3]); 7100 * // => [2, 3] 7101 * 7102 * _.drop([1, 2, 3], 2); 7103 * // => [3] 7104 * 7105 * _.drop([1, 2, 3], 5); 7106 * // => [] 7107 * 7108 * _.drop([1, 2, 3], 0); 7109 * // => [1, 2, 3] 7110 */ 7111 function drop(array, n, guard) { 7112 var length = array == null ? 0 : array.length; 7113 if (!length) { 7114 return []; 7115 } 7116 n = (guard || n === undefined) ? 1 : toInteger(n); 7117 return baseSlice(array, n < 0 ? 0 : n, length); 7118 } 7119 7120 /** 7121 * Creates a slice of `array` with `n` elements dropped from the end. 7122 * 7123 * @static 7124 * @memberOf _ 7125 * @since 3.0.0 7126 * @category Array 7127 * @param {Array} array The array to query. 7128 * @param {number} [n=1] The number of elements to drop. 7129 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 7130 * @returns {Array} Returns the slice of `array`. 7131 * @example 7132 * 7133 * _.dropRight([1, 2, 3]); 7134 * // => [1, 2] 7135 * 7136 * _.dropRight([1, 2, 3], 2); 7137 * // => [1] 7138 * 7139 * _.dropRight([1, 2, 3], 5); 7140 * // => [] 7141 * 7142 * _.dropRight([1, 2, 3], 0); 7143 * // => [1, 2, 3] 7144 */ 7145 function dropRight(array, n, guard) { 7146 var length = array == null ? 0 : array.length; 7147 if (!length) { 7148 return []; 7149 } 7150 n = (guard || n === undefined) ? 1 : toInteger(n); 7151 n = length - n; 7152 return baseSlice(array, 0, n < 0 ? 0 : n); 7153 } 7154 7155 /** 7156 * Creates a slice of `array` excluding elements dropped from the end. 7157 * Elements are dropped until `predicate` returns falsey. The predicate is 7158 * invoked with three arguments: (value, index, array). 7159 * 7160 * @static 7161 * @memberOf _ 7162 * @since 3.0.0 7163 * @category Array 7164 * @param {Array} array The array to query. 7165 * @param {Function} [predicate=_.identity] The function invoked per iteration. 7166 * @returns {Array} Returns the slice of `array`. 7167 * @example 7168 * 7169 * var users = [ 7170 * { 'user': 'barney', 'active': true }, 7171 * { 'user': 'fred', 'active': false }, 7172 * { 'user': 'pebbles', 'active': false } 7173 * ]; 7174 * 7175 * _.dropRightWhile(users, function(o) { return !o.active; }); 7176 * // => objects for ['barney'] 7177 * 7178 * // The `_.matches` iteratee shorthand. 7179 * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); 7180 * // => objects for ['barney', 'fred'] 7181 * 7182 * // The `_.matchesProperty` iteratee shorthand. 7183 * _.dropRightWhile(users, ['active', false]); 7184 * // => objects for ['barney'] 7185 * 7186 * // The `_.property` iteratee shorthand. 7187 * _.dropRightWhile(users, 'active'); 7188 * // => objects for ['barney', 'fred', 'pebbles'] 7189 */ 7190 function dropRightWhile(array, predicate) { 7191 return (array && array.length) 7192 ? baseWhile(array, getIteratee(predicate, 3), true, true) 7193 : []; 7194 } 7195 7196 /** 7197 * Creates a slice of `array` excluding elements dropped from the beginning. 7198 * Elements are dropped until `predicate` returns falsey. The predicate is 7199 * invoked with three arguments: (value, index, array). 7200 * 7201 * @static 7202 * @memberOf _ 7203 * @since 3.0.0 7204 * @category Array 7205 * @param {Array} array The array to query. 7206 * @param {Function} [predicate=_.identity] The function invoked per iteration. 7207 * @returns {Array} Returns the slice of `array`. 7208 * @example 7209 * 7210 * var users = [ 7211 * { 'user': 'barney', 'active': false }, 7212 * { 'user': 'fred', 'active': false }, 7213 * { 'user': 'pebbles', 'active': true } 7214 * ]; 7215 * 7216 * _.dropWhile(users, function(o) { return !o.active; }); 7217 * // => objects for ['pebbles'] 7218 * 7219 * // The `_.matches` iteratee shorthand. 7220 * _.dropWhile(users, { 'user': 'barney', 'active': false }); 7221 * // => objects for ['fred', 'pebbles'] 7222 * 7223 * // The `_.matchesProperty` iteratee shorthand. 7224 * _.dropWhile(users, ['active', false]); 7225 * // => objects for ['pebbles'] 7226 * 7227 * // The `_.property` iteratee shorthand. 7228 * _.dropWhile(users, 'active'); 7229 * // => objects for ['barney', 'fred', 'pebbles'] 7230 */ 7231 function dropWhile(array, predicate) { 7232 return (array && array.length) 7233 ? baseWhile(array, getIteratee(predicate, 3), true) 7234 : []; 7235 } 7236 7237 /** 7238 * Fills elements of `array` with `value` from `start` up to, but not 7239 * including, `end`. 7240 * 7241 * **Note:** This method mutates `array`. 7242 * 7243 * @static 7244 * @memberOf _ 7245 * @since 3.2.0 7246 * @category Array 7247 * @param {Array} array The array to fill. 7248 * @param {*} value The value to fill `array` with. 7249 * @param {number} [start=0] The start position. 7250 * @param {number} [end=array.length] The end position. 7251 * @returns {Array} Returns `array`. 7252 * @example 7253 * 7254 * var array = [1, 2, 3]; 7255 * 7256 * _.fill(array, 'a'); 7257 * console.log(array); 7258 * // => ['a', 'a', 'a'] 7259 * 7260 * _.fill(Array(3), 2); 7261 * // => [2, 2, 2] 7262 * 7263 * _.fill([4, 6, 8, 10], '*', 1, 3); 7264 * // => [4, '*', '*', 10] 7265 */ 7266 function fill(array, value, start, end) { 7267 var length = array == null ? 0 : array.length; 7268 if (!length) { 7269 return []; 7270 } 7271 if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { 7272 start = 0; 7273 end = length; 7274 } 7275 return baseFill(array, value, start, end); 7276 } 7277 7278 /** 7279 * This method is like `_.find` except that it returns the index of the first 7280 * element `predicate` returns truthy for instead of the element itself. 7281 * 7282 * @static 7283 * @memberOf _ 7284 * @since 1.1.0 7285 * @category Array 7286 * @param {Array} array The array to inspect. 7287 * @param {Function} [predicate=_.identity] The function invoked per iteration. 7288 * @param {number} [fromIndex=0] The index to search from. 7289 * @returns {number} Returns the index of the found element, else `-1`. 7290 * @example 7291 * 7292 * var users = [ 7293 * { 'user': 'barney', 'active': false }, 7294 * { 'user': 'fred', 'active': false }, 7295 * { 'user': 'pebbles', 'active': true } 7296 * ]; 7297 * 7298 * _.findIndex(users, function(o) { return o.user == 'barney'; }); 7299 * // => 0 7300 * 7301 * // The `_.matches` iteratee shorthand. 7302 * _.findIndex(users, { 'user': 'fred', 'active': false }); 7303 * // => 1 7304 * 7305 * // The `_.matchesProperty` iteratee shorthand. 7306 * _.findIndex(users, ['active', false]); 7307 * // => 0 7308 * 7309 * // The `_.property` iteratee shorthand. 7310 * _.findIndex(users, 'active'); 7311 * // => 2 7312 */ 7313 function findIndex(array, predicate, fromIndex) { 7314 var length = array == null ? 0 : array.length; 7315 if (!length) { 7316 return -1; 7317 } 7318 var index = fromIndex == null ? 0 : toInteger(fromIndex); 7319 if (index < 0) { 7320 index = nativeMax(length + index, 0); 7321 } 7322 return baseFindIndex(array, getIteratee(predicate, 3), index); 7323 } 7324 7325 /** 7326 * This method is like `_.findIndex` except that it iterates over elements 7327 * of `collection` from right to left. 7328 * 7329 * @static 7330 * @memberOf _ 7331 * @since 2.0.0 7332 * @category Array 7333 * @param {Array} array The array to inspect. 7334 * @param {Function} [predicate=_.identity] The function invoked per iteration. 7335 * @param {number} [fromIndex=array.length-1] The index to search from. 7336 * @returns {number} Returns the index of the found element, else `-1`. 7337 * @example 7338 * 7339 * var users = [ 7340 * { 'user': 'barney', 'active': true }, 7341 * { 'user': 'fred', 'active': false }, 7342 * { 'user': 'pebbles', 'active': false } 7343 * ]; 7344 * 7345 * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); 7346 * // => 2 7347 * 7348 * // The `_.matches` iteratee shorthand. 7349 * _.findLastIndex(users, { 'user': 'barney', 'active': true }); 7350 * // => 0 7351 * 7352 * // The `_.matchesProperty` iteratee shorthand. 7353 * _.findLastIndex(users, ['active', false]); 7354 * // => 2 7355 * 7356 * // The `_.property` iteratee shorthand. 7357 * _.findLastIndex(users, 'active'); 7358 * // => 0 7359 */ 7360 function findLastIndex(array, predicate, fromIndex) { 7361 var length = array == null ? 0 : array.length; 7362 if (!length) { 7363 return -1; 7364 } 7365 var index = length - 1; 7366 if (fromIndex !== undefined) { 7367 index = toInteger(fromIndex); 7368 index = fromIndex < 0 7369 ? nativeMax(length + index, 0) 7370 : nativeMin(index, length - 1); 7371 } 7372 return baseFindIndex(array, getIteratee(predicate, 3), index, true); 7373 } 7374 7375 /** 7376 * Flattens `array` a single level deep. 7377 * 7378 * @static 7379 * @memberOf _ 7380 * @since 0.1.0 7381 * @category Array 7382 * @param {Array} array The array to flatten. 7383 * @returns {Array} Returns the new flattened array. 7384 * @example 7385 * 7386 * _.flatten([1, [2, [3, [4]], 5]]); 7387 * // => [1, 2, [3, [4]], 5] 7388 */ 7389 function flatten(array) { 7390 var length = array == null ? 0 : array.length; 7391 return length ? baseFlatten(array, 1) : []; 7392 } 7393 7394 /** 7395 * Recursively flattens `array`. 7396 * 7397 * @static 7398 * @memberOf _ 7399 * @since 3.0.0 7400 * @category Array 7401 * @param {Array} array The array to flatten. 7402 * @returns {Array} Returns the new flattened array. 7403 * @example 7404 * 7405 * _.flattenDeep([1, [2, [3, [4]], 5]]); 7406 * // => [1, 2, 3, 4, 5] 7407 */ 7408 function flattenDeep(array) { 7409 var length = array == null ? 0 : array.length; 7410 return length ? baseFlatten(array, INFINITY) : []; 7411 } 7412 7413 /** 7414 * Recursively flatten `array` up to `depth` times. 7415 * 7416 * @static 7417 * @memberOf _ 7418 * @since 4.4.0 7419 * @category Array 7420 * @param {Array} array The array to flatten. 7421 * @param {number} [depth=1] The maximum recursion depth. 7422 * @returns {Array} Returns the new flattened array. 7423 * @example 7424 * 7425 * var array = [1, [2, [3, [4]], 5]]; 7426 * 7427 * _.flattenDepth(array, 1); 7428 * // => [1, 2, [3, [4]], 5] 7429 * 7430 * _.flattenDepth(array, 2); 7431 * // => [1, 2, 3, [4], 5] 7432 */ 7433 function flattenDepth(array, depth) { 7434 var length = array == null ? 0 : array.length; 7435 if (!length) { 7436 return []; 7437 } 7438 depth = depth === undefined ? 1 : toInteger(depth); 7439 return baseFlatten(array, depth); 7440 } 7441 7442 /** 7443 * The inverse of `_.toPairs`; this method returns an object composed 7444 * from key-value `pairs`. 7445 * 7446 * @static 7447 * @memberOf _ 7448 * @since 4.0.0 7449 * @category Array 7450 * @param {Array} pairs The key-value pairs. 7451 * @returns {Object} Returns the new object. 7452 * @example 7453 * 7454 * _.fromPairs([['a', 1], ['b', 2]]); 7455 * // => { 'a': 1, 'b': 2 } 7456 */ 7457 function fromPairs(pairs) { 7458 var index = -1, 7459 length = pairs == null ? 0 : pairs.length, 7460 result = {}; 7461 7462 while (++index < length) { 7463 var pair = pairs[index]; 7464 result[pair[0]] = pair[1]; 7465 } 7466 return result; 7467 } 7468 7469 /** 7470 * Gets the first element of `array`. 7471 * 7472 * @static 7473 * @memberOf _ 7474 * @since 0.1.0 7475 * @alias first 7476 * @category Array 7477 * @param {Array} array The array to query. 7478 * @returns {*} Returns the first element of `array`. 7479 * @example 7480 * 7481 * _.head([1, 2, 3]); 7482 * // => 1 7483 * 7484 * _.head([]); 7485 * // => undefined 7486 */ 7487 function head(array) { 7488 return (array && array.length) ? array[0] : undefined; 7489 } 7490 7491 /** 7492 * Gets the index at which the first occurrence of `value` is found in `array` 7493 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 7494 * for equality comparisons. If `fromIndex` is negative, it's used as the 7495 * offset from the end of `array`. 7496 * 7497 * @static 7498 * @memberOf _ 7499 * @since 0.1.0 7500 * @category Array 7501 * @param {Array} array The array to inspect. 7502 * @param {*} value The value to search for. 7503 * @param {number} [fromIndex=0] The index to search from. 7504 * @returns {number} Returns the index of the matched value, else `-1`. 7505 * @example 7506 * 7507 * _.indexOf([1, 2, 1, 2], 2); 7508 * // => 1 7509 * 7510 * // Search from the `fromIndex`. 7511 * _.indexOf([1, 2, 1, 2], 2, 2); 7512 * // => 3 7513 */ 7514 function indexOf(array, value, fromIndex) { 7515 var length = array == null ? 0 : array.length; 7516 if (!length) { 7517 return -1; 7518 } 7519 var index = fromIndex == null ? 0 : toInteger(fromIndex); 7520 if (index < 0) { 7521 index = nativeMax(length + index, 0); 7522 } 7523 return baseIndexOf(array, value, index); 7524 } 7525 7526 /** 7527 * Gets all but the last element of `array`. 7528 * 7529 * @static 7530 * @memberOf _ 7531 * @since 0.1.0 7532 * @category Array 7533 * @param {Array} array The array to query. 7534 * @returns {Array} Returns the slice of `array`. 7535 * @example 7536 * 7537 * _.initial([1, 2, 3]); 7538 * // => [1, 2] 7539 */ 7540 function initial(array) { 7541 var length = array == null ? 0 : array.length; 7542 return length ? baseSlice(array, 0, -1) : []; 7543 } 7544 7545 /** 7546 * Creates an array of unique values that are included in all given arrays 7547 * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 7548 * for equality comparisons. The order and references of result values are 7549 * determined by the first array. 7550 * 7551 * @static 7552 * @memberOf _ 7553 * @since 0.1.0 7554 * @category Array 7555 * @param {...Array} [arrays] The arrays to inspect. 7556 * @returns {Array} Returns the new array of intersecting values. 7557 * @example 7558 * 7559 * _.intersection([2, 1], [2, 3]); 7560 * // => [2] 7561 */ 7562 var intersection = baseRest(function(arrays) { 7563 var mapped = arrayMap(arrays, castArrayLikeObject); 7564 return (mapped.length && mapped[0] === arrays[0]) 7565 ? baseIntersection(mapped) 7566 : []; 7567 }); 7568 7569 /** 7570 * This method is like `_.intersection` except that it accepts `iteratee` 7571 * which is invoked for each element of each `arrays` to generate the criterion 7572 * by which they're compared. The order and references of result values are 7573 * determined by the first array. The iteratee is invoked with one argument: 7574 * (value). 7575 * 7576 * @static 7577 * @memberOf _ 7578 * @since 4.0.0 7579 * @category Array 7580 * @param {...Array} [arrays] The arrays to inspect. 7581 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 7582 * @returns {Array} Returns the new array of intersecting values. 7583 * @example 7584 * 7585 * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); 7586 * // => [2.1] 7587 * 7588 * // The `_.property` iteratee shorthand. 7589 * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); 7590 * // => [{ 'x': 1 }] 7591 */ 7592 var intersectionBy = baseRest(function(arrays) { 7593 var iteratee = last(arrays), 7594 mapped = arrayMap(arrays, castArrayLikeObject); 7595 7596 if (iteratee === last(mapped)) { 7597 iteratee = undefined; 7598 } else { 7599 mapped.pop(); 7600 } 7601 return (mapped.length && mapped[0] === arrays[0]) 7602 ? baseIntersection(mapped, getIteratee(iteratee, 2)) 7603 : []; 7604 }); 7605 7606 /** 7607 * This method is like `_.intersection` except that it accepts `comparator` 7608 * which is invoked to compare elements of `arrays`. The order and references 7609 * of result values are determined by the first array. The comparator is 7610 * invoked with two arguments: (arrVal, othVal). 7611 * 7612 * @static 7613 * @memberOf _ 7614 * @since 4.0.0 7615 * @category Array 7616 * @param {...Array} [arrays] The arrays to inspect. 7617 * @param {Function} [comparator] The comparator invoked per element. 7618 * @returns {Array} Returns the new array of intersecting values. 7619 * @example 7620 * 7621 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 7622 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 7623 * 7624 * _.intersectionWith(objects, others, _.isEqual); 7625 * // => [{ 'x': 1, 'y': 2 }] 7626 */ 7627 var intersectionWith = baseRest(function(arrays) { 7628 var comparator = last(arrays), 7629 mapped = arrayMap(arrays, castArrayLikeObject); 7630 7631 comparator = typeof comparator == 'function' ? comparator : undefined; 7632 if (comparator) { 7633 mapped.pop(); 7634 } 7635 return (mapped.length && mapped[0] === arrays[0]) 7636 ? baseIntersection(mapped, undefined, comparator) 7637 : []; 7638 }); 7639 7640 /** 7641 * Converts all elements in `array` into a string separated by `separator`. 7642 * 7643 * @static 7644 * @memberOf _ 7645 * @since 4.0.0 7646 * @category Array 7647 * @param {Array} array The array to convert. 7648 * @param {string} [separator=','] The element separator. 7649 * @returns {string} Returns the joined string. 7650 * @example 7651 * 7652 * _.join(['a', 'b', 'c'], '~'); 7653 * // => 'a~b~c' 7654 */ 7655 function join(array, separator) { 7656 return array == null ? '' : nativeJoin.call(array, separator); 7657 } 7658 7659 /** 7660 * Gets the last element of `array`. 7661 * 7662 * @static 7663 * @memberOf _ 7664 * @since 0.1.0 7665 * @category Array 7666 * @param {Array} array The array to query. 7667 * @returns {*} Returns the last element of `array`. 7668 * @example 7669 * 7670 * _.last([1, 2, 3]); 7671 * // => 3 7672 */ 7673 function last(array) { 7674 var length = array == null ? 0 : array.length; 7675 return length ? array[length - 1] : undefined; 7676 } 7677 7678 /** 7679 * This method is like `_.indexOf` except that it iterates over elements of 7680 * `array` from right to left. 7681 * 7682 * @static 7683 * @memberOf _ 7684 * @since 0.1.0 7685 * @category Array 7686 * @param {Array} array The array to inspect. 7687 * @param {*} value The value to search for. 7688 * @param {number} [fromIndex=array.length-1] The index to search from. 7689 * @returns {number} Returns the index of the matched value, else `-1`. 7690 * @example 7691 * 7692 * _.lastIndexOf([1, 2, 1, 2], 2); 7693 * // => 3 7694 * 7695 * // Search from the `fromIndex`. 7696 * _.lastIndexOf([1, 2, 1, 2], 2, 2); 7697 * // => 1 7698 */ 7699 function lastIndexOf(array, value, fromIndex) { 7700 var length = array == null ? 0 : array.length; 7701 if (!length) { 7702 return -1; 7703 } 7704 var index = length; 7705 if (fromIndex !== undefined) { 7706 index = toInteger(fromIndex); 7707 index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1); 7708 } 7709 return value === value 7710 ? strictLastIndexOf(array, value, index) 7711 : baseFindIndex(array, baseIsNaN, index, true); 7712 } 7713 7714 /** 7715 * Gets the element at index `n` of `array`. If `n` is negative, the nth 7716 * element from the end is returned. 7717 * 7718 * @static 7719 * @memberOf _ 7720 * @since 4.11.0 7721 * @category Array 7722 * @param {Array} array The array to query. 7723 * @param {number} [n=0] The index of the element to return. 7724 * @returns {*} Returns the nth element of `array`. 7725 * @example 7726 * 7727 * var array = ['a', 'b', 'c', 'd']; 7728 * 7729 * _.nth(array, 1); 7730 * // => 'b' 7731 * 7732 * _.nth(array, -2); 7733 * // => 'c'; 7734 */ 7735 function nth(array, n) { 7736 return (array && array.length) ? baseNth(array, toInteger(n)) : undefined; 7737 } 7738 7739 /** 7740 * Removes all given values from `array` using 7741 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 7742 * for equality comparisons. 7743 * 7744 * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove` 7745 * to remove elements from an array by predicate. 7746 * 7747 * @static 7748 * @memberOf _ 7749 * @since 2.0.0 7750 * @category Array 7751 * @param {Array} array The array to modify. 7752 * @param {...*} [values] The values to remove. 7753 * @returns {Array} Returns `array`. 7754 * @example 7755 * 7756 * var array = ['a', 'b', 'c', 'a', 'b', 'c']; 7757 * 7758 * _.pull(array, 'a', 'c'); 7759 * console.log(array); 7760 * // => ['b', 'b'] 7761 */ 7762 var pull = baseRest(pullAll); 7763 7764 /** 7765 * This method is like `_.pull` except that it accepts an array of values to remove. 7766 * 7767 * **Note:** Unlike `_.difference`, this method mutates `array`. 7768 * 7769 * @static 7770 * @memberOf _ 7771 * @since 4.0.0 7772 * @category Array 7773 * @param {Array} array The array to modify. 7774 * @param {Array} values The values to remove. 7775 * @returns {Array} Returns `array`. 7776 * @example 7777 * 7778 * var array = ['a', 'b', 'c', 'a', 'b', 'c']; 7779 * 7780 * _.pullAll(array, ['a', 'c']); 7781 * console.log(array); 7782 * // => ['b', 'b'] 7783 */ 7784 function pullAll(array, values) { 7785 return (array && array.length && values && values.length) 7786 ? basePullAll(array, values) 7787 : array; 7788 } 7789 7790 /** 7791 * This method is like `_.pullAll` except that it accepts `iteratee` which is 7792 * invoked for each element of `array` and `values` to generate the criterion 7793 * by which they're compared. The iteratee is invoked with one argument: (value). 7794 * 7795 * **Note:** Unlike `_.differenceBy`, this method mutates `array`. 7796 * 7797 * @static 7798 * @memberOf _ 7799 * @since 4.0.0 7800 * @category Array 7801 * @param {Array} array The array to modify. 7802 * @param {Array} values The values to remove. 7803 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 7804 * @returns {Array} Returns `array`. 7805 * @example 7806 * 7807 * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; 7808 * 7809 * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x'); 7810 * console.log(array); 7811 * // => [{ 'x': 2 }] 7812 */ 7813 function pullAllBy(array, values, iteratee) { 7814 return (array && array.length && values && values.length) 7815 ? basePullAll(array, values, getIteratee(iteratee, 2)) 7816 : array; 7817 } 7818 7819 /** 7820 * This method is like `_.pullAll` except that it accepts `comparator` which 7821 * is invoked to compare elements of `array` to `values`. The comparator is 7822 * invoked with two arguments: (arrVal, othVal). 7823 * 7824 * **Note:** Unlike `_.differenceWith`, this method mutates `array`. 7825 * 7826 * @static 7827 * @memberOf _ 7828 * @since 4.6.0 7829 * @category Array 7830 * @param {Array} array The array to modify. 7831 * @param {Array} values The values to remove. 7832 * @param {Function} [comparator] The comparator invoked per element. 7833 * @returns {Array} Returns `array`. 7834 * @example 7835 * 7836 * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }]; 7837 * 7838 * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual); 7839 * console.log(array); 7840 * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] 7841 */ 7842 function pullAllWith(array, values, comparator) { 7843 return (array && array.length && values && values.length) 7844 ? basePullAll(array, values, undefined, comparator) 7845 : array; 7846 } 7847 7848 /** 7849 * Removes elements from `array` corresponding to `indexes` and returns an 7850 * array of removed elements. 7851 * 7852 * **Note:** Unlike `_.at`, this method mutates `array`. 7853 * 7854 * @static 7855 * @memberOf _ 7856 * @since 3.0.0 7857 * @category Array 7858 * @param {Array} array The array to modify. 7859 * @param {...(number|number[])} [indexes] The indexes of elements to remove. 7860 * @returns {Array} Returns the new array of removed elements. 7861 * @example 7862 * 7863 * var array = ['a', 'b', 'c', 'd']; 7864 * var pulled = _.pullAt(array, [1, 3]); 7865 * 7866 * console.log(array); 7867 * // => ['a', 'c'] 7868 * 7869 * console.log(pulled); 7870 * // => ['b', 'd'] 7871 */ 7872 var pullAt = flatRest(function(array, indexes) { 7873 var length = array == null ? 0 : array.length, 7874 result = baseAt(array, indexes); 7875 7876 basePullAt(array, arrayMap(indexes, function(index) { 7877 return isIndex(index, length) ? +index : index; 7878 }).sort(compareAscending)); 7879 7880 return result; 7881 }); 7882 7883 /** 7884 * Removes all elements from `array` that `predicate` returns truthy for 7885 * and returns an array of the removed elements. The predicate is invoked 7886 * with three arguments: (value, index, array). 7887 * 7888 * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull` 7889 * to pull elements from an array by value. 7890 * 7891 * @static 7892 * @memberOf _ 7893 * @since 2.0.0 7894 * @category Array 7895 * @param {Array} array The array to modify. 7896 * @param {Function} [predicate=_.identity] The function invoked per iteration. 7897 * @returns {Array} Returns the new array of removed elements. 7898 * @example 7899 * 7900 * var array = [1, 2, 3, 4]; 7901 * var evens = _.remove(array, function(n) { 7902 * return n % 2 == 0; 7903 * }); 7904 * 7905 * console.log(array); 7906 * // => [1, 3] 7907 * 7908 * console.log(evens); 7909 * // => [2, 4] 7910 */ 7911 function remove(array, predicate) { 7912 var result = []; 7913 if (!(array && array.length)) { 7914 return result; 7915 } 7916 var index = -1, 7917 indexes = [], 7918 length = array.length; 7919 7920 predicate = getIteratee(predicate, 3); 7921 while (++index < length) { 7922 var value = array[index]; 7923 if (predicate(value, index, array)) { 7924 result.push(value); 7925 indexes.push(index); 7926 } 7927 } 7928 basePullAt(array, indexes); 7929 return result; 7930 } 7931 7932 /** 7933 * Reverses `array` so that the first element becomes the last, the second 7934 * element becomes the second to last, and so on. 7935 * 7936 * **Note:** This method mutates `array` and is based on 7937 * [`Array#reverse`](https://mdn.io/Array/reverse). 7938 * 7939 * @static 7940 * @memberOf _ 7941 * @since 4.0.0 7942 * @category Array 7943 * @param {Array} array The array to modify. 7944 * @returns {Array} Returns `array`. 7945 * @example 7946 * 7947 * var array = [1, 2, 3]; 7948 * 7949 * _.reverse(array); 7950 * // => [3, 2, 1] 7951 * 7952 * console.log(array); 7953 * // => [3, 2, 1] 7954 */ 7955 function reverse(array) { 7956 return array == null ? array : nativeReverse.call(array); 7957 } 7958 7959 /** 7960 * Creates a slice of `array` from `start` up to, but not including, `end`. 7961 * 7962 * **Note:** This method is used instead of 7963 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are 7964 * returned. 7965 * 7966 * @static 7967 * @memberOf _ 7968 * @since 3.0.0 7969 * @category Array 7970 * @param {Array} array The array to slice. 7971 * @param {number} [start=0] The start position. 7972 * @param {number} [end=array.length] The end position. 7973 * @returns {Array} Returns the slice of `array`. 7974 */ 7975 function slice(array, start, end) { 7976 var length = array == null ? 0 : array.length; 7977 if (!length) { 7978 return []; 7979 } 7980 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) { 7981 start = 0; 7982 end = length; 7983 } 7984 else { 7985 start = start == null ? 0 : toInteger(start); 7986 end = end === undefined ? length : toInteger(end); 7987 } 7988 return baseSlice(array, start, end); 7989 } 7990 7991 /** 7992 * Uses a binary search to determine the lowest index at which `value` 7993 * should be inserted into `array` in order to maintain its sort order. 7994 * 7995 * @static 7996 * @memberOf _ 7997 * @since 0.1.0 7998 * @category Array 7999 * @param {Array} array The sorted array to inspect. 8000 * @param {*} value The value to evaluate. 8001 * @returns {number} Returns the index at which `value` should be inserted 8002 * into `array`. 8003 * @example 8004 * 8005 * _.sortedIndex([30, 50], 40); 8006 * // => 1 8007 */ 8008 function sortedIndex(array, value) { 8009 return baseSortedIndex(array, value); 8010 } 8011 8012 /** 8013 * This method is like `_.sortedIndex` except that it accepts `iteratee` 8014 * which is invoked for `value` and each element of `array` to compute their 8015 * sort ranking. The iteratee is invoked with one argument: (value). 8016 * 8017 * @static 8018 * @memberOf _ 8019 * @since 4.0.0 8020 * @category Array 8021 * @param {Array} array The sorted array to inspect. 8022 * @param {*} value The value to evaluate. 8023 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 8024 * @returns {number} Returns the index at which `value` should be inserted 8025 * into `array`. 8026 * @example 8027 * 8028 * var objects = [{ 'x': 4 }, { 'x': 5 }]; 8029 * 8030 * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); 8031 * // => 0 8032 * 8033 * // The `_.property` iteratee shorthand. 8034 * _.sortedIndexBy(objects, { 'x': 4 }, 'x'); 8035 * // => 0 8036 */ 8037 function sortedIndexBy(array, value, iteratee) { 8038 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2)); 8039 } 8040 8041 /** 8042 * This method is like `_.indexOf` except that it performs a binary 8043 * search on a sorted `array`. 8044 * 8045 * @static 8046 * @memberOf _ 8047 * @since 4.0.0 8048 * @category Array 8049 * @param {Array} array The array to inspect. 8050 * @param {*} value The value to search for. 8051 * @returns {number} Returns the index of the matched value, else `-1`. 8052 * @example 8053 * 8054 * _.sortedIndexOf([4, 5, 5, 5, 6], 5); 8055 * // => 1 8056 */ 8057 function sortedIndexOf(array, value) { 8058 var length = array == null ? 0 : array.length; 8059 if (length) { 8060 var index = baseSortedIndex(array, value); 8061 if (index < length && eq(array[index], value)) { 8062 return index; 8063 } 8064 } 8065 return -1; 8066 } 8067 8068 /** 8069 * This method is like `_.sortedIndex` except that it returns the highest 8070 * index at which `value` should be inserted into `array` in order to 8071 * maintain its sort order. 8072 * 8073 * @static 8074 * @memberOf _ 8075 * @since 3.0.0 8076 * @category Array 8077 * @param {Array} array The sorted array to inspect. 8078 * @param {*} value The value to evaluate. 8079 * @returns {number} Returns the index at which `value` should be inserted 8080 * into `array`. 8081 * @example 8082 * 8083 * _.sortedLastIndex([4, 5, 5, 5, 6], 5); 8084 * // => 4 8085 */ 8086 function sortedLastIndex(array, value) { 8087 return baseSortedIndex(array, value, true); 8088 } 8089 8090 /** 8091 * This method is like `_.sortedLastIndex` except that it accepts `iteratee` 8092 * which is invoked for `value` and each element of `array` to compute their 8093 * sort ranking. The iteratee is invoked with one argument: (value). 8094 * 8095 * @static 8096 * @memberOf _ 8097 * @since 4.0.0 8098 * @category Array 8099 * @param {Array} array The sorted array to inspect. 8100 * @param {*} value The value to evaluate. 8101 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 8102 * @returns {number} Returns the index at which `value` should be inserted 8103 * into `array`. 8104 * @example 8105 * 8106 * var objects = [{ 'x': 4 }, { 'x': 5 }]; 8107 * 8108 * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); 8109 * // => 1 8110 * 8111 * // The `_.property` iteratee shorthand. 8112 * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x'); 8113 * // => 1 8114 */ 8115 function sortedLastIndexBy(array, value, iteratee) { 8116 return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true); 8117 } 8118 8119 /** 8120 * This method is like `_.lastIndexOf` except that it performs a binary 8121 * search on a sorted `array`. 8122 * 8123 * @static 8124 * @memberOf _ 8125 * @since 4.0.0 8126 * @category Array 8127 * @param {Array} array The array to inspect. 8128 * @param {*} value The value to search for. 8129 * @returns {number} Returns the index of the matched value, else `-1`. 8130 * @example 8131 * 8132 * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5); 8133 * // => 3 8134 */ 8135 function sortedLastIndexOf(array, value) { 8136 var length = array == null ? 0 : array.length; 8137 if (length) { 8138 var index = baseSortedIndex(array, value, true) - 1; 8139 if (eq(array[index], value)) { 8140 return index; 8141 } 8142 } 8143 return -1; 8144 } 8145 8146 /** 8147 * This method is like `_.uniq` except that it's designed and optimized 8148 * for sorted arrays. 8149 * 8150 * @static 8151 * @memberOf _ 8152 * @since 4.0.0 8153 * @category Array 8154 * @param {Array} array The array to inspect. 8155 * @returns {Array} Returns the new duplicate free array. 8156 * @example 8157 * 8158 * _.sortedUniq([1, 1, 2]); 8159 * // => [1, 2] 8160 */ 8161 function sortedUniq(array) { 8162 return (array && array.length) 8163 ? baseSortedUniq(array) 8164 : []; 8165 } 8166 8167 /** 8168 * This method is like `_.uniqBy` except that it's designed and optimized 8169 * for sorted arrays. 8170 * 8171 * @static 8172 * @memberOf _ 8173 * @since 4.0.0 8174 * @category Array 8175 * @param {Array} array The array to inspect. 8176 * @param {Function} [iteratee] The iteratee invoked per element. 8177 * @returns {Array} Returns the new duplicate free array. 8178 * @example 8179 * 8180 * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); 8181 * // => [1.1, 2.3] 8182 */ 8183 function sortedUniqBy(array, iteratee) { 8184 return (array && array.length) 8185 ? baseSortedUniq(array, getIteratee(iteratee, 2)) 8186 : []; 8187 } 8188 8189 /** 8190 * Gets all but the first element of `array`. 8191 * 8192 * @static 8193 * @memberOf _ 8194 * @since 4.0.0 8195 * @category Array 8196 * @param {Array} array The array to query. 8197 * @returns {Array} Returns the slice of `array`. 8198 * @example 8199 * 8200 * _.tail([1, 2, 3]); 8201 * // => [2, 3] 8202 */ 8203 function tail(array) { 8204 var length = array == null ? 0 : array.length; 8205 return length ? baseSlice(array, 1, length) : []; 8206 } 8207 8208 /** 8209 * Creates a slice of `array` with `n` elements taken from the beginning. 8210 * 8211 * @static 8212 * @memberOf _ 8213 * @since 0.1.0 8214 * @category Array 8215 * @param {Array} array The array to query. 8216 * @param {number} [n=1] The number of elements to take. 8217 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 8218 * @returns {Array} Returns the slice of `array`. 8219 * @example 8220 * 8221 * _.take([1, 2, 3]); 8222 * // => [1] 8223 * 8224 * _.take([1, 2, 3], 2); 8225 * // => [1, 2] 8226 * 8227 * _.take([1, 2, 3], 5); 8228 * // => [1, 2, 3] 8229 * 8230 * _.take([1, 2, 3], 0); 8231 * // => [] 8232 */ 8233 function take(array, n, guard) { 8234 if (!(array && array.length)) { 8235 return []; 8236 } 8237 n = (guard || n === undefined) ? 1 : toInteger(n); 8238 return baseSlice(array, 0, n < 0 ? 0 : n); 8239 } 8240 8241 /** 8242 * Creates a slice of `array` with `n` elements taken from the end. 8243 * 8244 * @static 8245 * @memberOf _ 8246 * @since 3.0.0 8247 * @category Array 8248 * @param {Array} array The array to query. 8249 * @param {number} [n=1] The number of elements to take. 8250 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 8251 * @returns {Array} Returns the slice of `array`. 8252 * @example 8253 * 8254 * _.takeRight([1, 2, 3]); 8255 * // => [3] 8256 * 8257 * _.takeRight([1, 2, 3], 2); 8258 * // => [2, 3] 8259 * 8260 * _.takeRight([1, 2, 3], 5); 8261 * // => [1, 2, 3] 8262 * 8263 * _.takeRight([1, 2, 3], 0); 8264 * // => [] 8265 */ 8266 function takeRight(array, n, guard) { 8267 var length = array == null ? 0 : array.length; 8268 if (!length) { 8269 return []; 8270 } 8271 n = (guard || n === undefined) ? 1 : toInteger(n); 8272 n = length - n; 8273 return baseSlice(array, n < 0 ? 0 : n, length); 8274 } 8275 8276 /** 8277 * Creates a slice of `array` with elements taken from the end. Elements are 8278 * taken until `predicate` returns falsey. The predicate is invoked with 8279 * three arguments: (value, index, array). 8280 * 8281 * @static 8282 * @memberOf _ 8283 * @since 3.0.0 8284 * @category Array 8285 * @param {Array} array The array to query. 8286 * @param {Function} [predicate=_.identity] The function invoked per iteration. 8287 * @returns {Array} Returns the slice of `array`. 8288 * @example 8289 * 8290 * var users = [ 8291 * { 'user': 'barney', 'active': true }, 8292 * { 'user': 'fred', 'active': false }, 8293 * { 'user': 'pebbles', 'active': false } 8294 * ]; 8295 * 8296 * _.takeRightWhile(users, function(o) { return !o.active; }); 8297 * // => objects for ['fred', 'pebbles'] 8298 * 8299 * // The `_.matches` iteratee shorthand. 8300 * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); 8301 * // => objects for ['pebbles'] 8302 * 8303 * // The `_.matchesProperty` iteratee shorthand. 8304 * _.takeRightWhile(users, ['active', false]); 8305 * // => objects for ['fred', 'pebbles'] 8306 * 8307 * // The `_.property` iteratee shorthand. 8308 * _.takeRightWhile(users, 'active'); 8309 * // => [] 8310 */ 8311 function takeRightWhile(array, predicate) { 8312 return (array && array.length) 8313 ? baseWhile(array, getIteratee(predicate, 3), false, true) 8314 : []; 8315 } 8316 8317 /** 8318 * Creates a slice of `array` with elements taken from the beginning. Elements 8319 * are taken until `predicate` returns falsey. The predicate is invoked with 8320 * three arguments: (value, index, array). 8321 * 8322 * @static 8323 * @memberOf _ 8324 * @since 3.0.0 8325 * @category Array 8326 * @param {Array} array The array to query. 8327 * @param {Function} [predicate=_.identity] The function invoked per iteration. 8328 * @returns {Array} Returns the slice of `array`. 8329 * @example 8330 * 8331 * var users = [ 8332 * { 'user': 'barney', 'active': false }, 8333 * { 'user': 'fred', 'active': false }, 8334 * { 'user': 'pebbles', 'active': true } 8335 * ]; 8336 * 8337 * _.takeWhile(users, function(o) { return !o.active; }); 8338 * // => objects for ['barney', 'fred'] 8339 * 8340 * // The `_.matches` iteratee shorthand. 8341 * _.takeWhile(users, { 'user': 'barney', 'active': false }); 8342 * // => objects for ['barney'] 8343 * 8344 * // The `_.matchesProperty` iteratee shorthand. 8345 * _.takeWhile(users, ['active', false]); 8346 * // => objects for ['barney', 'fred'] 8347 * 8348 * // The `_.property` iteratee shorthand. 8349 * _.takeWhile(users, 'active'); 8350 * // => [] 8351 */ 8352 function takeWhile(array, predicate) { 8353 return (array && array.length) 8354 ? baseWhile(array, getIteratee(predicate, 3)) 8355 : []; 8356 } 8357 8358 /** 8359 * Creates an array of unique values, in order, from all given arrays using 8360 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 8361 * for equality comparisons. 8362 * 8363 * @static 8364 * @memberOf _ 8365 * @since 0.1.0 8366 * @category Array 8367 * @param {...Array} [arrays] The arrays to inspect. 8368 * @returns {Array} Returns the new array of combined values. 8369 * @example 8370 * 8371 * _.union([2], [1, 2]); 8372 * // => [2, 1] 8373 */ 8374 var union = baseRest(function(arrays) { 8375 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); 8376 }); 8377 8378 /** 8379 * This method is like `_.union` except that it accepts `iteratee` which is 8380 * invoked for each element of each `arrays` to generate the criterion by 8381 * which uniqueness is computed. Result values are chosen from the first 8382 * array in which the value occurs. The iteratee is invoked with one argument: 8383 * (value). 8384 * 8385 * @static 8386 * @memberOf _ 8387 * @since 4.0.0 8388 * @category Array 8389 * @param {...Array} [arrays] The arrays to inspect. 8390 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 8391 * @returns {Array} Returns the new array of combined values. 8392 * @example 8393 * 8394 * _.unionBy([2.1], [1.2, 2.3], Math.floor); 8395 * // => [2.1, 1.2] 8396 * 8397 * // The `_.property` iteratee shorthand. 8398 * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); 8399 * // => [{ 'x': 1 }, { 'x': 2 }] 8400 */ 8401 var unionBy = baseRest(function(arrays) { 8402 var iteratee = last(arrays); 8403 if (isArrayLikeObject(iteratee)) { 8404 iteratee = undefined; 8405 } 8406 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)); 8407 }); 8408 8409 /** 8410 * This method is like `_.union` except that it accepts `comparator` which 8411 * is invoked to compare elements of `arrays`. Result values are chosen from 8412 * the first array in which the value occurs. The comparator is invoked 8413 * with two arguments: (arrVal, othVal). 8414 * 8415 * @static 8416 * @memberOf _ 8417 * @since 4.0.0 8418 * @category Array 8419 * @param {...Array} [arrays] The arrays to inspect. 8420 * @param {Function} [comparator] The comparator invoked per element. 8421 * @returns {Array} Returns the new array of combined values. 8422 * @example 8423 * 8424 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 8425 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 8426 * 8427 * _.unionWith(objects, others, _.isEqual); 8428 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] 8429 */ 8430 var unionWith = baseRest(function(arrays) { 8431 var comparator = last(arrays); 8432 comparator = typeof comparator == 'function' ? comparator : undefined; 8433 return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator); 8434 }); 8435 8436 /** 8437 * Creates a duplicate-free version of an array, using 8438 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 8439 * for equality comparisons, in which only the first occurrence of each element 8440 * is kept. The order of result values is determined by the order they occur 8441 * in the array. 8442 * 8443 * @static 8444 * @memberOf _ 8445 * @since 0.1.0 8446 * @category Array 8447 * @param {Array} array The array to inspect. 8448 * @returns {Array} Returns the new duplicate free array. 8449 * @example 8450 * 8451 * _.uniq([2, 1, 2]); 8452 * // => [2, 1] 8453 */ 8454 function uniq(array) { 8455 return (array && array.length) ? baseUniq(array) : []; 8456 } 8457 8458 /** 8459 * This method is like `_.uniq` except that it accepts `iteratee` which is 8460 * invoked for each element in `array` to generate the criterion by which 8461 * uniqueness is computed. The order of result values is determined by the 8462 * order they occur in the array. The iteratee is invoked with one argument: 8463 * (value). 8464 * 8465 * @static 8466 * @memberOf _ 8467 * @since 4.0.0 8468 * @category Array 8469 * @param {Array} array The array to inspect. 8470 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 8471 * @returns {Array} Returns the new duplicate free array. 8472 * @example 8473 * 8474 * _.uniqBy([2.1, 1.2, 2.3], Math.floor); 8475 * // => [2.1, 1.2] 8476 * 8477 * // The `_.property` iteratee shorthand. 8478 * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); 8479 * // => [{ 'x': 1 }, { 'x': 2 }] 8480 */ 8481 function uniqBy(array, iteratee) { 8482 return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : []; 8483 } 8484 8485 /** 8486 * This method is like `_.uniq` except that it accepts `comparator` which 8487 * is invoked to compare elements of `array`. The order of result values is 8488 * determined by the order they occur in the array.The comparator is invoked 8489 * with two arguments: (arrVal, othVal). 8490 * 8491 * @static 8492 * @memberOf _ 8493 * @since 4.0.0 8494 * @category Array 8495 * @param {Array} array The array to inspect. 8496 * @param {Function} [comparator] The comparator invoked per element. 8497 * @returns {Array} Returns the new duplicate free array. 8498 * @example 8499 * 8500 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; 8501 * 8502 * _.uniqWith(objects, _.isEqual); 8503 * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] 8504 */ 8505 function uniqWith(array, comparator) { 8506 comparator = typeof comparator == 'function' ? comparator : undefined; 8507 return (array && array.length) ? baseUniq(array, undefined, comparator) : []; 8508 } 8509 8510 /** 8511 * This method is like `_.zip` except that it accepts an array of grouped 8512 * elements and creates an array regrouping the elements to their pre-zip 8513 * configuration. 8514 * 8515 * @static 8516 * @memberOf _ 8517 * @since 1.2.0 8518 * @category Array 8519 * @param {Array} array The array of grouped elements to process. 8520 * @returns {Array} Returns the new array of regrouped elements. 8521 * @example 8522 * 8523 * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); 8524 * // => [['a', 1, true], ['b', 2, false]] 8525 * 8526 * _.unzip(zipped); 8527 * // => [['a', 'b'], [1, 2], [true, false]] 8528 */ 8529 function unzip(array) { 8530 if (!(array && array.length)) { 8531 return []; 8532 } 8533 var length = 0; 8534 array = arrayFilter(array, function(group) { 8535 if (isArrayLikeObject(group)) { 8536 length = nativeMax(group.length, length); 8537 return true; 8538 } 8539 }); 8540 return baseTimes(length, function(index) { 8541 return arrayMap(array, baseProperty(index)); 8542 }); 8543 } 8544 8545 /** 8546 * This method is like `_.unzip` except that it accepts `iteratee` to specify 8547 * how regrouped values should be combined. The iteratee is invoked with the 8548 * elements of each group: (...group). 8549 * 8550 * @static 8551 * @memberOf _ 8552 * @since 3.8.0 8553 * @category Array 8554 * @param {Array} array The array of grouped elements to process. 8555 * @param {Function} [iteratee=_.identity] The function to combine 8556 * regrouped values. 8557 * @returns {Array} Returns the new array of regrouped elements. 8558 * @example 8559 * 8560 * var zipped = _.zip([1, 2], [10, 20], [100, 200]); 8561 * // => [[1, 10, 100], [2, 20, 200]] 8562 * 8563 * _.unzipWith(zipped, _.add); 8564 * // => [3, 30, 300] 8565 */ 8566 function unzipWith(array, iteratee) { 8567 if (!(array && array.length)) { 8568 return []; 8569 } 8570 var result = unzip(array); 8571 if (iteratee == null) { 8572 return result; 8573 } 8574 return arrayMap(result, function(group) { 8575 return apply(iteratee, undefined, group); 8576 }); 8577 } 8578 8579 /** 8580 * Creates an array excluding all given values using 8581 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 8582 * for equality comparisons. 8583 * 8584 * **Note:** Unlike `_.pull`, this method returns a new array. 8585 * 8586 * @static 8587 * @memberOf _ 8588 * @since 0.1.0 8589 * @category Array 8590 * @param {Array} array The array to inspect. 8591 * @param {...*} [values] The values to exclude. 8592 * @returns {Array} Returns the new array of filtered values. 8593 * @see _.difference, _.xor 8594 * @example 8595 * 8596 * _.without([2, 1, 2, 3], 1, 2); 8597 * // => [3] 8598 */ 8599 var without = baseRest(function(array, values) { 8600 return isArrayLikeObject(array) 8601 ? baseDifference(array, values) 8602 : []; 8603 }); 8604 8605 /** 8606 * Creates an array of unique values that is the 8607 * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) 8608 * of the given arrays. The order of result values is determined by the order 8609 * they occur in the arrays. 8610 * 8611 * @static 8612 * @memberOf _ 8613 * @since 2.4.0 8614 * @category Array 8615 * @param {...Array} [arrays] The arrays to inspect. 8616 * @returns {Array} Returns the new array of filtered values. 8617 * @see _.difference, _.without 8618 * @example 8619 * 8620 * _.xor([2, 1], [2, 3]); 8621 * // => [1, 3] 8622 */ 8623 var xor = baseRest(function(arrays) { 8624 return baseXor(arrayFilter(arrays, isArrayLikeObject)); 8625 }); 8626 8627 /** 8628 * This method is like `_.xor` except that it accepts `iteratee` which is 8629 * invoked for each element of each `arrays` to generate the criterion by 8630 * which by which they're compared. The order of result values is determined 8631 * by the order they occur in the arrays. The iteratee is invoked with one 8632 * argument: (value). 8633 * 8634 * @static 8635 * @memberOf _ 8636 * @since 4.0.0 8637 * @category Array 8638 * @param {...Array} [arrays] The arrays to inspect. 8639 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 8640 * @returns {Array} Returns the new array of filtered values. 8641 * @example 8642 * 8643 * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor); 8644 * // => [1.2, 3.4] 8645 * 8646 * // The `_.property` iteratee shorthand. 8647 * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); 8648 * // => [{ 'x': 2 }] 8649 */ 8650 var xorBy = baseRest(function(arrays) { 8651 var iteratee = last(arrays); 8652 if (isArrayLikeObject(iteratee)) { 8653 iteratee = undefined; 8654 } 8655 return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2)); 8656 }); 8657 8658 /** 8659 * This method is like `_.xor` except that it accepts `comparator` which is 8660 * invoked to compare elements of `arrays`. The order of result values is 8661 * determined by the order they occur in the arrays. The comparator is invoked 8662 * with two arguments: (arrVal, othVal). 8663 * 8664 * @static 8665 * @memberOf _ 8666 * @since 4.0.0 8667 * @category Array 8668 * @param {...Array} [arrays] The arrays to inspect. 8669 * @param {Function} [comparator] The comparator invoked per element. 8670 * @returns {Array} Returns the new array of filtered values. 8671 * @example 8672 * 8673 * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; 8674 * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; 8675 * 8676 * _.xorWith(objects, others, _.isEqual); 8677 * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] 8678 */ 8679 var xorWith = baseRest(function(arrays) { 8680 var comparator = last(arrays); 8681 comparator = typeof comparator == 'function' ? comparator : undefined; 8682 return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator); 8683 }); 8684 8685 /** 8686 * Creates an array of grouped elements, the first of which contains the 8687 * first elements of the given arrays, the second of which contains the 8688 * second elements of the given arrays, and so on. 8689 * 8690 * @static 8691 * @memberOf _ 8692 * @since 0.1.0 8693 * @category Array 8694 * @param {...Array} [arrays] The arrays to process. 8695 * @returns {Array} Returns the new array of grouped elements. 8696 * @example 8697 * 8698 * _.zip(['a', 'b'], [1, 2], [true, false]); 8699 * // => [['a', 1, true], ['b', 2, false]] 8700 */ 8701 var zip = baseRest(unzip); 8702 8703 /** 8704 * This method is like `_.fromPairs` except that it accepts two arrays, 8705 * one of property identifiers and one of corresponding values. 8706 * 8707 * @static 8708 * @memberOf _ 8709 * @since 0.4.0 8710 * @category Array 8711 * @param {Array} [props=[]] The property identifiers. 8712 * @param {Array} [values=[]] The property values. 8713 * @returns {Object} Returns the new object. 8714 * @example 8715 * 8716 * _.zipObject(['a', 'b'], [1, 2]); 8717 * // => { 'a': 1, 'b': 2 } 8718 */ 8719 function zipObject(props, values) { 8720 return baseZipObject(props || [], values || [], assignValue); 8721 } 8722 8723 /** 8724 * This method is like `_.zipObject` except that it supports property paths. 8725 * 8726 * @static 8727 * @memberOf _ 8728 * @since 4.1.0 8729 * @category Array 8730 * @param {Array} [props=[]] The property identifiers. 8731 * @param {Array} [values=[]] The property values. 8732 * @returns {Object} Returns the new object. 8733 * @example 8734 * 8735 * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]); 8736 * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } 8737 */ 8738 function zipObjectDeep(props, values) { 8739 return baseZipObject(props || [], values || [], baseSet); 8740 } 8741 8742 /** 8743 * This method is like `_.zip` except that it accepts `iteratee` to specify 8744 * how grouped values should be combined. The iteratee is invoked with the 8745 * elements of each group: (...group). 8746 * 8747 * @static 8748 * @memberOf _ 8749 * @since 3.8.0 8750 * @category Array 8751 * @param {...Array} [arrays] The arrays to process. 8752 * @param {Function} [iteratee=_.identity] The function to combine 8753 * grouped values. 8754 * @returns {Array} Returns the new array of grouped elements. 8755 * @example 8756 * 8757 * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) { 8758 * return a + b + c; 8759 * }); 8760 * // => [111, 222] 8761 */ 8762 var zipWith = baseRest(function(arrays) { 8763 var length = arrays.length, 8764 iteratee = length > 1 ? arrays[length - 1] : undefined; 8765 8766 iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined; 8767 return unzipWith(arrays, iteratee); 8768 }); 8769 8770 /*------------------------------------------------------------------------*/ 8771 8772 /** 8773 * Creates a `lodash` wrapper instance that wraps `value` with explicit method 8774 * chain sequences enabled. The result of such sequences must be unwrapped 8775 * with `_#value`. 8776 * 8777 * @static 8778 * @memberOf _ 8779 * @since 1.3.0 8780 * @category Seq 8781 * @param {*} value The value to wrap. 8782 * @returns {Object} Returns the new `lodash` wrapper instance. 8783 * @example 8784 * 8785 * var users = [ 8786 * { 'user': 'barney', 'age': 36 }, 8787 * { 'user': 'fred', 'age': 40 }, 8788 * { 'user': 'pebbles', 'age': 1 } 8789 * ]; 8790 * 8791 * var youngest = _ 8792 * .chain(users) 8793 * .sortBy('age') 8794 * .map(function(o) { 8795 * return o.user + ' is ' + o.age; 8796 * }) 8797 * .head() 8798 * .value(); 8799 * // => 'pebbles is 1' 8800 */ 8801 function chain(value) { 8802 var result = lodash(value); 8803 result.__chain__ = true; 8804 return result; 8805 } 8806 8807 /** 8808 * This method invokes `interceptor` and returns `value`. The interceptor 8809 * is invoked with one argument; (value). The purpose of this method is to 8810 * "tap into" a method chain sequence in order to modify intermediate results. 8811 * 8812 * @static 8813 * @memberOf _ 8814 * @since 0.1.0 8815 * @category Seq 8816 * @param {*} value The value to provide to `interceptor`. 8817 * @param {Function} interceptor The function to invoke. 8818 * @returns {*} Returns `value`. 8819 * @example 8820 * 8821 * _([1, 2, 3]) 8822 * .tap(function(array) { 8823 * // Mutate input array. 8824 * array.pop(); 8825 * }) 8826 * .reverse() 8827 * .value(); 8828 * // => [2, 1] 8829 */ 8830 function tap(value, interceptor) { 8831 interceptor(value); 8832 return value; 8833 } 8834 8835 /** 8836 * This method is like `_.tap` except that it returns the result of `interceptor`. 8837 * The purpose of this method is to "pass thru" values replacing intermediate 8838 * results in a method chain sequence. 8839 * 8840 * @static 8841 * @memberOf _ 8842 * @since 3.0.0 8843 * @category Seq 8844 * @param {*} value The value to provide to `interceptor`. 8845 * @param {Function} interceptor The function to invoke. 8846 * @returns {*} Returns the result of `interceptor`. 8847 * @example 8848 * 8849 * _(' abc ') 8850 * .chain() 8851 * .trim() 8852 * .thru(function(value) { 8853 * return [value]; 8854 * }) 8855 * .value(); 8856 * // => ['abc'] 8857 */ 8858 function thru(value, interceptor) { 8859 return interceptor(value); 8860 } 8861 8862 /** 8863 * This method is the wrapper version of `_.at`. 8864 * 8865 * @name at 8866 * @memberOf _ 8867 * @since 1.0.0 8868 * @category Seq 8869 * @param {...(string|string[])} [paths] The property paths to pick. 8870 * @returns {Object} Returns the new `lodash` wrapper instance. 8871 * @example 8872 * 8873 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; 8874 * 8875 * _(object).at(['a[0].b.c', 'a[1]']).value(); 8876 * // => [3, 4] 8877 */ 8878 var wrapperAt = flatRest(function(paths) { 8879 var length = paths.length, 8880 start = length ? paths[0] : 0, 8881 value = this.__wrapped__, 8882 interceptor = function(object) { return baseAt(object, paths); }; 8883 8884 if (length > 1 || this.__actions__.length || 8885 !(value instanceof LazyWrapper) || !isIndex(start)) { 8886 return this.thru(interceptor); 8887 } 8888 value = value.slice(start, +start + (length ? 1 : 0)); 8889 value.__actions__.push({ 8890 'func': thru, 8891 'args': [interceptor], 8892 'thisArg': undefined 8893 }); 8894 return new LodashWrapper(value, this.__chain__).thru(function(array) { 8895 if (length && !array.length) { 8896 array.push(undefined); 8897 } 8898 return array; 8899 }); 8900 }); 8901 8902 /** 8903 * Creates a `lodash` wrapper instance with explicit method chain sequences enabled. 8904 * 8905 * @name chain 8906 * @memberOf _ 8907 * @since 0.1.0 8908 * @category Seq 8909 * @returns {Object} Returns the new `lodash` wrapper instance. 8910 * @example 8911 * 8912 * var users = [ 8913 * { 'user': 'barney', 'age': 36 }, 8914 * { 'user': 'fred', 'age': 40 } 8915 * ]; 8916 * 8917 * // A sequence without explicit chaining. 8918 * _(users).head(); 8919 * // => { 'user': 'barney', 'age': 36 } 8920 * 8921 * // A sequence with explicit chaining. 8922 * _(users) 8923 * .chain() 8924 * .head() 8925 * .pick('user') 8926 * .value(); 8927 * // => { 'user': 'barney' } 8928 */ 8929 function wrapperChain() { 8930 return chain(this); 8931 } 8932 8933 /** 8934 * Executes the chain sequence and returns the wrapped result. 8935 * 8936 * @name commit 8937 * @memberOf _ 8938 * @since 3.2.0 8939 * @category Seq 8940 * @returns {Object} Returns the new `lodash` wrapper instance. 8941 * @example 8942 * 8943 * var array = [1, 2]; 8944 * var wrapped = _(array).push(3); 8945 * 8946 * console.log(array); 8947 * // => [1, 2] 8948 * 8949 * wrapped = wrapped.commit(); 8950 * console.log(array); 8951 * // => [1, 2, 3] 8952 * 8953 * wrapped.last(); 8954 * // => 3 8955 * 8956 * console.log(array); 8957 * // => [1, 2, 3] 8958 */ 8959 function wrapperCommit() { 8960 return new LodashWrapper(this.value(), this.__chain__); 8961 } 8962 8963 /** 8964 * Gets the next value on a wrapped object following the 8965 * [iterator protocol](https://mdn.io/iteration_protocols#iterator). 8966 * 8967 * @name next 8968 * @memberOf _ 8969 * @since 4.0.0 8970 * @category Seq 8971 * @returns {Object} Returns the next iterator value. 8972 * @example 8973 * 8974 * var wrapped = _([1, 2]); 8975 * 8976 * wrapped.next(); 8977 * // => { 'done': false, 'value': 1 } 8978 * 8979 * wrapped.next(); 8980 * // => { 'done': false, 'value': 2 } 8981 * 8982 * wrapped.next(); 8983 * // => { 'done': true, 'value': undefined } 8984 */ 8985 function wrapperNext() { 8986 if (this.__values__ === undefined) { 8987 this.__values__ = toArray(this.value()); 8988 } 8989 var done = this.__index__ >= this.__values__.length, 8990 value = done ? undefined : this.__values__[this.__index__++]; 8991 8992 return { 'done': done, 'value': value }; 8993 } 8994 8995 /** 8996 * Enables the wrapper to be iterable. 8997 * 8998 * @name Symbol.iterator 8999 * @memberOf _ 9000 * @since 4.0.0 9001 * @category Seq 9002 * @returns {Object} Returns the wrapper object. 9003 * @example 9004 * 9005 * var wrapped = _([1, 2]); 9006 * 9007 * wrapped[Symbol.iterator]() === wrapped; 9008 * // => true 9009 * 9010 * Array.from(wrapped); 9011 * // => [1, 2] 9012 */ 9013 function wrapperToIterator() { 9014 return this; 9015 } 9016 9017 /** 9018 * Creates a clone of the chain sequence planting `value` as the wrapped value. 9019 * 9020 * @name plant 9021 * @memberOf _ 9022 * @since 3.2.0 9023 * @category Seq 9024 * @param {*} value The value to plant. 9025 * @returns {Object} Returns the new `lodash` wrapper instance. 9026 * @example 9027 * 9028 * function square(n) { 9029 * return n * n; 9030 * } 9031 * 9032 * var wrapped = _([1, 2]).map(square); 9033 * var other = wrapped.plant([3, 4]); 9034 * 9035 * other.value(); 9036 * // => [9, 16] 9037 * 9038 * wrapped.value(); 9039 * // => [1, 4] 9040 */ 9041 function wrapperPlant(value) { 9042 var result, 9043 parent = this; 9044 9045 while (parent instanceof baseLodash) { 9046 var clone = wrapperClone(parent); 9047 clone.__index__ = 0; 9048 clone.__values__ = undefined; 9049 if (result) { 9050 previous.__wrapped__ = clone; 9051 } else { 9052 result = clone; 9053 } 9054 var previous = clone; 9055 parent = parent.__wrapped__; 9056 } 9057 previous.__wrapped__ = value; 9058 return result; 9059 } 9060 9061 /** 9062 * This method is the wrapper version of `_.reverse`. 9063 * 9064 * **Note:** This method mutates the wrapped array. 9065 * 9066 * @name reverse 9067 * @memberOf _ 9068 * @since 0.1.0 9069 * @category Seq 9070 * @returns {Object} Returns the new `lodash` wrapper instance. 9071 * @example 9072 * 9073 * var array = [1, 2, 3]; 9074 * 9075 * _(array).reverse().value() 9076 * // => [3, 2, 1] 9077 * 9078 * console.log(array); 9079 * // => [3, 2, 1] 9080 */ 9081 function wrapperReverse() { 9082 var value = this.__wrapped__; 9083 if (value instanceof LazyWrapper) { 9084 var wrapped = value; 9085 if (this.__actions__.length) { 9086 wrapped = new LazyWrapper(this); 9087 } 9088 wrapped = wrapped.reverse(); 9089 wrapped.__actions__.push({ 9090 'func': thru, 9091 'args': [reverse], 9092 'thisArg': undefined 9093 }); 9094 return new LodashWrapper(wrapped, this.__chain__); 9095 } 9096 return this.thru(reverse); 9097 } 9098 9099 /** 9100 * Executes the chain sequence to resolve the unwrapped value. 9101 * 9102 * @name value 9103 * @memberOf _ 9104 * @since 0.1.0 9105 * @alias toJSON, valueOf 9106 * @category Seq 9107 * @returns {*} Returns the resolved unwrapped value. 9108 * @example 9109 * 9110 * _([1, 2, 3]).value(); 9111 * // => [1, 2, 3] 9112 */ 9113 function wrapperValue() { 9114 return baseWrapperValue(this.__wrapped__, this.__actions__); 9115 } 9116 9117 /*------------------------------------------------------------------------*/ 9118 9119 /** 9120 * Creates an object composed of keys generated from the results of running 9121 * each element of `collection` thru `iteratee`. The corresponding value of 9122 * each key is the number of times the key was returned by `iteratee`. The 9123 * iteratee is invoked with one argument: (value). 9124 * 9125 * @static 9126 * @memberOf _ 9127 * @since 0.5.0 9128 * @category Collection 9129 * @param {Array|Object} collection The collection to iterate over. 9130 * @param {Function} [iteratee=_.identity] The iteratee to transform keys. 9131 * @returns {Object} Returns the composed aggregate object. 9132 * @example 9133 * 9134 * _.countBy([6.1, 4.2, 6.3], Math.floor); 9135 * // => { '4': 1, '6': 2 } 9136 * 9137 * // The `_.property` iteratee shorthand. 9138 * _.countBy(['one', 'two', 'three'], 'length'); 9139 * // => { '3': 2, '5': 1 } 9140 */ 9141 var countBy = createAggregator(function(result, value, key) { 9142 if (hasOwnProperty.call(result, key)) { 9143 ++result[key]; 9144 } else { 9145 baseAssignValue(result, key, 1); 9146 } 9147 }); 9148 9149 /** 9150 * Checks if `predicate` returns truthy for **all** elements of `collection`. 9151 * Iteration is stopped once `predicate` returns falsey. The predicate is 9152 * invoked with three arguments: (value, index|key, collection). 9153 * 9154 * **Note:** This method returns `true` for 9155 * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because 9156 * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of 9157 * elements of empty collections. 9158 * 9159 * @static 9160 * @memberOf _ 9161 * @since 0.1.0 9162 * @category Collection 9163 * @param {Array|Object} collection The collection to iterate over. 9164 * @param {Function} [predicate=_.identity] The function invoked per iteration. 9165 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 9166 * @returns {boolean} Returns `true` if all elements pass the predicate check, 9167 * else `false`. 9168 * @example 9169 * 9170 * _.every([true, 1, null, 'yes'], Boolean); 9171 * // => false 9172 * 9173 * var users = [ 9174 * { 'user': 'barney', 'age': 36, 'active': false }, 9175 * { 'user': 'fred', 'age': 40, 'active': false } 9176 * ]; 9177 * 9178 * // The `_.matches` iteratee shorthand. 9179 * _.every(users, { 'user': 'barney', 'active': false }); 9180 * // => false 9181 * 9182 * // The `_.matchesProperty` iteratee shorthand. 9183 * _.every(users, ['active', false]); 9184 * // => true 9185 * 9186 * // The `_.property` iteratee shorthand. 9187 * _.every(users, 'active'); 9188 * // => false 9189 */ 9190 function every(collection, predicate, guard) { 9191 var func = isArray(collection) ? arrayEvery : baseEvery; 9192 if (guard && isIterateeCall(collection, predicate, guard)) { 9193 predicate = undefined; 9194 } 9195 return func(collection, getIteratee(predicate, 3)); 9196 } 9197 9198 /** 9199 * Iterates over elements of `collection`, returning an array of all elements 9200 * `predicate` returns truthy for. The predicate is invoked with three 9201 * arguments: (value, index|key, collection). 9202 * 9203 * **Note:** Unlike `_.remove`, this method returns a new array. 9204 * 9205 * @static 9206 * @memberOf _ 9207 * @since 0.1.0 9208 * @category Collection 9209 * @param {Array|Object} collection The collection to iterate over. 9210 * @param {Function} [predicate=_.identity] The function invoked per iteration. 9211 * @returns {Array} Returns the new filtered array. 9212 * @see _.reject 9213 * @example 9214 * 9215 * var users = [ 9216 * { 'user': 'barney', 'age': 36, 'active': true }, 9217 * { 'user': 'fred', 'age': 40, 'active': false } 9218 * ]; 9219 * 9220 * _.filter(users, function(o) { return !o.active; }); 9221 * // => objects for ['fred'] 9222 * 9223 * // The `_.matches` iteratee shorthand. 9224 * _.filter(users, { 'age': 36, 'active': true }); 9225 * // => objects for ['barney'] 9226 * 9227 * // The `_.matchesProperty` iteratee shorthand. 9228 * _.filter(users, ['active', false]); 9229 * // => objects for ['fred'] 9230 * 9231 * // The `_.property` iteratee shorthand. 9232 * _.filter(users, 'active'); 9233 * // => objects for ['barney'] 9234 * 9235 * // Combining several predicates using `_.overEvery` or `_.overSome`. 9236 * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]])); 9237 * // => objects for ['fred', 'barney'] 9238 */ 9239 function filter(collection, predicate) { 9240 var func = isArray(collection) ? arrayFilter : baseFilter; 9241 return func(collection, getIteratee(predicate, 3)); 9242 } 9243 9244 /** 9245 * Iterates over elements of `collection`, returning the first element 9246 * `predicate` returns truthy for. The predicate is invoked with three 9247 * arguments: (value, index|key, collection). 9248 * 9249 * @static 9250 * @memberOf _ 9251 * @since 0.1.0 9252 * @category Collection 9253 * @param {Array|Object} collection The collection to inspect. 9254 * @param {Function} [predicate=_.identity] The function invoked per iteration. 9255 * @param {number} [fromIndex=0] The index to search from. 9256 * @returns {*} Returns the matched element, else `undefined`. 9257 * @example 9258 * 9259 * var users = [ 9260 * { 'user': 'barney', 'age': 36, 'active': true }, 9261 * { 'user': 'fred', 'age': 40, 'active': false }, 9262 * { 'user': 'pebbles', 'age': 1, 'active': true } 9263 * ]; 9264 * 9265 * _.find(users, function(o) { return o.age < 40; }); 9266 * // => object for 'barney' 9267 * 9268 * // The `_.matches` iteratee shorthand. 9269 * _.find(users, { 'age': 1, 'active': true }); 9270 * // => object for 'pebbles' 9271 * 9272 * // The `_.matchesProperty` iteratee shorthand. 9273 * _.find(users, ['active', false]); 9274 * // => object for 'fred' 9275 * 9276 * // The `_.property` iteratee shorthand. 9277 * _.find(users, 'active'); 9278 * // => object for 'barney' 9279 */ 9280 var find = createFind(findIndex); 9281 9282 /** 9283 * This method is like `_.find` except that it iterates over elements of 9284 * `collection` from right to left. 9285 * 9286 * @static 9287 * @memberOf _ 9288 * @since 2.0.0 9289 * @category Collection 9290 * @param {Array|Object} collection The collection to inspect. 9291 * @param {Function} [predicate=_.identity] The function invoked per iteration. 9292 * @param {number} [fromIndex=collection.length-1] The index to search from. 9293 * @returns {*} Returns the matched element, else `undefined`. 9294 * @example 9295 * 9296 * _.findLast([1, 2, 3, 4], function(n) { 9297 * return n % 2 == 1; 9298 * }); 9299 * // => 3 9300 */ 9301 var findLast = createFind(findLastIndex); 9302 9303 /** 9304 * Creates a flattened array of values by running each element in `collection` 9305 * thru `iteratee` and flattening the mapped results. The iteratee is invoked 9306 * with three arguments: (value, index|key, collection). 9307 * 9308 * @static 9309 * @memberOf _ 9310 * @since 4.0.0 9311 * @category Collection 9312 * @param {Array|Object} collection The collection to iterate over. 9313 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9314 * @returns {Array} Returns the new flattened array. 9315 * @example 9316 * 9317 * function duplicate(n) { 9318 * return [n, n]; 9319 * } 9320 * 9321 * _.flatMap([1, 2], duplicate); 9322 * // => [1, 1, 2, 2] 9323 */ 9324 function flatMap(collection, iteratee) { 9325 return baseFlatten(map(collection, iteratee), 1); 9326 } 9327 9328 /** 9329 * This method is like `_.flatMap` except that it recursively flattens the 9330 * mapped results. 9331 * 9332 * @static 9333 * @memberOf _ 9334 * @since 4.7.0 9335 * @category Collection 9336 * @param {Array|Object} collection The collection to iterate over. 9337 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9338 * @returns {Array} Returns the new flattened array. 9339 * @example 9340 * 9341 * function duplicate(n) { 9342 * return [[[n, n]]]; 9343 * } 9344 * 9345 * _.flatMapDeep([1, 2], duplicate); 9346 * // => [1, 1, 2, 2] 9347 */ 9348 function flatMapDeep(collection, iteratee) { 9349 return baseFlatten(map(collection, iteratee), INFINITY); 9350 } 9351 9352 /** 9353 * This method is like `_.flatMap` except that it recursively flattens the 9354 * mapped results up to `depth` times. 9355 * 9356 * @static 9357 * @memberOf _ 9358 * @since 4.7.0 9359 * @category Collection 9360 * @param {Array|Object} collection The collection to iterate over. 9361 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9362 * @param {number} [depth=1] The maximum recursion depth. 9363 * @returns {Array} Returns the new flattened array. 9364 * @example 9365 * 9366 * function duplicate(n) { 9367 * return [[[n, n]]]; 9368 * } 9369 * 9370 * _.flatMapDepth([1, 2], duplicate, 2); 9371 * // => [[1, 1], [2, 2]] 9372 */ 9373 function flatMapDepth(collection, iteratee, depth) { 9374 depth = depth === undefined ? 1 : toInteger(depth); 9375 return baseFlatten(map(collection, iteratee), depth); 9376 } 9377 9378 /** 9379 * Iterates over elements of `collection` and invokes `iteratee` for each element. 9380 * The iteratee is invoked with three arguments: (value, index|key, collection). 9381 * Iteratee functions may exit iteration early by explicitly returning `false`. 9382 * 9383 * **Note:** As with other "Collections" methods, objects with a "length" 9384 * property are iterated like arrays. To avoid this behavior use `_.forIn` 9385 * or `_.forOwn` for object iteration. 9386 * 9387 * @static 9388 * @memberOf _ 9389 * @since 0.1.0 9390 * @alias each 9391 * @category Collection 9392 * @param {Array|Object} collection The collection to iterate over. 9393 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9394 * @returns {Array|Object} Returns `collection`. 9395 * @see _.forEachRight 9396 * @example 9397 * 9398 * _.forEach([1, 2], function(value) { 9399 * console.log(value); 9400 * }); 9401 * // => Logs `1` then `2`. 9402 * 9403 * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { 9404 * console.log(key); 9405 * }); 9406 * // => Logs 'a' then 'b' (iteration order is not guaranteed). 9407 */ 9408 function forEach(collection, iteratee) { 9409 var func = isArray(collection) ? arrayEach : baseEach; 9410 return func(collection, getIteratee(iteratee, 3)); 9411 } 9412 9413 /** 9414 * This method is like `_.forEach` except that it iterates over elements of 9415 * `collection` from right to left. 9416 * 9417 * @static 9418 * @memberOf _ 9419 * @since 2.0.0 9420 * @alias eachRight 9421 * @category Collection 9422 * @param {Array|Object} collection The collection to iterate over. 9423 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9424 * @returns {Array|Object} Returns `collection`. 9425 * @see _.forEach 9426 * @example 9427 * 9428 * _.forEachRight([1, 2], function(value) { 9429 * console.log(value); 9430 * }); 9431 * // => Logs `2` then `1`. 9432 */ 9433 function forEachRight(collection, iteratee) { 9434 var func = isArray(collection) ? arrayEachRight : baseEachRight; 9435 return func(collection, getIteratee(iteratee, 3)); 9436 } 9437 9438 /** 9439 * Creates an object composed of keys generated from the results of running 9440 * each element of `collection` thru `iteratee`. The order of grouped values 9441 * is determined by the order they occur in `collection`. The corresponding 9442 * value of each key is an array of elements responsible for generating the 9443 * key. The iteratee is invoked with one argument: (value). 9444 * 9445 * @static 9446 * @memberOf _ 9447 * @since 0.1.0 9448 * @category Collection 9449 * @param {Array|Object} collection The collection to iterate over. 9450 * @param {Function} [iteratee=_.identity] The iteratee to transform keys. 9451 * @returns {Object} Returns the composed aggregate object. 9452 * @example 9453 * 9454 * _.groupBy([6.1, 4.2, 6.3], Math.floor); 9455 * // => { '4': [4.2], '6': [6.1, 6.3] } 9456 * 9457 * // The `_.property` iteratee shorthand. 9458 * _.groupBy(['one', 'two', 'three'], 'length'); 9459 * // => { '3': ['one', 'two'], '5': ['three'] } 9460 */ 9461 var groupBy = createAggregator(function(result, value, key) { 9462 if (hasOwnProperty.call(result, key)) { 9463 result[key].push(value); 9464 } else { 9465 baseAssignValue(result, key, [value]); 9466 } 9467 }); 9468 9469 /** 9470 * Checks if `value` is in `collection`. If `collection` is a string, it's 9471 * checked for a substring of `value`, otherwise 9472 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 9473 * is used for equality comparisons. If `fromIndex` is negative, it's used as 9474 * the offset from the end of `collection`. 9475 * 9476 * @static 9477 * @memberOf _ 9478 * @since 0.1.0 9479 * @category Collection 9480 * @param {Array|Object|string} collection The collection to inspect. 9481 * @param {*} value The value to search for. 9482 * @param {number} [fromIndex=0] The index to search from. 9483 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. 9484 * @returns {boolean} Returns `true` if `value` is found, else `false`. 9485 * @example 9486 * 9487 * _.includes([1, 2, 3], 1); 9488 * // => true 9489 * 9490 * _.includes([1, 2, 3], 1, 2); 9491 * // => false 9492 * 9493 * _.includes({ 'a': 1, 'b': 2 }, 1); 9494 * // => true 9495 * 9496 * _.includes('abcd', 'bc'); 9497 * // => true 9498 */ 9499 function includes(collection, value, fromIndex, guard) { 9500 collection = isArrayLike(collection) ? collection : values(collection); 9501 fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0; 9502 9503 var length = collection.length; 9504 if (fromIndex < 0) { 9505 fromIndex = nativeMax(length + fromIndex, 0); 9506 } 9507 return isString(collection) 9508 ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1) 9509 : (!!length && baseIndexOf(collection, value, fromIndex) > -1); 9510 } 9511 9512 /** 9513 * Invokes the method at `path` of each element in `collection`, returning 9514 * an array of the results of each invoked method. Any additional arguments 9515 * are provided to each invoked method. If `path` is a function, it's invoked 9516 * for, and `this` bound to, each element in `collection`. 9517 * 9518 * @static 9519 * @memberOf _ 9520 * @since 4.0.0 9521 * @category Collection 9522 * @param {Array|Object} collection The collection to iterate over. 9523 * @param {Array|Function|string} path The path of the method to invoke or 9524 * the function invoked per iteration. 9525 * @param {...*} [args] The arguments to invoke each method with. 9526 * @returns {Array} Returns the array of results. 9527 * @example 9528 * 9529 * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); 9530 * // => [[1, 5, 7], [1, 2, 3]] 9531 * 9532 * _.invokeMap([123, 456], String.prototype.split, ''); 9533 * // => [['1', '2', '3'], ['4', '5', '6']] 9534 */ 9535 var invokeMap = baseRest(function(collection, path, args) { 9536 var index = -1, 9537 isFunc = typeof path == 'function', 9538 result = isArrayLike(collection) ? Array(collection.length) : []; 9539 9540 baseEach(collection, function(value) { 9541 result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args); 9542 }); 9543 return result; 9544 }); 9545 9546 /** 9547 * Creates an object composed of keys generated from the results of running 9548 * each element of `collection` thru `iteratee`. The corresponding value of 9549 * each key is the last element responsible for generating the key. The 9550 * iteratee is invoked with one argument: (value). 9551 * 9552 * @static 9553 * @memberOf _ 9554 * @since 4.0.0 9555 * @category Collection 9556 * @param {Array|Object} collection The collection to iterate over. 9557 * @param {Function} [iteratee=_.identity] The iteratee to transform keys. 9558 * @returns {Object} Returns the composed aggregate object. 9559 * @example 9560 * 9561 * var array = [ 9562 * { 'dir': 'left', 'code': 97 }, 9563 * { 'dir': 'right', 'code': 100 } 9564 * ]; 9565 * 9566 * _.keyBy(array, function(o) { 9567 * return String.fromCharCode(o.code); 9568 * }); 9569 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } 9570 * 9571 * _.keyBy(array, 'dir'); 9572 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } 9573 */ 9574 var keyBy = createAggregator(function(result, value, key) { 9575 baseAssignValue(result, key, value); 9576 }); 9577 9578 /** 9579 * Creates an array of values by running each element in `collection` thru 9580 * `iteratee`. The iteratee is invoked with three arguments: 9581 * (value, index|key, collection). 9582 * 9583 * Many lodash methods are guarded to work as iteratees for methods like 9584 * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. 9585 * 9586 * The guarded methods are: 9587 * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, 9588 * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, 9589 * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, 9590 * `template`, `trim`, `trimEnd`, `trimStart`, and `words` 9591 * 9592 * @static 9593 * @memberOf _ 9594 * @since 0.1.0 9595 * @category Collection 9596 * @param {Array|Object} collection The collection to iterate over. 9597 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9598 * @returns {Array} Returns the new mapped array. 9599 * @example 9600 * 9601 * function square(n) { 9602 * return n * n; 9603 * } 9604 * 9605 * _.map([4, 8], square); 9606 * // => [16, 64] 9607 * 9608 * _.map({ 'a': 4, 'b': 8 }, square); 9609 * // => [16, 64] (iteration order is not guaranteed) 9610 * 9611 * var users = [ 9612 * { 'user': 'barney' }, 9613 * { 'user': 'fred' } 9614 * ]; 9615 * 9616 * // The `_.property` iteratee shorthand. 9617 * _.map(users, 'user'); 9618 * // => ['barney', 'fred'] 9619 */ 9620 function map(collection, iteratee) { 9621 var func = isArray(collection) ? arrayMap : baseMap; 9622 return func(collection, getIteratee(iteratee, 3)); 9623 } 9624 9625 /** 9626 * This method is like `_.sortBy` except that it allows specifying the sort 9627 * orders of the iteratees to sort by. If `orders` is unspecified, all values 9628 * are sorted in ascending order. Otherwise, specify an order of "desc" for 9629 * descending or "asc" for ascending sort order of corresponding values. 9630 * 9631 * @static 9632 * @memberOf _ 9633 * @since 4.0.0 9634 * @category Collection 9635 * @param {Array|Object} collection The collection to iterate over. 9636 * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]] 9637 * The iteratees to sort by. 9638 * @param {string[]} [orders] The sort orders of `iteratees`. 9639 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. 9640 * @returns {Array} Returns the new sorted array. 9641 * @example 9642 * 9643 * var users = [ 9644 * { 'user': 'fred', 'age': 48 }, 9645 * { 'user': 'barney', 'age': 34 }, 9646 * { 'user': 'fred', 'age': 40 }, 9647 * { 'user': 'barney', 'age': 36 } 9648 * ]; 9649 * 9650 * // Sort by `user` in ascending order and by `age` in descending order. 9651 * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); 9652 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] 9653 */ 9654 function orderBy(collection, iteratees, orders, guard) { 9655 if (collection == null) { 9656 return []; 9657 } 9658 if (!isArray(iteratees)) { 9659 iteratees = iteratees == null ? [] : [iteratees]; 9660 } 9661 orders = guard ? undefined : orders; 9662 if (!isArray(orders)) { 9663 orders = orders == null ? [] : [orders]; 9664 } 9665 return baseOrderBy(collection, iteratees, orders); 9666 } 9667 9668 /** 9669 * Creates an array of elements split into two groups, the first of which 9670 * contains elements `predicate` returns truthy for, the second of which 9671 * contains elements `predicate` returns falsey for. The predicate is 9672 * invoked with one argument: (value). 9673 * 9674 * @static 9675 * @memberOf _ 9676 * @since 3.0.0 9677 * @category Collection 9678 * @param {Array|Object} collection The collection to iterate over. 9679 * @param {Function} [predicate=_.identity] The function invoked per iteration. 9680 * @returns {Array} Returns the array of grouped elements. 9681 * @example 9682 * 9683 * var users = [ 9684 * { 'user': 'barney', 'age': 36, 'active': false }, 9685 * { 'user': 'fred', 'age': 40, 'active': true }, 9686 * { 'user': 'pebbles', 'age': 1, 'active': false } 9687 * ]; 9688 * 9689 * _.partition(users, function(o) { return o.active; }); 9690 * // => objects for [['fred'], ['barney', 'pebbles']] 9691 * 9692 * // The `_.matches` iteratee shorthand. 9693 * _.partition(users, { 'age': 1, 'active': false }); 9694 * // => objects for [['pebbles'], ['barney', 'fred']] 9695 * 9696 * // The `_.matchesProperty` iteratee shorthand. 9697 * _.partition(users, ['active', false]); 9698 * // => objects for [['barney', 'pebbles'], ['fred']] 9699 * 9700 * // The `_.property` iteratee shorthand. 9701 * _.partition(users, 'active'); 9702 * // => objects for [['fred'], ['barney', 'pebbles']] 9703 */ 9704 var partition = createAggregator(function(result, value, key) { 9705 result[key ? 0 : 1].push(value); 9706 }, function() { return [[], []]; }); 9707 9708 /** 9709 * Reduces `collection` to a value which is the accumulated result of running 9710 * each element in `collection` thru `iteratee`, where each successive 9711 * invocation is supplied the return value of the previous. If `accumulator` 9712 * is not given, the first element of `collection` is used as the initial 9713 * value. The iteratee is invoked with four arguments: 9714 * (accumulator, value, index|key, collection). 9715 * 9716 * Many lodash methods are guarded to work as iteratees for methods like 9717 * `_.reduce`, `_.reduceRight`, and `_.transform`. 9718 * 9719 * The guarded methods are: 9720 * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, 9721 * and `sortBy` 9722 * 9723 * @static 9724 * @memberOf _ 9725 * @since 0.1.0 9726 * @category Collection 9727 * @param {Array|Object} collection The collection to iterate over. 9728 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9729 * @param {*} [accumulator] The initial value. 9730 * @returns {*} Returns the accumulated value. 9731 * @see _.reduceRight 9732 * @example 9733 * 9734 * _.reduce([1, 2], function(sum, n) { 9735 * return sum + n; 9736 * }, 0); 9737 * // => 3 9738 * 9739 * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { 9740 * (result[value] || (result[value] = [])).push(key); 9741 * return result; 9742 * }, {}); 9743 * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) 9744 */ 9745 function reduce(collection, iteratee, accumulator) { 9746 var func = isArray(collection) ? arrayReduce : baseReduce, 9747 initAccum = arguments.length < 3; 9748 9749 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach); 9750 } 9751 9752 /** 9753 * This method is like `_.reduce` except that it iterates over elements of 9754 * `collection` from right to left. 9755 * 9756 * @static 9757 * @memberOf _ 9758 * @since 0.1.0 9759 * @category Collection 9760 * @param {Array|Object} collection The collection to iterate over. 9761 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 9762 * @param {*} [accumulator] The initial value. 9763 * @returns {*} Returns the accumulated value. 9764 * @see _.reduce 9765 * @example 9766 * 9767 * var array = [[0, 1], [2, 3], [4, 5]]; 9768 * 9769 * _.reduceRight(array, function(flattened, other) { 9770 * return flattened.concat(other); 9771 * }, []); 9772 * // => [4, 5, 2, 3, 0, 1] 9773 */ 9774 function reduceRight(collection, iteratee, accumulator) { 9775 var func = isArray(collection) ? arrayReduceRight : baseReduce, 9776 initAccum = arguments.length < 3; 9777 9778 return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight); 9779 } 9780 9781 /** 9782 * The opposite of `_.filter`; this method returns the elements of `collection` 9783 * that `predicate` does **not** return truthy for. 9784 * 9785 * @static 9786 * @memberOf _ 9787 * @since 0.1.0 9788 * @category Collection 9789 * @param {Array|Object} collection The collection to iterate over. 9790 * @param {Function} [predicate=_.identity] The function invoked per iteration. 9791 * @returns {Array} Returns the new filtered array. 9792 * @see _.filter 9793 * @example 9794 * 9795 * var users = [ 9796 * { 'user': 'barney', 'age': 36, 'active': false }, 9797 * { 'user': 'fred', 'age': 40, 'active': true } 9798 * ]; 9799 * 9800 * _.reject(users, function(o) { return !o.active; }); 9801 * // => objects for ['fred'] 9802 * 9803 * // The `_.matches` iteratee shorthand. 9804 * _.reject(users, { 'age': 40, 'active': true }); 9805 * // => objects for ['barney'] 9806 * 9807 * // The `_.matchesProperty` iteratee shorthand. 9808 * _.reject(users, ['active', false]); 9809 * // => objects for ['fred'] 9810 * 9811 * // The `_.property` iteratee shorthand. 9812 * _.reject(users, 'active'); 9813 * // => objects for ['barney'] 9814 */ 9815 function reject(collection, predicate) { 9816 var func = isArray(collection) ? arrayFilter : baseFilter; 9817 return func(collection, negate(getIteratee(predicate, 3))); 9818 } 9819 9820 /** 9821 * Gets a random element from `collection`. 9822 * 9823 * @static 9824 * @memberOf _ 9825 * @since 2.0.0 9826 * @category Collection 9827 * @param {Array|Object} collection The collection to sample. 9828 * @returns {*} Returns the random element. 9829 * @example 9830 * 9831 * _.sample([1, 2, 3, 4]); 9832 * // => 2 9833 */ 9834 function sample(collection) { 9835 var func = isArray(collection) ? arraySample : baseSample; 9836 return func(collection); 9837 } 9838 9839 /** 9840 * Gets `n` random elements at unique keys from `collection` up to the 9841 * size of `collection`. 9842 * 9843 * @static 9844 * @memberOf _ 9845 * @since 4.0.0 9846 * @category Collection 9847 * @param {Array|Object} collection The collection to sample. 9848 * @param {number} [n=1] The number of elements to sample. 9849 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 9850 * @returns {Array} Returns the random elements. 9851 * @example 9852 * 9853 * _.sampleSize([1, 2, 3], 2); 9854 * // => [3, 1] 9855 * 9856 * _.sampleSize([1, 2, 3], 4); 9857 * // => [2, 3, 1] 9858 */ 9859 function sampleSize(collection, n, guard) { 9860 if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) { 9861 n = 1; 9862 } else { 9863 n = toInteger(n); 9864 } 9865 var func = isArray(collection) ? arraySampleSize : baseSampleSize; 9866 return func(collection, n); 9867 } 9868 9869 /** 9870 * Creates an array of shuffled values, using a version of the 9871 * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). 9872 * 9873 * @static 9874 * @memberOf _ 9875 * @since 0.1.0 9876 * @category Collection 9877 * @param {Array|Object} collection The collection to shuffle. 9878 * @returns {Array} Returns the new shuffled array. 9879 * @example 9880 * 9881 * _.shuffle([1, 2, 3, 4]); 9882 * // => [4, 1, 3, 2] 9883 */ 9884 function shuffle(collection) { 9885 var func = isArray(collection) ? arrayShuffle : baseShuffle; 9886 return func(collection); 9887 } 9888 9889 /** 9890 * Gets the size of `collection` by returning its length for array-like 9891 * values or the number of own enumerable string keyed properties for objects. 9892 * 9893 * @static 9894 * @memberOf _ 9895 * @since 0.1.0 9896 * @category Collection 9897 * @param {Array|Object|string} collection The collection to inspect. 9898 * @returns {number} Returns the collection size. 9899 * @example 9900 * 9901 * _.size([1, 2, 3]); 9902 * // => 3 9903 * 9904 * _.size({ 'a': 1, 'b': 2 }); 9905 * // => 2 9906 * 9907 * _.size('pebbles'); 9908 * // => 7 9909 */ 9910 function size(collection) { 9911 if (collection == null) { 9912 return 0; 9913 } 9914 if (isArrayLike(collection)) { 9915 return isString(collection) ? stringSize(collection) : collection.length; 9916 } 9917 var tag = getTag(collection); 9918 if (tag == mapTag || tag == setTag) { 9919 return collection.size; 9920 } 9921 return baseKeys(collection).length; 9922 } 9923 9924 /** 9925 * Checks if `predicate` returns truthy for **any** element of `collection`. 9926 * Iteration is stopped once `predicate` returns truthy. The predicate is 9927 * invoked with three arguments: (value, index|key, collection). 9928 * 9929 * @static 9930 * @memberOf _ 9931 * @since 0.1.0 9932 * @category Collection 9933 * @param {Array|Object} collection The collection to iterate over. 9934 * @param {Function} [predicate=_.identity] The function invoked per iteration. 9935 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 9936 * @returns {boolean} Returns `true` if any element passes the predicate check, 9937 * else `false`. 9938 * @example 9939 * 9940 * _.some([null, 0, 'yes', false], Boolean); 9941 * // => true 9942 * 9943 * var users = [ 9944 * { 'user': 'barney', 'active': true }, 9945 * { 'user': 'fred', 'active': false } 9946 * ]; 9947 * 9948 * // The `_.matches` iteratee shorthand. 9949 * _.some(users, { 'user': 'barney', 'active': false }); 9950 * // => false 9951 * 9952 * // The `_.matchesProperty` iteratee shorthand. 9953 * _.some(users, ['active', false]); 9954 * // => true 9955 * 9956 * // The `_.property` iteratee shorthand. 9957 * _.some(users, 'active'); 9958 * // => true 9959 */ 9960 function some(collection, predicate, guard) { 9961 var func = isArray(collection) ? arraySome : baseSome; 9962 if (guard && isIterateeCall(collection, predicate, guard)) { 9963 predicate = undefined; 9964 } 9965 return func(collection, getIteratee(predicate, 3)); 9966 } 9967 9968 /** 9969 * Creates an array of elements, sorted in ascending order by the results of 9970 * running each element in a collection thru each iteratee. This method 9971 * performs a stable sort, that is, it preserves the original sort order of 9972 * equal elements. The iteratees are invoked with one argument: (value). 9973 * 9974 * @static 9975 * @memberOf _ 9976 * @since 0.1.0 9977 * @category Collection 9978 * @param {Array|Object} collection The collection to iterate over. 9979 * @param {...(Function|Function[])} [iteratees=[_.identity]] 9980 * The iteratees to sort by. 9981 * @returns {Array} Returns the new sorted array. 9982 * @example 9983 * 9984 * var users = [ 9985 * { 'user': 'fred', 'age': 48 }, 9986 * { 'user': 'barney', 'age': 36 }, 9987 * { 'user': 'fred', 'age': 30 }, 9988 * { 'user': 'barney', 'age': 34 } 9989 * ]; 9990 * 9991 * _.sortBy(users, [function(o) { return o.user; }]); 9992 * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]] 9993 * 9994 * _.sortBy(users, ['user', 'age']); 9995 * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]] 9996 */ 9997 var sortBy = baseRest(function(collection, iteratees) { 9998 if (collection == null) { 9999 return []; 10000 } 10001 var length = iteratees.length; 10002 if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { 10003 iteratees = []; 10004 } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { 10005 iteratees = [iteratees[0]]; 10006 } 10007 return baseOrderBy(collection, baseFlatten(iteratees, 1), []); 10008 }); 10009 10010 /*------------------------------------------------------------------------*/ 10011 10012 /** 10013 * Gets the timestamp of the number of milliseconds that have elapsed since 10014 * the Unix epoch (1 January 1970 00:00:00 UTC). 10015 * 10016 * @static 10017 * @memberOf _ 10018 * @since 2.4.0 10019 * @category Date 10020 * @returns {number} Returns the timestamp. 10021 * @example 10022 * 10023 * _.defer(function(stamp) { 10024 * console.log(_.now() - stamp); 10025 * }, _.now()); 10026 * // => Logs the number of milliseconds it took for the deferred invocation. 10027 */ 10028 var now = ctxNow || function() { 10029 return root.Date.now(); 10030 }; 10031 10032 /*------------------------------------------------------------------------*/ 10033 10034 /** 10035 * The opposite of `_.before`; this method creates a function that invokes 10036 * `func` once it's called `n` or more times. 10037 * 10038 * @static 10039 * @memberOf _ 10040 * @since 0.1.0 10041 * @category Function 10042 * @param {number} n The number of calls before `func` is invoked. 10043 * @param {Function} func The function to restrict. 10044 * @returns {Function} Returns the new restricted function. 10045 * @example 10046 * 10047 * var saves = ['profile', 'settings']; 10048 * 10049 * var done = _.after(saves.length, function() { 10050 * console.log('done saving!'); 10051 * }); 10052 * 10053 * _.forEach(saves, function(type) { 10054 * asyncSave({ 'type': type, 'complete': done }); 10055 * }); 10056 * // => Logs 'done saving!' after the two async saves have completed. 10057 */ 10058 function after(n, func) { 10059 if (typeof func != 'function') { 10060 throw new TypeError(FUNC_ERROR_TEXT); 10061 } 10062 n = toInteger(n); 10063 return function() { 10064 if (--n < 1) { 10065 return func.apply(this, arguments); 10066 } 10067 }; 10068 } 10069 10070 /** 10071 * Creates a function that invokes `func`, with up to `n` arguments, 10072 * ignoring any additional arguments. 10073 * 10074 * @static 10075 * @memberOf _ 10076 * @since 3.0.0 10077 * @category Function 10078 * @param {Function} func The function to cap arguments for. 10079 * @param {number} [n=func.length] The arity cap. 10080 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 10081 * @returns {Function} Returns the new capped function. 10082 * @example 10083 * 10084 * _.map(['6', '8', '10'], _.ary(parseInt, 1)); 10085 * // => [6, 8, 10] 10086 */ 10087 function ary(func, n, guard) { 10088 n = guard ? undefined : n; 10089 n = (func && n == null) ? func.length : n; 10090 return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n); 10091 } 10092 10093 /** 10094 * Creates a function that invokes `func`, with the `this` binding and arguments 10095 * of the created function, while it's called less than `n` times. Subsequent 10096 * calls to the created function return the result of the last `func` invocation. 10097 * 10098 * @static 10099 * @memberOf _ 10100 * @since 3.0.0 10101 * @category Function 10102 * @param {number} n The number of calls at which `func` is no longer invoked. 10103 * @param {Function} func The function to restrict. 10104 * @returns {Function} Returns the new restricted function. 10105 * @example 10106 * 10107 * jQuery(element).on('click', _.before(5, addContactToList)); 10108 * // => Allows adding up to 4 contacts to the list. 10109 */ 10110 function before(n, func) { 10111 var result; 10112 if (typeof func != 'function') { 10113 throw new TypeError(FUNC_ERROR_TEXT); 10114 } 10115 n = toInteger(n); 10116 return function() { 10117 if (--n > 0) { 10118 result = func.apply(this, arguments); 10119 } 10120 if (n <= 1) { 10121 func = undefined; 10122 } 10123 return result; 10124 }; 10125 } 10126 10127 /** 10128 * Creates a function that invokes `func` with the `this` binding of `thisArg` 10129 * and `partials` prepended to the arguments it receives. 10130 * 10131 * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, 10132 * may be used as a placeholder for partially applied arguments. 10133 * 10134 * **Note:** Unlike native `Function#bind`, this method doesn't set the "length" 10135 * property of bound functions. 10136 * 10137 * @static 10138 * @memberOf _ 10139 * @since 0.1.0 10140 * @category Function 10141 * @param {Function} func The function to bind. 10142 * @param {*} thisArg The `this` binding of `func`. 10143 * @param {...*} [partials] The arguments to be partially applied. 10144 * @returns {Function} Returns the new bound function. 10145 * @example 10146 * 10147 * function greet(greeting, punctuation) { 10148 * return greeting + ' ' + this.user + punctuation; 10149 * } 10150 * 10151 * var object = { 'user': 'fred' }; 10152 * 10153 * var bound = _.bind(greet, object, 'hi'); 10154 * bound('!'); 10155 * // => 'hi fred!' 10156 * 10157 * // Bound with placeholders. 10158 * var bound = _.bind(greet, object, _, '!'); 10159 * bound('hi'); 10160 * // => 'hi fred!' 10161 */ 10162 var bind = baseRest(function(func, thisArg, partials) { 10163 var bitmask = WRAP_BIND_FLAG; 10164 if (partials.length) { 10165 var holders = replaceHolders(partials, getHolder(bind)); 10166 bitmask |= WRAP_PARTIAL_FLAG; 10167 } 10168 return createWrap(func, bitmask, thisArg, partials, holders); 10169 }); 10170 10171 /** 10172 * Creates a function that invokes the method at `object[key]` with `partials` 10173 * prepended to the arguments it receives. 10174 * 10175 * This method differs from `_.bind` by allowing bound functions to reference 10176 * methods that may be redefined or don't yet exist. See 10177 * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) 10178 * for more details. 10179 * 10180 * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic 10181 * builds, may be used as a placeholder for partially applied arguments. 10182 * 10183 * @static 10184 * @memberOf _ 10185 * @since 0.10.0 10186 * @category Function 10187 * @param {Object} object The object to invoke the method on. 10188 * @param {string} key The key of the method. 10189 * @param {...*} [partials] The arguments to be partially applied. 10190 * @returns {Function} Returns the new bound function. 10191 * @example 10192 * 10193 * var object = { 10194 * 'user': 'fred', 10195 * 'greet': function(greeting, punctuation) { 10196 * return greeting + ' ' + this.user + punctuation; 10197 * } 10198 * }; 10199 * 10200 * var bound = _.bindKey(object, 'greet', 'hi'); 10201 * bound('!'); 10202 * // => 'hi fred!' 10203 * 10204 * object.greet = function(greeting, punctuation) { 10205 * return greeting + 'ya ' + this.user + punctuation; 10206 * }; 10207 * 10208 * bound('!'); 10209 * // => 'hiya fred!' 10210 * 10211 * // Bound with placeholders. 10212 * var bound = _.bindKey(object, 'greet', _, '!'); 10213 * bound('hi'); 10214 * // => 'hiya fred!' 10215 */ 10216 var bindKey = baseRest(function(object, key, partials) { 10217 var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG; 10218 if (partials.length) { 10219 var holders = replaceHolders(partials, getHolder(bindKey)); 10220 bitmask |= WRAP_PARTIAL_FLAG; 10221 } 10222 return createWrap(key, bitmask, object, partials, holders); 10223 }); 10224 10225 /** 10226 * Creates a function that accepts arguments of `func` and either invokes 10227 * `func` returning its result, if at least `arity` number of arguments have 10228 * been provided, or returns a function that accepts the remaining `func` 10229 * arguments, and so on. The arity of `func` may be specified if `func.length` 10230 * is not sufficient. 10231 * 10232 * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, 10233 * may be used as a placeholder for provided arguments. 10234 * 10235 * **Note:** This method doesn't set the "length" property of curried functions. 10236 * 10237 * @static 10238 * @memberOf _ 10239 * @since 2.0.0 10240 * @category Function 10241 * @param {Function} func The function to curry. 10242 * @param {number} [arity=func.length] The arity of `func`. 10243 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 10244 * @returns {Function} Returns the new curried function. 10245 * @example 10246 * 10247 * var abc = function(a, b, c) { 10248 * return [a, b, c]; 10249 * }; 10250 * 10251 * var curried = _.curry(abc); 10252 * 10253 * curried(1)(2)(3); 10254 * // => [1, 2, 3] 10255 * 10256 * curried(1, 2)(3); 10257 * // => [1, 2, 3] 10258 * 10259 * curried(1, 2, 3); 10260 * // => [1, 2, 3] 10261 * 10262 * // Curried with placeholders. 10263 * curried(1)(_, 3)(2); 10264 * // => [1, 2, 3] 10265 */ 10266 function curry(func, arity, guard) { 10267 arity = guard ? undefined : arity; 10268 var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); 10269 result.placeholder = curry.placeholder; 10270 return result; 10271 } 10272 10273 /** 10274 * This method is like `_.curry` except that arguments are applied to `func` 10275 * in the manner of `_.partialRight` instead of `_.partial`. 10276 * 10277 * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic 10278 * builds, may be used as a placeholder for provided arguments. 10279 * 10280 * **Note:** This method doesn't set the "length" property of curried functions. 10281 * 10282 * @static 10283 * @memberOf _ 10284 * @since 3.0.0 10285 * @category Function 10286 * @param {Function} func The function to curry. 10287 * @param {number} [arity=func.length] The arity of `func`. 10288 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 10289 * @returns {Function} Returns the new curried function. 10290 * @example 10291 * 10292 * var abc = function(a, b, c) { 10293 * return [a, b, c]; 10294 * }; 10295 * 10296 * var curried = _.curryRight(abc); 10297 * 10298 * curried(3)(2)(1); 10299 * // => [1, 2, 3] 10300 * 10301 * curried(2, 3)(1); 10302 * // => [1, 2, 3] 10303 * 10304 * curried(1, 2, 3); 10305 * // => [1, 2, 3] 10306 * 10307 * // Curried with placeholders. 10308 * curried(3)(1, _)(2); 10309 * // => [1, 2, 3] 10310 */ 10311 function curryRight(func, arity, guard) { 10312 arity = guard ? undefined : arity; 10313 var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); 10314 result.placeholder = curryRight.placeholder; 10315 return result; 10316 } 10317 10318 /** 10319 * Creates a debounced function that delays invoking `func` until after `wait` 10320 * milliseconds have elapsed since the last time the debounced function was 10321 * invoked. The debounced function comes with a `cancel` method to cancel 10322 * delayed `func` invocations and a `flush` method to immediately invoke them. 10323 * Provide `options` to indicate whether `func` should be invoked on the 10324 * leading and/or trailing edge of the `wait` timeout. The `func` is invoked 10325 * with the last arguments provided to the debounced function. Subsequent 10326 * calls to the debounced function return the result of the last `func` 10327 * invocation. 10328 * 10329 * **Note:** If `leading` and `trailing` options are `true`, `func` is 10330 * invoked on the trailing edge of the timeout only if the debounced function 10331 * is invoked more than once during the `wait` timeout. 10332 * 10333 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred 10334 * until to the next tick, similar to `setTimeout` with a timeout of `0`. 10335 * 10336 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) 10337 * for details over the differences between `_.debounce` and `_.throttle`. 10338 * 10339 * @static 10340 * @memberOf _ 10341 * @since 0.1.0 10342 * @category Function 10343 * @param {Function} func The function to debounce. 10344 * @param {number} [wait=0] The number of milliseconds to delay. 10345 * @param {Object} [options={}] The options object. 10346 * @param {boolean} [options.leading=false] 10347 * Specify invoking on the leading edge of the timeout. 10348 * @param {number} [options.maxWait] 10349 * The maximum time `func` is allowed to be delayed before it's invoked. 10350 * @param {boolean} [options.trailing=true] 10351 * Specify invoking on the trailing edge of the timeout. 10352 * @returns {Function} Returns the new debounced function. 10353 * @example 10354 * 10355 * // Avoid costly calculations while the window size is in flux. 10356 * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); 10357 * 10358 * // Invoke `sendMail` when clicked, debouncing subsequent calls. 10359 * jQuery(element).on('click', _.debounce(sendMail, 300, { 10360 * 'leading': true, 10361 * 'trailing': false 10362 * })); 10363 * 10364 * // Ensure `batchLog` is invoked once after 1 second of debounced calls. 10365 * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); 10366 * var source = new EventSource('/stream'); 10367 * jQuery(source).on('message', debounced); 10368 * 10369 * // Cancel the trailing debounced invocation. 10370 * jQuery(window).on('popstate', debounced.cancel); 10371 */ 10372 function debounce(func, wait, options) { 10373 var lastArgs, 10374 lastThis, 10375 maxWait, 10376 result, 10377 timerId, 10378 lastCallTime, 10379 lastInvokeTime = 0, 10380 leading = false, 10381 maxing = false, 10382 trailing = true; 10383 10384 if (typeof func != 'function') { 10385 throw new TypeError(FUNC_ERROR_TEXT); 10386 } 10387 wait = toNumber(wait) || 0; 10388 if (isObject(options)) { 10389 leading = !!options.leading; 10390 maxing = 'maxWait' in options; 10391 maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; 10392 trailing = 'trailing' in options ? !!options.trailing : trailing; 10393 } 10394 10395 function invokeFunc(time) { 10396 var args = lastArgs, 10397 thisArg = lastThis; 10398 10399 lastArgs = lastThis = undefined; 10400 lastInvokeTime = time; 10401 result = func.apply(thisArg, args); 10402 return result; 10403 } 10404 10405 function leadingEdge(time) { 10406 // Reset any `maxWait` timer. 10407 lastInvokeTime = time; 10408 // Start the timer for the trailing edge. 10409 timerId = setTimeout(timerExpired, wait); 10410 // Invoke the leading edge. 10411 return leading ? invokeFunc(time) : result; 10412 } 10413 10414 function remainingWait(time) { 10415 var timeSinceLastCall = time - lastCallTime, 10416 timeSinceLastInvoke = time - lastInvokeTime, 10417 timeWaiting = wait - timeSinceLastCall; 10418 10419 return maxing 10420 ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) 10421 : timeWaiting; 10422 } 10423 10424 function shouldInvoke(time) { 10425 var timeSinceLastCall = time - lastCallTime, 10426 timeSinceLastInvoke = time - lastInvokeTime; 10427 10428 // Either this is the first call, activity has stopped and we're at the 10429 // trailing edge, the system time has gone backwards and we're treating 10430 // it as the trailing edge, or we've hit the `maxWait` limit. 10431 return (lastCallTime === undefined || (timeSinceLastCall >= wait) || 10432 (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); 10433 } 10434 10435 function timerExpired() { 10436 var time = now(); 10437 if (shouldInvoke(time)) { 10438 return trailingEdge(time); 10439 } 10440 // Restart the timer. 10441 timerId = setTimeout(timerExpired, remainingWait(time)); 10442 } 10443 10444 function trailingEdge(time) { 10445 timerId = undefined; 10446 10447 // Only invoke if we have `lastArgs` which means `func` has been 10448 // debounced at least once. 10449 if (trailing && lastArgs) { 10450 return invokeFunc(time); 10451 } 10452 lastArgs = lastThis = undefined; 10453 return result; 10454 } 10455 10456 function cancel() { 10457 if (timerId !== undefined) { 10458 clearTimeout(timerId); 10459 } 10460 lastInvokeTime = 0; 10461 lastArgs = lastCallTime = lastThis = timerId = undefined; 10462 } 10463 10464 function flush() { 10465 return timerId === undefined ? result : trailingEdge(now()); 10466 } 10467 10468 function debounced() { 10469 var time = now(), 10470 isInvoking = shouldInvoke(time); 10471 10472 lastArgs = arguments; 10473 lastThis = this; 10474 lastCallTime = time; 10475 10476 if (isInvoking) { 10477 if (timerId === undefined) { 10478 return leadingEdge(lastCallTime); 10479 } 10480 if (maxing) { 10481 // Handle invocations in a tight loop. 10482 clearTimeout(timerId); 10483 timerId = setTimeout(timerExpired, wait); 10484 return invokeFunc(lastCallTime); 10485 } 10486 } 10487 if (timerId === undefined) { 10488 timerId = setTimeout(timerExpired, wait); 10489 } 10490 return result; 10491 } 10492 debounced.cancel = cancel; 10493 debounced.flush = flush; 10494 return debounced; 10495 } 10496 10497 /** 10498 * Defers invoking the `func` until the current call stack has cleared. Any 10499 * additional arguments are provided to `func` when it's invoked. 10500 * 10501 * @static 10502 * @memberOf _ 10503 * @since 0.1.0 10504 * @category Function 10505 * @param {Function} func The function to defer. 10506 * @param {...*} [args] The arguments to invoke `func` with. 10507 * @returns {number} Returns the timer id. 10508 * @example 10509 * 10510 * _.defer(function(text) { 10511 * console.log(text); 10512 * }, 'deferred'); 10513 * // => Logs 'deferred' after one millisecond. 10514 */ 10515 var defer = baseRest(function(func, args) { 10516 return baseDelay(func, 1, args); 10517 }); 10518 10519 /** 10520 * Invokes `func` after `wait` milliseconds. Any additional arguments are 10521 * provided to `func` when it's invoked. 10522 * 10523 * @static 10524 * @memberOf _ 10525 * @since 0.1.0 10526 * @category Function 10527 * @param {Function} func The function to delay. 10528 * @param {number} wait The number of milliseconds to delay invocation. 10529 * @param {...*} [args] The arguments to invoke `func` with. 10530 * @returns {number} Returns the timer id. 10531 * @example 10532 * 10533 * _.delay(function(text) { 10534 * console.log(text); 10535 * }, 1000, 'later'); 10536 * // => Logs 'later' after one second. 10537 */ 10538 var delay = baseRest(function(func, wait, args) { 10539 return baseDelay(func, toNumber(wait) || 0, args); 10540 }); 10541 10542 /** 10543 * Creates a function that invokes `func` with arguments reversed. 10544 * 10545 * @static 10546 * @memberOf _ 10547 * @since 4.0.0 10548 * @category Function 10549 * @param {Function} func The function to flip arguments for. 10550 * @returns {Function} Returns the new flipped function. 10551 * @example 10552 * 10553 * var flipped = _.flip(function() { 10554 * return _.toArray(arguments); 10555 * }); 10556 * 10557 * flipped('a', 'b', 'c', 'd'); 10558 * // => ['d', 'c', 'b', 'a'] 10559 */ 10560 function flip(func) { 10561 return createWrap(func, WRAP_FLIP_FLAG); 10562 } 10563 10564 /** 10565 * Creates a function that memoizes the result of `func`. If `resolver` is 10566 * provided, it determines the cache key for storing the result based on the 10567 * arguments provided to the memoized function. By default, the first argument 10568 * provided to the memoized function is used as the map cache key. The `func` 10569 * is invoked with the `this` binding of the memoized function. 10570 * 10571 * **Note:** The cache is exposed as the `cache` property on the memoized 10572 * function. Its creation may be customized by replacing the `_.memoize.Cache` 10573 * constructor with one whose instances implement the 10574 * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) 10575 * method interface of `clear`, `delete`, `get`, `has`, and `set`. 10576 * 10577 * @static 10578 * @memberOf _ 10579 * @since 0.1.0 10580 * @category Function 10581 * @param {Function} func The function to have its output memoized. 10582 * @param {Function} [resolver] The function to resolve the cache key. 10583 * @returns {Function} Returns the new memoized function. 10584 * @example 10585 * 10586 * var object = { 'a': 1, 'b': 2 }; 10587 * var other = { 'c': 3, 'd': 4 }; 10588 * 10589 * var values = _.memoize(_.values); 10590 * values(object); 10591 * // => [1, 2] 10592 * 10593 * values(other); 10594 * // => [3, 4] 10595 * 10596 * object.a = 2; 10597 * values(object); 10598 * // => [1, 2] 10599 * 10600 * // Modify the result cache. 10601 * values.cache.set(object, ['a', 'b']); 10602 * values(object); 10603 * // => ['a', 'b'] 10604 * 10605 * // Replace `_.memoize.Cache`. 10606 * _.memoize.Cache = WeakMap; 10607 */ 10608 function memoize(func, resolver) { 10609 if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { 10610 throw new TypeError(FUNC_ERROR_TEXT); 10611 } 10612 var memoized = function() { 10613 var args = arguments, 10614 key = resolver ? resolver.apply(this, args) : args[0], 10615 cache = memoized.cache; 10616 10617 if (cache.has(key)) { 10618 return cache.get(key); 10619 } 10620 var result = func.apply(this, args); 10621 memoized.cache = cache.set(key, result) || cache; 10622 return result; 10623 }; 10624 memoized.cache = new (memoize.Cache || MapCache); 10625 return memoized; 10626 } 10627 10628 // Expose `MapCache`. 10629 memoize.Cache = MapCache; 10630 10631 /** 10632 * Creates a function that negates the result of the predicate `func`. The 10633 * `func` predicate is invoked with the `this` binding and arguments of the 10634 * created function. 10635 * 10636 * @static 10637 * @memberOf _ 10638 * @since 3.0.0 10639 * @category Function 10640 * @param {Function} predicate The predicate to negate. 10641 * @returns {Function} Returns the new negated function. 10642 * @example 10643 * 10644 * function isEven(n) { 10645 * return n % 2 == 0; 10646 * } 10647 * 10648 * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); 10649 * // => [1, 3, 5] 10650 */ 10651 function negate(predicate) { 10652 if (typeof predicate != 'function') { 10653 throw new TypeError(FUNC_ERROR_TEXT); 10654 } 10655 return function() { 10656 var args = arguments; 10657 switch (args.length) { 10658 case 0: return !predicate.call(this); 10659 case 1: return !predicate.call(this, args[0]); 10660 case 2: return !predicate.call(this, args[0], args[1]); 10661 case 3: return !predicate.call(this, args[0], args[1], args[2]); 10662 } 10663 return !predicate.apply(this, args); 10664 }; 10665 } 10666 10667 /** 10668 * Creates a function that is restricted to invoking `func` once. Repeat calls 10669 * to the function return the value of the first invocation. The `func` is 10670 * invoked with the `this` binding and arguments of the created function. 10671 * 10672 * @static 10673 * @memberOf _ 10674 * @since 0.1.0 10675 * @category Function 10676 * @param {Function} func The function to restrict. 10677 * @returns {Function} Returns the new restricted function. 10678 * @example 10679 * 10680 * var initialize = _.once(createApplication); 10681 * initialize(); 10682 * initialize(); 10683 * // => `createApplication` is invoked once 10684 */ 10685 function once(func) { 10686 return before(2, func); 10687 } 10688 10689 /** 10690 * Creates a function that invokes `func` with its arguments transformed. 10691 * 10692 * @static 10693 * @since 4.0.0 10694 * @memberOf _ 10695 * @category Function 10696 * @param {Function} func The function to wrap. 10697 * @param {...(Function|Function[])} [transforms=[_.identity]] 10698 * The argument transforms. 10699 * @returns {Function} Returns the new function. 10700 * @example 10701 * 10702 * function doubled(n) { 10703 * return n * 2; 10704 * } 10705 * 10706 * function square(n) { 10707 * return n * n; 10708 * } 10709 * 10710 * var func = _.overArgs(function(x, y) { 10711 * return [x, y]; 10712 * }, [square, doubled]); 10713 * 10714 * func(9, 3); 10715 * // => [81, 6] 10716 * 10717 * func(10, 5); 10718 * // => [100, 10] 10719 */ 10720 var overArgs = castRest(function(func, transforms) { 10721 transforms = (transforms.length == 1 && isArray(transforms[0])) 10722 ? arrayMap(transforms[0], baseUnary(getIteratee())) 10723 : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee())); 10724 10725 var funcsLength = transforms.length; 10726 return baseRest(function(args) { 10727 var index = -1, 10728 length = nativeMin(args.length, funcsLength); 10729 10730 while (++index < length) { 10731 args[index] = transforms[index].call(this, args[index]); 10732 } 10733 return apply(func, this, args); 10734 }); 10735 }); 10736 10737 /** 10738 * Creates a function that invokes `func` with `partials` prepended to the 10739 * arguments it receives. This method is like `_.bind` except it does **not** 10740 * alter the `this` binding. 10741 * 10742 * The `_.partial.placeholder` value, which defaults to `_` in monolithic 10743 * builds, may be used as a placeholder for partially applied arguments. 10744 * 10745 * **Note:** This method doesn't set the "length" property of partially 10746 * applied functions. 10747 * 10748 * @static 10749 * @memberOf _ 10750 * @since 0.2.0 10751 * @category Function 10752 * @param {Function} func The function to partially apply arguments to. 10753 * @param {...*} [partials] The arguments to be partially applied. 10754 * @returns {Function} Returns the new partially applied function. 10755 * @example 10756 * 10757 * function greet(greeting, name) { 10758 * return greeting + ' ' + name; 10759 * } 10760 * 10761 * var sayHelloTo = _.partial(greet, 'hello'); 10762 * sayHelloTo('fred'); 10763 * // => 'hello fred' 10764 * 10765 * // Partially applied with placeholders. 10766 * var greetFred = _.partial(greet, _, 'fred'); 10767 * greetFred('hi'); 10768 * // => 'hi fred' 10769 */ 10770 var partial = baseRest(function(func, partials) { 10771 var holders = replaceHolders(partials, getHolder(partial)); 10772 return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders); 10773 }); 10774 10775 /** 10776 * This method is like `_.partial` except that partially applied arguments 10777 * are appended to the arguments it receives. 10778 * 10779 * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic 10780 * builds, may be used as a placeholder for partially applied arguments. 10781 * 10782 * **Note:** This method doesn't set the "length" property of partially 10783 * applied functions. 10784 * 10785 * @static 10786 * @memberOf _ 10787 * @since 1.0.0 10788 * @category Function 10789 * @param {Function} func The function to partially apply arguments to. 10790 * @param {...*} [partials] The arguments to be partially applied. 10791 * @returns {Function} Returns the new partially applied function. 10792 * @example 10793 * 10794 * function greet(greeting, name) { 10795 * return greeting + ' ' + name; 10796 * } 10797 * 10798 * var greetFred = _.partialRight(greet, 'fred'); 10799 * greetFred('hi'); 10800 * // => 'hi fred' 10801 * 10802 * // Partially applied with placeholders. 10803 * var sayHelloTo = _.partialRight(greet, 'hello', _); 10804 * sayHelloTo('fred'); 10805 * // => 'hello fred' 10806 */ 10807 var partialRight = baseRest(function(func, partials) { 10808 var holders = replaceHolders(partials, getHolder(partialRight)); 10809 return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders); 10810 }); 10811 10812 /** 10813 * Creates a function that invokes `func` with arguments arranged according 10814 * to the specified `indexes` where the argument value at the first index is 10815 * provided as the first argument, the argument value at the second index is 10816 * provided as the second argument, and so on. 10817 * 10818 * @static 10819 * @memberOf _ 10820 * @since 3.0.0 10821 * @category Function 10822 * @param {Function} func The function to rearrange arguments for. 10823 * @param {...(number|number[])} indexes The arranged argument indexes. 10824 * @returns {Function} Returns the new function. 10825 * @example 10826 * 10827 * var rearged = _.rearg(function(a, b, c) { 10828 * return [a, b, c]; 10829 * }, [2, 0, 1]); 10830 * 10831 * rearged('b', 'c', 'a') 10832 * // => ['a', 'b', 'c'] 10833 */ 10834 var rearg = flatRest(function(func, indexes) { 10835 return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes); 10836 }); 10837 10838 /** 10839 * Creates a function that invokes `func` with the `this` binding of the 10840 * created function and arguments from `start` and beyond provided as 10841 * an array. 10842 * 10843 * **Note:** This method is based on the 10844 * [rest parameter](https://mdn.io/rest_parameters). 10845 * 10846 * @static 10847 * @memberOf _ 10848 * @since 4.0.0 10849 * @category Function 10850 * @param {Function} func The function to apply a rest parameter to. 10851 * @param {number} [start=func.length-1] The start position of the rest parameter. 10852 * @returns {Function} Returns the new function. 10853 * @example 10854 * 10855 * var say = _.rest(function(what, names) { 10856 * return what + ' ' + _.initial(names).join(', ') + 10857 * (_.size(names) > 1 ? ', & ' : '') + _.last(names); 10858 * }); 10859 * 10860 * say('hello', 'fred', 'barney', 'pebbles'); 10861 * // => 'hello fred, barney, & pebbles' 10862 */ 10863 function rest(func, start) { 10864 if (typeof func != 'function') { 10865 throw new TypeError(FUNC_ERROR_TEXT); 10866 } 10867 start = start === undefined ? start : toInteger(start); 10868 return baseRest(func, start); 10869 } 10870 10871 /** 10872 * Creates a function that invokes `func` with the `this` binding of the 10873 * create function and an array of arguments much like 10874 * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply). 10875 * 10876 * **Note:** This method is based on the 10877 * [spread operator](https://mdn.io/spread_operator). 10878 * 10879 * @static 10880 * @memberOf _ 10881 * @since 3.2.0 10882 * @category Function 10883 * @param {Function} func The function to spread arguments over. 10884 * @param {number} [start=0] The start position of the spread. 10885 * @returns {Function} Returns the new function. 10886 * @example 10887 * 10888 * var say = _.spread(function(who, what) { 10889 * return who + ' says ' + what; 10890 * }); 10891 * 10892 * say(['fred', 'hello']); 10893 * // => 'fred says hello' 10894 * 10895 * var numbers = Promise.all([ 10896 * Promise.resolve(40), 10897 * Promise.resolve(36) 10898 * ]); 10899 * 10900 * numbers.then(_.spread(function(x, y) { 10901 * return x + y; 10902 * })); 10903 * // => a Promise of 76 10904 */ 10905 function spread(func, start) { 10906 if (typeof func != 'function') { 10907 throw new TypeError(FUNC_ERROR_TEXT); 10908 } 10909 start = start == null ? 0 : nativeMax(toInteger(start), 0); 10910 return baseRest(function(args) { 10911 var array = args[start], 10912 otherArgs = castSlice(args, 0, start); 10913 10914 if (array) { 10915 arrayPush(otherArgs, array); 10916 } 10917 return apply(func, this, otherArgs); 10918 }); 10919 } 10920 10921 /** 10922 * Creates a throttled function that only invokes `func` at most once per 10923 * every `wait` milliseconds. The throttled function comes with a `cancel` 10924 * method to cancel delayed `func` invocations and a `flush` method to 10925 * immediately invoke them. Provide `options` to indicate whether `func` 10926 * should be invoked on the leading and/or trailing edge of the `wait` 10927 * timeout. The `func` is invoked with the last arguments provided to the 10928 * throttled function. Subsequent calls to the throttled function return the 10929 * result of the last `func` invocation. 10930 * 10931 * **Note:** If `leading` and `trailing` options are `true`, `func` is 10932 * invoked on the trailing edge of the timeout only if the throttled function 10933 * is invoked more than once during the `wait` timeout. 10934 * 10935 * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred 10936 * until to the next tick, similar to `setTimeout` with a timeout of `0`. 10937 * 10938 * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) 10939 * for details over the differences between `_.throttle` and `_.debounce`. 10940 * 10941 * @static 10942 * @memberOf _ 10943 * @since 0.1.0 10944 * @category Function 10945 * @param {Function} func The function to throttle. 10946 * @param {number} [wait=0] The number of milliseconds to throttle invocations to. 10947 * @param {Object} [options={}] The options object. 10948 * @param {boolean} [options.leading=true] 10949 * Specify invoking on the leading edge of the timeout. 10950 * @param {boolean} [options.trailing=true] 10951 * Specify invoking on the trailing edge of the timeout. 10952 * @returns {Function} Returns the new throttled function. 10953 * @example 10954 * 10955 * // Avoid excessively updating the position while scrolling. 10956 * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); 10957 * 10958 * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. 10959 * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); 10960 * jQuery(element).on('click', throttled); 10961 * 10962 * // Cancel the trailing throttled invocation. 10963 * jQuery(window).on('popstate', throttled.cancel); 10964 */ 10965 function throttle(func, wait, options) { 10966 var leading = true, 10967 trailing = true; 10968 10969 if (typeof func != 'function') { 10970 throw new TypeError(FUNC_ERROR_TEXT); 10971 } 10972 if (isObject(options)) { 10973 leading = 'leading' in options ? !!options.leading : leading; 10974 trailing = 'trailing' in options ? !!options.trailing : trailing; 10975 } 10976 return debounce(func, wait, { 10977 'leading': leading, 10978 'maxWait': wait, 10979 'trailing': trailing 10980 }); 10981 } 10982 10983 /** 10984 * Creates a function that accepts up to one argument, ignoring any 10985 * additional arguments. 10986 * 10987 * @static 10988 * @memberOf _ 10989 * @since 4.0.0 10990 * @category Function 10991 * @param {Function} func The function to cap arguments for. 10992 * @returns {Function} Returns the new capped function. 10993 * @example 10994 * 10995 * _.map(['6', '8', '10'], _.unary(parseInt)); 10996 * // => [6, 8, 10] 10997 */ 10998 function unary(func) { 10999 return ary(func, 1); 11000 } 11001 11002 /** 11003 * Creates a function that provides `value` to `wrapper` as its first 11004 * argument. Any additional arguments provided to the function are appended 11005 * to those provided to the `wrapper`. The wrapper is invoked with the `this` 11006 * binding of the created function. 11007 * 11008 * @static 11009 * @memberOf _ 11010 * @since 0.1.0 11011 * @category Function 11012 * @param {*} value The value to wrap. 11013 * @param {Function} [wrapper=identity] The wrapper function. 11014 * @returns {Function} Returns the new function. 11015 * @example 11016 * 11017 * var p = _.wrap(_.escape, function(func, text) { 11018 * return '<p>' + func(text) + '</p>'; 11019 * }); 11020 * 11021 * p('fred, barney, & pebbles'); 11022 * // => '<p>fred, barney, & pebbles</p>' 11023 */ 11024 function wrap(value, wrapper) { 11025 return partial(castFunction(wrapper), value); 11026 } 11027 11028 /*------------------------------------------------------------------------*/ 11029 11030 /** 11031 * Casts `value` as an array if it's not one. 11032 * 11033 * @static 11034 * @memberOf _ 11035 * @since 4.4.0 11036 * @category Lang 11037 * @param {*} value The value to inspect. 11038 * @returns {Array} Returns the cast array. 11039 * @example 11040 * 11041 * _.castArray(1); 11042 * // => [1] 11043 * 11044 * _.castArray({ 'a': 1 }); 11045 * // => [{ 'a': 1 }] 11046 * 11047 * _.castArray('abc'); 11048 * // => ['abc'] 11049 * 11050 * _.castArray(null); 11051 * // => [null] 11052 * 11053 * _.castArray(undefined); 11054 * // => [undefined] 11055 * 11056 * _.castArray(); 11057 * // => [] 11058 * 11059 * var array = [1, 2, 3]; 11060 * console.log(_.castArray(array) === array); 11061 * // => true 11062 */ 11063 function castArray() { 11064 if (!arguments.length) { 11065 return []; 11066 } 11067 var value = arguments[0]; 11068 return isArray(value) ? value : [value]; 11069 } 11070 11071 /** 11072 * Creates a shallow clone of `value`. 11073 * 11074 * **Note:** This method is loosely based on the 11075 * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) 11076 * and supports cloning arrays, array buffers, booleans, date objects, maps, 11077 * numbers, `Object` objects, regexes, sets, strings, symbols, and typed 11078 * arrays. The own enumerable properties of `arguments` objects are cloned 11079 * as plain objects. An empty object is returned for uncloneable values such 11080 * as error objects, functions, DOM nodes, and WeakMaps. 11081 * 11082 * @static 11083 * @memberOf _ 11084 * @since 0.1.0 11085 * @category Lang 11086 * @param {*} value The value to clone. 11087 * @returns {*} Returns the cloned value. 11088 * @see _.cloneDeep 11089 * @example 11090 * 11091 * var objects = [{ 'a': 1 }, { 'b': 2 }]; 11092 * 11093 * var shallow = _.clone(objects); 11094 * console.log(shallow[0] === objects[0]); 11095 * // => true 11096 */ 11097 function clone(value) { 11098 return baseClone(value, CLONE_SYMBOLS_FLAG); 11099 } 11100 11101 /** 11102 * This method is like `_.clone` except that it accepts `customizer` which 11103 * is invoked to produce the cloned value. If `customizer` returns `undefined`, 11104 * cloning is handled by the method instead. The `customizer` is invoked with 11105 * up to four arguments; (value [, index|key, object, stack]). 11106 * 11107 * @static 11108 * @memberOf _ 11109 * @since 4.0.0 11110 * @category Lang 11111 * @param {*} value The value to clone. 11112 * @param {Function} [customizer] The function to customize cloning. 11113 * @returns {*} Returns the cloned value. 11114 * @see _.cloneDeepWith 11115 * @example 11116 * 11117 * function customizer(value) { 11118 * if (_.isElement(value)) { 11119 * return value.cloneNode(false); 11120 * } 11121 * } 11122 * 11123 * var el = _.cloneWith(document.body, customizer); 11124 * 11125 * console.log(el === document.body); 11126 * // => false 11127 * console.log(el.nodeName); 11128 * // => 'BODY' 11129 * console.log(el.childNodes.length); 11130 * // => 0 11131 */ 11132 function cloneWith(value, customizer) { 11133 customizer = typeof customizer == 'function' ? customizer : undefined; 11134 return baseClone(value, CLONE_SYMBOLS_FLAG, customizer); 11135 } 11136 11137 /** 11138 * This method is like `_.clone` except that it recursively clones `value`. 11139 * 11140 * @static 11141 * @memberOf _ 11142 * @since 1.0.0 11143 * @category Lang 11144 * @param {*} value The value to recursively clone. 11145 * @returns {*} Returns the deep cloned value. 11146 * @see _.clone 11147 * @example 11148 * 11149 * var objects = [{ 'a': 1 }, { 'b': 2 }]; 11150 * 11151 * var deep = _.cloneDeep(objects); 11152 * console.log(deep[0] === objects[0]); 11153 * // => false 11154 */ 11155 function cloneDeep(value) { 11156 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG); 11157 } 11158 11159 /** 11160 * This method is like `_.cloneWith` except that it recursively clones `value`. 11161 * 11162 * @static 11163 * @memberOf _ 11164 * @since 4.0.0 11165 * @category Lang 11166 * @param {*} value The value to recursively clone. 11167 * @param {Function} [customizer] The function to customize cloning. 11168 * @returns {*} Returns the deep cloned value. 11169 * @see _.cloneWith 11170 * @example 11171 * 11172 * function customizer(value) { 11173 * if (_.isElement(value)) { 11174 * return value.cloneNode(true); 11175 * } 11176 * } 11177 * 11178 * var el = _.cloneDeepWith(document.body, customizer); 11179 * 11180 * console.log(el === document.body); 11181 * // => false 11182 * console.log(el.nodeName); 11183 * // => 'BODY' 11184 * console.log(el.childNodes.length); 11185 * // => 20 11186 */ 11187 function cloneDeepWith(value, customizer) { 11188 customizer = typeof customizer == 'function' ? customizer : undefined; 11189 return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer); 11190 } 11191 11192 /** 11193 * Checks if `object` conforms to `source` by invoking the predicate 11194 * properties of `source` with the corresponding property values of `object`. 11195 * 11196 * **Note:** This method is equivalent to `_.conforms` when `source` is 11197 * partially applied. 11198 * 11199 * @static 11200 * @memberOf _ 11201 * @since 4.14.0 11202 * @category Lang 11203 * @param {Object} object The object to inspect. 11204 * @param {Object} source The object of property predicates to conform to. 11205 * @returns {boolean} Returns `true` if `object` conforms, else `false`. 11206 * @example 11207 * 11208 * var object = { 'a': 1, 'b': 2 }; 11209 * 11210 * _.conformsTo(object, { 'b': function(n) { return n > 1; } }); 11211 * // => true 11212 * 11213 * _.conformsTo(object, { 'b': function(n) { return n > 2; } }); 11214 * // => false 11215 */ 11216 function conformsTo(object, source) { 11217 return source == null || baseConformsTo(object, source, keys(source)); 11218 } 11219 11220 /** 11221 * Performs a 11222 * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 11223 * comparison between two values to determine if they are equivalent. 11224 * 11225 * @static 11226 * @memberOf _ 11227 * @since 4.0.0 11228 * @category Lang 11229 * @param {*} value The value to compare. 11230 * @param {*} other The other value to compare. 11231 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 11232 * @example 11233 * 11234 * var object = { 'a': 1 }; 11235 * var other = { 'a': 1 }; 11236 * 11237 * _.eq(object, object); 11238 * // => true 11239 * 11240 * _.eq(object, other); 11241 * // => false 11242 * 11243 * _.eq('a', 'a'); 11244 * // => true 11245 * 11246 * _.eq('a', Object('a')); 11247 * // => false 11248 * 11249 * _.eq(NaN, NaN); 11250 * // => true 11251 */ 11252 function eq(value, other) { 11253 return value === other || (value !== value && other !== other); 11254 } 11255 11256 /** 11257 * Checks if `value` is greater than `other`. 11258 * 11259 * @static 11260 * @memberOf _ 11261 * @since 3.9.0 11262 * @category Lang 11263 * @param {*} value The value to compare. 11264 * @param {*} other The other value to compare. 11265 * @returns {boolean} Returns `true` if `value` is greater than `other`, 11266 * else `false`. 11267 * @see _.lt 11268 * @example 11269 * 11270 * _.gt(3, 1); 11271 * // => true 11272 * 11273 * _.gt(3, 3); 11274 * // => false 11275 * 11276 * _.gt(1, 3); 11277 * // => false 11278 */ 11279 var gt = createRelationalOperation(baseGt); 11280 11281 /** 11282 * Checks if `value` is greater than or equal to `other`. 11283 * 11284 * @static 11285 * @memberOf _ 11286 * @since 3.9.0 11287 * @category Lang 11288 * @param {*} value The value to compare. 11289 * @param {*} other The other value to compare. 11290 * @returns {boolean} Returns `true` if `value` is greater than or equal to 11291 * `other`, else `false`. 11292 * @see _.lte 11293 * @example 11294 * 11295 * _.gte(3, 1); 11296 * // => true 11297 * 11298 * _.gte(3, 3); 11299 * // => true 11300 * 11301 * _.gte(1, 3); 11302 * // => false 11303 */ 11304 var gte = createRelationalOperation(function(value, other) { 11305 return value >= other; 11306 }); 11307 11308 /** 11309 * Checks if `value` is likely an `arguments` object. 11310 * 11311 * @static 11312 * @memberOf _ 11313 * @since 0.1.0 11314 * @category Lang 11315 * @param {*} value The value to check. 11316 * @returns {boolean} Returns `true` if `value` is an `arguments` object, 11317 * else `false`. 11318 * @example 11319 * 11320 * _.isArguments(function() { return arguments; }()); 11321 * // => true 11322 * 11323 * _.isArguments([1, 2, 3]); 11324 * // => false 11325 */ 11326 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { 11327 return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && 11328 !propertyIsEnumerable.call(value, 'callee'); 11329 }; 11330 11331 /** 11332 * Checks if `value` is classified as an `Array` object. 11333 * 11334 * @static 11335 * @memberOf _ 11336 * @since 0.1.0 11337 * @category Lang 11338 * @param {*} value The value to check. 11339 * @returns {boolean} Returns `true` if `value` is an array, else `false`. 11340 * @example 11341 * 11342 * _.isArray([1, 2, 3]); 11343 * // => true 11344 * 11345 * _.isArray(document.body.children); 11346 * // => false 11347 * 11348 * _.isArray('abc'); 11349 * // => false 11350 * 11351 * _.isArray(_.noop); 11352 * // => false 11353 */ 11354 var isArray = Array.isArray; 11355 11356 /** 11357 * Checks if `value` is classified as an `ArrayBuffer` object. 11358 * 11359 * @static 11360 * @memberOf _ 11361 * @since 4.3.0 11362 * @category Lang 11363 * @param {*} value The value to check. 11364 * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. 11365 * @example 11366 * 11367 * _.isArrayBuffer(new ArrayBuffer(2)); 11368 * // => true 11369 * 11370 * _.isArrayBuffer(new Array(2)); 11371 * // => false 11372 */ 11373 var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; 11374 11375 /** 11376 * Checks if `value` is array-like. A value is considered array-like if it's 11377 * not a function and has a `value.length` that's an integer greater than or 11378 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. 11379 * 11380 * @static 11381 * @memberOf _ 11382 * @since 4.0.0 11383 * @category Lang 11384 * @param {*} value The value to check. 11385 * @returns {boolean} Returns `true` if `value` is array-like, else `false`. 11386 * @example 11387 * 11388 * _.isArrayLike([1, 2, 3]); 11389 * // => true 11390 * 11391 * _.isArrayLike(document.body.children); 11392 * // => true 11393 * 11394 * _.isArrayLike('abc'); 11395 * // => true 11396 * 11397 * _.isArrayLike(_.noop); 11398 * // => false 11399 */ 11400 function isArrayLike(value) { 11401 return value != null && isLength(value.length) && !isFunction(value); 11402 } 11403 11404 /** 11405 * This method is like `_.isArrayLike` except that it also checks if `value` 11406 * is an object. 11407 * 11408 * @static 11409 * @memberOf _ 11410 * @since 4.0.0 11411 * @category Lang 11412 * @param {*} value The value to check. 11413 * @returns {boolean} Returns `true` if `value` is an array-like object, 11414 * else `false`. 11415 * @example 11416 * 11417 * _.isArrayLikeObject([1, 2, 3]); 11418 * // => true 11419 * 11420 * _.isArrayLikeObject(document.body.children); 11421 * // => true 11422 * 11423 * _.isArrayLikeObject('abc'); 11424 * // => false 11425 * 11426 * _.isArrayLikeObject(_.noop); 11427 * // => false 11428 */ 11429 function isArrayLikeObject(value) { 11430 return isObjectLike(value) && isArrayLike(value); 11431 } 11432 11433 /** 11434 * Checks if `value` is classified as a boolean primitive or object. 11435 * 11436 * @static 11437 * @memberOf _ 11438 * @since 0.1.0 11439 * @category Lang 11440 * @param {*} value The value to check. 11441 * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. 11442 * @example 11443 * 11444 * _.isBoolean(false); 11445 * // => true 11446 * 11447 * _.isBoolean(null); 11448 * // => false 11449 */ 11450 function isBoolean(value) { 11451 return value === true || value === false || 11452 (isObjectLike(value) && baseGetTag(value) == boolTag); 11453 } 11454 11455 /** 11456 * Checks if `value` is a buffer. 11457 * 11458 * @static 11459 * @memberOf _ 11460 * @since 4.3.0 11461 * @category Lang 11462 * @param {*} value The value to check. 11463 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. 11464 * @example 11465 * 11466 * _.isBuffer(new Buffer(2)); 11467 * // => true 11468 * 11469 * _.isBuffer(new Uint8Array(2)); 11470 * // => false 11471 */ 11472 var isBuffer = nativeIsBuffer || stubFalse; 11473 11474 /** 11475 * Checks if `value` is classified as a `Date` object. 11476 * 11477 * @static 11478 * @memberOf _ 11479 * @since 0.1.0 11480 * @category Lang 11481 * @param {*} value The value to check. 11482 * @returns {boolean} Returns `true` if `value` is a date object, else `false`. 11483 * @example 11484 * 11485 * _.isDate(new Date); 11486 * // => true 11487 * 11488 * _.isDate('Mon April 23 2012'); 11489 * // => false 11490 */ 11491 var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; 11492 11493 /** 11494 * Checks if `value` is likely a DOM element. 11495 * 11496 * @static 11497 * @memberOf _ 11498 * @since 0.1.0 11499 * @category Lang 11500 * @param {*} value The value to check. 11501 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. 11502 * @example 11503 * 11504 * _.isElement(document.body); 11505 * // => true 11506 * 11507 * _.isElement('<body>'); 11508 * // => false 11509 */ 11510 function isElement(value) { 11511 return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); 11512 } 11513 11514 /** 11515 * Checks if `value` is an empty object, collection, map, or set. 11516 * 11517 * Objects are considered empty if they have no own enumerable string keyed 11518 * properties. 11519 * 11520 * Array-like values such as `arguments` objects, arrays, buffers, strings, or 11521 * jQuery-like collections are considered empty if they have a `length` of `0`. 11522 * Similarly, maps and sets are considered empty if they have a `size` of `0`. 11523 * 11524 * @static 11525 * @memberOf _ 11526 * @since 0.1.0 11527 * @category Lang 11528 * @param {*} value The value to check. 11529 * @returns {boolean} Returns `true` if `value` is empty, else `false`. 11530 * @example 11531 * 11532 * _.isEmpty(null); 11533 * // => true 11534 * 11535 * _.isEmpty(true); 11536 * // => true 11537 * 11538 * _.isEmpty(1); 11539 * // => true 11540 * 11541 * _.isEmpty([1, 2, 3]); 11542 * // => false 11543 * 11544 * _.isEmpty({ 'a': 1 }); 11545 * // => false 11546 */ 11547 function isEmpty(value) { 11548 if (value == null) { 11549 return true; 11550 } 11551 if (isArrayLike(value) && 11552 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || 11553 isBuffer(value) || isTypedArray(value) || isArguments(value))) { 11554 return !value.length; 11555 } 11556 var tag = getTag(value); 11557 if (tag == mapTag || tag == setTag) { 11558 return !value.size; 11559 } 11560 if (isPrototype(value)) { 11561 return !baseKeys(value).length; 11562 } 11563 for (var key in value) { 11564 if (hasOwnProperty.call(value, key)) { 11565 return false; 11566 } 11567 } 11568 return true; 11569 } 11570 11571 /** 11572 * Performs a deep comparison between two values to determine if they are 11573 * equivalent. 11574 * 11575 * **Note:** This method supports comparing arrays, array buffers, booleans, 11576 * date objects, error objects, maps, numbers, `Object` objects, regexes, 11577 * sets, strings, symbols, and typed arrays. `Object` objects are compared 11578 * by their own, not inherited, enumerable properties. Functions and DOM 11579 * nodes are compared by strict equality, i.e. `===`. 11580 * 11581 * @static 11582 * @memberOf _ 11583 * @since 0.1.0 11584 * @category Lang 11585 * @param {*} value The value to compare. 11586 * @param {*} other The other value to compare. 11587 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 11588 * @example 11589 * 11590 * var object = { 'a': 1 }; 11591 * var other = { 'a': 1 }; 11592 * 11593 * _.isEqual(object, other); 11594 * // => true 11595 * 11596 * object === other; 11597 * // => false 11598 */ 11599 function isEqual(value, other) { 11600 return baseIsEqual(value, other); 11601 } 11602 11603 /** 11604 * This method is like `_.isEqual` except that it accepts `customizer` which 11605 * is invoked to compare values. If `customizer` returns `undefined`, comparisons 11606 * are handled by the method instead. The `customizer` is invoked with up to 11607 * six arguments: (objValue, othValue [, index|key, object, other, stack]). 11608 * 11609 * @static 11610 * @memberOf _ 11611 * @since 4.0.0 11612 * @category Lang 11613 * @param {*} value The value to compare. 11614 * @param {*} other The other value to compare. 11615 * @param {Function} [customizer] The function to customize comparisons. 11616 * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 11617 * @example 11618 * 11619 * function isGreeting(value) { 11620 * return /^h(?:i|ello)$/.test(value); 11621 * } 11622 * 11623 * function customizer(objValue, othValue) { 11624 * if (isGreeting(objValue) && isGreeting(othValue)) { 11625 * return true; 11626 * } 11627 * } 11628 * 11629 * var array = ['hello', 'goodbye']; 11630 * var other = ['hi', 'goodbye']; 11631 * 11632 * _.isEqualWith(array, other, customizer); 11633 * // => true 11634 */ 11635 function isEqualWith(value, other, customizer) { 11636 customizer = typeof customizer == 'function' ? customizer : undefined; 11637 var result = customizer ? customizer(value, other) : undefined; 11638 return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result; 11639 } 11640 11641 /** 11642 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, 11643 * `SyntaxError`, `TypeError`, or `URIError` object. 11644 * 11645 * @static 11646 * @memberOf _ 11647 * @since 3.0.0 11648 * @category Lang 11649 * @param {*} value The value to check. 11650 * @returns {boolean} Returns `true` if `value` is an error object, else `false`. 11651 * @example 11652 * 11653 * _.isError(new Error); 11654 * // => true 11655 * 11656 * _.isError(Error); 11657 * // => false 11658 */ 11659 function isError(value) { 11660 if (!isObjectLike(value)) { 11661 return false; 11662 } 11663 var tag = baseGetTag(value); 11664 return tag == errorTag || tag == domExcTag || 11665 (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); 11666 } 11667 11668 /** 11669 * Checks if `value` is a finite primitive number. 11670 * 11671 * **Note:** This method is based on 11672 * [`Number.isFinite`](https://mdn.io/Number/isFinite). 11673 * 11674 * @static 11675 * @memberOf _ 11676 * @since 0.1.0 11677 * @category Lang 11678 * @param {*} value The value to check. 11679 * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. 11680 * @example 11681 * 11682 * _.isFinite(3); 11683 * // => true 11684 * 11685 * _.isFinite(Number.MIN_VALUE); 11686 * // => true 11687 * 11688 * _.isFinite(Infinity); 11689 * // => false 11690 * 11691 * _.isFinite('3'); 11692 * // => false 11693 */ 11694 function isFinite(value) { 11695 return typeof value == 'number' && nativeIsFinite(value); 11696 } 11697 11698 /** 11699 * Checks if `value` is classified as a `Function` object. 11700 * 11701 * @static 11702 * @memberOf _ 11703 * @since 0.1.0 11704 * @category Lang 11705 * @param {*} value The value to check. 11706 * @returns {boolean} Returns `true` if `value` is a function, else `false`. 11707 * @example 11708 * 11709 * _.isFunction(_); 11710 * // => true 11711 * 11712 * _.isFunction(/abc/); 11713 * // => false 11714 */ 11715 function isFunction(value) { 11716 if (!isObject(value)) { 11717 return false; 11718 } 11719 // The use of `Object#toString` avoids issues with the `typeof` operator 11720 // in Safari 9 which returns 'object' for typed arrays and other constructors. 11721 var tag = baseGetTag(value); 11722 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; 11723 } 11724 11725 /** 11726 * Checks if `value` is an integer. 11727 * 11728 * **Note:** This method is based on 11729 * [`Number.isInteger`](https://mdn.io/Number/isInteger). 11730 * 11731 * @static 11732 * @memberOf _ 11733 * @since 4.0.0 11734 * @category Lang 11735 * @param {*} value The value to check. 11736 * @returns {boolean} Returns `true` if `value` is an integer, else `false`. 11737 * @example 11738 * 11739 * _.isInteger(3); 11740 * // => true 11741 * 11742 * _.isInteger(Number.MIN_VALUE); 11743 * // => false 11744 * 11745 * _.isInteger(Infinity); 11746 * // => false 11747 * 11748 * _.isInteger('3'); 11749 * // => false 11750 */ 11751 function isInteger(value) { 11752 return typeof value == 'number' && value == toInteger(value); 11753 } 11754 11755 /** 11756 * Checks if `value` is a valid array-like length. 11757 * 11758 * **Note:** This method is loosely based on 11759 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). 11760 * 11761 * @static 11762 * @memberOf _ 11763 * @since 4.0.0 11764 * @category Lang 11765 * @param {*} value The value to check. 11766 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. 11767 * @example 11768 * 11769 * _.isLength(3); 11770 * // => true 11771 * 11772 * _.isLength(Number.MIN_VALUE); 11773 * // => false 11774 * 11775 * _.isLength(Infinity); 11776 * // => false 11777 * 11778 * _.isLength('3'); 11779 * // => false 11780 */ 11781 function isLength(value) { 11782 return typeof value == 'number' && 11783 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; 11784 } 11785 11786 /** 11787 * Checks if `value` is the 11788 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) 11789 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) 11790 * 11791 * @static 11792 * @memberOf _ 11793 * @since 0.1.0 11794 * @category Lang 11795 * @param {*} value The value to check. 11796 * @returns {boolean} Returns `true` if `value` is an object, else `false`. 11797 * @example 11798 * 11799 * _.isObject({}); 11800 * // => true 11801 * 11802 * _.isObject([1, 2, 3]); 11803 * // => true 11804 * 11805 * _.isObject(_.noop); 11806 * // => true 11807 * 11808 * _.isObject(null); 11809 * // => false 11810 */ 11811 function isObject(value) { 11812 var type = typeof value; 11813 return value != null && (type == 'object' || type == 'function'); 11814 } 11815 11816 /** 11817 * Checks if `value` is object-like. A value is object-like if it's not `null` 11818 * and has a `typeof` result of "object". 11819 * 11820 * @static 11821 * @memberOf _ 11822 * @since 4.0.0 11823 * @category Lang 11824 * @param {*} value The value to check. 11825 * @returns {boolean} Returns `true` if `value` is object-like, else `false`. 11826 * @example 11827 * 11828 * _.isObjectLike({}); 11829 * // => true 11830 * 11831 * _.isObjectLike([1, 2, 3]); 11832 * // => true 11833 * 11834 * _.isObjectLike(_.noop); 11835 * // => false 11836 * 11837 * _.isObjectLike(null); 11838 * // => false 11839 */ 11840 function isObjectLike(value) { 11841 return value != null && typeof value == 'object'; 11842 } 11843 11844 /** 11845 * Checks if `value` is classified as a `Map` object. 11846 * 11847 * @static 11848 * @memberOf _ 11849 * @since 4.3.0 11850 * @category Lang 11851 * @param {*} value The value to check. 11852 * @returns {boolean} Returns `true` if `value` is a map, else `false`. 11853 * @example 11854 * 11855 * _.isMap(new Map); 11856 * // => true 11857 * 11858 * _.isMap(new WeakMap); 11859 * // => false 11860 */ 11861 var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; 11862 11863 /** 11864 * Performs a partial deep comparison between `object` and `source` to 11865 * determine if `object` contains equivalent property values. 11866 * 11867 * **Note:** This method is equivalent to `_.matches` when `source` is 11868 * partially applied. 11869 * 11870 * Partial comparisons will match empty array and empty object `source` 11871 * values against any array or object value, respectively. See `_.isEqual` 11872 * for a list of supported value comparisons. 11873 * 11874 * @static 11875 * @memberOf _ 11876 * @since 3.0.0 11877 * @category Lang 11878 * @param {Object} object The object to inspect. 11879 * @param {Object} source The object of property values to match. 11880 * @returns {boolean} Returns `true` if `object` is a match, else `false`. 11881 * @example 11882 * 11883 * var object = { 'a': 1, 'b': 2 }; 11884 * 11885 * _.isMatch(object, { 'b': 2 }); 11886 * // => true 11887 * 11888 * _.isMatch(object, { 'b': 1 }); 11889 * // => false 11890 */ 11891 function isMatch(object, source) { 11892 return object === source || baseIsMatch(object, source, getMatchData(source)); 11893 } 11894 11895 /** 11896 * This method is like `_.isMatch` except that it accepts `customizer` which 11897 * is invoked to compare values. If `customizer` returns `undefined`, comparisons 11898 * are handled by the method instead. The `customizer` is invoked with five 11899 * arguments: (objValue, srcValue, index|key, object, source). 11900 * 11901 * @static 11902 * @memberOf _ 11903 * @since 4.0.0 11904 * @category Lang 11905 * @param {Object} object The object to inspect. 11906 * @param {Object} source The object of property values to match. 11907 * @param {Function} [customizer] The function to customize comparisons. 11908 * @returns {boolean} Returns `true` if `object` is a match, else `false`. 11909 * @example 11910 * 11911 * function isGreeting(value) { 11912 * return /^h(?:i|ello)$/.test(value); 11913 * } 11914 * 11915 * function customizer(objValue, srcValue) { 11916 * if (isGreeting(objValue) && isGreeting(srcValue)) { 11917 * return true; 11918 * } 11919 * } 11920 * 11921 * var object = { 'greeting': 'hello' }; 11922 * var source = { 'greeting': 'hi' }; 11923 * 11924 * _.isMatchWith(object, source, customizer); 11925 * // => true 11926 */ 11927 function isMatchWith(object, source, customizer) { 11928 customizer = typeof customizer == 'function' ? customizer : undefined; 11929 return baseIsMatch(object, source, getMatchData(source), customizer); 11930 } 11931 11932 /** 11933 * Checks if `value` is `NaN`. 11934 * 11935 * **Note:** This method is based on 11936 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as 11937 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for 11938 * `undefined` and other non-number values. 11939 * 11940 * @static 11941 * @memberOf _ 11942 * @since 0.1.0 11943 * @category Lang 11944 * @param {*} value The value to check. 11945 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. 11946 * @example 11947 * 11948 * _.isNaN(NaN); 11949 * // => true 11950 * 11951 * _.isNaN(new Number(NaN)); 11952 * // => true 11953 * 11954 * isNaN(undefined); 11955 * // => true 11956 * 11957 * _.isNaN(undefined); 11958 * // => false 11959 */ 11960 function isNaN(value) { 11961 // An `NaN` primitive is the only value that is not equal to itself. 11962 // Perform the `toStringTag` check first to avoid errors with some 11963 // ActiveX objects in IE. 11964 return isNumber(value) && value != +value; 11965 } 11966 11967 /** 11968 * Checks if `value` is a pristine native function. 11969 * 11970 * **Note:** This method can't reliably detect native functions in the presence 11971 * of the core-js package because core-js circumvents this kind of detection. 11972 * Despite multiple requests, the core-js maintainer has made it clear: any 11973 * attempt to fix the detection will be obstructed. As a result, we're left 11974 * with little choice but to throw an error. Unfortunately, this also affects 11975 * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), 11976 * which rely on core-js. 11977 * 11978 * @static 11979 * @memberOf _ 11980 * @since 3.0.0 11981 * @category Lang 11982 * @param {*} value The value to check. 11983 * @returns {boolean} Returns `true` if `value` is a native function, 11984 * else `false`. 11985 * @example 11986 * 11987 * _.isNative(Array.prototype.push); 11988 * // => true 11989 * 11990 * _.isNative(_); 11991 * // => false 11992 */ 11993 function isNative(value) { 11994 if (isMaskable(value)) { 11995 throw new Error(CORE_ERROR_TEXT); 11996 } 11997 return baseIsNative(value); 11998 } 11999 12000 /** 12001 * Checks if `value` is `null`. 12002 * 12003 * @static 12004 * @memberOf _ 12005 * @since 0.1.0 12006 * @category Lang 12007 * @param {*} value The value to check. 12008 * @returns {boolean} Returns `true` if `value` is `null`, else `false`. 12009 * @example 12010 * 12011 * _.isNull(null); 12012 * // => true 12013 * 12014 * _.isNull(void 0); 12015 * // => false 12016 */ 12017 function isNull(value) { 12018 return value === null; 12019 } 12020 12021 /** 12022 * Checks if `value` is `null` or `undefined`. 12023 * 12024 * @static 12025 * @memberOf _ 12026 * @since 4.0.0 12027 * @category Lang 12028 * @param {*} value The value to check. 12029 * @returns {boolean} Returns `true` if `value` is nullish, else `false`. 12030 * @example 12031 * 12032 * _.isNil(null); 12033 * // => true 12034 * 12035 * _.isNil(void 0); 12036 * // => true 12037 * 12038 * _.isNil(NaN); 12039 * // => false 12040 */ 12041 function isNil(value) { 12042 return value == null; 12043 } 12044 12045 /** 12046 * Checks if `value` is classified as a `Number` primitive or object. 12047 * 12048 * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are 12049 * classified as numbers, use the `_.isFinite` method. 12050 * 12051 * @static 12052 * @memberOf _ 12053 * @since 0.1.0 12054 * @category Lang 12055 * @param {*} value The value to check. 12056 * @returns {boolean} Returns `true` if `value` is a number, else `false`. 12057 * @example 12058 * 12059 * _.isNumber(3); 12060 * // => true 12061 * 12062 * _.isNumber(Number.MIN_VALUE); 12063 * // => true 12064 * 12065 * _.isNumber(Infinity); 12066 * // => true 12067 * 12068 * _.isNumber('3'); 12069 * // => false 12070 */ 12071 function isNumber(value) { 12072 return typeof value == 'number' || 12073 (isObjectLike(value) && baseGetTag(value) == numberTag); 12074 } 12075 12076 /** 12077 * Checks if `value` is a plain object, that is, an object created by the 12078 * `Object` constructor or one with a `[[Prototype]]` of `null`. 12079 * 12080 * @static 12081 * @memberOf _ 12082 * @since 0.8.0 12083 * @category Lang 12084 * @param {*} value The value to check. 12085 * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. 12086 * @example 12087 * 12088 * function Foo() { 12089 * this.a = 1; 12090 * } 12091 * 12092 * _.isPlainObject(new Foo); 12093 * // => false 12094 * 12095 * _.isPlainObject([1, 2, 3]); 12096 * // => false 12097 * 12098 * _.isPlainObject({ 'x': 0, 'y': 0 }); 12099 * // => true 12100 * 12101 * _.isPlainObject(Object.create(null)); 12102 * // => true 12103 */ 12104 function isPlainObject(value) { 12105 if (!isObjectLike(value) || baseGetTag(value) != objectTag) { 12106 return false; 12107 } 12108 var proto = getPrototype(value); 12109 if (proto === null) { 12110 return true; 12111 } 12112 var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; 12113 return typeof Ctor == 'function' && Ctor instanceof Ctor && 12114 funcToString.call(Ctor) == objectCtorString; 12115 } 12116 12117 /** 12118 * Checks if `value` is classified as a `RegExp` object. 12119 * 12120 * @static 12121 * @memberOf _ 12122 * @since 0.1.0 12123 * @category Lang 12124 * @param {*} value The value to check. 12125 * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. 12126 * @example 12127 * 12128 * _.isRegExp(/abc/); 12129 * // => true 12130 * 12131 * _.isRegExp('/abc/'); 12132 * // => false 12133 */ 12134 var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; 12135 12136 /** 12137 * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 12138 * double precision number which isn't the result of a rounded unsafe integer. 12139 * 12140 * **Note:** This method is based on 12141 * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). 12142 * 12143 * @static 12144 * @memberOf _ 12145 * @since 4.0.0 12146 * @category Lang 12147 * @param {*} value The value to check. 12148 * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. 12149 * @example 12150 * 12151 * _.isSafeInteger(3); 12152 * // => true 12153 * 12154 * _.isSafeInteger(Number.MIN_VALUE); 12155 * // => false 12156 * 12157 * _.isSafeInteger(Infinity); 12158 * // => false 12159 * 12160 * _.isSafeInteger('3'); 12161 * // => false 12162 */ 12163 function isSafeInteger(value) { 12164 return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER; 12165 } 12166 12167 /** 12168 * Checks if `value` is classified as a `Set` object. 12169 * 12170 * @static 12171 * @memberOf _ 12172 * @since 4.3.0 12173 * @category Lang 12174 * @param {*} value The value to check. 12175 * @returns {boolean} Returns `true` if `value` is a set, else `false`. 12176 * @example 12177 * 12178 * _.isSet(new Set); 12179 * // => true 12180 * 12181 * _.isSet(new WeakSet); 12182 * // => false 12183 */ 12184 var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; 12185 12186 /** 12187 * Checks if `value` is classified as a `String` primitive or object. 12188 * 12189 * @static 12190 * @since 0.1.0 12191 * @memberOf _ 12192 * @category Lang 12193 * @param {*} value The value to check. 12194 * @returns {boolean} Returns `true` if `value` is a string, else `false`. 12195 * @example 12196 * 12197 * _.isString('abc'); 12198 * // => true 12199 * 12200 * _.isString(1); 12201 * // => false 12202 */ 12203 function isString(value) { 12204 return typeof value == 'string' || 12205 (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); 12206 } 12207 12208 /** 12209 * Checks if `value` is classified as a `Symbol` primitive or object. 12210 * 12211 * @static 12212 * @memberOf _ 12213 * @since 4.0.0 12214 * @category Lang 12215 * @param {*} value The value to check. 12216 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. 12217 * @example 12218 * 12219 * _.isSymbol(Symbol.iterator); 12220 * // => true 12221 * 12222 * _.isSymbol('abc'); 12223 * // => false 12224 */ 12225 function isSymbol(value) { 12226 return typeof value == 'symbol' || 12227 (isObjectLike(value) && baseGetTag(value) == symbolTag); 12228 } 12229 12230 /** 12231 * Checks if `value` is classified as a typed array. 12232 * 12233 * @static 12234 * @memberOf _ 12235 * @since 3.0.0 12236 * @category Lang 12237 * @param {*} value The value to check. 12238 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. 12239 * @example 12240 * 12241 * _.isTypedArray(new Uint8Array); 12242 * // => true 12243 * 12244 * _.isTypedArray([]); 12245 * // => false 12246 */ 12247 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; 12248 12249 /** 12250 * Checks if `value` is `undefined`. 12251 * 12252 * @static 12253 * @since 0.1.0 12254 * @memberOf _ 12255 * @category Lang 12256 * @param {*} value The value to check. 12257 * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. 12258 * @example 12259 * 12260 * _.isUndefined(void 0); 12261 * // => true 12262 * 12263 * _.isUndefined(null); 12264 * // => false 12265 */ 12266 function isUndefined(value) { 12267 return value === undefined; 12268 } 12269 12270 /** 12271 * Checks if `value` is classified as a `WeakMap` object. 12272 * 12273 * @static 12274 * @memberOf _ 12275 * @since 4.3.0 12276 * @category Lang 12277 * @param {*} value The value to check. 12278 * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. 12279 * @example 12280 * 12281 * _.isWeakMap(new WeakMap); 12282 * // => true 12283 * 12284 * _.isWeakMap(new Map); 12285 * // => false 12286 */ 12287 function isWeakMap(value) { 12288 return isObjectLike(value) && getTag(value) == weakMapTag; 12289 } 12290 12291 /** 12292 * Checks if `value` is classified as a `WeakSet` object. 12293 * 12294 * @static 12295 * @memberOf _ 12296 * @since 4.3.0 12297 * @category Lang 12298 * @param {*} value The value to check. 12299 * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. 12300 * @example 12301 * 12302 * _.isWeakSet(new WeakSet); 12303 * // => true 12304 * 12305 * _.isWeakSet(new Set); 12306 * // => false 12307 */ 12308 function isWeakSet(value) { 12309 return isObjectLike(value) && baseGetTag(value) == weakSetTag; 12310 } 12311 12312 /** 12313 * Checks if `value` is less than `other`. 12314 * 12315 * @static 12316 * @memberOf _ 12317 * @since 3.9.0 12318 * @category Lang 12319 * @param {*} value The value to compare. 12320 * @param {*} other The other value to compare. 12321 * @returns {boolean} Returns `true` if `value` is less than `other`, 12322 * else `false`. 12323 * @see _.gt 12324 * @example 12325 * 12326 * _.lt(1, 3); 12327 * // => true 12328 * 12329 * _.lt(3, 3); 12330 * // => false 12331 * 12332 * _.lt(3, 1); 12333 * // => false 12334 */ 12335 var lt = createRelationalOperation(baseLt); 12336 12337 /** 12338 * Checks if `value` is less than or equal to `other`. 12339 * 12340 * @static 12341 * @memberOf _ 12342 * @since 3.9.0 12343 * @category Lang 12344 * @param {*} value The value to compare. 12345 * @param {*} other The other value to compare. 12346 * @returns {boolean} Returns `true` if `value` is less than or equal to 12347 * `other`, else `false`. 12348 * @see _.gte 12349 * @example 12350 * 12351 * _.lte(1, 3); 12352 * // => true 12353 * 12354 * _.lte(3, 3); 12355 * // => true 12356 * 12357 * _.lte(3, 1); 12358 * // => false 12359 */ 12360 var lte = createRelationalOperation(function(value, other) { 12361 return value <= other; 12362 }); 12363 12364 /** 12365 * Converts `value` to an array. 12366 * 12367 * @static 12368 * @since 0.1.0 12369 * @memberOf _ 12370 * @category Lang 12371 * @param {*} value The value to convert. 12372 * @returns {Array} Returns the converted array. 12373 * @example 12374 * 12375 * _.toArray({ 'a': 1, 'b': 2 }); 12376 * // => [1, 2] 12377 * 12378 * _.toArray('abc'); 12379 * // => ['a', 'b', 'c'] 12380 * 12381 * _.toArray(1); 12382 * // => [] 12383 * 12384 * _.toArray(null); 12385 * // => [] 12386 */ 12387 function toArray(value) { 12388 if (!value) { 12389 return []; 12390 } 12391 if (isArrayLike(value)) { 12392 return isString(value) ? stringToArray(value) : copyArray(value); 12393 } 12394 if (symIterator && value[symIterator]) { 12395 return iteratorToArray(value[symIterator]()); 12396 } 12397 var tag = getTag(value), 12398 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); 12399 12400 return func(value); 12401 } 12402 12403 /** 12404 * Converts `value` to a finite number. 12405 * 12406 * @static 12407 * @memberOf _ 12408 * @since 4.12.0 12409 * @category Lang 12410 * @param {*} value The value to convert. 12411 * @returns {number} Returns the converted number. 12412 * @example 12413 * 12414 * _.toFinite(3.2); 12415 * // => 3.2 12416 * 12417 * _.toFinite(Number.MIN_VALUE); 12418 * // => 5e-324 12419 * 12420 * _.toFinite(Infinity); 12421 * // => 1.7976931348623157e+308 12422 * 12423 * _.toFinite('3.2'); 12424 * // => 3.2 12425 */ 12426 function toFinite(value) { 12427 if (!value) { 12428 return value === 0 ? value : 0; 12429 } 12430 value = toNumber(value); 12431 if (value === INFINITY || value === -INFINITY) { 12432 var sign = (value < 0 ? -1 : 1); 12433 return sign * MAX_INTEGER; 12434 } 12435 return value === value ? value : 0; 12436 } 12437 12438 /** 12439 * Converts `value` to an integer. 12440 * 12441 * **Note:** This method is loosely based on 12442 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). 12443 * 12444 * @static 12445 * @memberOf _ 12446 * @since 4.0.0 12447 * @category Lang 12448 * @param {*} value The value to convert. 12449 * @returns {number} Returns the converted integer. 12450 * @example 12451 * 12452 * _.toInteger(3.2); 12453 * // => 3 12454 * 12455 * _.toInteger(Number.MIN_VALUE); 12456 * // => 0 12457 * 12458 * _.toInteger(Infinity); 12459 * // => 1.7976931348623157e+308 12460 * 12461 * _.toInteger('3.2'); 12462 * // => 3 12463 */ 12464 function toInteger(value) { 12465 var result = toFinite(value), 12466 remainder = result % 1; 12467 12468 return result === result ? (remainder ? result - remainder : result) : 0; 12469 } 12470 12471 /** 12472 * Converts `value` to an integer suitable for use as the length of an 12473 * array-like object. 12474 * 12475 * **Note:** This method is based on 12476 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). 12477 * 12478 * @static 12479 * @memberOf _ 12480 * @since 4.0.0 12481 * @category Lang 12482 * @param {*} value The value to convert. 12483 * @returns {number} Returns the converted integer. 12484 * @example 12485 * 12486 * _.toLength(3.2); 12487 * // => 3 12488 * 12489 * _.toLength(Number.MIN_VALUE); 12490 * // => 0 12491 * 12492 * _.toLength(Infinity); 12493 * // => 4294967295 12494 * 12495 * _.toLength('3.2'); 12496 * // => 3 12497 */ 12498 function toLength(value) { 12499 return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0; 12500 } 12501 12502 /** 12503 * Converts `value` to a number. 12504 * 12505 * @static 12506 * @memberOf _ 12507 * @since 4.0.0 12508 * @category Lang 12509 * @param {*} value The value to process. 12510 * @returns {number} Returns the number. 12511 * @example 12512 * 12513 * _.toNumber(3.2); 12514 * // => 3.2 12515 * 12516 * _.toNumber(Number.MIN_VALUE); 12517 * // => 5e-324 12518 * 12519 * _.toNumber(Infinity); 12520 * // => Infinity 12521 * 12522 * _.toNumber('3.2'); 12523 * // => 3.2 12524 */ 12525 function toNumber(value) { 12526 if (typeof value == 'number') { 12527 return value; 12528 } 12529 if (isSymbol(value)) { 12530 return NAN; 12531 } 12532 if (isObject(value)) { 12533 var other = typeof value.valueOf == 'function' ? value.valueOf() : value; 12534 value = isObject(other) ? (other + '') : other; 12535 } 12536 if (typeof value != 'string') { 12537 return value === 0 ? value : +value; 12538 } 12539 value = baseTrim(value); 12540 var isBinary = reIsBinary.test(value); 12541 return (isBinary || reIsOctal.test(value)) 12542 ? freeParseInt(value.slice(2), isBinary ? 2 : 8) 12543 : (reIsBadHex.test(value) ? NAN : +value); 12544 } 12545 12546 /** 12547 * Converts `value` to a plain object flattening inherited enumerable string 12548 * keyed properties of `value` to own properties of the plain object. 12549 * 12550 * @static 12551 * @memberOf _ 12552 * @since 3.0.0 12553 * @category Lang 12554 * @param {*} value The value to convert. 12555 * @returns {Object} Returns the converted plain object. 12556 * @example 12557 * 12558 * function Foo() { 12559 * this.b = 2; 12560 * } 12561 * 12562 * Foo.prototype.c = 3; 12563 * 12564 * _.assign({ 'a': 1 }, new Foo); 12565 * // => { 'a': 1, 'b': 2 } 12566 * 12567 * _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); 12568 * // => { 'a': 1, 'b': 2, 'c': 3 } 12569 */ 12570 function toPlainObject(value) { 12571 return copyObject(value, keysIn(value)); 12572 } 12573 12574 /** 12575 * Converts `value` to a safe integer. A safe integer can be compared and 12576 * represented correctly. 12577 * 12578 * @static 12579 * @memberOf _ 12580 * @since 4.0.0 12581 * @category Lang 12582 * @param {*} value The value to convert. 12583 * @returns {number} Returns the converted integer. 12584 * @example 12585 * 12586 * _.toSafeInteger(3.2); 12587 * // => 3 12588 * 12589 * _.toSafeInteger(Number.MIN_VALUE); 12590 * // => 0 12591 * 12592 * _.toSafeInteger(Infinity); 12593 * // => 9007199254740991 12594 * 12595 * _.toSafeInteger('3.2'); 12596 * // => 3 12597 */ 12598 function toSafeInteger(value) { 12599 return value 12600 ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) 12601 : (value === 0 ? value : 0); 12602 } 12603 12604 /** 12605 * Converts `value` to a string. An empty string is returned for `null` 12606 * and `undefined` values. The sign of `-0` is preserved. 12607 * 12608 * @static 12609 * @memberOf _ 12610 * @since 4.0.0 12611 * @category Lang 12612 * @param {*} value The value to convert. 12613 * @returns {string} Returns the converted string. 12614 * @example 12615 * 12616 * _.toString(null); 12617 * // => '' 12618 * 12619 * _.toString(-0); 12620 * // => '-0' 12621 * 12622 * _.toString([1, 2, 3]); 12623 * // => '1,2,3' 12624 */ 12625 function toString(value) { 12626 return value == null ? '' : baseToString(value); 12627 } 12628 12629 /*------------------------------------------------------------------------*/ 12630 12631 /** 12632 * Assigns own enumerable string keyed properties of source objects to the 12633 * destination object. Source objects are applied from left to right. 12634 * Subsequent sources overwrite property assignments of previous sources. 12635 * 12636 * **Note:** This method mutates `object` and is loosely based on 12637 * [`Object.assign`](https://mdn.io/Object/assign). 12638 * 12639 * @static 12640 * @memberOf _ 12641 * @since 0.10.0 12642 * @category Object 12643 * @param {Object} object The destination object. 12644 * @param {...Object} [sources] The source objects. 12645 * @returns {Object} Returns `object`. 12646 * @see _.assignIn 12647 * @example 12648 * 12649 * function Foo() { 12650 * this.a = 1; 12651 * } 12652 * 12653 * function Bar() { 12654 * this.c = 3; 12655 * } 12656 * 12657 * Foo.prototype.b = 2; 12658 * Bar.prototype.d = 4; 12659 * 12660 * _.assign({ 'a': 0 }, new Foo, new Bar); 12661 * // => { 'a': 1, 'c': 3 } 12662 */ 12663 var assign = createAssigner(function(object, source) { 12664 if (isPrototype(source) || isArrayLike(source)) { 12665 copyObject(source, keys(source), object); 12666 return; 12667 } 12668 for (var key in source) { 12669 if (hasOwnProperty.call(source, key)) { 12670 assignValue(object, key, source[key]); 12671 } 12672 } 12673 }); 12674 12675 /** 12676 * This method is like `_.assign` except that it iterates over own and 12677 * inherited source properties. 12678 * 12679 * **Note:** This method mutates `object`. 12680 * 12681 * @static 12682 * @memberOf _ 12683 * @since 4.0.0 12684 * @alias extend 12685 * @category Object 12686 * @param {Object} object The destination object. 12687 * @param {...Object} [sources] The source objects. 12688 * @returns {Object} Returns `object`. 12689 * @see _.assign 12690 * @example 12691 * 12692 * function Foo() { 12693 * this.a = 1; 12694 * } 12695 * 12696 * function Bar() { 12697 * this.c = 3; 12698 * } 12699 * 12700 * Foo.prototype.b = 2; 12701 * Bar.prototype.d = 4; 12702 * 12703 * _.assignIn({ 'a': 0 }, new Foo, new Bar); 12704 * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } 12705 */ 12706 var assignIn = createAssigner(function(object, source) { 12707 copyObject(source, keysIn(source), object); 12708 }); 12709 12710 /** 12711 * This method is like `_.assignIn` except that it accepts `customizer` 12712 * which is invoked to produce the assigned values. If `customizer` returns 12713 * `undefined`, assignment is handled by the method instead. The `customizer` 12714 * is invoked with five arguments: (objValue, srcValue, key, object, source). 12715 * 12716 * **Note:** This method mutates `object`. 12717 * 12718 * @static 12719 * @memberOf _ 12720 * @since 4.0.0 12721 * @alias extendWith 12722 * @category Object 12723 * @param {Object} object The destination object. 12724 * @param {...Object} sources The source objects. 12725 * @param {Function} [customizer] The function to customize assigned values. 12726 * @returns {Object} Returns `object`. 12727 * @see _.assignWith 12728 * @example 12729 * 12730 * function customizer(objValue, srcValue) { 12731 * return _.isUndefined(objValue) ? srcValue : objValue; 12732 * } 12733 * 12734 * var defaults = _.partialRight(_.assignInWith, customizer); 12735 * 12736 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); 12737 * // => { 'a': 1, 'b': 2 } 12738 */ 12739 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { 12740 copyObject(source, keysIn(source), object, customizer); 12741 }); 12742 12743 /** 12744 * This method is like `_.assign` except that it accepts `customizer` 12745 * which is invoked to produce the assigned values. If `customizer` returns 12746 * `undefined`, assignment is handled by the method instead. The `customizer` 12747 * is invoked with five arguments: (objValue, srcValue, key, object, source). 12748 * 12749 * **Note:** This method mutates `object`. 12750 * 12751 * @static 12752 * @memberOf _ 12753 * @since 4.0.0 12754 * @category Object 12755 * @param {Object} object The destination object. 12756 * @param {...Object} sources The source objects. 12757 * @param {Function} [customizer] The function to customize assigned values. 12758 * @returns {Object} Returns `object`. 12759 * @see _.assignInWith 12760 * @example 12761 * 12762 * function customizer(objValue, srcValue) { 12763 * return _.isUndefined(objValue) ? srcValue : objValue; 12764 * } 12765 * 12766 * var defaults = _.partialRight(_.assignWith, customizer); 12767 * 12768 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); 12769 * // => { 'a': 1, 'b': 2 } 12770 */ 12771 var assignWith = createAssigner(function(object, source, srcIndex, customizer) { 12772 copyObject(source, keys(source), object, customizer); 12773 }); 12774 12775 /** 12776 * Creates an array of values corresponding to `paths` of `object`. 12777 * 12778 * @static 12779 * @memberOf _ 12780 * @since 1.0.0 12781 * @category Object 12782 * @param {Object} object The object to iterate over. 12783 * @param {...(string|string[])} [paths] The property paths to pick. 12784 * @returns {Array} Returns the picked values. 12785 * @example 12786 * 12787 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; 12788 * 12789 * _.at(object, ['a[0].b.c', 'a[1]']); 12790 * // => [3, 4] 12791 */ 12792 var at = flatRest(baseAt); 12793 12794 /** 12795 * Creates an object that inherits from the `prototype` object. If a 12796 * `properties` object is given, its own enumerable string keyed properties 12797 * are assigned to the created object. 12798 * 12799 * @static 12800 * @memberOf _ 12801 * @since 2.3.0 12802 * @category Object 12803 * @param {Object} prototype The object to inherit from. 12804 * @param {Object} [properties] The properties to assign to the object. 12805 * @returns {Object} Returns the new object. 12806 * @example 12807 * 12808 * function Shape() { 12809 * this.x = 0; 12810 * this.y = 0; 12811 * } 12812 * 12813 * function Circle() { 12814 * Shape.call(this); 12815 * } 12816 * 12817 * Circle.prototype = _.create(Shape.prototype, { 12818 * 'constructor': Circle 12819 * }); 12820 * 12821 * var circle = new Circle; 12822 * circle instanceof Circle; 12823 * // => true 12824 * 12825 * circle instanceof Shape; 12826 * // => true 12827 */ 12828 function create(prototype, properties) { 12829 var result = baseCreate(prototype); 12830 return properties == null ? result : baseAssign(result, properties); 12831 } 12832 12833 /** 12834 * Assigns own and inherited enumerable string keyed properties of source 12835 * objects to the destination object for all destination properties that 12836 * resolve to `undefined`. Source objects are applied from left to right. 12837 * Once a property is set, additional values of the same property are ignored. 12838 * 12839 * **Note:** This method mutates `object`. 12840 * 12841 * @static 12842 * @since 0.1.0 12843 * @memberOf _ 12844 * @category Object 12845 * @param {Object} object The destination object. 12846 * @param {...Object} [sources] The source objects. 12847 * @returns {Object} Returns `object`. 12848 * @see _.defaultsDeep 12849 * @example 12850 * 12851 * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); 12852 * // => { 'a': 1, 'b': 2 } 12853 */ 12854 var defaults = baseRest(function(object, sources) { 12855 object = Object(object); 12856 12857 var index = -1; 12858 var length = sources.length; 12859 var guard = length > 2 ? sources[2] : undefined; 12860 12861 if (guard && isIterateeCall(sources[0], sources[1], guard)) { 12862 length = 1; 12863 } 12864 12865 while (++index < length) { 12866 var source = sources[index]; 12867 var props = keysIn(source); 12868 var propsIndex = -1; 12869 var propsLength = props.length; 12870 12871 while (++propsIndex < propsLength) { 12872 var key = props[propsIndex]; 12873 var value = object[key]; 12874 12875 if (value === undefined || 12876 (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { 12877 object[key] = source[key]; 12878 } 12879 } 12880 } 12881 12882 return object; 12883 }); 12884 12885 /** 12886 * This method is like `_.defaults` except that it recursively assigns 12887 * default properties. 12888 * 12889 * **Note:** This method mutates `object`. 12890 * 12891 * @static 12892 * @memberOf _ 12893 * @since 3.10.0 12894 * @category Object 12895 * @param {Object} object The destination object. 12896 * @param {...Object} [sources] The source objects. 12897 * @returns {Object} Returns `object`. 12898 * @see _.defaults 12899 * @example 12900 * 12901 * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); 12902 * // => { 'a': { 'b': 2, 'c': 3 } } 12903 */ 12904 var defaultsDeep = baseRest(function(args) { 12905 args.push(undefined, customDefaultsMerge); 12906 return apply(mergeWith, undefined, args); 12907 }); 12908 12909 /** 12910 * This method is like `_.find` except that it returns the key of the first 12911 * element `predicate` returns truthy for instead of the element itself. 12912 * 12913 * @static 12914 * @memberOf _ 12915 * @since 1.1.0 12916 * @category Object 12917 * @param {Object} object The object to inspect. 12918 * @param {Function} [predicate=_.identity] The function invoked per iteration. 12919 * @returns {string|undefined} Returns the key of the matched element, 12920 * else `undefined`. 12921 * @example 12922 * 12923 * var users = { 12924 * 'barney': { 'age': 36, 'active': true }, 12925 * 'fred': { 'age': 40, 'active': false }, 12926 * 'pebbles': { 'age': 1, 'active': true } 12927 * }; 12928 * 12929 * _.findKey(users, function(o) { return o.age < 40; }); 12930 * // => 'barney' (iteration order is not guaranteed) 12931 * 12932 * // The `_.matches` iteratee shorthand. 12933 * _.findKey(users, { 'age': 1, 'active': true }); 12934 * // => 'pebbles' 12935 * 12936 * // The `_.matchesProperty` iteratee shorthand. 12937 * _.findKey(users, ['active', false]); 12938 * // => 'fred' 12939 * 12940 * // The `_.property` iteratee shorthand. 12941 * _.findKey(users, 'active'); 12942 * // => 'barney' 12943 */ 12944 function findKey(object, predicate) { 12945 return baseFindKey(object, getIteratee(predicate, 3), baseForOwn); 12946 } 12947 12948 /** 12949 * This method is like `_.findKey` except that it iterates over elements of 12950 * a collection in the opposite order. 12951 * 12952 * @static 12953 * @memberOf _ 12954 * @since 2.0.0 12955 * @category Object 12956 * @param {Object} object The object to inspect. 12957 * @param {Function} [predicate=_.identity] The function invoked per iteration. 12958 * @returns {string|undefined} Returns the key of the matched element, 12959 * else `undefined`. 12960 * @example 12961 * 12962 * var users = { 12963 * 'barney': { 'age': 36, 'active': true }, 12964 * 'fred': { 'age': 40, 'active': false }, 12965 * 'pebbles': { 'age': 1, 'active': true } 12966 * }; 12967 * 12968 * _.findLastKey(users, function(o) { return o.age < 40; }); 12969 * // => returns 'pebbles' assuming `_.findKey` returns 'barney' 12970 * 12971 * // The `_.matches` iteratee shorthand. 12972 * _.findLastKey(users, { 'age': 36, 'active': true }); 12973 * // => 'barney' 12974 * 12975 * // The `_.matchesProperty` iteratee shorthand. 12976 * _.findLastKey(users, ['active', false]); 12977 * // => 'fred' 12978 * 12979 * // The `_.property` iteratee shorthand. 12980 * _.findLastKey(users, 'active'); 12981 * // => 'pebbles' 12982 */ 12983 function findLastKey(object, predicate) { 12984 return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight); 12985 } 12986 12987 /** 12988 * Iterates over own and inherited enumerable string keyed properties of an 12989 * object and invokes `iteratee` for each property. The iteratee is invoked 12990 * with three arguments: (value, key, object). Iteratee functions may exit 12991 * iteration early by explicitly returning `false`. 12992 * 12993 * @static 12994 * @memberOf _ 12995 * @since 0.3.0 12996 * @category Object 12997 * @param {Object} object The object to iterate over. 12998 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 12999 * @returns {Object} Returns `object`. 13000 * @see _.forInRight 13001 * @example 13002 * 13003 * function Foo() { 13004 * this.a = 1; 13005 * this.b = 2; 13006 * } 13007 * 13008 * Foo.prototype.c = 3; 13009 * 13010 * _.forIn(new Foo, function(value, key) { 13011 * console.log(key); 13012 * }); 13013 * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). 13014 */ 13015 function forIn(object, iteratee) { 13016 return object == null 13017 ? object 13018 : baseFor(object, getIteratee(iteratee, 3), keysIn); 13019 } 13020 13021 /** 13022 * This method is like `_.forIn` except that it iterates over properties of 13023 * `object` in the opposite order. 13024 * 13025 * @static 13026 * @memberOf _ 13027 * @since 2.0.0 13028 * @category Object 13029 * @param {Object} object The object to iterate over. 13030 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 13031 * @returns {Object} Returns `object`. 13032 * @see _.forIn 13033 * @example 13034 * 13035 * function Foo() { 13036 * this.a = 1; 13037 * this.b = 2; 13038 * } 13039 * 13040 * Foo.prototype.c = 3; 13041 * 13042 * _.forInRight(new Foo, function(value, key) { 13043 * console.log(key); 13044 * }); 13045 * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. 13046 */ 13047 function forInRight(object, iteratee) { 13048 return object == null 13049 ? object 13050 : baseForRight(object, getIteratee(iteratee, 3), keysIn); 13051 } 13052 13053 /** 13054 * Iterates over own enumerable string keyed properties of an object and 13055 * invokes `iteratee` for each property. The iteratee is invoked with three 13056 * arguments: (value, key, object). Iteratee functions may exit iteration 13057 * early by explicitly returning `false`. 13058 * 13059 * @static 13060 * @memberOf _ 13061 * @since 0.3.0 13062 * @category Object 13063 * @param {Object} object The object to iterate over. 13064 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 13065 * @returns {Object} Returns `object`. 13066 * @see _.forOwnRight 13067 * @example 13068 * 13069 * function Foo() { 13070 * this.a = 1; 13071 * this.b = 2; 13072 * } 13073 * 13074 * Foo.prototype.c = 3; 13075 * 13076 * _.forOwn(new Foo, function(value, key) { 13077 * console.log(key); 13078 * }); 13079 * // => Logs 'a' then 'b' (iteration order is not guaranteed). 13080 */ 13081 function forOwn(object, iteratee) { 13082 return object && baseForOwn(object, getIteratee(iteratee, 3)); 13083 } 13084 13085 /** 13086 * This method is like `_.forOwn` except that it iterates over properties of 13087 * `object` in the opposite order. 13088 * 13089 * @static 13090 * @memberOf _ 13091 * @since 2.0.0 13092 * @category Object 13093 * @param {Object} object The object to iterate over. 13094 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 13095 * @returns {Object} Returns `object`. 13096 * @see _.forOwn 13097 * @example 13098 * 13099 * function Foo() { 13100 * this.a = 1; 13101 * this.b = 2; 13102 * } 13103 * 13104 * Foo.prototype.c = 3; 13105 * 13106 * _.forOwnRight(new Foo, function(value, key) { 13107 * console.log(key); 13108 * }); 13109 * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. 13110 */ 13111 function forOwnRight(object, iteratee) { 13112 return object && baseForOwnRight(object, getIteratee(iteratee, 3)); 13113 } 13114 13115 /** 13116 * Creates an array of function property names from own enumerable properties 13117 * of `object`. 13118 * 13119 * @static 13120 * @since 0.1.0 13121 * @memberOf _ 13122 * @category Object 13123 * @param {Object} object The object to inspect. 13124 * @returns {Array} Returns the function names. 13125 * @see _.functionsIn 13126 * @example 13127 * 13128 * function Foo() { 13129 * this.a = _.constant('a'); 13130 * this.b = _.constant('b'); 13131 * } 13132 * 13133 * Foo.prototype.c = _.constant('c'); 13134 * 13135 * _.functions(new Foo); 13136 * // => ['a', 'b'] 13137 */ 13138 function functions(object) { 13139 return object == null ? [] : baseFunctions(object, keys(object)); 13140 } 13141 13142 /** 13143 * Creates an array of function property names from own and inherited 13144 * enumerable properties of `object`. 13145 * 13146 * @static 13147 * @memberOf _ 13148 * @since 4.0.0 13149 * @category Object 13150 * @param {Object} object The object to inspect. 13151 * @returns {Array} Returns the function names. 13152 * @see _.functions 13153 * @example 13154 * 13155 * function Foo() { 13156 * this.a = _.constant('a'); 13157 * this.b = _.constant('b'); 13158 * } 13159 * 13160 * Foo.prototype.c = _.constant('c'); 13161 * 13162 * _.functionsIn(new Foo); 13163 * // => ['a', 'b', 'c'] 13164 */ 13165 function functionsIn(object) { 13166 return object == null ? [] : baseFunctions(object, keysIn(object)); 13167 } 13168 13169 /** 13170 * Gets the value at `path` of `object`. If the resolved value is 13171 * `undefined`, the `defaultValue` is returned in its place. 13172 * 13173 * @static 13174 * @memberOf _ 13175 * @since 3.7.0 13176 * @category Object 13177 * @param {Object} object The object to query. 13178 * @param {Array|string} path The path of the property to get. 13179 * @param {*} [defaultValue] The value returned for `undefined` resolved values. 13180 * @returns {*} Returns the resolved value. 13181 * @example 13182 * 13183 * var object = { 'a': [{ 'b': { 'c': 3 } }] }; 13184 * 13185 * _.get(object, 'a[0].b.c'); 13186 * // => 3 13187 * 13188 * _.get(object, ['a', '0', 'b', 'c']); 13189 * // => 3 13190 * 13191 * _.get(object, 'a.b.c', 'default'); 13192 * // => 'default' 13193 */ 13194 function get(object, path, defaultValue) { 13195 var result = object == null ? undefined : baseGet(object, path); 13196 return result === undefined ? defaultValue : result; 13197 } 13198 13199 /** 13200 * Checks if `path` is a direct property of `object`. 13201 * 13202 * @static 13203 * @since 0.1.0 13204 * @memberOf _ 13205 * @category Object 13206 * @param {Object} object The object to query. 13207 * @param {Array|string} path The path to check. 13208 * @returns {boolean} Returns `true` if `path` exists, else `false`. 13209 * @example 13210 * 13211 * var object = { 'a': { 'b': 2 } }; 13212 * var other = _.create({ 'a': _.create({ 'b': 2 }) }); 13213 * 13214 * _.has(object, 'a'); 13215 * // => true 13216 * 13217 * _.has(object, 'a.b'); 13218 * // => true 13219 * 13220 * _.has(object, ['a', 'b']); 13221 * // => true 13222 * 13223 * _.has(other, 'a'); 13224 * // => false 13225 */ 13226 function has(object, path) { 13227 return object != null && hasPath(object, path, baseHas); 13228 } 13229 13230 /** 13231 * Checks if `path` is a direct or inherited property of `object`. 13232 * 13233 * @static 13234 * @memberOf _ 13235 * @since 4.0.0 13236 * @category Object 13237 * @param {Object} object The object to query. 13238 * @param {Array|string} path The path to check. 13239 * @returns {boolean} Returns `true` if `path` exists, else `false`. 13240 * @example 13241 * 13242 * var object = _.create({ 'a': _.create({ 'b': 2 }) }); 13243 * 13244 * _.hasIn(object, 'a'); 13245 * // => true 13246 * 13247 * _.hasIn(object, 'a.b'); 13248 * // => true 13249 * 13250 * _.hasIn(object, ['a', 'b']); 13251 * // => true 13252 * 13253 * _.hasIn(object, 'b'); 13254 * // => false 13255 */ 13256 function hasIn(object, path) { 13257 return object != null && hasPath(object, path, baseHasIn); 13258 } 13259 13260 /** 13261 * Creates an object composed of the inverted keys and values of `object`. 13262 * If `object` contains duplicate values, subsequent values overwrite 13263 * property assignments of previous values. 13264 * 13265 * @static 13266 * @memberOf _ 13267 * @since 0.7.0 13268 * @category Object 13269 * @param {Object} object The object to invert. 13270 * @returns {Object} Returns the new inverted object. 13271 * @example 13272 * 13273 * var object = { 'a': 1, 'b': 2, 'c': 1 }; 13274 * 13275 * _.invert(object); 13276 * // => { '1': 'c', '2': 'b' } 13277 */ 13278 var invert = createInverter(function(result, value, key) { 13279 if (value != null && 13280 typeof value.toString != 'function') { 13281 value = nativeObjectToString.call(value); 13282 } 13283 13284 result[value] = key; 13285 }, constant(identity)); 13286 13287 /** 13288 * This method is like `_.invert` except that the inverted object is generated 13289 * from the results of running each element of `object` thru `iteratee`. The 13290 * corresponding inverted value of each inverted key is an array of keys 13291 * responsible for generating the inverted value. The iteratee is invoked 13292 * with one argument: (value). 13293 * 13294 * @static 13295 * @memberOf _ 13296 * @since 4.1.0 13297 * @category Object 13298 * @param {Object} object The object to invert. 13299 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 13300 * @returns {Object} Returns the new inverted object. 13301 * @example 13302 * 13303 * var object = { 'a': 1, 'b': 2, 'c': 1 }; 13304 * 13305 * _.invertBy(object); 13306 * // => { '1': ['a', 'c'], '2': ['b'] } 13307 * 13308 * _.invertBy(object, function(value) { 13309 * return 'group' + value; 13310 * }); 13311 * // => { 'group1': ['a', 'c'], 'group2': ['b'] } 13312 */ 13313 var invertBy = createInverter(function(result, value, key) { 13314 if (value != null && 13315 typeof value.toString != 'function') { 13316 value = nativeObjectToString.call(value); 13317 } 13318 13319 if (hasOwnProperty.call(result, value)) { 13320 result[value].push(key); 13321 } else { 13322 result[value] = [key]; 13323 } 13324 }, getIteratee); 13325 13326 /** 13327 * Invokes the method at `path` of `object`. 13328 * 13329 * @static 13330 * @memberOf _ 13331 * @since 4.0.0 13332 * @category Object 13333 * @param {Object} object The object to query. 13334 * @param {Array|string} path The path of the method to invoke. 13335 * @param {...*} [args] The arguments to invoke the method with. 13336 * @returns {*} Returns the result of the invoked method. 13337 * @example 13338 * 13339 * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] }; 13340 * 13341 * _.invoke(object, 'a[0].b.c.slice', 1, 3); 13342 * // => [2, 3] 13343 */ 13344 var invoke = baseRest(baseInvoke); 13345 13346 /** 13347 * Creates an array of the own enumerable property names of `object`. 13348 * 13349 * **Note:** Non-object values are coerced to objects. See the 13350 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) 13351 * for more details. 13352 * 13353 * @static 13354 * @since 0.1.0 13355 * @memberOf _ 13356 * @category Object 13357 * @param {Object} object The object to query. 13358 * @returns {Array} Returns the array of property names. 13359 * @example 13360 * 13361 * function Foo() { 13362 * this.a = 1; 13363 * this.b = 2; 13364 * } 13365 * 13366 * Foo.prototype.c = 3; 13367 * 13368 * _.keys(new Foo); 13369 * // => ['a', 'b'] (iteration order is not guaranteed) 13370 * 13371 * _.keys('hi'); 13372 * // => ['0', '1'] 13373 */ 13374 function keys(object) { 13375 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); 13376 } 13377 13378 /** 13379 * Creates an array of the own and inherited enumerable property names of `object`. 13380 * 13381 * **Note:** Non-object values are coerced to objects. 13382 * 13383 * @static 13384 * @memberOf _ 13385 * @since 3.0.0 13386 * @category Object 13387 * @param {Object} object The object to query. 13388 * @returns {Array} Returns the array of property names. 13389 * @example 13390 * 13391 * function Foo() { 13392 * this.a = 1; 13393 * this.b = 2; 13394 * } 13395 * 13396 * Foo.prototype.c = 3; 13397 * 13398 * _.keysIn(new Foo); 13399 * // => ['a', 'b', 'c'] (iteration order is not guaranteed) 13400 */ 13401 function keysIn(object) { 13402 return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); 13403 } 13404 13405 /** 13406 * The opposite of `_.mapValues`; this method creates an object with the 13407 * same values as `object` and keys generated by running each own enumerable 13408 * string keyed property of `object` thru `iteratee`. The iteratee is invoked 13409 * with three arguments: (value, key, object). 13410 * 13411 * @static 13412 * @memberOf _ 13413 * @since 3.8.0 13414 * @category Object 13415 * @param {Object} object The object to iterate over. 13416 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 13417 * @returns {Object} Returns the new mapped object. 13418 * @see _.mapValues 13419 * @example 13420 * 13421 * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { 13422 * return key + value; 13423 * }); 13424 * // => { 'a1': 1, 'b2': 2 } 13425 */ 13426 function mapKeys(object, iteratee) { 13427 var result = {}; 13428 iteratee = getIteratee(iteratee, 3); 13429 13430 baseForOwn(object, function(value, key, object) { 13431 baseAssignValue(result, iteratee(value, key, object), value); 13432 }); 13433 return result; 13434 } 13435 13436 /** 13437 * Creates an object with the same keys as `object` and values generated 13438 * by running each own enumerable string keyed property of `object` thru 13439 * `iteratee`. The iteratee is invoked with three arguments: 13440 * (value, key, object). 13441 * 13442 * @static 13443 * @memberOf _ 13444 * @since 2.4.0 13445 * @category Object 13446 * @param {Object} object The object to iterate over. 13447 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 13448 * @returns {Object} Returns the new mapped object. 13449 * @see _.mapKeys 13450 * @example 13451 * 13452 * var users = { 13453 * 'fred': { 'user': 'fred', 'age': 40 }, 13454 * 'pebbles': { 'user': 'pebbles', 'age': 1 } 13455 * }; 13456 * 13457 * _.mapValues(users, function(o) { return o.age; }); 13458 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) 13459 * 13460 * // The `_.property` iteratee shorthand. 13461 * _.mapValues(users, 'age'); 13462 * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) 13463 */ 13464 function mapValues(object, iteratee) { 13465 var result = {}; 13466 iteratee = getIteratee(iteratee, 3); 13467 13468 baseForOwn(object, function(value, key, object) { 13469 baseAssignValue(result, key, iteratee(value, key, object)); 13470 }); 13471 return result; 13472 } 13473 13474 /** 13475 * This method is like `_.assign` except that it recursively merges own and 13476 * inherited enumerable string keyed properties of source objects into the 13477 * destination object. Source properties that resolve to `undefined` are 13478 * skipped if a destination value exists. Array and plain object properties 13479 * are merged recursively. Other objects and value types are overridden by 13480 * assignment. Source objects are applied from left to right. Subsequent 13481 * sources overwrite property assignments of previous sources. 13482 * 13483 * **Note:** This method mutates `object`. 13484 * 13485 * @static 13486 * @memberOf _ 13487 * @since 0.5.0 13488 * @category Object 13489 * @param {Object} object The destination object. 13490 * @param {...Object} [sources] The source objects. 13491 * @returns {Object} Returns `object`. 13492 * @example 13493 * 13494 * var object = { 13495 * 'a': [{ 'b': 2 }, { 'd': 4 }] 13496 * }; 13497 * 13498 * var other = { 13499 * 'a': [{ 'c': 3 }, { 'e': 5 }] 13500 * }; 13501 * 13502 * _.merge(object, other); 13503 * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } 13504 */ 13505 var merge = createAssigner(function(object, source, srcIndex) { 13506 baseMerge(object, source, srcIndex); 13507 }); 13508 13509 /** 13510 * This method is like `_.merge` except that it accepts `customizer` which 13511 * is invoked to produce the merged values of the destination and source 13512 * properties. If `customizer` returns `undefined`, merging is handled by the 13513 * method instead. The `customizer` is invoked with six arguments: 13514 * (objValue, srcValue, key, object, source, stack). 13515 * 13516 * **Note:** This method mutates `object`. 13517 * 13518 * @static 13519 * @memberOf _ 13520 * @since 4.0.0 13521 * @category Object 13522 * @param {Object} object The destination object. 13523 * @param {...Object} sources The source objects. 13524 * @param {Function} customizer The function to customize assigned values. 13525 * @returns {Object} Returns `object`. 13526 * @example 13527 * 13528 * function customizer(objValue, srcValue) { 13529 * if (_.isArray(objValue)) { 13530 * return objValue.concat(srcValue); 13531 * } 13532 * } 13533 * 13534 * var object = { 'a': [1], 'b': [2] }; 13535 * var other = { 'a': [3], 'b': [4] }; 13536 * 13537 * _.mergeWith(object, other, customizer); 13538 * // => { 'a': [1, 3], 'b': [2, 4] } 13539 */ 13540 var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { 13541 baseMerge(object, source, srcIndex, customizer); 13542 }); 13543 13544 /** 13545 * The opposite of `_.pick`; this method creates an object composed of the 13546 * own and inherited enumerable property paths of `object` that are not omitted. 13547 * 13548 * **Note:** This method is considerably slower than `_.pick`. 13549 * 13550 * @static 13551 * @since 0.1.0 13552 * @memberOf _ 13553 * @category Object 13554 * @param {Object} object The source object. 13555 * @param {...(string|string[])} [paths] The property paths to omit. 13556 * @returns {Object} Returns the new object. 13557 * @example 13558 * 13559 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 13560 * 13561 * _.omit(object, ['a', 'c']); 13562 * // => { 'b': '2' } 13563 */ 13564 var omit = flatRest(function(object, paths) { 13565 var result = {}; 13566 if (object == null) { 13567 return result; 13568 } 13569 var isDeep = false; 13570 paths = arrayMap(paths, function(path) { 13571 path = castPath(path, object); 13572 isDeep || (isDeep = path.length > 1); 13573 return path; 13574 }); 13575 copyObject(object, getAllKeysIn(object), result); 13576 if (isDeep) { 13577 result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone); 13578 } 13579 var length = paths.length; 13580 while (length--) { 13581 baseUnset(result, paths[length]); 13582 } 13583 return result; 13584 }); 13585 13586 /** 13587 * The opposite of `_.pickBy`; this method creates an object composed of 13588 * the own and inherited enumerable string keyed properties of `object` that 13589 * `predicate` doesn't return truthy for. The predicate is invoked with two 13590 * arguments: (value, key). 13591 * 13592 * @static 13593 * @memberOf _ 13594 * @since 4.0.0 13595 * @category Object 13596 * @param {Object} object The source object. 13597 * @param {Function} [predicate=_.identity] The function invoked per property. 13598 * @returns {Object} Returns the new object. 13599 * @example 13600 * 13601 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 13602 * 13603 * _.omitBy(object, _.isNumber); 13604 * // => { 'b': '2' } 13605 */ 13606 function omitBy(object, predicate) { 13607 return pickBy(object, negate(getIteratee(predicate))); 13608 } 13609 13610 /** 13611 * Creates an object composed of the picked `object` properties. 13612 * 13613 * @static 13614 * @since 0.1.0 13615 * @memberOf _ 13616 * @category Object 13617 * @param {Object} object The source object. 13618 * @param {...(string|string[])} [paths] The property paths to pick. 13619 * @returns {Object} Returns the new object. 13620 * @example 13621 * 13622 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 13623 * 13624 * _.pick(object, ['a', 'c']); 13625 * // => { 'a': 1, 'c': 3 } 13626 */ 13627 var pick = flatRest(function(object, paths) { 13628 return object == null ? {} : basePick(object, paths); 13629 }); 13630 13631 /** 13632 * Creates an object composed of the `object` properties `predicate` returns 13633 * truthy for. The predicate is invoked with two arguments: (value, key). 13634 * 13635 * @static 13636 * @memberOf _ 13637 * @since 4.0.0 13638 * @category Object 13639 * @param {Object} object The source object. 13640 * @param {Function} [predicate=_.identity] The function invoked per property. 13641 * @returns {Object} Returns the new object. 13642 * @example 13643 * 13644 * var object = { 'a': 1, 'b': '2', 'c': 3 }; 13645 * 13646 * _.pickBy(object, _.isNumber); 13647 * // => { 'a': 1, 'c': 3 } 13648 */ 13649 function pickBy(object, predicate) { 13650 if (object == null) { 13651 return {}; 13652 } 13653 var props = arrayMap(getAllKeysIn(object), function(prop) { 13654 return [prop]; 13655 }); 13656 predicate = getIteratee(predicate); 13657 return basePickBy(object, props, function(value, path) { 13658 return predicate(value, path[0]); 13659 }); 13660 } 13661 13662 /** 13663 * This method is like `_.get` except that if the resolved value is a 13664 * function it's invoked with the `this` binding of its parent object and 13665 * its result is returned. 13666 * 13667 * @static 13668 * @since 0.1.0 13669 * @memberOf _ 13670 * @category Object 13671 * @param {Object} object The object to query. 13672 * @param {Array|string} path The path of the property to resolve. 13673 * @param {*} [defaultValue] The value returned for `undefined` resolved values. 13674 * @returns {*} Returns the resolved value. 13675 * @example 13676 * 13677 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; 13678 * 13679 * _.result(object, 'a[0].b.c1'); 13680 * // => 3 13681 * 13682 * _.result(object, 'a[0].b.c2'); 13683 * // => 4 13684 * 13685 * _.result(object, 'a[0].b.c3', 'default'); 13686 * // => 'default' 13687 * 13688 * _.result(object, 'a[0].b.c3', _.constant('default')); 13689 * // => 'default' 13690 */ 13691 function result(object, path, defaultValue) { 13692 path = castPath(path, object); 13693 13694 var index = -1, 13695 length = path.length; 13696 13697 // Ensure the loop is entered when path is empty. 13698 if (!length) { 13699 length = 1; 13700 object = undefined; 13701 } 13702 while (++index < length) { 13703 var value = object == null ? undefined : object[toKey(path[index])]; 13704 if (value === undefined) { 13705 index = length; 13706 value = defaultValue; 13707 } 13708 object = isFunction(value) ? value.call(object) : value; 13709 } 13710 return object; 13711 } 13712 13713 /** 13714 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist, 13715 * it's created. Arrays are created for missing index properties while objects 13716 * are created for all other missing properties. Use `_.setWith` to customize 13717 * `path` creation. 13718 * 13719 * **Note:** This method mutates `object`. 13720 * 13721 * @static 13722 * @memberOf _ 13723 * @since 3.7.0 13724 * @category Object 13725 * @param {Object} object The object to modify. 13726 * @param {Array|string} path The path of the property to set. 13727 * @param {*} value The value to set. 13728 * @returns {Object} Returns `object`. 13729 * @example 13730 * 13731 * var object = { 'a': [{ 'b': { 'c': 3 } }] }; 13732 * 13733 * _.set(object, 'a[0].b.c', 4); 13734 * console.log(object.a[0].b.c); 13735 * // => 4 13736 * 13737 * _.set(object, ['x', '0', 'y', 'z'], 5); 13738 * console.log(object.x[0].y.z); 13739 * // => 5 13740 */ 13741 function set(object, path, value) { 13742 return object == null ? object : baseSet(object, path, value); 13743 } 13744 13745 /** 13746 * This method is like `_.set` except that it accepts `customizer` which is 13747 * invoked to produce the objects of `path`. If `customizer` returns `undefined` 13748 * path creation is handled by the method instead. The `customizer` is invoked 13749 * with three arguments: (nsValue, key, nsObject). 13750 * 13751 * **Note:** This method mutates `object`. 13752 * 13753 * @static 13754 * @memberOf _ 13755 * @since 4.0.0 13756 * @category Object 13757 * @param {Object} object The object to modify. 13758 * @param {Array|string} path The path of the property to set. 13759 * @param {*} value The value to set. 13760 * @param {Function} [customizer] The function to customize assigned values. 13761 * @returns {Object} Returns `object`. 13762 * @example 13763 * 13764 * var object = {}; 13765 * 13766 * _.setWith(object, '[0][1]', 'a', Object); 13767 * // => { '0': { '1': 'a' } } 13768 */ 13769 function setWith(object, path, value, customizer) { 13770 customizer = typeof customizer == 'function' ? customizer : undefined; 13771 return object == null ? object : baseSet(object, path, value, customizer); 13772 } 13773 13774 /** 13775 * Creates an array of own enumerable string keyed-value pairs for `object` 13776 * which can be consumed by `_.fromPairs`. If `object` is a map or set, its 13777 * entries are returned. 13778 * 13779 * @static 13780 * @memberOf _ 13781 * @since 4.0.0 13782 * @alias entries 13783 * @category Object 13784 * @param {Object} object The object to query. 13785 * @returns {Array} Returns the key-value pairs. 13786 * @example 13787 * 13788 * function Foo() { 13789 * this.a = 1; 13790 * this.b = 2; 13791 * } 13792 * 13793 * Foo.prototype.c = 3; 13794 * 13795 * _.toPairs(new Foo); 13796 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) 13797 */ 13798 var toPairs = createToPairs(keys); 13799 13800 /** 13801 * Creates an array of own and inherited enumerable string keyed-value pairs 13802 * for `object` which can be consumed by `_.fromPairs`. If `object` is a map 13803 * or set, its entries are returned. 13804 * 13805 * @static 13806 * @memberOf _ 13807 * @since 4.0.0 13808 * @alias entriesIn 13809 * @category Object 13810 * @param {Object} object The object to query. 13811 * @returns {Array} Returns the key-value pairs. 13812 * @example 13813 * 13814 * function Foo() { 13815 * this.a = 1; 13816 * this.b = 2; 13817 * } 13818 * 13819 * Foo.prototype.c = 3; 13820 * 13821 * _.toPairsIn(new Foo); 13822 * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) 13823 */ 13824 var toPairsIn = createToPairs(keysIn); 13825 13826 /** 13827 * An alternative to `_.reduce`; this method transforms `object` to a new 13828 * `accumulator` object which is the result of running each of its own 13829 * enumerable string keyed properties thru `iteratee`, with each invocation 13830 * potentially mutating the `accumulator` object. If `accumulator` is not 13831 * provided, a new object with the same `[[Prototype]]` will be used. The 13832 * iteratee is invoked with four arguments: (accumulator, value, key, object). 13833 * Iteratee functions may exit iteration early by explicitly returning `false`. 13834 * 13835 * @static 13836 * @memberOf _ 13837 * @since 1.3.0 13838 * @category Object 13839 * @param {Object} object The object to iterate over. 13840 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 13841 * @param {*} [accumulator] The custom accumulator value. 13842 * @returns {*} Returns the accumulated value. 13843 * @example 13844 * 13845 * _.transform([2, 3, 4], function(result, n) { 13846 * result.push(n *= n); 13847 * return n % 2 == 0; 13848 * }, []); 13849 * // => [4, 9] 13850 * 13851 * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { 13852 * (result[value] || (result[value] = [])).push(key); 13853 * }, {}); 13854 * // => { '1': ['a', 'c'], '2': ['b'] } 13855 */ 13856 function transform(object, iteratee, accumulator) { 13857 var isArr = isArray(object), 13858 isArrLike = isArr || isBuffer(object) || isTypedArray(object); 13859 13860 iteratee = getIteratee(iteratee, 4); 13861 if (accumulator == null) { 13862 var Ctor = object && object.constructor; 13863 if (isArrLike) { 13864 accumulator = isArr ? new Ctor : []; 13865 } 13866 else if (isObject(object)) { 13867 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; 13868 } 13869 else { 13870 accumulator = {}; 13871 } 13872 } 13873 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) { 13874 return iteratee(accumulator, value, index, object); 13875 }); 13876 return accumulator; 13877 } 13878 13879 /** 13880 * Removes the property at `path` of `object`. 13881 * 13882 * **Note:** This method mutates `object`. 13883 * 13884 * @static 13885 * @memberOf _ 13886 * @since 4.0.0 13887 * @category Object 13888 * @param {Object} object The object to modify. 13889 * @param {Array|string} path The path of the property to unset. 13890 * @returns {boolean} Returns `true` if the property is deleted, else `false`. 13891 * @example 13892 * 13893 * var object = { 'a': [{ 'b': { 'c': 7 } }] }; 13894 * _.unset(object, 'a[0].b.c'); 13895 * // => true 13896 * 13897 * console.log(object); 13898 * // => { 'a': [{ 'b': {} }] }; 13899 * 13900 * _.unset(object, ['a', '0', 'b', 'c']); 13901 * // => true 13902 * 13903 * console.log(object); 13904 * // => { 'a': [{ 'b': {} }] }; 13905 */ 13906 function unset(object, path) { 13907 return object == null ? true : baseUnset(object, path); 13908 } 13909 13910 /** 13911 * This method is like `_.set` except that accepts `updater` to produce the 13912 * value to set. Use `_.updateWith` to customize `path` creation. The `updater` 13913 * is invoked with one argument: (value). 13914 * 13915 * **Note:** This method mutates `object`. 13916 * 13917 * @static 13918 * @memberOf _ 13919 * @since 4.6.0 13920 * @category Object 13921 * @param {Object} object The object to modify. 13922 * @param {Array|string} path The path of the property to set. 13923 * @param {Function} updater The function to produce the updated value. 13924 * @returns {Object} Returns `object`. 13925 * @example 13926 * 13927 * var object = { 'a': [{ 'b': { 'c': 3 } }] }; 13928 * 13929 * _.update(object, 'a[0].b.c', function(n) { return n * n; }); 13930 * console.log(object.a[0].b.c); 13931 * // => 9 13932 * 13933 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; }); 13934 * console.log(object.x[0].y.z); 13935 * // => 0 13936 */ 13937 function update(object, path, updater) { 13938 return object == null ? object : baseUpdate(object, path, castFunction(updater)); 13939 } 13940 13941 /** 13942 * This method is like `_.update` except that it accepts `customizer` which is 13943 * invoked to produce the objects of `path`. If `customizer` returns `undefined` 13944 * path creation is handled by the method instead. The `customizer` is invoked 13945 * with three arguments: (nsValue, key, nsObject). 13946 * 13947 * **Note:** This method mutates `object`. 13948 * 13949 * @static 13950 * @memberOf _ 13951 * @since 4.6.0 13952 * @category Object 13953 * @param {Object} object The object to modify. 13954 * @param {Array|string} path The path of the property to set. 13955 * @param {Function} updater The function to produce the updated value. 13956 * @param {Function} [customizer] The function to customize assigned values. 13957 * @returns {Object} Returns `object`. 13958 * @example 13959 * 13960 * var object = {}; 13961 * 13962 * _.updateWith(object, '[0][1]', _.constant('a'), Object); 13963 * // => { '0': { '1': 'a' } } 13964 */ 13965 function updateWith(object, path, updater, customizer) { 13966 customizer = typeof customizer == 'function' ? customizer : undefined; 13967 return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer); 13968 } 13969 13970 /** 13971 * Creates an array of the own enumerable string keyed property values of `object`. 13972 * 13973 * **Note:** Non-object values are coerced to objects. 13974 * 13975 * @static 13976 * @since 0.1.0 13977 * @memberOf _ 13978 * @category Object 13979 * @param {Object} object The object to query. 13980 * @returns {Array} Returns the array of property values. 13981 * @example 13982 * 13983 * function Foo() { 13984 * this.a = 1; 13985 * this.b = 2; 13986 * } 13987 * 13988 * Foo.prototype.c = 3; 13989 * 13990 * _.values(new Foo); 13991 * // => [1, 2] (iteration order is not guaranteed) 13992 * 13993 * _.values('hi'); 13994 * // => ['h', 'i'] 13995 */ 13996 function values(object) { 13997 return object == null ? [] : baseValues(object, keys(object)); 13998 } 13999 14000 /** 14001 * Creates an array of the own and inherited enumerable string keyed property 14002 * values of `object`. 14003 * 14004 * **Note:** Non-object values are coerced to objects. 14005 * 14006 * @static 14007 * @memberOf _ 14008 * @since 3.0.0 14009 * @category Object 14010 * @param {Object} object The object to query. 14011 * @returns {Array} Returns the array of property values. 14012 * @example 14013 * 14014 * function Foo() { 14015 * this.a = 1; 14016 * this.b = 2; 14017 * } 14018 * 14019 * Foo.prototype.c = 3; 14020 * 14021 * _.valuesIn(new Foo); 14022 * // => [1, 2, 3] (iteration order is not guaranteed) 14023 */ 14024 function valuesIn(object) { 14025 return object == null ? [] : baseValues(object, keysIn(object)); 14026 } 14027 14028 /*------------------------------------------------------------------------*/ 14029 14030 /** 14031 * Clamps `number` within the inclusive `lower` and `upper` bounds. 14032 * 14033 * @static 14034 * @memberOf _ 14035 * @since 4.0.0 14036 * @category Number 14037 * @param {number} number The number to clamp. 14038 * @param {number} [lower] The lower bound. 14039 * @param {number} upper The upper bound. 14040 * @returns {number} Returns the clamped number. 14041 * @example 14042 * 14043 * _.clamp(-10, -5, 5); 14044 * // => -5 14045 * 14046 * _.clamp(10, -5, 5); 14047 * // => 5 14048 */ 14049 function clamp(number, lower, upper) { 14050 if (upper === undefined) { 14051 upper = lower; 14052 lower = undefined; 14053 } 14054 if (upper !== undefined) { 14055 upper = toNumber(upper); 14056 upper = upper === upper ? upper : 0; 14057 } 14058 if (lower !== undefined) { 14059 lower = toNumber(lower); 14060 lower = lower === lower ? lower : 0; 14061 } 14062 return baseClamp(toNumber(number), lower, upper); 14063 } 14064 14065 /** 14066 * Checks if `n` is between `start` and up to, but not including, `end`. If 14067 * `end` is not specified, it's set to `start` with `start` then set to `0`. 14068 * If `start` is greater than `end` the params are swapped to support 14069 * negative ranges. 14070 * 14071 * @static 14072 * @memberOf _ 14073 * @since 3.3.0 14074 * @category Number 14075 * @param {number} number The number to check. 14076 * @param {number} [start=0] The start of the range. 14077 * @param {number} end The end of the range. 14078 * @returns {boolean} Returns `true` if `number` is in the range, else `false`. 14079 * @see _.range, _.rangeRight 14080 * @example 14081 * 14082 * _.inRange(3, 2, 4); 14083 * // => true 14084 * 14085 * _.inRange(4, 8); 14086 * // => true 14087 * 14088 * _.inRange(4, 2); 14089 * // => false 14090 * 14091 * _.inRange(2, 2); 14092 * // => false 14093 * 14094 * _.inRange(1.2, 2); 14095 * // => true 14096 * 14097 * _.inRange(5.2, 4); 14098 * // => false 14099 * 14100 * _.inRange(-3, -2, -6); 14101 * // => true 14102 */ 14103 function inRange(number, start, end) { 14104 start = toFinite(start); 14105 if (end === undefined) { 14106 end = start; 14107 start = 0; 14108 } else { 14109 end = toFinite(end); 14110 } 14111 number = toNumber(number); 14112 return baseInRange(number, start, end); 14113 } 14114 14115 /** 14116 * Produces a random number between the inclusive `lower` and `upper` bounds. 14117 * If only one argument is provided a number between `0` and the given number 14118 * is returned. If `floating` is `true`, or either `lower` or `upper` are 14119 * floats, a floating-point number is returned instead of an integer. 14120 * 14121 * **Note:** JavaScript follows the IEEE-754 standard for resolving 14122 * floating-point values which can produce unexpected results. 14123 * 14124 * @static 14125 * @memberOf _ 14126 * @since 0.7.0 14127 * @category Number 14128 * @param {number} [lower=0] The lower bound. 14129 * @param {number} [upper=1] The upper bound. 14130 * @param {boolean} [floating] Specify returning a floating-point number. 14131 * @returns {number} Returns the random number. 14132 * @example 14133 * 14134 * _.random(0, 5); 14135 * // => an integer between 0 and 5 14136 * 14137 * _.random(5); 14138 * // => also an integer between 0 and 5 14139 * 14140 * _.random(5, true); 14141 * // => a floating-point number between 0 and 5 14142 * 14143 * _.random(1.2, 5.2); 14144 * // => a floating-point number between 1.2 and 5.2 14145 */ 14146 function random(lower, upper, floating) { 14147 if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) { 14148 upper = floating = undefined; 14149 } 14150 if (floating === undefined) { 14151 if (typeof upper == 'boolean') { 14152 floating = upper; 14153 upper = undefined; 14154 } 14155 else if (typeof lower == 'boolean') { 14156 floating = lower; 14157 lower = undefined; 14158 } 14159 } 14160 if (lower === undefined && upper === undefined) { 14161 lower = 0; 14162 upper = 1; 14163 } 14164 else { 14165 lower = toFinite(lower); 14166 if (upper === undefined) { 14167 upper = lower; 14168 lower = 0; 14169 } else { 14170 upper = toFinite(upper); 14171 } 14172 } 14173 if (lower > upper) { 14174 var temp = lower; 14175 lower = upper; 14176 upper = temp; 14177 } 14178 if (floating || lower % 1 || upper % 1) { 14179 var rand = nativeRandom(); 14180 return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper); 14181 } 14182 return baseRandom(lower, upper); 14183 } 14184 14185 /*------------------------------------------------------------------------*/ 14186 14187 /** 14188 * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). 14189 * 14190 * @static 14191 * @memberOf _ 14192 * @since 3.0.0 14193 * @category String 14194 * @param {string} [string=''] The string to convert. 14195 * @returns {string} Returns the camel cased string. 14196 * @example 14197 * 14198 * _.camelCase('Foo Bar'); 14199 * // => 'fooBar' 14200 * 14201 * _.camelCase('--foo-bar--'); 14202 * // => 'fooBar' 14203 * 14204 * _.camelCase('__FOO_BAR__'); 14205 * // => 'fooBar' 14206 */ 14207 var camelCase = createCompounder(function(result, word, index) { 14208 word = word.toLowerCase(); 14209 return result + (index ? capitalize(word) : word); 14210 }); 14211 14212 /** 14213 * Converts the first character of `string` to upper case and the remaining 14214 * to lower case. 14215 * 14216 * @static 14217 * @memberOf _ 14218 * @since 3.0.0 14219 * @category String 14220 * @param {string} [string=''] The string to capitalize. 14221 * @returns {string} Returns the capitalized string. 14222 * @example 14223 * 14224 * _.capitalize('FRED'); 14225 * // => 'Fred' 14226 */ 14227 function capitalize(string) { 14228 return upperFirst(toString(string).toLowerCase()); 14229 } 14230 14231 /** 14232 * Deburrs `string` by converting 14233 * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) 14234 * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) 14235 * letters to basic Latin letters and removing 14236 * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). 14237 * 14238 * @static 14239 * @memberOf _ 14240 * @since 3.0.0 14241 * @category String 14242 * @param {string} [string=''] The string to deburr. 14243 * @returns {string} Returns the deburred string. 14244 * @example 14245 * 14246 * _.deburr('déjà vu'); 14247 * // => 'deja vu' 14248 */ 14249 function deburr(string) { 14250 string = toString(string); 14251 return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); 14252 } 14253 14254 /** 14255 * Checks if `string` ends with the given target string. 14256 * 14257 * @static 14258 * @memberOf _ 14259 * @since 3.0.0 14260 * @category String 14261 * @param {string} [string=''] The string to inspect. 14262 * @param {string} [target] The string to search for. 14263 * @param {number} [position=string.length] The position to search up to. 14264 * @returns {boolean} Returns `true` if `string` ends with `target`, 14265 * else `false`. 14266 * @example 14267 * 14268 * _.endsWith('abc', 'c'); 14269 * // => true 14270 * 14271 * _.endsWith('abc', 'b'); 14272 * // => false 14273 * 14274 * _.endsWith('abc', 'b', 2); 14275 * // => true 14276 */ 14277 function endsWith(string, target, position) { 14278 string = toString(string); 14279 target = baseToString(target); 14280 14281 var length = string.length; 14282 position = position === undefined 14283 ? length 14284 : baseClamp(toInteger(position), 0, length); 14285 14286 var end = position; 14287 position -= target.length; 14288 return position >= 0 && string.slice(position, end) == target; 14289 } 14290 14291 /** 14292 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their 14293 * corresponding HTML entities. 14294 * 14295 * **Note:** No other characters are escaped. To escape additional 14296 * characters use a third-party library like [_he_](https://mths.be/he). 14297 * 14298 * Though the ">" character is escaped for symmetry, characters like 14299 * ">" and "/" don't need escaping in HTML and have no special meaning 14300 * unless they're part of a tag or unquoted attribute value. See 14301 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) 14302 * (under "semi-related fun fact") for more details. 14303 * 14304 * When working with HTML you should always 14305 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce 14306 * XSS vectors. 14307 * 14308 * @static 14309 * @since 0.1.0 14310 * @memberOf _ 14311 * @category String 14312 * @param {string} [string=''] The string to escape. 14313 * @returns {string} Returns the escaped string. 14314 * @example 14315 * 14316 * _.escape('fred, barney, & pebbles'); 14317 * // => 'fred, barney, & pebbles' 14318 */ 14319 function escape(string) { 14320 string = toString(string); 14321 return (string && reHasUnescapedHtml.test(string)) 14322 ? string.replace(reUnescapedHtml, escapeHtmlChar) 14323 : string; 14324 } 14325 14326 /** 14327 * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", 14328 * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. 14329 * 14330 * @static 14331 * @memberOf _ 14332 * @since 3.0.0 14333 * @category String 14334 * @param {string} [string=''] The string to escape. 14335 * @returns {string} Returns the escaped string. 14336 * @example 14337 * 14338 * _.escapeRegExp('[lodash](https://lodash.com/)'); 14339 * // => '\[lodash\]\(https://lodash\.com/\)' 14340 */ 14341 function escapeRegExp(string) { 14342 string = toString(string); 14343 return (string && reHasRegExpChar.test(string)) 14344 ? string.replace(reRegExpChar, '\\$&') 14345 : string; 14346 } 14347 14348 /** 14349 * Converts `string` to 14350 * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). 14351 * 14352 * @static 14353 * @memberOf _ 14354 * @since 3.0.0 14355 * @category String 14356 * @param {string} [string=''] The string to convert. 14357 * @returns {string} Returns the kebab cased string. 14358 * @example 14359 * 14360 * _.kebabCase('Foo Bar'); 14361 * // => 'foo-bar' 14362 * 14363 * _.kebabCase('fooBar'); 14364 * // => 'foo-bar' 14365 * 14366 * _.kebabCase('__FOO_BAR__'); 14367 * // => 'foo-bar' 14368 */ 14369 var kebabCase = createCompounder(function(result, word, index) { 14370 return result + (index ? '-' : '') + word.toLowerCase(); 14371 }); 14372 14373 /** 14374 * Converts `string`, as space separated words, to lower case. 14375 * 14376 * @static 14377 * @memberOf _ 14378 * @since 4.0.0 14379 * @category String 14380 * @param {string} [string=''] The string to convert. 14381 * @returns {string} Returns the lower cased string. 14382 * @example 14383 * 14384 * _.lowerCase('--Foo-Bar--'); 14385 * // => 'foo bar' 14386 * 14387 * _.lowerCase('fooBar'); 14388 * // => 'foo bar' 14389 * 14390 * _.lowerCase('__FOO_BAR__'); 14391 * // => 'foo bar' 14392 */ 14393 var lowerCase = createCompounder(function(result, word, index) { 14394 return result + (index ? ' ' : '') + word.toLowerCase(); 14395 }); 14396 14397 /** 14398 * Converts the first character of `string` to lower case. 14399 * 14400 * @static 14401 * @memberOf _ 14402 * @since 4.0.0 14403 * @category String 14404 * @param {string} [string=''] The string to convert. 14405 * @returns {string} Returns the converted string. 14406 * @example 14407 * 14408 * _.lowerFirst('Fred'); 14409 * // => 'fred' 14410 * 14411 * _.lowerFirst('FRED'); 14412 * // => 'fRED' 14413 */ 14414 var lowerFirst = createCaseFirst('toLowerCase'); 14415 14416 /** 14417 * Pads `string` on the left and right sides if it's shorter than `length`. 14418 * Padding characters are truncated if they can't be evenly divided by `length`. 14419 * 14420 * @static 14421 * @memberOf _ 14422 * @since 3.0.0 14423 * @category String 14424 * @param {string} [string=''] The string to pad. 14425 * @param {number} [length=0] The padding length. 14426 * @param {string} [chars=' '] The string used as padding. 14427 * @returns {string} Returns the padded string. 14428 * @example 14429 * 14430 * _.pad('abc', 8); 14431 * // => ' abc ' 14432 * 14433 * _.pad('abc', 8, '_-'); 14434 * // => '_-abc_-_' 14435 * 14436 * _.pad('abc', 3); 14437 * // => 'abc' 14438 */ 14439 function pad(string, length, chars) { 14440 string = toString(string); 14441 length = toInteger(length); 14442 14443 var strLength = length ? stringSize(string) : 0; 14444 if (!length || strLength >= length) { 14445 return string; 14446 } 14447 var mid = (length - strLength) / 2; 14448 return ( 14449 createPadding(nativeFloor(mid), chars) + 14450 string + 14451 createPadding(nativeCeil(mid), chars) 14452 ); 14453 } 14454 14455 /** 14456 * Pads `string` on the right side if it's shorter than `length`. Padding 14457 * characters are truncated if they exceed `length`. 14458 * 14459 * @static 14460 * @memberOf _ 14461 * @since 4.0.0 14462 * @category String 14463 * @param {string} [string=''] The string to pad. 14464 * @param {number} [length=0] The padding length. 14465 * @param {string} [chars=' '] The string used as padding. 14466 * @returns {string} Returns the padded string. 14467 * @example 14468 * 14469 * _.padEnd('abc', 6); 14470 * // => 'abc ' 14471 * 14472 * _.padEnd('abc', 6, '_-'); 14473 * // => 'abc_-_' 14474 * 14475 * _.padEnd('abc', 3); 14476 * // => 'abc' 14477 */ 14478 function padEnd(string, length, chars) { 14479 string = toString(string); 14480 length = toInteger(length); 14481 14482 var strLength = length ? stringSize(string) : 0; 14483 return (length && strLength < length) 14484 ? (string + createPadding(length - strLength, chars)) 14485 : string; 14486 } 14487 14488 /** 14489 * Pads `string` on the left side if it's shorter than `length`. Padding 14490 * characters are truncated if they exceed `length`. 14491 * 14492 * @static 14493 * @memberOf _ 14494 * @since 4.0.0 14495 * @category String 14496 * @param {string} [string=''] The string to pad. 14497 * @param {number} [length=0] The padding length. 14498 * @param {string} [chars=' '] The string used as padding. 14499 * @returns {string} Returns the padded string. 14500 * @example 14501 * 14502 * _.padStart('abc', 6); 14503 * // => ' abc' 14504 * 14505 * _.padStart('abc', 6, '_-'); 14506 * // => '_-_abc' 14507 * 14508 * _.padStart('abc', 3); 14509 * // => 'abc' 14510 */ 14511 function padStart(string, length, chars) { 14512 string = toString(string); 14513 length = toInteger(length); 14514 14515 var strLength = length ? stringSize(string) : 0; 14516 return (length && strLength < length) 14517 ? (createPadding(length - strLength, chars) + string) 14518 : string; 14519 } 14520 14521 /** 14522 * Converts `string` to an integer of the specified radix. If `radix` is 14523 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a 14524 * hexadecimal, in which case a `radix` of `16` is used. 14525 * 14526 * **Note:** This method aligns with the 14527 * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. 14528 * 14529 * @static 14530 * @memberOf _ 14531 * @since 1.1.0 14532 * @category String 14533 * @param {string} string The string to convert. 14534 * @param {number} [radix=10] The radix to interpret `value` by. 14535 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 14536 * @returns {number} Returns the converted integer. 14537 * @example 14538 * 14539 * _.parseInt('08'); 14540 * // => 8 14541 * 14542 * _.map(['6', '08', '10'], _.parseInt); 14543 * // => [6, 8, 10] 14544 */ 14545 function parseInt(string, radix, guard) { 14546 if (guard || radix == null) { 14547 radix = 0; 14548 } else if (radix) { 14549 radix = +radix; 14550 } 14551 return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0); 14552 } 14553 14554 /** 14555 * Repeats the given string `n` times. 14556 * 14557 * @static 14558 * @memberOf _ 14559 * @since 3.0.0 14560 * @category String 14561 * @param {string} [string=''] The string to repeat. 14562 * @param {number} [n=1] The number of times to repeat the string. 14563 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 14564 * @returns {string} Returns the repeated string. 14565 * @example 14566 * 14567 * _.repeat('*', 3); 14568 * // => '***' 14569 * 14570 * _.repeat('abc', 2); 14571 * // => 'abcabc' 14572 * 14573 * _.repeat('abc', 0); 14574 * // => '' 14575 */ 14576 function repeat(string, n, guard) { 14577 if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) { 14578 n = 1; 14579 } else { 14580 n = toInteger(n); 14581 } 14582 return baseRepeat(toString(string), n); 14583 } 14584 14585 /** 14586 * Replaces matches for `pattern` in `string` with `replacement`. 14587 * 14588 * **Note:** This method is based on 14589 * [`String#replace`](https://mdn.io/String/replace). 14590 * 14591 * @static 14592 * @memberOf _ 14593 * @since 4.0.0 14594 * @category String 14595 * @param {string} [string=''] The string to modify. 14596 * @param {RegExp|string} pattern The pattern to replace. 14597 * @param {Function|string} replacement The match replacement. 14598 * @returns {string} Returns the modified string. 14599 * @example 14600 * 14601 * _.replace('Hi Fred', 'Fred', 'Barney'); 14602 * // => 'Hi Barney' 14603 */ 14604 function replace() { 14605 var args = arguments, 14606 string = toString(args[0]); 14607 14608 return args.length < 3 ? string : string.replace(args[1], args[2]); 14609 } 14610 14611 /** 14612 * Converts `string` to 14613 * [snake case](https://en.wikipedia.org/wiki/Snake_case). 14614 * 14615 * @static 14616 * @memberOf _ 14617 * @since 3.0.0 14618 * @category String 14619 * @param {string} [string=''] The string to convert. 14620 * @returns {string} Returns the snake cased string. 14621 * @example 14622 * 14623 * _.snakeCase('Foo Bar'); 14624 * // => 'foo_bar' 14625 * 14626 * _.snakeCase('fooBar'); 14627 * // => 'foo_bar' 14628 * 14629 * _.snakeCase('--FOO-BAR--'); 14630 * // => 'foo_bar' 14631 */ 14632 var snakeCase = createCompounder(function(result, word, index) { 14633 return result + (index ? '_' : '') + word.toLowerCase(); 14634 }); 14635 14636 /** 14637 * Splits `string` by `separator`. 14638 * 14639 * **Note:** This method is based on 14640 * [`String#split`](https://mdn.io/String/split). 14641 * 14642 * @static 14643 * @memberOf _ 14644 * @since 4.0.0 14645 * @category String 14646 * @param {string} [string=''] The string to split. 14647 * @param {RegExp|string} separator The separator pattern to split by. 14648 * @param {number} [limit] The length to truncate results to. 14649 * @returns {Array} Returns the string segments. 14650 * @example 14651 * 14652 * _.split('a-b-c', '-', 2); 14653 * // => ['a', 'b'] 14654 */ 14655 function split(string, separator, limit) { 14656 if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { 14657 separator = limit = undefined; 14658 } 14659 limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0; 14660 if (!limit) { 14661 return []; 14662 } 14663 string = toString(string); 14664 if (string && ( 14665 typeof separator == 'string' || 14666 (separator != null && !isRegExp(separator)) 14667 )) { 14668 separator = baseToString(separator); 14669 if (!separator && hasUnicode(string)) { 14670 return castSlice(stringToArray(string), 0, limit); 14671 } 14672 } 14673 return string.split(separator, limit); 14674 } 14675 14676 /** 14677 * Converts `string` to 14678 * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). 14679 * 14680 * @static 14681 * @memberOf _ 14682 * @since 3.1.0 14683 * @category String 14684 * @param {string} [string=''] The string to convert. 14685 * @returns {string} Returns the start cased string. 14686 * @example 14687 * 14688 * _.startCase('--foo-bar--'); 14689 * // => 'Foo Bar' 14690 * 14691 * _.startCase('fooBar'); 14692 * // => 'Foo Bar' 14693 * 14694 * _.startCase('__FOO_BAR__'); 14695 * // => 'FOO BAR' 14696 */ 14697 var startCase = createCompounder(function(result, word, index) { 14698 return result + (index ? ' ' : '') + upperFirst(word); 14699 }); 14700 14701 /** 14702 * Checks if `string` starts with the given target string. 14703 * 14704 * @static 14705 * @memberOf _ 14706 * @since 3.0.0 14707 * @category String 14708 * @param {string} [string=''] The string to inspect. 14709 * @param {string} [target] The string to search for. 14710 * @param {number} [position=0] The position to search from. 14711 * @returns {boolean} Returns `true` if `string` starts with `target`, 14712 * else `false`. 14713 * @example 14714 * 14715 * _.startsWith('abc', 'a'); 14716 * // => true 14717 * 14718 * _.startsWith('abc', 'b'); 14719 * // => false 14720 * 14721 * _.startsWith('abc', 'b', 1); 14722 * // => true 14723 */ 14724 function startsWith(string, target, position) { 14725 string = toString(string); 14726 position = position == null 14727 ? 0 14728 : baseClamp(toInteger(position), 0, string.length); 14729 14730 target = baseToString(target); 14731 return string.slice(position, position + target.length) == target; 14732 } 14733 14734 /** 14735 * Creates a compiled template function that can interpolate data properties 14736 * in "interpolate" delimiters, HTML-escape interpolated data properties in 14737 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data 14738 * properties may be accessed as free variables in the template. If a setting 14739 * object is given, it takes precedence over `_.templateSettings` values. 14740 * 14741 * **Note:** In the development build `_.template` utilizes 14742 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) 14743 * for easier debugging. 14744 * 14745 * For more information on precompiling templates see 14746 * [lodash's custom builds documentation](https://lodash.com/custom-builds). 14747 * 14748 * For more information on Chrome extension sandboxes see 14749 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). 14750 * 14751 * @static 14752 * @since 0.1.0 14753 * @memberOf _ 14754 * @category String 14755 * @param {string} [string=''] The template string. 14756 * @param {Object} [options={}] The options object. 14757 * @param {RegExp} [options.escape=_.templateSettings.escape] 14758 * The HTML "escape" delimiter. 14759 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] 14760 * The "evaluate" delimiter. 14761 * @param {Object} [options.imports=_.templateSettings.imports] 14762 * An object to import into the template as free variables. 14763 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] 14764 * The "interpolate" delimiter. 14765 * @param {string} [options.sourceURL='lodash.templateSources[n]'] 14766 * The sourceURL of the compiled template. 14767 * @param {string} [options.variable='obj'] 14768 * The data object variable name. 14769 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 14770 * @returns {Function} Returns the compiled template function. 14771 * @example 14772 * 14773 * // Use the "interpolate" delimiter to create a compiled template. 14774 * var compiled = _.template('hello <%= user %>!'); 14775 * compiled({ 'user': 'fred' }); 14776 * // => 'hello fred!' 14777 * 14778 * // Use the HTML "escape" delimiter to escape data property values. 14779 * var compiled = _.template('<b><%- value %></b>'); 14780 * compiled({ 'value': '<script>' }); 14781 * // => '<b><script></b>' 14782 * 14783 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML. 14784 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>'); 14785 * compiled({ 'users': ['fred', 'barney'] }); 14786 * // => '<li>fred</li><li>barney</li>' 14787 * 14788 * // Use the internal `print` function in "evaluate" delimiters. 14789 * var compiled = _.template('<% print("hello " + user); %>!'); 14790 * compiled({ 'user': 'barney' }); 14791 * // => 'hello barney!' 14792 * 14793 * // Use the ES template literal delimiter as an "interpolate" delimiter. 14794 * // Disable support by replacing the "interpolate" delimiter. 14795 * var compiled = _.template('hello ${ user }!'); 14796 * compiled({ 'user': 'pebbles' }); 14797 * // => 'hello pebbles!' 14798 * 14799 * // Use backslashes to treat delimiters as plain text. 14800 * var compiled = _.template('<%= "\\<%- value %\\>" %>'); 14801 * compiled({ 'value': 'ignored' }); 14802 * // => '<%- value %>' 14803 * 14804 * // Use the `imports` option to import `jQuery` as `jq`. 14805 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>'; 14806 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); 14807 * compiled({ 'users': ['fred', 'barney'] }); 14808 * // => '<li>fred</li><li>barney</li>' 14809 * 14810 * // Use the `sourceURL` option to specify a custom sourceURL for the template. 14811 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); 14812 * compiled(data); 14813 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector. 14814 * 14815 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template. 14816 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); 14817 * compiled.source; 14818 * // => function(data) { 14819 * // var __t, __p = ''; 14820 * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!'; 14821 * // return __p; 14822 * // } 14823 * 14824 * // Use custom template delimiters. 14825 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; 14826 * var compiled = _.template('hello {{ user }}!'); 14827 * compiled({ 'user': 'mustache' }); 14828 * // => 'hello mustache!' 14829 * 14830 * // Use the `source` property to inline compiled templates for meaningful 14831 * // line numbers in error messages and stack traces. 14832 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\ 14833 * var JST = {\ 14834 * "main": ' + _.template(mainText).source + '\ 14835 * };\ 14836 * '); 14837 */ 14838 function template(string, options, guard) { 14839 // Based on John Resig's `tmpl` implementation 14840 // (http://ejohn.org/blog/javascript-micro-templating/) 14841 // and Laura Doktorova's doT.js (https://github.com/olado/doT). 14842 var settings = lodash.templateSettings; 14843 14844 if (guard && isIterateeCall(string, options, guard)) { 14845 options = undefined; 14846 } 14847 string = toString(string); 14848 options = assignInWith({}, options, settings, customDefaultsAssignIn); 14849 14850 var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), 14851 importsKeys = keys(imports), 14852 importsValues = baseValues(imports, importsKeys); 14853 14854 var isEscaping, 14855 isEvaluating, 14856 index = 0, 14857 interpolate = options.interpolate || reNoMatch, 14858 source = "__p += '"; 14859 14860 // Compile the regexp to match each delimiter. 14861 var reDelimiters = RegExp( 14862 (options.escape || reNoMatch).source + '|' + 14863 interpolate.source + '|' + 14864 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + 14865 (options.evaluate || reNoMatch).source + '|$' 14866 , 'g'); 14867 14868 // Use a sourceURL for easier debugging. 14869 // The sourceURL gets injected into the source that's eval-ed, so be careful 14870 // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in 14871 // and escape the comment, thus injecting code that gets evaled. 14872 var sourceURL = '//# sourceURL=' + 14873 (hasOwnProperty.call(options, 'sourceURL') 14874 ? (options.sourceURL + '').replace(/\s/g, ' ') 14875 : ('lodash.templateSources[' + (++templateCounter) + ']') 14876 ) + '\n'; 14877 14878 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { 14879 interpolateValue || (interpolateValue = esTemplateValue); 14880 14881 // Escape characters that can't be included in string literals. 14882 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar); 14883 14884 // Replace delimiters with snippets. 14885 if (escapeValue) { 14886 isEscaping = true; 14887 source += "' +\n__e(" + escapeValue + ") +\n'"; 14888 } 14889 if (evaluateValue) { 14890 isEvaluating = true; 14891 source += "';\n" + evaluateValue + ";\n__p += '"; 14892 } 14893 if (interpolateValue) { 14894 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'"; 14895 } 14896 index = offset + match.length; 14897 14898 // The JS engine embedded in Adobe products needs `match` returned in 14899 // order to produce the correct `offset` value. 14900 return match; 14901 }); 14902 14903 source += "';\n"; 14904 14905 // If `variable` is not specified wrap a with-statement around the generated 14906 // code to add the data object to the top of the scope chain. 14907 var variable = hasOwnProperty.call(options, 'variable') && options.variable; 14908 if (!variable) { 14909 source = 'with (obj) {\n' + source + '\n}\n'; 14910 } 14911 // Throw an error if a forbidden character was found in `variable`, to prevent 14912 // potential command injection attacks. 14913 else if (reForbiddenIdentifierChars.test(variable)) { 14914 throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT); 14915 } 14916 14917 // Cleanup code by stripping empty strings. 14918 source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) 14919 .replace(reEmptyStringMiddle, '$1') 14920 .replace(reEmptyStringTrailing, '$1;'); 14921 14922 // Frame code as the function body. 14923 source = 'function(' + (variable || 'obj') + ') {\n' + 14924 (variable 14925 ? '' 14926 : 'obj || (obj = {});\n' 14927 ) + 14928 "var __t, __p = ''" + 14929 (isEscaping 14930 ? ', __e = _.escape' 14931 : '' 14932 ) + 14933 (isEvaluating 14934 ? ', __j = Array.prototype.join;\n' + 14935 "function print() { __p += __j.call(arguments, '') }\n" 14936 : ';\n' 14937 ) + 14938 source + 14939 'return __p\n}'; 14940 14941 var result = attempt(function() { 14942 return Function(importsKeys, sourceURL + 'return ' + source) 14943 .apply(undefined, importsValues); 14944 }); 14945 14946 // Provide the compiled function's source by its `toString` method or 14947 // the `source` property as a convenience for inlining compiled templates. 14948 result.source = source; 14949 if (isError(result)) { 14950 throw result; 14951 } 14952 return result; 14953 } 14954 14955 /** 14956 * Converts `string`, as a whole, to lower case just like 14957 * [String#toLowerCase](https://mdn.io/toLowerCase). 14958 * 14959 * @static 14960 * @memberOf _ 14961 * @since 4.0.0 14962 * @category String 14963 * @param {string} [string=''] The string to convert. 14964 * @returns {string} Returns the lower cased string. 14965 * @example 14966 * 14967 * _.toLower('--Foo-Bar--'); 14968 * // => '--foo-bar--' 14969 * 14970 * _.toLower('fooBar'); 14971 * // => 'foobar' 14972 * 14973 * _.toLower('__FOO_BAR__'); 14974 * // => '__foo_bar__' 14975 */ 14976 function toLower(value) { 14977 return toString(value).toLowerCase(); 14978 } 14979 14980 /** 14981 * Converts `string`, as a whole, to upper case just like 14982 * [String#toUpperCase](https://mdn.io/toUpperCase). 14983 * 14984 * @static 14985 * @memberOf _ 14986 * @since 4.0.0 14987 * @category String 14988 * @param {string} [string=''] The string to convert. 14989 * @returns {string} Returns the upper cased string. 14990 * @example 14991 * 14992 * _.toUpper('--foo-bar--'); 14993 * // => '--FOO-BAR--' 14994 * 14995 * _.toUpper('fooBar'); 14996 * // => 'FOOBAR' 14997 * 14998 * _.toUpper('__foo_bar__'); 14999 * // => '__FOO_BAR__' 15000 */ 15001 function toUpper(value) { 15002 return toString(value).toUpperCase(); 15003 } 15004 15005 /** 15006 * Removes leading and trailing whitespace or specified characters from `string`. 15007 * 15008 * @static 15009 * @memberOf _ 15010 * @since 3.0.0 15011 * @category String 15012 * @param {string} [string=''] The string to trim. 15013 * @param {string} [chars=whitespace] The characters to trim. 15014 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 15015 * @returns {string} Returns the trimmed string. 15016 * @example 15017 * 15018 * _.trim(' abc '); 15019 * // => 'abc' 15020 * 15021 * _.trim('-_-abc-_-', '_-'); 15022 * // => 'abc' 15023 * 15024 * _.map([' foo ', ' bar '], _.trim); 15025 * // => ['foo', 'bar'] 15026 */ 15027 function trim(string, chars, guard) { 15028 string = toString(string); 15029 if (string && (guard || chars === undefined)) { 15030 return baseTrim(string); 15031 } 15032 if (!string || !(chars = baseToString(chars))) { 15033 return string; 15034 } 15035 var strSymbols = stringToArray(string), 15036 chrSymbols = stringToArray(chars), 15037 start = charsStartIndex(strSymbols, chrSymbols), 15038 end = charsEndIndex(strSymbols, chrSymbols) + 1; 15039 15040 return castSlice(strSymbols, start, end).join(''); 15041 } 15042 15043 /** 15044 * Removes trailing whitespace or specified characters from `string`. 15045 * 15046 * @static 15047 * @memberOf _ 15048 * @since 4.0.0 15049 * @category String 15050 * @param {string} [string=''] The string to trim. 15051 * @param {string} [chars=whitespace] The characters to trim. 15052 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 15053 * @returns {string} Returns the trimmed string. 15054 * @example 15055 * 15056 * _.trimEnd(' abc '); 15057 * // => ' abc' 15058 * 15059 * _.trimEnd('-_-abc-_-', '_-'); 15060 * // => '-_-abc' 15061 */ 15062 function trimEnd(string, chars, guard) { 15063 string = toString(string); 15064 if (string && (guard || chars === undefined)) { 15065 return string.slice(0, trimmedEndIndex(string) + 1); 15066 } 15067 if (!string || !(chars = baseToString(chars))) { 15068 return string; 15069 } 15070 var strSymbols = stringToArray(string), 15071 end = charsEndIndex(strSymbols, stringToArray(chars)) + 1; 15072 15073 return castSlice(strSymbols, 0, end).join(''); 15074 } 15075 15076 /** 15077 * Removes leading whitespace or specified characters from `string`. 15078 * 15079 * @static 15080 * @memberOf _ 15081 * @since 4.0.0 15082 * @category String 15083 * @param {string} [string=''] The string to trim. 15084 * @param {string} [chars=whitespace] The characters to trim. 15085 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 15086 * @returns {string} Returns the trimmed string. 15087 * @example 15088 * 15089 * _.trimStart(' abc '); 15090 * // => 'abc ' 15091 * 15092 * _.trimStart('-_-abc-_-', '_-'); 15093 * // => 'abc-_-' 15094 */ 15095 function trimStart(string, chars, guard) { 15096 string = toString(string); 15097 if (string && (guard || chars === undefined)) { 15098 return string.replace(reTrimStart, ''); 15099 } 15100 if (!string || !(chars = baseToString(chars))) { 15101 return string; 15102 } 15103 var strSymbols = stringToArray(string), 15104 start = charsStartIndex(strSymbols, stringToArray(chars)); 15105 15106 return castSlice(strSymbols, start).join(''); 15107 } 15108 15109 /** 15110 * Truncates `string` if it's longer than the given maximum string length. 15111 * The last characters of the truncated string are replaced with the omission 15112 * string which defaults to "...". 15113 * 15114 * @static 15115 * @memberOf _ 15116 * @since 4.0.0 15117 * @category String 15118 * @param {string} [string=''] The string to truncate. 15119 * @param {Object} [options={}] The options object. 15120 * @param {number} [options.length=30] The maximum string length. 15121 * @param {string} [options.omission='...'] The string to indicate text is omitted. 15122 * @param {RegExp|string} [options.separator] The separator pattern to truncate to. 15123 * @returns {string} Returns the truncated string. 15124 * @example 15125 * 15126 * _.truncate('hi-diddly-ho there, neighborino'); 15127 * // => 'hi-diddly-ho there, neighbo...' 15128 * 15129 * _.truncate('hi-diddly-ho there, neighborino', { 15130 * 'length': 24, 15131 * 'separator': ' ' 15132 * }); 15133 * // => 'hi-diddly-ho there,...' 15134 * 15135 * _.truncate('hi-diddly-ho there, neighborino', { 15136 * 'length': 24, 15137 * 'separator': /,? +/ 15138 * }); 15139 * // => 'hi-diddly-ho there...' 15140 * 15141 * _.truncate('hi-diddly-ho there, neighborino', { 15142 * 'omission': ' [...]' 15143 * }); 15144 * // => 'hi-diddly-ho there, neig [...]' 15145 */ 15146 function truncate(string, options) { 15147 var length = DEFAULT_TRUNC_LENGTH, 15148 omission = DEFAULT_TRUNC_OMISSION; 15149 15150 if (isObject(options)) { 15151 var separator = 'separator' in options ? options.separator : separator; 15152 length = 'length' in options ? toInteger(options.length) : length; 15153 omission = 'omission' in options ? baseToString(options.omission) : omission; 15154 } 15155 string = toString(string); 15156 15157 var strLength = string.length; 15158 if (hasUnicode(string)) { 15159 var strSymbols = stringToArray(string); 15160 strLength = strSymbols.length; 15161 } 15162 if (length >= strLength) { 15163 return string; 15164 } 15165 var end = length - stringSize(omission); 15166 if (end < 1) { 15167 return omission; 15168 } 15169 var result = strSymbols 15170 ? castSlice(strSymbols, 0, end).join('') 15171 : string.slice(0, end); 15172 15173 if (separator === undefined) { 15174 return result + omission; 15175 } 15176 if (strSymbols) { 15177 end += (result.length - end); 15178 } 15179 if (isRegExp(separator)) { 15180 if (string.slice(end).search(separator)) { 15181 var match, 15182 substring = result; 15183 15184 if (!separator.global) { 15185 separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g'); 15186 } 15187 separator.lastIndex = 0; 15188 while ((match = separator.exec(substring))) { 15189 var newEnd = match.index; 15190 } 15191 result = result.slice(0, newEnd === undefined ? end : newEnd); 15192 } 15193 } else if (string.indexOf(baseToString(separator), end) != end) { 15194 var index = result.lastIndexOf(separator); 15195 if (index > -1) { 15196 result = result.slice(0, index); 15197 } 15198 } 15199 return result + omission; 15200 } 15201 15202 /** 15203 * The inverse of `_.escape`; this method converts the HTML entities 15204 * `&`, `<`, `>`, `"`, and `'` in `string` to 15205 * their corresponding characters. 15206 * 15207 * **Note:** No other HTML entities are unescaped. To unescape additional 15208 * HTML entities use a third-party library like [_he_](https://mths.be/he). 15209 * 15210 * @static 15211 * @memberOf _ 15212 * @since 0.6.0 15213 * @category String 15214 * @param {string} [string=''] The string to unescape. 15215 * @returns {string} Returns the unescaped string. 15216 * @example 15217 * 15218 * _.unescape('fred, barney, & pebbles'); 15219 * // => 'fred, barney, & pebbles' 15220 */ 15221 function unescape(string) { 15222 string = toString(string); 15223 return (string && reHasEscapedHtml.test(string)) 15224 ? string.replace(reEscapedHtml, unescapeHtmlChar) 15225 : string; 15226 } 15227 15228 /** 15229 * Converts `string`, as space separated words, to upper case. 15230 * 15231 * @static 15232 * @memberOf _ 15233 * @since 4.0.0 15234 * @category String 15235 * @param {string} [string=''] The string to convert. 15236 * @returns {string} Returns the upper cased string. 15237 * @example 15238 * 15239 * _.upperCase('--foo-bar'); 15240 * // => 'FOO BAR' 15241 * 15242 * _.upperCase('fooBar'); 15243 * // => 'FOO BAR' 15244 * 15245 * _.upperCase('__foo_bar__'); 15246 * // => 'FOO BAR' 15247 */ 15248 var upperCase = createCompounder(function(result, word, index) { 15249 return result + (index ? ' ' : '') + word.toUpperCase(); 15250 }); 15251 15252 /** 15253 * Converts the first character of `string` to upper case. 15254 * 15255 * @static 15256 * @memberOf _ 15257 * @since 4.0.0 15258 * @category String 15259 * @param {string} [string=''] The string to convert. 15260 * @returns {string} Returns the converted string. 15261 * @example 15262 * 15263 * _.upperFirst('fred'); 15264 * // => 'Fred' 15265 * 15266 * _.upperFirst('FRED'); 15267 * // => 'FRED' 15268 */ 15269 var upperFirst = createCaseFirst('toUpperCase'); 15270 15271 /** 15272 * Splits `string` into an array of its words. 15273 * 15274 * @static 15275 * @memberOf _ 15276 * @since 3.0.0 15277 * @category String 15278 * @param {string} [string=''] The string to inspect. 15279 * @param {RegExp|string} [pattern] The pattern to match words. 15280 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. 15281 * @returns {Array} Returns the words of `string`. 15282 * @example 15283 * 15284 * _.words('fred, barney, & pebbles'); 15285 * // => ['fred', 'barney', 'pebbles'] 15286 * 15287 * _.words('fred, barney, & pebbles', /[^, ]+/g); 15288 * // => ['fred', 'barney', '&', 'pebbles'] 15289 */ 15290 function words(string, pattern, guard) { 15291 string = toString(string); 15292 pattern = guard ? undefined : pattern; 15293 15294 if (pattern === undefined) { 15295 return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string); 15296 } 15297 return string.match(pattern) || []; 15298 } 15299 15300 /*------------------------------------------------------------------------*/ 15301 15302 /** 15303 * Attempts to invoke `func`, returning either the result or the caught error 15304 * object. Any additional arguments are provided to `func` when it's invoked. 15305 * 15306 * @static 15307 * @memberOf _ 15308 * @since 3.0.0 15309 * @category Util 15310 * @param {Function} func The function to attempt. 15311 * @param {...*} [args] The arguments to invoke `func` with. 15312 * @returns {*} Returns the `func` result or error object. 15313 * @example 15314 * 15315 * // Avoid throwing errors for invalid selectors. 15316 * var elements = _.attempt(function(selector) { 15317 * return document.querySelectorAll(selector); 15318 * }, '>_>'); 15319 * 15320 * if (_.isError(elements)) { 15321 * elements = []; 15322 * } 15323 */ 15324 var attempt = baseRest(function(func, args) { 15325 try { 15326 return apply(func, undefined, args); 15327 } catch (e) { 15328 return isError(e) ? e : new Error(e); 15329 } 15330 }); 15331 15332 /** 15333 * Binds methods of an object to the object itself, overwriting the existing 15334 * method. 15335 * 15336 * **Note:** This method doesn't set the "length" property of bound functions. 15337 * 15338 * @static 15339 * @since 0.1.0 15340 * @memberOf _ 15341 * @category Util 15342 * @param {Object} object The object to bind and assign the bound methods to. 15343 * @param {...(string|string[])} methodNames The object method names to bind. 15344 * @returns {Object} Returns `object`. 15345 * @example 15346 * 15347 * var view = { 15348 * 'label': 'docs', 15349 * 'click': function() { 15350 * console.log('clicked ' + this.label); 15351 * } 15352 * }; 15353 * 15354 * _.bindAll(view, ['click']); 15355 * jQuery(element).on('click', view.click); 15356 * // => Logs 'clicked docs' when clicked. 15357 */ 15358 var bindAll = flatRest(function(object, methodNames) { 15359 arrayEach(methodNames, function(key) { 15360 key = toKey(key); 15361 baseAssignValue(object, key, bind(object[key], object)); 15362 }); 15363 return object; 15364 }); 15365 15366 /** 15367 * Creates a function that iterates over `pairs` and invokes the corresponding 15368 * function of the first predicate to return truthy. The predicate-function 15369 * pairs are invoked with the `this` binding and arguments of the created 15370 * function. 15371 * 15372 * @static 15373 * @memberOf _ 15374 * @since 4.0.0 15375 * @category Util 15376 * @param {Array} pairs The predicate-function pairs. 15377 * @returns {Function} Returns the new composite function. 15378 * @example 15379 * 15380 * var func = _.cond([ 15381 * [_.matches({ 'a': 1 }), _.constant('matches A')], 15382 * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')], 15383 * [_.stubTrue, _.constant('no match')] 15384 * ]); 15385 * 15386 * func({ 'a': 1, 'b': 2 }); 15387 * // => 'matches A' 15388 * 15389 * func({ 'a': 0, 'b': 1 }); 15390 * // => 'matches B' 15391 * 15392 * func({ 'a': '1', 'b': '2' }); 15393 * // => 'no match' 15394 */ 15395 function cond(pairs) { 15396 var length = pairs == null ? 0 : pairs.length, 15397 toIteratee = getIteratee(); 15398 15399 pairs = !length ? [] : arrayMap(pairs, function(pair) { 15400 if (typeof pair[1] != 'function') { 15401 throw new TypeError(FUNC_ERROR_TEXT); 15402 } 15403 return [toIteratee(pair[0]), pair[1]]; 15404 }); 15405 15406 return baseRest(function(args) { 15407 var index = -1; 15408 while (++index < length) { 15409 var pair = pairs[index]; 15410 if (apply(pair[0], this, args)) { 15411 return apply(pair[1], this, args); 15412 } 15413 } 15414 }); 15415 } 15416 15417 /** 15418 * Creates a function that invokes the predicate properties of `source` with 15419 * the corresponding property values of a given object, returning `true` if 15420 * all predicates return truthy, else `false`. 15421 * 15422 * **Note:** The created function is equivalent to `_.conformsTo` with 15423 * `source` partially applied. 15424 * 15425 * @static 15426 * @memberOf _ 15427 * @since 4.0.0 15428 * @category Util 15429 * @param {Object} source The object of property predicates to conform to. 15430 * @returns {Function} Returns the new spec function. 15431 * @example 15432 * 15433 * var objects = [ 15434 * { 'a': 2, 'b': 1 }, 15435 * { 'a': 1, 'b': 2 } 15436 * ]; 15437 * 15438 * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } })); 15439 * // => [{ 'a': 1, 'b': 2 }] 15440 */ 15441 function conforms(source) { 15442 return baseConforms(baseClone(source, CLONE_DEEP_FLAG)); 15443 } 15444 15445 /** 15446 * Creates a function that returns `value`. 15447 * 15448 * @static 15449 * @memberOf _ 15450 * @since 2.4.0 15451 * @category Util 15452 * @param {*} value The value to return from the new function. 15453 * @returns {Function} Returns the new constant function. 15454 * @example 15455 * 15456 * var objects = _.times(2, _.constant({ 'a': 1 })); 15457 * 15458 * console.log(objects); 15459 * // => [{ 'a': 1 }, { 'a': 1 }] 15460 * 15461 * console.log(objects[0] === objects[1]); 15462 * // => true 15463 */ 15464 function constant(value) { 15465 return function() { 15466 return value; 15467 }; 15468 } 15469 15470 /** 15471 * Checks `value` to determine whether a default value should be returned in 15472 * its place. The `defaultValue` is returned if `value` is `NaN`, `null`, 15473 * or `undefined`. 15474 * 15475 * @static 15476 * @memberOf _ 15477 * @since 4.14.0 15478 * @category Util 15479 * @param {*} value The value to check. 15480 * @param {*} defaultValue The default value. 15481 * @returns {*} Returns the resolved value. 15482 * @example 15483 * 15484 * _.defaultTo(1, 10); 15485 * // => 1 15486 * 15487 * _.defaultTo(undefined, 10); 15488 * // => 10 15489 */ 15490 function defaultTo(value, defaultValue) { 15491 return (value == null || value !== value) ? defaultValue : value; 15492 } 15493 15494 /** 15495 * Creates a function that returns the result of invoking the given functions 15496 * with the `this` binding of the created function, where each successive 15497 * invocation is supplied the return value of the previous. 15498 * 15499 * @static 15500 * @memberOf _ 15501 * @since 3.0.0 15502 * @category Util 15503 * @param {...(Function|Function[])} [funcs] The functions to invoke. 15504 * @returns {Function} Returns the new composite function. 15505 * @see _.flowRight 15506 * @example 15507 * 15508 * function square(n) { 15509 * return n * n; 15510 * } 15511 * 15512 * var addSquare = _.flow([_.add, square]); 15513 * addSquare(1, 2); 15514 * // => 9 15515 */ 15516 var flow = createFlow(); 15517 15518 /** 15519 * This method is like `_.flow` except that it creates a function that 15520 * invokes the given functions from right to left. 15521 * 15522 * @static 15523 * @since 3.0.0 15524 * @memberOf _ 15525 * @category Util 15526 * @param {...(Function|Function[])} [funcs] The functions to invoke. 15527 * @returns {Function} Returns the new composite function. 15528 * @see _.flow 15529 * @example 15530 * 15531 * function square(n) { 15532 * return n * n; 15533 * } 15534 * 15535 * var addSquare = _.flowRight([square, _.add]); 15536 * addSquare(1, 2); 15537 * // => 9 15538 */ 15539 var flowRight = createFlow(true); 15540 15541 /** 15542 * This method returns the first argument it receives. 15543 * 15544 * @static 15545 * @since 0.1.0 15546 * @memberOf _ 15547 * @category Util 15548 * @param {*} value Any value. 15549 * @returns {*} Returns `value`. 15550 * @example 15551 * 15552 * var object = { 'a': 1 }; 15553 * 15554 * console.log(_.identity(object) === object); 15555 * // => true 15556 */ 15557 function identity(value) { 15558 return value; 15559 } 15560 15561 /** 15562 * Creates a function that invokes `func` with the arguments of the created 15563 * function. If `func` is a property name, the created function returns the 15564 * property value for a given element. If `func` is an array or object, the 15565 * created function returns `true` for elements that contain the equivalent 15566 * source properties, otherwise it returns `false`. 15567 * 15568 * @static 15569 * @since 4.0.0 15570 * @memberOf _ 15571 * @category Util 15572 * @param {*} [func=_.identity] The value to convert to a callback. 15573 * @returns {Function} Returns the callback. 15574 * @example 15575 * 15576 * var users = [ 15577 * { 'user': 'barney', 'age': 36, 'active': true }, 15578 * { 'user': 'fred', 'age': 40, 'active': false } 15579 * ]; 15580 * 15581 * // The `_.matches` iteratee shorthand. 15582 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true })); 15583 * // => [{ 'user': 'barney', 'age': 36, 'active': true }] 15584 * 15585 * // The `_.matchesProperty` iteratee shorthand. 15586 * _.filter(users, _.iteratee(['user', 'fred'])); 15587 * // => [{ 'user': 'fred', 'age': 40 }] 15588 * 15589 * // The `_.property` iteratee shorthand. 15590 * _.map(users, _.iteratee('user')); 15591 * // => ['barney', 'fred'] 15592 * 15593 * // Create custom iteratee shorthands. 15594 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) { 15595 * return !_.isRegExp(func) ? iteratee(func) : function(string) { 15596 * return func.test(string); 15597 * }; 15598 * }); 15599 * 15600 * _.filter(['abc', 'def'], /ef/); 15601 * // => ['def'] 15602 */ 15603 function iteratee(func) { 15604 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG)); 15605 } 15606 15607 /** 15608 * Creates a function that performs a partial deep comparison between a given 15609 * object and `source`, returning `true` if the given object has equivalent 15610 * property values, else `false`. 15611 * 15612 * **Note:** The created function is equivalent to `_.isMatch` with `source` 15613 * partially applied. 15614 * 15615 * Partial comparisons will match empty array and empty object `source` 15616 * values against any array or object value, respectively. See `_.isEqual` 15617 * for a list of supported value comparisons. 15618 * 15619 * **Note:** Multiple values can be checked by combining several matchers 15620 * using `_.overSome` 15621 * 15622 * @static 15623 * @memberOf _ 15624 * @since 3.0.0 15625 * @category Util 15626 * @param {Object} source The object of property values to match. 15627 * @returns {Function} Returns the new spec function. 15628 * @example 15629 * 15630 * var objects = [ 15631 * { 'a': 1, 'b': 2, 'c': 3 }, 15632 * { 'a': 4, 'b': 5, 'c': 6 } 15633 * ]; 15634 * 15635 * _.filter(objects, _.matches({ 'a': 4, 'c': 6 })); 15636 * // => [{ 'a': 4, 'b': 5, 'c': 6 }] 15637 * 15638 * // Checking for several possible values 15639 * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })])); 15640 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }] 15641 */ 15642 function matches(source) { 15643 return baseMatches(baseClone(source, CLONE_DEEP_FLAG)); 15644 } 15645 15646 /** 15647 * Creates a function that performs a partial deep comparison between the 15648 * value at `path` of a given object to `srcValue`, returning `true` if the 15649 * object value is equivalent, else `false`. 15650 * 15651 * **Note:** Partial comparisons will match empty array and empty object 15652 * `srcValue` values against any array or object value, respectively. See 15653 * `_.isEqual` for a list of supported value comparisons. 15654 * 15655 * **Note:** Multiple values can be checked by combining several matchers 15656 * using `_.overSome` 15657 * 15658 * @static 15659 * @memberOf _ 15660 * @since 3.2.0 15661 * @category Util 15662 * @param {Array|string} path The path of the property to get. 15663 * @param {*} srcValue The value to match. 15664 * @returns {Function} Returns the new spec function. 15665 * @example 15666 * 15667 * var objects = [ 15668 * { 'a': 1, 'b': 2, 'c': 3 }, 15669 * { 'a': 4, 'b': 5, 'c': 6 } 15670 * ]; 15671 * 15672 * _.find(objects, _.matchesProperty('a', 4)); 15673 * // => { 'a': 4, 'b': 5, 'c': 6 } 15674 * 15675 * // Checking for several possible values 15676 * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)])); 15677 * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }] 15678 */ 15679 function matchesProperty(path, srcValue) { 15680 return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG)); 15681 } 15682 15683 /** 15684 * Creates a function that invokes the method at `path` of a given object. 15685 * Any additional arguments are provided to the invoked method. 15686 * 15687 * @static 15688 * @memberOf _ 15689 * @since 3.7.0 15690 * @category Util 15691 * @param {Array|string} path The path of the method to invoke. 15692 * @param {...*} [args] The arguments to invoke the method with. 15693 * @returns {Function} Returns the new invoker function. 15694 * @example 15695 * 15696 * var objects = [ 15697 * { 'a': { 'b': _.constant(2) } }, 15698 * { 'a': { 'b': _.constant(1) } } 15699 * ]; 15700 * 15701 * _.map(objects, _.method('a.b')); 15702 * // => [2, 1] 15703 * 15704 * _.map(objects, _.method(['a', 'b'])); 15705 * // => [2, 1] 15706 */ 15707 var method = baseRest(function(path, args) { 15708 return function(object) { 15709 return baseInvoke(object, path, args); 15710 }; 15711 }); 15712 15713 /** 15714 * The opposite of `_.method`; this method creates a function that invokes 15715 * the method at a given path of `object`. Any additional arguments are 15716 * provided to the invoked method. 15717 * 15718 * @static 15719 * @memberOf _ 15720 * @since 3.7.0 15721 * @category Util 15722 * @param {Object} object The object to query. 15723 * @param {...*} [args] The arguments to invoke the method with. 15724 * @returns {Function} Returns the new invoker function. 15725 * @example 15726 * 15727 * var array = _.times(3, _.constant), 15728 * object = { 'a': array, 'b': array, 'c': array }; 15729 * 15730 * _.map(['a[2]', 'c[0]'], _.methodOf(object)); 15731 * // => [2, 0] 15732 * 15733 * _.map([['a', '2'], ['c', '0']], _.methodOf(object)); 15734 * // => [2, 0] 15735 */ 15736 var methodOf = baseRest(function(object, args) { 15737 return function(path) { 15738 return baseInvoke(object, path, args); 15739 }; 15740 }); 15741 15742 /** 15743 * Adds all own enumerable string keyed function properties of a source 15744 * object to the destination object. If `object` is a function, then methods 15745 * are added to its prototype as well. 15746 * 15747 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to 15748 * avoid conflicts caused by modifying the original. 15749 * 15750 * @static 15751 * @since 0.1.0 15752 * @memberOf _ 15753 * @category Util 15754 * @param {Function|Object} [object=lodash] The destination object. 15755 * @param {Object} source The object of functions to add. 15756 * @param {Object} [options={}] The options object. 15757 * @param {boolean} [options.chain=true] Specify whether mixins are chainable. 15758 * @returns {Function|Object} Returns `object`. 15759 * @example 15760 * 15761 * function vowels(string) { 15762 * return _.filter(string, function(v) { 15763 * return /[aeiou]/i.test(v); 15764 * }); 15765 * } 15766 * 15767 * _.mixin({ 'vowels': vowels }); 15768 * _.vowels('fred'); 15769 * // => ['e'] 15770 * 15771 * _('fred').vowels().value(); 15772 * // => ['e'] 15773 * 15774 * _.mixin({ 'vowels': vowels }, { 'chain': false }); 15775 * _('fred').vowels(); 15776 * // => ['e'] 15777 */ 15778 function mixin(object, source, options) { 15779 var props = keys(source), 15780 methodNames = baseFunctions(source, props); 15781 15782 if (options == null && 15783 !(isObject(source) && (methodNames.length || !props.length))) { 15784 options = source; 15785 source = object; 15786 object = this; 15787 methodNames = baseFunctions(source, keys(source)); 15788 } 15789 var chain = !(isObject(options) && 'chain' in options) || !!options.chain, 15790 isFunc = isFunction(object); 15791 15792 arrayEach(methodNames, function(methodName) { 15793 var func = source[methodName]; 15794 object[methodName] = func; 15795 if (isFunc) { 15796 object.prototype[methodName] = function() { 15797 var chainAll = this.__chain__; 15798 if (chain || chainAll) { 15799 var result = object(this.__wrapped__), 15800 actions = result.__actions__ = copyArray(this.__actions__); 15801 15802 actions.push({ 'func': func, 'args': arguments, 'thisArg': object }); 15803 result.__chain__ = chainAll; 15804 return result; 15805 } 15806 return func.apply(object, arrayPush([this.value()], arguments)); 15807 }; 15808 } 15809 }); 15810 15811 return object; 15812 } 15813 15814 /** 15815 * Reverts the `_` variable to its previous value and returns a reference to 15816 * the `lodash` function. 15817 * 15818 * @static 15819 * @since 0.1.0 15820 * @memberOf _ 15821 * @category Util 15822 * @returns {Function} Returns the `lodash` function. 15823 * @example 15824 * 15825 * var lodash = _.noConflict(); 15826 */ 15827 function noConflict() { 15828 if (root._ === this) { 15829 root._ = oldDash; 15830 } 15831 return this; 15832 } 15833 15834 /** 15835 * This method returns `undefined`. 15836 * 15837 * @static 15838 * @memberOf _ 15839 * @since 2.3.0 15840 * @category Util 15841 * @example 15842 * 15843 * _.times(2, _.noop); 15844 * // => [undefined, undefined] 15845 */ 15846 function noop() { 15847 // No operation performed. 15848 } 15849 15850 /** 15851 * Creates a function that gets the argument at index `n`. If `n` is negative, 15852 * the nth argument from the end is returned. 15853 * 15854 * @static 15855 * @memberOf _ 15856 * @since 4.0.0 15857 * @category Util 15858 * @param {number} [n=0] The index of the argument to return. 15859 * @returns {Function} Returns the new pass-thru function. 15860 * @example 15861 * 15862 * var func = _.nthArg(1); 15863 * func('a', 'b', 'c', 'd'); 15864 * // => 'b' 15865 * 15866 * var func = _.nthArg(-2); 15867 * func('a', 'b', 'c', 'd'); 15868 * // => 'c' 15869 */ 15870 function nthArg(n) { 15871 n = toInteger(n); 15872 return baseRest(function(args) { 15873 return baseNth(args, n); 15874 }); 15875 } 15876 15877 /** 15878 * Creates a function that invokes `iteratees` with the arguments it receives 15879 * and returns their results. 15880 * 15881 * @static 15882 * @memberOf _ 15883 * @since 4.0.0 15884 * @category Util 15885 * @param {...(Function|Function[])} [iteratees=[_.identity]] 15886 * The iteratees to invoke. 15887 * @returns {Function} Returns the new function. 15888 * @example 15889 * 15890 * var func = _.over([Math.max, Math.min]); 15891 * 15892 * func(1, 2, 3, 4); 15893 * // => [4, 1] 15894 */ 15895 var over = createOver(arrayMap); 15896 15897 /** 15898 * Creates a function that checks if **all** of the `predicates` return 15899 * truthy when invoked with the arguments it receives. 15900 * 15901 * Following shorthands are possible for providing predicates. 15902 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate. 15903 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them. 15904 * 15905 * @static 15906 * @memberOf _ 15907 * @since 4.0.0 15908 * @category Util 15909 * @param {...(Function|Function[])} [predicates=[_.identity]] 15910 * The predicates to check. 15911 * @returns {Function} Returns the new function. 15912 * @example 15913 * 15914 * var func = _.overEvery([Boolean, isFinite]); 15915 * 15916 * func('1'); 15917 * // => true 15918 * 15919 * func(null); 15920 * // => false 15921 * 15922 * func(NaN); 15923 * // => false 15924 */ 15925 var overEvery = createOver(arrayEvery); 15926 15927 /** 15928 * Creates a function that checks if **any** of the `predicates` return 15929 * truthy when invoked with the arguments it receives. 15930 * 15931 * Following shorthands are possible for providing predicates. 15932 * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate. 15933 * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them. 15934 * 15935 * @static 15936 * @memberOf _ 15937 * @since 4.0.0 15938 * @category Util 15939 * @param {...(Function|Function[])} [predicates=[_.identity]] 15940 * The predicates to check. 15941 * @returns {Function} Returns the new function. 15942 * @example 15943 * 15944 * var func = _.overSome([Boolean, isFinite]); 15945 * 15946 * func('1'); 15947 * // => true 15948 * 15949 * func(null); 15950 * // => true 15951 * 15952 * func(NaN); 15953 * // => false 15954 * 15955 * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }]) 15956 * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]]) 15957 */ 15958 var overSome = createOver(arraySome); 15959 15960 /** 15961 * Creates a function that returns the value at `path` of a given object. 15962 * 15963 * @static 15964 * @memberOf _ 15965 * @since 2.4.0 15966 * @category Util 15967 * @param {Array|string} path The path of the property to get. 15968 * @returns {Function} Returns the new accessor function. 15969 * @example 15970 * 15971 * var objects = [ 15972 * { 'a': { 'b': 2 } }, 15973 * { 'a': { 'b': 1 } } 15974 * ]; 15975 * 15976 * _.map(objects, _.property('a.b')); 15977 * // => [2, 1] 15978 * 15979 * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b'); 15980 * // => [1, 2] 15981 */ 15982 function property(path) { 15983 return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path); 15984 } 15985 15986 /** 15987 * The opposite of `_.property`; this method creates a function that returns 15988 * the value at a given path of `object`. 15989 * 15990 * @static 15991 * @memberOf _ 15992 * @since 3.0.0 15993 * @category Util 15994 * @param {Object} object The object to query. 15995 * @returns {Function} Returns the new accessor function. 15996 * @example 15997 * 15998 * var array = [0, 1, 2], 15999 * object = { 'a': array, 'b': array, 'c': array }; 16000 * 16001 * _.map(['a[2]', 'c[0]'], _.propertyOf(object)); 16002 * // => [2, 0] 16003 * 16004 * _.map([['a', '2'], ['c', '0']], _.propertyOf(object)); 16005 * // => [2, 0] 16006 */ 16007 function propertyOf(object) { 16008 return function(path) { 16009 return object == null ? undefined : baseGet(object, path); 16010 }; 16011 } 16012 16013 /** 16014 * Creates an array of numbers (positive and/or negative) progressing from 16015 * `start` up to, but not including, `end`. A step of `-1` is used if a negative 16016 * `start` is specified without an `end` or `step`. If `end` is not specified, 16017 * it's set to `start` with `start` then set to `0`. 16018 * 16019 * **Note:** JavaScript follows the IEEE-754 standard for resolving 16020 * floating-point values which can produce unexpected results. 16021 * 16022 * @static 16023 * @since 0.1.0 16024 * @memberOf _ 16025 * @category Util 16026 * @param {number} [start=0] The start of the range. 16027 * @param {number} end The end of the range. 16028 * @param {number} [step=1] The value to increment or decrement by. 16029 * @returns {Array} Returns the range of numbers. 16030 * @see _.inRange, _.rangeRight 16031 * @example 16032 * 16033 * _.range(4); 16034 * // => [0, 1, 2, 3] 16035 * 16036 * _.range(-4); 16037 * // => [0, -1, -2, -3] 16038 * 16039 * _.range(1, 5); 16040 * // => [1, 2, 3, 4] 16041 * 16042 * _.range(0, 20, 5); 16043 * // => [0, 5, 10, 15] 16044 * 16045 * _.range(0, -4, -1); 16046 * // => [0, -1, -2, -3] 16047 * 16048 * _.range(1, 4, 0); 16049 * // => [1, 1, 1] 16050 * 16051 * _.range(0); 16052 * // => [] 16053 */ 16054 var range = createRange(); 16055 16056 /** 16057 * This method is like `_.range` except that it populates values in 16058 * descending order. 16059 * 16060 * @static 16061 * @memberOf _ 16062 * @since 4.0.0 16063 * @category Util 16064 * @param {number} [start=0] The start of the range. 16065 * @param {number} end The end of the range. 16066 * @param {number} [step=1] The value to increment or decrement by. 16067 * @returns {Array} Returns the range of numbers. 16068 * @see _.inRange, _.range 16069 * @example 16070 * 16071 * _.rangeRight(4); 16072 * // => [3, 2, 1, 0] 16073 * 16074 * _.rangeRight(-4); 16075 * // => [-3, -2, -1, 0] 16076 * 16077 * _.rangeRight(1, 5); 16078 * // => [4, 3, 2, 1] 16079 * 16080 * _.rangeRight(0, 20, 5); 16081 * // => [15, 10, 5, 0] 16082 * 16083 * _.rangeRight(0, -4, -1); 16084 * // => [-3, -2, -1, 0] 16085 * 16086 * _.rangeRight(1, 4, 0); 16087 * // => [1, 1, 1] 16088 * 16089 * _.rangeRight(0); 16090 * // => [] 16091 */ 16092 var rangeRight = createRange(true); 16093 16094 /** 16095 * This method returns a new empty array. 16096 * 16097 * @static 16098 * @memberOf _ 16099 * @since 4.13.0 16100 * @category Util 16101 * @returns {Array} Returns the new empty array. 16102 * @example 16103 * 16104 * var arrays = _.times(2, _.stubArray); 16105 * 16106 * console.log(arrays); 16107 * // => [[], []] 16108 * 16109 * console.log(arrays[0] === arrays[1]); 16110 * // => false 16111 */ 16112 function stubArray() { 16113 return []; 16114 } 16115 16116 /** 16117 * This method returns `false`. 16118 * 16119 * @static 16120 * @memberOf _ 16121 * @since 4.13.0 16122 * @category Util 16123 * @returns {boolean} Returns `false`. 16124 * @example 16125 * 16126 * _.times(2, _.stubFalse); 16127 * // => [false, false] 16128 */ 16129 function stubFalse() { 16130 return false; 16131 } 16132 16133 /** 16134 * This method returns a new empty object. 16135 * 16136 * @static 16137 * @memberOf _ 16138 * @since 4.13.0 16139 * @category Util 16140 * @returns {Object} Returns the new empty object. 16141 * @example 16142 * 16143 * var objects = _.times(2, _.stubObject); 16144 * 16145 * console.log(objects); 16146 * // => [{}, {}] 16147 * 16148 * console.log(objects[0] === objects[1]); 16149 * // => false 16150 */ 16151 function stubObject() { 16152 return {}; 16153 } 16154 16155 /** 16156 * This method returns an empty string. 16157 * 16158 * @static 16159 * @memberOf _ 16160 * @since 4.13.0 16161 * @category Util 16162 * @returns {string} Returns the empty string. 16163 * @example 16164 * 16165 * _.times(2, _.stubString); 16166 * // => ['', ''] 16167 */ 16168 function stubString() { 16169 return ''; 16170 } 16171 16172 /** 16173 * This method returns `true`. 16174 * 16175 * @static 16176 * @memberOf _ 16177 * @since 4.13.0 16178 * @category Util 16179 * @returns {boolean} Returns `true`. 16180 * @example 16181 * 16182 * _.times(2, _.stubTrue); 16183 * // => [true, true] 16184 */ 16185 function stubTrue() { 16186 return true; 16187 } 16188 16189 /** 16190 * Invokes the iteratee `n` times, returning an array of the results of 16191 * each invocation. The iteratee is invoked with one argument; (index). 16192 * 16193 * @static 16194 * @since 0.1.0 16195 * @memberOf _ 16196 * @category Util 16197 * @param {number} n The number of times to invoke `iteratee`. 16198 * @param {Function} [iteratee=_.identity] The function invoked per iteration. 16199 * @returns {Array} Returns the array of results. 16200 * @example 16201 * 16202 * _.times(3, String); 16203 * // => ['0', '1', '2'] 16204 * 16205 * _.times(4, _.constant(0)); 16206 * // => [0, 0, 0, 0] 16207 */ 16208 function times(n, iteratee) { 16209 n = toInteger(n); 16210 if (n < 1 || n > MAX_SAFE_INTEGER) { 16211 return []; 16212 } 16213 var index = MAX_ARRAY_LENGTH, 16214 length = nativeMin(n, MAX_ARRAY_LENGTH); 16215 16216 iteratee = getIteratee(iteratee); 16217 n -= MAX_ARRAY_LENGTH; 16218 16219 var result = baseTimes(length, iteratee); 16220 while (++index < n) { 16221 iteratee(index); 16222 } 16223 return result; 16224 } 16225 16226 /** 16227 * Converts `value` to a property path array. 16228 * 16229 * @static 16230 * @memberOf _ 16231 * @since 4.0.0 16232 * @category Util 16233 * @param {*} value The value to convert. 16234 * @returns {Array} Returns the new property path array. 16235 * @example 16236 * 16237 * _.toPath('a.b.c'); 16238 * // => ['a', 'b', 'c'] 16239 * 16240 * _.toPath('a[0].b.c'); 16241 * // => ['a', '0', 'b', 'c'] 16242 */ 16243 function toPath(value) { 16244 if (isArray(value)) { 16245 return arrayMap(value, toKey); 16246 } 16247 return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value))); 16248 } 16249 16250 /** 16251 * Generates a unique ID. If `prefix` is given, the ID is appended to it. 16252 * 16253 * @static 16254 * @since 0.1.0 16255 * @memberOf _ 16256 * @category Util 16257 * @param {string} [prefix=''] The value to prefix the ID with. 16258 * @returns {string} Returns the unique ID. 16259 * @example 16260 * 16261 * _.uniqueId('contact_'); 16262 * // => 'contact_104' 16263 * 16264 * _.uniqueId(); 16265 * // => '105' 16266 */ 16267 function uniqueId(prefix) { 16268 var id = ++idCounter; 16269 return toString(prefix) + id; 16270 } 16271 16272 /*------------------------------------------------------------------------*/ 16273 16274 /** 16275 * Adds two numbers. 16276 * 16277 * @static 16278 * @memberOf _ 16279 * @since 3.4.0 16280 * @category Math 16281 * @param {number} augend The first number in an addition. 16282 * @param {number} addend The second number in an addition. 16283 * @returns {number} Returns the total. 16284 * @example 16285 * 16286 * _.add(6, 4); 16287 * // => 10 16288 */ 16289 var add = createMathOperation(function(augend, addend) { 16290 return augend + addend; 16291 }, 0); 16292 16293 /** 16294 * Computes `number` rounded up to `precision`. 16295 * 16296 * @static 16297 * @memberOf _ 16298 * @since 3.10.0 16299 * @category Math 16300 * @param {number} number The number to round up. 16301 * @param {number} [precision=0] The precision to round up to. 16302 * @returns {number} Returns the rounded up number. 16303 * @example 16304 * 16305 * _.ceil(4.006); 16306 * // => 5 16307 * 16308 * _.ceil(6.004, 2); 16309 * // => 6.01 16310 * 16311 * _.ceil(6040, -2); 16312 * // => 6100 16313 */ 16314 var ceil = createRound('ceil'); 16315 16316 /** 16317 * Divide two numbers. 16318 * 16319 * @static 16320 * @memberOf _ 16321 * @since 4.7.0 16322 * @category Math 16323 * @param {number} dividend The first number in a division. 16324 * @param {number} divisor The second number in a division. 16325 * @returns {number} Returns the quotient. 16326 * @example 16327 * 16328 * _.divide(6, 4); 16329 * // => 1.5 16330 */ 16331 var divide = createMathOperation(function(dividend, divisor) { 16332 return dividend / divisor; 16333 }, 1); 16334 16335 /** 16336 * Computes `number` rounded down to `precision`. 16337 * 16338 * @static 16339 * @memberOf _ 16340 * @since 3.10.0 16341 * @category Math 16342 * @param {number} number The number to round down. 16343 * @param {number} [precision=0] The precision to round down to. 16344 * @returns {number} Returns the rounded down number. 16345 * @example 16346 * 16347 * _.floor(4.006); 16348 * // => 4 16349 * 16350 * _.floor(0.046, 2); 16351 * // => 0.04 16352 * 16353 * _.floor(4060, -2); 16354 * // => 4000 16355 */ 16356 var floor = createRound('floor'); 16357 16358 /** 16359 * Computes the maximum value of `array`. If `array` is empty or falsey, 16360 * `undefined` is returned. 16361 * 16362 * @static 16363 * @since 0.1.0 16364 * @memberOf _ 16365 * @category Math 16366 * @param {Array} array The array to iterate over. 16367 * @returns {*} Returns the maximum value. 16368 * @example 16369 * 16370 * _.max([4, 2, 8, 6]); 16371 * // => 8 16372 * 16373 * _.max([]); 16374 * // => undefined 16375 */ 16376 function max(array) { 16377 return (array && array.length) 16378 ? baseExtremum(array, identity, baseGt) 16379 : undefined; 16380 } 16381 16382 /** 16383 * This method is like `_.max` except that it accepts `iteratee` which is 16384 * invoked for each element in `array` to generate the criterion by which 16385 * the value is ranked. The iteratee is invoked with one argument: (value). 16386 * 16387 * @static 16388 * @memberOf _ 16389 * @since 4.0.0 16390 * @category Math 16391 * @param {Array} array The array to iterate over. 16392 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16393 * @returns {*} Returns the maximum value. 16394 * @example 16395 * 16396 * var objects = [{ 'n': 1 }, { 'n': 2 }]; 16397 * 16398 * _.maxBy(objects, function(o) { return o.n; }); 16399 * // => { 'n': 2 } 16400 * 16401 * // The `_.property` iteratee shorthand. 16402 * _.maxBy(objects, 'n'); 16403 * // => { 'n': 2 } 16404 */ 16405 function maxBy(array, iteratee) { 16406 return (array && array.length) 16407 ? baseExtremum(array, getIteratee(iteratee, 2), baseGt) 16408 : undefined; 16409 } 16410 16411 /** 16412 * Computes the mean of the values in `array`. 16413 * 16414 * @static 16415 * @memberOf _ 16416 * @since 4.0.0 16417 * @category Math 16418 * @param {Array} array The array to iterate over. 16419 * @returns {number} Returns the mean. 16420 * @example 16421 * 16422 * _.mean([4, 2, 8, 6]); 16423 * // => 5 16424 */ 16425 function mean(array) { 16426 return baseMean(array, identity); 16427 } 16428 16429 /** 16430 * This method is like `_.mean` except that it accepts `iteratee` which is 16431 * invoked for each element in `array` to generate the value to be averaged. 16432 * The iteratee is invoked with one argument: (value). 16433 * 16434 * @static 16435 * @memberOf _ 16436 * @since 4.7.0 16437 * @category Math 16438 * @param {Array} array The array to iterate over. 16439 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16440 * @returns {number} Returns the mean. 16441 * @example 16442 * 16443 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]; 16444 * 16445 * _.meanBy(objects, function(o) { return o.n; }); 16446 * // => 5 16447 * 16448 * // The `_.property` iteratee shorthand. 16449 * _.meanBy(objects, 'n'); 16450 * // => 5 16451 */ 16452 function meanBy(array, iteratee) { 16453 return baseMean(array, getIteratee(iteratee, 2)); 16454 } 16455 16456 /** 16457 * Computes the minimum value of `array`. If `array` is empty or falsey, 16458 * `undefined` is returned. 16459 * 16460 * @static 16461 * @since 0.1.0 16462 * @memberOf _ 16463 * @category Math 16464 * @param {Array} array The array to iterate over. 16465 * @returns {*} Returns the minimum value. 16466 * @example 16467 * 16468 * _.min([4, 2, 8, 6]); 16469 * // => 2 16470 * 16471 * _.min([]); 16472 * // => undefined 16473 */ 16474 function min(array) { 16475 return (array && array.length) 16476 ? baseExtremum(array, identity, baseLt) 16477 : undefined; 16478 } 16479 16480 /** 16481 * This method is like `_.min` except that it accepts `iteratee` which is 16482 * invoked for each element in `array` to generate the criterion by which 16483 * the value is ranked. The iteratee is invoked with one argument: (value). 16484 * 16485 * @static 16486 * @memberOf _ 16487 * @since 4.0.0 16488 * @category Math 16489 * @param {Array} array The array to iterate over. 16490 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16491 * @returns {*} Returns the minimum value. 16492 * @example 16493 * 16494 * var objects = [{ 'n': 1 }, { 'n': 2 }]; 16495 * 16496 * _.minBy(objects, function(o) { return o.n; }); 16497 * // => { 'n': 1 } 16498 * 16499 * // The `_.property` iteratee shorthand. 16500 * _.minBy(objects, 'n'); 16501 * // => { 'n': 1 } 16502 */ 16503 function minBy(array, iteratee) { 16504 return (array && array.length) 16505 ? baseExtremum(array, getIteratee(iteratee, 2), baseLt) 16506 : undefined; 16507 } 16508 16509 /** 16510 * Multiply two numbers. 16511 * 16512 * @static 16513 * @memberOf _ 16514 * @since 4.7.0 16515 * @category Math 16516 * @param {number} multiplier The first number in a multiplication. 16517 * @param {number} multiplicand The second number in a multiplication. 16518 * @returns {number} Returns the product. 16519 * @example 16520 * 16521 * _.multiply(6, 4); 16522 * // => 24 16523 */ 16524 var multiply = createMathOperation(function(multiplier, multiplicand) { 16525 return multiplier * multiplicand; 16526 }, 1); 16527 16528 /** 16529 * Computes `number` rounded to `precision`. 16530 * 16531 * @static 16532 * @memberOf _ 16533 * @since 3.10.0 16534 * @category Math 16535 * @param {number} number The number to round. 16536 * @param {number} [precision=0] The precision to round to. 16537 * @returns {number} Returns the rounded number. 16538 * @example 16539 * 16540 * _.round(4.006); 16541 * // => 4 16542 * 16543 * _.round(4.006, 2); 16544 * // => 4.01 16545 * 16546 * _.round(4060, -2); 16547 * // => 4100 16548 */ 16549 var round = createRound('round'); 16550 16551 /** 16552 * Subtract two numbers. 16553 * 16554 * @static 16555 * @memberOf _ 16556 * @since 4.0.0 16557 * @category Math 16558 * @param {number} minuend The first number in a subtraction. 16559 * @param {number} subtrahend The second number in a subtraction. 16560 * @returns {number} Returns the difference. 16561 * @example 16562 * 16563 * _.subtract(6, 4); 16564 * // => 2 16565 */ 16566 var subtract = createMathOperation(function(minuend, subtrahend) { 16567 return minuend - subtrahend; 16568 }, 0); 16569 16570 /** 16571 * Computes the sum of the values in `array`. 16572 * 16573 * @static 16574 * @memberOf _ 16575 * @since 3.4.0 16576 * @category Math 16577 * @param {Array} array The array to iterate over. 16578 * @returns {number} Returns the sum. 16579 * @example 16580 * 16581 * _.sum([4, 2, 8, 6]); 16582 * // => 20 16583 */ 16584 function sum(array) { 16585 return (array && array.length) 16586 ? baseSum(array, identity) 16587 : 0; 16588 } 16589 16590 /** 16591 * This method is like `_.sum` except that it accepts `iteratee` which is 16592 * invoked for each element in `array` to generate the value to be summed. 16593 * The iteratee is invoked with one argument: (value). 16594 * 16595 * @static 16596 * @memberOf _ 16597 * @since 4.0.0 16598 * @category Math 16599 * @param {Array} array The array to iterate over. 16600 * @param {Function} [iteratee=_.identity] The iteratee invoked per element. 16601 * @returns {number} Returns the sum. 16602 * @example 16603 * 16604 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]; 16605 * 16606 * _.sumBy(objects, function(o) { return o.n; }); 16607 * // => 20 16608 * 16609 * // The `_.property` iteratee shorthand. 16610 * _.sumBy(objects, 'n'); 16611 * // => 20 16612 */ 16613 function sumBy(array, iteratee) { 16614 return (array && array.length) 16615 ? baseSum(array, getIteratee(iteratee, 2)) 16616 : 0; 16617 } 16618 16619 /*------------------------------------------------------------------------*/ 16620 16621 // Add methods that return wrapped values in chain sequences. 16622 lodash.after = after; 16623 lodash.ary = ary; 16624 lodash.assign = assign; 16625 lodash.assignIn = assignIn; 16626 lodash.assignInWith = assignInWith; 16627 lodash.assignWith = assignWith; 16628 lodash.at = at; 16629 lodash.before = before; 16630 lodash.bind = bind; 16631 lodash.bindAll = bindAll; 16632 lodash.bindKey = bindKey; 16633 lodash.castArray = castArray; 16634 lodash.chain = chain; 16635 lodash.chunk = chunk; 16636 lodash.compact = compact; 16637 lodash.concat = concat; 16638 lodash.cond = cond; 16639 lodash.conforms = conforms; 16640 lodash.constant = constant; 16641 lodash.countBy = countBy; 16642 lodash.create = create; 16643 lodash.curry = curry; 16644 lodash.curryRight = curryRight; 16645 lodash.debounce = debounce; 16646 lodash.defaults = defaults; 16647 lodash.defaultsDeep = defaultsDeep; 16648 lodash.defer = defer; 16649 lodash.delay = delay; 16650 lodash.difference = difference; 16651 lodash.differenceBy = differenceBy; 16652 lodash.differenceWith = differenceWith; 16653 lodash.drop = drop; 16654 lodash.dropRight = dropRight; 16655 lodash.dropRightWhile = dropRightWhile; 16656 lodash.dropWhile = dropWhile; 16657 lodash.fill = fill; 16658 lodash.filter = filter; 16659 lodash.flatMap = flatMap; 16660 lodash.flatMapDeep = flatMapDeep; 16661 lodash.flatMapDepth = flatMapDepth; 16662 lodash.flatten = flatten; 16663 lodash.flattenDeep = flattenDeep; 16664 lodash.flattenDepth = flattenDepth; 16665 lodash.flip = flip; 16666 lodash.flow = flow; 16667 lodash.flowRight = flowRight; 16668 lodash.fromPairs = fromPairs; 16669 lodash.functions = functions; 16670 lodash.functionsIn = functionsIn; 16671 lodash.groupBy = groupBy; 16672 lodash.initial = initial; 16673 lodash.intersection = intersection; 16674 lodash.intersectionBy = intersectionBy; 16675 lodash.intersectionWith = intersectionWith; 16676 lodash.invert = invert; 16677 lodash.invertBy = invertBy; 16678 lodash.invokeMap = invokeMap; 16679 lodash.iteratee = iteratee; 16680 lodash.keyBy = keyBy; 16681 lodash.keys = keys; 16682 lodash.keysIn = keysIn; 16683 lodash.map = map; 16684 lodash.mapKeys = mapKeys; 16685 lodash.mapValues = mapValues; 16686 lodash.matches = matches; 16687 lodash.matchesProperty = matchesProperty; 16688 lodash.memoize = memoize; 16689 lodash.merge = merge; 16690 lodash.mergeWith = mergeWith; 16691 lodash.method = method; 16692 lodash.methodOf = methodOf; 16693 lodash.mixin = mixin; 16694 lodash.negate = negate; 16695 lodash.nthArg = nthArg; 16696 lodash.omit = omit; 16697 lodash.omitBy = omitBy; 16698 lodash.once = once; 16699 lodash.orderBy = orderBy; 16700 lodash.over = over; 16701 lodash.overArgs = overArgs; 16702 lodash.overEvery = overEvery; 16703 lodash.overSome = overSome; 16704 lodash.partial = partial; 16705 lodash.partialRight = partialRight; 16706 lodash.partition = partition; 16707 lodash.pick = pick; 16708 lodash.pickBy = pickBy; 16709 lodash.property = property; 16710 lodash.propertyOf = propertyOf; 16711 lodash.pull = pull; 16712 lodash.pullAll = pullAll; 16713 lodash.pullAllBy = pullAllBy; 16714 lodash.pullAllWith = pullAllWith; 16715 lodash.pullAt = pullAt; 16716 lodash.range = range; 16717 lodash.rangeRight = rangeRight; 16718 lodash.rearg = rearg; 16719 lodash.reject = reject; 16720 lodash.remove = remove; 16721 lodash.rest = rest; 16722 lodash.reverse = reverse; 16723 lodash.sampleSize = sampleSize; 16724 lodash.set = set; 16725 lodash.setWith = setWith; 16726 lodash.shuffle = shuffle; 16727 lodash.slice = slice; 16728 lodash.sortBy = sortBy; 16729 lodash.sortedUniq = sortedUniq; 16730 lodash.sortedUniqBy = sortedUniqBy; 16731 lodash.split = split; 16732 lodash.spread = spread; 16733 lodash.tail = tail; 16734 lodash.take = take; 16735 lodash.takeRight = takeRight; 16736 lodash.takeRightWhile = takeRightWhile; 16737 lodash.takeWhile = takeWhile; 16738 lodash.tap = tap; 16739 lodash.throttle = throttle; 16740 lodash.thru = thru; 16741 lodash.toArray = toArray; 16742 lodash.toPairs = toPairs; 16743 lodash.toPairsIn = toPairsIn; 16744 lodash.toPath = toPath; 16745 lodash.toPlainObject = toPlainObject; 16746 lodash.transform = transform; 16747 lodash.unary = unary; 16748 lodash.union = union; 16749 lodash.unionBy = unionBy; 16750 lodash.unionWith = unionWith; 16751 lodash.uniq = uniq; 16752 lodash.uniqBy = uniqBy; 16753 lodash.uniqWith = uniqWith; 16754 lodash.unset = unset; 16755 lodash.unzip = unzip; 16756 lodash.unzipWith = unzipWith; 16757 lodash.update = update; 16758 lodash.updateWith = updateWith; 16759 lodash.values = values; 16760 lodash.valuesIn = valuesIn; 16761 lodash.without = without; 16762 lodash.words = words; 16763 lodash.wrap = wrap; 16764 lodash.xor = xor; 16765 lodash.xorBy = xorBy; 16766 lodash.xorWith = xorWith; 16767 lodash.zip = zip; 16768 lodash.zipObject = zipObject; 16769 lodash.zipObjectDeep = zipObjectDeep; 16770 lodash.zipWith = zipWith; 16771 16772 // Add aliases. 16773 lodash.entries = toPairs; 16774 lodash.entriesIn = toPairsIn; 16775 lodash.extend = assignIn; 16776 lodash.extendWith = assignInWith; 16777 16778 // Add methods to `lodash.prototype`. 16779 mixin(lodash, lodash); 16780 16781 /*------------------------------------------------------------------------*/ 16782 16783 // Add methods that return unwrapped values in chain sequences. 16784 lodash.add = add; 16785 lodash.attempt = attempt; 16786 lodash.camelCase = camelCase; 16787 lodash.capitalize = capitalize; 16788 lodash.ceil = ceil; 16789 lodash.clamp = clamp; 16790 lodash.clone = clone; 16791 lodash.cloneDeep = cloneDeep; 16792 lodash.cloneDeepWith = cloneDeepWith; 16793 lodash.cloneWith = cloneWith; 16794 lodash.conformsTo = conformsTo; 16795 lodash.deburr = deburr; 16796 lodash.defaultTo = defaultTo; 16797 lodash.divide = divide; 16798 lodash.endsWith = endsWith; 16799 lodash.eq = eq; 16800 lodash.escape = escape; 16801 lodash.escapeRegExp = escapeRegExp; 16802 lodash.every = every; 16803 lodash.find = find; 16804 lodash.findIndex = findIndex; 16805 lodash.findKey = findKey; 16806 lodash.findLast = findLast; 16807 lodash.findLastIndex = findLastIndex; 16808 lodash.findLastKey = findLastKey; 16809 lodash.floor = floor; 16810 lodash.forEach = forEach; 16811 lodash.forEachRight = forEachRight; 16812 lodash.forIn = forIn; 16813 lodash.forInRight = forInRight; 16814 lodash.forOwn = forOwn; 16815 lodash.forOwnRight = forOwnRight; 16816 lodash.get = get; 16817 lodash.gt = gt; 16818 lodash.gte = gte; 16819 lodash.has = has; 16820 lodash.hasIn = hasIn; 16821 lodash.head = head; 16822 lodash.identity = identity; 16823 lodash.includes = includes; 16824 lodash.indexOf = indexOf; 16825 lodash.inRange = inRange; 16826 lodash.invoke = invoke; 16827 lodash.isArguments = isArguments; 16828 lodash.isArray = isArray; 16829 lodash.isArrayBuffer = isArrayBuffer; 16830 lodash.isArrayLike = isArrayLike; 16831 lodash.isArrayLikeObject = isArrayLikeObject; 16832 lodash.isBoolean = isBoolean; 16833 lodash.isBuffer = isBuffer; 16834 lodash.isDate = isDate; 16835 lodash.isElement = isElement; 16836 lodash.isEmpty = isEmpty; 16837 lodash.isEqual = isEqual; 16838 lodash.isEqualWith = isEqualWith; 16839 lodash.isError = isError; 16840 lodash.isFinite = isFinite; 16841 lodash.isFunction = isFunction; 16842 lodash.isInteger = isInteger; 16843 lodash.isLength = isLength; 16844 lodash.isMap = isMap; 16845 lodash.isMatch = isMatch; 16846 lodash.isMatchWith = isMatchWith; 16847 lodash.isNaN = isNaN; 16848 lodash.isNative = isNative; 16849 lodash.isNil = isNil; 16850 lodash.isNull = isNull; 16851 lodash.isNumber = isNumber; 16852 lodash.isObject = isObject; 16853 lodash.isObjectLike = isObjectLike; 16854 lodash.isPlainObject = isPlainObject; 16855 lodash.isRegExp = isRegExp; 16856 lodash.isSafeInteger = isSafeInteger; 16857 lodash.isSet = isSet; 16858 lodash.isString = isString; 16859 lodash.isSymbol = isSymbol; 16860 lodash.isTypedArray = isTypedArray; 16861 lodash.isUndefined = isUndefined; 16862 lodash.isWeakMap = isWeakMap; 16863 lodash.isWeakSet = isWeakSet; 16864 lodash.join = join; 16865 lodash.kebabCase = kebabCase; 16866 lodash.last = last; 16867 lodash.lastIndexOf = lastIndexOf; 16868 lodash.lowerCase = lowerCase; 16869 lodash.lowerFirst = lowerFirst; 16870 lodash.lt = lt; 16871 lodash.lte = lte; 16872 lodash.max = max; 16873 lodash.maxBy = maxBy; 16874 lodash.mean = mean; 16875 lodash.meanBy = meanBy; 16876 lodash.min = min; 16877 lodash.minBy = minBy; 16878 lodash.stubArray = stubArray; 16879 lodash.stubFalse = stubFalse; 16880 lodash.stubObject = stubObject; 16881 lodash.stubString = stubString; 16882 lodash.stubTrue = stubTrue; 16883 lodash.multiply = multiply; 16884 lodash.nth = nth; 16885 lodash.noConflict = noConflict; 16886 lodash.noop = noop; 16887 lodash.now = now; 16888 lodash.pad = pad; 16889 lodash.padEnd = padEnd; 16890 lodash.padStart = padStart; 16891 lodash.parseInt = parseInt; 16892 lodash.random = random; 16893 lodash.reduce = reduce; 16894 lodash.reduceRight = reduceRight; 16895 lodash.repeat = repeat; 16896 lodash.replace = replace; 16897 lodash.result = result; 16898 lodash.round = round; 16899 lodash.runInContext = runInContext; 16900 lodash.sample = sample; 16901 lodash.size = size; 16902 lodash.snakeCase = snakeCase; 16903 lodash.some = some; 16904 lodash.sortedIndex = sortedIndex; 16905 lodash.sortedIndexBy = sortedIndexBy; 16906 lodash.sortedIndexOf = sortedIndexOf; 16907 lodash.sortedLastIndex = sortedLastIndex; 16908 lodash.sortedLastIndexBy = sortedLastIndexBy; 16909 lodash.sortedLastIndexOf = sortedLastIndexOf; 16910 lodash.startCase = startCase; 16911 lodash.startsWith = startsWith; 16912 lodash.subtract = subtract; 16913 lodash.sum = sum; 16914 lodash.sumBy = sumBy; 16915 lodash.template = template; 16916 lodash.times = times; 16917 lodash.toFinite = toFinite; 16918 lodash.toInteger = toInteger; 16919 lodash.toLength = toLength; 16920 lodash.toLower = toLower; 16921 lodash.toNumber = toNumber; 16922 lodash.toSafeInteger = toSafeInteger; 16923 lodash.toString = toString; 16924 lodash.toUpper = toUpper; 16925 lodash.trim = trim; 16926 lodash.trimEnd = trimEnd; 16927 lodash.trimStart = trimStart; 16928 lodash.truncate = truncate; 16929 lodash.unescape = unescape; 16930 lodash.uniqueId = uniqueId; 16931 lodash.upperCase = upperCase; 16932 lodash.upperFirst = upperFirst; 16933 16934 // Add aliases. 16935 lodash.each = forEach; 16936 lodash.eachRight = forEachRight; 16937 lodash.first = head; 16938 16939 mixin(lodash, (function() { 16940 var source = {}; 16941 baseForOwn(lodash, function(func, methodName) { 16942 if (!hasOwnProperty.call(lodash.prototype, methodName)) { 16943 source[methodName] = func; 16944 } 16945 }); 16946 return source; 16947 }()), { 'chain': false }); 16948 16949 /*------------------------------------------------------------------------*/ 16950 16951 /** 16952 * The semantic version number. 16953 * 16954 * @static 16955 * @memberOf _ 16956 * @type {string} 16957 */ 16958 lodash.VERSION = VERSION; 16959 16960 // Assign default placeholders. 16961 arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) { 16962 lodash[methodName].placeholder = lodash; 16963 }); 16964 16965 // Add `LazyWrapper` methods for `_.drop` and `_.take` variants. 16966 arrayEach(['drop', 'take'], function(methodName, index) { 16967 LazyWrapper.prototype[methodName] = function(n) { 16968 n = n === undefined ? 1 : nativeMax(toInteger(n), 0); 16969 16970 var result = (this.__filtered__ && !index) 16971 ? new LazyWrapper(this) 16972 : this.clone(); 16973 16974 if (result.__filtered__) { 16975 result.__takeCount__ = nativeMin(n, result.__takeCount__); 16976 } else { 16977 result.__views__.push({ 16978 'size': nativeMin(n, MAX_ARRAY_LENGTH), 16979 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') 16980 }); 16981 } 16982 return result; 16983 }; 16984 16985 LazyWrapper.prototype[methodName + 'Right'] = function(n) { 16986 return this.reverse()[methodName](n).reverse(); 16987 }; 16988 }); 16989 16990 // Add `LazyWrapper` methods that accept an `iteratee` value. 16991 arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) { 16992 var type = index + 1, 16993 isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG; 16994 16995 LazyWrapper.prototype[methodName] = function(iteratee) { 16996 var result = this.clone(); 16997 result.__iteratees__.push({ 16998 'iteratee': getIteratee(iteratee, 3), 16999 'type': type 17000 }); 17001 result.__filtered__ = result.__filtered__ || isFilter; 17002 return result; 17003 }; 17004 }); 17005 17006 // Add `LazyWrapper` methods for `_.head` and `_.last`. 17007 arrayEach(['head', 'last'], function(methodName, index) { 17008 var takeName = 'take' + (index ? 'Right' : ''); 17009 17010 LazyWrapper.prototype[methodName] = function() { 17011 return this[takeName](1).value()[0]; 17012 }; 17013 }); 17014 17015 // Add `LazyWrapper` methods for `_.initial` and `_.tail`. 17016 arrayEach(['initial', 'tail'], function(methodName, index) { 17017 var dropName = 'drop' + (index ? '' : 'Right'); 17018 17019 LazyWrapper.prototype[methodName] = function() { 17020 return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1); 17021 }; 17022 }); 17023 17024 LazyWrapper.prototype.compact = function() { 17025 return this.filter(identity); 17026 }; 17027 17028 LazyWrapper.prototype.find = function(predicate) { 17029 return this.filter(predicate).head(); 17030 }; 17031 17032 LazyWrapper.prototype.findLast = function(predicate) { 17033 return this.reverse().find(predicate); 17034 }; 17035 17036 LazyWrapper.prototype.invokeMap = baseRest(function(path, args) { 17037 if (typeof path == 'function') { 17038 return new LazyWrapper(this); 17039 } 17040 return this.map(function(value) { 17041 return baseInvoke(value, path, args); 17042 }); 17043 }); 17044 17045 LazyWrapper.prototype.reject = function(predicate) { 17046 return this.filter(negate(getIteratee(predicate))); 17047 }; 17048 17049 LazyWrapper.prototype.slice = function(start, end) { 17050 start = toInteger(start); 17051 17052 var result = this; 17053 if (result.__filtered__ && (start > 0 || end < 0)) { 17054 return new LazyWrapper(result); 17055 } 17056 if (start < 0) { 17057 result = result.takeRight(-start); 17058 } else if (start) { 17059 result = result.drop(start); 17060 } 17061 if (end !== undefined) { 17062 end = toInteger(end); 17063 result = end < 0 ? result.dropRight(-end) : result.take(end - start); 17064 } 17065 return result; 17066 }; 17067 17068 LazyWrapper.prototype.takeRightWhile = function(predicate) { 17069 return this.reverse().takeWhile(predicate).reverse(); 17070 }; 17071 17072 LazyWrapper.prototype.toArray = function() { 17073 return this.take(MAX_ARRAY_LENGTH); 17074 }; 17075 17076 // Add `LazyWrapper` methods to `lodash.prototype`. 17077 baseForOwn(LazyWrapper.prototype, function(func, methodName) { 17078 var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName), 17079 isTaker = /^(?:head|last)$/.test(methodName), 17080 lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName], 17081 retUnwrapped = isTaker || /^find/.test(methodName); 17082 17083 if (!lodashFunc) { 17084 return; 17085 } 17086 lodash.prototype[methodName] = function() { 17087 var value = this.__wrapped__, 17088 args = isTaker ? [1] : arguments, 17089 isLazy = value instanceof LazyWrapper, 17090 iteratee = args[0], 17091 useLazy = isLazy || isArray(value); 17092 17093 var interceptor = function(value) { 17094 var result = lodashFunc.apply(lodash, arrayPush([value], args)); 17095 return (isTaker && chainAll) ? result[0] : result; 17096 }; 17097 17098 if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) { 17099 // Avoid lazy use if the iteratee has a "length" value other than `1`. 17100 isLazy = useLazy = false; 17101 } 17102 var chainAll = this.__chain__, 17103 isHybrid = !!this.__actions__.length, 17104 isUnwrapped = retUnwrapped && !chainAll, 17105 onlyLazy = isLazy && !isHybrid; 17106 17107 if (!retUnwrapped && useLazy) { 17108 value = onlyLazy ? value : new LazyWrapper(this); 17109 var result = func.apply(value, args); 17110 result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined }); 17111 return new LodashWrapper(result, chainAll); 17112 } 17113 if (isUnwrapped && onlyLazy) { 17114 return func.apply(this, args); 17115 } 17116 result = this.thru(interceptor); 17117 return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result; 17118 }; 17119 }); 17120 17121 // Add `Array` methods to `lodash.prototype`. 17122 arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { 17123 var func = arrayProto[methodName], 17124 chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', 17125 retUnwrapped = /^(?:pop|shift)$/.test(methodName); 17126 17127 lodash.prototype[methodName] = function() { 17128 var args = arguments; 17129 if (retUnwrapped && !this.__chain__) { 17130 var value = this.value(); 17131 return func.apply(isArray(value) ? value : [], args); 17132 } 17133 return this[chainName](function(value) { 17134 return func.apply(isArray(value) ? value : [], args); 17135 }); 17136 }; 17137 }); 17138 17139 // Map minified method names to their real names. 17140 baseForOwn(LazyWrapper.prototype, function(func, methodName) { 17141 var lodashFunc = lodash[methodName]; 17142 if (lodashFunc) { 17143 var key = lodashFunc.name + ''; 17144 if (!hasOwnProperty.call(realNames, key)) { 17145 realNames[key] = []; 17146 } 17147 realNames[key].push({ 'name': methodName, 'func': lodashFunc }); 17148 } 17149 }); 17150 17151 realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{ 17152 'name': 'wrapper', 17153 'func': undefined 17154 }]; 17155 17156 // Add methods to `LazyWrapper`. 17157 LazyWrapper.prototype.clone = lazyClone; 17158 LazyWrapper.prototype.reverse = lazyReverse; 17159 LazyWrapper.prototype.value = lazyValue; 17160 17161 // Add chain sequence methods to the `lodash` wrapper. 17162 lodash.prototype.at = wrapperAt; 17163 lodash.prototype.chain = wrapperChain; 17164 lodash.prototype.commit = wrapperCommit; 17165 lodash.prototype.next = wrapperNext; 17166 lodash.prototype.plant = wrapperPlant; 17167 lodash.prototype.reverse = wrapperReverse; 17168 lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; 17169 17170 // Add lazy aliases. 17171 lodash.prototype.first = lodash.prototype.head; 17172 17173 if (symIterator) { 17174 lodash.prototype[symIterator] = wrapperToIterator; 17175 } 17176 return lodash; 17177 }); 17178 17179 /*--------------------------------------------------------------------------*/ 17180 17181 // Export lodash. 17182 var _ = runInContext(); 17183 17184 // Some AMD build optimizers, like r.js, check for condition patterns like: 17185 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { 17186 // Expose Lodash on the global object to prevent errors when Lodash is 17187 // loaded by a script tag in the presence of an AMD loader. 17188 // See http://requirejs.org/docs/errors.html#mismatch for more details. 17189 // Use `_.noConflict` to remove Lodash from the global object. 17190 root._ = _; 17191 17192 // Define as an anonymous module so, through path mapping, it can be 17193 // referenced as the "underscore" module. 17194 define(function() { 17195 return _; 17196 }); 17197 } 17198 // Check for `exports` after `define` in case a build optimizer adds it. 17199 else if (freeModule) { 17200 // Export for Node.js. 17201 (freeModule.exports = _)._ = _; 17202 // Export for CommonJS support. 17203 freeExports._ = _; 17204 } 17205 else { 17206 // Export to the global object. 17207 root._ = _; 17208 } 17209 }.call(this));
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |