| 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.18.1';
|
|---|
| 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 | INVALID_TEMPL_IMPORTS_ERROR_TEXT = 'Invalid `imports` option passed into `_.template`';
|
|---|
| 25 |
|
|---|
| 26 | /** Used to stand-in for `undefined` hash values. */
|
|---|
| 27 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|---|
| 28 |
|
|---|
| 29 | /** Used as the maximum memoize cache size. */
|
|---|
| 30 | var MAX_MEMOIZE_SIZE = 500;
|
|---|
| 31 |
|
|---|
| 32 | /** Used as the internal argument placeholder. */
|
|---|
| 33 | var PLACEHOLDER = '__lodash_placeholder__';
|
|---|
| 34 |
|
|---|
| 35 | /** Used to compose bitmasks for cloning. */
|
|---|
| 36 | var CLONE_DEEP_FLAG = 1,
|
|---|
| 37 | CLONE_FLAT_FLAG = 2,
|
|---|
| 38 | CLONE_SYMBOLS_FLAG = 4;
|
|---|
| 39 |
|
|---|
| 40 | /** Used to compose bitmasks for value comparisons. */
|
|---|
| 41 | var COMPARE_PARTIAL_FLAG = 1,
|
|---|
| 42 | COMPARE_UNORDERED_FLAG = 2;
|
|---|
| 43 |
|
|---|
| 44 | /** Used to compose bitmasks for function metadata. */
|
|---|
| 45 | var WRAP_BIND_FLAG = 1,
|
|---|
| 46 | WRAP_BIND_KEY_FLAG = 2,
|
|---|
| 47 | WRAP_CURRY_BOUND_FLAG = 4,
|
|---|
| 48 | WRAP_CURRY_FLAG = 8,
|
|---|
| 49 | WRAP_CURRY_RIGHT_FLAG = 16,
|
|---|
| 50 | WRAP_PARTIAL_FLAG = 32,
|
|---|
| 51 | WRAP_PARTIAL_RIGHT_FLAG = 64,
|
|---|
| 52 | WRAP_ARY_FLAG = 128,
|
|---|
| 53 | WRAP_REARG_FLAG = 256,
|
|---|
| 54 | WRAP_FLIP_FLAG = 512;
|
|---|
| 55 |
|
|---|
| 56 | /** Used as default options for `_.truncate`. */
|
|---|
| 57 | var DEFAULT_TRUNC_LENGTH = 30,
|
|---|
| 58 | DEFAULT_TRUNC_OMISSION = '...';
|
|---|
| 59 |
|
|---|
| 60 | /** Used to detect hot functions by number of calls within a span of milliseconds. */
|
|---|
| 61 | var HOT_COUNT = 800,
|
|---|
| 62 | HOT_SPAN = 16;
|
|---|
| 63 |
|
|---|
| 64 | /** Used to indicate the type of lazy iteratees. */
|
|---|
| 65 | var LAZY_FILTER_FLAG = 1,
|
|---|
| 66 | LAZY_MAP_FLAG = 2,
|
|---|
| 67 | LAZY_WHILE_FLAG = 3;
|
|---|
| 68 |
|
|---|
| 69 | /** Used as references for various `Number` constants. */
|
|---|
| 70 | var INFINITY = 1 / 0,
|
|---|
| 71 | MAX_SAFE_INTEGER = 9007199254740991,
|
|---|
| 72 | MAX_INTEGER = 1.7976931348623157e+308,
|
|---|
| 73 | NAN = 0 / 0;
|
|---|
| 74 |
|
|---|
| 75 | /** Used as references for the maximum length and index of an array. */
|
|---|
| 76 | var MAX_ARRAY_LENGTH = 4294967295,
|
|---|
| 77 | MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
|
|---|
| 78 | HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
|---|
| 79 |
|
|---|
| 80 | /** Used to associate wrap methods with their bit flags. */
|
|---|
| 81 | var wrapFlags = [
|
|---|
| 82 | ['ary', WRAP_ARY_FLAG],
|
|---|
| 83 | ['bind', WRAP_BIND_FLAG],
|
|---|
| 84 | ['bindKey', WRAP_BIND_KEY_FLAG],
|
|---|
| 85 | ['curry', WRAP_CURRY_FLAG],
|
|---|
| 86 | ['curryRight', WRAP_CURRY_RIGHT_FLAG],
|
|---|
| 87 | ['flip', WRAP_FLIP_FLAG],
|
|---|
| 88 | ['partial', WRAP_PARTIAL_FLAG],
|
|---|
| 89 | ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
|
|---|
| 90 | ['rearg', WRAP_REARG_FLAG]
|
|---|
| 91 | ];
|
|---|
| 92 |
|
|---|
| 93 | /** `Object#toString` result references. */
|
|---|
| 94 | var argsTag = '[object Arguments]',
|
|---|
| 95 | arrayTag = '[object Array]',
|
|---|
| 96 | asyncTag = '[object AsyncFunction]',
|
|---|
| 97 | boolTag = '[object Boolean]',
|
|---|
| 98 | dateTag = '[object Date]',
|
|---|
| 99 | domExcTag = '[object DOMException]',
|
|---|
| 100 | errorTag = '[object Error]',
|
|---|
| 101 | funcTag = '[object Function]',
|
|---|
| 102 | genTag = '[object GeneratorFunction]',
|
|---|
| 103 | mapTag = '[object Map]',
|
|---|
| 104 | numberTag = '[object Number]',
|
|---|
| 105 | nullTag = '[object Null]',
|
|---|
| 106 | objectTag = '[object Object]',
|
|---|
| 107 | promiseTag = '[object Promise]',
|
|---|
| 108 | proxyTag = '[object Proxy]',
|
|---|
| 109 | regexpTag = '[object RegExp]',
|
|---|
| 110 | setTag = '[object Set]',
|
|---|
| 111 | stringTag = '[object String]',
|
|---|
| 112 | symbolTag = '[object Symbol]',
|
|---|
| 113 | undefinedTag = '[object Undefined]',
|
|---|
| 114 | weakMapTag = '[object WeakMap]',
|
|---|
| 115 | weakSetTag = '[object WeakSet]';
|
|---|
| 116 |
|
|---|
| 117 | var arrayBufferTag = '[object ArrayBuffer]',
|
|---|
| 118 | dataViewTag = '[object DataView]',
|
|---|
| 119 | float32Tag = '[object Float32Array]',
|
|---|
| 120 | float64Tag = '[object Float64Array]',
|
|---|
| 121 | int8Tag = '[object Int8Array]',
|
|---|
| 122 | int16Tag = '[object Int16Array]',
|
|---|
| 123 | int32Tag = '[object Int32Array]',
|
|---|
| 124 | uint8Tag = '[object Uint8Array]',
|
|---|
| 125 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
|---|
| 126 | uint16Tag = '[object Uint16Array]',
|
|---|
| 127 | uint32Tag = '[object Uint32Array]';
|
|---|
| 128 |
|
|---|
| 129 | /** Used to match empty string literals in compiled template source. */
|
|---|
| 130 | var reEmptyStringLeading = /\b__p \+= '';/g,
|
|---|
| 131 | reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
|---|
| 132 | reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
|
|---|
| 133 |
|
|---|
| 134 | /** Used to match HTML entities and HTML characters. */
|
|---|
| 135 | var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
|
|---|
| 136 | reUnescapedHtml = /[&<>"']/g,
|
|---|
| 137 | reHasEscapedHtml = RegExp(reEscapedHtml.source),
|
|---|
| 138 | reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|---|
| 139 |
|
|---|
| 140 | /** Used to match template delimiters. */
|
|---|
| 141 | var reEscape = /<%-([\s\S]+?)%>/g,
|
|---|
| 142 | reEvaluate = /<%([\s\S]+?)%>/g,
|
|---|
| 143 | reInterpolate = /<%=([\s\S]+?)%>/g;
|
|---|
| 144 |
|
|---|
| 145 | /** Used to match property names within property paths. */
|
|---|
| 146 | var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
|---|
| 147 | reIsPlainProp = /^\w*$/,
|
|---|
| 148 | rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|---|
| 149 |
|
|---|
| 150 | /**
|
|---|
| 151 | * Used to match `RegExp`
|
|---|
| 152 | * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|---|
| 153 | */
|
|---|
| 154 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
|
|---|
| 155 | reHasRegExpChar = RegExp(reRegExpChar.source);
|
|---|
| 156 |
|
|---|
| 157 | /** Used to match leading whitespace. */
|
|---|
| 158 | var reTrimStart = /^\s+/;
|
|---|
| 159 |
|
|---|
| 160 | /** Used to match a single whitespace character. */
|
|---|
| 161 | var reWhitespace = /\s/;
|
|---|
| 162 |
|
|---|
| 163 | /** Used to match wrap detail comments. */
|
|---|
| 164 | var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
|
|---|
| 165 | reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
|
|---|
| 166 | reSplitDetails = /,? & /;
|
|---|
| 167 |
|
|---|
| 168 | /** Used to match words composed of alphanumeric characters. */
|
|---|
| 169 | var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|---|
| 170 |
|
|---|
| 171 | /**
|
|---|
| 172 | * Used to validate the `validate` option in `_.template` variable.
|
|---|
| 173 | *
|
|---|
| 174 | * Forbids characters which could potentially change the meaning of the function argument definition:
|
|---|
| 175 | * - "()," (modification of function parameters)
|
|---|
| 176 | * - "=" (default value)
|
|---|
| 177 | * - "[]{}" (destructuring of function parameters)
|
|---|
| 178 | * - "/" (beginning of a comment)
|
|---|
| 179 | * - whitespace
|
|---|
| 180 | */
|
|---|
| 181 | var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
|
|---|
| 182 |
|
|---|
| 183 | /** Used to match backslashes in property paths. */
|
|---|
| 184 | var reEscapeChar = /\\(\\)?/g;
|
|---|
| 185 |
|
|---|
| 186 | /**
|
|---|
| 187 | * Used to match
|
|---|
| 188 | * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
|
|---|
| 189 | */
|
|---|
| 190 | var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
|
|---|
| 191 |
|
|---|
| 192 | /** Used to match `RegExp` flags from their coerced string values. */
|
|---|
| 193 | var reFlags = /\w*$/;
|
|---|
| 194 |
|
|---|
| 195 | /** Used to detect bad signed hexadecimal string values. */
|
|---|
| 196 | var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|---|
| 197 |
|
|---|
| 198 | /** Used to detect binary string values. */
|
|---|
| 199 | var reIsBinary = /^0b[01]+$/i;
|
|---|
| 200 |
|
|---|
| 201 | /** Used to detect host constructors (Safari). */
|
|---|
| 202 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|---|
| 203 |
|
|---|
| 204 | /** Used to detect octal string values. */
|
|---|
| 205 | var reIsOctal = /^0o[0-7]+$/i;
|
|---|
| 206 |
|
|---|
| 207 | /** Used to detect unsigned integer values. */
|
|---|
| 208 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
|---|
| 209 |
|
|---|
| 210 | /** Used to match Latin Unicode letters (excluding mathematical operators). */
|
|---|
| 211 | var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
|
|---|
| 212 |
|
|---|
| 213 | /** Used to ensure capturing order of template delimiters. */
|
|---|
| 214 | var reNoMatch = /($^)/;
|
|---|
| 215 |
|
|---|
| 216 | /** Used to match unescaped characters in compiled string literals. */
|
|---|
| 217 | var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
|
|---|
| 218 |
|
|---|
| 219 | /** Used to compose unicode character classes. */
|
|---|
| 220 | var rsAstralRange = '\\ud800-\\udfff',
|
|---|
| 221 | rsComboMarksRange = '\\u0300-\\u036f',
|
|---|
| 222 | reComboHalfMarksRange = '\\ufe20-\\ufe2f',
|
|---|
| 223 | rsComboSymbolsRange = '\\u20d0-\\u20ff',
|
|---|
| 224 | rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
|
|---|
| 225 | rsDingbatRange = '\\u2700-\\u27bf',
|
|---|
| 226 | rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
|
|---|
| 227 | rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
|
|---|
| 228 | rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
|
|---|
| 229 | rsPunctuationRange = '\\u2000-\\u206f',
|
|---|
| 230 | 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',
|
|---|
| 231 | rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
|
|---|
| 232 | rsVarRange = '\\ufe0e\\ufe0f',
|
|---|
| 233 | rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
|
|---|
| 234 |
|
|---|
| 235 | /** Used to compose unicode capture groups. */
|
|---|
| 236 | var rsApos = "['\u2019]",
|
|---|
| 237 | rsAstral = '[' + rsAstralRange + ']',
|
|---|
| 238 | rsBreak = '[' + rsBreakRange + ']',
|
|---|
| 239 | rsCombo = '[' + rsComboRange + ']',
|
|---|
| 240 | rsDigits = '\\d+',
|
|---|
| 241 | rsDingbat = '[' + rsDingbatRange + ']',
|
|---|
| 242 | rsLower = '[' + rsLowerRange + ']',
|
|---|
| 243 | rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
|
|---|
| 244 | rsFitz = '\\ud83c[\\udffb-\\udfff]',
|
|---|
| 245 | rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
|
|---|
| 246 | rsNonAstral = '[^' + rsAstralRange + ']',
|
|---|
| 247 | rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
|
|---|
| 248 | rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
|
|---|
| 249 | rsUpper = '[' + rsUpperRange + ']',
|
|---|
| 250 | rsZWJ = '\\u200d';
|
|---|
| 251 |
|
|---|
| 252 | /** Used to compose unicode regexes. */
|
|---|
| 253 | var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
|
|---|
| 254 | rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
|
|---|
| 255 | rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
|
|---|
| 256 | rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
|
|---|
| 257 | reOptMod = rsModifier + '?',
|
|---|
| 258 | rsOptVar = '[' + rsVarRange + ']?',
|
|---|
| 259 | rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
|
|---|
| 260 | rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
|
|---|
| 261 | rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
|
|---|
| 262 | rsSeq = rsOptVar + reOptMod + rsOptJoin,
|
|---|
| 263 | rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
|
|---|
| 264 | rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
|
|---|
| 265 |
|
|---|
| 266 | /** Used to match apostrophes. */
|
|---|
| 267 | var reApos = RegExp(rsApos, 'g');
|
|---|
| 268 |
|
|---|
| 269 | /**
|
|---|
| 270 | * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
|
|---|
| 271 | * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
|
|---|
| 272 | */
|
|---|
| 273 | var reComboMark = RegExp(rsCombo, 'g');
|
|---|
| 274 |
|
|---|
| 275 | /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
|
|---|
| 276 | var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
|
|---|
| 277 |
|
|---|
| 278 | /** Used to match complex or compound words. */
|
|---|
| 279 | var reUnicodeWord = RegExp([
|
|---|
| 280 | rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
|
|---|
| 281 | rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
|
|---|
| 282 | rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
|
|---|
| 283 | rsUpper + '+' + rsOptContrUpper,
|
|---|
| 284 | rsOrdUpper,
|
|---|
| 285 | rsOrdLower,
|
|---|
| 286 | rsDigits,
|
|---|
| 287 | rsEmoji
|
|---|
| 288 | ].join('|'), 'g');
|
|---|
| 289 |
|
|---|
| 290 | /** 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/). */
|
|---|
| 291 | var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
|
|---|
| 292 |
|
|---|
| 293 | /** Used to detect strings that need a more robust regexp to match words. */
|
|---|
| 294 | 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 ]/;
|
|---|
| 295 |
|
|---|
| 296 | /** Used to assign default `context` object properties. */
|
|---|
| 297 | var contextProps = [
|
|---|
| 298 | 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
|
|---|
| 299 | 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
|
|---|
| 300 | 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
|
|---|
| 301 | 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
|
|---|
| 302 | '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
|
|---|
| 303 | ];
|
|---|
| 304 |
|
|---|
| 305 | /** Used to make template sourceURLs easier to identify. */
|
|---|
| 306 | var templateCounter = -1;
|
|---|
| 307 |
|
|---|
| 308 | /** Used to identify `toStringTag` values of typed arrays. */
|
|---|
| 309 | var typedArrayTags = {};
|
|---|
| 310 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
|---|
| 311 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
|---|
| 312 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
|---|
| 313 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
|---|
| 314 | typedArrayTags[uint32Tag] = true;
|
|---|
| 315 | typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
|---|
| 316 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
|---|
| 317 | typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
|
|---|
| 318 | typedArrayTags[errorTag] = typedArrayTags[funcTag] =
|
|---|
| 319 | typedArrayTags[mapTag] = typedArrayTags[numberTag] =
|
|---|
| 320 | typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
|
|---|
| 321 | typedArrayTags[setTag] = typedArrayTags[stringTag] =
|
|---|
| 322 | typedArrayTags[weakMapTag] = false;
|
|---|
| 323 |
|
|---|
| 324 | /** Used to identify `toStringTag` values supported by `_.clone`. */
|
|---|
| 325 | var cloneableTags = {};
|
|---|
| 326 | cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
|---|
| 327 | cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
|
|---|
| 328 | cloneableTags[boolTag] = cloneableTags[dateTag] =
|
|---|
| 329 | cloneableTags[float32Tag] = cloneableTags[float64Tag] =
|
|---|
| 330 | cloneableTags[int8Tag] = cloneableTags[int16Tag] =
|
|---|
| 331 | cloneableTags[int32Tag] = cloneableTags[mapTag] =
|
|---|
| 332 | cloneableTags[numberTag] = cloneableTags[objectTag] =
|
|---|
| 333 | cloneableTags[regexpTag] = cloneableTags[setTag] =
|
|---|
| 334 | cloneableTags[stringTag] = cloneableTags[symbolTag] =
|
|---|
| 335 | cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
|
|---|
| 336 | cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
|---|
| 337 | cloneableTags[errorTag] = cloneableTags[funcTag] =
|
|---|
| 338 | cloneableTags[weakMapTag] = false;
|
|---|
| 339 |
|
|---|
| 340 | /** Used to map Latin Unicode letters to basic Latin letters. */
|
|---|
| 341 | var deburredLetters = {
|
|---|
| 342 | // Latin-1 Supplement block.
|
|---|
| 343 | '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
|
|---|
| 344 | '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
|
|---|
| 345 | '\xc7': 'C', '\xe7': 'c',
|
|---|
| 346 | '\xd0': 'D', '\xf0': 'd',
|
|---|
| 347 | '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
|
|---|
| 348 | '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
|
|---|
| 349 | '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
|
|---|
| 350 | '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
|
|---|
| 351 | '\xd1': 'N', '\xf1': 'n',
|
|---|
| 352 | '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
|
|---|
| 353 | '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
|
|---|
| 354 | '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
|
|---|
| 355 | '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
|
|---|
| 356 | '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
|
|---|
| 357 | '\xc6': 'Ae', '\xe6': 'ae',
|
|---|
| 358 | '\xde': 'Th', '\xfe': 'th',
|
|---|
| 359 | '\xdf': 'ss',
|
|---|
| 360 | // Latin Extended-A block.
|
|---|
| 361 | '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
|
|---|
| 362 | '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
|
|---|
| 363 | '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
|
|---|
| 364 | '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
|
|---|
| 365 | '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
|
|---|
| 366 | '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
|
|---|
| 367 | '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
|
|---|
| 368 | '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
|
|---|
| 369 | '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
|
|---|
| 370 | '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
|
|---|
| 371 | '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
|
|---|
| 372 | '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
|
|---|
| 373 | '\u0134': 'J', '\u0135': 'j',
|
|---|
| 374 | '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
|
|---|
| 375 | '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
|
|---|
| 376 | '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
|
|---|
| 377 | '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
|
|---|
| 378 | '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
|
|---|
| 379 | '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
|
|---|
| 380 | '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
|
|---|
| 381 | '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
|
|---|
| 382 | '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
|
|---|
| 383 | '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
|
|---|
| 384 | '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
|
|---|
| 385 | '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
|
|---|
| 386 | '\u0163': 't', '\u0165': 't', '\u0167': 't',
|
|---|
| 387 | '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
|
|---|
| 388 | '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
|
|---|
| 389 | '\u0174': 'W', '\u0175': 'w',
|
|---|
| 390 | '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
|
|---|
| 391 | '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
|
|---|
| 392 | '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
|
|---|
| 393 | '\u0132': 'IJ', '\u0133': 'ij',
|
|---|
| 394 | '\u0152': 'Oe', '\u0153': 'oe',
|
|---|
| 395 | '\u0149': "'n", '\u017f': 's'
|
|---|
| 396 | };
|
|---|
| 397 |
|
|---|
| 398 | /** Used to map characters to HTML entities. */
|
|---|
| 399 | var htmlEscapes = {
|
|---|
| 400 | '&': '&',
|
|---|
| 401 | '<': '<',
|
|---|
| 402 | '>': '>',
|
|---|
| 403 | '"': '"',
|
|---|
| 404 | "'": '''
|
|---|
| 405 | };
|
|---|
| 406 |
|
|---|
| 407 | /** Used to map HTML entities to characters. */
|
|---|
| 408 | var htmlUnescapes = {
|
|---|
| 409 | '&': '&',
|
|---|
| 410 | '<': '<',
|
|---|
| 411 | '>': '>',
|
|---|
| 412 | '"': '"',
|
|---|
| 413 | ''': "'"
|
|---|
| 414 | };
|
|---|
| 415 |
|
|---|
| 416 | /** Used to escape characters for inclusion in compiled string literals. */
|
|---|
| 417 | var stringEscapes = {
|
|---|
| 418 | '\\': '\\',
|
|---|
| 419 | "'": "'",
|
|---|
| 420 | '\n': 'n',
|
|---|
| 421 | '\r': 'r',
|
|---|
| 422 | '\u2028': 'u2028',
|
|---|
| 423 | '\u2029': 'u2029'
|
|---|
| 424 | };
|
|---|
| 425 |
|
|---|
| 426 | /** Built-in method references without a dependency on `root`. */
|
|---|
| 427 | var freeParseFloat = parseFloat,
|
|---|
| 428 | freeParseInt = parseInt;
|
|---|
| 429 |
|
|---|
| 430 | /** Detect free variable `global` from Node.js. */
|
|---|
| 431 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
|---|
| 432 |
|
|---|
| 433 | /** Detect free variable `self`. */
|
|---|
| 434 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|---|
| 435 |
|
|---|
| 436 | /** Used as a reference to the global object. */
|
|---|
| 437 | var root = freeGlobal || freeSelf || Function('return this')();
|
|---|
| 438 |
|
|---|
| 439 | /** Detect free variable `exports`. */
|
|---|
| 440 | var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
|
|---|
| 441 |
|
|---|
| 442 | /** Detect free variable `module`. */
|
|---|
| 443 | var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
|
|---|
| 444 |
|
|---|
| 445 | /** Detect the popular CommonJS extension `module.exports`. */
|
|---|
| 446 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
|---|
| 447 |
|
|---|
| 448 | /** Detect free variable `process` from Node.js. */
|
|---|
| 449 | var freeProcess = moduleExports && freeGlobal.process;
|
|---|
| 450 |
|
|---|
| 451 | /** Used to access faster Node.js helpers. */
|
|---|
| 452 | var nodeUtil = (function() {
|
|---|
| 453 | try {
|
|---|
| 454 | // Use `util.types` for Node.js 10+.
|
|---|
| 455 | var types = freeModule && freeModule.require && freeModule.require('util').types;
|
|---|
| 456 |
|
|---|
| 457 | if (types) {
|
|---|
| 458 | return types;
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | // Legacy `process.binding('util')` for Node.js < 10.
|
|---|
| 462 | return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
|---|
| 463 | } catch (e) {}
|
|---|
| 464 | }());
|
|---|
| 465 |
|
|---|
| 466 | /* Node.js helper references. */
|
|---|
| 467 | var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
|
|---|
| 468 | nodeIsDate = nodeUtil && nodeUtil.isDate,
|
|---|
| 469 | nodeIsMap = nodeUtil && nodeUtil.isMap,
|
|---|
| 470 | nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
|
|---|
| 471 | nodeIsSet = nodeUtil && nodeUtil.isSet,
|
|---|
| 472 | nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
|---|
| 473 |
|
|---|
| 474 | /*--------------------------------------------------------------------------*/
|
|---|
| 475 |
|
|---|
| 476 | /**
|
|---|
| 477 | * A faster alternative to `Function#apply`, this function invokes `func`
|
|---|
| 478 | * with the `this` binding of `thisArg` and the arguments of `args`.
|
|---|
| 479 | *
|
|---|
| 480 | * @private
|
|---|
| 481 | * @param {Function} func The function to invoke.
|
|---|
| 482 | * @param {*} thisArg The `this` binding of `func`.
|
|---|
| 483 | * @param {Array} args The arguments to invoke `func` with.
|
|---|
| 484 | * @returns {*} Returns the result of `func`.
|
|---|
| 485 | */
|
|---|
| 486 | function apply(func, thisArg, args) {
|
|---|
| 487 | switch (args.length) {
|
|---|
| 488 | case 0: return func.call(thisArg);
|
|---|
| 489 | case 1: return func.call(thisArg, args[0]);
|
|---|
| 490 | case 2: return func.call(thisArg, args[0], args[1]);
|
|---|
| 491 | case 3: return func.call(thisArg, args[0], args[1], args[2]);
|
|---|
| 492 | }
|
|---|
| 493 | return func.apply(thisArg, args);
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | /**
|
|---|
| 497 | * A specialized version of `baseAggregator` for arrays.
|
|---|
| 498 | *
|
|---|
| 499 | * @private
|
|---|
| 500 | * @param {Array} [array] The array to iterate over.
|
|---|
| 501 | * @param {Function} setter The function to set `accumulator` values.
|
|---|
| 502 | * @param {Function} iteratee The iteratee to transform keys.
|
|---|
| 503 | * @param {Object} accumulator The initial aggregated object.
|
|---|
| 504 | * @returns {Function} Returns `accumulator`.
|
|---|
| 505 | */
|
|---|
| 506 | function arrayAggregator(array, setter, iteratee, accumulator) {
|
|---|
| 507 | var index = -1,
|
|---|
| 508 | length = array == null ? 0 : array.length;
|
|---|
| 509 |
|
|---|
| 510 | while (++index < length) {
|
|---|
| 511 | var value = array[index];
|
|---|
| 512 | setter(accumulator, value, iteratee(value), array);
|
|---|
| 513 | }
|
|---|
| 514 | return accumulator;
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | /**
|
|---|
| 518 | * A specialized version of `_.forEach` for arrays without support for
|
|---|
| 519 | * iteratee shorthands.
|
|---|
| 520 | *
|
|---|
| 521 | * @private
|
|---|
| 522 | * @param {Array} [array] The array to iterate over.
|
|---|
| 523 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 524 | * @returns {Array} Returns `array`.
|
|---|
| 525 | */
|
|---|
| 526 | function arrayEach(array, iteratee) {
|
|---|
| 527 | var index = -1,
|
|---|
| 528 | length = array == null ? 0 : array.length;
|
|---|
| 529 |
|
|---|
| 530 | while (++index < length) {
|
|---|
| 531 | if (iteratee(array[index], index, array) === false) {
|
|---|
| 532 | break;
|
|---|
| 533 | }
|
|---|
| 534 | }
|
|---|
| 535 | return array;
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | /**
|
|---|
| 539 | * A specialized version of `_.forEachRight` for arrays without support for
|
|---|
| 540 | * iteratee shorthands.
|
|---|
| 541 | *
|
|---|
| 542 | * @private
|
|---|
| 543 | * @param {Array} [array] The array to iterate over.
|
|---|
| 544 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 545 | * @returns {Array} Returns `array`.
|
|---|
| 546 | */
|
|---|
| 547 | function arrayEachRight(array, iteratee) {
|
|---|
| 548 | var length = array == null ? 0 : array.length;
|
|---|
| 549 |
|
|---|
| 550 | while (length--) {
|
|---|
| 551 | if (iteratee(array[length], length, array) === false) {
|
|---|
| 552 | break;
|
|---|
| 553 | }
|
|---|
| 554 | }
|
|---|
| 555 | return array;
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | /**
|
|---|
| 559 | * A specialized version of `_.every` for arrays without support for
|
|---|
| 560 | * iteratee shorthands.
|
|---|
| 561 | *
|
|---|
| 562 | * @private
|
|---|
| 563 | * @param {Array} [array] The array to iterate over.
|
|---|
| 564 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 565 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
|---|
| 566 | * else `false`.
|
|---|
| 567 | */
|
|---|
| 568 | function arrayEvery(array, predicate) {
|
|---|
| 569 | var index = -1,
|
|---|
| 570 | length = array == null ? 0 : array.length;
|
|---|
| 571 |
|
|---|
| 572 | while (++index < length) {
|
|---|
| 573 | if (!predicate(array[index], index, array)) {
|
|---|
| 574 | return false;
|
|---|
| 575 | }
|
|---|
| 576 | }
|
|---|
| 577 | return true;
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | /**
|
|---|
| 581 | * A specialized version of `_.filter` for arrays without support for
|
|---|
| 582 | * iteratee shorthands.
|
|---|
| 583 | *
|
|---|
| 584 | * @private
|
|---|
| 585 | * @param {Array} [array] The array to iterate over.
|
|---|
| 586 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 587 | * @returns {Array} Returns the new filtered array.
|
|---|
| 588 | */
|
|---|
| 589 | function arrayFilter(array, predicate) {
|
|---|
| 590 | var index = -1,
|
|---|
| 591 | length = array == null ? 0 : array.length,
|
|---|
| 592 | resIndex = 0,
|
|---|
| 593 | result = [];
|
|---|
| 594 |
|
|---|
| 595 | while (++index < length) {
|
|---|
| 596 | var value = array[index];
|
|---|
| 597 | if (predicate(value, index, array)) {
|
|---|
| 598 | result[resIndex++] = value;
|
|---|
| 599 | }
|
|---|
| 600 | }
|
|---|
| 601 | return result;
|
|---|
| 602 | }
|
|---|
| 603 |
|
|---|
| 604 | /**
|
|---|
| 605 | * A specialized version of `_.includes` for arrays without support for
|
|---|
| 606 | * specifying an index to search from.
|
|---|
| 607 | *
|
|---|
| 608 | * @private
|
|---|
| 609 | * @param {Array} [array] The array to inspect.
|
|---|
| 610 | * @param {*} target The value to search for.
|
|---|
| 611 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
|---|
| 612 | */
|
|---|
| 613 | function arrayIncludes(array, value) {
|
|---|
| 614 | var length = array == null ? 0 : array.length;
|
|---|
| 615 | return !!length && baseIndexOf(array, value, 0) > -1;
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | /**
|
|---|
| 619 | * This function is like `arrayIncludes` except that it accepts a comparator.
|
|---|
| 620 | *
|
|---|
| 621 | * @private
|
|---|
| 622 | * @param {Array} [array] The array to inspect.
|
|---|
| 623 | * @param {*} target The value to search for.
|
|---|
| 624 | * @param {Function} comparator The comparator invoked per element.
|
|---|
| 625 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
|---|
| 626 | */
|
|---|
| 627 | function arrayIncludesWith(array, value, comparator) {
|
|---|
| 628 | var index = -1,
|
|---|
| 629 | length = array == null ? 0 : array.length;
|
|---|
| 630 |
|
|---|
| 631 | while (++index < length) {
|
|---|
| 632 | if (comparator(value, array[index])) {
|
|---|
| 633 | return true;
|
|---|
| 634 | }
|
|---|
| 635 | }
|
|---|
| 636 | return false;
|
|---|
| 637 | }
|
|---|
| 638 |
|
|---|
| 639 | /**
|
|---|
| 640 | * A specialized version of `_.map` for arrays without support for iteratee
|
|---|
| 641 | * shorthands.
|
|---|
| 642 | *
|
|---|
| 643 | * @private
|
|---|
| 644 | * @param {Array} [array] The array to iterate over.
|
|---|
| 645 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 646 | * @returns {Array} Returns the new mapped array.
|
|---|
| 647 | */
|
|---|
| 648 | function arrayMap(array, iteratee) {
|
|---|
| 649 | var index = -1,
|
|---|
| 650 | length = array == null ? 0 : array.length,
|
|---|
| 651 | result = Array(length);
|
|---|
| 652 |
|
|---|
| 653 | while (++index < length) {
|
|---|
| 654 | result[index] = iteratee(array[index], index, array);
|
|---|
| 655 | }
|
|---|
| 656 | return result;
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 | /**
|
|---|
| 660 | * Appends the elements of `values` to `array`.
|
|---|
| 661 | *
|
|---|
| 662 | * @private
|
|---|
| 663 | * @param {Array} array The array to modify.
|
|---|
| 664 | * @param {Array} values The values to append.
|
|---|
| 665 | * @returns {Array} Returns `array`.
|
|---|
| 666 | */
|
|---|
| 667 | function arrayPush(array, values) {
|
|---|
| 668 | var index = -1,
|
|---|
| 669 | length = values.length,
|
|---|
| 670 | offset = array.length;
|
|---|
| 671 |
|
|---|
| 672 | while (++index < length) {
|
|---|
| 673 | array[offset + index] = values[index];
|
|---|
| 674 | }
|
|---|
| 675 | return array;
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | /**
|
|---|
| 679 | * A specialized version of `_.reduce` for arrays without support for
|
|---|
| 680 | * iteratee shorthands.
|
|---|
| 681 | *
|
|---|
| 682 | * @private
|
|---|
| 683 | * @param {Array} [array] The array to iterate over.
|
|---|
| 684 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 685 | * @param {*} [accumulator] The initial value.
|
|---|
| 686 | * @param {boolean} [initAccum] Specify using the first element of `array` as
|
|---|
| 687 | * the initial value.
|
|---|
| 688 | * @returns {*} Returns the accumulated value.
|
|---|
| 689 | */
|
|---|
| 690 | function arrayReduce(array, iteratee, accumulator, initAccum) {
|
|---|
| 691 | var index = -1,
|
|---|
| 692 | length = array == null ? 0 : array.length;
|
|---|
| 693 |
|
|---|
| 694 | if (initAccum && length) {
|
|---|
| 695 | accumulator = array[++index];
|
|---|
| 696 | }
|
|---|
| 697 | while (++index < length) {
|
|---|
| 698 | accumulator = iteratee(accumulator, array[index], index, array);
|
|---|
| 699 | }
|
|---|
| 700 | return accumulator;
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | /**
|
|---|
| 704 | * A specialized version of `_.reduceRight` for arrays without support for
|
|---|
| 705 | * iteratee shorthands.
|
|---|
| 706 | *
|
|---|
| 707 | * @private
|
|---|
| 708 | * @param {Array} [array] The array to iterate over.
|
|---|
| 709 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 710 | * @param {*} [accumulator] The initial value.
|
|---|
| 711 | * @param {boolean} [initAccum] Specify using the last element of `array` as
|
|---|
| 712 | * the initial value.
|
|---|
| 713 | * @returns {*} Returns the accumulated value.
|
|---|
| 714 | */
|
|---|
| 715 | function arrayReduceRight(array, iteratee, accumulator, initAccum) {
|
|---|
| 716 | var length = array == null ? 0 : array.length;
|
|---|
| 717 | if (initAccum && length) {
|
|---|
| 718 | accumulator = array[--length];
|
|---|
| 719 | }
|
|---|
| 720 | while (length--) {
|
|---|
| 721 | accumulator = iteratee(accumulator, array[length], length, array);
|
|---|
| 722 | }
|
|---|
| 723 | return accumulator;
|
|---|
| 724 | }
|
|---|
| 725 |
|
|---|
| 726 | /**
|
|---|
| 727 | * A specialized version of `_.some` for arrays without support for iteratee
|
|---|
| 728 | * shorthands.
|
|---|
| 729 | *
|
|---|
| 730 | * @private
|
|---|
| 731 | * @param {Array} [array] The array to iterate over.
|
|---|
| 732 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 733 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
|---|
| 734 | * else `false`.
|
|---|
| 735 | */
|
|---|
| 736 | function arraySome(array, predicate) {
|
|---|
| 737 | var index = -1,
|
|---|
| 738 | length = array == null ? 0 : array.length;
|
|---|
| 739 |
|
|---|
| 740 | while (++index < length) {
|
|---|
| 741 | if (predicate(array[index], index, array)) {
|
|---|
| 742 | return true;
|
|---|
| 743 | }
|
|---|
| 744 | }
|
|---|
| 745 | return false;
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | /**
|
|---|
| 749 | * Gets the size of an ASCII `string`.
|
|---|
| 750 | *
|
|---|
| 751 | * @private
|
|---|
| 752 | * @param {string} string The string inspect.
|
|---|
| 753 | * @returns {number} Returns the string size.
|
|---|
| 754 | */
|
|---|
| 755 | var asciiSize = baseProperty('length');
|
|---|
| 756 |
|
|---|
| 757 | /**
|
|---|
| 758 | * Converts an ASCII `string` to an array.
|
|---|
| 759 | *
|
|---|
| 760 | * @private
|
|---|
| 761 | * @param {string} string The string to convert.
|
|---|
| 762 | * @returns {Array} Returns the converted array.
|
|---|
| 763 | */
|
|---|
| 764 | function asciiToArray(string) {
|
|---|
| 765 | return string.split('');
|
|---|
| 766 | }
|
|---|
| 767 |
|
|---|
| 768 | /**
|
|---|
| 769 | * Splits an ASCII `string` into an array of its words.
|
|---|
| 770 | *
|
|---|
| 771 | * @private
|
|---|
| 772 | * @param {string} The string to inspect.
|
|---|
| 773 | * @returns {Array} Returns the words of `string`.
|
|---|
| 774 | */
|
|---|
| 775 | function asciiWords(string) {
|
|---|
| 776 | return string.match(reAsciiWord) || [];
|
|---|
| 777 | }
|
|---|
| 778 |
|
|---|
| 779 | /**
|
|---|
| 780 | * The base implementation of methods like `_.findKey` and `_.findLastKey`,
|
|---|
| 781 | * without support for iteratee shorthands, which iterates over `collection`
|
|---|
| 782 | * using `eachFunc`.
|
|---|
| 783 | *
|
|---|
| 784 | * @private
|
|---|
| 785 | * @param {Array|Object} collection The collection to inspect.
|
|---|
| 786 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 787 | * @param {Function} eachFunc The function to iterate over `collection`.
|
|---|
| 788 | * @returns {*} Returns the found element or its key, else `undefined`.
|
|---|
| 789 | */
|
|---|
| 790 | function baseFindKey(collection, predicate, eachFunc) {
|
|---|
| 791 | var result;
|
|---|
| 792 | eachFunc(collection, function(value, key, collection) {
|
|---|
| 793 | if (predicate(value, key, collection)) {
|
|---|
| 794 | result = key;
|
|---|
| 795 | return false;
|
|---|
| 796 | }
|
|---|
| 797 | });
|
|---|
| 798 | return result;
|
|---|
| 799 | }
|
|---|
| 800 |
|
|---|
| 801 | /**
|
|---|
| 802 | * The base implementation of `_.findIndex` and `_.findLastIndex` without
|
|---|
| 803 | * support for iteratee shorthands.
|
|---|
| 804 | *
|
|---|
| 805 | * @private
|
|---|
| 806 | * @param {Array} array The array to inspect.
|
|---|
| 807 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 808 | * @param {number} fromIndex The index to search from.
|
|---|
| 809 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
|---|
| 810 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 811 | */
|
|---|
| 812 | function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
|---|
| 813 | var length = array.length,
|
|---|
| 814 | index = fromIndex + (fromRight ? 1 : -1);
|
|---|
| 815 |
|
|---|
| 816 | while ((fromRight ? index-- : ++index < length)) {
|
|---|
| 817 | if (predicate(array[index], index, array)) {
|
|---|
| 818 | return index;
|
|---|
| 819 | }
|
|---|
| 820 | }
|
|---|
| 821 | return -1;
|
|---|
| 822 | }
|
|---|
| 823 |
|
|---|
| 824 | /**
|
|---|
| 825 | * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
|
|---|
| 826 | *
|
|---|
| 827 | * @private
|
|---|
| 828 | * @param {Array} array The array to inspect.
|
|---|
| 829 | * @param {*} value The value to search for.
|
|---|
| 830 | * @param {number} fromIndex The index to search from.
|
|---|
| 831 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 832 | */
|
|---|
| 833 | function baseIndexOf(array, value, fromIndex) {
|
|---|
| 834 | return value === value
|
|---|
| 835 | ? strictIndexOf(array, value, fromIndex)
|
|---|
| 836 | : baseFindIndex(array, baseIsNaN, fromIndex);
|
|---|
| 837 | }
|
|---|
| 838 |
|
|---|
| 839 | /**
|
|---|
| 840 | * This function is like `baseIndexOf` except that it accepts a comparator.
|
|---|
| 841 | *
|
|---|
| 842 | * @private
|
|---|
| 843 | * @param {Array} array The array to inspect.
|
|---|
| 844 | * @param {*} value The value to search for.
|
|---|
| 845 | * @param {number} fromIndex The index to search from.
|
|---|
| 846 | * @param {Function} comparator The comparator invoked per element.
|
|---|
| 847 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 848 | */
|
|---|
| 849 | function baseIndexOfWith(array, value, fromIndex, comparator) {
|
|---|
| 850 | var index = fromIndex - 1,
|
|---|
| 851 | length = array.length;
|
|---|
| 852 |
|
|---|
| 853 | while (++index < length) {
|
|---|
| 854 | if (comparator(array[index], value)) {
|
|---|
| 855 | return index;
|
|---|
| 856 | }
|
|---|
| 857 | }
|
|---|
| 858 | return -1;
|
|---|
| 859 | }
|
|---|
| 860 |
|
|---|
| 861 | /**
|
|---|
| 862 | * The base implementation of `_.isNaN` without support for number objects.
|
|---|
| 863 | *
|
|---|
| 864 | * @private
|
|---|
| 865 | * @param {*} value The value to check.
|
|---|
| 866 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
|---|
| 867 | */
|
|---|
| 868 | function baseIsNaN(value) {
|
|---|
| 869 | return value !== value;
|
|---|
| 870 | }
|
|---|
| 871 |
|
|---|
| 872 | /**
|
|---|
| 873 | * The base implementation of `_.mean` and `_.meanBy` without support for
|
|---|
| 874 | * iteratee shorthands.
|
|---|
| 875 | *
|
|---|
| 876 | * @private
|
|---|
| 877 | * @param {Array} array The array to iterate over.
|
|---|
| 878 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 879 | * @returns {number} Returns the mean.
|
|---|
| 880 | */
|
|---|
| 881 | function baseMean(array, iteratee) {
|
|---|
| 882 | var length = array == null ? 0 : array.length;
|
|---|
| 883 | return length ? (baseSum(array, iteratee) / length) : NAN;
|
|---|
| 884 | }
|
|---|
| 885 |
|
|---|
| 886 | /**
|
|---|
| 887 | * The base implementation of `_.property` without support for deep paths.
|
|---|
| 888 | *
|
|---|
| 889 | * @private
|
|---|
| 890 | * @param {string} key The key of the property to get.
|
|---|
| 891 | * @returns {Function} Returns the new accessor function.
|
|---|
| 892 | */
|
|---|
| 893 | function baseProperty(key) {
|
|---|
| 894 | return function(object) {
|
|---|
| 895 | return object == null ? undefined : object[key];
|
|---|
| 896 | };
|
|---|
| 897 | }
|
|---|
| 898 |
|
|---|
| 899 | /**
|
|---|
| 900 | * The base implementation of `_.propertyOf` without support for deep paths.
|
|---|
| 901 | *
|
|---|
| 902 | * @private
|
|---|
| 903 | * @param {Object} object The object to query.
|
|---|
| 904 | * @returns {Function} Returns the new accessor function.
|
|---|
| 905 | */
|
|---|
| 906 | function basePropertyOf(object) {
|
|---|
| 907 | return function(key) {
|
|---|
| 908 | return object == null ? undefined : object[key];
|
|---|
| 909 | };
|
|---|
| 910 | }
|
|---|
| 911 |
|
|---|
| 912 | /**
|
|---|
| 913 | * The base implementation of `_.reduce` and `_.reduceRight`, without support
|
|---|
| 914 | * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
|
|---|
| 915 | *
|
|---|
| 916 | * @private
|
|---|
| 917 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 918 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 919 | * @param {*} accumulator The initial value.
|
|---|
| 920 | * @param {boolean} initAccum Specify using the first or last element of
|
|---|
| 921 | * `collection` as the initial value.
|
|---|
| 922 | * @param {Function} eachFunc The function to iterate over `collection`.
|
|---|
| 923 | * @returns {*} Returns the accumulated value.
|
|---|
| 924 | */
|
|---|
| 925 | function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
|
|---|
| 926 | eachFunc(collection, function(value, index, collection) {
|
|---|
| 927 | accumulator = initAccum
|
|---|
| 928 | ? (initAccum = false, value)
|
|---|
| 929 | : iteratee(accumulator, value, index, collection);
|
|---|
| 930 | });
|
|---|
| 931 | return accumulator;
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | /**
|
|---|
| 935 | * The base implementation of `_.sortBy` which uses `comparer` to define the
|
|---|
| 936 | * sort order of `array` and replaces criteria objects with their corresponding
|
|---|
| 937 | * values.
|
|---|
| 938 | *
|
|---|
| 939 | * @private
|
|---|
| 940 | * @param {Array} array The array to sort.
|
|---|
| 941 | * @param {Function} comparer The function to define sort order.
|
|---|
| 942 | * @returns {Array} Returns `array`.
|
|---|
| 943 | */
|
|---|
| 944 | function baseSortBy(array, comparer) {
|
|---|
| 945 | var length = array.length;
|
|---|
| 946 |
|
|---|
| 947 | array.sort(comparer);
|
|---|
| 948 | while (length--) {
|
|---|
| 949 | array[length] = array[length].value;
|
|---|
| 950 | }
|
|---|
| 951 | return array;
|
|---|
| 952 | }
|
|---|
| 953 |
|
|---|
| 954 | /**
|
|---|
| 955 | * The base implementation of `_.sum` and `_.sumBy` without support for
|
|---|
| 956 | * iteratee shorthands.
|
|---|
| 957 | *
|
|---|
| 958 | * @private
|
|---|
| 959 | * @param {Array} array The array to iterate over.
|
|---|
| 960 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 961 | * @returns {number} Returns the sum.
|
|---|
| 962 | */
|
|---|
| 963 | function baseSum(array, iteratee) {
|
|---|
| 964 | var result,
|
|---|
| 965 | index = -1,
|
|---|
| 966 | length = array.length;
|
|---|
| 967 |
|
|---|
| 968 | while (++index < length) {
|
|---|
| 969 | var current = iteratee(array[index]);
|
|---|
| 970 | if (current !== undefined) {
|
|---|
| 971 | result = result === undefined ? current : (result + current);
|
|---|
| 972 | }
|
|---|
| 973 | }
|
|---|
| 974 | return result;
|
|---|
| 975 | }
|
|---|
| 976 |
|
|---|
| 977 | /**
|
|---|
| 978 | * The base implementation of `_.times` without support for iteratee shorthands
|
|---|
| 979 | * or max array length checks.
|
|---|
| 980 | *
|
|---|
| 981 | * @private
|
|---|
| 982 | * @param {number} n The number of times to invoke `iteratee`.
|
|---|
| 983 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 984 | * @returns {Array} Returns the array of results.
|
|---|
| 985 | */
|
|---|
| 986 | function baseTimes(n, iteratee) {
|
|---|
| 987 | var index = -1,
|
|---|
| 988 | result = Array(n);
|
|---|
| 989 |
|
|---|
| 990 | while (++index < n) {
|
|---|
| 991 | result[index] = iteratee(index);
|
|---|
| 992 | }
|
|---|
| 993 | return result;
|
|---|
| 994 | }
|
|---|
| 995 |
|
|---|
| 996 | /**
|
|---|
| 997 | * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
|
|---|
| 998 | * of key-value pairs for `object` corresponding to the property names of `props`.
|
|---|
| 999 | *
|
|---|
| 1000 | * @private
|
|---|
| 1001 | * @param {Object} object The object to query.
|
|---|
| 1002 | * @param {Array} props The property names to get values for.
|
|---|
| 1003 | * @returns {Object} Returns the key-value pairs.
|
|---|
| 1004 | */
|
|---|
| 1005 | function baseToPairs(object, props) {
|
|---|
| 1006 | return arrayMap(props, function(key) {
|
|---|
| 1007 | return [key, object[key]];
|
|---|
| 1008 | });
|
|---|
| 1009 | }
|
|---|
| 1010 |
|
|---|
| 1011 | /**
|
|---|
| 1012 | * The base implementation of `_.trim`.
|
|---|
| 1013 | *
|
|---|
| 1014 | * @private
|
|---|
| 1015 | * @param {string} string The string to trim.
|
|---|
| 1016 | * @returns {string} Returns the trimmed string.
|
|---|
| 1017 | */
|
|---|
| 1018 | function baseTrim(string) {
|
|---|
| 1019 | return string
|
|---|
| 1020 | ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
|
|---|
| 1021 | : string;
|
|---|
| 1022 | }
|
|---|
| 1023 |
|
|---|
| 1024 | /**
|
|---|
| 1025 | * The base implementation of `_.unary` without support for storing metadata.
|
|---|
| 1026 | *
|
|---|
| 1027 | * @private
|
|---|
| 1028 | * @param {Function} func The function to cap arguments for.
|
|---|
| 1029 | * @returns {Function} Returns the new capped function.
|
|---|
| 1030 | */
|
|---|
| 1031 | function baseUnary(func) {
|
|---|
| 1032 | return function(value) {
|
|---|
| 1033 | return func(value);
|
|---|
| 1034 | };
|
|---|
| 1035 | }
|
|---|
| 1036 |
|
|---|
| 1037 | /**
|
|---|
| 1038 | * The base implementation of `_.values` and `_.valuesIn` which creates an
|
|---|
| 1039 | * array of `object` property values corresponding to the property names
|
|---|
| 1040 | * of `props`.
|
|---|
| 1041 | *
|
|---|
| 1042 | * @private
|
|---|
| 1043 | * @param {Object} object The object to query.
|
|---|
| 1044 | * @param {Array} props The property names to get values for.
|
|---|
| 1045 | * @returns {Object} Returns the array of property values.
|
|---|
| 1046 | */
|
|---|
| 1047 | function baseValues(object, props) {
|
|---|
| 1048 | return arrayMap(props, function(key) {
|
|---|
| 1049 | return object[key];
|
|---|
| 1050 | });
|
|---|
| 1051 | }
|
|---|
| 1052 |
|
|---|
| 1053 | /**
|
|---|
| 1054 | * Checks if a `cache` value for `key` exists.
|
|---|
| 1055 | *
|
|---|
| 1056 | * @private
|
|---|
| 1057 | * @param {Object} cache The cache to query.
|
|---|
| 1058 | * @param {string} key The key of the entry to check.
|
|---|
| 1059 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|---|
| 1060 | */
|
|---|
| 1061 | function cacheHas(cache, key) {
|
|---|
| 1062 | return cache.has(key);
|
|---|
| 1063 | }
|
|---|
| 1064 |
|
|---|
| 1065 | /**
|
|---|
| 1066 | * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
|
|---|
| 1067 | * that is not found in the character symbols.
|
|---|
| 1068 | *
|
|---|
| 1069 | * @private
|
|---|
| 1070 | * @param {Array} strSymbols The string symbols to inspect.
|
|---|
| 1071 | * @param {Array} chrSymbols The character symbols to find.
|
|---|
| 1072 | * @returns {number} Returns the index of the first unmatched string symbol.
|
|---|
| 1073 | */
|
|---|
| 1074 | function charsStartIndex(strSymbols, chrSymbols) {
|
|---|
| 1075 | var index = -1,
|
|---|
| 1076 | length = strSymbols.length;
|
|---|
| 1077 |
|
|---|
| 1078 | while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
|
|---|
| 1079 | return index;
|
|---|
| 1080 | }
|
|---|
| 1081 |
|
|---|
| 1082 | /**
|
|---|
| 1083 | * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
|
|---|
| 1084 | * that is not found in the character symbols.
|
|---|
| 1085 | *
|
|---|
| 1086 | * @private
|
|---|
| 1087 | * @param {Array} strSymbols The string symbols to inspect.
|
|---|
| 1088 | * @param {Array} chrSymbols The character symbols to find.
|
|---|
| 1089 | * @returns {number} Returns the index of the last unmatched string symbol.
|
|---|
| 1090 | */
|
|---|
| 1091 | function charsEndIndex(strSymbols, chrSymbols) {
|
|---|
| 1092 | var index = strSymbols.length;
|
|---|
| 1093 |
|
|---|
| 1094 | while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
|
|---|
| 1095 | return index;
|
|---|
| 1096 | }
|
|---|
| 1097 |
|
|---|
| 1098 | /**
|
|---|
| 1099 | * Gets the number of `placeholder` occurrences in `array`.
|
|---|
| 1100 | *
|
|---|
| 1101 | * @private
|
|---|
| 1102 | * @param {Array} array The array to inspect.
|
|---|
| 1103 | * @param {*} placeholder The placeholder to search for.
|
|---|
| 1104 | * @returns {number} Returns the placeholder count.
|
|---|
| 1105 | */
|
|---|
| 1106 | function countHolders(array, placeholder) {
|
|---|
| 1107 | var length = array.length,
|
|---|
| 1108 | result = 0;
|
|---|
| 1109 |
|
|---|
| 1110 | while (length--) {
|
|---|
| 1111 | if (array[length] === placeholder) {
|
|---|
| 1112 | ++result;
|
|---|
| 1113 | }
|
|---|
| 1114 | }
|
|---|
| 1115 | return result;
|
|---|
| 1116 | }
|
|---|
| 1117 |
|
|---|
| 1118 | /**
|
|---|
| 1119 | * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
|
|---|
| 1120 | * letters to basic Latin letters.
|
|---|
| 1121 | *
|
|---|
| 1122 | * @private
|
|---|
| 1123 | * @param {string} letter The matched letter to deburr.
|
|---|
| 1124 | * @returns {string} Returns the deburred letter.
|
|---|
| 1125 | */
|
|---|
| 1126 | var deburrLetter = basePropertyOf(deburredLetters);
|
|---|
| 1127 |
|
|---|
| 1128 | /**
|
|---|
| 1129 | * Used by `_.escape` to convert characters to HTML entities.
|
|---|
| 1130 | *
|
|---|
| 1131 | * @private
|
|---|
| 1132 | * @param {string} chr The matched character to escape.
|
|---|
| 1133 | * @returns {string} Returns the escaped character.
|
|---|
| 1134 | */
|
|---|
| 1135 | var escapeHtmlChar = basePropertyOf(htmlEscapes);
|
|---|
| 1136 |
|
|---|
| 1137 | /**
|
|---|
| 1138 | * Used by `_.template` to escape characters for inclusion in compiled string literals.
|
|---|
| 1139 | *
|
|---|
| 1140 | * @private
|
|---|
| 1141 | * @param {string} chr The matched character to escape.
|
|---|
| 1142 | * @returns {string} Returns the escaped character.
|
|---|
| 1143 | */
|
|---|
| 1144 | function escapeStringChar(chr) {
|
|---|
| 1145 | return '\\' + stringEscapes[chr];
|
|---|
| 1146 | }
|
|---|
| 1147 |
|
|---|
| 1148 | /**
|
|---|
| 1149 | * Gets the value at `key` of `object`.
|
|---|
| 1150 | *
|
|---|
| 1151 | * @private
|
|---|
| 1152 | * @param {Object} [object] The object to query.
|
|---|
| 1153 | * @param {string} key The key of the property to get.
|
|---|
| 1154 | * @returns {*} Returns the property value.
|
|---|
| 1155 | */
|
|---|
| 1156 | function getValue(object, key) {
|
|---|
| 1157 | return object == null ? undefined : object[key];
|
|---|
| 1158 | }
|
|---|
| 1159 |
|
|---|
| 1160 | /**
|
|---|
| 1161 | * Checks if `string` contains Unicode symbols.
|
|---|
| 1162 | *
|
|---|
| 1163 | * @private
|
|---|
| 1164 | * @param {string} string The string to inspect.
|
|---|
| 1165 | * @returns {boolean} Returns `true` if a symbol is found, else `false`.
|
|---|
| 1166 | */
|
|---|
| 1167 | function hasUnicode(string) {
|
|---|
| 1168 | return reHasUnicode.test(string);
|
|---|
| 1169 | }
|
|---|
| 1170 |
|
|---|
| 1171 | /**
|
|---|
| 1172 | * Checks if `string` contains a word composed of Unicode symbols.
|
|---|
| 1173 | *
|
|---|
| 1174 | * @private
|
|---|
| 1175 | * @param {string} string The string to inspect.
|
|---|
| 1176 | * @returns {boolean} Returns `true` if a word is found, else `false`.
|
|---|
| 1177 | */
|
|---|
| 1178 | function hasUnicodeWord(string) {
|
|---|
| 1179 | return reHasUnicodeWord.test(string);
|
|---|
| 1180 | }
|
|---|
| 1181 |
|
|---|
| 1182 | /**
|
|---|
| 1183 | * Converts `iterator` to an array.
|
|---|
| 1184 | *
|
|---|
| 1185 | * @private
|
|---|
| 1186 | * @param {Object} iterator The iterator to convert.
|
|---|
| 1187 | * @returns {Array} Returns the converted array.
|
|---|
| 1188 | */
|
|---|
| 1189 | function iteratorToArray(iterator) {
|
|---|
| 1190 | var data,
|
|---|
| 1191 | result = [];
|
|---|
| 1192 |
|
|---|
| 1193 | while (!(data = iterator.next()).done) {
|
|---|
| 1194 | result.push(data.value);
|
|---|
| 1195 | }
|
|---|
| 1196 | return result;
|
|---|
| 1197 | }
|
|---|
| 1198 |
|
|---|
| 1199 | /**
|
|---|
| 1200 | * Converts `map` to its key-value pairs.
|
|---|
| 1201 | *
|
|---|
| 1202 | * @private
|
|---|
| 1203 | * @param {Object} map The map to convert.
|
|---|
| 1204 | * @returns {Array} Returns the key-value pairs.
|
|---|
| 1205 | */
|
|---|
| 1206 | function mapToArray(map) {
|
|---|
| 1207 | var index = -1,
|
|---|
| 1208 | result = Array(map.size);
|
|---|
| 1209 |
|
|---|
| 1210 | map.forEach(function(value, key) {
|
|---|
| 1211 | result[++index] = [key, value];
|
|---|
| 1212 | });
|
|---|
| 1213 | return result;
|
|---|
| 1214 | }
|
|---|
| 1215 |
|
|---|
| 1216 | /**
|
|---|
| 1217 | * Creates a unary function that invokes `func` with its argument transformed.
|
|---|
| 1218 | *
|
|---|
| 1219 | * @private
|
|---|
| 1220 | * @param {Function} func The function to wrap.
|
|---|
| 1221 | * @param {Function} transform The argument transform.
|
|---|
| 1222 | * @returns {Function} Returns the new function.
|
|---|
| 1223 | */
|
|---|
| 1224 | function overArg(func, transform) {
|
|---|
| 1225 | return function(arg) {
|
|---|
| 1226 | return func(transform(arg));
|
|---|
| 1227 | };
|
|---|
| 1228 | }
|
|---|
| 1229 |
|
|---|
| 1230 | /**
|
|---|
| 1231 | * Replaces all `placeholder` elements in `array` with an internal placeholder
|
|---|
| 1232 | * and returns an array of their indexes.
|
|---|
| 1233 | *
|
|---|
| 1234 | * @private
|
|---|
| 1235 | * @param {Array} array The array to modify.
|
|---|
| 1236 | * @param {*} placeholder The placeholder to replace.
|
|---|
| 1237 | * @returns {Array} Returns the new array of placeholder indexes.
|
|---|
| 1238 | */
|
|---|
| 1239 | function replaceHolders(array, placeholder) {
|
|---|
| 1240 | var index = -1,
|
|---|
| 1241 | length = array.length,
|
|---|
| 1242 | resIndex = 0,
|
|---|
| 1243 | result = [];
|
|---|
| 1244 |
|
|---|
| 1245 | while (++index < length) {
|
|---|
| 1246 | var value = array[index];
|
|---|
| 1247 | if (value === placeholder || value === PLACEHOLDER) {
|
|---|
| 1248 | array[index] = PLACEHOLDER;
|
|---|
| 1249 | result[resIndex++] = index;
|
|---|
| 1250 | }
|
|---|
| 1251 | }
|
|---|
| 1252 | return result;
|
|---|
| 1253 | }
|
|---|
| 1254 |
|
|---|
| 1255 | /**
|
|---|
| 1256 | * Converts `set` to an array of its values.
|
|---|
| 1257 | *
|
|---|
| 1258 | * @private
|
|---|
| 1259 | * @param {Object} set The set to convert.
|
|---|
| 1260 | * @returns {Array} Returns the values.
|
|---|
| 1261 | */
|
|---|
| 1262 | function setToArray(set) {
|
|---|
| 1263 | var index = -1,
|
|---|
| 1264 | result = Array(set.size);
|
|---|
| 1265 |
|
|---|
| 1266 | set.forEach(function(value) {
|
|---|
| 1267 | result[++index] = value;
|
|---|
| 1268 | });
|
|---|
| 1269 | return result;
|
|---|
| 1270 | }
|
|---|
| 1271 |
|
|---|
| 1272 | /**
|
|---|
| 1273 | * Converts `set` to its value-value pairs.
|
|---|
| 1274 | *
|
|---|
| 1275 | * @private
|
|---|
| 1276 | * @param {Object} set The set to convert.
|
|---|
| 1277 | * @returns {Array} Returns the value-value pairs.
|
|---|
| 1278 | */
|
|---|
| 1279 | function setToPairs(set) {
|
|---|
| 1280 | var index = -1,
|
|---|
| 1281 | result = Array(set.size);
|
|---|
| 1282 |
|
|---|
| 1283 | set.forEach(function(value) {
|
|---|
| 1284 | result[++index] = [value, value];
|
|---|
| 1285 | });
|
|---|
| 1286 | return result;
|
|---|
| 1287 | }
|
|---|
| 1288 |
|
|---|
| 1289 | /**
|
|---|
| 1290 | * A specialized version of `_.indexOf` which performs strict equality
|
|---|
| 1291 | * comparisons of values, i.e. `===`.
|
|---|
| 1292 | *
|
|---|
| 1293 | * @private
|
|---|
| 1294 | * @param {Array} array The array to inspect.
|
|---|
| 1295 | * @param {*} value The value to search for.
|
|---|
| 1296 | * @param {number} fromIndex The index to search from.
|
|---|
| 1297 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 1298 | */
|
|---|
| 1299 | function strictIndexOf(array, value, fromIndex) {
|
|---|
| 1300 | var index = fromIndex - 1,
|
|---|
| 1301 | length = array.length;
|
|---|
| 1302 |
|
|---|
| 1303 | while (++index < length) {
|
|---|
| 1304 | if (array[index] === value) {
|
|---|
| 1305 | return index;
|
|---|
| 1306 | }
|
|---|
| 1307 | }
|
|---|
| 1308 | return -1;
|
|---|
| 1309 | }
|
|---|
| 1310 |
|
|---|
| 1311 | /**
|
|---|
| 1312 | * A specialized version of `_.lastIndexOf` which performs strict equality
|
|---|
| 1313 | * comparisons of values, i.e. `===`.
|
|---|
| 1314 | *
|
|---|
| 1315 | * @private
|
|---|
| 1316 | * @param {Array} array The array to inspect.
|
|---|
| 1317 | * @param {*} value The value to search for.
|
|---|
| 1318 | * @param {number} fromIndex The index to search from.
|
|---|
| 1319 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 1320 | */
|
|---|
| 1321 | function strictLastIndexOf(array, value, fromIndex) {
|
|---|
| 1322 | var index = fromIndex + 1;
|
|---|
| 1323 | while (index--) {
|
|---|
| 1324 | if (array[index] === value) {
|
|---|
| 1325 | return index;
|
|---|
| 1326 | }
|
|---|
| 1327 | }
|
|---|
| 1328 | return index;
|
|---|
| 1329 | }
|
|---|
| 1330 |
|
|---|
| 1331 | /**
|
|---|
| 1332 | * Gets the number of symbols in `string`.
|
|---|
| 1333 | *
|
|---|
| 1334 | * @private
|
|---|
| 1335 | * @param {string} string The string to inspect.
|
|---|
| 1336 | * @returns {number} Returns the string size.
|
|---|
| 1337 | */
|
|---|
| 1338 | function stringSize(string) {
|
|---|
| 1339 | return hasUnicode(string)
|
|---|
| 1340 | ? unicodeSize(string)
|
|---|
| 1341 | : asciiSize(string);
|
|---|
| 1342 | }
|
|---|
| 1343 |
|
|---|
| 1344 | /**
|
|---|
| 1345 | * Converts `string` to an array.
|
|---|
| 1346 | *
|
|---|
| 1347 | * @private
|
|---|
| 1348 | * @param {string} string The string to convert.
|
|---|
| 1349 | * @returns {Array} Returns the converted array.
|
|---|
| 1350 | */
|
|---|
| 1351 | function stringToArray(string) {
|
|---|
| 1352 | return hasUnicode(string)
|
|---|
| 1353 | ? unicodeToArray(string)
|
|---|
| 1354 | : asciiToArray(string);
|
|---|
| 1355 | }
|
|---|
| 1356 |
|
|---|
| 1357 | /**
|
|---|
| 1358 | * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
|
|---|
| 1359 | * character of `string`.
|
|---|
| 1360 | *
|
|---|
| 1361 | * @private
|
|---|
| 1362 | * @param {string} string The string to inspect.
|
|---|
| 1363 | * @returns {number} Returns the index of the last non-whitespace character.
|
|---|
| 1364 | */
|
|---|
| 1365 | function trimmedEndIndex(string) {
|
|---|
| 1366 | var index = string.length;
|
|---|
| 1367 |
|
|---|
| 1368 | while (index-- && reWhitespace.test(string.charAt(index))) {}
|
|---|
| 1369 | return index;
|
|---|
| 1370 | }
|
|---|
| 1371 |
|
|---|
| 1372 | /**
|
|---|
| 1373 | * Used by `_.unescape` to convert HTML entities to characters.
|
|---|
| 1374 | *
|
|---|
| 1375 | * @private
|
|---|
| 1376 | * @param {string} chr The matched character to unescape.
|
|---|
| 1377 | * @returns {string} Returns the unescaped character.
|
|---|
| 1378 | */
|
|---|
| 1379 | var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
|
|---|
| 1380 |
|
|---|
| 1381 | /**
|
|---|
| 1382 | * Gets the size of a Unicode `string`.
|
|---|
| 1383 | *
|
|---|
| 1384 | * @private
|
|---|
| 1385 | * @param {string} string The string inspect.
|
|---|
| 1386 | * @returns {number} Returns the string size.
|
|---|
| 1387 | */
|
|---|
| 1388 | function unicodeSize(string) {
|
|---|
| 1389 | var result = reUnicode.lastIndex = 0;
|
|---|
| 1390 | while (reUnicode.test(string)) {
|
|---|
| 1391 | ++result;
|
|---|
| 1392 | }
|
|---|
| 1393 | return result;
|
|---|
| 1394 | }
|
|---|
| 1395 |
|
|---|
| 1396 | /**
|
|---|
| 1397 | * Converts a Unicode `string` to an array.
|
|---|
| 1398 | *
|
|---|
| 1399 | * @private
|
|---|
| 1400 | * @param {string} string The string to convert.
|
|---|
| 1401 | * @returns {Array} Returns the converted array.
|
|---|
| 1402 | */
|
|---|
| 1403 | function unicodeToArray(string) {
|
|---|
| 1404 | return string.match(reUnicode) || [];
|
|---|
| 1405 | }
|
|---|
| 1406 |
|
|---|
| 1407 | /**
|
|---|
| 1408 | * Splits a Unicode `string` into an array of its words.
|
|---|
| 1409 | *
|
|---|
| 1410 | * @private
|
|---|
| 1411 | * @param {string} The string to inspect.
|
|---|
| 1412 | * @returns {Array} Returns the words of `string`.
|
|---|
| 1413 | */
|
|---|
| 1414 | function unicodeWords(string) {
|
|---|
| 1415 | return string.match(reUnicodeWord) || [];
|
|---|
| 1416 | }
|
|---|
| 1417 |
|
|---|
| 1418 | /*--------------------------------------------------------------------------*/
|
|---|
| 1419 |
|
|---|
| 1420 | /**
|
|---|
| 1421 | * Create a new pristine `lodash` function using the `context` object.
|
|---|
| 1422 | *
|
|---|
| 1423 | * @static
|
|---|
| 1424 | * @memberOf _
|
|---|
| 1425 | * @since 1.1.0
|
|---|
| 1426 | * @category Util
|
|---|
| 1427 | * @param {Object} [context=root] The context object.
|
|---|
| 1428 | * @returns {Function} Returns a new `lodash` function.
|
|---|
| 1429 | * @example
|
|---|
| 1430 | *
|
|---|
| 1431 | * _.mixin({ 'foo': _.constant('foo') });
|
|---|
| 1432 | *
|
|---|
| 1433 | * var lodash = _.runInContext();
|
|---|
| 1434 | * lodash.mixin({ 'bar': lodash.constant('bar') });
|
|---|
| 1435 | *
|
|---|
| 1436 | * _.isFunction(_.foo);
|
|---|
| 1437 | * // => true
|
|---|
| 1438 | * _.isFunction(_.bar);
|
|---|
| 1439 | * // => false
|
|---|
| 1440 | *
|
|---|
| 1441 | * lodash.isFunction(lodash.foo);
|
|---|
| 1442 | * // => false
|
|---|
| 1443 | * lodash.isFunction(lodash.bar);
|
|---|
| 1444 | * // => true
|
|---|
| 1445 | *
|
|---|
| 1446 | * // Create a suped-up `defer` in Node.js.
|
|---|
| 1447 | * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
|
|---|
| 1448 | */
|
|---|
| 1449 | var runInContext = (function runInContext(context) {
|
|---|
| 1450 | context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
|
|---|
| 1451 |
|
|---|
| 1452 | /** Built-in constructor references. */
|
|---|
| 1453 | var Array = context.Array,
|
|---|
| 1454 | Date = context.Date,
|
|---|
| 1455 | Error = context.Error,
|
|---|
| 1456 | Function = context.Function,
|
|---|
| 1457 | Math = context.Math,
|
|---|
| 1458 | Object = context.Object,
|
|---|
| 1459 | RegExp = context.RegExp,
|
|---|
| 1460 | String = context.String,
|
|---|
| 1461 | TypeError = context.TypeError;
|
|---|
| 1462 |
|
|---|
| 1463 | /** Used for built-in method references. */
|
|---|
| 1464 | var arrayProto = Array.prototype,
|
|---|
| 1465 | funcProto = Function.prototype,
|
|---|
| 1466 | objectProto = Object.prototype;
|
|---|
| 1467 |
|
|---|
| 1468 | /** Used to detect overreaching core-js shims. */
|
|---|
| 1469 | var coreJsData = context['__core-js_shared__'];
|
|---|
| 1470 |
|
|---|
| 1471 | /** Used to resolve the decompiled source of functions. */
|
|---|
| 1472 | var funcToString = funcProto.toString;
|
|---|
| 1473 |
|
|---|
| 1474 | /** Used to check objects for own properties. */
|
|---|
| 1475 | var hasOwnProperty = objectProto.hasOwnProperty;
|
|---|
| 1476 |
|
|---|
| 1477 | /** Used to generate unique IDs. */
|
|---|
| 1478 | var idCounter = 0;
|
|---|
| 1479 |
|
|---|
| 1480 | /** Used to detect methods masquerading as native. */
|
|---|
| 1481 | var maskSrcKey = (function() {
|
|---|
| 1482 | var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
|---|
| 1483 | return uid ? ('Symbol(src)_1.' + uid) : '';
|
|---|
| 1484 | }());
|
|---|
| 1485 |
|
|---|
| 1486 | /**
|
|---|
| 1487 | * Used to resolve the
|
|---|
| 1488 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
|---|
| 1489 | * of values.
|
|---|
| 1490 | */
|
|---|
| 1491 | var nativeObjectToString = objectProto.toString;
|
|---|
| 1492 |
|
|---|
| 1493 | /** Used to infer the `Object` constructor. */
|
|---|
| 1494 | var objectCtorString = funcToString.call(Object);
|
|---|
| 1495 |
|
|---|
| 1496 | /** Used to restore the original `_` reference in `_.noConflict`. */
|
|---|
| 1497 | var oldDash = root._;
|
|---|
| 1498 |
|
|---|
| 1499 | /** Used to detect if a method is native. */
|
|---|
| 1500 | var reIsNative = RegExp('^' +
|
|---|
| 1501 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
|---|
| 1502 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
|---|
| 1503 | );
|
|---|
| 1504 |
|
|---|
| 1505 | /** Built-in value references. */
|
|---|
| 1506 | var Buffer = moduleExports ? context.Buffer : undefined,
|
|---|
| 1507 | Symbol = context.Symbol,
|
|---|
| 1508 | Uint8Array = context.Uint8Array,
|
|---|
| 1509 | allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
|
|---|
| 1510 | getPrototype = overArg(Object.getPrototypeOf, Object),
|
|---|
| 1511 | objectCreate = Object.create,
|
|---|
| 1512 | propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
|---|
| 1513 | splice = arrayProto.splice,
|
|---|
| 1514 | spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
|
|---|
| 1515 | symIterator = Symbol ? Symbol.iterator : undefined,
|
|---|
| 1516 | symToStringTag = Symbol ? Symbol.toStringTag : undefined;
|
|---|
| 1517 |
|
|---|
| 1518 | var defineProperty = (function() {
|
|---|
| 1519 | try {
|
|---|
| 1520 | var func = getNative(Object, 'defineProperty');
|
|---|
| 1521 | func({}, '', {});
|
|---|
| 1522 | return func;
|
|---|
| 1523 | } catch (e) {}
|
|---|
| 1524 | }());
|
|---|
| 1525 |
|
|---|
| 1526 | /** Mocked built-ins. */
|
|---|
| 1527 | var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
|
|---|
| 1528 | ctxNow = Date && Date.now !== root.Date.now && Date.now,
|
|---|
| 1529 | ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
|
|---|
| 1530 |
|
|---|
| 1531 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
|---|
| 1532 | var nativeCeil = Math.ceil,
|
|---|
| 1533 | nativeFloor = Math.floor,
|
|---|
| 1534 | nativeGetSymbols = Object.getOwnPropertySymbols,
|
|---|
| 1535 | nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
|
|---|
| 1536 | nativeIsFinite = context.isFinite,
|
|---|
| 1537 | nativeJoin = arrayProto.join,
|
|---|
| 1538 | nativeKeys = overArg(Object.keys, Object),
|
|---|
| 1539 | nativeMax = Math.max,
|
|---|
| 1540 | nativeMin = Math.min,
|
|---|
| 1541 | nativeNow = Date.now,
|
|---|
| 1542 | nativeParseInt = context.parseInt,
|
|---|
| 1543 | nativeRandom = Math.random,
|
|---|
| 1544 | nativeReverse = arrayProto.reverse;
|
|---|
| 1545 |
|
|---|
| 1546 | /* Built-in method references that are verified to be native. */
|
|---|
| 1547 | var DataView = getNative(context, 'DataView'),
|
|---|
| 1548 | Map = getNative(context, 'Map'),
|
|---|
| 1549 | Promise = getNative(context, 'Promise'),
|
|---|
| 1550 | Set = getNative(context, 'Set'),
|
|---|
| 1551 | WeakMap = getNative(context, 'WeakMap'),
|
|---|
| 1552 | nativeCreate = getNative(Object, 'create');
|
|---|
| 1553 |
|
|---|
| 1554 | /** Used to store function metadata. */
|
|---|
| 1555 | var metaMap = WeakMap && new WeakMap;
|
|---|
| 1556 |
|
|---|
| 1557 | /** Used to lookup unminified function names. */
|
|---|
| 1558 | var realNames = {};
|
|---|
| 1559 |
|
|---|
| 1560 | /** Used to detect maps, sets, and weakmaps. */
|
|---|
| 1561 | var dataViewCtorString = toSource(DataView),
|
|---|
| 1562 | mapCtorString = toSource(Map),
|
|---|
| 1563 | promiseCtorString = toSource(Promise),
|
|---|
| 1564 | setCtorString = toSource(Set),
|
|---|
| 1565 | weakMapCtorString = toSource(WeakMap);
|
|---|
| 1566 |
|
|---|
| 1567 | /** Used to convert symbols to primitives and strings. */
|
|---|
| 1568 | var symbolProto = Symbol ? Symbol.prototype : undefined,
|
|---|
| 1569 | symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
|
|---|
| 1570 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
|---|
| 1571 |
|
|---|
| 1572 | /*------------------------------------------------------------------------*/
|
|---|
| 1573 |
|
|---|
| 1574 | /**
|
|---|
| 1575 | * Creates a `lodash` object which wraps `value` to enable implicit method
|
|---|
| 1576 | * chain sequences. Methods that operate on and return arrays, collections,
|
|---|
| 1577 | * and functions can be chained together. Methods that retrieve a single value
|
|---|
| 1578 | * or may return a primitive value will automatically end the chain sequence
|
|---|
| 1579 | * and return the unwrapped value. Otherwise, the value must be unwrapped
|
|---|
| 1580 | * with `_#value`.
|
|---|
| 1581 | *
|
|---|
| 1582 | * Explicit chain sequences, which must be unwrapped with `_#value`, may be
|
|---|
| 1583 | * enabled using `_.chain`.
|
|---|
| 1584 | *
|
|---|
| 1585 | * The execution of chained methods is lazy, that is, it's deferred until
|
|---|
| 1586 | * `_#value` is implicitly or explicitly called.
|
|---|
| 1587 | *
|
|---|
| 1588 | * Lazy evaluation allows several methods to support shortcut fusion.
|
|---|
| 1589 | * Shortcut fusion is an optimization to merge iteratee calls; this avoids
|
|---|
| 1590 | * the creation of intermediate arrays and can greatly reduce the number of
|
|---|
| 1591 | * iteratee executions. Sections of a chain sequence qualify for shortcut
|
|---|
| 1592 | * fusion if the section is applied to an array and iteratees accept only
|
|---|
| 1593 | * one argument. The heuristic for whether a section qualifies for shortcut
|
|---|
| 1594 | * fusion is subject to change.
|
|---|
| 1595 | *
|
|---|
| 1596 | * Chaining is supported in custom builds as long as the `_#value` method is
|
|---|
| 1597 | * directly or indirectly included in the build.
|
|---|
| 1598 | *
|
|---|
| 1599 | * In addition to lodash methods, wrappers have `Array` and `String` methods.
|
|---|
| 1600 | *
|
|---|
| 1601 | * The wrapper `Array` methods are:
|
|---|
| 1602 | * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
|
|---|
| 1603 | *
|
|---|
| 1604 | * The wrapper `String` methods are:
|
|---|
| 1605 | * `replace` and `split`
|
|---|
| 1606 | *
|
|---|
| 1607 | * The wrapper methods that support shortcut fusion are:
|
|---|
| 1608 | * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
|
|---|
| 1609 | * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
|
|---|
| 1610 | * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
|
|---|
| 1611 | *
|
|---|
| 1612 | * The chainable wrapper methods are:
|
|---|
| 1613 | * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
|
|---|
| 1614 | * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
|
|---|
| 1615 | * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
|
|---|
| 1616 | * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
|
|---|
| 1617 | * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
|
|---|
| 1618 | * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
|
|---|
| 1619 | * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
|
|---|
| 1620 | * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
|
|---|
| 1621 | * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
|
|---|
| 1622 | * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
|
|---|
| 1623 | * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
|
|---|
| 1624 | * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
|
|---|
| 1625 | * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
|
|---|
| 1626 | * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
|
|---|
| 1627 | * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
|
|---|
| 1628 | * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
|
|---|
| 1629 | * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
|
|---|
| 1630 | * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
|
|---|
| 1631 | * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
|
|---|
| 1632 | * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
|
|---|
| 1633 | * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
|
|---|
| 1634 | * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
|
|---|
| 1635 | * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
|
|---|
| 1636 | * `zipObject`, `zipObjectDeep`, and `zipWith`
|
|---|
| 1637 | *
|
|---|
| 1638 | * The wrapper methods that are **not** chainable by default are:
|
|---|
| 1639 | * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
|
|---|
| 1640 | * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
|
|---|
| 1641 | * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
|
|---|
| 1642 | * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
|
|---|
| 1643 | * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
|
|---|
| 1644 | * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
|
|---|
| 1645 | * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
|
|---|
| 1646 | * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
|
|---|
| 1647 | * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
|
|---|
| 1648 | * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
|
|---|
| 1649 | * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
|
|---|
| 1650 | * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
|
|---|
| 1651 | * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
|
|---|
| 1652 | * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
|
|---|
| 1653 | * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
|
|---|
| 1654 | * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
|
|---|
| 1655 | * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
|
|---|
| 1656 | * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
|
|---|
| 1657 | * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
|
|---|
| 1658 | * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
|
|---|
| 1659 | * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
|
|---|
| 1660 | * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
|
|---|
| 1661 | * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
|
|---|
| 1662 | * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
|
|---|
| 1663 | * `upperFirst`, `value`, and `words`
|
|---|
| 1664 | *
|
|---|
| 1665 | * @name _
|
|---|
| 1666 | * @constructor
|
|---|
| 1667 | * @category Seq
|
|---|
| 1668 | * @param {*} value The value to wrap in a `lodash` instance.
|
|---|
| 1669 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
|---|
| 1670 | * @example
|
|---|
| 1671 | *
|
|---|
| 1672 | * function square(n) {
|
|---|
| 1673 | * return n * n;
|
|---|
| 1674 | * }
|
|---|
| 1675 | *
|
|---|
| 1676 | * var wrapped = _([1, 2, 3]);
|
|---|
| 1677 | *
|
|---|
| 1678 | * // Returns an unwrapped value.
|
|---|
| 1679 | * wrapped.reduce(_.add);
|
|---|
| 1680 | * // => 6
|
|---|
| 1681 | *
|
|---|
| 1682 | * // Returns a wrapped value.
|
|---|
| 1683 | * var squares = wrapped.map(square);
|
|---|
| 1684 | *
|
|---|
| 1685 | * _.isArray(squares);
|
|---|
| 1686 | * // => false
|
|---|
| 1687 | *
|
|---|
| 1688 | * _.isArray(squares.value());
|
|---|
| 1689 | * // => true
|
|---|
| 1690 | */
|
|---|
| 1691 | function lodash(value) {
|
|---|
| 1692 | if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
|
|---|
| 1693 | if (value instanceof LodashWrapper) {
|
|---|
| 1694 | return value;
|
|---|
| 1695 | }
|
|---|
| 1696 | if (hasOwnProperty.call(value, '__wrapped__')) {
|
|---|
| 1697 | return wrapperClone(value);
|
|---|
| 1698 | }
|
|---|
| 1699 | }
|
|---|
| 1700 | return new LodashWrapper(value);
|
|---|
| 1701 | }
|
|---|
| 1702 |
|
|---|
| 1703 | /**
|
|---|
| 1704 | * The base implementation of `_.create` without support for assigning
|
|---|
| 1705 | * properties to the created object.
|
|---|
| 1706 | *
|
|---|
| 1707 | * @private
|
|---|
| 1708 | * @param {Object} proto The object to inherit from.
|
|---|
| 1709 | * @returns {Object} Returns the new object.
|
|---|
| 1710 | */
|
|---|
| 1711 | var baseCreate = (function() {
|
|---|
| 1712 | function object() {}
|
|---|
| 1713 | return function(proto) {
|
|---|
| 1714 | if (!isObject(proto)) {
|
|---|
| 1715 | return {};
|
|---|
| 1716 | }
|
|---|
| 1717 | if (objectCreate) {
|
|---|
| 1718 | return objectCreate(proto);
|
|---|
| 1719 | }
|
|---|
| 1720 | object.prototype = proto;
|
|---|
| 1721 | var result = new object;
|
|---|
| 1722 | object.prototype = undefined;
|
|---|
| 1723 | return result;
|
|---|
| 1724 | };
|
|---|
| 1725 | }());
|
|---|
| 1726 |
|
|---|
| 1727 | /**
|
|---|
| 1728 | * The function whose prototype chain sequence wrappers inherit from.
|
|---|
| 1729 | *
|
|---|
| 1730 | * @private
|
|---|
| 1731 | */
|
|---|
| 1732 | function baseLodash() {
|
|---|
| 1733 | // No operation performed.
|
|---|
| 1734 | }
|
|---|
| 1735 |
|
|---|
| 1736 | /**
|
|---|
| 1737 | * The base constructor for creating `lodash` wrapper objects.
|
|---|
| 1738 | *
|
|---|
| 1739 | * @private
|
|---|
| 1740 | * @param {*} value The value to wrap.
|
|---|
| 1741 | * @param {boolean} [chainAll] Enable explicit method chain sequences.
|
|---|
| 1742 | */
|
|---|
| 1743 | function LodashWrapper(value, chainAll) {
|
|---|
| 1744 | this.__wrapped__ = value;
|
|---|
| 1745 | this.__actions__ = [];
|
|---|
| 1746 | this.__chain__ = !!chainAll;
|
|---|
| 1747 | this.__index__ = 0;
|
|---|
| 1748 | this.__values__ = undefined;
|
|---|
| 1749 | }
|
|---|
| 1750 |
|
|---|
| 1751 | /**
|
|---|
| 1752 | * By default, the template delimiters used by lodash are like those in
|
|---|
| 1753 | * embedded Ruby (ERB) as well as ES2015 template strings. Change the
|
|---|
| 1754 | * following template settings to use alternative delimiters.
|
|---|
| 1755 | *
|
|---|
| 1756 | * **Security:** See
|
|---|
| 1757 | * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md)
|
|---|
| 1758 | * — `_.template` is insecure and will be removed in v5.
|
|---|
| 1759 | *
|
|---|
| 1760 | * @static
|
|---|
| 1761 | * @memberOf _
|
|---|
| 1762 | * @type {Object}
|
|---|
| 1763 | */
|
|---|
| 1764 | lodash.templateSettings = {
|
|---|
| 1765 |
|
|---|
| 1766 | /**
|
|---|
| 1767 | * Used to detect `data` property values to be HTML-escaped.
|
|---|
| 1768 | *
|
|---|
| 1769 | * @memberOf _.templateSettings
|
|---|
| 1770 | * @type {RegExp}
|
|---|
| 1771 | */
|
|---|
| 1772 | 'escape': reEscape,
|
|---|
| 1773 |
|
|---|
| 1774 | /**
|
|---|
| 1775 | * Used to detect code to be evaluated.
|
|---|
| 1776 | *
|
|---|
| 1777 | * @memberOf _.templateSettings
|
|---|
| 1778 | * @type {RegExp}
|
|---|
| 1779 | */
|
|---|
| 1780 | 'evaluate': reEvaluate,
|
|---|
| 1781 |
|
|---|
| 1782 | /**
|
|---|
| 1783 | * Used to detect `data` property values to inject.
|
|---|
| 1784 | *
|
|---|
| 1785 | * @memberOf _.templateSettings
|
|---|
| 1786 | * @type {RegExp}
|
|---|
| 1787 | */
|
|---|
| 1788 | 'interpolate': reInterpolate,
|
|---|
| 1789 |
|
|---|
| 1790 | /**
|
|---|
| 1791 | * Used to reference the data object in the template text.
|
|---|
| 1792 | *
|
|---|
| 1793 | * @memberOf _.templateSettings
|
|---|
| 1794 | * @type {string}
|
|---|
| 1795 | */
|
|---|
| 1796 | 'variable': '',
|
|---|
| 1797 |
|
|---|
| 1798 | /**
|
|---|
| 1799 | * Used to import variables into the compiled template.
|
|---|
| 1800 | *
|
|---|
| 1801 | * @memberOf _.templateSettings
|
|---|
| 1802 | * @type {Object}
|
|---|
| 1803 | */
|
|---|
| 1804 | 'imports': {
|
|---|
| 1805 |
|
|---|
| 1806 | /**
|
|---|
| 1807 | * A reference to the `lodash` function.
|
|---|
| 1808 | *
|
|---|
| 1809 | * @memberOf _.templateSettings.imports
|
|---|
| 1810 | * @type {Function}
|
|---|
| 1811 | */
|
|---|
| 1812 | '_': lodash
|
|---|
| 1813 | }
|
|---|
| 1814 | };
|
|---|
| 1815 |
|
|---|
| 1816 | // Ensure wrappers are instances of `baseLodash`.
|
|---|
| 1817 | lodash.prototype = baseLodash.prototype;
|
|---|
| 1818 | lodash.prototype.constructor = lodash;
|
|---|
| 1819 |
|
|---|
| 1820 | LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
|---|
| 1821 | LodashWrapper.prototype.constructor = LodashWrapper;
|
|---|
| 1822 |
|
|---|
| 1823 | /*------------------------------------------------------------------------*/
|
|---|
| 1824 |
|
|---|
| 1825 | /**
|
|---|
| 1826 | * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
|
|---|
| 1827 | *
|
|---|
| 1828 | * @private
|
|---|
| 1829 | * @constructor
|
|---|
| 1830 | * @param {*} value The value to wrap.
|
|---|
| 1831 | */
|
|---|
| 1832 | function LazyWrapper(value) {
|
|---|
| 1833 | this.__wrapped__ = value;
|
|---|
| 1834 | this.__actions__ = [];
|
|---|
| 1835 | this.__dir__ = 1;
|
|---|
| 1836 | this.__filtered__ = false;
|
|---|
| 1837 | this.__iteratees__ = [];
|
|---|
| 1838 | this.__takeCount__ = MAX_ARRAY_LENGTH;
|
|---|
| 1839 | this.__views__ = [];
|
|---|
| 1840 | }
|
|---|
| 1841 |
|
|---|
| 1842 | /**
|
|---|
| 1843 | * Creates a clone of the lazy wrapper object.
|
|---|
| 1844 | *
|
|---|
| 1845 | * @private
|
|---|
| 1846 | * @name clone
|
|---|
| 1847 | * @memberOf LazyWrapper
|
|---|
| 1848 | * @returns {Object} Returns the cloned `LazyWrapper` object.
|
|---|
| 1849 | */
|
|---|
| 1850 | function lazyClone() {
|
|---|
| 1851 | var result = new LazyWrapper(this.__wrapped__);
|
|---|
| 1852 | result.__actions__ = copyArray(this.__actions__);
|
|---|
| 1853 | result.__dir__ = this.__dir__;
|
|---|
| 1854 | result.__filtered__ = this.__filtered__;
|
|---|
| 1855 | result.__iteratees__ = copyArray(this.__iteratees__);
|
|---|
| 1856 | result.__takeCount__ = this.__takeCount__;
|
|---|
| 1857 | result.__views__ = copyArray(this.__views__);
|
|---|
| 1858 | return result;
|
|---|
| 1859 | }
|
|---|
| 1860 |
|
|---|
| 1861 | /**
|
|---|
| 1862 | * Reverses the direction of lazy iteration.
|
|---|
| 1863 | *
|
|---|
| 1864 | * @private
|
|---|
| 1865 | * @name reverse
|
|---|
| 1866 | * @memberOf LazyWrapper
|
|---|
| 1867 | * @returns {Object} Returns the new reversed `LazyWrapper` object.
|
|---|
| 1868 | */
|
|---|
| 1869 | function lazyReverse() {
|
|---|
| 1870 | if (this.__filtered__) {
|
|---|
| 1871 | var result = new LazyWrapper(this);
|
|---|
| 1872 | result.__dir__ = -1;
|
|---|
| 1873 | result.__filtered__ = true;
|
|---|
| 1874 | } else {
|
|---|
| 1875 | result = this.clone();
|
|---|
| 1876 | result.__dir__ *= -1;
|
|---|
| 1877 | }
|
|---|
| 1878 | return result;
|
|---|
| 1879 | }
|
|---|
| 1880 |
|
|---|
| 1881 | /**
|
|---|
| 1882 | * Extracts the unwrapped value from its lazy wrapper.
|
|---|
| 1883 | *
|
|---|
| 1884 | * @private
|
|---|
| 1885 | * @name value
|
|---|
| 1886 | * @memberOf LazyWrapper
|
|---|
| 1887 | * @returns {*} Returns the unwrapped value.
|
|---|
| 1888 | */
|
|---|
| 1889 | function lazyValue() {
|
|---|
| 1890 | var array = this.__wrapped__.value(),
|
|---|
| 1891 | dir = this.__dir__,
|
|---|
| 1892 | isArr = isArray(array),
|
|---|
| 1893 | isRight = dir < 0,
|
|---|
| 1894 | arrLength = isArr ? array.length : 0,
|
|---|
| 1895 | view = getView(0, arrLength, this.__views__),
|
|---|
| 1896 | start = view.start,
|
|---|
| 1897 | end = view.end,
|
|---|
| 1898 | length = end - start,
|
|---|
| 1899 | index = isRight ? end : (start - 1),
|
|---|
| 1900 | iteratees = this.__iteratees__,
|
|---|
| 1901 | iterLength = iteratees.length,
|
|---|
| 1902 | resIndex = 0,
|
|---|
| 1903 | takeCount = nativeMin(length, this.__takeCount__);
|
|---|
| 1904 |
|
|---|
| 1905 | if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
|
|---|
| 1906 | return baseWrapperValue(array, this.__actions__);
|
|---|
| 1907 | }
|
|---|
| 1908 | var result = [];
|
|---|
| 1909 |
|
|---|
| 1910 | outer:
|
|---|
| 1911 | while (length-- && resIndex < takeCount) {
|
|---|
| 1912 | index += dir;
|
|---|
| 1913 |
|
|---|
| 1914 | var iterIndex = -1,
|
|---|
| 1915 | value = array[index];
|
|---|
| 1916 |
|
|---|
| 1917 | while (++iterIndex < iterLength) {
|
|---|
| 1918 | var data = iteratees[iterIndex],
|
|---|
| 1919 | iteratee = data.iteratee,
|
|---|
| 1920 | type = data.type,
|
|---|
| 1921 | computed = iteratee(value);
|
|---|
| 1922 |
|
|---|
| 1923 | if (type == LAZY_MAP_FLAG) {
|
|---|
| 1924 | value = computed;
|
|---|
| 1925 | } else if (!computed) {
|
|---|
| 1926 | if (type == LAZY_FILTER_FLAG) {
|
|---|
| 1927 | continue outer;
|
|---|
| 1928 | } else {
|
|---|
| 1929 | break outer;
|
|---|
| 1930 | }
|
|---|
| 1931 | }
|
|---|
| 1932 | }
|
|---|
| 1933 | result[resIndex++] = value;
|
|---|
| 1934 | }
|
|---|
| 1935 | return result;
|
|---|
| 1936 | }
|
|---|
| 1937 |
|
|---|
| 1938 | // Ensure `LazyWrapper` is an instance of `baseLodash`.
|
|---|
| 1939 | LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
|---|
| 1940 | LazyWrapper.prototype.constructor = LazyWrapper;
|
|---|
| 1941 |
|
|---|
| 1942 | /*------------------------------------------------------------------------*/
|
|---|
| 1943 |
|
|---|
| 1944 | /**
|
|---|
| 1945 | * Creates a hash object.
|
|---|
| 1946 | *
|
|---|
| 1947 | * @private
|
|---|
| 1948 | * @constructor
|
|---|
| 1949 | * @param {Array} [entries] The key-value pairs to cache.
|
|---|
| 1950 | */
|
|---|
| 1951 | function Hash(entries) {
|
|---|
| 1952 | var index = -1,
|
|---|
| 1953 | length = entries == null ? 0 : entries.length;
|
|---|
| 1954 |
|
|---|
| 1955 | this.clear();
|
|---|
| 1956 | while (++index < length) {
|
|---|
| 1957 | var entry = entries[index];
|
|---|
| 1958 | this.set(entry[0], entry[1]);
|
|---|
| 1959 | }
|
|---|
| 1960 | }
|
|---|
| 1961 |
|
|---|
| 1962 | /**
|
|---|
| 1963 | * Removes all key-value entries from the hash.
|
|---|
| 1964 | *
|
|---|
| 1965 | * @private
|
|---|
| 1966 | * @name clear
|
|---|
| 1967 | * @memberOf Hash
|
|---|
| 1968 | */
|
|---|
| 1969 | function hashClear() {
|
|---|
| 1970 | this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
|---|
| 1971 | this.size = 0;
|
|---|
| 1972 | }
|
|---|
| 1973 |
|
|---|
| 1974 | /**
|
|---|
| 1975 | * Removes `key` and its value from the hash.
|
|---|
| 1976 | *
|
|---|
| 1977 | * @private
|
|---|
| 1978 | * @name delete
|
|---|
| 1979 | * @memberOf Hash
|
|---|
| 1980 | * @param {Object} hash The hash to modify.
|
|---|
| 1981 | * @param {string} key The key of the value to remove.
|
|---|
| 1982 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|---|
| 1983 | */
|
|---|
| 1984 | function hashDelete(key) {
|
|---|
| 1985 | var result = this.has(key) && delete this.__data__[key];
|
|---|
| 1986 | this.size -= result ? 1 : 0;
|
|---|
| 1987 | return result;
|
|---|
| 1988 | }
|
|---|
| 1989 |
|
|---|
| 1990 | /**
|
|---|
| 1991 | * Gets the hash value for `key`.
|
|---|
| 1992 | *
|
|---|
| 1993 | * @private
|
|---|
| 1994 | * @name get
|
|---|
| 1995 | * @memberOf Hash
|
|---|
| 1996 | * @param {string} key The key of the value to get.
|
|---|
| 1997 | * @returns {*} Returns the entry value.
|
|---|
| 1998 | */
|
|---|
| 1999 | function hashGet(key) {
|
|---|
| 2000 | var data = this.__data__;
|
|---|
| 2001 | if (nativeCreate) {
|
|---|
| 2002 | var result = data[key];
|
|---|
| 2003 | return result === HASH_UNDEFINED ? undefined : result;
|
|---|
| 2004 | }
|
|---|
| 2005 | return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
|---|
| 2006 | }
|
|---|
| 2007 |
|
|---|
| 2008 | /**
|
|---|
| 2009 | * Checks if a hash value for `key` exists.
|
|---|
| 2010 | *
|
|---|
| 2011 | * @private
|
|---|
| 2012 | * @name has
|
|---|
| 2013 | * @memberOf Hash
|
|---|
| 2014 | * @param {string} key The key of the entry to check.
|
|---|
| 2015 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|---|
| 2016 | */
|
|---|
| 2017 | function hashHas(key) {
|
|---|
| 2018 | var data = this.__data__;
|
|---|
| 2019 | return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
|
|---|
| 2020 | }
|
|---|
| 2021 |
|
|---|
| 2022 | /**
|
|---|
| 2023 | * Sets the hash `key` to `value`.
|
|---|
| 2024 | *
|
|---|
| 2025 | * @private
|
|---|
| 2026 | * @name set
|
|---|
| 2027 | * @memberOf Hash
|
|---|
| 2028 | * @param {string} key The key of the value to set.
|
|---|
| 2029 | * @param {*} value The value to set.
|
|---|
| 2030 | * @returns {Object} Returns the hash instance.
|
|---|
| 2031 | */
|
|---|
| 2032 | function hashSet(key, value) {
|
|---|
| 2033 | var data = this.__data__;
|
|---|
| 2034 | this.size += this.has(key) ? 0 : 1;
|
|---|
| 2035 | data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
|---|
| 2036 | return this;
|
|---|
| 2037 | }
|
|---|
| 2038 |
|
|---|
| 2039 | // Add methods to `Hash`.
|
|---|
| 2040 | Hash.prototype.clear = hashClear;
|
|---|
| 2041 | Hash.prototype['delete'] = hashDelete;
|
|---|
| 2042 | Hash.prototype.get = hashGet;
|
|---|
| 2043 | Hash.prototype.has = hashHas;
|
|---|
| 2044 | Hash.prototype.set = hashSet;
|
|---|
| 2045 |
|
|---|
| 2046 | /*------------------------------------------------------------------------*/
|
|---|
| 2047 |
|
|---|
| 2048 | /**
|
|---|
| 2049 | * Creates an list cache object.
|
|---|
| 2050 | *
|
|---|
| 2051 | * @private
|
|---|
| 2052 | * @constructor
|
|---|
| 2053 | * @param {Array} [entries] The key-value pairs to cache.
|
|---|
| 2054 | */
|
|---|
| 2055 | function ListCache(entries) {
|
|---|
| 2056 | var index = -1,
|
|---|
| 2057 | length = entries == null ? 0 : entries.length;
|
|---|
| 2058 |
|
|---|
| 2059 | this.clear();
|
|---|
| 2060 | while (++index < length) {
|
|---|
| 2061 | var entry = entries[index];
|
|---|
| 2062 | this.set(entry[0], entry[1]);
|
|---|
| 2063 | }
|
|---|
| 2064 | }
|
|---|
| 2065 |
|
|---|
| 2066 | /**
|
|---|
| 2067 | * Removes all key-value entries from the list cache.
|
|---|
| 2068 | *
|
|---|
| 2069 | * @private
|
|---|
| 2070 | * @name clear
|
|---|
| 2071 | * @memberOf ListCache
|
|---|
| 2072 | */
|
|---|
| 2073 | function listCacheClear() {
|
|---|
| 2074 | this.__data__ = [];
|
|---|
| 2075 | this.size = 0;
|
|---|
| 2076 | }
|
|---|
| 2077 |
|
|---|
| 2078 | /**
|
|---|
| 2079 | * Removes `key` and its value from the list cache.
|
|---|
| 2080 | *
|
|---|
| 2081 | * @private
|
|---|
| 2082 | * @name delete
|
|---|
| 2083 | * @memberOf ListCache
|
|---|
| 2084 | * @param {string} key The key of the value to remove.
|
|---|
| 2085 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|---|
| 2086 | */
|
|---|
| 2087 | function listCacheDelete(key) {
|
|---|
| 2088 | var data = this.__data__,
|
|---|
| 2089 | index = assocIndexOf(data, key);
|
|---|
| 2090 |
|
|---|
| 2091 | if (index < 0) {
|
|---|
| 2092 | return false;
|
|---|
| 2093 | }
|
|---|
| 2094 | var lastIndex = data.length - 1;
|
|---|
| 2095 | if (index == lastIndex) {
|
|---|
| 2096 | data.pop();
|
|---|
| 2097 | } else {
|
|---|
| 2098 | splice.call(data, index, 1);
|
|---|
| 2099 | }
|
|---|
| 2100 | --this.size;
|
|---|
| 2101 | return true;
|
|---|
| 2102 | }
|
|---|
| 2103 |
|
|---|
| 2104 | /**
|
|---|
| 2105 | * Gets the list cache value for `key`.
|
|---|
| 2106 | *
|
|---|
| 2107 | * @private
|
|---|
| 2108 | * @name get
|
|---|
| 2109 | * @memberOf ListCache
|
|---|
| 2110 | * @param {string} key The key of the value to get.
|
|---|
| 2111 | * @returns {*} Returns the entry value.
|
|---|
| 2112 | */
|
|---|
| 2113 | function listCacheGet(key) {
|
|---|
| 2114 | var data = this.__data__,
|
|---|
| 2115 | index = assocIndexOf(data, key);
|
|---|
| 2116 |
|
|---|
| 2117 | return index < 0 ? undefined : data[index][1];
|
|---|
| 2118 | }
|
|---|
| 2119 |
|
|---|
| 2120 | /**
|
|---|
| 2121 | * Checks if a list cache value for `key` exists.
|
|---|
| 2122 | *
|
|---|
| 2123 | * @private
|
|---|
| 2124 | * @name has
|
|---|
| 2125 | * @memberOf ListCache
|
|---|
| 2126 | * @param {string} key The key of the entry to check.
|
|---|
| 2127 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|---|
| 2128 | */
|
|---|
| 2129 | function listCacheHas(key) {
|
|---|
| 2130 | return assocIndexOf(this.__data__, key) > -1;
|
|---|
| 2131 | }
|
|---|
| 2132 |
|
|---|
| 2133 | /**
|
|---|
| 2134 | * Sets the list cache `key` to `value`.
|
|---|
| 2135 | *
|
|---|
| 2136 | * @private
|
|---|
| 2137 | * @name set
|
|---|
| 2138 | * @memberOf ListCache
|
|---|
| 2139 | * @param {string} key The key of the value to set.
|
|---|
| 2140 | * @param {*} value The value to set.
|
|---|
| 2141 | * @returns {Object} Returns the list cache instance.
|
|---|
| 2142 | */
|
|---|
| 2143 | function listCacheSet(key, value) {
|
|---|
| 2144 | var data = this.__data__,
|
|---|
| 2145 | index = assocIndexOf(data, key);
|
|---|
| 2146 |
|
|---|
| 2147 | if (index < 0) {
|
|---|
| 2148 | ++this.size;
|
|---|
| 2149 | data.push([key, value]);
|
|---|
| 2150 | } else {
|
|---|
| 2151 | data[index][1] = value;
|
|---|
| 2152 | }
|
|---|
| 2153 | return this;
|
|---|
| 2154 | }
|
|---|
| 2155 |
|
|---|
| 2156 | // Add methods to `ListCache`.
|
|---|
| 2157 | ListCache.prototype.clear = listCacheClear;
|
|---|
| 2158 | ListCache.prototype['delete'] = listCacheDelete;
|
|---|
| 2159 | ListCache.prototype.get = listCacheGet;
|
|---|
| 2160 | ListCache.prototype.has = listCacheHas;
|
|---|
| 2161 | ListCache.prototype.set = listCacheSet;
|
|---|
| 2162 |
|
|---|
| 2163 | /*------------------------------------------------------------------------*/
|
|---|
| 2164 |
|
|---|
| 2165 | /**
|
|---|
| 2166 | * Creates a map cache object to store key-value pairs.
|
|---|
| 2167 | *
|
|---|
| 2168 | * @private
|
|---|
| 2169 | * @constructor
|
|---|
| 2170 | * @param {Array} [entries] The key-value pairs to cache.
|
|---|
| 2171 | */
|
|---|
| 2172 | function MapCache(entries) {
|
|---|
| 2173 | var index = -1,
|
|---|
| 2174 | length = entries == null ? 0 : entries.length;
|
|---|
| 2175 |
|
|---|
| 2176 | this.clear();
|
|---|
| 2177 | while (++index < length) {
|
|---|
| 2178 | var entry = entries[index];
|
|---|
| 2179 | this.set(entry[0], entry[1]);
|
|---|
| 2180 | }
|
|---|
| 2181 | }
|
|---|
| 2182 |
|
|---|
| 2183 | /**
|
|---|
| 2184 | * Removes all key-value entries from the map.
|
|---|
| 2185 | *
|
|---|
| 2186 | * @private
|
|---|
| 2187 | * @name clear
|
|---|
| 2188 | * @memberOf MapCache
|
|---|
| 2189 | */
|
|---|
| 2190 | function mapCacheClear() {
|
|---|
| 2191 | this.size = 0;
|
|---|
| 2192 | this.__data__ = {
|
|---|
| 2193 | 'hash': new Hash,
|
|---|
| 2194 | 'map': new (Map || ListCache),
|
|---|
| 2195 | 'string': new Hash
|
|---|
| 2196 | };
|
|---|
| 2197 | }
|
|---|
| 2198 |
|
|---|
| 2199 | /**
|
|---|
| 2200 | * Removes `key` and its value from the map.
|
|---|
| 2201 | *
|
|---|
| 2202 | * @private
|
|---|
| 2203 | * @name delete
|
|---|
| 2204 | * @memberOf MapCache
|
|---|
| 2205 | * @param {string} key The key of the value to remove.
|
|---|
| 2206 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|---|
| 2207 | */
|
|---|
| 2208 | function mapCacheDelete(key) {
|
|---|
| 2209 | var result = getMapData(this, key)['delete'](key);
|
|---|
| 2210 | this.size -= result ? 1 : 0;
|
|---|
| 2211 | return result;
|
|---|
| 2212 | }
|
|---|
| 2213 |
|
|---|
| 2214 | /**
|
|---|
| 2215 | * Gets the map value for `key`.
|
|---|
| 2216 | *
|
|---|
| 2217 | * @private
|
|---|
| 2218 | * @name get
|
|---|
| 2219 | * @memberOf MapCache
|
|---|
| 2220 | * @param {string} key The key of the value to get.
|
|---|
| 2221 | * @returns {*} Returns the entry value.
|
|---|
| 2222 | */
|
|---|
| 2223 | function mapCacheGet(key) {
|
|---|
| 2224 | return getMapData(this, key).get(key);
|
|---|
| 2225 | }
|
|---|
| 2226 |
|
|---|
| 2227 | /**
|
|---|
| 2228 | * Checks if a map value for `key` exists.
|
|---|
| 2229 | *
|
|---|
| 2230 | * @private
|
|---|
| 2231 | * @name has
|
|---|
| 2232 | * @memberOf MapCache
|
|---|
| 2233 | * @param {string} key The key of the entry to check.
|
|---|
| 2234 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|---|
| 2235 | */
|
|---|
| 2236 | function mapCacheHas(key) {
|
|---|
| 2237 | return getMapData(this, key).has(key);
|
|---|
| 2238 | }
|
|---|
| 2239 |
|
|---|
| 2240 | /**
|
|---|
| 2241 | * Sets the map `key` to `value`.
|
|---|
| 2242 | *
|
|---|
| 2243 | * @private
|
|---|
| 2244 | * @name set
|
|---|
| 2245 | * @memberOf MapCache
|
|---|
| 2246 | * @param {string} key The key of the value to set.
|
|---|
| 2247 | * @param {*} value The value to set.
|
|---|
| 2248 | * @returns {Object} Returns the map cache instance.
|
|---|
| 2249 | */
|
|---|
| 2250 | function mapCacheSet(key, value) {
|
|---|
| 2251 | var data = getMapData(this, key),
|
|---|
| 2252 | size = data.size;
|
|---|
| 2253 |
|
|---|
| 2254 | data.set(key, value);
|
|---|
| 2255 | this.size += data.size == size ? 0 : 1;
|
|---|
| 2256 | return this;
|
|---|
| 2257 | }
|
|---|
| 2258 |
|
|---|
| 2259 | // Add methods to `MapCache`.
|
|---|
| 2260 | MapCache.prototype.clear = mapCacheClear;
|
|---|
| 2261 | MapCache.prototype['delete'] = mapCacheDelete;
|
|---|
| 2262 | MapCache.prototype.get = mapCacheGet;
|
|---|
| 2263 | MapCache.prototype.has = mapCacheHas;
|
|---|
| 2264 | MapCache.prototype.set = mapCacheSet;
|
|---|
| 2265 |
|
|---|
| 2266 | /*------------------------------------------------------------------------*/
|
|---|
| 2267 |
|
|---|
| 2268 | /**
|
|---|
| 2269 | *
|
|---|
| 2270 | * Creates an array cache object to store unique values.
|
|---|
| 2271 | *
|
|---|
| 2272 | * @private
|
|---|
| 2273 | * @constructor
|
|---|
| 2274 | * @param {Array} [values] The values to cache.
|
|---|
| 2275 | */
|
|---|
| 2276 | function SetCache(values) {
|
|---|
| 2277 | var index = -1,
|
|---|
| 2278 | length = values == null ? 0 : values.length;
|
|---|
| 2279 |
|
|---|
| 2280 | this.__data__ = new MapCache;
|
|---|
| 2281 | while (++index < length) {
|
|---|
| 2282 | this.add(values[index]);
|
|---|
| 2283 | }
|
|---|
| 2284 | }
|
|---|
| 2285 |
|
|---|
| 2286 | /**
|
|---|
| 2287 | * Adds `value` to the array cache.
|
|---|
| 2288 | *
|
|---|
| 2289 | * @private
|
|---|
| 2290 | * @name add
|
|---|
| 2291 | * @memberOf SetCache
|
|---|
| 2292 | * @alias push
|
|---|
| 2293 | * @param {*} value The value to cache.
|
|---|
| 2294 | * @returns {Object} Returns the cache instance.
|
|---|
| 2295 | */
|
|---|
| 2296 | function setCacheAdd(value) {
|
|---|
| 2297 | this.__data__.set(value, HASH_UNDEFINED);
|
|---|
| 2298 | return this;
|
|---|
| 2299 | }
|
|---|
| 2300 |
|
|---|
| 2301 | /**
|
|---|
| 2302 | * Checks if `value` is in the array cache.
|
|---|
| 2303 | *
|
|---|
| 2304 | * @private
|
|---|
| 2305 | * @name has
|
|---|
| 2306 | * @memberOf SetCache
|
|---|
| 2307 | * @param {*} value The value to search for.
|
|---|
| 2308 | * @returns {boolean} Returns `true` if `value` is found, else `false`.
|
|---|
| 2309 | */
|
|---|
| 2310 | function setCacheHas(value) {
|
|---|
| 2311 | return this.__data__.has(value);
|
|---|
| 2312 | }
|
|---|
| 2313 |
|
|---|
| 2314 | // Add methods to `SetCache`.
|
|---|
| 2315 | SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
|---|
| 2316 | SetCache.prototype.has = setCacheHas;
|
|---|
| 2317 |
|
|---|
| 2318 | /*------------------------------------------------------------------------*/
|
|---|
| 2319 |
|
|---|
| 2320 | /**
|
|---|
| 2321 | * Creates a stack cache object to store key-value pairs.
|
|---|
| 2322 | *
|
|---|
| 2323 | * @private
|
|---|
| 2324 | * @constructor
|
|---|
| 2325 | * @param {Array} [entries] The key-value pairs to cache.
|
|---|
| 2326 | */
|
|---|
| 2327 | function Stack(entries) {
|
|---|
| 2328 | var data = this.__data__ = new ListCache(entries);
|
|---|
| 2329 | this.size = data.size;
|
|---|
| 2330 | }
|
|---|
| 2331 |
|
|---|
| 2332 | /**
|
|---|
| 2333 | * Removes all key-value entries from the stack.
|
|---|
| 2334 | *
|
|---|
| 2335 | * @private
|
|---|
| 2336 | * @name clear
|
|---|
| 2337 | * @memberOf Stack
|
|---|
| 2338 | */
|
|---|
| 2339 | function stackClear() {
|
|---|
| 2340 | this.__data__ = new ListCache;
|
|---|
| 2341 | this.size = 0;
|
|---|
| 2342 | }
|
|---|
| 2343 |
|
|---|
| 2344 | /**
|
|---|
| 2345 | * Removes `key` and its value from the stack.
|
|---|
| 2346 | *
|
|---|
| 2347 | * @private
|
|---|
| 2348 | * @name delete
|
|---|
| 2349 | * @memberOf Stack
|
|---|
| 2350 | * @param {string} key The key of the value to remove.
|
|---|
| 2351 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|---|
| 2352 | */
|
|---|
| 2353 | function stackDelete(key) {
|
|---|
| 2354 | var data = this.__data__,
|
|---|
| 2355 | result = data['delete'](key);
|
|---|
| 2356 |
|
|---|
| 2357 | this.size = data.size;
|
|---|
| 2358 | return result;
|
|---|
| 2359 | }
|
|---|
| 2360 |
|
|---|
| 2361 | /**
|
|---|
| 2362 | * Gets the stack value for `key`.
|
|---|
| 2363 | *
|
|---|
| 2364 | * @private
|
|---|
| 2365 | * @name get
|
|---|
| 2366 | * @memberOf Stack
|
|---|
| 2367 | * @param {string} key The key of the value to get.
|
|---|
| 2368 | * @returns {*} Returns the entry value.
|
|---|
| 2369 | */
|
|---|
| 2370 | function stackGet(key) {
|
|---|
| 2371 | return this.__data__.get(key);
|
|---|
| 2372 | }
|
|---|
| 2373 |
|
|---|
| 2374 | /**
|
|---|
| 2375 | * Checks if a stack value for `key` exists.
|
|---|
| 2376 | *
|
|---|
| 2377 | * @private
|
|---|
| 2378 | * @name has
|
|---|
| 2379 | * @memberOf Stack
|
|---|
| 2380 | * @param {string} key The key of the entry to check.
|
|---|
| 2381 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
|---|
| 2382 | */
|
|---|
| 2383 | function stackHas(key) {
|
|---|
| 2384 | return this.__data__.has(key);
|
|---|
| 2385 | }
|
|---|
| 2386 |
|
|---|
| 2387 | /**
|
|---|
| 2388 | * Sets the stack `key` to `value`.
|
|---|
| 2389 | *
|
|---|
| 2390 | * @private
|
|---|
| 2391 | * @name set
|
|---|
| 2392 | * @memberOf Stack
|
|---|
| 2393 | * @param {string} key The key of the value to set.
|
|---|
| 2394 | * @param {*} value The value to set.
|
|---|
| 2395 | * @returns {Object} Returns the stack cache instance.
|
|---|
| 2396 | */
|
|---|
| 2397 | function stackSet(key, value) {
|
|---|
| 2398 | var data = this.__data__;
|
|---|
| 2399 | if (data instanceof ListCache) {
|
|---|
| 2400 | var pairs = data.__data__;
|
|---|
| 2401 | if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
|---|
| 2402 | pairs.push([key, value]);
|
|---|
| 2403 | this.size = ++data.size;
|
|---|
| 2404 | return this;
|
|---|
| 2405 | }
|
|---|
| 2406 | data = this.__data__ = new MapCache(pairs);
|
|---|
| 2407 | }
|
|---|
| 2408 | data.set(key, value);
|
|---|
| 2409 | this.size = data.size;
|
|---|
| 2410 | return this;
|
|---|
| 2411 | }
|
|---|
| 2412 |
|
|---|
| 2413 | // Add methods to `Stack`.
|
|---|
| 2414 | Stack.prototype.clear = stackClear;
|
|---|
| 2415 | Stack.prototype['delete'] = stackDelete;
|
|---|
| 2416 | Stack.prototype.get = stackGet;
|
|---|
| 2417 | Stack.prototype.has = stackHas;
|
|---|
| 2418 | Stack.prototype.set = stackSet;
|
|---|
| 2419 |
|
|---|
| 2420 | /*------------------------------------------------------------------------*/
|
|---|
| 2421 |
|
|---|
| 2422 | /**
|
|---|
| 2423 | * Creates an array of the enumerable property names of the array-like `value`.
|
|---|
| 2424 | *
|
|---|
| 2425 | * @private
|
|---|
| 2426 | * @param {*} value The value to query.
|
|---|
| 2427 | * @param {boolean} inherited Specify returning inherited property names.
|
|---|
| 2428 | * @returns {Array} Returns the array of property names.
|
|---|
| 2429 | */
|
|---|
| 2430 | function arrayLikeKeys(value, inherited) {
|
|---|
| 2431 | var isArr = isArray(value),
|
|---|
| 2432 | isArg = !isArr && isArguments(value),
|
|---|
| 2433 | isBuff = !isArr && !isArg && isBuffer(value),
|
|---|
| 2434 | isType = !isArr && !isArg && !isBuff && isTypedArray(value),
|
|---|
| 2435 | skipIndexes = isArr || isArg || isBuff || isType,
|
|---|
| 2436 | result = skipIndexes ? baseTimes(value.length, String) : [],
|
|---|
| 2437 | length = result.length;
|
|---|
| 2438 |
|
|---|
| 2439 | for (var key in value) {
|
|---|
| 2440 | if ((inherited || hasOwnProperty.call(value, key)) &&
|
|---|
| 2441 | !(skipIndexes && (
|
|---|
| 2442 | // Safari 9 has enumerable `arguments.length` in strict mode.
|
|---|
| 2443 | key == 'length' ||
|
|---|
| 2444 | // Node.js 0.10 has enumerable non-index properties on buffers.
|
|---|
| 2445 | (isBuff && (key == 'offset' || key == 'parent')) ||
|
|---|
| 2446 | // PhantomJS 2 has enumerable non-index properties on typed arrays.
|
|---|
| 2447 | (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
|
|---|
| 2448 | // Skip index properties.
|
|---|
| 2449 | isIndex(key, length)
|
|---|
| 2450 | ))) {
|
|---|
| 2451 | result.push(key);
|
|---|
| 2452 | }
|
|---|
| 2453 | }
|
|---|
| 2454 | return result;
|
|---|
| 2455 | }
|
|---|
| 2456 |
|
|---|
| 2457 | /**
|
|---|
| 2458 | * A specialized version of `_.sample` for arrays.
|
|---|
| 2459 | *
|
|---|
| 2460 | * @private
|
|---|
| 2461 | * @param {Array} array The array to sample.
|
|---|
| 2462 | * @returns {*} Returns the random element.
|
|---|
| 2463 | */
|
|---|
| 2464 | function arraySample(array) {
|
|---|
| 2465 | var length = array.length;
|
|---|
| 2466 | return length ? array[baseRandom(0, length - 1)] : undefined;
|
|---|
| 2467 | }
|
|---|
| 2468 |
|
|---|
| 2469 | /**
|
|---|
| 2470 | * A specialized version of `_.sampleSize` for arrays.
|
|---|
| 2471 | *
|
|---|
| 2472 | * @private
|
|---|
| 2473 | * @param {Array} array The array to sample.
|
|---|
| 2474 | * @param {number} n The number of elements to sample.
|
|---|
| 2475 | * @returns {Array} Returns the random elements.
|
|---|
| 2476 | */
|
|---|
| 2477 | function arraySampleSize(array, n) {
|
|---|
| 2478 | return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
|
|---|
| 2479 | }
|
|---|
| 2480 |
|
|---|
| 2481 | /**
|
|---|
| 2482 | * A specialized version of `_.shuffle` for arrays.
|
|---|
| 2483 | *
|
|---|
| 2484 | * @private
|
|---|
| 2485 | * @param {Array} array The array to shuffle.
|
|---|
| 2486 | * @returns {Array} Returns the new shuffled array.
|
|---|
| 2487 | */
|
|---|
| 2488 | function arrayShuffle(array) {
|
|---|
| 2489 | return shuffleSelf(copyArray(array));
|
|---|
| 2490 | }
|
|---|
| 2491 |
|
|---|
| 2492 | /**
|
|---|
| 2493 | * This function is like `assignValue` except that it doesn't assign
|
|---|
| 2494 | * `undefined` values.
|
|---|
| 2495 | *
|
|---|
| 2496 | * @private
|
|---|
| 2497 | * @param {Object} object The object to modify.
|
|---|
| 2498 | * @param {string} key The key of the property to assign.
|
|---|
| 2499 | * @param {*} value The value to assign.
|
|---|
| 2500 | */
|
|---|
| 2501 | function assignMergeValue(object, key, value) {
|
|---|
| 2502 | if ((value !== undefined && !eq(object[key], value)) ||
|
|---|
| 2503 | (value === undefined && !(key in object))) {
|
|---|
| 2504 | baseAssignValue(object, key, value);
|
|---|
| 2505 | }
|
|---|
| 2506 | }
|
|---|
| 2507 |
|
|---|
| 2508 | /**
|
|---|
| 2509 | * Assigns `value` to `key` of `object` if the existing value is not equivalent
|
|---|
| 2510 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 2511 | * for equality comparisons.
|
|---|
| 2512 | *
|
|---|
| 2513 | * @private
|
|---|
| 2514 | * @param {Object} object The object to modify.
|
|---|
| 2515 | * @param {string} key The key of the property to assign.
|
|---|
| 2516 | * @param {*} value The value to assign.
|
|---|
| 2517 | */
|
|---|
| 2518 | function assignValue(object, key, value) {
|
|---|
| 2519 | var objValue = object[key];
|
|---|
| 2520 | if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
|---|
| 2521 | (value === undefined && !(key in object))) {
|
|---|
| 2522 | baseAssignValue(object, key, value);
|
|---|
| 2523 | }
|
|---|
| 2524 | }
|
|---|
| 2525 |
|
|---|
| 2526 | /**
|
|---|
| 2527 | * Gets the index at which the `key` is found in `array` of key-value pairs.
|
|---|
| 2528 | *
|
|---|
| 2529 | * @private
|
|---|
| 2530 | * @param {Array} array The array to inspect.
|
|---|
| 2531 | * @param {*} key The key to search for.
|
|---|
| 2532 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 2533 | */
|
|---|
| 2534 | function assocIndexOf(array, key) {
|
|---|
| 2535 | var length = array.length;
|
|---|
| 2536 | while (length--) {
|
|---|
| 2537 | if (eq(array[length][0], key)) {
|
|---|
| 2538 | return length;
|
|---|
| 2539 | }
|
|---|
| 2540 | }
|
|---|
| 2541 | return -1;
|
|---|
| 2542 | }
|
|---|
| 2543 |
|
|---|
| 2544 | /**
|
|---|
| 2545 | * Aggregates elements of `collection` on `accumulator` with keys transformed
|
|---|
| 2546 | * by `iteratee` and values set by `setter`.
|
|---|
| 2547 | *
|
|---|
| 2548 | * @private
|
|---|
| 2549 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 2550 | * @param {Function} setter The function to set `accumulator` values.
|
|---|
| 2551 | * @param {Function} iteratee The iteratee to transform keys.
|
|---|
| 2552 | * @param {Object} accumulator The initial aggregated object.
|
|---|
| 2553 | * @returns {Function} Returns `accumulator`.
|
|---|
| 2554 | */
|
|---|
| 2555 | function baseAggregator(collection, setter, iteratee, accumulator) {
|
|---|
| 2556 | baseEach(collection, function(value, key, collection) {
|
|---|
| 2557 | setter(accumulator, value, iteratee(value), collection);
|
|---|
| 2558 | });
|
|---|
| 2559 | return accumulator;
|
|---|
| 2560 | }
|
|---|
| 2561 |
|
|---|
| 2562 | /**
|
|---|
| 2563 | * The base implementation of `_.assign` without support for multiple sources
|
|---|
| 2564 | * or `customizer` functions.
|
|---|
| 2565 | *
|
|---|
| 2566 | * @private
|
|---|
| 2567 | * @param {Object} object The destination object.
|
|---|
| 2568 | * @param {Object} source The source object.
|
|---|
| 2569 | * @returns {Object} Returns `object`.
|
|---|
| 2570 | */
|
|---|
| 2571 | function baseAssign(object, source) {
|
|---|
| 2572 | return object && copyObject(source, keys(source), object);
|
|---|
| 2573 | }
|
|---|
| 2574 |
|
|---|
| 2575 | /**
|
|---|
| 2576 | * The base implementation of `_.assignIn` without support for multiple sources
|
|---|
| 2577 | * or `customizer` functions.
|
|---|
| 2578 | *
|
|---|
| 2579 | * @private
|
|---|
| 2580 | * @param {Object} object The destination object.
|
|---|
| 2581 | * @param {Object} source The source object.
|
|---|
| 2582 | * @returns {Object} Returns `object`.
|
|---|
| 2583 | */
|
|---|
| 2584 | function baseAssignIn(object, source) {
|
|---|
| 2585 | return object && copyObject(source, keysIn(source), object);
|
|---|
| 2586 | }
|
|---|
| 2587 |
|
|---|
| 2588 | /**
|
|---|
| 2589 | * The base implementation of `assignValue` and `assignMergeValue` without
|
|---|
| 2590 | * value checks.
|
|---|
| 2591 | *
|
|---|
| 2592 | * @private
|
|---|
| 2593 | * @param {Object} object The object to modify.
|
|---|
| 2594 | * @param {string} key The key of the property to assign.
|
|---|
| 2595 | * @param {*} value The value to assign.
|
|---|
| 2596 | */
|
|---|
| 2597 | function baseAssignValue(object, key, value) {
|
|---|
| 2598 | if (key == '__proto__' && defineProperty) {
|
|---|
| 2599 | defineProperty(object, key, {
|
|---|
| 2600 | 'configurable': true,
|
|---|
| 2601 | 'enumerable': true,
|
|---|
| 2602 | 'value': value,
|
|---|
| 2603 | 'writable': true
|
|---|
| 2604 | });
|
|---|
| 2605 | } else {
|
|---|
| 2606 | object[key] = value;
|
|---|
| 2607 | }
|
|---|
| 2608 | }
|
|---|
| 2609 |
|
|---|
| 2610 | /**
|
|---|
| 2611 | * The base implementation of `_.at` without support for individual paths.
|
|---|
| 2612 | *
|
|---|
| 2613 | * @private
|
|---|
| 2614 | * @param {Object} object The object to iterate over.
|
|---|
| 2615 | * @param {string[]} paths The property paths to pick.
|
|---|
| 2616 | * @returns {Array} Returns the picked elements.
|
|---|
| 2617 | */
|
|---|
| 2618 | function baseAt(object, paths) {
|
|---|
| 2619 | var index = -1,
|
|---|
| 2620 | length = paths.length,
|
|---|
| 2621 | result = Array(length),
|
|---|
| 2622 | skip = object == null;
|
|---|
| 2623 |
|
|---|
| 2624 | while (++index < length) {
|
|---|
| 2625 | result[index] = skip ? undefined : get(object, paths[index]);
|
|---|
| 2626 | }
|
|---|
| 2627 | return result;
|
|---|
| 2628 | }
|
|---|
| 2629 |
|
|---|
| 2630 | /**
|
|---|
| 2631 | * The base implementation of `_.clamp` which doesn't coerce arguments.
|
|---|
| 2632 | *
|
|---|
| 2633 | * @private
|
|---|
| 2634 | * @param {number} number The number to clamp.
|
|---|
| 2635 | * @param {number} [lower] The lower bound.
|
|---|
| 2636 | * @param {number} upper The upper bound.
|
|---|
| 2637 | * @returns {number} Returns the clamped number.
|
|---|
| 2638 | */
|
|---|
| 2639 | function baseClamp(number, lower, upper) {
|
|---|
| 2640 | if (number === number) {
|
|---|
| 2641 | if (upper !== undefined) {
|
|---|
| 2642 | number = number <= upper ? number : upper;
|
|---|
| 2643 | }
|
|---|
| 2644 | if (lower !== undefined) {
|
|---|
| 2645 | number = number >= lower ? number : lower;
|
|---|
| 2646 | }
|
|---|
| 2647 | }
|
|---|
| 2648 | return number;
|
|---|
| 2649 | }
|
|---|
| 2650 |
|
|---|
| 2651 | /**
|
|---|
| 2652 | * The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
|---|
| 2653 | * traversed objects.
|
|---|
| 2654 | *
|
|---|
| 2655 | * @private
|
|---|
| 2656 | * @param {*} value The value to clone.
|
|---|
| 2657 | * @param {boolean} bitmask The bitmask flags.
|
|---|
| 2658 | * 1 - Deep clone
|
|---|
| 2659 | * 2 - Flatten inherited properties
|
|---|
| 2660 | * 4 - Clone symbols
|
|---|
| 2661 | * @param {Function} [customizer] The function to customize cloning.
|
|---|
| 2662 | * @param {string} [key] The key of `value`.
|
|---|
| 2663 | * @param {Object} [object] The parent object of `value`.
|
|---|
| 2664 | * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
|---|
| 2665 | * @returns {*} Returns the cloned value.
|
|---|
| 2666 | */
|
|---|
| 2667 | function baseClone(value, bitmask, customizer, key, object, stack) {
|
|---|
| 2668 | var result,
|
|---|
| 2669 | isDeep = bitmask & CLONE_DEEP_FLAG,
|
|---|
| 2670 | isFlat = bitmask & CLONE_FLAT_FLAG,
|
|---|
| 2671 | isFull = bitmask & CLONE_SYMBOLS_FLAG;
|
|---|
| 2672 |
|
|---|
| 2673 | if (customizer) {
|
|---|
| 2674 | result = object ? customizer(value, key, object, stack) : customizer(value);
|
|---|
| 2675 | }
|
|---|
| 2676 | if (result !== undefined) {
|
|---|
| 2677 | return result;
|
|---|
| 2678 | }
|
|---|
| 2679 | if (!isObject(value)) {
|
|---|
| 2680 | return value;
|
|---|
| 2681 | }
|
|---|
| 2682 | var isArr = isArray(value);
|
|---|
| 2683 | if (isArr) {
|
|---|
| 2684 | result = initCloneArray(value);
|
|---|
| 2685 | if (!isDeep) {
|
|---|
| 2686 | return copyArray(value, result);
|
|---|
| 2687 | }
|
|---|
| 2688 | } else {
|
|---|
| 2689 | var tag = getTag(value),
|
|---|
| 2690 | isFunc = tag == funcTag || tag == genTag;
|
|---|
| 2691 |
|
|---|
| 2692 | if (isBuffer(value)) {
|
|---|
| 2693 | return cloneBuffer(value, isDeep);
|
|---|
| 2694 | }
|
|---|
| 2695 | if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
|---|
| 2696 | result = (isFlat || isFunc) ? {} : initCloneObject(value);
|
|---|
| 2697 | if (!isDeep) {
|
|---|
| 2698 | return isFlat
|
|---|
| 2699 | ? copySymbolsIn(value, baseAssignIn(result, value))
|
|---|
| 2700 | : copySymbols(value, baseAssign(result, value));
|
|---|
| 2701 | }
|
|---|
| 2702 | } else {
|
|---|
| 2703 | if (!cloneableTags[tag]) {
|
|---|
| 2704 | return object ? value : {};
|
|---|
| 2705 | }
|
|---|
| 2706 | result = initCloneByTag(value, tag, isDeep);
|
|---|
| 2707 | }
|
|---|
| 2708 | }
|
|---|
| 2709 | // Check for circular references and return its corresponding clone.
|
|---|
| 2710 | stack || (stack = new Stack);
|
|---|
| 2711 | var stacked = stack.get(value);
|
|---|
| 2712 | if (stacked) {
|
|---|
| 2713 | return stacked;
|
|---|
| 2714 | }
|
|---|
| 2715 | stack.set(value, result);
|
|---|
| 2716 |
|
|---|
| 2717 | if (isSet(value)) {
|
|---|
| 2718 | value.forEach(function(subValue) {
|
|---|
| 2719 | result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
|
|---|
| 2720 | });
|
|---|
| 2721 | } else if (isMap(value)) {
|
|---|
| 2722 | value.forEach(function(subValue, key) {
|
|---|
| 2723 | result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
|
|---|
| 2724 | });
|
|---|
| 2725 | }
|
|---|
| 2726 |
|
|---|
| 2727 | var keysFunc = isFull
|
|---|
| 2728 | ? (isFlat ? getAllKeysIn : getAllKeys)
|
|---|
| 2729 | : (isFlat ? keysIn : keys);
|
|---|
| 2730 |
|
|---|
| 2731 | var props = isArr ? undefined : keysFunc(value);
|
|---|
| 2732 | arrayEach(props || value, function(subValue, key) {
|
|---|
| 2733 | if (props) {
|
|---|
| 2734 | key = subValue;
|
|---|
| 2735 | subValue = value[key];
|
|---|
| 2736 | }
|
|---|
| 2737 | // Recursively populate clone (susceptible to call stack limits).
|
|---|
| 2738 | assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
|
|---|
| 2739 | });
|
|---|
| 2740 | return result;
|
|---|
| 2741 | }
|
|---|
| 2742 |
|
|---|
| 2743 | /**
|
|---|
| 2744 | * The base implementation of `_.conforms` which doesn't clone `source`.
|
|---|
| 2745 | *
|
|---|
| 2746 | * @private
|
|---|
| 2747 | * @param {Object} source The object of property predicates to conform to.
|
|---|
| 2748 | * @returns {Function} Returns the new spec function.
|
|---|
| 2749 | */
|
|---|
| 2750 | function baseConforms(source) {
|
|---|
| 2751 | var props = keys(source);
|
|---|
| 2752 | return function(object) {
|
|---|
| 2753 | return baseConformsTo(object, source, props);
|
|---|
| 2754 | };
|
|---|
| 2755 | }
|
|---|
| 2756 |
|
|---|
| 2757 | /**
|
|---|
| 2758 | * The base implementation of `_.conformsTo` which accepts `props` to check.
|
|---|
| 2759 | *
|
|---|
| 2760 | * @private
|
|---|
| 2761 | * @param {Object} object The object to inspect.
|
|---|
| 2762 | * @param {Object} source The object of property predicates to conform to.
|
|---|
| 2763 | * @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
|---|
| 2764 | */
|
|---|
| 2765 | function baseConformsTo(object, source, props) {
|
|---|
| 2766 | var length = props.length;
|
|---|
| 2767 | if (object == null) {
|
|---|
| 2768 | return !length;
|
|---|
| 2769 | }
|
|---|
| 2770 | object = Object(object);
|
|---|
| 2771 | while (length--) {
|
|---|
| 2772 | var key = props[length],
|
|---|
| 2773 | predicate = source[key],
|
|---|
| 2774 | value = object[key];
|
|---|
| 2775 |
|
|---|
| 2776 | if ((value === undefined && !(key in object)) || !predicate(value)) {
|
|---|
| 2777 | return false;
|
|---|
| 2778 | }
|
|---|
| 2779 | }
|
|---|
| 2780 | return true;
|
|---|
| 2781 | }
|
|---|
| 2782 |
|
|---|
| 2783 | /**
|
|---|
| 2784 | * The base implementation of `_.delay` and `_.defer` which accepts `args`
|
|---|
| 2785 | * to provide to `func`.
|
|---|
| 2786 | *
|
|---|
| 2787 | * @private
|
|---|
| 2788 | * @param {Function} func The function to delay.
|
|---|
| 2789 | * @param {number} wait The number of milliseconds to delay invocation.
|
|---|
| 2790 | * @param {Array} args The arguments to provide to `func`.
|
|---|
| 2791 | * @returns {number|Object} Returns the timer id or timeout object.
|
|---|
| 2792 | */
|
|---|
| 2793 | function baseDelay(func, wait, args) {
|
|---|
| 2794 | if (typeof func != 'function') {
|
|---|
| 2795 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 2796 | }
|
|---|
| 2797 | return setTimeout(function() { func.apply(undefined, args); }, wait);
|
|---|
| 2798 | }
|
|---|
| 2799 |
|
|---|
| 2800 | /**
|
|---|
| 2801 | * The base implementation of methods like `_.difference` without support
|
|---|
| 2802 | * for excluding multiple arrays or iteratee shorthands.
|
|---|
| 2803 | *
|
|---|
| 2804 | * @private
|
|---|
| 2805 | * @param {Array} array The array to inspect.
|
|---|
| 2806 | * @param {Array} values The values to exclude.
|
|---|
| 2807 | * @param {Function} [iteratee] The iteratee invoked per element.
|
|---|
| 2808 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 2809 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 2810 | */
|
|---|
| 2811 | function baseDifference(array, values, iteratee, comparator) {
|
|---|
| 2812 | var index = -1,
|
|---|
| 2813 | includes = arrayIncludes,
|
|---|
| 2814 | isCommon = true,
|
|---|
| 2815 | length = array.length,
|
|---|
| 2816 | result = [],
|
|---|
| 2817 | valuesLength = values.length;
|
|---|
| 2818 |
|
|---|
| 2819 | if (!length) {
|
|---|
| 2820 | return result;
|
|---|
| 2821 | }
|
|---|
| 2822 | if (iteratee) {
|
|---|
| 2823 | values = arrayMap(values, baseUnary(iteratee));
|
|---|
| 2824 | }
|
|---|
| 2825 | if (comparator) {
|
|---|
| 2826 | includes = arrayIncludesWith;
|
|---|
| 2827 | isCommon = false;
|
|---|
| 2828 | }
|
|---|
| 2829 | else if (values.length >= LARGE_ARRAY_SIZE) {
|
|---|
| 2830 | includes = cacheHas;
|
|---|
| 2831 | isCommon = false;
|
|---|
| 2832 | values = new SetCache(values);
|
|---|
| 2833 | }
|
|---|
| 2834 | outer:
|
|---|
| 2835 | while (++index < length) {
|
|---|
| 2836 | var value = array[index],
|
|---|
| 2837 | computed = iteratee == null ? value : iteratee(value);
|
|---|
| 2838 |
|
|---|
| 2839 | value = (comparator || value !== 0) ? value : 0;
|
|---|
| 2840 | if (isCommon && computed === computed) {
|
|---|
| 2841 | var valuesIndex = valuesLength;
|
|---|
| 2842 | while (valuesIndex--) {
|
|---|
| 2843 | if (values[valuesIndex] === computed) {
|
|---|
| 2844 | continue outer;
|
|---|
| 2845 | }
|
|---|
| 2846 | }
|
|---|
| 2847 | result.push(value);
|
|---|
| 2848 | }
|
|---|
| 2849 | else if (!includes(values, computed, comparator)) {
|
|---|
| 2850 | result.push(value);
|
|---|
| 2851 | }
|
|---|
| 2852 | }
|
|---|
| 2853 | return result;
|
|---|
| 2854 | }
|
|---|
| 2855 |
|
|---|
| 2856 | /**
|
|---|
| 2857 | * The base implementation of `_.forEach` without support for iteratee shorthands.
|
|---|
| 2858 | *
|
|---|
| 2859 | * @private
|
|---|
| 2860 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 2861 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 2862 | * @returns {Array|Object} Returns `collection`.
|
|---|
| 2863 | */
|
|---|
| 2864 | var baseEach = createBaseEach(baseForOwn);
|
|---|
| 2865 |
|
|---|
| 2866 | /**
|
|---|
| 2867 | * The base implementation of `_.forEachRight` without support for iteratee shorthands.
|
|---|
| 2868 | *
|
|---|
| 2869 | * @private
|
|---|
| 2870 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 2871 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 2872 | * @returns {Array|Object} Returns `collection`.
|
|---|
| 2873 | */
|
|---|
| 2874 | var baseEachRight = createBaseEach(baseForOwnRight, true);
|
|---|
| 2875 |
|
|---|
| 2876 | /**
|
|---|
| 2877 | * The base implementation of `_.every` without support for iteratee shorthands.
|
|---|
| 2878 | *
|
|---|
| 2879 | * @private
|
|---|
| 2880 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 2881 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 2882 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
|---|
| 2883 | * else `false`
|
|---|
| 2884 | */
|
|---|
| 2885 | function baseEvery(collection, predicate) {
|
|---|
| 2886 | var result = true;
|
|---|
| 2887 | baseEach(collection, function(value, index, collection) {
|
|---|
| 2888 | result = !!predicate(value, index, collection);
|
|---|
| 2889 | return result;
|
|---|
| 2890 | });
|
|---|
| 2891 | return result;
|
|---|
| 2892 | }
|
|---|
| 2893 |
|
|---|
| 2894 | /**
|
|---|
| 2895 | * The base implementation of methods like `_.max` and `_.min` which accepts a
|
|---|
| 2896 | * `comparator` to determine the extremum value.
|
|---|
| 2897 | *
|
|---|
| 2898 | * @private
|
|---|
| 2899 | * @param {Array} array The array to iterate over.
|
|---|
| 2900 | * @param {Function} iteratee The iteratee invoked per iteration.
|
|---|
| 2901 | * @param {Function} comparator The comparator used to compare values.
|
|---|
| 2902 | * @returns {*} Returns the extremum value.
|
|---|
| 2903 | */
|
|---|
| 2904 | function baseExtremum(array, iteratee, comparator) {
|
|---|
| 2905 | var index = -1,
|
|---|
| 2906 | length = array.length;
|
|---|
| 2907 |
|
|---|
| 2908 | while (++index < length) {
|
|---|
| 2909 | var value = array[index],
|
|---|
| 2910 | current = iteratee(value);
|
|---|
| 2911 |
|
|---|
| 2912 | if (current != null && (computed === undefined
|
|---|
| 2913 | ? (current === current && !isSymbol(current))
|
|---|
| 2914 | : comparator(current, computed)
|
|---|
| 2915 | )) {
|
|---|
| 2916 | var computed = current,
|
|---|
| 2917 | result = value;
|
|---|
| 2918 | }
|
|---|
| 2919 | }
|
|---|
| 2920 | return result;
|
|---|
| 2921 | }
|
|---|
| 2922 |
|
|---|
| 2923 | /**
|
|---|
| 2924 | * The base implementation of `_.fill` without an iteratee call guard.
|
|---|
| 2925 | *
|
|---|
| 2926 | * @private
|
|---|
| 2927 | * @param {Array} array The array to fill.
|
|---|
| 2928 | * @param {*} value The value to fill `array` with.
|
|---|
| 2929 | * @param {number} [start=0] The start position.
|
|---|
| 2930 | * @param {number} [end=array.length] The end position.
|
|---|
| 2931 | * @returns {Array} Returns `array`.
|
|---|
| 2932 | */
|
|---|
| 2933 | function baseFill(array, value, start, end) {
|
|---|
| 2934 | var length = array.length;
|
|---|
| 2935 |
|
|---|
| 2936 | start = toInteger(start);
|
|---|
| 2937 | if (start < 0) {
|
|---|
| 2938 | start = -start > length ? 0 : (length + start);
|
|---|
| 2939 | }
|
|---|
| 2940 | end = (end === undefined || end > length) ? length : toInteger(end);
|
|---|
| 2941 | if (end < 0) {
|
|---|
| 2942 | end += length;
|
|---|
| 2943 | }
|
|---|
| 2944 | end = start > end ? 0 : toLength(end);
|
|---|
| 2945 | while (start < end) {
|
|---|
| 2946 | array[start++] = value;
|
|---|
| 2947 | }
|
|---|
| 2948 | return array;
|
|---|
| 2949 | }
|
|---|
| 2950 |
|
|---|
| 2951 | /**
|
|---|
| 2952 | * The base implementation of `_.filter` without support for iteratee shorthands.
|
|---|
| 2953 | *
|
|---|
| 2954 | * @private
|
|---|
| 2955 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 2956 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 2957 | * @returns {Array} Returns the new filtered array.
|
|---|
| 2958 | */
|
|---|
| 2959 | function baseFilter(collection, predicate) {
|
|---|
| 2960 | var result = [];
|
|---|
| 2961 | baseEach(collection, function(value, index, collection) {
|
|---|
| 2962 | if (predicate(value, index, collection)) {
|
|---|
| 2963 | result.push(value);
|
|---|
| 2964 | }
|
|---|
| 2965 | });
|
|---|
| 2966 | return result;
|
|---|
| 2967 | }
|
|---|
| 2968 |
|
|---|
| 2969 | /**
|
|---|
| 2970 | * The base implementation of `_.flatten` with support for restricting flattening.
|
|---|
| 2971 | *
|
|---|
| 2972 | * @private
|
|---|
| 2973 | * @param {Array} array The array to flatten.
|
|---|
| 2974 | * @param {number} depth The maximum recursion depth.
|
|---|
| 2975 | * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
|
|---|
| 2976 | * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
|
|---|
| 2977 | * @param {Array} [result=[]] The initial result value.
|
|---|
| 2978 | * @returns {Array} Returns the new flattened array.
|
|---|
| 2979 | */
|
|---|
| 2980 | function baseFlatten(array, depth, predicate, isStrict, result) {
|
|---|
| 2981 | var index = -1,
|
|---|
| 2982 | length = array.length;
|
|---|
| 2983 |
|
|---|
| 2984 | predicate || (predicate = isFlattenable);
|
|---|
| 2985 | result || (result = []);
|
|---|
| 2986 |
|
|---|
| 2987 | while (++index < length) {
|
|---|
| 2988 | var value = array[index];
|
|---|
| 2989 | if (depth > 0 && predicate(value)) {
|
|---|
| 2990 | if (depth > 1) {
|
|---|
| 2991 | // Recursively flatten arrays (susceptible to call stack limits).
|
|---|
| 2992 | baseFlatten(value, depth - 1, predicate, isStrict, result);
|
|---|
| 2993 | } else {
|
|---|
| 2994 | arrayPush(result, value);
|
|---|
| 2995 | }
|
|---|
| 2996 | } else if (!isStrict) {
|
|---|
| 2997 | result[result.length] = value;
|
|---|
| 2998 | }
|
|---|
| 2999 | }
|
|---|
| 3000 | return result;
|
|---|
| 3001 | }
|
|---|
| 3002 |
|
|---|
| 3003 | /**
|
|---|
| 3004 | * The base implementation of `baseForOwn` which iterates over `object`
|
|---|
| 3005 | * properties returned by `keysFunc` and invokes `iteratee` for each property.
|
|---|
| 3006 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
|---|
| 3007 | *
|
|---|
| 3008 | * @private
|
|---|
| 3009 | * @param {Object} object The object to iterate over.
|
|---|
| 3010 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 3011 | * @param {Function} keysFunc The function to get the keys of `object`.
|
|---|
| 3012 | * @returns {Object} Returns `object`.
|
|---|
| 3013 | */
|
|---|
| 3014 | var baseFor = createBaseFor();
|
|---|
| 3015 |
|
|---|
| 3016 | /**
|
|---|
| 3017 | * This function is like `baseFor` except that it iterates over properties
|
|---|
| 3018 | * in the opposite order.
|
|---|
| 3019 | *
|
|---|
| 3020 | * @private
|
|---|
| 3021 | * @param {Object} object The object to iterate over.
|
|---|
| 3022 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 3023 | * @param {Function} keysFunc The function to get the keys of `object`.
|
|---|
| 3024 | * @returns {Object} Returns `object`.
|
|---|
| 3025 | */
|
|---|
| 3026 | var baseForRight = createBaseFor(true);
|
|---|
| 3027 |
|
|---|
| 3028 | /**
|
|---|
| 3029 | * The base implementation of `_.forOwn` without support for iteratee shorthands.
|
|---|
| 3030 | *
|
|---|
| 3031 | * @private
|
|---|
| 3032 | * @param {Object} object The object to iterate over.
|
|---|
| 3033 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 3034 | * @returns {Object} Returns `object`.
|
|---|
| 3035 | */
|
|---|
| 3036 | function baseForOwn(object, iteratee) {
|
|---|
| 3037 | return object && baseFor(object, iteratee, keys);
|
|---|
| 3038 | }
|
|---|
| 3039 |
|
|---|
| 3040 | /**
|
|---|
| 3041 | * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
|
|---|
| 3042 | *
|
|---|
| 3043 | * @private
|
|---|
| 3044 | * @param {Object} object The object to iterate over.
|
|---|
| 3045 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 3046 | * @returns {Object} Returns `object`.
|
|---|
| 3047 | */
|
|---|
| 3048 | function baseForOwnRight(object, iteratee) {
|
|---|
| 3049 | return object && baseForRight(object, iteratee, keys);
|
|---|
| 3050 | }
|
|---|
| 3051 |
|
|---|
| 3052 | /**
|
|---|
| 3053 | * The base implementation of `_.functions` which creates an array of
|
|---|
| 3054 | * `object` function property names filtered from `props`.
|
|---|
| 3055 | *
|
|---|
| 3056 | * @private
|
|---|
| 3057 | * @param {Object} object The object to inspect.
|
|---|
| 3058 | * @param {Array} props The property names to filter.
|
|---|
| 3059 | * @returns {Array} Returns the function names.
|
|---|
| 3060 | */
|
|---|
| 3061 | function baseFunctions(object, props) {
|
|---|
| 3062 | return arrayFilter(props, function(key) {
|
|---|
| 3063 | return isFunction(object[key]);
|
|---|
| 3064 | });
|
|---|
| 3065 | }
|
|---|
| 3066 |
|
|---|
| 3067 | /**
|
|---|
| 3068 | * The base implementation of `_.get` without support for default values.
|
|---|
| 3069 | *
|
|---|
| 3070 | * @private
|
|---|
| 3071 | * @param {Object} object The object to query.
|
|---|
| 3072 | * @param {Array|string} path The path of the property to get.
|
|---|
| 3073 | * @returns {*} Returns the resolved value.
|
|---|
| 3074 | */
|
|---|
| 3075 | function baseGet(object, path) {
|
|---|
| 3076 | path = castPath(path, object);
|
|---|
| 3077 |
|
|---|
| 3078 | var index = 0,
|
|---|
| 3079 | length = path.length;
|
|---|
| 3080 |
|
|---|
| 3081 | while (object != null && index < length) {
|
|---|
| 3082 | object = object[toKey(path[index++])];
|
|---|
| 3083 | }
|
|---|
| 3084 | return (index && index == length) ? object : undefined;
|
|---|
| 3085 | }
|
|---|
| 3086 |
|
|---|
| 3087 | /**
|
|---|
| 3088 | * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
|---|
| 3089 | * `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
|---|
| 3090 | * symbols of `object`.
|
|---|
| 3091 | *
|
|---|
| 3092 | * @private
|
|---|
| 3093 | * @param {Object} object The object to query.
|
|---|
| 3094 | * @param {Function} keysFunc The function to get the keys of `object`.
|
|---|
| 3095 | * @param {Function} symbolsFunc The function to get the symbols of `object`.
|
|---|
| 3096 | * @returns {Array} Returns the array of property names and symbols.
|
|---|
| 3097 | */
|
|---|
| 3098 | function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
|---|
| 3099 | var result = keysFunc(object);
|
|---|
| 3100 | return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
|---|
| 3101 | }
|
|---|
| 3102 |
|
|---|
| 3103 | /**
|
|---|
| 3104 | * The base implementation of `getTag` without fallbacks for buggy environments.
|
|---|
| 3105 | *
|
|---|
| 3106 | * @private
|
|---|
| 3107 | * @param {*} value The value to query.
|
|---|
| 3108 | * @returns {string} Returns the `toStringTag`.
|
|---|
| 3109 | */
|
|---|
| 3110 | function baseGetTag(value) {
|
|---|
| 3111 | if (value == null) {
|
|---|
| 3112 | return value === undefined ? undefinedTag : nullTag;
|
|---|
| 3113 | }
|
|---|
| 3114 | return (symToStringTag && symToStringTag in Object(value))
|
|---|
| 3115 | ? getRawTag(value)
|
|---|
| 3116 | : objectToString(value);
|
|---|
| 3117 | }
|
|---|
| 3118 |
|
|---|
| 3119 | /**
|
|---|
| 3120 | * The base implementation of `_.gt` which doesn't coerce arguments.
|
|---|
| 3121 | *
|
|---|
| 3122 | * @private
|
|---|
| 3123 | * @param {*} value The value to compare.
|
|---|
| 3124 | * @param {*} other The other value to compare.
|
|---|
| 3125 | * @returns {boolean} Returns `true` if `value` is greater than `other`,
|
|---|
| 3126 | * else `false`.
|
|---|
| 3127 | */
|
|---|
| 3128 | function baseGt(value, other) {
|
|---|
| 3129 | return value > other;
|
|---|
| 3130 | }
|
|---|
| 3131 |
|
|---|
| 3132 | /**
|
|---|
| 3133 | * The base implementation of `_.has` without support for deep paths.
|
|---|
| 3134 | *
|
|---|
| 3135 | * @private
|
|---|
| 3136 | * @param {Object} [object] The object to query.
|
|---|
| 3137 | * @param {Array|string} key The key to check.
|
|---|
| 3138 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
|---|
| 3139 | */
|
|---|
| 3140 | function baseHas(object, key) {
|
|---|
| 3141 | return object != null && hasOwnProperty.call(object, key);
|
|---|
| 3142 | }
|
|---|
| 3143 |
|
|---|
| 3144 | /**
|
|---|
| 3145 | * The base implementation of `_.hasIn` without support for deep paths.
|
|---|
| 3146 | *
|
|---|
| 3147 | * @private
|
|---|
| 3148 | * @param {Object} [object] The object to query.
|
|---|
| 3149 | * @param {Array|string} key The key to check.
|
|---|
| 3150 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
|---|
| 3151 | */
|
|---|
| 3152 | function baseHasIn(object, key) {
|
|---|
| 3153 | return object != null && key in Object(object);
|
|---|
| 3154 | }
|
|---|
| 3155 |
|
|---|
| 3156 | /**
|
|---|
| 3157 | * The base implementation of `_.inRange` which doesn't coerce arguments.
|
|---|
| 3158 | *
|
|---|
| 3159 | * @private
|
|---|
| 3160 | * @param {number} number The number to check.
|
|---|
| 3161 | * @param {number} start The start of the range.
|
|---|
| 3162 | * @param {number} end The end of the range.
|
|---|
| 3163 | * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
|
|---|
| 3164 | */
|
|---|
| 3165 | function baseInRange(number, start, end) {
|
|---|
| 3166 | return number >= nativeMin(start, end) && number < nativeMax(start, end);
|
|---|
| 3167 | }
|
|---|
| 3168 |
|
|---|
| 3169 | /**
|
|---|
| 3170 | * The base implementation of methods like `_.intersection`, without support
|
|---|
| 3171 | * for iteratee shorthands, that accepts an array of arrays to inspect.
|
|---|
| 3172 | *
|
|---|
| 3173 | * @private
|
|---|
| 3174 | * @param {Array} arrays The arrays to inspect.
|
|---|
| 3175 | * @param {Function} [iteratee] The iteratee invoked per element.
|
|---|
| 3176 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 3177 | * @returns {Array} Returns the new array of shared values.
|
|---|
| 3178 | */
|
|---|
| 3179 | function baseIntersection(arrays, iteratee, comparator) {
|
|---|
| 3180 | var includes = comparator ? arrayIncludesWith : arrayIncludes,
|
|---|
| 3181 | length = arrays[0].length,
|
|---|
| 3182 | othLength = arrays.length,
|
|---|
| 3183 | othIndex = othLength,
|
|---|
| 3184 | caches = Array(othLength),
|
|---|
| 3185 | maxLength = Infinity,
|
|---|
| 3186 | result = [];
|
|---|
| 3187 |
|
|---|
| 3188 | while (othIndex--) {
|
|---|
| 3189 | var array = arrays[othIndex];
|
|---|
| 3190 | if (othIndex && iteratee) {
|
|---|
| 3191 | array = arrayMap(array, baseUnary(iteratee));
|
|---|
| 3192 | }
|
|---|
| 3193 | maxLength = nativeMin(array.length, maxLength);
|
|---|
| 3194 | caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
|
|---|
| 3195 | ? new SetCache(othIndex && array)
|
|---|
| 3196 | : undefined;
|
|---|
| 3197 | }
|
|---|
| 3198 | array = arrays[0];
|
|---|
| 3199 |
|
|---|
| 3200 | var index = -1,
|
|---|
| 3201 | seen = caches[0];
|
|---|
| 3202 |
|
|---|
| 3203 | outer:
|
|---|
| 3204 | while (++index < length && result.length < maxLength) {
|
|---|
| 3205 | var value = array[index],
|
|---|
| 3206 | computed = iteratee ? iteratee(value) : value;
|
|---|
| 3207 |
|
|---|
| 3208 | value = (comparator || value !== 0) ? value : 0;
|
|---|
| 3209 | if (!(seen
|
|---|
| 3210 | ? cacheHas(seen, computed)
|
|---|
| 3211 | : includes(result, computed, comparator)
|
|---|
| 3212 | )) {
|
|---|
| 3213 | othIndex = othLength;
|
|---|
| 3214 | while (--othIndex) {
|
|---|
| 3215 | var cache = caches[othIndex];
|
|---|
| 3216 | if (!(cache
|
|---|
| 3217 | ? cacheHas(cache, computed)
|
|---|
| 3218 | : includes(arrays[othIndex], computed, comparator))
|
|---|
| 3219 | ) {
|
|---|
| 3220 | continue outer;
|
|---|
| 3221 | }
|
|---|
| 3222 | }
|
|---|
| 3223 | if (seen) {
|
|---|
| 3224 | seen.push(computed);
|
|---|
| 3225 | }
|
|---|
| 3226 | result.push(value);
|
|---|
| 3227 | }
|
|---|
| 3228 | }
|
|---|
| 3229 | return result;
|
|---|
| 3230 | }
|
|---|
| 3231 |
|
|---|
| 3232 | /**
|
|---|
| 3233 | * The base implementation of `_.invert` and `_.invertBy` which inverts
|
|---|
| 3234 | * `object` with values transformed by `iteratee` and set by `setter`.
|
|---|
| 3235 | *
|
|---|
| 3236 | * @private
|
|---|
| 3237 | * @param {Object} object The object to iterate over.
|
|---|
| 3238 | * @param {Function} setter The function to set `accumulator` values.
|
|---|
| 3239 | * @param {Function} iteratee The iteratee to transform values.
|
|---|
| 3240 | * @param {Object} accumulator The initial inverted object.
|
|---|
| 3241 | * @returns {Function} Returns `accumulator`.
|
|---|
| 3242 | */
|
|---|
| 3243 | function baseInverter(object, setter, iteratee, accumulator) {
|
|---|
| 3244 | baseForOwn(object, function(value, key, object) {
|
|---|
| 3245 | setter(accumulator, iteratee(value), key, object);
|
|---|
| 3246 | });
|
|---|
| 3247 | return accumulator;
|
|---|
| 3248 | }
|
|---|
| 3249 |
|
|---|
| 3250 | /**
|
|---|
| 3251 | * The base implementation of `_.invoke` without support for individual
|
|---|
| 3252 | * method arguments.
|
|---|
| 3253 | *
|
|---|
| 3254 | * @private
|
|---|
| 3255 | * @param {Object} object The object to query.
|
|---|
| 3256 | * @param {Array|string} path The path of the method to invoke.
|
|---|
| 3257 | * @param {Array} args The arguments to invoke the method with.
|
|---|
| 3258 | * @returns {*} Returns the result of the invoked method.
|
|---|
| 3259 | */
|
|---|
| 3260 | function baseInvoke(object, path, args) {
|
|---|
| 3261 | path = castPath(path, object);
|
|---|
| 3262 | object = parent(object, path);
|
|---|
| 3263 | var func = object == null ? object : object[toKey(last(path))];
|
|---|
| 3264 | return func == null ? undefined : apply(func, object, args);
|
|---|
| 3265 | }
|
|---|
| 3266 |
|
|---|
| 3267 | /**
|
|---|
| 3268 | * The base implementation of `_.isArguments`.
|
|---|
| 3269 | *
|
|---|
| 3270 | * @private
|
|---|
| 3271 | * @param {*} value The value to check.
|
|---|
| 3272 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
|---|
| 3273 | */
|
|---|
| 3274 | function baseIsArguments(value) {
|
|---|
| 3275 | return isObjectLike(value) && baseGetTag(value) == argsTag;
|
|---|
| 3276 | }
|
|---|
| 3277 |
|
|---|
| 3278 | /**
|
|---|
| 3279 | * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
|
|---|
| 3280 | *
|
|---|
| 3281 | * @private
|
|---|
| 3282 | * @param {*} value The value to check.
|
|---|
| 3283 | * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
|
|---|
| 3284 | */
|
|---|
| 3285 | function baseIsArrayBuffer(value) {
|
|---|
| 3286 | return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
|
|---|
| 3287 | }
|
|---|
| 3288 |
|
|---|
| 3289 | /**
|
|---|
| 3290 | * The base implementation of `_.isDate` without Node.js optimizations.
|
|---|
| 3291 | *
|
|---|
| 3292 | * @private
|
|---|
| 3293 | * @param {*} value The value to check.
|
|---|
| 3294 | * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
|---|
| 3295 | */
|
|---|
| 3296 | function baseIsDate(value) {
|
|---|
| 3297 | return isObjectLike(value) && baseGetTag(value) == dateTag;
|
|---|
| 3298 | }
|
|---|
| 3299 |
|
|---|
| 3300 | /**
|
|---|
| 3301 | * The base implementation of `_.isEqual` which supports partial comparisons
|
|---|
| 3302 | * and tracks traversed objects.
|
|---|
| 3303 | *
|
|---|
| 3304 | * @private
|
|---|
| 3305 | * @param {*} value The value to compare.
|
|---|
| 3306 | * @param {*} other The other value to compare.
|
|---|
| 3307 | * @param {boolean} bitmask The bitmask flags.
|
|---|
| 3308 | * 1 - Unordered comparison
|
|---|
| 3309 | * 2 - Partial comparison
|
|---|
| 3310 | * @param {Function} [customizer] The function to customize comparisons.
|
|---|
| 3311 | * @param {Object} [stack] Tracks traversed `value` and `other` objects.
|
|---|
| 3312 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|---|
| 3313 | */
|
|---|
| 3314 | function baseIsEqual(value, other, bitmask, customizer, stack) {
|
|---|
| 3315 | if (value === other) {
|
|---|
| 3316 | return true;
|
|---|
| 3317 | }
|
|---|
| 3318 | if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
|
|---|
| 3319 | return value !== value && other !== other;
|
|---|
| 3320 | }
|
|---|
| 3321 | return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
|---|
| 3322 | }
|
|---|
| 3323 |
|
|---|
| 3324 | /**
|
|---|
| 3325 | * A specialized version of `baseIsEqual` for arrays and objects which performs
|
|---|
| 3326 | * deep comparisons and tracks traversed objects enabling objects with circular
|
|---|
| 3327 | * references to be compared.
|
|---|
| 3328 | *
|
|---|
| 3329 | * @private
|
|---|
| 3330 | * @param {Object} object The object to compare.
|
|---|
| 3331 | * @param {Object} other The other object to compare.
|
|---|
| 3332 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
|---|
| 3333 | * @param {Function} customizer The function to customize comparisons.
|
|---|
| 3334 | * @param {Function} equalFunc The function to determine equivalents of values.
|
|---|
| 3335 | * @param {Object} [stack] Tracks traversed `object` and `other` objects.
|
|---|
| 3336 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
|---|
| 3337 | */
|
|---|
| 3338 | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
|---|
| 3339 | var objIsArr = isArray(object),
|
|---|
| 3340 | othIsArr = isArray(other),
|
|---|
| 3341 | objTag = objIsArr ? arrayTag : getTag(object),
|
|---|
| 3342 | othTag = othIsArr ? arrayTag : getTag(other);
|
|---|
| 3343 |
|
|---|
| 3344 | objTag = objTag == argsTag ? objectTag : objTag;
|
|---|
| 3345 | othTag = othTag == argsTag ? objectTag : othTag;
|
|---|
| 3346 |
|
|---|
| 3347 | var objIsObj = objTag == objectTag,
|
|---|
| 3348 | othIsObj = othTag == objectTag,
|
|---|
| 3349 | isSameTag = objTag == othTag;
|
|---|
| 3350 |
|
|---|
| 3351 | if (isSameTag && isBuffer(object)) {
|
|---|
| 3352 | if (!isBuffer(other)) {
|
|---|
| 3353 | return false;
|
|---|
| 3354 | }
|
|---|
| 3355 | objIsArr = true;
|
|---|
| 3356 | objIsObj = false;
|
|---|
| 3357 | }
|
|---|
| 3358 | if (isSameTag && !objIsObj) {
|
|---|
| 3359 | stack || (stack = new Stack);
|
|---|
| 3360 | return (objIsArr || isTypedArray(object))
|
|---|
| 3361 | ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
|
|---|
| 3362 | : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
|
|---|
| 3363 | }
|
|---|
| 3364 | if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
|
|---|
| 3365 | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
|---|
| 3366 | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
|---|
| 3367 |
|
|---|
| 3368 | if (objIsWrapped || othIsWrapped) {
|
|---|
| 3369 | var objUnwrapped = objIsWrapped ? object.value() : object,
|
|---|
| 3370 | othUnwrapped = othIsWrapped ? other.value() : other;
|
|---|
| 3371 |
|
|---|
| 3372 | stack || (stack = new Stack);
|
|---|
| 3373 | return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
|
|---|
| 3374 | }
|
|---|
| 3375 | }
|
|---|
| 3376 | if (!isSameTag) {
|
|---|
| 3377 | return false;
|
|---|
| 3378 | }
|
|---|
| 3379 | stack || (stack = new Stack);
|
|---|
| 3380 | return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
|
|---|
| 3381 | }
|
|---|
| 3382 |
|
|---|
| 3383 | /**
|
|---|
| 3384 | * The base implementation of `_.isMap` without Node.js optimizations.
|
|---|
| 3385 | *
|
|---|
| 3386 | * @private
|
|---|
| 3387 | * @param {*} value The value to check.
|
|---|
| 3388 | * @returns {boolean} Returns `true` if `value` is a map, else `false`.
|
|---|
| 3389 | */
|
|---|
| 3390 | function baseIsMap(value) {
|
|---|
| 3391 | return isObjectLike(value) && getTag(value) == mapTag;
|
|---|
| 3392 | }
|
|---|
| 3393 |
|
|---|
| 3394 | /**
|
|---|
| 3395 | * The base implementation of `_.isMatch` without support for iteratee shorthands.
|
|---|
| 3396 | *
|
|---|
| 3397 | * @private
|
|---|
| 3398 | * @param {Object} object The object to inspect.
|
|---|
| 3399 | * @param {Object} source The object of property values to match.
|
|---|
| 3400 | * @param {Array} matchData The property names, values, and compare flags to match.
|
|---|
| 3401 | * @param {Function} [customizer] The function to customize comparisons.
|
|---|
| 3402 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|---|
| 3403 | */
|
|---|
| 3404 | function baseIsMatch(object, source, matchData, customizer) {
|
|---|
| 3405 | var index = matchData.length,
|
|---|
| 3406 | length = index,
|
|---|
| 3407 | noCustomizer = !customizer;
|
|---|
| 3408 |
|
|---|
| 3409 | if (object == null) {
|
|---|
| 3410 | return !length;
|
|---|
| 3411 | }
|
|---|
| 3412 | object = Object(object);
|
|---|
| 3413 | while (index--) {
|
|---|
| 3414 | var data = matchData[index];
|
|---|
| 3415 | if ((noCustomizer && data[2])
|
|---|
| 3416 | ? data[1] !== object[data[0]]
|
|---|
| 3417 | : !(data[0] in object)
|
|---|
| 3418 | ) {
|
|---|
| 3419 | return false;
|
|---|
| 3420 | }
|
|---|
| 3421 | }
|
|---|
| 3422 | while (++index < length) {
|
|---|
| 3423 | data = matchData[index];
|
|---|
| 3424 | var key = data[0],
|
|---|
| 3425 | objValue = object[key],
|
|---|
| 3426 | srcValue = data[1];
|
|---|
| 3427 |
|
|---|
| 3428 | if (noCustomizer && data[2]) {
|
|---|
| 3429 | if (objValue === undefined && !(key in object)) {
|
|---|
| 3430 | return false;
|
|---|
| 3431 | }
|
|---|
| 3432 | } else {
|
|---|
| 3433 | var stack = new Stack;
|
|---|
| 3434 | if (customizer) {
|
|---|
| 3435 | var result = customizer(objValue, srcValue, key, object, source, stack);
|
|---|
| 3436 | }
|
|---|
| 3437 | if (!(result === undefined
|
|---|
| 3438 | ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
|
|---|
| 3439 | : result
|
|---|
| 3440 | )) {
|
|---|
| 3441 | return false;
|
|---|
| 3442 | }
|
|---|
| 3443 | }
|
|---|
| 3444 | }
|
|---|
| 3445 | return true;
|
|---|
| 3446 | }
|
|---|
| 3447 |
|
|---|
| 3448 | /**
|
|---|
| 3449 | * The base implementation of `_.isNative` without bad shim checks.
|
|---|
| 3450 | *
|
|---|
| 3451 | * @private
|
|---|
| 3452 | * @param {*} value The value to check.
|
|---|
| 3453 | * @returns {boolean} Returns `true` if `value` is a native function,
|
|---|
| 3454 | * else `false`.
|
|---|
| 3455 | */
|
|---|
| 3456 | function baseIsNative(value) {
|
|---|
| 3457 | if (!isObject(value) || isMasked(value)) {
|
|---|
| 3458 | return false;
|
|---|
| 3459 | }
|
|---|
| 3460 | var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
|---|
| 3461 | return pattern.test(toSource(value));
|
|---|
| 3462 | }
|
|---|
| 3463 |
|
|---|
| 3464 | /**
|
|---|
| 3465 | * The base implementation of `_.isRegExp` without Node.js optimizations.
|
|---|
| 3466 | *
|
|---|
| 3467 | * @private
|
|---|
| 3468 | * @param {*} value The value to check.
|
|---|
| 3469 | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
|
|---|
| 3470 | */
|
|---|
| 3471 | function baseIsRegExp(value) {
|
|---|
| 3472 | return isObjectLike(value) && baseGetTag(value) == regexpTag;
|
|---|
| 3473 | }
|
|---|
| 3474 |
|
|---|
| 3475 | /**
|
|---|
| 3476 | * The base implementation of `_.isSet` without Node.js optimizations.
|
|---|
| 3477 | *
|
|---|
| 3478 | * @private
|
|---|
| 3479 | * @param {*} value The value to check.
|
|---|
| 3480 | * @returns {boolean} Returns `true` if `value` is a set, else `false`.
|
|---|
| 3481 | */
|
|---|
| 3482 | function baseIsSet(value) {
|
|---|
| 3483 | return isObjectLike(value) && getTag(value) == setTag;
|
|---|
| 3484 | }
|
|---|
| 3485 |
|
|---|
| 3486 | /**
|
|---|
| 3487 | * The base implementation of `_.isTypedArray` without Node.js optimizations.
|
|---|
| 3488 | *
|
|---|
| 3489 | * @private
|
|---|
| 3490 | * @param {*} value The value to check.
|
|---|
| 3491 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
|---|
| 3492 | */
|
|---|
| 3493 | function baseIsTypedArray(value) {
|
|---|
| 3494 | return isObjectLike(value) &&
|
|---|
| 3495 | isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
|
|---|
| 3496 | }
|
|---|
| 3497 |
|
|---|
| 3498 | /**
|
|---|
| 3499 | * The base implementation of `_.iteratee`.
|
|---|
| 3500 | *
|
|---|
| 3501 | * @private
|
|---|
| 3502 | * @param {*} [value=_.identity] The value to convert to an iteratee.
|
|---|
| 3503 | * @returns {Function} Returns the iteratee.
|
|---|
| 3504 | */
|
|---|
| 3505 | function baseIteratee(value) {
|
|---|
| 3506 | // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
|
|---|
| 3507 | // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
|
|---|
| 3508 | if (typeof value == 'function') {
|
|---|
| 3509 | return value;
|
|---|
| 3510 | }
|
|---|
| 3511 | if (value == null) {
|
|---|
| 3512 | return identity;
|
|---|
| 3513 | }
|
|---|
| 3514 | if (typeof value == 'object') {
|
|---|
| 3515 | return isArray(value)
|
|---|
| 3516 | ? baseMatchesProperty(value[0], value[1])
|
|---|
| 3517 | : baseMatches(value);
|
|---|
| 3518 | }
|
|---|
| 3519 | return property(value);
|
|---|
| 3520 | }
|
|---|
| 3521 |
|
|---|
| 3522 | /**
|
|---|
| 3523 | * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
|---|
| 3524 | *
|
|---|
| 3525 | * @private
|
|---|
| 3526 | * @param {Object} object The object to query.
|
|---|
| 3527 | * @returns {Array} Returns the array of property names.
|
|---|
| 3528 | */
|
|---|
| 3529 | function baseKeys(object) {
|
|---|
| 3530 | if (!isPrototype(object)) {
|
|---|
| 3531 | return nativeKeys(object);
|
|---|
| 3532 | }
|
|---|
| 3533 | var result = [];
|
|---|
| 3534 | for (var key in Object(object)) {
|
|---|
| 3535 | if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
|---|
| 3536 | result.push(key);
|
|---|
| 3537 | }
|
|---|
| 3538 | }
|
|---|
| 3539 | return result;
|
|---|
| 3540 | }
|
|---|
| 3541 |
|
|---|
| 3542 | /**
|
|---|
| 3543 | * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
|
|---|
| 3544 | *
|
|---|
| 3545 | * @private
|
|---|
| 3546 | * @param {Object} object The object to query.
|
|---|
| 3547 | * @returns {Array} Returns the array of property names.
|
|---|
| 3548 | */
|
|---|
| 3549 | function baseKeysIn(object) {
|
|---|
| 3550 | if (!isObject(object)) {
|
|---|
| 3551 | return nativeKeysIn(object);
|
|---|
| 3552 | }
|
|---|
| 3553 | var isProto = isPrototype(object),
|
|---|
| 3554 | result = [];
|
|---|
| 3555 |
|
|---|
| 3556 | for (var key in object) {
|
|---|
| 3557 | if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
|---|
| 3558 | result.push(key);
|
|---|
| 3559 | }
|
|---|
| 3560 | }
|
|---|
| 3561 | return result;
|
|---|
| 3562 | }
|
|---|
| 3563 |
|
|---|
| 3564 | /**
|
|---|
| 3565 | * The base implementation of `_.lt` which doesn't coerce arguments.
|
|---|
| 3566 | *
|
|---|
| 3567 | * @private
|
|---|
| 3568 | * @param {*} value The value to compare.
|
|---|
| 3569 | * @param {*} other The other value to compare.
|
|---|
| 3570 | * @returns {boolean} Returns `true` if `value` is less than `other`,
|
|---|
| 3571 | * else `false`.
|
|---|
| 3572 | */
|
|---|
| 3573 | function baseLt(value, other) {
|
|---|
| 3574 | return value < other;
|
|---|
| 3575 | }
|
|---|
| 3576 |
|
|---|
| 3577 | /**
|
|---|
| 3578 | * The base implementation of `_.map` without support for iteratee shorthands.
|
|---|
| 3579 | *
|
|---|
| 3580 | * @private
|
|---|
| 3581 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 3582 | * @param {Function} iteratee The function invoked per iteration.
|
|---|
| 3583 | * @returns {Array} Returns the new mapped array.
|
|---|
| 3584 | */
|
|---|
| 3585 | function baseMap(collection, iteratee) {
|
|---|
| 3586 | var index = -1,
|
|---|
| 3587 | result = isArrayLike(collection) ? Array(collection.length) : [];
|
|---|
| 3588 |
|
|---|
| 3589 | baseEach(collection, function(value, key, collection) {
|
|---|
| 3590 | result[++index] = iteratee(value, key, collection);
|
|---|
| 3591 | });
|
|---|
| 3592 | return result;
|
|---|
| 3593 | }
|
|---|
| 3594 |
|
|---|
| 3595 | /**
|
|---|
| 3596 | * The base implementation of `_.matches` which doesn't clone `source`.
|
|---|
| 3597 | *
|
|---|
| 3598 | * @private
|
|---|
| 3599 | * @param {Object} source The object of property values to match.
|
|---|
| 3600 | * @returns {Function} Returns the new spec function.
|
|---|
| 3601 | */
|
|---|
| 3602 | function baseMatches(source) {
|
|---|
| 3603 | var matchData = getMatchData(source);
|
|---|
| 3604 | if (matchData.length == 1 && matchData[0][2]) {
|
|---|
| 3605 | return matchesStrictComparable(matchData[0][0], matchData[0][1]);
|
|---|
| 3606 | }
|
|---|
| 3607 | return function(object) {
|
|---|
| 3608 | return object === source || baseIsMatch(object, source, matchData);
|
|---|
| 3609 | };
|
|---|
| 3610 | }
|
|---|
| 3611 |
|
|---|
| 3612 | /**
|
|---|
| 3613 | * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
|
|---|
| 3614 | *
|
|---|
| 3615 | * @private
|
|---|
| 3616 | * @param {string} path The path of the property to get.
|
|---|
| 3617 | * @param {*} srcValue The value to match.
|
|---|
| 3618 | * @returns {Function} Returns the new spec function.
|
|---|
| 3619 | */
|
|---|
| 3620 | function baseMatchesProperty(path, srcValue) {
|
|---|
| 3621 | if (isKey(path) && isStrictComparable(srcValue)) {
|
|---|
| 3622 | return matchesStrictComparable(toKey(path), srcValue);
|
|---|
| 3623 | }
|
|---|
| 3624 | return function(object) {
|
|---|
| 3625 | var objValue = get(object, path);
|
|---|
| 3626 | return (objValue === undefined && objValue === srcValue)
|
|---|
| 3627 | ? hasIn(object, path)
|
|---|
| 3628 | : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
|
|---|
| 3629 | };
|
|---|
| 3630 | }
|
|---|
| 3631 |
|
|---|
| 3632 | /**
|
|---|
| 3633 | * The base implementation of `_.merge` without support for multiple sources.
|
|---|
| 3634 | *
|
|---|
| 3635 | * @private
|
|---|
| 3636 | * @param {Object} object The destination object.
|
|---|
| 3637 | * @param {Object} source The source object.
|
|---|
| 3638 | * @param {number} srcIndex The index of `source`.
|
|---|
| 3639 | * @param {Function} [customizer] The function to customize merged values.
|
|---|
| 3640 | * @param {Object} [stack] Tracks traversed source values and their merged
|
|---|
| 3641 | * counterparts.
|
|---|
| 3642 | */
|
|---|
| 3643 | function baseMerge(object, source, srcIndex, customizer, stack) {
|
|---|
| 3644 | if (object === source) {
|
|---|
| 3645 | return;
|
|---|
| 3646 | }
|
|---|
| 3647 | baseFor(source, function(srcValue, key) {
|
|---|
| 3648 | stack || (stack = new Stack);
|
|---|
| 3649 | if (isObject(srcValue)) {
|
|---|
| 3650 | baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
|---|
| 3651 | }
|
|---|
| 3652 | else {
|
|---|
| 3653 | var newValue = customizer
|
|---|
| 3654 | ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
|
|---|
| 3655 | : undefined;
|
|---|
| 3656 |
|
|---|
| 3657 | if (newValue === undefined) {
|
|---|
| 3658 | newValue = srcValue;
|
|---|
| 3659 | }
|
|---|
| 3660 | assignMergeValue(object, key, newValue);
|
|---|
| 3661 | }
|
|---|
| 3662 | }, keysIn);
|
|---|
| 3663 | }
|
|---|
| 3664 |
|
|---|
| 3665 | /**
|
|---|
| 3666 | * A specialized version of `baseMerge` for arrays and objects which performs
|
|---|
| 3667 | * deep merges and tracks traversed objects enabling objects with circular
|
|---|
| 3668 | * references to be merged.
|
|---|
| 3669 | *
|
|---|
| 3670 | * @private
|
|---|
| 3671 | * @param {Object} object The destination object.
|
|---|
| 3672 | * @param {Object} source The source object.
|
|---|
| 3673 | * @param {string} key The key of the value to merge.
|
|---|
| 3674 | * @param {number} srcIndex The index of `source`.
|
|---|
| 3675 | * @param {Function} mergeFunc The function to merge values.
|
|---|
| 3676 | * @param {Function} [customizer] The function to customize assigned values.
|
|---|
| 3677 | * @param {Object} [stack] Tracks traversed source values and their merged
|
|---|
| 3678 | * counterparts.
|
|---|
| 3679 | */
|
|---|
| 3680 | function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
|
|---|
| 3681 | var objValue = safeGet(object, key),
|
|---|
| 3682 | srcValue = safeGet(source, key),
|
|---|
| 3683 | stacked = stack.get(srcValue);
|
|---|
| 3684 |
|
|---|
| 3685 | if (stacked) {
|
|---|
| 3686 | assignMergeValue(object, key, stacked);
|
|---|
| 3687 | return;
|
|---|
| 3688 | }
|
|---|
| 3689 | var newValue = customizer
|
|---|
| 3690 | ? customizer(objValue, srcValue, (key + ''), object, source, stack)
|
|---|
| 3691 | : undefined;
|
|---|
| 3692 |
|
|---|
| 3693 | var isCommon = newValue === undefined;
|
|---|
| 3694 |
|
|---|
| 3695 | if (isCommon) {
|
|---|
| 3696 | var isArr = isArray(srcValue),
|
|---|
| 3697 | isBuff = !isArr && isBuffer(srcValue),
|
|---|
| 3698 | isTyped = !isArr && !isBuff && isTypedArray(srcValue);
|
|---|
| 3699 |
|
|---|
| 3700 | newValue = srcValue;
|
|---|
| 3701 | if (isArr || isBuff || isTyped) {
|
|---|
| 3702 | if (isArray(objValue)) {
|
|---|
| 3703 | newValue = objValue;
|
|---|
| 3704 | }
|
|---|
| 3705 | else if (isArrayLikeObject(objValue)) {
|
|---|
| 3706 | newValue = copyArray(objValue);
|
|---|
| 3707 | }
|
|---|
| 3708 | else if (isBuff) {
|
|---|
| 3709 | isCommon = false;
|
|---|
| 3710 | newValue = cloneBuffer(srcValue, true);
|
|---|
| 3711 | }
|
|---|
| 3712 | else if (isTyped) {
|
|---|
| 3713 | isCommon = false;
|
|---|
| 3714 | newValue = cloneTypedArray(srcValue, true);
|
|---|
| 3715 | }
|
|---|
| 3716 | else {
|
|---|
| 3717 | newValue = [];
|
|---|
| 3718 | }
|
|---|
| 3719 | }
|
|---|
| 3720 | else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
|---|
| 3721 | newValue = objValue;
|
|---|
| 3722 | if (isArguments(objValue)) {
|
|---|
| 3723 | newValue = toPlainObject(objValue);
|
|---|
| 3724 | }
|
|---|
| 3725 | else if (!isObject(objValue) || isFunction(objValue)) {
|
|---|
| 3726 | newValue = initCloneObject(srcValue);
|
|---|
| 3727 | }
|
|---|
| 3728 | }
|
|---|
| 3729 | else {
|
|---|
| 3730 | isCommon = false;
|
|---|
| 3731 | }
|
|---|
| 3732 | }
|
|---|
| 3733 | if (isCommon) {
|
|---|
| 3734 | // Recursively merge objects and arrays (susceptible to call stack limits).
|
|---|
| 3735 | stack.set(srcValue, newValue);
|
|---|
| 3736 | mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
|
|---|
| 3737 | stack['delete'](srcValue);
|
|---|
| 3738 | }
|
|---|
| 3739 | assignMergeValue(object, key, newValue);
|
|---|
| 3740 | }
|
|---|
| 3741 |
|
|---|
| 3742 | /**
|
|---|
| 3743 | * The base implementation of `_.nth` which doesn't coerce arguments.
|
|---|
| 3744 | *
|
|---|
| 3745 | * @private
|
|---|
| 3746 | * @param {Array} array The array to query.
|
|---|
| 3747 | * @param {number} n The index of the element to return.
|
|---|
| 3748 | * @returns {*} Returns the nth element of `array`.
|
|---|
| 3749 | */
|
|---|
| 3750 | function baseNth(array, n) {
|
|---|
| 3751 | var length = array.length;
|
|---|
| 3752 | if (!length) {
|
|---|
| 3753 | return;
|
|---|
| 3754 | }
|
|---|
| 3755 | n += n < 0 ? length : 0;
|
|---|
| 3756 | return isIndex(n, length) ? array[n] : undefined;
|
|---|
| 3757 | }
|
|---|
| 3758 |
|
|---|
| 3759 | /**
|
|---|
| 3760 | * The base implementation of `_.orderBy` without param guards.
|
|---|
| 3761 | *
|
|---|
| 3762 | * @private
|
|---|
| 3763 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 3764 | * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
|---|
| 3765 | * @param {string[]} orders The sort orders of `iteratees`.
|
|---|
| 3766 | * @returns {Array} Returns the new sorted array.
|
|---|
| 3767 | */
|
|---|
| 3768 | function baseOrderBy(collection, iteratees, orders) {
|
|---|
| 3769 | if (iteratees.length) {
|
|---|
| 3770 | iteratees = arrayMap(iteratees, function(iteratee) {
|
|---|
| 3771 | if (isArray(iteratee)) {
|
|---|
| 3772 | return function(value) {
|
|---|
| 3773 | return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
|
|---|
| 3774 | };
|
|---|
| 3775 | }
|
|---|
| 3776 | return iteratee;
|
|---|
| 3777 | });
|
|---|
| 3778 | } else {
|
|---|
| 3779 | iteratees = [identity];
|
|---|
| 3780 | }
|
|---|
| 3781 |
|
|---|
| 3782 | var index = -1;
|
|---|
| 3783 | iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
|
|---|
| 3784 |
|
|---|
| 3785 | var result = baseMap(collection, function(value, key, collection) {
|
|---|
| 3786 | var criteria = arrayMap(iteratees, function(iteratee) {
|
|---|
| 3787 | return iteratee(value);
|
|---|
| 3788 | });
|
|---|
| 3789 | return { 'criteria': criteria, 'index': ++index, 'value': value };
|
|---|
| 3790 | });
|
|---|
| 3791 |
|
|---|
| 3792 | return baseSortBy(result, function(object, other) {
|
|---|
| 3793 | return compareMultiple(object, other, orders);
|
|---|
| 3794 | });
|
|---|
| 3795 | }
|
|---|
| 3796 |
|
|---|
| 3797 | /**
|
|---|
| 3798 | * The base implementation of `_.pick` without support for individual
|
|---|
| 3799 | * property identifiers.
|
|---|
| 3800 | *
|
|---|
| 3801 | * @private
|
|---|
| 3802 | * @param {Object} object The source object.
|
|---|
| 3803 | * @param {string[]} paths The property paths to pick.
|
|---|
| 3804 | * @returns {Object} Returns the new object.
|
|---|
| 3805 | */
|
|---|
| 3806 | function basePick(object, paths) {
|
|---|
| 3807 | return basePickBy(object, paths, function(value, path) {
|
|---|
| 3808 | return hasIn(object, path);
|
|---|
| 3809 | });
|
|---|
| 3810 | }
|
|---|
| 3811 |
|
|---|
| 3812 | /**
|
|---|
| 3813 | * The base implementation of `_.pickBy` without support for iteratee shorthands.
|
|---|
| 3814 | *
|
|---|
| 3815 | * @private
|
|---|
| 3816 | * @param {Object} object The source object.
|
|---|
| 3817 | * @param {string[]} paths The property paths to pick.
|
|---|
| 3818 | * @param {Function} predicate The function invoked per property.
|
|---|
| 3819 | * @returns {Object} Returns the new object.
|
|---|
| 3820 | */
|
|---|
| 3821 | function basePickBy(object, paths, predicate) {
|
|---|
| 3822 | var index = -1,
|
|---|
| 3823 | length = paths.length,
|
|---|
| 3824 | result = {};
|
|---|
| 3825 |
|
|---|
| 3826 | while (++index < length) {
|
|---|
| 3827 | var path = paths[index],
|
|---|
| 3828 | value = baseGet(object, path);
|
|---|
| 3829 |
|
|---|
| 3830 | if (predicate(value, path)) {
|
|---|
| 3831 | baseSet(result, castPath(path, object), value);
|
|---|
| 3832 | }
|
|---|
| 3833 | }
|
|---|
| 3834 | return result;
|
|---|
| 3835 | }
|
|---|
| 3836 |
|
|---|
| 3837 | /**
|
|---|
| 3838 | * A specialized version of `baseProperty` which supports deep paths.
|
|---|
| 3839 | *
|
|---|
| 3840 | * @private
|
|---|
| 3841 | * @param {Array|string} path The path of the property to get.
|
|---|
| 3842 | * @returns {Function} Returns the new accessor function.
|
|---|
| 3843 | */
|
|---|
| 3844 | function basePropertyDeep(path) {
|
|---|
| 3845 | return function(object) {
|
|---|
| 3846 | return baseGet(object, path);
|
|---|
| 3847 | };
|
|---|
| 3848 | }
|
|---|
| 3849 |
|
|---|
| 3850 | /**
|
|---|
| 3851 | * The base implementation of `_.pullAllBy` without support for iteratee
|
|---|
| 3852 | * shorthands.
|
|---|
| 3853 | *
|
|---|
| 3854 | * @private
|
|---|
| 3855 | * @param {Array} array The array to modify.
|
|---|
| 3856 | * @param {Array} values The values to remove.
|
|---|
| 3857 | * @param {Function} [iteratee] The iteratee invoked per element.
|
|---|
| 3858 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 3859 | * @returns {Array} Returns `array`.
|
|---|
| 3860 | */
|
|---|
| 3861 | function basePullAll(array, values, iteratee, comparator) {
|
|---|
| 3862 | var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
|
|---|
| 3863 | index = -1,
|
|---|
| 3864 | length = values.length,
|
|---|
| 3865 | seen = array;
|
|---|
| 3866 |
|
|---|
| 3867 | if (array === values) {
|
|---|
| 3868 | values = copyArray(values);
|
|---|
| 3869 | }
|
|---|
| 3870 | if (iteratee) {
|
|---|
| 3871 | seen = arrayMap(array, baseUnary(iteratee));
|
|---|
| 3872 | }
|
|---|
| 3873 | while (++index < length) {
|
|---|
| 3874 | var fromIndex = 0,
|
|---|
| 3875 | value = values[index],
|
|---|
| 3876 | computed = iteratee ? iteratee(value) : value;
|
|---|
| 3877 |
|
|---|
| 3878 | while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
|
|---|
| 3879 | if (seen !== array) {
|
|---|
| 3880 | splice.call(seen, fromIndex, 1);
|
|---|
| 3881 | }
|
|---|
| 3882 | splice.call(array, fromIndex, 1);
|
|---|
| 3883 | }
|
|---|
| 3884 | }
|
|---|
| 3885 | return array;
|
|---|
| 3886 | }
|
|---|
| 3887 |
|
|---|
| 3888 | /**
|
|---|
| 3889 | * The base implementation of `_.pullAt` without support for individual
|
|---|
| 3890 | * indexes or capturing the removed elements.
|
|---|
| 3891 | *
|
|---|
| 3892 | * @private
|
|---|
| 3893 | * @param {Array} array The array to modify.
|
|---|
| 3894 | * @param {number[]} indexes The indexes of elements to remove.
|
|---|
| 3895 | * @returns {Array} Returns `array`.
|
|---|
| 3896 | */
|
|---|
| 3897 | function basePullAt(array, indexes) {
|
|---|
| 3898 | var length = array ? indexes.length : 0,
|
|---|
| 3899 | lastIndex = length - 1;
|
|---|
| 3900 |
|
|---|
| 3901 | while (length--) {
|
|---|
| 3902 | var index = indexes[length];
|
|---|
| 3903 | if (length == lastIndex || index !== previous) {
|
|---|
| 3904 | var previous = index;
|
|---|
| 3905 | if (isIndex(index)) {
|
|---|
| 3906 | splice.call(array, index, 1);
|
|---|
| 3907 | } else {
|
|---|
| 3908 | baseUnset(array, index);
|
|---|
| 3909 | }
|
|---|
| 3910 | }
|
|---|
| 3911 | }
|
|---|
| 3912 | return array;
|
|---|
| 3913 | }
|
|---|
| 3914 |
|
|---|
| 3915 | /**
|
|---|
| 3916 | * The base implementation of `_.random` without support for returning
|
|---|
| 3917 | * floating-point numbers.
|
|---|
| 3918 | *
|
|---|
| 3919 | * @private
|
|---|
| 3920 | * @param {number} lower The lower bound.
|
|---|
| 3921 | * @param {number} upper The upper bound.
|
|---|
| 3922 | * @returns {number} Returns the random number.
|
|---|
| 3923 | */
|
|---|
| 3924 | function baseRandom(lower, upper) {
|
|---|
| 3925 | return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
|
|---|
| 3926 | }
|
|---|
| 3927 |
|
|---|
| 3928 | /**
|
|---|
| 3929 | * The base implementation of `_.range` and `_.rangeRight` which doesn't
|
|---|
| 3930 | * coerce arguments.
|
|---|
| 3931 | *
|
|---|
| 3932 | * @private
|
|---|
| 3933 | * @param {number} start The start of the range.
|
|---|
| 3934 | * @param {number} end The end of the range.
|
|---|
| 3935 | * @param {number} step The value to increment or decrement by.
|
|---|
| 3936 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
|---|
| 3937 | * @returns {Array} Returns the range of numbers.
|
|---|
| 3938 | */
|
|---|
| 3939 | function baseRange(start, end, step, fromRight) {
|
|---|
| 3940 | var index = -1,
|
|---|
| 3941 | length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
|
|---|
| 3942 | result = Array(length);
|
|---|
| 3943 |
|
|---|
| 3944 | while (length--) {
|
|---|
| 3945 | result[fromRight ? length : ++index] = start;
|
|---|
| 3946 | start += step;
|
|---|
| 3947 | }
|
|---|
| 3948 | return result;
|
|---|
| 3949 | }
|
|---|
| 3950 |
|
|---|
| 3951 | /**
|
|---|
| 3952 | * The base implementation of `_.repeat` which doesn't coerce arguments.
|
|---|
| 3953 | *
|
|---|
| 3954 | * @private
|
|---|
| 3955 | * @param {string} string The string to repeat.
|
|---|
| 3956 | * @param {number} n The number of times to repeat the string.
|
|---|
| 3957 | * @returns {string} Returns the repeated string.
|
|---|
| 3958 | */
|
|---|
| 3959 | function baseRepeat(string, n) {
|
|---|
| 3960 | var result = '';
|
|---|
| 3961 | if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
|
|---|
| 3962 | return result;
|
|---|
| 3963 | }
|
|---|
| 3964 | // Leverage the exponentiation by squaring algorithm for a faster repeat.
|
|---|
| 3965 | // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
|
|---|
| 3966 | do {
|
|---|
| 3967 | if (n % 2) {
|
|---|
| 3968 | result += string;
|
|---|
| 3969 | }
|
|---|
| 3970 | n = nativeFloor(n / 2);
|
|---|
| 3971 | if (n) {
|
|---|
| 3972 | string += string;
|
|---|
| 3973 | }
|
|---|
| 3974 | } while (n);
|
|---|
| 3975 |
|
|---|
| 3976 | return result;
|
|---|
| 3977 | }
|
|---|
| 3978 |
|
|---|
| 3979 | /**
|
|---|
| 3980 | * The base implementation of `_.rest` which doesn't validate or coerce arguments.
|
|---|
| 3981 | *
|
|---|
| 3982 | * @private
|
|---|
| 3983 | * @param {Function} func The function to apply a rest parameter to.
|
|---|
| 3984 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
|---|
| 3985 | * @returns {Function} Returns the new function.
|
|---|
| 3986 | */
|
|---|
| 3987 | function baseRest(func, start) {
|
|---|
| 3988 | return setToString(overRest(func, start, identity), func + '');
|
|---|
| 3989 | }
|
|---|
| 3990 |
|
|---|
| 3991 | /**
|
|---|
| 3992 | * The base implementation of `_.sample`.
|
|---|
| 3993 | *
|
|---|
| 3994 | * @private
|
|---|
| 3995 | * @param {Array|Object} collection The collection to sample.
|
|---|
| 3996 | * @returns {*} Returns the random element.
|
|---|
| 3997 | */
|
|---|
| 3998 | function baseSample(collection) {
|
|---|
| 3999 | return arraySample(values(collection));
|
|---|
| 4000 | }
|
|---|
| 4001 |
|
|---|
| 4002 | /**
|
|---|
| 4003 | * The base implementation of `_.sampleSize` without param guards.
|
|---|
| 4004 | *
|
|---|
| 4005 | * @private
|
|---|
| 4006 | * @param {Array|Object} collection The collection to sample.
|
|---|
| 4007 | * @param {number} n The number of elements to sample.
|
|---|
| 4008 | * @returns {Array} Returns the random elements.
|
|---|
| 4009 | */
|
|---|
| 4010 | function baseSampleSize(collection, n) {
|
|---|
| 4011 | var array = values(collection);
|
|---|
| 4012 | return shuffleSelf(array, baseClamp(n, 0, array.length));
|
|---|
| 4013 | }
|
|---|
| 4014 |
|
|---|
| 4015 | /**
|
|---|
| 4016 | * The base implementation of `_.set`.
|
|---|
| 4017 | *
|
|---|
| 4018 | * @private
|
|---|
| 4019 | * @param {Object} object The object to modify.
|
|---|
| 4020 | * @param {Array|string} path The path of the property to set.
|
|---|
| 4021 | * @param {*} value The value to set.
|
|---|
| 4022 | * @param {Function} [customizer] The function to customize path creation.
|
|---|
| 4023 | * @returns {Object} Returns `object`.
|
|---|
| 4024 | */
|
|---|
| 4025 | function baseSet(object, path, value, customizer) {
|
|---|
| 4026 | if (!isObject(object)) {
|
|---|
| 4027 | return object;
|
|---|
| 4028 | }
|
|---|
| 4029 | path = castPath(path, object);
|
|---|
| 4030 |
|
|---|
| 4031 | var index = -1,
|
|---|
| 4032 | length = path.length,
|
|---|
| 4033 | lastIndex = length - 1,
|
|---|
| 4034 | nested = object;
|
|---|
| 4035 |
|
|---|
| 4036 | while (nested != null && ++index < length) {
|
|---|
| 4037 | var key = toKey(path[index]),
|
|---|
| 4038 | newValue = value;
|
|---|
| 4039 |
|
|---|
| 4040 | if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|---|
| 4041 | return object;
|
|---|
| 4042 | }
|
|---|
| 4043 |
|
|---|
| 4044 | if (index != lastIndex) {
|
|---|
| 4045 | var objValue = nested[key];
|
|---|
| 4046 | newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
|---|
| 4047 | if (newValue === undefined) {
|
|---|
| 4048 | newValue = isObject(objValue)
|
|---|
| 4049 | ? objValue
|
|---|
| 4050 | : (isIndex(path[index + 1]) ? [] : {});
|
|---|
| 4051 | }
|
|---|
| 4052 | }
|
|---|
| 4053 | assignValue(nested, key, newValue);
|
|---|
| 4054 | nested = nested[key];
|
|---|
| 4055 | }
|
|---|
| 4056 | return object;
|
|---|
| 4057 | }
|
|---|
| 4058 |
|
|---|
| 4059 | /**
|
|---|
| 4060 | * The base implementation of `setData` without support for hot loop shorting.
|
|---|
| 4061 | *
|
|---|
| 4062 | * @private
|
|---|
| 4063 | * @param {Function} func The function to associate metadata with.
|
|---|
| 4064 | * @param {*} data The metadata.
|
|---|
| 4065 | * @returns {Function} Returns `func`.
|
|---|
| 4066 | */
|
|---|
| 4067 | var baseSetData = !metaMap ? identity : function(func, data) {
|
|---|
| 4068 | metaMap.set(func, data);
|
|---|
| 4069 | return func;
|
|---|
| 4070 | };
|
|---|
| 4071 |
|
|---|
| 4072 | /**
|
|---|
| 4073 | * The base implementation of `setToString` without support for hot loop shorting.
|
|---|
| 4074 | *
|
|---|
| 4075 | * @private
|
|---|
| 4076 | * @param {Function} func The function to modify.
|
|---|
| 4077 | * @param {Function} string The `toString` result.
|
|---|
| 4078 | * @returns {Function} Returns `func`.
|
|---|
| 4079 | */
|
|---|
| 4080 | var baseSetToString = !defineProperty ? identity : function(func, string) {
|
|---|
| 4081 | return defineProperty(func, 'toString', {
|
|---|
| 4082 | 'configurable': true,
|
|---|
| 4083 | 'enumerable': false,
|
|---|
| 4084 | 'value': constant(string),
|
|---|
| 4085 | 'writable': true
|
|---|
| 4086 | });
|
|---|
| 4087 | };
|
|---|
| 4088 |
|
|---|
| 4089 | /**
|
|---|
| 4090 | * The base implementation of `_.shuffle`.
|
|---|
| 4091 | *
|
|---|
| 4092 | * @private
|
|---|
| 4093 | * @param {Array|Object} collection The collection to shuffle.
|
|---|
| 4094 | * @returns {Array} Returns the new shuffled array.
|
|---|
| 4095 | */
|
|---|
| 4096 | function baseShuffle(collection) {
|
|---|
| 4097 | return shuffleSelf(values(collection));
|
|---|
| 4098 | }
|
|---|
| 4099 |
|
|---|
| 4100 | /**
|
|---|
| 4101 | * The base implementation of `_.slice` without an iteratee call guard.
|
|---|
| 4102 | *
|
|---|
| 4103 | * @private
|
|---|
| 4104 | * @param {Array} array The array to slice.
|
|---|
| 4105 | * @param {number} [start=0] The start position.
|
|---|
| 4106 | * @param {number} [end=array.length] The end position.
|
|---|
| 4107 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 4108 | */
|
|---|
| 4109 | function baseSlice(array, start, end) {
|
|---|
| 4110 | var index = -1,
|
|---|
| 4111 | length = array.length;
|
|---|
| 4112 |
|
|---|
| 4113 | if (start < 0) {
|
|---|
| 4114 | start = -start > length ? 0 : (length + start);
|
|---|
| 4115 | }
|
|---|
| 4116 | end = end > length ? length : end;
|
|---|
| 4117 | if (end < 0) {
|
|---|
| 4118 | end += length;
|
|---|
| 4119 | }
|
|---|
| 4120 | length = start > end ? 0 : ((end - start) >>> 0);
|
|---|
| 4121 | start >>>= 0;
|
|---|
| 4122 |
|
|---|
| 4123 | var result = Array(length);
|
|---|
| 4124 | while (++index < length) {
|
|---|
| 4125 | result[index] = array[index + start];
|
|---|
| 4126 | }
|
|---|
| 4127 | return result;
|
|---|
| 4128 | }
|
|---|
| 4129 |
|
|---|
| 4130 | /**
|
|---|
| 4131 | * The base implementation of `_.some` without support for iteratee shorthands.
|
|---|
| 4132 | *
|
|---|
| 4133 | * @private
|
|---|
| 4134 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 4135 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 4136 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
|---|
| 4137 | * else `false`.
|
|---|
| 4138 | */
|
|---|
| 4139 | function baseSome(collection, predicate) {
|
|---|
| 4140 | var result;
|
|---|
| 4141 |
|
|---|
| 4142 | baseEach(collection, function(value, index, collection) {
|
|---|
| 4143 | result = predicate(value, index, collection);
|
|---|
| 4144 | return !result;
|
|---|
| 4145 | });
|
|---|
| 4146 | return !!result;
|
|---|
| 4147 | }
|
|---|
| 4148 |
|
|---|
| 4149 | /**
|
|---|
| 4150 | * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
|
|---|
| 4151 | * performs a binary search of `array` to determine the index at which `value`
|
|---|
| 4152 | * should be inserted into `array` in order to maintain its sort order.
|
|---|
| 4153 | *
|
|---|
| 4154 | * @private
|
|---|
| 4155 | * @param {Array} array The sorted array to inspect.
|
|---|
| 4156 | * @param {*} value The value to evaluate.
|
|---|
| 4157 | * @param {boolean} [retHighest] Specify returning the highest qualified index.
|
|---|
| 4158 | * @returns {number} Returns the index at which `value` should be inserted
|
|---|
| 4159 | * into `array`.
|
|---|
| 4160 | */
|
|---|
| 4161 | function baseSortedIndex(array, value, retHighest) {
|
|---|
| 4162 | var low = 0,
|
|---|
| 4163 | high = array == null ? low : array.length;
|
|---|
| 4164 |
|
|---|
| 4165 | if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
|
|---|
| 4166 | while (low < high) {
|
|---|
| 4167 | var mid = (low + high) >>> 1,
|
|---|
| 4168 | computed = array[mid];
|
|---|
| 4169 |
|
|---|
| 4170 | if (computed !== null && !isSymbol(computed) &&
|
|---|
| 4171 | (retHighest ? (computed <= value) : (computed < value))) {
|
|---|
| 4172 | low = mid + 1;
|
|---|
| 4173 | } else {
|
|---|
| 4174 | high = mid;
|
|---|
| 4175 | }
|
|---|
| 4176 | }
|
|---|
| 4177 | return high;
|
|---|
| 4178 | }
|
|---|
| 4179 | return baseSortedIndexBy(array, value, identity, retHighest);
|
|---|
| 4180 | }
|
|---|
| 4181 |
|
|---|
| 4182 | /**
|
|---|
| 4183 | * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
|
|---|
| 4184 | * which invokes `iteratee` for `value` and each element of `array` to compute
|
|---|
| 4185 | * their sort ranking. The iteratee is invoked with one argument; (value).
|
|---|
| 4186 | *
|
|---|
| 4187 | * @private
|
|---|
| 4188 | * @param {Array} array The sorted array to inspect.
|
|---|
| 4189 | * @param {*} value The value to evaluate.
|
|---|
| 4190 | * @param {Function} iteratee The iteratee invoked per element.
|
|---|
| 4191 | * @param {boolean} [retHighest] Specify returning the highest qualified index.
|
|---|
| 4192 | * @returns {number} Returns the index at which `value` should be inserted
|
|---|
| 4193 | * into `array`.
|
|---|
| 4194 | */
|
|---|
| 4195 | function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
|---|
| 4196 | var low = 0,
|
|---|
| 4197 | high = array == null ? 0 : array.length;
|
|---|
| 4198 | if (high === 0) {
|
|---|
| 4199 | return 0;
|
|---|
| 4200 | }
|
|---|
| 4201 |
|
|---|
| 4202 | value = iteratee(value);
|
|---|
| 4203 | var valIsNaN = value !== value,
|
|---|
| 4204 | valIsNull = value === null,
|
|---|
| 4205 | valIsSymbol = isSymbol(value),
|
|---|
| 4206 | valIsUndefined = value === undefined;
|
|---|
| 4207 |
|
|---|
| 4208 | while (low < high) {
|
|---|
| 4209 | var mid = nativeFloor((low + high) / 2),
|
|---|
| 4210 | computed = iteratee(array[mid]),
|
|---|
| 4211 | othIsDefined = computed !== undefined,
|
|---|
| 4212 | othIsNull = computed === null,
|
|---|
| 4213 | othIsReflexive = computed === computed,
|
|---|
| 4214 | othIsSymbol = isSymbol(computed);
|
|---|
| 4215 |
|
|---|
| 4216 | if (valIsNaN) {
|
|---|
| 4217 | var setLow = retHighest || othIsReflexive;
|
|---|
| 4218 | } else if (valIsUndefined) {
|
|---|
| 4219 | setLow = othIsReflexive && (retHighest || othIsDefined);
|
|---|
| 4220 | } else if (valIsNull) {
|
|---|
| 4221 | setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
|
|---|
| 4222 | } else if (valIsSymbol) {
|
|---|
| 4223 | setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
|
|---|
| 4224 | } else if (othIsNull || othIsSymbol) {
|
|---|
| 4225 | setLow = false;
|
|---|
| 4226 | } else {
|
|---|
| 4227 | setLow = retHighest ? (computed <= value) : (computed < value);
|
|---|
| 4228 | }
|
|---|
| 4229 | if (setLow) {
|
|---|
| 4230 | low = mid + 1;
|
|---|
| 4231 | } else {
|
|---|
| 4232 | high = mid;
|
|---|
| 4233 | }
|
|---|
| 4234 | }
|
|---|
| 4235 | return nativeMin(high, MAX_ARRAY_INDEX);
|
|---|
| 4236 | }
|
|---|
| 4237 |
|
|---|
| 4238 | /**
|
|---|
| 4239 | * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
|
|---|
| 4240 | * support for iteratee shorthands.
|
|---|
| 4241 | *
|
|---|
| 4242 | * @private
|
|---|
| 4243 | * @param {Array} array The array to inspect.
|
|---|
| 4244 | * @param {Function} [iteratee] The iteratee invoked per element.
|
|---|
| 4245 | * @returns {Array} Returns the new duplicate free array.
|
|---|
| 4246 | */
|
|---|
| 4247 | function baseSortedUniq(array, iteratee) {
|
|---|
| 4248 | var index = -1,
|
|---|
| 4249 | length = array.length,
|
|---|
| 4250 | resIndex = 0,
|
|---|
| 4251 | result = [];
|
|---|
| 4252 |
|
|---|
| 4253 | while (++index < length) {
|
|---|
| 4254 | var value = array[index],
|
|---|
| 4255 | computed = iteratee ? iteratee(value) : value;
|
|---|
| 4256 |
|
|---|
| 4257 | if (!index || !eq(computed, seen)) {
|
|---|
| 4258 | var seen = computed;
|
|---|
| 4259 | result[resIndex++] = value === 0 ? 0 : value;
|
|---|
| 4260 | }
|
|---|
| 4261 | }
|
|---|
| 4262 | return result;
|
|---|
| 4263 | }
|
|---|
| 4264 |
|
|---|
| 4265 | /**
|
|---|
| 4266 | * The base implementation of `_.toNumber` which doesn't ensure correct
|
|---|
| 4267 | * conversions of binary, hexadecimal, or octal string values.
|
|---|
| 4268 | *
|
|---|
| 4269 | * @private
|
|---|
| 4270 | * @param {*} value The value to process.
|
|---|
| 4271 | * @returns {number} Returns the number.
|
|---|
| 4272 | */
|
|---|
| 4273 | function baseToNumber(value) {
|
|---|
| 4274 | if (typeof value == 'number') {
|
|---|
| 4275 | return value;
|
|---|
| 4276 | }
|
|---|
| 4277 | if (isSymbol(value)) {
|
|---|
| 4278 | return NAN;
|
|---|
| 4279 | }
|
|---|
| 4280 | return +value;
|
|---|
| 4281 | }
|
|---|
| 4282 |
|
|---|
| 4283 | /**
|
|---|
| 4284 | * The base implementation of `_.toString` which doesn't convert nullish
|
|---|
| 4285 | * values to empty strings.
|
|---|
| 4286 | *
|
|---|
| 4287 | * @private
|
|---|
| 4288 | * @param {*} value The value to process.
|
|---|
| 4289 | * @returns {string} Returns the string.
|
|---|
| 4290 | */
|
|---|
| 4291 | function baseToString(value) {
|
|---|
| 4292 | // Exit early for strings to avoid a performance hit in some environments.
|
|---|
| 4293 | if (typeof value == 'string') {
|
|---|
| 4294 | return value;
|
|---|
| 4295 | }
|
|---|
| 4296 | if (isArray(value)) {
|
|---|
| 4297 | // Recursively convert values (susceptible to call stack limits).
|
|---|
| 4298 | return arrayMap(value, baseToString) + '';
|
|---|
| 4299 | }
|
|---|
| 4300 | if (isSymbol(value)) {
|
|---|
| 4301 | return symbolToString ? symbolToString.call(value) : '';
|
|---|
| 4302 | }
|
|---|
| 4303 | var result = (value + '');
|
|---|
| 4304 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
|---|
| 4305 | }
|
|---|
| 4306 |
|
|---|
| 4307 | /**
|
|---|
| 4308 | * The base implementation of `_.uniqBy` without support for iteratee shorthands.
|
|---|
| 4309 | *
|
|---|
| 4310 | * @private
|
|---|
| 4311 | * @param {Array} array The array to inspect.
|
|---|
| 4312 | * @param {Function} [iteratee] The iteratee invoked per element.
|
|---|
| 4313 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 4314 | * @returns {Array} Returns the new duplicate free array.
|
|---|
| 4315 | */
|
|---|
| 4316 | function baseUniq(array, iteratee, comparator) {
|
|---|
| 4317 | var index = -1,
|
|---|
| 4318 | includes = arrayIncludes,
|
|---|
| 4319 | length = array.length,
|
|---|
| 4320 | isCommon = true,
|
|---|
| 4321 | result = [],
|
|---|
| 4322 | seen = result;
|
|---|
| 4323 |
|
|---|
| 4324 | if (comparator) {
|
|---|
| 4325 | isCommon = false;
|
|---|
| 4326 | includes = arrayIncludesWith;
|
|---|
| 4327 | }
|
|---|
| 4328 | else if (length >= LARGE_ARRAY_SIZE) {
|
|---|
| 4329 | var set = iteratee ? null : createSet(array);
|
|---|
| 4330 | if (set) {
|
|---|
| 4331 | return setToArray(set);
|
|---|
| 4332 | }
|
|---|
| 4333 | isCommon = false;
|
|---|
| 4334 | includes = cacheHas;
|
|---|
| 4335 | seen = new SetCache;
|
|---|
| 4336 | }
|
|---|
| 4337 | else {
|
|---|
| 4338 | seen = iteratee ? [] : result;
|
|---|
| 4339 | }
|
|---|
| 4340 | outer:
|
|---|
| 4341 | while (++index < length) {
|
|---|
| 4342 | var value = array[index],
|
|---|
| 4343 | computed = iteratee ? iteratee(value) : value;
|
|---|
| 4344 |
|
|---|
| 4345 | value = (comparator || value !== 0) ? value : 0;
|
|---|
| 4346 | if (isCommon && computed === computed) {
|
|---|
| 4347 | var seenIndex = seen.length;
|
|---|
| 4348 | while (seenIndex--) {
|
|---|
| 4349 | if (seen[seenIndex] === computed) {
|
|---|
| 4350 | continue outer;
|
|---|
| 4351 | }
|
|---|
| 4352 | }
|
|---|
| 4353 | if (iteratee) {
|
|---|
| 4354 | seen.push(computed);
|
|---|
| 4355 | }
|
|---|
| 4356 | result.push(value);
|
|---|
| 4357 | }
|
|---|
| 4358 | else if (!includes(seen, computed, comparator)) {
|
|---|
| 4359 | if (seen !== result) {
|
|---|
| 4360 | seen.push(computed);
|
|---|
| 4361 | }
|
|---|
| 4362 | result.push(value);
|
|---|
| 4363 | }
|
|---|
| 4364 | }
|
|---|
| 4365 | return result;
|
|---|
| 4366 | }
|
|---|
| 4367 |
|
|---|
| 4368 | /**
|
|---|
| 4369 | * The base implementation of `_.unset`.
|
|---|
| 4370 | *
|
|---|
| 4371 | * @private
|
|---|
| 4372 | * @param {Object} object The object to modify.
|
|---|
| 4373 | * @param {Array|string} path The property path to unset.
|
|---|
| 4374 | * @returns {boolean} Returns `true` if the property is deleted, else `false`.
|
|---|
| 4375 | */
|
|---|
| 4376 | function baseUnset(object, path) {
|
|---|
| 4377 | path = castPath(path, object);
|
|---|
| 4378 |
|
|---|
| 4379 | // Prevent prototype pollution:
|
|---|
| 4380 | // https://github.com/lodash/lodash/security/advisories/GHSA-xxjr-mmjv-4gpg
|
|---|
| 4381 | // https://github.com/lodash/lodash/security/advisories/GHSA-f23m-r3pf-42rh
|
|---|
| 4382 | var index = -1,
|
|---|
| 4383 | length = path.length;
|
|---|
| 4384 |
|
|---|
| 4385 | if (!length) {
|
|---|
| 4386 | return true;
|
|---|
| 4387 | }
|
|---|
| 4388 |
|
|---|
| 4389 | while (++index < length) {
|
|---|
| 4390 | var key = toKey(path[index]);
|
|---|
| 4391 |
|
|---|
| 4392 | // Always block "__proto__" anywhere in the path if it's not expected
|
|---|
| 4393 | if (key === '__proto__' && !hasOwnProperty.call(object, '__proto__')) {
|
|---|
| 4394 | return false;
|
|---|
| 4395 | }
|
|---|
| 4396 |
|
|---|
| 4397 | // Block constructor/prototype as non-terminal traversal keys to prevent
|
|---|
| 4398 | // escaping the object graph into built-in constructors and prototypes.
|
|---|
| 4399 | if ((key === 'constructor' || key === 'prototype') && index < length - 1) {
|
|---|
| 4400 | return false;
|
|---|
| 4401 | }
|
|---|
| 4402 | }
|
|---|
| 4403 |
|
|---|
| 4404 | var obj = parent(object, path);
|
|---|
| 4405 | return obj == null || delete obj[toKey(last(path))];
|
|---|
| 4406 | }
|
|---|
| 4407 |
|
|---|
| 4408 | /**
|
|---|
| 4409 | * The base implementation of `_.update`.
|
|---|
| 4410 | *
|
|---|
| 4411 | * @private
|
|---|
| 4412 | * @param {Object} object The object to modify.
|
|---|
| 4413 | * @param {Array|string} path The path of the property to update.
|
|---|
| 4414 | * @param {Function} updater The function to produce the updated value.
|
|---|
| 4415 | * @param {Function} [customizer] The function to customize path creation.
|
|---|
| 4416 | * @returns {Object} Returns `object`.
|
|---|
| 4417 | */
|
|---|
| 4418 | function baseUpdate(object, path, updater, customizer) {
|
|---|
| 4419 | return baseSet(object, path, updater(baseGet(object, path)), customizer);
|
|---|
| 4420 | }
|
|---|
| 4421 |
|
|---|
| 4422 | /**
|
|---|
| 4423 | * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
|
|---|
| 4424 | * without support for iteratee shorthands.
|
|---|
| 4425 | *
|
|---|
| 4426 | * @private
|
|---|
| 4427 | * @param {Array} array The array to query.
|
|---|
| 4428 | * @param {Function} predicate The function invoked per iteration.
|
|---|
| 4429 | * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
|
|---|
| 4430 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
|---|
| 4431 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 4432 | */
|
|---|
| 4433 | function baseWhile(array, predicate, isDrop, fromRight) {
|
|---|
| 4434 | var length = array.length,
|
|---|
| 4435 | index = fromRight ? length : -1;
|
|---|
| 4436 |
|
|---|
| 4437 | while ((fromRight ? index-- : ++index < length) &&
|
|---|
| 4438 | predicate(array[index], index, array)) {}
|
|---|
| 4439 |
|
|---|
| 4440 | return isDrop
|
|---|
| 4441 | ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
|
|---|
| 4442 | : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
|
|---|
| 4443 | }
|
|---|
| 4444 |
|
|---|
| 4445 | /**
|
|---|
| 4446 | * The base implementation of `wrapperValue` which returns the result of
|
|---|
| 4447 | * performing a sequence of actions on the unwrapped `value`, where each
|
|---|
| 4448 | * successive action is supplied the return value of the previous.
|
|---|
| 4449 | *
|
|---|
| 4450 | * @private
|
|---|
| 4451 | * @param {*} value The unwrapped value.
|
|---|
| 4452 | * @param {Array} actions Actions to perform to resolve the unwrapped value.
|
|---|
| 4453 | * @returns {*} Returns the resolved value.
|
|---|
| 4454 | */
|
|---|
| 4455 | function baseWrapperValue(value, actions) {
|
|---|
| 4456 | var result = value;
|
|---|
| 4457 | if (result instanceof LazyWrapper) {
|
|---|
| 4458 | result = result.value();
|
|---|
| 4459 | }
|
|---|
| 4460 | return arrayReduce(actions, function(result, action) {
|
|---|
| 4461 | return action.func.apply(action.thisArg, arrayPush([result], action.args));
|
|---|
| 4462 | }, result);
|
|---|
| 4463 | }
|
|---|
| 4464 |
|
|---|
| 4465 | /**
|
|---|
| 4466 | * The base implementation of methods like `_.xor`, without support for
|
|---|
| 4467 | * iteratee shorthands, that accepts an array of arrays to inspect.
|
|---|
| 4468 | *
|
|---|
| 4469 | * @private
|
|---|
| 4470 | * @param {Array} arrays The arrays to inspect.
|
|---|
| 4471 | * @param {Function} [iteratee] The iteratee invoked per element.
|
|---|
| 4472 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 4473 | * @returns {Array} Returns the new array of values.
|
|---|
| 4474 | */
|
|---|
| 4475 | function baseXor(arrays, iteratee, comparator) {
|
|---|
| 4476 | var length = arrays.length;
|
|---|
| 4477 | if (length < 2) {
|
|---|
| 4478 | return length ? baseUniq(arrays[0]) : [];
|
|---|
| 4479 | }
|
|---|
| 4480 | var index = -1,
|
|---|
| 4481 | result = Array(length);
|
|---|
| 4482 |
|
|---|
| 4483 | while (++index < length) {
|
|---|
| 4484 | var array = arrays[index],
|
|---|
| 4485 | othIndex = -1;
|
|---|
| 4486 |
|
|---|
| 4487 | while (++othIndex < length) {
|
|---|
| 4488 | if (othIndex != index) {
|
|---|
| 4489 | result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
|
|---|
| 4490 | }
|
|---|
| 4491 | }
|
|---|
| 4492 | }
|
|---|
| 4493 | return baseUniq(baseFlatten(result, 1), iteratee, comparator);
|
|---|
| 4494 | }
|
|---|
| 4495 |
|
|---|
| 4496 | /**
|
|---|
| 4497 | * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
|
|---|
| 4498 | *
|
|---|
| 4499 | * @private
|
|---|
| 4500 | * @param {Array} props The property identifiers.
|
|---|
| 4501 | * @param {Array} values The property values.
|
|---|
| 4502 | * @param {Function} assignFunc The function to assign values.
|
|---|
| 4503 | * @returns {Object} Returns the new object.
|
|---|
| 4504 | */
|
|---|
| 4505 | function baseZipObject(props, values, assignFunc) {
|
|---|
| 4506 | var index = -1,
|
|---|
| 4507 | length = props.length,
|
|---|
| 4508 | valsLength = values.length,
|
|---|
| 4509 | result = {};
|
|---|
| 4510 |
|
|---|
| 4511 | while (++index < length) {
|
|---|
| 4512 | var value = index < valsLength ? values[index] : undefined;
|
|---|
| 4513 | assignFunc(result, props[index], value);
|
|---|
| 4514 | }
|
|---|
| 4515 | return result;
|
|---|
| 4516 | }
|
|---|
| 4517 |
|
|---|
| 4518 | /**
|
|---|
| 4519 | * Casts `value` to an empty array if it's not an array like object.
|
|---|
| 4520 | *
|
|---|
| 4521 | * @private
|
|---|
| 4522 | * @param {*} value The value to inspect.
|
|---|
| 4523 | * @returns {Array|Object} Returns the cast array-like object.
|
|---|
| 4524 | */
|
|---|
| 4525 | function castArrayLikeObject(value) {
|
|---|
| 4526 | return isArrayLikeObject(value) ? value : [];
|
|---|
| 4527 | }
|
|---|
| 4528 |
|
|---|
| 4529 | /**
|
|---|
| 4530 | * Casts `value` to `identity` if it's not a function.
|
|---|
| 4531 | *
|
|---|
| 4532 | * @private
|
|---|
| 4533 | * @param {*} value The value to inspect.
|
|---|
| 4534 | * @returns {Function} Returns cast function.
|
|---|
| 4535 | */
|
|---|
| 4536 | function castFunction(value) {
|
|---|
| 4537 | return typeof value == 'function' ? value : identity;
|
|---|
| 4538 | }
|
|---|
| 4539 |
|
|---|
| 4540 | /**
|
|---|
| 4541 | * Casts `value` to a path array if it's not one.
|
|---|
| 4542 | *
|
|---|
| 4543 | * @private
|
|---|
| 4544 | * @param {*} value The value to inspect.
|
|---|
| 4545 | * @param {Object} [object] The object to query keys on.
|
|---|
| 4546 | * @returns {Array} Returns the cast property path array.
|
|---|
| 4547 | */
|
|---|
| 4548 | function castPath(value, object) {
|
|---|
| 4549 | if (isArray(value)) {
|
|---|
| 4550 | return value;
|
|---|
| 4551 | }
|
|---|
| 4552 | return isKey(value, object) ? [value] : stringToPath(toString(value));
|
|---|
| 4553 | }
|
|---|
| 4554 |
|
|---|
| 4555 | /**
|
|---|
| 4556 | * A `baseRest` alias which can be replaced with `identity` by module
|
|---|
| 4557 | * replacement plugins.
|
|---|
| 4558 | *
|
|---|
| 4559 | * @private
|
|---|
| 4560 | * @type {Function}
|
|---|
| 4561 | * @param {Function} func The function to apply a rest parameter to.
|
|---|
| 4562 | * @returns {Function} Returns the new function.
|
|---|
| 4563 | */
|
|---|
| 4564 | var castRest = baseRest;
|
|---|
| 4565 |
|
|---|
| 4566 | /**
|
|---|
| 4567 | * Casts `array` to a slice if it's needed.
|
|---|
| 4568 | *
|
|---|
| 4569 | * @private
|
|---|
| 4570 | * @param {Array} array The array to inspect.
|
|---|
| 4571 | * @param {number} start The start position.
|
|---|
| 4572 | * @param {number} [end=array.length] The end position.
|
|---|
| 4573 | * @returns {Array} Returns the cast slice.
|
|---|
| 4574 | */
|
|---|
| 4575 | function castSlice(array, start, end) {
|
|---|
| 4576 | var length = array.length;
|
|---|
| 4577 | end = end === undefined ? length : end;
|
|---|
| 4578 | return (!start && end >= length) ? array : baseSlice(array, start, end);
|
|---|
| 4579 | }
|
|---|
| 4580 |
|
|---|
| 4581 | /**
|
|---|
| 4582 | * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
|
|---|
| 4583 | *
|
|---|
| 4584 | * @private
|
|---|
| 4585 | * @param {number|Object} id The timer id or timeout object of the timer to clear.
|
|---|
| 4586 | */
|
|---|
| 4587 | var clearTimeout = ctxClearTimeout || function(id) {
|
|---|
| 4588 | return root.clearTimeout(id);
|
|---|
| 4589 | };
|
|---|
| 4590 |
|
|---|
| 4591 | /**
|
|---|
| 4592 | * Creates a clone of `buffer`.
|
|---|
| 4593 | *
|
|---|
| 4594 | * @private
|
|---|
| 4595 | * @param {Buffer} buffer The buffer to clone.
|
|---|
| 4596 | * @param {boolean} [isDeep] Specify a deep clone.
|
|---|
| 4597 | * @returns {Buffer} Returns the cloned buffer.
|
|---|
| 4598 | */
|
|---|
| 4599 | function cloneBuffer(buffer, isDeep) {
|
|---|
| 4600 | if (isDeep) {
|
|---|
| 4601 | return buffer.slice();
|
|---|
| 4602 | }
|
|---|
| 4603 | var length = buffer.length,
|
|---|
| 4604 | result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
|
|---|
| 4605 |
|
|---|
| 4606 | buffer.copy(result);
|
|---|
| 4607 | return result;
|
|---|
| 4608 | }
|
|---|
| 4609 |
|
|---|
| 4610 | /**
|
|---|
| 4611 | * Creates a clone of `arrayBuffer`.
|
|---|
| 4612 | *
|
|---|
| 4613 | * @private
|
|---|
| 4614 | * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
|
|---|
| 4615 | * @returns {ArrayBuffer} Returns the cloned array buffer.
|
|---|
| 4616 | */
|
|---|
| 4617 | function cloneArrayBuffer(arrayBuffer) {
|
|---|
| 4618 | var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|---|
| 4619 | new Uint8Array(result).set(new Uint8Array(arrayBuffer));
|
|---|
| 4620 | return result;
|
|---|
| 4621 | }
|
|---|
| 4622 |
|
|---|
| 4623 | /**
|
|---|
| 4624 | * Creates a clone of `dataView`.
|
|---|
| 4625 | *
|
|---|
| 4626 | * @private
|
|---|
| 4627 | * @param {Object} dataView The data view to clone.
|
|---|
| 4628 | * @param {boolean} [isDeep] Specify a deep clone.
|
|---|
| 4629 | * @returns {Object} Returns the cloned data view.
|
|---|
| 4630 | */
|
|---|
| 4631 | function cloneDataView(dataView, isDeep) {
|
|---|
| 4632 | var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
|
|---|
| 4633 | return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
|---|
| 4634 | }
|
|---|
| 4635 |
|
|---|
| 4636 | /**
|
|---|
| 4637 | * Creates a clone of `regexp`.
|
|---|
| 4638 | *
|
|---|
| 4639 | * @private
|
|---|
| 4640 | * @param {Object} regexp The regexp to clone.
|
|---|
| 4641 | * @returns {Object} Returns the cloned regexp.
|
|---|
| 4642 | */
|
|---|
| 4643 | function cloneRegExp(regexp) {
|
|---|
| 4644 | var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
|---|
| 4645 | result.lastIndex = regexp.lastIndex;
|
|---|
| 4646 | return result;
|
|---|
| 4647 | }
|
|---|
| 4648 |
|
|---|
| 4649 | /**
|
|---|
| 4650 | * Creates a clone of the `symbol` object.
|
|---|
| 4651 | *
|
|---|
| 4652 | * @private
|
|---|
| 4653 | * @param {Object} symbol The symbol object to clone.
|
|---|
| 4654 | * @returns {Object} Returns the cloned symbol object.
|
|---|
| 4655 | */
|
|---|
| 4656 | function cloneSymbol(symbol) {
|
|---|
| 4657 | return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
|---|
| 4658 | }
|
|---|
| 4659 |
|
|---|
| 4660 | /**
|
|---|
| 4661 | * Creates a clone of `typedArray`.
|
|---|
| 4662 | *
|
|---|
| 4663 | * @private
|
|---|
| 4664 | * @param {Object} typedArray The typed array to clone.
|
|---|
| 4665 | * @param {boolean} [isDeep] Specify a deep clone.
|
|---|
| 4666 | * @returns {Object} Returns the cloned typed array.
|
|---|
| 4667 | */
|
|---|
| 4668 | function cloneTypedArray(typedArray, isDeep) {
|
|---|
| 4669 | var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
|---|
| 4670 | return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
|---|
| 4671 | }
|
|---|
| 4672 |
|
|---|
| 4673 | /**
|
|---|
| 4674 | * Compares values to sort them in ascending order.
|
|---|
| 4675 | *
|
|---|
| 4676 | * @private
|
|---|
| 4677 | * @param {*} value The value to compare.
|
|---|
| 4678 | * @param {*} other The other value to compare.
|
|---|
| 4679 | * @returns {number} Returns the sort order indicator for `value`.
|
|---|
| 4680 | */
|
|---|
| 4681 | function compareAscending(value, other) {
|
|---|
| 4682 | if (value !== other) {
|
|---|
| 4683 | var valIsDefined = value !== undefined,
|
|---|
| 4684 | valIsNull = value === null,
|
|---|
| 4685 | valIsReflexive = value === value,
|
|---|
| 4686 | valIsSymbol = isSymbol(value);
|
|---|
| 4687 |
|
|---|
| 4688 | var othIsDefined = other !== undefined,
|
|---|
| 4689 | othIsNull = other === null,
|
|---|
| 4690 | othIsReflexive = other === other,
|
|---|
| 4691 | othIsSymbol = isSymbol(other);
|
|---|
| 4692 |
|
|---|
| 4693 | if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
|
|---|
| 4694 | (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
|
|---|
| 4695 | (valIsNull && othIsDefined && othIsReflexive) ||
|
|---|
| 4696 | (!valIsDefined && othIsReflexive) ||
|
|---|
| 4697 | !valIsReflexive) {
|
|---|
| 4698 | return 1;
|
|---|
| 4699 | }
|
|---|
| 4700 | if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
|
|---|
| 4701 | (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
|
|---|
| 4702 | (othIsNull && valIsDefined && valIsReflexive) ||
|
|---|
| 4703 | (!othIsDefined && valIsReflexive) ||
|
|---|
| 4704 | !othIsReflexive) {
|
|---|
| 4705 | return -1;
|
|---|
| 4706 | }
|
|---|
| 4707 | }
|
|---|
| 4708 | return 0;
|
|---|
| 4709 | }
|
|---|
| 4710 |
|
|---|
| 4711 | /**
|
|---|
| 4712 | * Used by `_.orderBy` to compare multiple properties of a value to another
|
|---|
| 4713 | * and stable sort them.
|
|---|
| 4714 | *
|
|---|
| 4715 | * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
|
|---|
| 4716 | * specify an order of "desc" for descending or "asc" for ascending sort order
|
|---|
| 4717 | * of corresponding values.
|
|---|
| 4718 | *
|
|---|
| 4719 | * @private
|
|---|
| 4720 | * @param {Object} object The object to compare.
|
|---|
| 4721 | * @param {Object} other The other object to compare.
|
|---|
| 4722 | * @param {boolean[]|string[]} orders The order to sort by for each property.
|
|---|
| 4723 | * @returns {number} Returns the sort order indicator for `object`.
|
|---|
| 4724 | */
|
|---|
| 4725 | function compareMultiple(object, other, orders) {
|
|---|
| 4726 | var index = -1,
|
|---|
| 4727 | objCriteria = object.criteria,
|
|---|
| 4728 | othCriteria = other.criteria,
|
|---|
| 4729 | length = objCriteria.length,
|
|---|
| 4730 | ordersLength = orders.length;
|
|---|
| 4731 |
|
|---|
| 4732 | while (++index < length) {
|
|---|
| 4733 | var result = compareAscending(objCriteria[index], othCriteria[index]);
|
|---|
| 4734 | if (result) {
|
|---|
| 4735 | if (index >= ordersLength) {
|
|---|
| 4736 | return result;
|
|---|
| 4737 | }
|
|---|
| 4738 | var order = orders[index];
|
|---|
| 4739 | return result * (order == 'desc' ? -1 : 1);
|
|---|
| 4740 | }
|
|---|
| 4741 | }
|
|---|
| 4742 | // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
|---|
| 4743 | // that causes it, under certain circumstances, to provide the same value for
|
|---|
| 4744 | // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
|
|---|
| 4745 | // for more details.
|
|---|
| 4746 | //
|
|---|
| 4747 | // This also ensures a stable sort in V8 and other engines.
|
|---|
| 4748 | // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
|
|---|
| 4749 | return object.index - other.index;
|
|---|
| 4750 | }
|
|---|
| 4751 |
|
|---|
| 4752 | /**
|
|---|
| 4753 | * Creates an array that is the composition of partially applied arguments,
|
|---|
| 4754 | * placeholders, and provided arguments into a single array of arguments.
|
|---|
| 4755 | *
|
|---|
| 4756 | * @private
|
|---|
| 4757 | * @param {Array} args The provided arguments.
|
|---|
| 4758 | * @param {Array} partials The arguments to prepend to those provided.
|
|---|
| 4759 | * @param {Array} holders The `partials` placeholder indexes.
|
|---|
| 4760 | * @params {boolean} [isCurried] Specify composing for a curried function.
|
|---|
| 4761 | * @returns {Array} Returns the new array of composed arguments.
|
|---|
| 4762 | */
|
|---|
| 4763 | function composeArgs(args, partials, holders, isCurried) {
|
|---|
| 4764 | var argsIndex = -1,
|
|---|
| 4765 | argsLength = args.length,
|
|---|
| 4766 | holdersLength = holders.length,
|
|---|
| 4767 | leftIndex = -1,
|
|---|
| 4768 | leftLength = partials.length,
|
|---|
| 4769 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
|---|
| 4770 | result = Array(leftLength + rangeLength),
|
|---|
| 4771 | isUncurried = !isCurried;
|
|---|
| 4772 |
|
|---|
| 4773 | while (++leftIndex < leftLength) {
|
|---|
| 4774 | result[leftIndex] = partials[leftIndex];
|
|---|
| 4775 | }
|
|---|
| 4776 | while (++argsIndex < holdersLength) {
|
|---|
| 4777 | if (isUncurried || argsIndex < argsLength) {
|
|---|
| 4778 | result[holders[argsIndex]] = args[argsIndex];
|
|---|
| 4779 | }
|
|---|
| 4780 | }
|
|---|
| 4781 | while (rangeLength--) {
|
|---|
| 4782 | result[leftIndex++] = args[argsIndex++];
|
|---|
| 4783 | }
|
|---|
| 4784 | return result;
|
|---|
| 4785 | }
|
|---|
| 4786 |
|
|---|
| 4787 | /**
|
|---|
| 4788 | * This function is like `composeArgs` except that the arguments composition
|
|---|
| 4789 | * is tailored for `_.partialRight`.
|
|---|
| 4790 | *
|
|---|
| 4791 | * @private
|
|---|
| 4792 | * @param {Array} args The provided arguments.
|
|---|
| 4793 | * @param {Array} partials The arguments to append to those provided.
|
|---|
| 4794 | * @param {Array} holders The `partials` placeholder indexes.
|
|---|
| 4795 | * @params {boolean} [isCurried] Specify composing for a curried function.
|
|---|
| 4796 | * @returns {Array} Returns the new array of composed arguments.
|
|---|
| 4797 | */
|
|---|
| 4798 | function composeArgsRight(args, partials, holders, isCurried) {
|
|---|
| 4799 | var argsIndex = -1,
|
|---|
| 4800 | argsLength = args.length,
|
|---|
| 4801 | holdersIndex = -1,
|
|---|
| 4802 | holdersLength = holders.length,
|
|---|
| 4803 | rightIndex = -1,
|
|---|
| 4804 | rightLength = partials.length,
|
|---|
| 4805 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
|---|
| 4806 | result = Array(rangeLength + rightLength),
|
|---|
| 4807 | isUncurried = !isCurried;
|
|---|
| 4808 |
|
|---|
| 4809 | while (++argsIndex < rangeLength) {
|
|---|
| 4810 | result[argsIndex] = args[argsIndex];
|
|---|
| 4811 | }
|
|---|
| 4812 | var offset = argsIndex;
|
|---|
| 4813 | while (++rightIndex < rightLength) {
|
|---|
| 4814 | result[offset + rightIndex] = partials[rightIndex];
|
|---|
| 4815 | }
|
|---|
| 4816 | while (++holdersIndex < holdersLength) {
|
|---|
| 4817 | if (isUncurried || argsIndex < argsLength) {
|
|---|
| 4818 | result[offset + holders[holdersIndex]] = args[argsIndex++];
|
|---|
| 4819 | }
|
|---|
| 4820 | }
|
|---|
| 4821 | return result;
|
|---|
| 4822 | }
|
|---|
| 4823 |
|
|---|
| 4824 | /**
|
|---|
| 4825 | * Copies the values of `source` to `array`.
|
|---|
| 4826 | *
|
|---|
| 4827 | * @private
|
|---|
| 4828 | * @param {Array} source The array to copy values from.
|
|---|
| 4829 | * @param {Array} [array=[]] The array to copy values to.
|
|---|
| 4830 | * @returns {Array} Returns `array`.
|
|---|
| 4831 | */
|
|---|
| 4832 | function copyArray(source, array) {
|
|---|
| 4833 | var index = -1,
|
|---|
| 4834 | length = source.length;
|
|---|
| 4835 |
|
|---|
| 4836 | array || (array = Array(length));
|
|---|
| 4837 | while (++index < length) {
|
|---|
| 4838 | array[index] = source[index];
|
|---|
| 4839 | }
|
|---|
| 4840 | return array;
|
|---|
| 4841 | }
|
|---|
| 4842 |
|
|---|
| 4843 | /**
|
|---|
| 4844 | * Copies properties of `source` to `object`.
|
|---|
| 4845 | *
|
|---|
| 4846 | * @private
|
|---|
| 4847 | * @param {Object} source The object to copy properties from.
|
|---|
| 4848 | * @param {Array} props The property identifiers to copy.
|
|---|
| 4849 | * @param {Object} [object={}] The object to copy properties to.
|
|---|
| 4850 | * @param {Function} [customizer] The function to customize copied values.
|
|---|
| 4851 | * @returns {Object} Returns `object`.
|
|---|
| 4852 | */
|
|---|
| 4853 | function copyObject(source, props, object, customizer) {
|
|---|
| 4854 | var isNew = !object;
|
|---|
| 4855 | object || (object = {});
|
|---|
| 4856 |
|
|---|
| 4857 | var index = -1,
|
|---|
| 4858 | length = props.length;
|
|---|
| 4859 |
|
|---|
| 4860 | while (++index < length) {
|
|---|
| 4861 | var key = props[index];
|
|---|
| 4862 |
|
|---|
| 4863 | var newValue = customizer
|
|---|
| 4864 | ? customizer(object[key], source[key], key, object, source)
|
|---|
| 4865 | : undefined;
|
|---|
| 4866 |
|
|---|
| 4867 | if (newValue === undefined) {
|
|---|
| 4868 | newValue = source[key];
|
|---|
| 4869 | }
|
|---|
| 4870 | if (isNew) {
|
|---|
| 4871 | baseAssignValue(object, key, newValue);
|
|---|
| 4872 | } else {
|
|---|
| 4873 | assignValue(object, key, newValue);
|
|---|
| 4874 | }
|
|---|
| 4875 | }
|
|---|
| 4876 | return object;
|
|---|
| 4877 | }
|
|---|
| 4878 |
|
|---|
| 4879 | /**
|
|---|
| 4880 | * Copies own symbols of `source` to `object`.
|
|---|
| 4881 | *
|
|---|
| 4882 | * @private
|
|---|
| 4883 | * @param {Object} source The object to copy symbols from.
|
|---|
| 4884 | * @param {Object} [object={}] The object to copy symbols to.
|
|---|
| 4885 | * @returns {Object} Returns `object`.
|
|---|
| 4886 | */
|
|---|
| 4887 | function copySymbols(source, object) {
|
|---|
| 4888 | return copyObject(source, getSymbols(source), object);
|
|---|
| 4889 | }
|
|---|
| 4890 |
|
|---|
| 4891 | /**
|
|---|
| 4892 | * Copies own and inherited symbols of `source` to `object`.
|
|---|
| 4893 | *
|
|---|
| 4894 | * @private
|
|---|
| 4895 | * @param {Object} source The object to copy symbols from.
|
|---|
| 4896 | * @param {Object} [object={}] The object to copy symbols to.
|
|---|
| 4897 | * @returns {Object} Returns `object`.
|
|---|
| 4898 | */
|
|---|
| 4899 | function copySymbolsIn(source, object) {
|
|---|
| 4900 | return copyObject(source, getSymbolsIn(source), object);
|
|---|
| 4901 | }
|
|---|
| 4902 |
|
|---|
| 4903 | /**
|
|---|
| 4904 | * Creates a function like `_.groupBy`.
|
|---|
| 4905 | *
|
|---|
| 4906 | * @private
|
|---|
| 4907 | * @param {Function} setter The function to set accumulator values.
|
|---|
| 4908 | * @param {Function} [initializer] The accumulator object initializer.
|
|---|
| 4909 | * @returns {Function} Returns the new aggregator function.
|
|---|
| 4910 | */
|
|---|
| 4911 | function createAggregator(setter, initializer) {
|
|---|
| 4912 | return function(collection, iteratee) {
|
|---|
| 4913 | var func = isArray(collection) ? arrayAggregator : baseAggregator,
|
|---|
| 4914 | accumulator = initializer ? initializer() : {};
|
|---|
| 4915 |
|
|---|
| 4916 | return func(collection, setter, getIteratee(iteratee, 2), accumulator);
|
|---|
| 4917 | };
|
|---|
| 4918 | }
|
|---|
| 4919 |
|
|---|
| 4920 | /**
|
|---|
| 4921 | * Creates a function like `_.assign`.
|
|---|
| 4922 | *
|
|---|
| 4923 | * @private
|
|---|
| 4924 | * @param {Function} assigner The function to assign values.
|
|---|
| 4925 | * @returns {Function} Returns the new assigner function.
|
|---|
| 4926 | */
|
|---|
| 4927 | function createAssigner(assigner) {
|
|---|
| 4928 | return baseRest(function(object, sources) {
|
|---|
| 4929 | var index = -1,
|
|---|
| 4930 | length = sources.length,
|
|---|
| 4931 | customizer = length > 1 ? sources[length - 1] : undefined,
|
|---|
| 4932 | guard = length > 2 ? sources[2] : undefined;
|
|---|
| 4933 |
|
|---|
| 4934 | customizer = (assigner.length > 3 && typeof customizer == 'function')
|
|---|
| 4935 | ? (length--, customizer)
|
|---|
| 4936 | : undefined;
|
|---|
| 4937 |
|
|---|
| 4938 | if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
|---|
| 4939 | customizer = length < 3 ? undefined : customizer;
|
|---|
| 4940 | length = 1;
|
|---|
| 4941 | }
|
|---|
| 4942 | object = Object(object);
|
|---|
| 4943 | while (++index < length) {
|
|---|
| 4944 | var source = sources[index];
|
|---|
| 4945 | if (source) {
|
|---|
| 4946 | assigner(object, source, index, customizer);
|
|---|
| 4947 | }
|
|---|
| 4948 | }
|
|---|
| 4949 | return object;
|
|---|
| 4950 | });
|
|---|
| 4951 | }
|
|---|
| 4952 |
|
|---|
| 4953 | /**
|
|---|
| 4954 | * Creates a `baseEach` or `baseEachRight` function.
|
|---|
| 4955 | *
|
|---|
| 4956 | * @private
|
|---|
| 4957 | * @param {Function} eachFunc The function to iterate over a collection.
|
|---|
| 4958 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
|---|
| 4959 | * @returns {Function} Returns the new base function.
|
|---|
| 4960 | */
|
|---|
| 4961 | function createBaseEach(eachFunc, fromRight) {
|
|---|
| 4962 | return function(collection, iteratee) {
|
|---|
| 4963 | if (collection == null) {
|
|---|
| 4964 | return collection;
|
|---|
| 4965 | }
|
|---|
| 4966 | if (!isArrayLike(collection)) {
|
|---|
| 4967 | return eachFunc(collection, iteratee);
|
|---|
| 4968 | }
|
|---|
| 4969 | var length = collection.length,
|
|---|
| 4970 | index = fromRight ? length : -1,
|
|---|
| 4971 | iterable = Object(collection);
|
|---|
| 4972 |
|
|---|
| 4973 | while ((fromRight ? index-- : ++index < length)) {
|
|---|
| 4974 | if (iteratee(iterable[index], index, iterable) === false) {
|
|---|
| 4975 | break;
|
|---|
| 4976 | }
|
|---|
| 4977 | }
|
|---|
| 4978 | return collection;
|
|---|
| 4979 | };
|
|---|
| 4980 | }
|
|---|
| 4981 |
|
|---|
| 4982 | /**
|
|---|
| 4983 | * Creates a base function for methods like `_.forIn` and `_.forOwn`.
|
|---|
| 4984 | *
|
|---|
| 4985 | * @private
|
|---|
| 4986 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
|---|
| 4987 | * @returns {Function} Returns the new base function.
|
|---|
| 4988 | */
|
|---|
| 4989 | function createBaseFor(fromRight) {
|
|---|
| 4990 | return function(object, iteratee, keysFunc) {
|
|---|
| 4991 | var index = -1,
|
|---|
| 4992 | iterable = Object(object),
|
|---|
| 4993 | props = keysFunc(object),
|
|---|
| 4994 | length = props.length;
|
|---|
| 4995 |
|
|---|
| 4996 | while (length--) {
|
|---|
| 4997 | var key = props[fromRight ? length : ++index];
|
|---|
| 4998 | if (iteratee(iterable[key], key, iterable) === false) {
|
|---|
| 4999 | break;
|
|---|
| 5000 | }
|
|---|
| 5001 | }
|
|---|
| 5002 | return object;
|
|---|
| 5003 | };
|
|---|
| 5004 | }
|
|---|
| 5005 |
|
|---|
| 5006 | /**
|
|---|
| 5007 | * Creates a function that wraps `func` to invoke it with the optional `this`
|
|---|
| 5008 | * binding of `thisArg`.
|
|---|
| 5009 | *
|
|---|
| 5010 | * @private
|
|---|
| 5011 | * @param {Function} func The function to wrap.
|
|---|
| 5012 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
|---|
| 5013 | * @param {*} [thisArg] The `this` binding of `func`.
|
|---|
| 5014 | * @returns {Function} Returns the new wrapped function.
|
|---|
| 5015 | */
|
|---|
| 5016 | function createBind(func, bitmask, thisArg) {
|
|---|
| 5017 | var isBind = bitmask & WRAP_BIND_FLAG,
|
|---|
| 5018 | Ctor = createCtor(func);
|
|---|
| 5019 |
|
|---|
| 5020 | function wrapper() {
|
|---|
| 5021 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
|---|
| 5022 | return fn.apply(isBind ? thisArg : this, arguments);
|
|---|
| 5023 | }
|
|---|
| 5024 | return wrapper;
|
|---|
| 5025 | }
|
|---|
| 5026 |
|
|---|
| 5027 | /**
|
|---|
| 5028 | * Creates a function like `_.lowerFirst`.
|
|---|
| 5029 | *
|
|---|
| 5030 | * @private
|
|---|
| 5031 | * @param {string} methodName The name of the `String` case method to use.
|
|---|
| 5032 | * @returns {Function} Returns the new case function.
|
|---|
| 5033 | */
|
|---|
| 5034 | function createCaseFirst(methodName) {
|
|---|
| 5035 | return function(string) {
|
|---|
| 5036 | string = toString(string);
|
|---|
| 5037 |
|
|---|
| 5038 | var strSymbols = hasUnicode(string)
|
|---|
| 5039 | ? stringToArray(string)
|
|---|
| 5040 | : undefined;
|
|---|
| 5041 |
|
|---|
| 5042 | var chr = strSymbols
|
|---|
| 5043 | ? strSymbols[0]
|
|---|
| 5044 | : string.charAt(0);
|
|---|
| 5045 |
|
|---|
| 5046 | var trailing = strSymbols
|
|---|
| 5047 | ? castSlice(strSymbols, 1).join('')
|
|---|
| 5048 | : string.slice(1);
|
|---|
| 5049 |
|
|---|
| 5050 | return chr[methodName]() + trailing;
|
|---|
| 5051 | };
|
|---|
| 5052 | }
|
|---|
| 5053 |
|
|---|
| 5054 | /**
|
|---|
| 5055 | * Creates a function like `_.camelCase`.
|
|---|
| 5056 | *
|
|---|
| 5057 | * @private
|
|---|
| 5058 | * @param {Function} callback The function to combine each word.
|
|---|
| 5059 | * @returns {Function} Returns the new compounder function.
|
|---|
| 5060 | */
|
|---|
| 5061 | function createCompounder(callback) {
|
|---|
| 5062 | return function(string) {
|
|---|
| 5063 | return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
|
|---|
| 5064 | };
|
|---|
| 5065 | }
|
|---|
| 5066 |
|
|---|
| 5067 | /**
|
|---|
| 5068 | * Creates a function that produces an instance of `Ctor` regardless of
|
|---|
| 5069 | * whether it was invoked as part of a `new` expression or by `call` or `apply`.
|
|---|
| 5070 | *
|
|---|
| 5071 | * @private
|
|---|
| 5072 | * @param {Function} Ctor The constructor to wrap.
|
|---|
| 5073 | * @returns {Function} Returns the new wrapped function.
|
|---|
| 5074 | */
|
|---|
| 5075 | function createCtor(Ctor) {
|
|---|
| 5076 | return function() {
|
|---|
| 5077 | // Use a `switch` statement to work with class constructors. See
|
|---|
| 5078 | // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
|---|
| 5079 | // for more details.
|
|---|
| 5080 | var args = arguments;
|
|---|
| 5081 | switch (args.length) {
|
|---|
| 5082 | case 0: return new Ctor;
|
|---|
| 5083 | case 1: return new Ctor(args[0]);
|
|---|
| 5084 | case 2: return new Ctor(args[0], args[1]);
|
|---|
| 5085 | case 3: return new Ctor(args[0], args[1], args[2]);
|
|---|
| 5086 | case 4: return new Ctor(args[0], args[1], args[2], args[3]);
|
|---|
| 5087 | case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
|
|---|
| 5088 | case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
|
|---|
| 5089 | case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
|---|
| 5090 | }
|
|---|
| 5091 | var thisBinding = baseCreate(Ctor.prototype),
|
|---|
| 5092 | result = Ctor.apply(thisBinding, args);
|
|---|
| 5093 |
|
|---|
| 5094 | // Mimic the constructor's `return` behavior.
|
|---|
| 5095 | // See https://es5.github.io/#x13.2.2 for more details.
|
|---|
| 5096 | return isObject(result) ? result : thisBinding;
|
|---|
| 5097 | };
|
|---|
| 5098 | }
|
|---|
| 5099 |
|
|---|
| 5100 | /**
|
|---|
| 5101 | * Creates a function that wraps `func` to enable currying.
|
|---|
| 5102 | *
|
|---|
| 5103 | * @private
|
|---|
| 5104 | * @param {Function} func The function to wrap.
|
|---|
| 5105 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
|---|
| 5106 | * @param {number} arity The arity of `func`.
|
|---|
| 5107 | * @returns {Function} Returns the new wrapped function.
|
|---|
| 5108 | */
|
|---|
| 5109 | function createCurry(func, bitmask, arity) {
|
|---|
| 5110 | var Ctor = createCtor(func);
|
|---|
| 5111 |
|
|---|
| 5112 | function wrapper() {
|
|---|
| 5113 | var length = arguments.length,
|
|---|
| 5114 | args = Array(length),
|
|---|
| 5115 | index = length,
|
|---|
| 5116 | placeholder = getHolder(wrapper);
|
|---|
| 5117 |
|
|---|
| 5118 | while (index--) {
|
|---|
| 5119 | args[index] = arguments[index];
|
|---|
| 5120 | }
|
|---|
| 5121 | var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
|
|---|
| 5122 | ? []
|
|---|
| 5123 | : replaceHolders(args, placeholder);
|
|---|
| 5124 |
|
|---|
| 5125 | length -= holders.length;
|
|---|
| 5126 | if (length < arity) {
|
|---|
| 5127 | return createRecurry(
|
|---|
| 5128 | func, bitmask, createHybrid, wrapper.placeholder, undefined,
|
|---|
| 5129 | args, holders, undefined, undefined, arity - length);
|
|---|
| 5130 | }
|
|---|
| 5131 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
|---|
| 5132 | return apply(fn, this, args);
|
|---|
| 5133 | }
|
|---|
| 5134 | return wrapper;
|
|---|
| 5135 | }
|
|---|
| 5136 |
|
|---|
| 5137 | /**
|
|---|
| 5138 | * Creates a `_.find` or `_.findLast` function.
|
|---|
| 5139 | *
|
|---|
| 5140 | * @private
|
|---|
| 5141 | * @param {Function} findIndexFunc The function to find the collection index.
|
|---|
| 5142 | * @returns {Function} Returns the new find function.
|
|---|
| 5143 | */
|
|---|
| 5144 | function createFind(findIndexFunc) {
|
|---|
| 5145 | return function(collection, predicate, fromIndex) {
|
|---|
| 5146 | var iterable = Object(collection);
|
|---|
| 5147 | if (!isArrayLike(collection)) {
|
|---|
| 5148 | var iteratee = getIteratee(predicate, 3);
|
|---|
| 5149 | collection = keys(collection);
|
|---|
| 5150 | predicate = function(key) { return iteratee(iterable[key], key, iterable); };
|
|---|
| 5151 | }
|
|---|
| 5152 | var index = findIndexFunc(collection, predicate, fromIndex);
|
|---|
| 5153 | return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
|
|---|
| 5154 | };
|
|---|
| 5155 | }
|
|---|
| 5156 |
|
|---|
| 5157 | /**
|
|---|
| 5158 | * Creates a `_.flow` or `_.flowRight` function.
|
|---|
| 5159 | *
|
|---|
| 5160 | * @private
|
|---|
| 5161 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
|---|
| 5162 | * @returns {Function} Returns the new flow function.
|
|---|
| 5163 | */
|
|---|
| 5164 | function createFlow(fromRight) {
|
|---|
| 5165 | return flatRest(function(funcs) {
|
|---|
| 5166 | var length = funcs.length,
|
|---|
| 5167 | index = length,
|
|---|
| 5168 | prereq = LodashWrapper.prototype.thru;
|
|---|
| 5169 |
|
|---|
| 5170 | if (fromRight) {
|
|---|
| 5171 | funcs.reverse();
|
|---|
| 5172 | }
|
|---|
| 5173 | while (index--) {
|
|---|
| 5174 | var func = funcs[index];
|
|---|
| 5175 | if (typeof func != 'function') {
|
|---|
| 5176 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 5177 | }
|
|---|
| 5178 | if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
|
|---|
| 5179 | var wrapper = new LodashWrapper([], true);
|
|---|
| 5180 | }
|
|---|
| 5181 | }
|
|---|
| 5182 | index = wrapper ? index : length;
|
|---|
| 5183 | while (++index < length) {
|
|---|
| 5184 | func = funcs[index];
|
|---|
| 5185 |
|
|---|
| 5186 | var funcName = getFuncName(func),
|
|---|
| 5187 | data = funcName == 'wrapper' ? getData(func) : undefined;
|
|---|
| 5188 |
|
|---|
| 5189 | if (data && isLaziable(data[0]) &&
|
|---|
| 5190 | data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
|
|---|
| 5191 | !data[4].length && data[9] == 1
|
|---|
| 5192 | ) {
|
|---|
| 5193 | wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
|
|---|
| 5194 | } else {
|
|---|
| 5195 | wrapper = (func.length == 1 && isLaziable(func))
|
|---|
| 5196 | ? wrapper[funcName]()
|
|---|
| 5197 | : wrapper.thru(func);
|
|---|
| 5198 | }
|
|---|
| 5199 | }
|
|---|
| 5200 | return function() {
|
|---|
| 5201 | var args = arguments,
|
|---|
| 5202 | value = args[0];
|
|---|
| 5203 |
|
|---|
| 5204 | if (wrapper && args.length == 1 && isArray(value)) {
|
|---|
| 5205 | return wrapper.plant(value).value();
|
|---|
| 5206 | }
|
|---|
| 5207 | var index = 0,
|
|---|
| 5208 | result = length ? funcs[index].apply(this, args) : value;
|
|---|
| 5209 |
|
|---|
| 5210 | while (++index < length) {
|
|---|
| 5211 | result = funcs[index].call(this, result);
|
|---|
| 5212 | }
|
|---|
| 5213 | return result;
|
|---|
| 5214 | };
|
|---|
| 5215 | });
|
|---|
| 5216 | }
|
|---|
| 5217 |
|
|---|
| 5218 | /**
|
|---|
| 5219 | * Creates a function that wraps `func` to invoke it with optional `this`
|
|---|
| 5220 | * binding of `thisArg`, partial application, and currying.
|
|---|
| 5221 | *
|
|---|
| 5222 | * @private
|
|---|
| 5223 | * @param {Function|string} func The function or method name to wrap.
|
|---|
| 5224 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
|---|
| 5225 | * @param {*} [thisArg] The `this` binding of `func`.
|
|---|
| 5226 | * @param {Array} [partials] The arguments to prepend to those provided to
|
|---|
| 5227 | * the new function.
|
|---|
| 5228 | * @param {Array} [holders] The `partials` placeholder indexes.
|
|---|
| 5229 | * @param {Array} [partialsRight] The arguments to append to those provided
|
|---|
| 5230 | * to the new function.
|
|---|
| 5231 | * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
|
|---|
| 5232 | * @param {Array} [argPos] The argument positions of the new function.
|
|---|
| 5233 | * @param {number} [ary] The arity cap of `func`.
|
|---|
| 5234 | * @param {number} [arity] The arity of `func`.
|
|---|
| 5235 | * @returns {Function} Returns the new wrapped function.
|
|---|
| 5236 | */
|
|---|
| 5237 | function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
|
|---|
| 5238 | var isAry = bitmask & WRAP_ARY_FLAG,
|
|---|
| 5239 | isBind = bitmask & WRAP_BIND_FLAG,
|
|---|
| 5240 | isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
|
|---|
| 5241 | isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
|
|---|
| 5242 | isFlip = bitmask & WRAP_FLIP_FLAG,
|
|---|
| 5243 | Ctor = isBindKey ? undefined : createCtor(func);
|
|---|
| 5244 |
|
|---|
| 5245 | function wrapper() {
|
|---|
| 5246 | var length = arguments.length,
|
|---|
| 5247 | args = Array(length),
|
|---|
| 5248 | index = length;
|
|---|
| 5249 |
|
|---|
| 5250 | while (index--) {
|
|---|
| 5251 | args[index] = arguments[index];
|
|---|
| 5252 | }
|
|---|
| 5253 | if (isCurried) {
|
|---|
| 5254 | var placeholder = getHolder(wrapper),
|
|---|
| 5255 | holdersCount = countHolders(args, placeholder);
|
|---|
| 5256 | }
|
|---|
| 5257 | if (partials) {
|
|---|
| 5258 | args = composeArgs(args, partials, holders, isCurried);
|
|---|
| 5259 | }
|
|---|
| 5260 | if (partialsRight) {
|
|---|
| 5261 | args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
|
|---|
| 5262 | }
|
|---|
| 5263 | length -= holdersCount;
|
|---|
| 5264 | if (isCurried && length < arity) {
|
|---|
| 5265 | var newHolders = replaceHolders(args, placeholder);
|
|---|
| 5266 | return createRecurry(
|
|---|
| 5267 | func, bitmask, createHybrid, wrapper.placeholder, thisArg,
|
|---|
| 5268 | args, newHolders, argPos, ary, arity - length
|
|---|
| 5269 | );
|
|---|
| 5270 | }
|
|---|
| 5271 | var thisBinding = isBind ? thisArg : this,
|
|---|
| 5272 | fn = isBindKey ? thisBinding[func] : func;
|
|---|
| 5273 |
|
|---|
| 5274 | length = args.length;
|
|---|
| 5275 | if (argPos) {
|
|---|
| 5276 | args = reorder(args, argPos);
|
|---|
| 5277 | } else if (isFlip && length > 1) {
|
|---|
| 5278 | args.reverse();
|
|---|
| 5279 | }
|
|---|
| 5280 | if (isAry && ary < length) {
|
|---|
| 5281 | args.length = ary;
|
|---|
| 5282 | }
|
|---|
| 5283 | if (this && this !== root && this instanceof wrapper) {
|
|---|
| 5284 | fn = Ctor || createCtor(fn);
|
|---|
| 5285 | }
|
|---|
| 5286 | return fn.apply(thisBinding, args);
|
|---|
| 5287 | }
|
|---|
| 5288 | return wrapper;
|
|---|
| 5289 | }
|
|---|
| 5290 |
|
|---|
| 5291 | /**
|
|---|
| 5292 | * Creates a function like `_.invertBy`.
|
|---|
| 5293 | *
|
|---|
| 5294 | * @private
|
|---|
| 5295 | * @param {Function} setter The function to set accumulator values.
|
|---|
| 5296 | * @param {Function} toIteratee The function to resolve iteratees.
|
|---|
| 5297 | * @returns {Function} Returns the new inverter function.
|
|---|
| 5298 | */
|
|---|
| 5299 | function createInverter(setter, toIteratee) {
|
|---|
| 5300 | return function(object, iteratee) {
|
|---|
| 5301 | return baseInverter(object, setter, toIteratee(iteratee), {});
|
|---|
| 5302 | };
|
|---|
| 5303 | }
|
|---|
| 5304 |
|
|---|
| 5305 | /**
|
|---|
| 5306 | * Creates a function that performs a mathematical operation on two values.
|
|---|
| 5307 | *
|
|---|
| 5308 | * @private
|
|---|
| 5309 | * @param {Function} operator The function to perform the operation.
|
|---|
| 5310 | * @param {number} [defaultValue] The value used for `undefined` arguments.
|
|---|
| 5311 | * @returns {Function} Returns the new mathematical operation function.
|
|---|
| 5312 | */
|
|---|
| 5313 | function createMathOperation(operator, defaultValue) {
|
|---|
| 5314 | return function(value, other) {
|
|---|
| 5315 | var result;
|
|---|
| 5316 | if (value === undefined && other === undefined) {
|
|---|
| 5317 | return defaultValue;
|
|---|
| 5318 | }
|
|---|
| 5319 | if (value !== undefined) {
|
|---|
| 5320 | result = value;
|
|---|
| 5321 | }
|
|---|
| 5322 | if (other !== undefined) {
|
|---|
| 5323 | if (result === undefined) {
|
|---|
| 5324 | return other;
|
|---|
| 5325 | }
|
|---|
| 5326 | if (typeof value == 'string' || typeof other == 'string') {
|
|---|
| 5327 | value = baseToString(value);
|
|---|
| 5328 | other = baseToString(other);
|
|---|
| 5329 | } else {
|
|---|
| 5330 | value = baseToNumber(value);
|
|---|
| 5331 | other = baseToNumber(other);
|
|---|
| 5332 | }
|
|---|
| 5333 | result = operator(value, other);
|
|---|
| 5334 | }
|
|---|
| 5335 | return result;
|
|---|
| 5336 | };
|
|---|
| 5337 | }
|
|---|
| 5338 |
|
|---|
| 5339 | /**
|
|---|
| 5340 | * Creates a function like `_.over`.
|
|---|
| 5341 | *
|
|---|
| 5342 | * @private
|
|---|
| 5343 | * @param {Function} arrayFunc The function to iterate over iteratees.
|
|---|
| 5344 | * @returns {Function} Returns the new over function.
|
|---|
| 5345 | */
|
|---|
| 5346 | function createOver(arrayFunc) {
|
|---|
| 5347 | return flatRest(function(iteratees) {
|
|---|
| 5348 | iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
|
|---|
| 5349 | return baseRest(function(args) {
|
|---|
| 5350 | var thisArg = this;
|
|---|
| 5351 | return arrayFunc(iteratees, function(iteratee) {
|
|---|
| 5352 | return apply(iteratee, thisArg, args);
|
|---|
| 5353 | });
|
|---|
| 5354 | });
|
|---|
| 5355 | });
|
|---|
| 5356 | }
|
|---|
| 5357 |
|
|---|
| 5358 | /**
|
|---|
| 5359 | * Creates the padding for `string` based on `length`. The `chars` string
|
|---|
| 5360 | * is truncated if the number of characters exceeds `length`.
|
|---|
| 5361 | *
|
|---|
| 5362 | * @private
|
|---|
| 5363 | * @param {number} length The padding length.
|
|---|
| 5364 | * @param {string} [chars=' '] The string used as padding.
|
|---|
| 5365 | * @returns {string} Returns the padding for `string`.
|
|---|
| 5366 | */
|
|---|
| 5367 | function createPadding(length, chars) {
|
|---|
| 5368 | chars = chars === undefined ? ' ' : baseToString(chars);
|
|---|
| 5369 |
|
|---|
| 5370 | var charsLength = chars.length;
|
|---|
| 5371 | if (charsLength < 2) {
|
|---|
| 5372 | return charsLength ? baseRepeat(chars, length) : chars;
|
|---|
| 5373 | }
|
|---|
| 5374 | var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
|
|---|
| 5375 | return hasUnicode(chars)
|
|---|
| 5376 | ? castSlice(stringToArray(result), 0, length).join('')
|
|---|
| 5377 | : result.slice(0, length);
|
|---|
| 5378 | }
|
|---|
| 5379 |
|
|---|
| 5380 | /**
|
|---|
| 5381 | * Creates a function that wraps `func` to invoke it with the `this` binding
|
|---|
| 5382 | * of `thisArg` and `partials` prepended to the arguments it receives.
|
|---|
| 5383 | *
|
|---|
| 5384 | * @private
|
|---|
| 5385 | * @param {Function} func The function to wrap.
|
|---|
| 5386 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
|---|
| 5387 | * @param {*} thisArg The `this` binding of `func`.
|
|---|
| 5388 | * @param {Array} partials The arguments to prepend to those provided to
|
|---|
| 5389 | * the new function.
|
|---|
| 5390 | * @returns {Function} Returns the new wrapped function.
|
|---|
| 5391 | */
|
|---|
| 5392 | function createPartial(func, bitmask, thisArg, partials) {
|
|---|
| 5393 | var isBind = bitmask & WRAP_BIND_FLAG,
|
|---|
| 5394 | Ctor = createCtor(func);
|
|---|
| 5395 |
|
|---|
| 5396 | function wrapper() {
|
|---|
| 5397 | var argsIndex = -1,
|
|---|
| 5398 | argsLength = arguments.length,
|
|---|
| 5399 | leftIndex = -1,
|
|---|
| 5400 | leftLength = partials.length,
|
|---|
| 5401 | args = Array(leftLength + argsLength),
|
|---|
| 5402 | fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
|---|
| 5403 |
|
|---|
| 5404 | while (++leftIndex < leftLength) {
|
|---|
| 5405 | args[leftIndex] = partials[leftIndex];
|
|---|
| 5406 | }
|
|---|
| 5407 | while (argsLength--) {
|
|---|
| 5408 | args[leftIndex++] = arguments[++argsIndex];
|
|---|
| 5409 | }
|
|---|
| 5410 | return apply(fn, isBind ? thisArg : this, args);
|
|---|
| 5411 | }
|
|---|
| 5412 | return wrapper;
|
|---|
| 5413 | }
|
|---|
| 5414 |
|
|---|
| 5415 | /**
|
|---|
| 5416 | * Creates a `_.range` or `_.rangeRight` function.
|
|---|
| 5417 | *
|
|---|
| 5418 | * @private
|
|---|
| 5419 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
|---|
| 5420 | * @returns {Function} Returns the new range function.
|
|---|
| 5421 | */
|
|---|
| 5422 | function createRange(fromRight) {
|
|---|
| 5423 | return function(start, end, step) {
|
|---|
| 5424 | if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
|
|---|
| 5425 | end = step = undefined;
|
|---|
| 5426 | }
|
|---|
| 5427 | // Ensure the sign of `-0` is preserved.
|
|---|
| 5428 | start = toFinite(start);
|
|---|
| 5429 | if (end === undefined) {
|
|---|
| 5430 | end = start;
|
|---|
| 5431 | start = 0;
|
|---|
| 5432 | } else {
|
|---|
| 5433 | end = toFinite(end);
|
|---|
| 5434 | }
|
|---|
| 5435 | step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
|
|---|
| 5436 | return baseRange(start, end, step, fromRight);
|
|---|
| 5437 | };
|
|---|
| 5438 | }
|
|---|
| 5439 |
|
|---|
| 5440 | /**
|
|---|
| 5441 | * Creates a function that performs a relational operation on two values.
|
|---|
| 5442 | *
|
|---|
| 5443 | * @private
|
|---|
| 5444 | * @param {Function} operator The function to perform the operation.
|
|---|
| 5445 | * @returns {Function} Returns the new relational operation function.
|
|---|
| 5446 | */
|
|---|
| 5447 | function createRelationalOperation(operator) {
|
|---|
| 5448 | return function(value, other) {
|
|---|
| 5449 | if (!(typeof value == 'string' && typeof other == 'string')) {
|
|---|
| 5450 | value = toNumber(value);
|
|---|
| 5451 | other = toNumber(other);
|
|---|
| 5452 | }
|
|---|
| 5453 | return operator(value, other);
|
|---|
| 5454 | };
|
|---|
| 5455 | }
|
|---|
| 5456 |
|
|---|
| 5457 | /**
|
|---|
| 5458 | * Creates a function that wraps `func` to continue currying.
|
|---|
| 5459 | *
|
|---|
| 5460 | * @private
|
|---|
| 5461 | * @param {Function} func The function to wrap.
|
|---|
| 5462 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
|---|
| 5463 | * @param {Function} wrapFunc The function to create the `func` wrapper.
|
|---|
| 5464 | * @param {*} placeholder The placeholder value.
|
|---|
| 5465 | * @param {*} [thisArg] The `this` binding of `func`.
|
|---|
| 5466 | * @param {Array} [partials] The arguments to prepend to those provided to
|
|---|
| 5467 | * the new function.
|
|---|
| 5468 | * @param {Array} [holders] The `partials` placeholder indexes.
|
|---|
| 5469 | * @param {Array} [argPos] The argument positions of the new function.
|
|---|
| 5470 | * @param {number} [ary] The arity cap of `func`.
|
|---|
| 5471 | * @param {number} [arity] The arity of `func`.
|
|---|
| 5472 | * @returns {Function} Returns the new wrapped function.
|
|---|
| 5473 | */
|
|---|
| 5474 | function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
|
|---|
| 5475 | var isCurry = bitmask & WRAP_CURRY_FLAG,
|
|---|
| 5476 | newHolders = isCurry ? holders : undefined,
|
|---|
| 5477 | newHoldersRight = isCurry ? undefined : holders,
|
|---|
| 5478 | newPartials = isCurry ? partials : undefined,
|
|---|
| 5479 | newPartialsRight = isCurry ? undefined : partials;
|
|---|
| 5480 |
|
|---|
| 5481 | bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
|
|---|
| 5482 | bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
|
|---|
| 5483 |
|
|---|
| 5484 | if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
|
|---|
| 5485 | bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
|
|---|
| 5486 | }
|
|---|
| 5487 | var newData = [
|
|---|
| 5488 | func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
|
|---|
| 5489 | newHoldersRight, argPos, ary, arity
|
|---|
| 5490 | ];
|
|---|
| 5491 |
|
|---|
| 5492 | var result = wrapFunc.apply(undefined, newData);
|
|---|
| 5493 | if (isLaziable(func)) {
|
|---|
| 5494 | setData(result, newData);
|
|---|
| 5495 | }
|
|---|
| 5496 | result.placeholder = placeholder;
|
|---|
| 5497 | return setWrapToString(result, func, bitmask);
|
|---|
| 5498 | }
|
|---|
| 5499 |
|
|---|
| 5500 | /**
|
|---|
| 5501 | * Creates a function like `_.round`.
|
|---|
| 5502 | *
|
|---|
| 5503 | * @private
|
|---|
| 5504 | * @param {string} methodName The name of the `Math` method to use when rounding.
|
|---|
| 5505 | * @returns {Function} Returns the new round function.
|
|---|
| 5506 | */
|
|---|
| 5507 | function createRound(methodName) {
|
|---|
| 5508 | var func = Math[methodName];
|
|---|
| 5509 | return function(number, precision) {
|
|---|
| 5510 | number = toNumber(number);
|
|---|
| 5511 | precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
|
|---|
| 5512 | if (precision && nativeIsFinite(number)) {
|
|---|
| 5513 | // Shift with exponential notation to avoid floating-point issues.
|
|---|
| 5514 | // See [MDN](https://mdn.io/round#Examples) for more details.
|
|---|
| 5515 | var pair = (toString(number) + 'e').split('e'),
|
|---|
| 5516 | value = func(pair[0] + 'e' + (+pair[1] + precision));
|
|---|
| 5517 |
|
|---|
| 5518 | pair = (toString(value) + 'e').split('e');
|
|---|
| 5519 | return +(pair[0] + 'e' + (+pair[1] - precision));
|
|---|
| 5520 | }
|
|---|
| 5521 | return func(number);
|
|---|
| 5522 | };
|
|---|
| 5523 | }
|
|---|
| 5524 |
|
|---|
| 5525 | /**
|
|---|
| 5526 | * Creates a set object of `values`.
|
|---|
| 5527 | *
|
|---|
| 5528 | * @private
|
|---|
| 5529 | * @param {Array} values The values to add to the set.
|
|---|
| 5530 | * @returns {Object} Returns the new set.
|
|---|
| 5531 | */
|
|---|
| 5532 | var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
|
|---|
| 5533 | return new Set(values);
|
|---|
| 5534 | };
|
|---|
| 5535 |
|
|---|
| 5536 | /**
|
|---|
| 5537 | * Creates a `_.toPairs` or `_.toPairsIn` function.
|
|---|
| 5538 | *
|
|---|
| 5539 | * @private
|
|---|
| 5540 | * @param {Function} keysFunc The function to get the keys of a given object.
|
|---|
| 5541 | * @returns {Function} Returns the new pairs function.
|
|---|
| 5542 | */
|
|---|
| 5543 | function createToPairs(keysFunc) {
|
|---|
| 5544 | return function(object) {
|
|---|
| 5545 | var tag = getTag(object);
|
|---|
| 5546 | if (tag == mapTag) {
|
|---|
| 5547 | return mapToArray(object);
|
|---|
| 5548 | }
|
|---|
| 5549 | if (tag == setTag) {
|
|---|
| 5550 | return setToPairs(object);
|
|---|
| 5551 | }
|
|---|
| 5552 | return baseToPairs(object, keysFunc(object));
|
|---|
| 5553 | };
|
|---|
| 5554 | }
|
|---|
| 5555 |
|
|---|
| 5556 | /**
|
|---|
| 5557 | * Creates a function that either curries or invokes `func` with optional
|
|---|
| 5558 | * `this` binding and partially applied arguments.
|
|---|
| 5559 | *
|
|---|
| 5560 | * @private
|
|---|
| 5561 | * @param {Function|string} func The function or method name to wrap.
|
|---|
| 5562 | * @param {number} bitmask The bitmask flags.
|
|---|
| 5563 | * 1 - `_.bind`
|
|---|
| 5564 | * 2 - `_.bindKey`
|
|---|
| 5565 | * 4 - `_.curry` or `_.curryRight` of a bound function
|
|---|
| 5566 | * 8 - `_.curry`
|
|---|
| 5567 | * 16 - `_.curryRight`
|
|---|
| 5568 | * 32 - `_.partial`
|
|---|
| 5569 | * 64 - `_.partialRight`
|
|---|
| 5570 | * 128 - `_.rearg`
|
|---|
| 5571 | * 256 - `_.ary`
|
|---|
| 5572 | * 512 - `_.flip`
|
|---|
| 5573 | * @param {*} [thisArg] The `this` binding of `func`.
|
|---|
| 5574 | * @param {Array} [partials] The arguments to be partially applied.
|
|---|
| 5575 | * @param {Array} [holders] The `partials` placeholder indexes.
|
|---|
| 5576 | * @param {Array} [argPos] The argument positions of the new function.
|
|---|
| 5577 | * @param {number} [ary] The arity cap of `func`.
|
|---|
| 5578 | * @param {number} [arity] The arity of `func`.
|
|---|
| 5579 | * @returns {Function} Returns the new wrapped function.
|
|---|
| 5580 | */
|
|---|
| 5581 | function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
|
|---|
| 5582 | var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
|
|---|
| 5583 | if (!isBindKey && typeof func != 'function') {
|
|---|
| 5584 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 5585 | }
|
|---|
| 5586 | var length = partials ? partials.length : 0;
|
|---|
| 5587 | if (!length) {
|
|---|
| 5588 | bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
|
|---|
| 5589 | partials = holders = undefined;
|
|---|
| 5590 | }
|
|---|
| 5591 | ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
|
|---|
| 5592 | arity = arity === undefined ? arity : toInteger(arity);
|
|---|
| 5593 | length -= holders ? holders.length : 0;
|
|---|
| 5594 |
|
|---|
| 5595 | if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
|
|---|
| 5596 | var partialsRight = partials,
|
|---|
| 5597 | holdersRight = holders;
|
|---|
| 5598 |
|
|---|
| 5599 | partials = holders = undefined;
|
|---|
| 5600 | }
|
|---|
| 5601 | var data = isBindKey ? undefined : getData(func);
|
|---|
| 5602 |
|
|---|
| 5603 | var newData = [
|
|---|
| 5604 | func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
|
|---|
| 5605 | argPos, ary, arity
|
|---|
| 5606 | ];
|
|---|
| 5607 |
|
|---|
| 5608 | if (data) {
|
|---|
| 5609 | mergeData(newData, data);
|
|---|
| 5610 | }
|
|---|
| 5611 | func = newData[0];
|
|---|
| 5612 | bitmask = newData[1];
|
|---|
| 5613 | thisArg = newData[2];
|
|---|
| 5614 | partials = newData[3];
|
|---|
| 5615 | holders = newData[4];
|
|---|
| 5616 | arity = newData[9] = newData[9] === undefined
|
|---|
| 5617 | ? (isBindKey ? 0 : func.length)
|
|---|
| 5618 | : nativeMax(newData[9] - length, 0);
|
|---|
| 5619 |
|
|---|
| 5620 | if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
|
|---|
| 5621 | bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
|
|---|
| 5622 | }
|
|---|
| 5623 | if (!bitmask || bitmask == WRAP_BIND_FLAG) {
|
|---|
| 5624 | var result = createBind(func, bitmask, thisArg);
|
|---|
| 5625 | } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
|
|---|
| 5626 | result = createCurry(func, bitmask, arity);
|
|---|
| 5627 | } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
|
|---|
| 5628 | result = createPartial(func, bitmask, thisArg, partials);
|
|---|
| 5629 | } else {
|
|---|
| 5630 | result = createHybrid.apply(undefined, newData);
|
|---|
| 5631 | }
|
|---|
| 5632 | var setter = data ? baseSetData : setData;
|
|---|
| 5633 | return setWrapToString(setter(result, newData), func, bitmask);
|
|---|
| 5634 | }
|
|---|
| 5635 |
|
|---|
| 5636 | /**
|
|---|
| 5637 | * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
|
|---|
| 5638 | * of source objects to the destination object for all destination properties
|
|---|
| 5639 | * that resolve to `undefined`.
|
|---|
| 5640 | *
|
|---|
| 5641 | * @private
|
|---|
| 5642 | * @param {*} objValue The destination value.
|
|---|
| 5643 | * @param {*} srcValue The source value.
|
|---|
| 5644 | * @param {string} key The key of the property to assign.
|
|---|
| 5645 | * @param {Object} object The parent object of `objValue`.
|
|---|
| 5646 | * @returns {*} Returns the value to assign.
|
|---|
| 5647 | */
|
|---|
| 5648 | function customDefaultsAssignIn(objValue, srcValue, key, object) {
|
|---|
| 5649 | if (objValue === undefined ||
|
|---|
| 5650 | (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
|---|
| 5651 | return srcValue;
|
|---|
| 5652 | }
|
|---|
| 5653 | return objValue;
|
|---|
| 5654 | }
|
|---|
| 5655 |
|
|---|
| 5656 | /**
|
|---|
| 5657 | * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
|
|---|
| 5658 | * objects into destination objects that are passed thru.
|
|---|
| 5659 | *
|
|---|
| 5660 | * @private
|
|---|
| 5661 | * @param {*} objValue The destination value.
|
|---|
| 5662 | * @param {*} srcValue The source value.
|
|---|
| 5663 | * @param {string} key The key of the property to merge.
|
|---|
| 5664 | * @param {Object} object The parent object of `objValue`.
|
|---|
| 5665 | * @param {Object} source The parent object of `srcValue`.
|
|---|
| 5666 | * @param {Object} [stack] Tracks traversed source values and their merged
|
|---|
| 5667 | * counterparts.
|
|---|
| 5668 | * @returns {*} Returns the value to assign.
|
|---|
| 5669 | */
|
|---|
| 5670 | function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
|
|---|
| 5671 | if (isObject(objValue) && isObject(srcValue)) {
|
|---|
| 5672 | // Recursively merge objects and arrays (susceptible to call stack limits).
|
|---|
| 5673 | stack.set(srcValue, objValue);
|
|---|
| 5674 | baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
|
|---|
| 5675 | stack['delete'](srcValue);
|
|---|
| 5676 | }
|
|---|
| 5677 | return objValue;
|
|---|
| 5678 | }
|
|---|
| 5679 |
|
|---|
| 5680 | /**
|
|---|
| 5681 | * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
|
|---|
| 5682 | * objects.
|
|---|
| 5683 | *
|
|---|
| 5684 | * @private
|
|---|
| 5685 | * @param {*} value The value to inspect.
|
|---|
| 5686 | * @param {string} key The key of the property to inspect.
|
|---|
| 5687 | * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
|
|---|
| 5688 | */
|
|---|
| 5689 | function customOmitClone(value) {
|
|---|
| 5690 | return isPlainObject(value) ? undefined : value;
|
|---|
| 5691 | }
|
|---|
| 5692 |
|
|---|
| 5693 | /**
|
|---|
| 5694 | * A specialized version of `baseIsEqualDeep` for arrays with support for
|
|---|
| 5695 | * partial deep comparisons.
|
|---|
| 5696 | *
|
|---|
| 5697 | * @private
|
|---|
| 5698 | * @param {Array} array The array to compare.
|
|---|
| 5699 | * @param {Array} other The other array to compare.
|
|---|
| 5700 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
|---|
| 5701 | * @param {Function} customizer The function to customize comparisons.
|
|---|
| 5702 | * @param {Function} equalFunc The function to determine equivalents of values.
|
|---|
| 5703 | * @param {Object} stack Tracks traversed `array` and `other` objects.
|
|---|
| 5704 | * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
|
|---|
| 5705 | */
|
|---|
| 5706 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
|
|---|
| 5707 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
|---|
| 5708 | arrLength = array.length,
|
|---|
| 5709 | othLength = other.length;
|
|---|
| 5710 |
|
|---|
| 5711 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
|---|
| 5712 | return false;
|
|---|
| 5713 | }
|
|---|
| 5714 | // Check that cyclic values are equal.
|
|---|
| 5715 | var arrStacked = stack.get(array);
|
|---|
| 5716 | var othStacked = stack.get(other);
|
|---|
| 5717 | if (arrStacked && othStacked) {
|
|---|
| 5718 | return arrStacked == other && othStacked == array;
|
|---|
| 5719 | }
|
|---|
| 5720 | var index = -1,
|
|---|
| 5721 | result = true,
|
|---|
| 5722 | seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
|
|---|
| 5723 |
|
|---|
| 5724 | stack.set(array, other);
|
|---|
| 5725 | stack.set(other, array);
|
|---|
| 5726 |
|
|---|
| 5727 | // Ignore non-index properties.
|
|---|
| 5728 | while (++index < arrLength) {
|
|---|
| 5729 | var arrValue = array[index],
|
|---|
| 5730 | othValue = other[index];
|
|---|
| 5731 |
|
|---|
| 5732 | if (customizer) {
|
|---|
| 5733 | var compared = isPartial
|
|---|
| 5734 | ? customizer(othValue, arrValue, index, other, array, stack)
|
|---|
| 5735 | : customizer(arrValue, othValue, index, array, other, stack);
|
|---|
| 5736 | }
|
|---|
| 5737 | if (compared !== undefined) {
|
|---|
| 5738 | if (compared) {
|
|---|
| 5739 | continue;
|
|---|
| 5740 | }
|
|---|
| 5741 | result = false;
|
|---|
| 5742 | break;
|
|---|
| 5743 | }
|
|---|
| 5744 | // Recursively compare arrays (susceptible to call stack limits).
|
|---|
| 5745 | if (seen) {
|
|---|
| 5746 | if (!arraySome(other, function(othValue, othIndex) {
|
|---|
| 5747 | if (!cacheHas(seen, othIndex) &&
|
|---|
| 5748 | (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
|---|
| 5749 | return seen.push(othIndex);
|
|---|
| 5750 | }
|
|---|
| 5751 | })) {
|
|---|
| 5752 | result = false;
|
|---|
| 5753 | break;
|
|---|
| 5754 | }
|
|---|
| 5755 | } else if (!(
|
|---|
| 5756 | arrValue === othValue ||
|
|---|
| 5757 | equalFunc(arrValue, othValue, bitmask, customizer, stack)
|
|---|
| 5758 | )) {
|
|---|
| 5759 | result = false;
|
|---|
| 5760 | break;
|
|---|
| 5761 | }
|
|---|
| 5762 | }
|
|---|
| 5763 | stack['delete'](array);
|
|---|
| 5764 | stack['delete'](other);
|
|---|
| 5765 | return result;
|
|---|
| 5766 | }
|
|---|
| 5767 |
|
|---|
| 5768 | /**
|
|---|
| 5769 | * A specialized version of `baseIsEqualDeep` for comparing objects of
|
|---|
| 5770 | * the same `toStringTag`.
|
|---|
| 5771 | *
|
|---|
| 5772 | * **Note:** This function only supports comparing values with tags of
|
|---|
| 5773 | * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
|---|
| 5774 | *
|
|---|
| 5775 | * @private
|
|---|
| 5776 | * @param {Object} object The object to compare.
|
|---|
| 5777 | * @param {Object} other The other object to compare.
|
|---|
| 5778 | * @param {string} tag The `toStringTag` of the objects to compare.
|
|---|
| 5779 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
|---|
| 5780 | * @param {Function} customizer The function to customize comparisons.
|
|---|
| 5781 | * @param {Function} equalFunc The function to determine equivalents of values.
|
|---|
| 5782 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
|---|
| 5783 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
|---|
| 5784 | */
|
|---|
| 5785 | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
|
|---|
| 5786 | switch (tag) {
|
|---|
| 5787 | case dataViewTag:
|
|---|
| 5788 | if ((object.byteLength != other.byteLength) ||
|
|---|
| 5789 | (object.byteOffset != other.byteOffset)) {
|
|---|
| 5790 | return false;
|
|---|
| 5791 | }
|
|---|
| 5792 | object = object.buffer;
|
|---|
| 5793 | other = other.buffer;
|
|---|
| 5794 |
|
|---|
| 5795 | case arrayBufferTag:
|
|---|
| 5796 | if ((object.byteLength != other.byteLength) ||
|
|---|
| 5797 | !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
|
|---|
| 5798 | return false;
|
|---|
| 5799 | }
|
|---|
| 5800 | return true;
|
|---|
| 5801 |
|
|---|
| 5802 | case boolTag:
|
|---|
| 5803 | case dateTag:
|
|---|
| 5804 | case numberTag:
|
|---|
| 5805 | // Coerce booleans to `1` or `0` and dates to milliseconds.
|
|---|
| 5806 | // Invalid dates are coerced to `NaN`.
|
|---|
| 5807 | return eq(+object, +other);
|
|---|
| 5808 |
|
|---|
| 5809 | case errorTag:
|
|---|
| 5810 | return object.name == other.name && object.message == other.message;
|
|---|
| 5811 |
|
|---|
| 5812 | case regexpTag:
|
|---|
| 5813 | case stringTag:
|
|---|
| 5814 | // Coerce regexes to strings and treat strings, primitives and objects,
|
|---|
| 5815 | // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
|
|---|
| 5816 | // for more details.
|
|---|
| 5817 | return object == (other + '');
|
|---|
| 5818 |
|
|---|
| 5819 | case mapTag:
|
|---|
| 5820 | var convert = mapToArray;
|
|---|
| 5821 |
|
|---|
| 5822 | case setTag:
|
|---|
| 5823 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
|
|---|
| 5824 | convert || (convert = setToArray);
|
|---|
| 5825 |
|
|---|
| 5826 | if (object.size != other.size && !isPartial) {
|
|---|
| 5827 | return false;
|
|---|
| 5828 | }
|
|---|
| 5829 | // Assume cyclic values are equal.
|
|---|
| 5830 | var stacked = stack.get(object);
|
|---|
| 5831 | if (stacked) {
|
|---|
| 5832 | return stacked == other;
|
|---|
| 5833 | }
|
|---|
| 5834 | bitmask |= COMPARE_UNORDERED_FLAG;
|
|---|
| 5835 |
|
|---|
| 5836 | // Recursively compare objects (susceptible to call stack limits).
|
|---|
| 5837 | stack.set(object, other);
|
|---|
| 5838 | var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
|
|---|
| 5839 | stack['delete'](object);
|
|---|
| 5840 | return result;
|
|---|
| 5841 |
|
|---|
| 5842 | case symbolTag:
|
|---|
| 5843 | if (symbolValueOf) {
|
|---|
| 5844 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
|---|
| 5845 | }
|
|---|
| 5846 | }
|
|---|
| 5847 | return false;
|
|---|
| 5848 | }
|
|---|
| 5849 |
|
|---|
| 5850 | /**
|
|---|
| 5851 | * A specialized version of `baseIsEqualDeep` for objects with support for
|
|---|
| 5852 | * partial deep comparisons.
|
|---|
| 5853 | *
|
|---|
| 5854 | * @private
|
|---|
| 5855 | * @param {Object} object The object to compare.
|
|---|
| 5856 | * @param {Object} other The other object to compare.
|
|---|
| 5857 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
|---|
| 5858 | * @param {Function} customizer The function to customize comparisons.
|
|---|
| 5859 | * @param {Function} equalFunc The function to determine equivalents of values.
|
|---|
| 5860 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
|---|
| 5861 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
|---|
| 5862 | */
|
|---|
| 5863 | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
|
|---|
| 5864 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
|---|
| 5865 | objProps = getAllKeys(object),
|
|---|
| 5866 | objLength = objProps.length,
|
|---|
| 5867 | othProps = getAllKeys(other),
|
|---|
| 5868 | othLength = othProps.length;
|
|---|
| 5869 |
|
|---|
| 5870 | if (objLength != othLength && !isPartial) {
|
|---|
| 5871 | return false;
|
|---|
| 5872 | }
|
|---|
| 5873 | var index = objLength;
|
|---|
| 5874 | while (index--) {
|
|---|
| 5875 | var key = objProps[index];
|
|---|
| 5876 | if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
|
|---|
| 5877 | return false;
|
|---|
| 5878 | }
|
|---|
| 5879 | }
|
|---|
| 5880 | // Check that cyclic values are equal.
|
|---|
| 5881 | var objStacked = stack.get(object);
|
|---|
| 5882 | var othStacked = stack.get(other);
|
|---|
| 5883 | if (objStacked && othStacked) {
|
|---|
| 5884 | return objStacked == other && othStacked == object;
|
|---|
| 5885 | }
|
|---|
| 5886 | var result = true;
|
|---|
| 5887 | stack.set(object, other);
|
|---|
| 5888 | stack.set(other, object);
|
|---|
| 5889 |
|
|---|
| 5890 | var skipCtor = isPartial;
|
|---|
| 5891 | while (++index < objLength) {
|
|---|
| 5892 | key = objProps[index];
|
|---|
| 5893 | var objValue = object[key],
|
|---|
| 5894 | othValue = other[key];
|
|---|
| 5895 |
|
|---|
| 5896 | if (customizer) {
|
|---|
| 5897 | var compared = isPartial
|
|---|
| 5898 | ? customizer(othValue, objValue, key, other, object, stack)
|
|---|
| 5899 | : customizer(objValue, othValue, key, object, other, stack);
|
|---|
| 5900 | }
|
|---|
| 5901 | // Recursively compare objects (susceptible to call stack limits).
|
|---|
| 5902 | if (!(compared === undefined
|
|---|
| 5903 | ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
|
|---|
| 5904 | : compared
|
|---|
| 5905 | )) {
|
|---|
| 5906 | result = false;
|
|---|
| 5907 | break;
|
|---|
| 5908 | }
|
|---|
| 5909 | skipCtor || (skipCtor = key == 'constructor');
|
|---|
| 5910 | }
|
|---|
| 5911 | if (result && !skipCtor) {
|
|---|
| 5912 | var objCtor = object.constructor,
|
|---|
| 5913 | othCtor = other.constructor;
|
|---|
| 5914 |
|
|---|
| 5915 | // Non `Object` object instances with different constructors are not equal.
|
|---|
| 5916 | if (objCtor != othCtor &&
|
|---|
| 5917 | ('constructor' in object && 'constructor' in other) &&
|
|---|
| 5918 | !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
|---|
| 5919 | typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
|---|
| 5920 | result = false;
|
|---|
| 5921 | }
|
|---|
| 5922 | }
|
|---|
| 5923 | stack['delete'](object);
|
|---|
| 5924 | stack['delete'](other);
|
|---|
| 5925 | return result;
|
|---|
| 5926 | }
|
|---|
| 5927 |
|
|---|
| 5928 | /**
|
|---|
| 5929 | * A specialized version of `baseRest` which flattens the rest array.
|
|---|
| 5930 | *
|
|---|
| 5931 | * @private
|
|---|
| 5932 | * @param {Function} func The function to apply a rest parameter to.
|
|---|
| 5933 | * @returns {Function} Returns the new function.
|
|---|
| 5934 | */
|
|---|
| 5935 | function flatRest(func) {
|
|---|
| 5936 | return setToString(overRest(func, undefined, flatten), func + '');
|
|---|
| 5937 | }
|
|---|
| 5938 |
|
|---|
| 5939 | /**
|
|---|
| 5940 | * Creates an array of own enumerable property names and symbols of `object`.
|
|---|
| 5941 | *
|
|---|
| 5942 | * @private
|
|---|
| 5943 | * @param {Object} object The object to query.
|
|---|
| 5944 | * @returns {Array} Returns the array of property names and symbols.
|
|---|
| 5945 | */
|
|---|
| 5946 | function getAllKeys(object) {
|
|---|
| 5947 | return baseGetAllKeys(object, keys, getSymbols);
|
|---|
| 5948 | }
|
|---|
| 5949 |
|
|---|
| 5950 | /**
|
|---|
| 5951 | * Creates an array of own and inherited enumerable property names and
|
|---|
| 5952 | * symbols of `object`.
|
|---|
| 5953 | *
|
|---|
| 5954 | * @private
|
|---|
| 5955 | * @param {Object} object The object to query.
|
|---|
| 5956 | * @returns {Array} Returns the array of property names and symbols.
|
|---|
| 5957 | */
|
|---|
| 5958 | function getAllKeysIn(object) {
|
|---|
| 5959 | return baseGetAllKeys(object, keysIn, getSymbolsIn);
|
|---|
| 5960 | }
|
|---|
| 5961 |
|
|---|
| 5962 | /**
|
|---|
| 5963 | * Gets metadata for `func`.
|
|---|
| 5964 | *
|
|---|
| 5965 | * @private
|
|---|
| 5966 | * @param {Function} func The function to query.
|
|---|
| 5967 | * @returns {*} Returns the metadata for `func`.
|
|---|
| 5968 | */
|
|---|
| 5969 | var getData = !metaMap ? noop : function(func) {
|
|---|
| 5970 | return metaMap.get(func);
|
|---|
| 5971 | };
|
|---|
| 5972 |
|
|---|
| 5973 | /**
|
|---|
| 5974 | * Gets the name of `func`.
|
|---|
| 5975 | *
|
|---|
| 5976 | * @private
|
|---|
| 5977 | * @param {Function} func The function to query.
|
|---|
| 5978 | * @returns {string} Returns the function name.
|
|---|
| 5979 | */
|
|---|
| 5980 | function getFuncName(func) {
|
|---|
| 5981 | var result = (func.name + ''),
|
|---|
| 5982 | array = realNames[result],
|
|---|
| 5983 | length = hasOwnProperty.call(realNames, result) ? array.length : 0;
|
|---|
| 5984 |
|
|---|
| 5985 | while (length--) {
|
|---|
| 5986 | var data = array[length],
|
|---|
| 5987 | otherFunc = data.func;
|
|---|
| 5988 | if (otherFunc == null || otherFunc == func) {
|
|---|
| 5989 | return data.name;
|
|---|
| 5990 | }
|
|---|
| 5991 | }
|
|---|
| 5992 | return result;
|
|---|
| 5993 | }
|
|---|
| 5994 |
|
|---|
| 5995 | /**
|
|---|
| 5996 | * Gets the argument placeholder value for `func`.
|
|---|
| 5997 | *
|
|---|
| 5998 | * @private
|
|---|
| 5999 | * @param {Function} func The function to inspect.
|
|---|
| 6000 | * @returns {*} Returns the placeholder value.
|
|---|
| 6001 | */
|
|---|
| 6002 | function getHolder(func) {
|
|---|
| 6003 | var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
|
|---|
| 6004 | return object.placeholder;
|
|---|
| 6005 | }
|
|---|
| 6006 |
|
|---|
| 6007 | /**
|
|---|
| 6008 | * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
|
|---|
| 6009 | * this function returns the custom method, otherwise it returns `baseIteratee`.
|
|---|
| 6010 | * If arguments are provided, the chosen function is invoked with them and
|
|---|
| 6011 | * its result is returned.
|
|---|
| 6012 | *
|
|---|
| 6013 | * @private
|
|---|
| 6014 | * @param {*} [value] The value to convert to an iteratee.
|
|---|
| 6015 | * @param {number} [arity] The arity of the created iteratee.
|
|---|
| 6016 | * @returns {Function} Returns the chosen function or its result.
|
|---|
| 6017 | */
|
|---|
| 6018 | function getIteratee() {
|
|---|
| 6019 | var result = lodash.iteratee || iteratee;
|
|---|
| 6020 | result = result === iteratee ? baseIteratee : result;
|
|---|
| 6021 | return arguments.length ? result(arguments[0], arguments[1]) : result;
|
|---|
| 6022 | }
|
|---|
| 6023 |
|
|---|
| 6024 | /**
|
|---|
| 6025 | * Gets the data for `map`.
|
|---|
| 6026 | *
|
|---|
| 6027 | * @private
|
|---|
| 6028 | * @param {Object} map The map to query.
|
|---|
| 6029 | * @param {string} key The reference key.
|
|---|
| 6030 | * @returns {*} Returns the map data.
|
|---|
| 6031 | */
|
|---|
| 6032 | function getMapData(map, key) {
|
|---|
| 6033 | var data = map.__data__;
|
|---|
| 6034 | return isKeyable(key)
|
|---|
| 6035 | ? data[typeof key == 'string' ? 'string' : 'hash']
|
|---|
| 6036 | : data.map;
|
|---|
| 6037 | }
|
|---|
| 6038 |
|
|---|
| 6039 | /**
|
|---|
| 6040 | * Gets the property names, values, and compare flags of `object`.
|
|---|
| 6041 | *
|
|---|
| 6042 | * @private
|
|---|
| 6043 | * @param {Object} object The object to query.
|
|---|
| 6044 | * @returns {Array} Returns the match data of `object`.
|
|---|
| 6045 | */
|
|---|
| 6046 | function getMatchData(object) {
|
|---|
| 6047 | var result = keys(object),
|
|---|
| 6048 | length = result.length;
|
|---|
| 6049 |
|
|---|
| 6050 | while (length--) {
|
|---|
| 6051 | var key = result[length],
|
|---|
| 6052 | value = object[key];
|
|---|
| 6053 |
|
|---|
| 6054 | result[length] = [key, value, isStrictComparable(value)];
|
|---|
| 6055 | }
|
|---|
| 6056 | return result;
|
|---|
| 6057 | }
|
|---|
| 6058 |
|
|---|
| 6059 | /**
|
|---|
| 6060 | * Gets the native function at `key` of `object`.
|
|---|
| 6061 | *
|
|---|
| 6062 | * @private
|
|---|
| 6063 | * @param {Object} object The object to query.
|
|---|
| 6064 | * @param {string} key The key of the method to get.
|
|---|
| 6065 | * @returns {*} Returns the function if it's native, else `undefined`.
|
|---|
| 6066 | */
|
|---|
| 6067 | function getNative(object, key) {
|
|---|
| 6068 | var value = getValue(object, key);
|
|---|
| 6069 | return baseIsNative(value) ? value : undefined;
|
|---|
| 6070 | }
|
|---|
| 6071 |
|
|---|
| 6072 | /**
|
|---|
| 6073 | * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
|---|
| 6074 | *
|
|---|
| 6075 | * @private
|
|---|
| 6076 | * @param {*} value The value to query.
|
|---|
| 6077 | * @returns {string} Returns the raw `toStringTag`.
|
|---|
| 6078 | */
|
|---|
| 6079 | function getRawTag(value) {
|
|---|
| 6080 | var isOwn = hasOwnProperty.call(value, symToStringTag),
|
|---|
| 6081 | tag = value[symToStringTag];
|
|---|
| 6082 |
|
|---|
| 6083 | try {
|
|---|
| 6084 | value[symToStringTag] = undefined;
|
|---|
| 6085 | var unmasked = true;
|
|---|
| 6086 | } catch (e) {}
|
|---|
| 6087 |
|
|---|
| 6088 | var result = nativeObjectToString.call(value);
|
|---|
| 6089 | if (unmasked) {
|
|---|
| 6090 | if (isOwn) {
|
|---|
| 6091 | value[symToStringTag] = tag;
|
|---|
| 6092 | } else {
|
|---|
| 6093 | delete value[symToStringTag];
|
|---|
| 6094 | }
|
|---|
| 6095 | }
|
|---|
| 6096 | return result;
|
|---|
| 6097 | }
|
|---|
| 6098 |
|
|---|
| 6099 | /**
|
|---|
| 6100 | * Creates an array of the own enumerable symbols of `object`.
|
|---|
| 6101 | *
|
|---|
| 6102 | * @private
|
|---|
| 6103 | * @param {Object} object The object to query.
|
|---|
| 6104 | * @returns {Array} Returns the array of symbols.
|
|---|
| 6105 | */
|
|---|
| 6106 | var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
|
|---|
| 6107 | if (object == null) {
|
|---|
| 6108 | return [];
|
|---|
| 6109 | }
|
|---|
| 6110 | object = Object(object);
|
|---|
| 6111 | return arrayFilter(nativeGetSymbols(object), function(symbol) {
|
|---|
| 6112 | return propertyIsEnumerable.call(object, symbol);
|
|---|
| 6113 | });
|
|---|
| 6114 | };
|
|---|
| 6115 |
|
|---|
| 6116 | /**
|
|---|
| 6117 | * Creates an array of the own and inherited enumerable symbols of `object`.
|
|---|
| 6118 | *
|
|---|
| 6119 | * @private
|
|---|
| 6120 | * @param {Object} object The object to query.
|
|---|
| 6121 | * @returns {Array} Returns the array of symbols.
|
|---|
| 6122 | */
|
|---|
| 6123 | var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
|
|---|
| 6124 | var result = [];
|
|---|
| 6125 | while (object) {
|
|---|
| 6126 | arrayPush(result, getSymbols(object));
|
|---|
| 6127 | object = getPrototype(object);
|
|---|
| 6128 | }
|
|---|
| 6129 | return result;
|
|---|
| 6130 | };
|
|---|
| 6131 |
|
|---|
| 6132 | /**
|
|---|
| 6133 | * Gets the `toStringTag` of `value`.
|
|---|
| 6134 | *
|
|---|
| 6135 | * @private
|
|---|
| 6136 | * @param {*} value The value to query.
|
|---|
| 6137 | * @returns {string} Returns the `toStringTag`.
|
|---|
| 6138 | */
|
|---|
| 6139 | var getTag = baseGetTag;
|
|---|
| 6140 |
|
|---|
| 6141 | // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
|---|
| 6142 | if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
|---|
| 6143 | (Map && getTag(new Map) != mapTag) ||
|
|---|
| 6144 | (Promise && getTag(Promise.resolve()) != promiseTag) ||
|
|---|
| 6145 | (Set && getTag(new Set) != setTag) ||
|
|---|
| 6146 | (WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
|---|
| 6147 | getTag = function(value) {
|
|---|
| 6148 | var result = baseGetTag(value),
|
|---|
| 6149 | Ctor = result == objectTag ? value.constructor : undefined,
|
|---|
| 6150 | ctorString = Ctor ? toSource(Ctor) : '';
|
|---|
| 6151 |
|
|---|
| 6152 | if (ctorString) {
|
|---|
| 6153 | switch (ctorString) {
|
|---|
| 6154 | case dataViewCtorString: return dataViewTag;
|
|---|
| 6155 | case mapCtorString: return mapTag;
|
|---|
| 6156 | case promiseCtorString: return promiseTag;
|
|---|
| 6157 | case setCtorString: return setTag;
|
|---|
| 6158 | case weakMapCtorString: return weakMapTag;
|
|---|
| 6159 | }
|
|---|
| 6160 | }
|
|---|
| 6161 | return result;
|
|---|
| 6162 | };
|
|---|
| 6163 | }
|
|---|
| 6164 |
|
|---|
| 6165 | /**
|
|---|
| 6166 | * Gets the view, applying any `transforms` to the `start` and `end` positions.
|
|---|
| 6167 | *
|
|---|
| 6168 | * @private
|
|---|
| 6169 | * @param {number} start The start of the view.
|
|---|
| 6170 | * @param {number} end The end of the view.
|
|---|
| 6171 | * @param {Array} transforms The transformations to apply to the view.
|
|---|
| 6172 | * @returns {Object} Returns an object containing the `start` and `end`
|
|---|
| 6173 | * positions of the view.
|
|---|
| 6174 | */
|
|---|
| 6175 | function getView(start, end, transforms) {
|
|---|
| 6176 | var index = -1,
|
|---|
| 6177 | length = transforms.length;
|
|---|
| 6178 |
|
|---|
| 6179 | while (++index < length) {
|
|---|
| 6180 | var data = transforms[index],
|
|---|
| 6181 | size = data.size;
|
|---|
| 6182 |
|
|---|
| 6183 | switch (data.type) {
|
|---|
| 6184 | case 'drop': start += size; break;
|
|---|
| 6185 | case 'dropRight': end -= size; break;
|
|---|
| 6186 | case 'take': end = nativeMin(end, start + size); break;
|
|---|
| 6187 | case 'takeRight': start = nativeMax(start, end - size); break;
|
|---|
| 6188 | }
|
|---|
| 6189 | }
|
|---|
| 6190 | return { 'start': start, 'end': end };
|
|---|
| 6191 | }
|
|---|
| 6192 |
|
|---|
| 6193 | /**
|
|---|
| 6194 | * Extracts wrapper details from the `source` body comment.
|
|---|
| 6195 | *
|
|---|
| 6196 | * @private
|
|---|
| 6197 | * @param {string} source The source to inspect.
|
|---|
| 6198 | * @returns {Array} Returns the wrapper details.
|
|---|
| 6199 | */
|
|---|
| 6200 | function getWrapDetails(source) {
|
|---|
| 6201 | var match = source.match(reWrapDetails);
|
|---|
| 6202 | return match ? match[1].split(reSplitDetails) : [];
|
|---|
| 6203 | }
|
|---|
| 6204 |
|
|---|
| 6205 | /**
|
|---|
| 6206 | * Checks if `path` exists on `object`.
|
|---|
| 6207 | *
|
|---|
| 6208 | * @private
|
|---|
| 6209 | * @param {Object} object The object to query.
|
|---|
| 6210 | * @param {Array|string} path The path to check.
|
|---|
| 6211 | * @param {Function} hasFunc The function to check properties.
|
|---|
| 6212 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
|---|
| 6213 | */
|
|---|
| 6214 | function hasPath(object, path, hasFunc) {
|
|---|
| 6215 | path = castPath(path, object);
|
|---|
| 6216 |
|
|---|
| 6217 | var index = -1,
|
|---|
| 6218 | length = path.length,
|
|---|
| 6219 | result = false;
|
|---|
| 6220 |
|
|---|
| 6221 | while (++index < length) {
|
|---|
| 6222 | var key = toKey(path[index]);
|
|---|
| 6223 | if (!(result = object != null && hasFunc(object, key))) {
|
|---|
| 6224 | break;
|
|---|
| 6225 | }
|
|---|
| 6226 | object = object[key];
|
|---|
| 6227 | }
|
|---|
| 6228 | if (result || ++index != length) {
|
|---|
| 6229 | return result;
|
|---|
| 6230 | }
|
|---|
| 6231 | length = object == null ? 0 : object.length;
|
|---|
| 6232 | return !!length && isLength(length) && isIndex(key, length) &&
|
|---|
| 6233 | (isArray(object) || isArguments(object));
|
|---|
| 6234 | }
|
|---|
| 6235 |
|
|---|
| 6236 | /**
|
|---|
| 6237 | * Initializes an array clone.
|
|---|
| 6238 | *
|
|---|
| 6239 | * @private
|
|---|
| 6240 | * @param {Array} array The array to clone.
|
|---|
| 6241 | * @returns {Array} Returns the initialized clone.
|
|---|
| 6242 | */
|
|---|
| 6243 | function initCloneArray(array) {
|
|---|
| 6244 | var length = array.length,
|
|---|
| 6245 | result = new array.constructor(length);
|
|---|
| 6246 |
|
|---|
| 6247 | // Add properties assigned by `RegExp#exec`.
|
|---|
| 6248 | if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
|
|---|
| 6249 | result.index = array.index;
|
|---|
| 6250 | result.input = array.input;
|
|---|
| 6251 | }
|
|---|
| 6252 | return result;
|
|---|
| 6253 | }
|
|---|
| 6254 |
|
|---|
| 6255 | /**
|
|---|
| 6256 | * Initializes an object clone.
|
|---|
| 6257 | *
|
|---|
| 6258 | * @private
|
|---|
| 6259 | * @param {Object} object The object to clone.
|
|---|
| 6260 | * @returns {Object} Returns the initialized clone.
|
|---|
| 6261 | */
|
|---|
| 6262 | function initCloneObject(object) {
|
|---|
| 6263 | return (typeof object.constructor == 'function' && !isPrototype(object))
|
|---|
| 6264 | ? baseCreate(getPrototype(object))
|
|---|
| 6265 | : {};
|
|---|
| 6266 | }
|
|---|
| 6267 |
|
|---|
| 6268 | /**
|
|---|
| 6269 | * Initializes an object clone based on its `toStringTag`.
|
|---|
| 6270 | *
|
|---|
| 6271 | * **Note:** This function only supports cloning values with tags of
|
|---|
| 6272 | * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
|
|---|
| 6273 | *
|
|---|
| 6274 | * @private
|
|---|
| 6275 | * @param {Object} object The object to clone.
|
|---|
| 6276 | * @param {string} tag The `toStringTag` of the object to clone.
|
|---|
| 6277 | * @param {boolean} [isDeep] Specify a deep clone.
|
|---|
| 6278 | * @returns {Object} Returns the initialized clone.
|
|---|
| 6279 | */
|
|---|
| 6280 | function initCloneByTag(object, tag, isDeep) {
|
|---|
| 6281 | var Ctor = object.constructor;
|
|---|
| 6282 | switch (tag) {
|
|---|
| 6283 | case arrayBufferTag:
|
|---|
| 6284 | return cloneArrayBuffer(object);
|
|---|
| 6285 |
|
|---|
| 6286 | case boolTag:
|
|---|
| 6287 | case dateTag:
|
|---|
| 6288 | return new Ctor(+object);
|
|---|
| 6289 |
|
|---|
| 6290 | case dataViewTag:
|
|---|
| 6291 | return cloneDataView(object, isDeep);
|
|---|
| 6292 |
|
|---|
| 6293 | case float32Tag: case float64Tag:
|
|---|
| 6294 | case int8Tag: case int16Tag: case int32Tag:
|
|---|
| 6295 | case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
|
|---|
| 6296 | return cloneTypedArray(object, isDeep);
|
|---|
| 6297 |
|
|---|
| 6298 | case mapTag:
|
|---|
| 6299 | return new Ctor;
|
|---|
| 6300 |
|
|---|
| 6301 | case numberTag:
|
|---|
| 6302 | case stringTag:
|
|---|
| 6303 | return new Ctor(object);
|
|---|
| 6304 |
|
|---|
| 6305 | case regexpTag:
|
|---|
| 6306 | return cloneRegExp(object);
|
|---|
| 6307 |
|
|---|
| 6308 | case setTag:
|
|---|
| 6309 | return new Ctor;
|
|---|
| 6310 |
|
|---|
| 6311 | case symbolTag:
|
|---|
| 6312 | return cloneSymbol(object);
|
|---|
| 6313 | }
|
|---|
| 6314 | }
|
|---|
| 6315 |
|
|---|
| 6316 | /**
|
|---|
| 6317 | * Inserts wrapper `details` in a comment at the top of the `source` body.
|
|---|
| 6318 | *
|
|---|
| 6319 | * @private
|
|---|
| 6320 | * @param {string} source The source to modify.
|
|---|
| 6321 | * @returns {Array} details The details to insert.
|
|---|
| 6322 | * @returns {string} Returns the modified source.
|
|---|
| 6323 | */
|
|---|
| 6324 | function insertWrapDetails(source, details) {
|
|---|
| 6325 | var length = details.length;
|
|---|
| 6326 | if (!length) {
|
|---|
| 6327 | return source;
|
|---|
| 6328 | }
|
|---|
| 6329 | var lastIndex = length - 1;
|
|---|
| 6330 | details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
|
|---|
| 6331 | details = details.join(length > 2 ? ', ' : ' ');
|
|---|
| 6332 | return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
|
|---|
| 6333 | }
|
|---|
| 6334 |
|
|---|
| 6335 | /**
|
|---|
| 6336 | * Checks if `value` is a flattenable `arguments` object or array.
|
|---|
| 6337 | *
|
|---|
| 6338 | * @private
|
|---|
| 6339 | * @param {*} value The value to check.
|
|---|
| 6340 | * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
|
|---|
| 6341 | */
|
|---|
| 6342 | function isFlattenable(value) {
|
|---|
| 6343 | return isArray(value) || isArguments(value) ||
|
|---|
| 6344 | !!(spreadableSymbol && value && value[spreadableSymbol]);
|
|---|
| 6345 | }
|
|---|
| 6346 |
|
|---|
| 6347 | /**
|
|---|
| 6348 | * Checks if `value` is a valid array-like index.
|
|---|
| 6349 | *
|
|---|
| 6350 | * @private
|
|---|
| 6351 | * @param {*} value The value to check.
|
|---|
| 6352 | * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
|---|
| 6353 | * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
|---|
| 6354 | */
|
|---|
| 6355 | function isIndex(value, length) {
|
|---|
| 6356 | var type = typeof value;
|
|---|
| 6357 | length = length == null ? MAX_SAFE_INTEGER : length;
|
|---|
| 6358 |
|
|---|
| 6359 | return !!length &&
|
|---|
| 6360 | (type == 'number' ||
|
|---|
| 6361 | (type != 'symbol' && reIsUint.test(value))) &&
|
|---|
| 6362 | (value > -1 && value % 1 == 0 && value < length);
|
|---|
| 6363 | }
|
|---|
| 6364 |
|
|---|
| 6365 | /**
|
|---|
| 6366 | * Checks if the given arguments are from an iteratee call.
|
|---|
| 6367 | *
|
|---|
| 6368 | * @private
|
|---|
| 6369 | * @param {*} value The potential iteratee value argument.
|
|---|
| 6370 | * @param {*} index The potential iteratee index or key argument.
|
|---|
| 6371 | * @param {*} object The potential iteratee object argument.
|
|---|
| 6372 | * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
|
|---|
| 6373 | * else `false`.
|
|---|
| 6374 | */
|
|---|
| 6375 | function isIterateeCall(value, index, object) {
|
|---|
| 6376 | if (!isObject(object)) {
|
|---|
| 6377 | return false;
|
|---|
| 6378 | }
|
|---|
| 6379 | var type = typeof index;
|
|---|
| 6380 | if (type == 'number'
|
|---|
| 6381 | ? (isArrayLike(object) && isIndex(index, object.length))
|
|---|
| 6382 | : (type == 'string' && index in object)
|
|---|
| 6383 | ) {
|
|---|
| 6384 | return eq(object[index], value);
|
|---|
| 6385 | }
|
|---|
| 6386 | return false;
|
|---|
| 6387 | }
|
|---|
| 6388 |
|
|---|
| 6389 | /**
|
|---|
| 6390 | * Checks if `value` is a property name and not a property path.
|
|---|
| 6391 | *
|
|---|
| 6392 | * @private
|
|---|
| 6393 | * @param {*} value The value to check.
|
|---|
| 6394 | * @param {Object} [object] The object to query keys on.
|
|---|
| 6395 | * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|---|
| 6396 | */
|
|---|
| 6397 | function isKey(value, object) {
|
|---|
| 6398 | if (isArray(value)) {
|
|---|
| 6399 | return false;
|
|---|
| 6400 | }
|
|---|
| 6401 | var type = typeof value;
|
|---|
| 6402 | if (type == 'number' || type == 'symbol' || type == 'boolean' ||
|
|---|
| 6403 | value == null || isSymbol(value)) {
|
|---|
| 6404 | return true;
|
|---|
| 6405 | }
|
|---|
| 6406 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
|---|
| 6407 | (object != null && value in Object(object));
|
|---|
| 6408 | }
|
|---|
| 6409 |
|
|---|
| 6410 | /**
|
|---|
| 6411 | * Checks if `value` is suitable for use as unique object key.
|
|---|
| 6412 | *
|
|---|
| 6413 | * @private
|
|---|
| 6414 | * @param {*} value The value to check.
|
|---|
| 6415 | * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
|---|
| 6416 | */
|
|---|
| 6417 | function isKeyable(value) {
|
|---|
| 6418 | var type = typeof value;
|
|---|
| 6419 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
|---|
| 6420 | ? (value !== '__proto__')
|
|---|
| 6421 | : (value === null);
|
|---|
| 6422 | }
|
|---|
| 6423 |
|
|---|
| 6424 | /**
|
|---|
| 6425 | * Checks if `func` has a lazy counterpart.
|
|---|
| 6426 | *
|
|---|
| 6427 | * @private
|
|---|
| 6428 | * @param {Function} func The function to check.
|
|---|
| 6429 | * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
|
|---|
| 6430 | * else `false`.
|
|---|
| 6431 | */
|
|---|
| 6432 | function isLaziable(func) {
|
|---|
| 6433 | var funcName = getFuncName(func),
|
|---|
| 6434 | other = lodash[funcName];
|
|---|
| 6435 |
|
|---|
| 6436 | if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
|
|---|
| 6437 | return false;
|
|---|
| 6438 | }
|
|---|
| 6439 | if (func === other) {
|
|---|
| 6440 | return true;
|
|---|
| 6441 | }
|
|---|
| 6442 | var data = getData(other);
|
|---|
| 6443 | return !!data && func === data[0];
|
|---|
| 6444 | }
|
|---|
| 6445 |
|
|---|
| 6446 | /**
|
|---|
| 6447 | * Checks if `func` has its source masked.
|
|---|
| 6448 | *
|
|---|
| 6449 | * @private
|
|---|
| 6450 | * @param {Function} func The function to check.
|
|---|
| 6451 | * @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
|---|
| 6452 | */
|
|---|
| 6453 | function isMasked(func) {
|
|---|
| 6454 | return !!maskSrcKey && (maskSrcKey in func);
|
|---|
| 6455 | }
|
|---|
| 6456 |
|
|---|
| 6457 | /**
|
|---|
| 6458 | * Checks if `func` is capable of being masked.
|
|---|
| 6459 | *
|
|---|
| 6460 | * @private
|
|---|
| 6461 | * @param {*} value The value to check.
|
|---|
| 6462 | * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
|
|---|
| 6463 | */
|
|---|
| 6464 | var isMaskable = coreJsData ? isFunction : stubFalse;
|
|---|
| 6465 |
|
|---|
| 6466 | /**
|
|---|
| 6467 | * Checks if `value` is likely a prototype object.
|
|---|
| 6468 | *
|
|---|
| 6469 | * @private
|
|---|
| 6470 | * @param {*} value The value to check.
|
|---|
| 6471 | * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
|---|
| 6472 | */
|
|---|
| 6473 | function isPrototype(value) {
|
|---|
| 6474 | var Ctor = value && value.constructor,
|
|---|
| 6475 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
|---|
| 6476 |
|
|---|
| 6477 | return value === proto;
|
|---|
| 6478 | }
|
|---|
| 6479 |
|
|---|
| 6480 | /**
|
|---|
| 6481 | * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
|---|
| 6482 | *
|
|---|
| 6483 | * @private
|
|---|
| 6484 | * @param {*} value The value to check.
|
|---|
| 6485 | * @returns {boolean} Returns `true` if `value` if suitable for strict
|
|---|
| 6486 | * equality comparisons, else `false`.
|
|---|
| 6487 | */
|
|---|
| 6488 | function isStrictComparable(value) {
|
|---|
| 6489 | return value === value && !isObject(value);
|
|---|
| 6490 | }
|
|---|
| 6491 |
|
|---|
| 6492 | /**
|
|---|
| 6493 | * A specialized version of `matchesProperty` for source values suitable
|
|---|
| 6494 | * for strict equality comparisons, i.e. `===`.
|
|---|
| 6495 | *
|
|---|
| 6496 | * @private
|
|---|
| 6497 | * @param {string} key The key of the property to get.
|
|---|
| 6498 | * @param {*} srcValue The value to match.
|
|---|
| 6499 | * @returns {Function} Returns the new spec function.
|
|---|
| 6500 | */
|
|---|
| 6501 | function matchesStrictComparable(key, srcValue) {
|
|---|
| 6502 | return function(object) {
|
|---|
| 6503 | if (object == null) {
|
|---|
| 6504 | return false;
|
|---|
| 6505 | }
|
|---|
| 6506 | return object[key] === srcValue &&
|
|---|
| 6507 | (srcValue !== undefined || (key in Object(object)));
|
|---|
| 6508 | };
|
|---|
| 6509 | }
|
|---|
| 6510 |
|
|---|
| 6511 | /**
|
|---|
| 6512 | * A specialized version of `_.memoize` which clears the memoized function's
|
|---|
| 6513 | * cache when it exceeds `MAX_MEMOIZE_SIZE`.
|
|---|
| 6514 | *
|
|---|
| 6515 | * @private
|
|---|
| 6516 | * @param {Function} func The function to have its output memoized.
|
|---|
| 6517 | * @returns {Function} Returns the new memoized function.
|
|---|
| 6518 | */
|
|---|
| 6519 | function memoizeCapped(func) {
|
|---|
| 6520 | var result = memoize(func, function(key) {
|
|---|
| 6521 | if (cache.size === MAX_MEMOIZE_SIZE) {
|
|---|
| 6522 | cache.clear();
|
|---|
| 6523 | }
|
|---|
| 6524 | return key;
|
|---|
| 6525 | });
|
|---|
| 6526 |
|
|---|
| 6527 | var cache = result.cache;
|
|---|
| 6528 | return result;
|
|---|
| 6529 | }
|
|---|
| 6530 |
|
|---|
| 6531 | /**
|
|---|
| 6532 | * Merges the function metadata of `source` into `data`.
|
|---|
| 6533 | *
|
|---|
| 6534 | * Merging metadata reduces the number of wrappers used to invoke a function.
|
|---|
| 6535 | * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
|
|---|
| 6536 | * may be applied regardless of execution order. Methods like `_.ary` and
|
|---|
| 6537 | * `_.rearg` modify function arguments, making the order in which they are
|
|---|
| 6538 | * executed important, preventing the merging of metadata. However, we make
|
|---|
| 6539 | * an exception for a safe combined case where curried functions have `_.ary`
|
|---|
| 6540 | * and or `_.rearg` applied.
|
|---|
| 6541 | *
|
|---|
| 6542 | * @private
|
|---|
| 6543 | * @param {Array} data The destination metadata.
|
|---|
| 6544 | * @param {Array} source The source metadata.
|
|---|
| 6545 | * @returns {Array} Returns `data`.
|
|---|
| 6546 | */
|
|---|
| 6547 | function mergeData(data, source) {
|
|---|
| 6548 | var bitmask = data[1],
|
|---|
| 6549 | srcBitmask = source[1],
|
|---|
| 6550 | newBitmask = bitmask | srcBitmask,
|
|---|
| 6551 | isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
|
|---|
| 6552 |
|
|---|
| 6553 | var isCombo =
|
|---|
| 6554 | ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
|
|---|
| 6555 | ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
|
|---|
| 6556 | ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
|
|---|
| 6557 |
|
|---|
| 6558 | // Exit early if metadata can't be merged.
|
|---|
| 6559 | if (!(isCommon || isCombo)) {
|
|---|
| 6560 | return data;
|
|---|
| 6561 | }
|
|---|
| 6562 | // Use source `thisArg` if available.
|
|---|
| 6563 | if (srcBitmask & WRAP_BIND_FLAG) {
|
|---|
| 6564 | data[2] = source[2];
|
|---|
| 6565 | // Set when currying a bound function.
|
|---|
| 6566 | newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
|
|---|
| 6567 | }
|
|---|
| 6568 | // Compose partial arguments.
|
|---|
| 6569 | var value = source[3];
|
|---|
| 6570 | if (value) {
|
|---|
| 6571 | var partials = data[3];
|
|---|
| 6572 | data[3] = partials ? composeArgs(partials, value, source[4]) : value;
|
|---|
| 6573 | data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
|
|---|
| 6574 | }
|
|---|
| 6575 | // Compose partial right arguments.
|
|---|
| 6576 | value = source[5];
|
|---|
| 6577 | if (value) {
|
|---|
| 6578 | partials = data[5];
|
|---|
| 6579 | data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
|
|---|
| 6580 | data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
|
|---|
| 6581 | }
|
|---|
| 6582 | // Use source `argPos` if available.
|
|---|
| 6583 | value = source[7];
|
|---|
| 6584 | if (value) {
|
|---|
| 6585 | data[7] = value;
|
|---|
| 6586 | }
|
|---|
| 6587 | // Use source `ary` if it's smaller.
|
|---|
| 6588 | if (srcBitmask & WRAP_ARY_FLAG) {
|
|---|
| 6589 | data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
|
|---|
| 6590 | }
|
|---|
| 6591 | // Use source `arity` if one is not provided.
|
|---|
| 6592 | if (data[9] == null) {
|
|---|
| 6593 | data[9] = source[9];
|
|---|
| 6594 | }
|
|---|
| 6595 | // Use source `func` and merge bitmasks.
|
|---|
| 6596 | data[0] = source[0];
|
|---|
| 6597 | data[1] = newBitmask;
|
|---|
| 6598 |
|
|---|
| 6599 | return data;
|
|---|
| 6600 | }
|
|---|
| 6601 |
|
|---|
| 6602 | /**
|
|---|
| 6603 | * This function is like
|
|---|
| 6604 | * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
|---|
| 6605 | * except that it includes inherited enumerable properties.
|
|---|
| 6606 | *
|
|---|
| 6607 | * @private
|
|---|
| 6608 | * @param {Object} object The object to query.
|
|---|
| 6609 | * @returns {Array} Returns the array of property names.
|
|---|
| 6610 | */
|
|---|
| 6611 | function nativeKeysIn(object) {
|
|---|
| 6612 | var result = [];
|
|---|
| 6613 | if (object != null) {
|
|---|
| 6614 | for (var key in Object(object)) {
|
|---|
| 6615 | result.push(key);
|
|---|
| 6616 | }
|
|---|
| 6617 | }
|
|---|
| 6618 | return result;
|
|---|
| 6619 | }
|
|---|
| 6620 |
|
|---|
| 6621 | /**
|
|---|
| 6622 | * Converts `value` to a string using `Object.prototype.toString`.
|
|---|
| 6623 | *
|
|---|
| 6624 | * @private
|
|---|
| 6625 | * @param {*} value The value to convert.
|
|---|
| 6626 | * @returns {string} Returns the converted string.
|
|---|
| 6627 | */
|
|---|
| 6628 | function objectToString(value) {
|
|---|
| 6629 | return nativeObjectToString.call(value);
|
|---|
| 6630 | }
|
|---|
| 6631 |
|
|---|
| 6632 | /**
|
|---|
| 6633 | * A specialized version of `baseRest` which transforms the rest array.
|
|---|
| 6634 | *
|
|---|
| 6635 | * @private
|
|---|
| 6636 | * @param {Function} func The function to apply a rest parameter to.
|
|---|
| 6637 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
|---|
| 6638 | * @param {Function} transform The rest array transform.
|
|---|
| 6639 | * @returns {Function} Returns the new function.
|
|---|
| 6640 | */
|
|---|
| 6641 | function overRest(func, start, transform) {
|
|---|
| 6642 | start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
|---|
| 6643 | return function() {
|
|---|
| 6644 | var args = arguments,
|
|---|
| 6645 | index = -1,
|
|---|
| 6646 | length = nativeMax(args.length - start, 0),
|
|---|
| 6647 | array = Array(length);
|
|---|
| 6648 |
|
|---|
| 6649 | while (++index < length) {
|
|---|
| 6650 | array[index] = args[start + index];
|
|---|
| 6651 | }
|
|---|
| 6652 | index = -1;
|
|---|
| 6653 | var otherArgs = Array(start + 1);
|
|---|
| 6654 | while (++index < start) {
|
|---|
| 6655 | otherArgs[index] = args[index];
|
|---|
| 6656 | }
|
|---|
| 6657 | otherArgs[start] = transform(array);
|
|---|
| 6658 | return apply(func, this, otherArgs);
|
|---|
| 6659 | };
|
|---|
| 6660 | }
|
|---|
| 6661 |
|
|---|
| 6662 | /**
|
|---|
| 6663 | * Gets the parent value at `path` of `object`.
|
|---|
| 6664 | *
|
|---|
| 6665 | * @private
|
|---|
| 6666 | * @param {Object} object The object to query.
|
|---|
| 6667 | * @param {Array} path The path to get the parent value of.
|
|---|
| 6668 | * @returns {*} Returns the parent value.
|
|---|
| 6669 | */
|
|---|
| 6670 | function parent(object, path) {
|
|---|
| 6671 | return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
|
|---|
| 6672 | }
|
|---|
| 6673 |
|
|---|
| 6674 | /**
|
|---|
| 6675 | * Reorder `array` according to the specified indexes where the element at
|
|---|
| 6676 | * the first index is assigned as the first element, the element at
|
|---|
| 6677 | * the second index is assigned as the second element, and so on.
|
|---|
| 6678 | *
|
|---|
| 6679 | * @private
|
|---|
| 6680 | * @param {Array} array The array to reorder.
|
|---|
| 6681 | * @param {Array} indexes The arranged array indexes.
|
|---|
| 6682 | * @returns {Array} Returns `array`.
|
|---|
| 6683 | */
|
|---|
| 6684 | function reorder(array, indexes) {
|
|---|
| 6685 | var arrLength = array.length,
|
|---|
| 6686 | length = nativeMin(indexes.length, arrLength),
|
|---|
| 6687 | oldArray = copyArray(array);
|
|---|
| 6688 |
|
|---|
| 6689 | while (length--) {
|
|---|
| 6690 | var index = indexes[length];
|
|---|
| 6691 | array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
|
|---|
| 6692 | }
|
|---|
| 6693 | return array;
|
|---|
| 6694 | }
|
|---|
| 6695 |
|
|---|
| 6696 | /**
|
|---|
| 6697 | * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
|
|---|
| 6698 | *
|
|---|
| 6699 | * @private
|
|---|
| 6700 | * @param {Object} object The object to query.
|
|---|
| 6701 | * @param {string} key The key of the property to get.
|
|---|
| 6702 | * @returns {*} Returns the property value.
|
|---|
| 6703 | */
|
|---|
| 6704 | function safeGet(object, key) {
|
|---|
| 6705 | if (key === 'constructor' && typeof object[key] === 'function') {
|
|---|
| 6706 | return;
|
|---|
| 6707 | }
|
|---|
| 6708 |
|
|---|
| 6709 | if (key == '__proto__') {
|
|---|
| 6710 | return;
|
|---|
| 6711 | }
|
|---|
| 6712 |
|
|---|
| 6713 | return object[key];
|
|---|
| 6714 | }
|
|---|
| 6715 |
|
|---|
| 6716 | /**
|
|---|
| 6717 | * Sets metadata for `func`.
|
|---|
| 6718 | *
|
|---|
| 6719 | * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
|
|---|
| 6720 | * period of time, it will trip its breaker and transition to an identity
|
|---|
| 6721 | * function to avoid garbage collection pauses in V8. See
|
|---|
| 6722 | * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
|
|---|
| 6723 | * for more details.
|
|---|
| 6724 | *
|
|---|
| 6725 | * @private
|
|---|
| 6726 | * @param {Function} func The function to associate metadata with.
|
|---|
| 6727 | * @param {*} data The metadata.
|
|---|
| 6728 | * @returns {Function} Returns `func`.
|
|---|
| 6729 | */
|
|---|
| 6730 | var setData = shortOut(baseSetData);
|
|---|
| 6731 |
|
|---|
| 6732 | /**
|
|---|
| 6733 | * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
|
|---|
| 6734 | *
|
|---|
| 6735 | * @private
|
|---|
| 6736 | * @param {Function} func The function to delay.
|
|---|
| 6737 | * @param {number} wait The number of milliseconds to delay invocation.
|
|---|
| 6738 | * @returns {number|Object} Returns the timer id or timeout object.
|
|---|
| 6739 | */
|
|---|
| 6740 | var setTimeout = ctxSetTimeout || function(func, wait) {
|
|---|
| 6741 | return root.setTimeout(func, wait);
|
|---|
| 6742 | };
|
|---|
| 6743 |
|
|---|
| 6744 | /**
|
|---|
| 6745 | * Sets the `toString` method of `func` to return `string`.
|
|---|
| 6746 | *
|
|---|
| 6747 | * @private
|
|---|
| 6748 | * @param {Function} func The function to modify.
|
|---|
| 6749 | * @param {Function} string The `toString` result.
|
|---|
| 6750 | * @returns {Function} Returns `func`.
|
|---|
| 6751 | */
|
|---|
| 6752 | var setToString = shortOut(baseSetToString);
|
|---|
| 6753 |
|
|---|
| 6754 | /**
|
|---|
| 6755 | * Sets the `toString` method of `wrapper` to mimic the source of `reference`
|
|---|
| 6756 | * with wrapper details in a comment at the top of the source body.
|
|---|
| 6757 | *
|
|---|
| 6758 | * @private
|
|---|
| 6759 | * @param {Function} wrapper The function to modify.
|
|---|
| 6760 | * @param {Function} reference The reference function.
|
|---|
| 6761 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
|---|
| 6762 | * @returns {Function} Returns `wrapper`.
|
|---|
| 6763 | */
|
|---|
| 6764 | function setWrapToString(wrapper, reference, bitmask) {
|
|---|
| 6765 | var source = (reference + '');
|
|---|
| 6766 | return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
|
|---|
| 6767 | }
|
|---|
| 6768 |
|
|---|
| 6769 | /**
|
|---|
| 6770 | * Creates a function that'll short out and invoke `identity` instead
|
|---|
| 6771 | * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
|
|---|
| 6772 | * milliseconds.
|
|---|
| 6773 | *
|
|---|
| 6774 | * @private
|
|---|
| 6775 | * @param {Function} func The function to restrict.
|
|---|
| 6776 | * @returns {Function} Returns the new shortable function.
|
|---|
| 6777 | */
|
|---|
| 6778 | function shortOut(func) {
|
|---|
| 6779 | var count = 0,
|
|---|
| 6780 | lastCalled = 0;
|
|---|
| 6781 |
|
|---|
| 6782 | return function() {
|
|---|
| 6783 | var stamp = nativeNow(),
|
|---|
| 6784 | remaining = HOT_SPAN - (stamp - lastCalled);
|
|---|
| 6785 |
|
|---|
| 6786 | lastCalled = stamp;
|
|---|
| 6787 | if (remaining > 0) {
|
|---|
| 6788 | if (++count >= HOT_COUNT) {
|
|---|
| 6789 | return arguments[0];
|
|---|
| 6790 | }
|
|---|
| 6791 | } else {
|
|---|
| 6792 | count = 0;
|
|---|
| 6793 | }
|
|---|
| 6794 | return func.apply(undefined, arguments);
|
|---|
| 6795 | };
|
|---|
| 6796 | }
|
|---|
| 6797 |
|
|---|
| 6798 | /**
|
|---|
| 6799 | * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
|
|---|
| 6800 | *
|
|---|
| 6801 | * @private
|
|---|
| 6802 | * @param {Array} array The array to shuffle.
|
|---|
| 6803 | * @param {number} [size=array.length] The size of `array`.
|
|---|
| 6804 | * @returns {Array} Returns `array`.
|
|---|
| 6805 | */
|
|---|
| 6806 | function shuffleSelf(array, size) {
|
|---|
| 6807 | var index = -1,
|
|---|
| 6808 | length = array.length,
|
|---|
| 6809 | lastIndex = length - 1;
|
|---|
| 6810 |
|
|---|
| 6811 | size = size === undefined ? length : size;
|
|---|
| 6812 | while (++index < size) {
|
|---|
| 6813 | var rand = baseRandom(index, lastIndex),
|
|---|
| 6814 | value = array[rand];
|
|---|
| 6815 |
|
|---|
| 6816 | array[rand] = array[index];
|
|---|
| 6817 | array[index] = value;
|
|---|
| 6818 | }
|
|---|
| 6819 | array.length = size;
|
|---|
| 6820 | return array;
|
|---|
| 6821 | }
|
|---|
| 6822 |
|
|---|
| 6823 | /**
|
|---|
| 6824 | * Converts `string` to a property path array.
|
|---|
| 6825 | *
|
|---|
| 6826 | * @private
|
|---|
| 6827 | * @param {string} string The string to convert.
|
|---|
| 6828 | * @returns {Array} Returns the property path array.
|
|---|
| 6829 | */
|
|---|
| 6830 | var stringToPath = memoizeCapped(function(string) {
|
|---|
| 6831 | var result = [];
|
|---|
| 6832 | if (string.charCodeAt(0) === 46 /* . */) {
|
|---|
| 6833 | result.push('');
|
|---|
| 6834 | }
|
|---|
| 6835 | string.replace(rePropName, function(match, number, quote, subString) {
|
|---|
| 6836 | result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
|
|---|
| 6837 | });
|
|---|
| 6838 | return result;
|
|---|
| 6839 | });
|
|---|
| 6840 |
|
|---|
| 6841 | /**
|
|---|
| 6842 | * Converts `value` to a string key if it's not a string or symbol.
|
|---|
| 6843 | *
|
|---|
| 6844 | * @private
|
|---|
| 6845 | * @param {*} value The value to inspect.
|
|---|
| 6846 | * @returns {string|symbol} Returns the key.
|
|---|
| 6847 | */
|
|---|
| 6848 | function toKey(value) {
|
|---|
| 6849 | if (typeof value == 'string' || isSymbol(value)) {
|
|---|
| 6850 | return value;
|
|---|
| 6851 | }
|
|---|
| 6852 | var result = (value + '');
|
|---|
| 6853 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
|---|
| 6854 | }
|
|---|
| 6855 |
|
|---|
| 6856 | /**
|
|---|
| 6857 | * Converts `func` to its source code.
|
|---|
| 6858 | *
|
|---|
| 6859 | * @private
|
|---|
| 6860 | * @param {Function} func The function to convert.
|
|---|
| 6861 | * @returns {string} Returns the source code.
|
|---|
| 6862 | */
|
|---|
| 6863 | function toSource(func) {
|
|---|
| 6864 | if (func != null) {
|
|---|
| 6865 | try {
|
|---|
| 6866 | return funcToString.call(func);
|
|---|
| 6867 | } catch (e) {}
|
|---|
| 6868 | try {
|
|---|
| 6869 | return (func + '');
|
|---|
| 6870 | } catch (e) {}
|
|---|
| 6871 | }
|
|---|
| 6872 | return '';
|
|---|
| 6873 | }
|
|---|
| 6874 |
|
|---|
| 6875 | /**
|
|---|
| 6876 | * Updates wrapper `details` based on `bitmask` flags.
|
|---|
| 6877 | *
|
|---|
| 6878 | * @private
|
|---|
| 6879 | * @returns {Array} details The details to modify.
|
|---|
| 6880 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
|---|
| 6881 | * @returns {Array} Returns `details`.
|
|---|
| 6882 | */
|
|---|
| 6883 | function updateWrapDetails(details, bitmask) {
|
|---|
| 6884 | arrayEach(wrapFlags, function(pair) {
|
|---|
| 6885 | var value = '_.' + pair[0];
|
|---|
| 6886 | if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
|
|---|
| 6887 | details.push(value);
|
|---|
| 6888 | }
|
|---|
| 6889 | });
|
|---|
| 6890 | return details.sort();
|
|---|
| 6891 | }
|
|---|
| 6892 |
|
|---|
| 6893 | /**
|
|---|
| 6894 | * Creates a clone of `wrapper`.
|
|---|
| 6895 | *
|
|---|
| 6896 | * @private
|
|---|
| 6897 | * @param {Object} wrapper The wrapper to clone.
|
|---|
| 6898 | * @returns {Object} Returns the cloned wrapper.
|
|---|
| 6899 | */
|
|---|
| 6900 | function wrapperClone(wrapper) {
|
|---|
| 6901 | if (wrapper instanceof LazyWrapper) {
|
|---|
| 6902 | return wrapper.clone();
|
|---|
| 6903 | }
|
|---|
| 6904 | var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
|
|---|
| 6905 | result.__actions__ = copyArray(wrapper.__actions__);
|
|---|
| 6906 | result.__index__ = wrapper.__index__;
|
|---|
| 6907 | result.__values__ = wrapper.__values__;
|
|---|
| 6908 | return result;
|
|---|
| 6909 | }
|
|---|
| 6910 |
|
|---|
| 6911 | /*------------------------------------------------------------------------*/
|
|---|
| 6912 |
|
|---|
| 6913 | /**
|
|---|
| 6914 | * Creates an array of elements split into groups the length of `size`.
|
|---|
| 6915 | * If `array` can't be split evenly, the final chunk will be the remaining
|
|---|
| 6916 | * elements.
|
|---|
| 6917 | *
|
|---|
| 6918 | * @static
|
|---|
| 6919 | * @memberOf _
|
|---|
| 6920 | * @since 3.0.0
|
|---|
| 6921 | * @category Array
|
|---|
| 6922 | * @param {Array} array The array to process.
|
|---|
| 6923 | * @param {number} [size=1] The length of each chunk
|
|---|
| 6924 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 6925 | * @returns {Array} Returns the new array of chunks.
|
|---|
| 6926 | * @example
|
|---|
| 6927 | *
|
|---|
| 6928 | * _.chunk(['a', 'b', 'c', 'd'], 2);
|
|---|
| 6929 | * // => [['a', 'b'], ['c', 'd']]
|
|---|
| 6930 | *
|
|---|
| 6931 | * _.chunk(['a', 'b', 'c', 'd'], 3);
|
|---|
| 6932 | * // => [['a', 'b', 'c'], ['d']]
|
|---|
| 6933 | */
|
|---|
| 6934 | function chunk(array, size, guard) {
|
|---|
| 6935 | if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
|
|---|
| 6936 | size = 1;
|
|---|
| 6937 | } else {
|
|---|
| 6938 | size = nativeMax(toInteger(size), 0);
|
|---|
| 6939 | }
|
|---|
| 6940 | var length = array == null ? 0 : array.length;
|
|---|
| 6941 | if (!length || size < 1) {
|
|---|
| 6942 | return [];
|
|---|
| 6943 | }
|
|---|
| 6944 | var index = 0,
|
|---|
| 6945 | resIndex = 0,
|
|---|
| 6946 | result = Array(nativeCeil(length / size));
|
|---|
| 6947 |
|
|---|
| 6948 | while (index < length) {
|
|---|
| 6949 | result[resIndex++] = baseSlice(array, index, (index += size));
|
|---|
| 6950 | }
|
|---|
| 6951 | return result;
|
|---|
| 6952 | }
|
|---|
| 6953 |
|
|---|
| 6954 | /**
|
|---|
| 6955 | * Creates an array with all falsey values removed. The values `false`, `null`,
|
|---|
| 6956 | * `0`, `-0`, `0n`, `""`, `undefined`, and `NaN` are falsy.
|
|---|
| 6957 | *
|
|---|
| 6958 | * @static
|
|---|
| 6959 | * @memberOf _
|
|---|
| 6960 | * @since 0.1.0
|
|---|
| 6961 | * @category Array
|
|---|
| 6962 | * @param {Array} array The array to compact.
|
|---|
| 6963 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 6964 | * @example
|
|---|
| 6965 | *
|
|---|
| 6966 | * _.compact([0, 1, false, 2, '', 3]);
|
|---|
| 6967 | * // => [1, 2, 3]
|
|---|
| 6968 | */
|
|---|
| 6969 | function compact(array) {
|
|---|
| 6970 | var index = -1,
|
|---|
| 6971 | length = array == null ? 0 : array.length,
|
|---|
| 6972 | resIndex = 0,
|
|---|
| 6973 | result = [];
|
|---|
| 6974 |
|
|---|
| 6975 | while (++index < length) {
|
|---|
| 6976 | var value = array[index];
|
|---|
| 6977 | if (value) {
|
|---|
| 6978 | result[resIndex++] = value;
|
|---|
| 6979 | }
|
|---|
| 6980 | }
|
|---|
| 6981 | return result;
|
|---|
| 6982 | }
|
|---|
| 6983 |
|
|---|
| 6984 | /**
|
|---|
| 6985 | * Creates a new array concatenating `array` with any additional arrays
|
|---|
| 6986 | * and/or values.
|
|---|
| 6987 | *
|
|---|
| 6988 | * @static
|
|---|
| 6989 | * @memberOf _
|
|---|
| 6990 | * @since 4.0.0
|
|---|
| 6991 | * @category Array
|
|---|
| 6992 | * @param {Array} array The array to concatenate.
|
|---|
| 6993 | * @param {...*} [values] The values to concatenate.
|
|---|
| 6994 | * @returns {Array} Returns the new concatenated array.
|
|---|
| 6995 | * @example
|
|---|
| 6996 | *
|
|---|
| 6997 | * var array = [1];
|
|---|
| 6998 | * var other = _.concat(array, 2, [3], [[4]]);
|
|---|
| 6999 | *
|
|---|
| 7000 | * console.log(other);
|
|---|
| 7001 | * // => [1, 2, 3, [4]]
|
|---|
| 7002 | *
|
|---|
| 7003 | * console.log(array);
|
|---|
| 7004 | * // => [1]
|
|---|
| 7005 | */
|
|---|
| 7006 | function concat() {
|
|---|
| 7007 | var length = arguments.length;
|
|---|
| 7008 | if (!length) {
|
|---|
| 7009 | return [];
|
|---|
| 7010 | }
|
|---|
| 7011 | var args = Array(length - 1),
|
|---|
| 7012 | array = arguments[0],
|
|---|
| 7013 | index = length;
|
|---|
| 7014 |
|
|---|
| 7015 | while (index--) {
|
|---|
| 7016 | args[index - 1] = arguments[index];
|
|---|
| 7017 | }
|
|---|
| 7018 | return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
|
|---|
| 7019 | }
|
|---|
| 7020 |
|
|---|
| 7021 | /**
|
|---|
| 7022 | * Creates an array of `array` values not included in the other given arrays
|
|---|
| 7023 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 7024 | * for equality comparisons. The order and references of result values are
|
|---|
| 7025 | * determined by the first array.
|
|---|
| 7026 | *
|
|---|
| 7027 | * **Note:** Unlike `_.pullAll`, this method returns a new array.
|
|---|
| 7028 | *
|
|---|
| 7029 | * @static
|
|---|
| 7030 | * @memberOf _
|
|---|
| 7031 | * @since 0.1.0
|
|---|
| 7032 | * @category Array
|
|---|
| 7033 | * @param {Array} array The array to inspect.
|
|---|
| 7034 | * @param {...Array} [values] The values to exclude.
|
|---|
| 7035 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 7036 | * @see _.without, _.xor
|
|---|
| 7037 | * @example
|
|---|
| 7038 | *
|
|---|
| 7039 | * _.difference([2, 1], [2, 3]);
|
|---|
| 7040 | * // => [1]
|
|---|
| 7041 | */
|
|---|
| 7042 | var difference = baseRest(function(array, values) {
|
|---|
| 7043 | return isArrayLikeObject(array)
|
|---|
| 7044 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
|
|---|
| 7045 | : [];
|
|---|
| 7046 | });
|
|---|
| 7047 |
|
|---|
| 7048 | /**
|
|---|
| 7049 | * This method is like `_.difference` except that it accepts `iteratee` which
|
|---|
| 7050 | * is invoked for each element of `array` and `values` to generate the criterion
|
|---|
| 7051 | * by which they're compared. The order and references of result values are
|
|---|
| 7052 | * determined by the first array. The iteratee is invoked with one argument:
|
|---|
| 7053 | * (value).
|
|---|
| 7054 | *
|
|---|
| 7055 | * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
|
|---|
| 7056 | *
|
|---|
| 7057 | * @static
|
|---|
| 7058 | * @memberOf _
|
|---|
| 7059 | * @since 4.0.0
|
|---|
| 7060 | * @category Array
|
|---|
| 7061 | * @param {Array} array The array to inspect.
|
|---|
| 7062 | * @param {...Array} [values] The values to exclude.
|
|---|
| 7063 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 7064 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 7065 | * @example
|
|---|
| 7066 | *
|
|---|
| 7067 | * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
|---|
| 7068 | * // => [1.2]
|
|---|
| 7069 | *
|
|---|
| 7070 | * // The `_.property` iteratee shorthand.
|
|---|
| 7071 | * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
|
|---|
| 7072 | * // => [{ 'x': 2 }]
|
|---|
| 7073 | */
|
|---|
| 7074 | var differenceBy = baseRest(function(array, values) {
|
|---|
| 7075 | var iteratee = last(values);
|
|---|
| 7076 | if (isArrayLikeObject(iteratee)) {
|
|---|
| 7077 | iteratee = undefined;
|
|---|
| 7078 | }
|
|---|
| 7079 | return isArrayLikeObject(array)
|
|---|
| 7080 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
|
|---|
| 7081 | : [];
|
|---|
| 7082 | });
|
|---|
| 7083 |
|
|---|
| 7084 | /**
|
|---|
| 7085 | * This method is like `_.difference` except that it accepts `comparator`
|
|---|
| 7086 | * which is invoked to compare elements of `array` to `values`. The order and
|
|---|
| 7087 | * references of result values are determined by the first array. The comparator
|
|---|
| 7088 | * is invoked with two arguments: (arrVal, othVal).
|
|---|
| 7089 | *
|
|---|
| 7090 | * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
|
|---|
| 7091 | *
|
|---|
| 7092 | * @static
|
|---|
| 7093 | * @memberOf _
|
|---|
| 7094 | * @since 4.0.0
|
|---|
| 7095 | * @category Array
|
|---|
| 7096 | * @param {Array} array The array to inspect.
|
|---|
| 7097 | * @param {...Array} [values] The values to exclude.
|
|---|
| 7098 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 7099 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 7100 | * @example
|
|---|
| 7101 | *
|
|---|
| 7102 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
|---|
| 7103 | *
|
|---|
| 7104 | * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
|
|---|
| 7105 | * // => [{ 'x': 2, 'y': 1 }]
|
|---|
| 7106 | */
|
|---|
| 7107 | var differenceWith = baseRest(function(array, values) {
|
|---|
| 7108 | var comparator = last(values);
|
|---|
| 7109 | if (isArrayLikeObject(comparator)) {
|
|---|
| 7110 | comparator = undefined;
|
|---|
| 7111 | }
|
|---|
| 7112 | return isArrayLikeObject(array)
|
|---|
| 7113 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
|
|---|
| 7114 | : [];
|
|---|
| 7115 | });
|
|---|
| 7116 |
|
|---|
| 7117 | /**
|
|---|
| 7118 | * Creates a slice of `array` with `n` elements dropped from the beginning.
|
|---|
| 7119 | *
|
|---|
| 7120 | * @static
|
|---|
| 7121 | * @memberOf _
|
|---|
| 7122 | * @since 0.5.0
|
|---|
| 7123 | * @category Array
|
|---|
| 7124 | * @param {Array} array The array to query.
|
|---|
| 7125 | * @param {number} [n=1] The number of elements to drop.
|
|---|
| 7126 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 7127 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 7128 | * @example
|
|---|
| 7129 | *
|
|---|
| 7130 | * _.drop([1, 2, 3]);
|
|---|
| 7131 | * // => [2, 3]
|
|---|
| 7132 | *
|
|---|
| 7133 | * _.drop([1, 2, 3], 2);
|
|---|
| 7134 | * // => [3]
|
|---|
| 7135 | *
|
|---|
| 7136 | * _.drop([1, 2, 3], 5);
|
|---|
| 7137 | * // => []
|
|---|
| 7138 | *
|
|---|
| 7139 | * _.drop([1, 2, 3], 0);
|
|---|
| 7140 | * // => [1, 2, 3]
|
|---|
| 7141 | */
|
|---|
| 7142 | function drop(array, n, guard) {
|
|---|
| 7143 | var length = array == null ? 0 : array.length;
|
|---|
| 7144 | if (!length) {
|
|---|
| 7145 | return [];
|
|---|
| 7146 | }
|
|---|
| 7147 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
|---|
| 7148 | return baseSlice(array, n < 0 ? 0 : n, length);
|
|---|
| 7149 | }
|
|---|
| 7150 |
|
|---|
| 7151 | /**
|
|---|
| 7152 | * Creates a slice of `array` with `n` elements dropped from the end.
|
|---|
| 7153 | *
|
|---|
| 7154 | * @static
|
|---|
| 7155 | * @memberOf _
|
|---|
| 7156 | * @since 3.0.0
|
|---|
| 7157 | * @category Array
|
|---|
| 7158 | * @param {Array} array The array to query.
|
|---|
| 7159 | * @param {number} [n=1] The number of elements to drop.
|
|---|
| 7160 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 7161 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 7162 | * @example
|
|---|
| 7163 | *
|
|---|
| 7164 | * _.dropRight([1, 2, 3]);
|
|---|
| 7165 | * // => [1, 2]
|
|---|
| 7166 | *
|
|---|
| 7167 | * _.dropRight([1, 2, 3], 2);
|
|---|
| 7168 | * // => [1]
|
|---|
| 7169 | *
|
|---|
| 7170 | * _.dropRight([1, 2, 3], 5);
|
|---|
| 7171 | * // => []
|
|---|
| 7172 | *
|
|---|
| 7173 | * _.dropRight([1, 2, 3], 0);
|
|---|
| 7174 | * // => [1, 2, 3]
|
|---|
| 7175 | */
|
|---|
| 7176 | function dropRight(array, n, guard) {
|
|---|
| 7177 | var length = array == null ? 0 : array.length;
|
|---|
| 7178 | if (!length) {
|
|---|
| 7179 | return [];
|
|---|
| 7180 | }
|
|---|
| 7181 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
|---|
| 7182 | n = length - n;
|
|---|
| 7183 | return baseSlice(array, 0, n < 0 ? 0 : n);
|
|---|
| 7184 | }
|
|---|
| 7185 |
|
|---|
| 7186 | /**
|
|---|
| 7187 | * Creates a slice of `array` excluding elements dropped from the end.
|
|---|
| 7188 | * Elements are dropped until `predicate` returns falsey. The predicate is
|
|---|
| 7189 | * invoked with three arguments: (value, index, array).
|
|---|
| 7190 | *
|
|---|
| 7191 | * @static
|
|---|
| 7192 | * @memberOf _
|
|---|
| 7193 | * @since 3.0.0
|
|---|
| 7194 | * @category Array
|
|---|
| 7195 | * @param {Array} array The array to query.
|
|---|
| 7196 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 7197 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 7198 | * @example
|
|---|
| 7199 | *
|
|---|
| 7200 | * var users = [
|
|---|
| 7201 | * { 'user': 'barney', 'active': true },
|
|---|
| 7202 | * { 'user': 'fred', 'active': false },
|
|---|
| 7203 | * { 'user': 'pebbles', 'active': false }
|
|---|
| 7204 | * ];
|
|---|
| 7205 | *
|
|---|
| 7206 | * _.dropRightWhile(users, function(o) { return !o.active; });
|
|---|
| 7207 | * // => objects for ['barney']
|
|---|
| 7208 | *
|
|---|
| 7209 | * // The `_.matches` iteratee shorthand.
|
|---|
| 7210 | * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
|
|---|
| 7211 | * // => objects for ['barney', 'fred']
|
|---|
| 7212 | *
|
|---|
| 7213 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 7214 | * _.dropRightWhile(users, ['active', false]);
|
|---|
| 7215 | * // => objects for ['barney']
|
|---|
| 7216 | *
|
|---|
| 7217 | * // The `_.property` iteratee shorthand.
|
|---|
| 7218 | * _.dropRightWhile(users, 'active');
|
|---|
| 7219 | * // => objects for ['barney', 'fred', 'pebbles']
|
|---|
| 7220 | */
|
|---|
| 7221 | function dropRightWhile(array, predicate) {
|
|---|
| 7222 | return (array && array.length)
|
|---|
| 7223 | ? baseWhile(array, getIteratee(predicate, 3), true, true)
|
|---|
| 7224 | : [];
|
|---|
| 7225 | }
|
|---|
| 7226 |
|
|---|
| 7227 | /**
|
|---|
| 7228 | * Creates a slice of `array` excluding elements dropped from the beginning.
|
|---|
| 7229 | * Elements are dropped until `predicate` returns falsey. The predicate is
|
|---|
| 7230 | * invoked with three arguments: (value, index, array).
|
|---|
| 7231 | *
|
|---|
| 7232 | * @static
|
|---|
| 7233 | * @memberOf _
|
|---|
| 7234 | * @since 3.0.0
|
|---|
| 7235 | * @category Array
|
|---|
| 7236 | * @param {Array} array The array to query.
|
|---|
| 7237 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 7238 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 7239 | * @example
|
|---|
| 7240 | *
|
|---|
| 7241 | * var users = [
|
|---|
| 7242 | * { 'user': 'barney', 'active': false },
|
|---|
| 7243 | * { 'user': 'fred', 'active': false },
|
|---|
| 7244 | * { 'user': 'pebbles', 'active': true }
|
|---|
| 7245 | * ];
|
|---|
| 7246 | *
|
|---|
| 7247 | * _.dropWhile(users, function(o) { return !o.active; });
|
|---|
| 7248 | * // => objects for ['pebbles']
|
|---|
| 7249 | *
|
|---|
| 7250 | * // The `_.matches` iteratee shorthand.
|
|---|
| 7251 | * _.dropWhile(users, { 'user': 'barney', 'active': false });
|
|---|
| 7252 | * // => objects for ['fred', 'pebbles']
|
|---|
| 7253 | *
|
|---|
| 7254 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 7255 | * _.dropWhile(users, ['active', false]);
|
|---|
| 7256 | * // => objects for ['pebbles']
|
|---|
| 7257 | *
|
|---|
| 7258 | * // The `_.property` iteratee shorthand.
|
|---|
| 7259 | * _.dropWhile(users, 'active');
|
|---|
| 7260 | * // => objects for ['barney', 'fred', 'pebbles']
|
|---|
| 7261 | */
|
|---|
| 7262 | function dropWhile(array, predicate) {
|
|---|
| 7263 | return (array && array.length)
|
|---|
| 7264 | ? baseWhile(array, getIteratee(predicate, 3), true)
|
|---|
| 7265 | : [];
|
|---|
| 7266 | }
|
|---|
| 7267 |
|
|---|
| 7268 | /**
|
|---|
| 7269 | * Fills elements of `array` with `value` from `start` up to, but not
|
|---|
| 7270 | * including, `end`.
|
|---|
| 7271 | *
|
|---|
| 7272 | * **Note:** This method mutates `array`.
|
|---|
| 7273 | *
|
|---|
| 7274 | * @static
|
|---|
| 7275 | * @memberOf _
|
|---|
| 7276 | * @since 3.2.0
|
|---|
| 7277 | * @category Array
|
|---|
| 7278 | * @param {Array} array The array to fill.
|
|---|
| 7279 | * @param {*} value The value to fill `array` with.
|
|---|
| 7280 | * @param {number} [start=0] The start position.
|
|---|
| 7281 | * @param {number} [end=array.length] The end position.
|
|---|
| 7282 | * @returns {Array} Returns `array`.
|
|---|
| 7283 | * @example
|
|---|
| 7284 | *
|
|---|
| 7285 | * var array = [1, 2, 3];
|
|---|
| 7286 | *
|
|---|
| 7287 | * _.fill(array, 'a');
|
|---|
| 7288 | * console.log(array);
|
|---|
| 7289 | * // => ['a', 'a', 'a']
|
|---|
| 7290 | *
|
|---|
| 7291 | * _.fill(Array(3), 2);
|
|---|
| 7292 | * // => [2, 2, 2]
|
|---|
| 7293 | *
|
|---|
| 7294 | * _.fill([4, 6, 8, 10], '*', 1, 3);
|
|---|
| 7295 | * // => [4, '*', '*', 10]
|
|---|
| 7296 | */
|
|---|
| 7297 | function fill(array, value, start, end) {
|
|---|
| 7298 | var length = array == null ? 0 : array.length;
|
|---|
| 7299 | if (!length) {
|
|---|
| 7300 | return [];
|
|---|
| 7301 | }
|
|---|
| 7302 | if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
|
|---|
| 7303 | start = 0;
|
|---|
| 7304 | end = length;
|
|---|
| 7305 | }
|
|---|
| 7306 | return baseFill(array, value, start, end);
|
|---|
| 7307 | }
|
|---|
| 7308 |
|
|---|
| 7309 | /**
|
|---|
| 7310 | * This method is like `_.find` except that it returns the index of the first
|
|---|
| 7311 | * element `predicate` returns truthy for instead of the element itself.
|
|---|
| 7312 | *
|
|---|
| 7313 | * @static
|
|---|
| 7314 | * @memberOf _
|
|---|
| 7315 | * @since 1.1.0
|
|---|
| 7316 | * @category Array
|
|---|
| 7317 | * @param {Array} array The array to inspect.
|
|---|
| 7318 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 7319 | * @param {number} [fromIndex=0] The index to search from.
|
|---|
| 7320 | * @returns {number} Returns the index of the found element, else `-1`.
|
|---|
| 7321 | * @example
|
|---|
| 7322 | *
|
|---|
| 7323 | * var users = [
|
|---|
| 7324 | * { 'user': 'barney', 'active': false },
|
|---|
| 7325 | * { 'user': 'fred', 'active': false },
|
|---|
| 7326 | * { 'user': 'pebbles', 'active': true }
|
|---|
| 7327 | * ];
|
|---|
| 7328 | *
|
|---|
| 7329 | * _.findIndex(users, function(o) { return o.user == 'barney'; });
|
|---|
| 7330 | * // => 0
|
|---|
| 7331 | *
|
|---|
| 7332 | * // The `_.matches` iteratee shorthand.
|
|---|
| 7333 | * _.findIndex(users, { 'user': 'fred', 'active': false });
|
|---|
| 7334 | * // => 1
|
|---|
| 7335 | *
|
|---|
| 7336 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 7337 | * _.findIndex(users, ['active', false]);
|
|---|
| 7338 | * // => 0
|
|---|
| 7339 | *
|
|---|
| 7340 | * // The `_.property` iteratee shorthand.
|
|---|
| 7341 | * _.findIndex(users, 'active');
|
|---|
| 7342 | * // => 2
|
|---|
| 7343 | */
|
|---|
| 7344 | function findIndex(array, predicate, fromIndex) {
|
|---|
| 7345 | var length = array == null ? 0 : array.length;
|
|---|
| 7346 | if (!length) {
|
|---|
| 7347 | return -1;
|
|---|
| 7348 | }
|
|---|
| 7349 | var index = fromIndex == null ? 0 : toInteger(fromIndex);
|
|---|
| 7350 | if (index < 0) {
|
|---|
| 7351 | index = nativeMax(length + index, 0);
|
|---|
| 7352 | }
|
|---|
| 7353 | return baseFindIndex(array, getIteratee(predicate, 3), index);
|
|---|
| 7354 | }
|
|---|
| 7355 |
|
|---|
| 7356 | /**
|
|---|
| 7357 | * This method is like `_.findIndex` except that it iterates over elements
|
|---|
| 7358 | * of `collection` from right to left.
|
|---|
| 7359 | *
|
|---|
| 7360 | * @static
|
|---|
| 7361 | * @memberOf _
|
|---|
| 7362 | * @since 2.0.0
|
|---|
| 7363 | * @category Array
|
|---|
| 7364 | * @param {Array} array The array to inspect.
|
|---|
| 7365 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 7366 | * @param {number} [fromIndex=array.length-1] The index to search from.
|
|---|
| 7367 | * @returns {number} Returns the index of the found element, else `-1`.
|
|---|
| 7368 | * @example
|
|---|
| 7369 | *
|
|---|
| 7370 | * var users = [
|
|---|
| 7371 | * { 'user': 'barney', 'active': true },
|
|---|
| 7372 | * { 'user': 'fred', 'active': false },
|
|---|
| 7373 | * { 'user': 'pebbles', 'active': false }
|
|---|
| 7374 | * ];
|
|---|
| 7375 | *
|
|---|
| 7376 | * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
|
|---|
| 7377 | * // => 2
|
|---|
| 7378 | *
|
|---|
| 7379 | * // The `_.matches` iteratee shorthand.
|
|---|
| 7380 | * _.findLastIndex(users, { 'user': 'barney', 'active': true });
|
|---|
| 7381 | * // => 0
|
|---|
| 7382 | *
|
|---|
| 7383 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 7384 | * _.findLastIndex(users, ['active', false]);
|
|---|
| 7385 | * // => 2
|
|---|
| 7386 | *
|
|---|
| 7387 | * // The `_.property` iteratee shorthand.
|
|---|
| 7388 | * _.findLastIndex(users, 'active');
|
|---|
| 7389 | * // => 0
|
|---|
| 7390 | */
|
|---|
| 7391 | function findLastIndex(array, predicate, fromIndex) {
|
|---|
| 7392 | var length = array == null ? 0 : array.length;
|
|---|
| 7393 | if (!length) {
|
|---|
| 7394 | return -1;
|
|---|
| 7395 | }
|
|---|
| 7396 | var index = length - 1;
|
|---|
| 7397 | if (fromIndex !== undefined) {
|
|---|
| 7398 | index = toInteger(fromIndex);
|
|---|
| 7399 | index = fromIndex < 0
|
|---|
| 7400 | ? nativeMax(length + index, 0)
|
|---|
| 7401 | : nativeMin(index, length - 1);
|
|---|
| 7402 | }
|
|---|
| 7403 | return baseFindIndex(array, getIteratee(predicate, 3), index, true);
|
|---|
| 7404 | }
|
|---|
| 7405 |
|
|---|
| 7406 | /**
|
|---|
| 7407 | * Flattens `array` a single level deep.
|
|---|
| 7408 | *
|
|---|
| 7409 | * @static
|
|---|
| 7410 | * @memberOf _
|
|---|
| 7411 | * @since 0.1.0
|
|---|
| 7412 | * @category Array
|
|---|
| 7413 | * @param {Array} array The array to flatten.
|
|---|
| 7414 | * @returns {Array} Returns the new flattened array.
|
|---|
| 7415 | * @example
|
|---|
| 7416 | *
|
|---|
| 7417 | * _.flatten([1, [2, [3, [4]], 5]]);
|
|---|
| 7418 | * // => [1, 2, [3, [4]], 5]
|
|---|
| 7419 | */
|
|---|
| 7420 | function flatten(array) {
|
|---|
| 7421 | var length = array == null ? 0 : array.length;
|
|---|
| 7422 | return length ? baseFlatten(array, 1) : [];
|
|---|
| 7423 | }
|
|---|
| 7424 |
|
|---|
| 7425 | /**
|
|---|
| 7426 | * Recursively flattens `array`.
|
|---|
| 7427 | *
|
|---|
| 7428 | * @static
|
|---|
| 7429 | * @memberOf _
|
|---|
| 7430 | * @since 3.0.0
|
|---|
| 7431 | * @category Array
|
|---|
| 7432 | * @param {Array} array The array to flatten.
|
|---|
| 7433 | * @returns {Array} Returns the new flattened array.
|
|---|
| 7434 | * @example
|
|---|
| 7435 | *
|
|---|
| 7436 | * _.flattenDeep([1, [2, [3, [4]], 5]]);
|
|---|
| 7437 | * // => [1, 2, 3, 4, 5]
|
|---|
| 7438 | */
|
|---|
| 7439 | function flattenDeep(array) {
|
|---|
| 7440 | var length = array == null ? 0 : array.length;
|
|---|
| 7441 | return length ? baseFlatten(array, INFINITY) : [];
|
|---|
| 7442 | }
|
|---|
| 7443 |
|
|---|
| 7444 | /**
|
|---|
| 7445 | * Recursively flatten `array` up to `depth` times.
|
|---|
| 7446 | *
|
|---|
| 7447 | * @static
|
|---|
| 7448 | * @memberOf _
|
|---|
| 7449 | * @since 4.4.0
|
|---|
| 7450 | * @category Array
|
|---|
| 7451 | * @param {Array} array The array to flatten.
|
|---|
| 7452 | * @param {number} [depth=1] The maximum recursion depth.
|
|---|
| 7453 | * @returns {Array} Returns the new flattened array.
|
|---|
| 7454 | * @example
|
|---|
| 7455 | *
|
|---|
| 7456 | * var array = [1, [2, [3, [4]], 5]];
|
|---|
| 7457 | *
|
|---|
| 7458 | * _.flattenDepth(array, 1);
|
|---|
| 7459 | * // => [1, 2, [3, [4]], 5]
|
|---|
| 7460 | *
|
|---|
| 7461 | * _.flattenDepth(array, 2);
|
|---|
| 7462 | * // => [1, 2, 3, [4], 5]
|
|---|
| 7463 | */
|
|---|
| 7464 | function flattenDepth(array, depth) {
|
|---|
| 7465 | var length = array == null ? 0 : array.length;
|
|---|
| 7466 | if (!length) {
|
|---|
| 7467 | return [];
|
|---|
| 7468 | }
|
|---|
| 7469 | depth = depth === undefined ? 1 : toInteger(depth);
|
|---|
| 7470 | return baseFlatten(array, depth);
|
|---|
| 7471 | }
|
|---|
| 7472 |
|
|---|
| 7473 | /**
|
|---|
| 7474 | * The inverse of `_.toPairs`; this method returns an object composed
|
|---|
| 7475 | * from key-value `pairs`.
|
|---|
| 7476 | *
|
|---|
| 7477 | * @static
|
|---|
| 7478 | * @memberOf _
|
|---|
| 7479 | * @since 4.0.0
|
|---|
| 7480 | * @category Array
|
|---|
| 7481 | * @param {Array} pairs The key-value pairs.
|
|---|
| 7482 | * @returns {Object} Returns the new object.
|
|---|
| 7483 | * @example
|
|---|
| 7484 | *
|
|---|
| 7485 | * _.fromPairs([['a', 1], ['b', 2]]);
|
|---|
| 7486 | * // => { 'a': 1, 'b': 2 }
|
|---|
| 7487 | */
|
|---|
| 7488 | function fromPairs(pairs) {
|
|---|
| 7489 | var index = -1,
|
|---|
| 7490 | length = pairs == null ? 0 : pairs.length,
|
|---|
| 7491 | result = {};
|
|---|
| 7492 |
|
|---|
| 7493 | while (++index < length) {
|
|---|
| 7494 | var pair = pairs[index];
|
|---|
| 7495 | baseAssignValue(result, pair[0], pair[1]);
|
|---|
| 7496 | }
|
|---|
| 7497 | return result;
|
|---|
| 7498 | }
|
|---|
| 7499 |
|
|---|
| 7500 | /**
|
|---|
| 7501 | * Gets the first element of `array`.
|
|---|
| 7502 | *
|
|---|
| 7503 | * @static
|
|---|
| 7504 | * @memberOf _
|
|---|
| 7505 | * @since 0.1.0
|
|---|
| 7506 | * @alias first
|
|---|
| 7507 | * @category Array
|
|---|
| 7508 | * @param {Array} array The array to query.
|
|---|
| 7509 | * @returns {*} Returns the first element of `array`.
|
|---|
| 7510 | * @example
|
|---|
| 7511 | *
|
|---|
| 7512 | * _.head([1, 2, 3]);
|
|---|
| 7513 | * // => 1
|
|---|
| 7514 | *
|
|---|
| 7515 | * _.head([]);
|
|---|
| 7516 | * // => undefined
|
|---|
| 7517 | */
|
|---|
| 7518 | function head(array) {
|
|---|
| 7519 | return (array && array.length) ? array[0] : undefined;
|
|---|
| 7520 | }
|
|---|
| 7521 |
|
|---|
| 7522 | /**
|
|---|
| 7523 | * Gets the index at which the first occurrence of `value` is found in `array`
|
|---|
| 7524 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 7525 | * for equality comparisons. If `fromIndex` is negative, it's used as the
|
|---|
| 7526 | * offset from the end of `array`.
|
|---|
| 7527 | *
|
|---|
| 7528 | * @static
|
|---|
| 7529 | * @memberOf _
|
|---|
| 7530 | * @since 0.1.0
|
|---|
| 7531 | * @category Array
|
|---|
| 7532 | * @param {Array} array The array to inspect.
|
|---|
| 7533 | * @param {*} value The value to search for.
|
|---|
| 7534 | * @param {number} [fromIndex=0] The index to search from.
|
|---|
| 7535 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 7536 | * @example
|
|---|
| 7537 | *
|
|---|
| 7538 | * _.indexOf([1, 2, 1, 2], 2);
|
|---|
| 7539 | * // => 1
|
|---|
| 7540 | *
|
|---|
| 7541 | * // Search from the `fromIndex`.
|
|---|
| 7542 | * _.indexOf([1, 2, 1, 2], 2, 2);
|
|---|
| 7543 | * // => 3
|
|---|
| 7544 | */
|
|---|
| 7545 | function indexOf(array, value, fromIndex) {
|
|---|
| 7546 | var length = array == null ? 0 : array.length;
|
|---|
| 7547 | if (!length) {
|
|---|
| 7548 | return -1;
|
|---|
| 7549 | }
|
|---|
| 7550 | var index = fromIndex == null ? 0 : toInteger(fromIndex);
|
|---|
| 7551 | if (index < 0) {
|
|---|
| 7552 | index = nativeMax(length + index, 0);
|
|---|
| 7553 | }
|
|---|
| 7554 | return baseIndexOf(array, value, index);
|
|---|
| 7555 | }
|
|---|
| 7556 |
|
|---|
| 7557 | /**
|
|---|
| 7558 | * Gets all but the last element of `array`.
|
|---|
| 7559 | *
|
|---|
| 7560 | * @static
|
|---|
| 7561 | * @memberOf _
|
|---|
| 7562 | * @since 0.1.0
|
|---|
| 7563 | * @category Array
|
|---|
| 7564 | * @param {Array} array The array to query.
|
|---|
| 7565 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 7566 | * @example
|
|---|
| 7567 | *
|
|---|
| 7568 | * _.initial([1, 2, 3]);
|
|---|
| 7569 | * // => [1, 2]
|
|---|
| 7570 | */
|
|---|
| 7571 | function initial(array) {
|
|---|
| 7572 | var length = array == null ? 0 : array.length;
|
|---|
| 7573 | return length ? baseSlice(array, 0, -1) : [];
|
|---|
| 7574 | }
|
|---|
| 7575 |
|
|---|
| 7576 | /**
|
|---|
| 7577 | * Creates an array of unique values that are included in all given arrays
|
|---|
| 7578 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 7579 | * for equality comparisons. The order and references of result values are
|
|---|
| 7580 | * determined by the first array.
|
|---|
| 7581 | *
|
|---|
| 7582 | * @static
|
|---|
| 7583 | * @memberOf _
|
|---|
| 7584 | * @since 0.1.0
|
|---|
| 7585 | * @category Array
|
|---|
| 7586 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 7587 | * @returns {Array} Returns the new array of intersecting values.
|
|---|
| 7588 | * @example
|
|---|
| 7589 | *
|
|---|
| 7590 | * _.intersection([2, 1], [2, 3]);
|
|---|
| 7591 | * // => [2]
|
|---|
| 7592 | */
|
|---|
| 7593 | var intersection = baseRest(function(arrays) {
|
|---|
| 7594 | var mapped = arrayMap(arrays, castArrayLikeObject);
|
|---|
| 7595 | return (mapped.length && mapped[0] === arrays[0])
|
|---|
| 7596 | ? baseIntersection(mapped)
|
|---|
| 7597 | : [];
|
|---|
| 7598 | });
|
|---|
| 7599 |
|
|---|
| 7600 | /**
|
|---|
| 7601 | * This method is like `_.intersection` except that it accepts `iteratee`
|
|---|
| 7602 | * which is invoked for each element of each `arrays` to generate the criterion
|
|---|
| 7603 | * by which they're compared. The order and references of result values are
|
|---|
| 7604 | * determined by the first array. The iteratee is invoked with one argument:
|
|---|
| 7605 | * (value).
|
|---|
| 7606 | *
|
|---|
| 7607 | * @static
|
|---|
| 7608 | * @memberOf _
|
|---|
| 7609 | * @since 4.0.0
|
|---|
| 7610 | * @category Array
|
|---|
| 7611 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 7612 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 7613 | * @returns {Array} Returns the new array of intersecting values.
|
|---|
| 7614 | * @example
|
|---|
| 7615 | *
|
|---|
| 7616 | * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
|---|
| 7617 | * // => [2.1]
|
|---|
| 7618 | *
|
|---|
| 7619 | * // The `_.property` iteratee shorthand.
|
|---|
| 7620 | * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
|---|
| 7621 | * // => [{ 'x': 1 }]
|
|---|
| 7622 | */
|
|---|
| 7623 | var intersectionBy = baseRest(function(arrays) {
|
|---|
| 7624 | var iteratee = last(arrays),
|
|---|
| 7625 | mapped = arrayMap(arrays, castArrayLikeObject);
|
|---|
| 7626 |
|
|---|
| 7627 | if (iteratee === last(mapped)) {
|
|---|
| 7628 | iteratee = undefined;
|
|---|
| 7629 | } else {
|
|---|
| 7630 | mapped.pop();
|
|---|
| 7631 | }
|
|---|
| 7632 | return (mapped.length && mapped[0] === arrays[0])
|
|---|
| 7633 | ? baseIntersection(mapped, getIteratee(iteratee, 2))
|
|---|
| 7634 | : [];
|
|---|
| 7635 | });
|
|---|
| 7636 |
|
|---|
| 7637 | /**
|
|---|
| 7638 | * This method is like `_.intersection` except that it accepts `comparator`
|
|---|
| 7639 | * which is invoked to compare elements of `arrays`. The order and references
|
|---|
| 7640 | * of result values are determined by the first array. The comparator is
|
|---|
| 7641 | * invoked with two arguments: (arrVal, othVal).
|
|---|
| 7642 | *
|
|---|
| 7643 | * @static
|
|---|
| 7644 | * @memberOf _
|
|---|
| 7645 | * @since 4.0.0
|
|---|
| 7646 | * @category Array
|
|---|
| 7647 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 7648 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 7649 | * @returns {Array} Returns the new array of intersecting values.
|
|---|
| 7650 | * @example
|
|---|
| 7651 | *
|
|---|
| 7652 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
|---|
| 7653 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
|---|
| 7654 | *
|
|---|
| 7655 | * _.intersectionWith(objects, others, _.isEqual);
|
|---|
| 7656 | * // => [{ 'x': 1, 'y': 2 }]
|
|---|
| 7657 | */
|
|---|
| 7658 | var intersectionWith = baseRest(function(arrays) {
|
|---|
| 7659 | var comparator = last(arrays),
|
|---|
| 7660 | mapped = arrayMap(arrays, castArrayLikeObject);
|
|---|
| 7661 |
|
|---|
| 7662 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
|---|
| 7663 | if (comparator) {
|
|---|
| 7664 | mapped.pop();
|
|---|
| 7665 | }
|
|---|
| 7666 | return (mapped.length && mapped[0] === arrays[0])
|
|---|
| 7667 | ? baseIntersection(mapped, undefined, comparator)
|
|---|
| 7668 | : [];
|
|---|
| 7669 | });
|
|---|
| 7670 |
|
|---|
| 7671 | /**
|
|---|
| 7672 | * Converts all elements in `array` into a string separated by `separator`.
|
|---|
| 7673 | *
|
|---|
| 7674 | * @static
|
|---|
| 7675 | * @memberOf _
|
|---|
| 7676 | * @since 4.0.0
|
|---|
| 7677 | * @category Array
|
|---|
| 7678 | * @param {Array} array The array to convert.
|
|---|
| 7679 | * @param {string} [separator=','] The element separator.
|
|---|
| 7680 | * @returns {string} Returns the joined string.
|
|---|
| 7681 | * @example
|
|---|
| 7682 | *
|
|---|
| 7683 | * _.join(['a', 'b', 'c'], '~');
|
|---|
| 7684 | * // => 'a~b~c'
|
|---|
| 7685 | */
|
|---|
| 7686 | function join(array, separator) {
|
|---|
| 7687 | return array == null ? '' : nativeJoin.call(array, separator);
|
|---|
| 7688 | }
|
|---|
| 7689 |
|
|---|
| 7690 | /**
|
|---|
| 7691 | * Gets the last element of `array`.
|
|---|
| 7692 | *
|
|---|
| 7693 | * @static
|
|---|
| 7694 | * @memberOf _
|
|---|
| 7695 | * @since 0.1.0
|
|---|
| 7696 | * @category Array
|
|---|
| 7697 | * @param {Array} array The array to query.
|
|---|
| 7698 | * @returns {*} Returns the last element of `array`.
|
|---|
| 7699 | * @example
|
|---|
| 7700 | *
|
|---|
| 7701 | * _.last([1, 2, 3]);
|
|---|
| 7702 | * // => 3
|
|---|
| 7703 | */
|
|---|
| 7704 | function last(array) {
|
|---|
| 7705 | var length = array == null ? 0 : array.length;
|
|---|
| 7706 | return length ? array[length - 1] : undefined;
|
|---|
| 7707 | }
|
|---|
| 7708 |
|
|---|
| 7709 | /**
|
|---|
| 7710 | * This method is like `_.indexOf` except that it iterates over elements of
|
|---|
| 7711 | * `array` from right to left.
|
|---|
| 7712 | *
|
|---|
| 7713 | * @static
|
|---|
| 7714 | * @memberOf _
|
|---|
| 7715 | * @since 0.1.0
|
|---|
| 7716 | * @category Array
|
|---|
| 7717 | * @param {Array} array The array to inspect.
|
|---|
| 7718 | * @param {*} value The value to search for.
|
|---|
| 7719 | * @param {number} [fromIndex=array.length-1] The index to search from.
|
|---|
| 7720 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 7721 | * @example
|
|---|
| 7722 | *
|
|---|
| 7723 | * _.lastIndexOf([1, 2, 1, 2], 2);
|
|---|
| 7724 | * // => 3
|
|---|
| 7725 | *
|
|---|
| 7726 | * // Search from the `fromIndex`.
|
|---|
| 7727 | * _.lastIndexOf([1, 2, 1, 2], 2, 2);
|
|---|
| 7728 | * // => 1
|
|---|
| 7729 | */
|
|---|
| 7730 | function lastIndexOf(array, value, fromIndex) {
|
|---|
| 7731 | var length = array == null ? 0 : array.length;
|
|---|
| 7732 | if (!length) {
|
|---|
| 7733 | return -1;
|
|---|
| 7734 | }
|
|---|
| 7735 | var index = length;
|
|---|
| 7736 | if (fromIndex !== undefined) {
|
|---|
| 7737 | index = toInteger(fromIndex);
|
|---|
| 7738 | index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
|
|---|
| 7739 | }
|
|---|
| 7740 | return value === value
|
|---|
| 7741 | ? strictLastIndexOf(array, value, index)
|
|---|
| 7742 | : baseFindIndex(array, baseIsNaN, index, true);
|
|---|
| 7743 | }
|
|---|
| 7744 |
|
|---|
| 7745 | /**
|
|---|
| 7746 | * Gets the element at index `n` of `array`. If `n` is negative, the nth
|
|---|
| 7747 | * element from the end is returned.
|
|---|
| 7748 | *
|
|---|
| 7749 | * @static
|
|---|
| 7750 | * @memberOf _
|
|---|
| 7751 | * @since 4.11.0
|
|---|
| 7752 | * @category Array
|
|---|
| 7753 | * @param {Array} array The array to query.
|
|---|
| 7754 | * @param {number} [n=0] The index of the element to return.
|
|---|
| 7755 | * @returns {*} Returns the nth element of `array`.
|
|---|
| 7756 | * @example
|
|---|
| 7757 | *
|
|---|
| 7758 | * var array = ['a', 'b', 'c', 'd'];
|
|---|
| 7759 | *
|
|---|
| 7760 | * _.nth(array, 1);
|
|---|
| 7761 | * // => 'b'
|
|---|
| 7762 | *
|
|---|
| 7763 | * _.nth(array, -2);
|
|---|
| 7764 | * // => 'c';
|
|---|
| 7765 | */
|
|---|
| 7766 | function nth(array, n) {
|
|---|
| 7767 | return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
|
|---|
| 7768 | }
|
|---|
| 7769 |
|
|---|
| 7770 | /**
|
|---|
| 7771 | * Removes all given values from `array` using
|
|---|
| 7772 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 7773 | * for equality comparisons.
|
|---|
| 7774 | *
|
|---|
| 7775 | * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
|
|---|
| 7776 | * to remove elements from an array by predicate.
|
|---|
| 7777 | *
|
|---|
| 7778 | * @static
|
|---|
| 7779 | * @memberOf _
|
|---|
| 7780 | * @since 2.0.0
|
|---|
| 7781 | * @category Array
|
|---|
| 7782 | * @param {Array} array The array to modify.
|
|---|
| 7783 | * @param {...*} [values] The values to remove.
|
|---|
| 7784 | * @returns {Array} Returns `array`.
|
|---|
| 7785 | * @example
|
|---|
| 7786 | *
|
|---|
| 7787 | * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
|
|---|
| 7788 | *
|
|---|
| 7789 | * _.pull(array, 'a', 'c');
|
|---|
| 7790 | * console.log(array);
|
|---|
| 7791 | * // => ['b', 'b']
|
|---|
| 7792 | */
|
|---|
| 7793 | var pull = baseRest(pullAll);
|
|---|
| 7794 |
|
|---|
| 7795 | /**
|
|---|
| 7796 | * This method is like `_.pull` except that it accepts an array of values to remove.
|
|---|
| 7797 | *
|
|---|
| 7798 | * **Note:** Unlike `_.difference`, this method mutates `array`.
|
|---|
| 7799 | *
|
|---|
| 7800 | * @static
|
|---|
| 7801 | * @memberOf _
|
|---|
| 7802 | * @since 4.0.0
|
|---|
| 7803 | * @category Array
|
|---|
| 7804 | * @param {Array} array The array to modify.
|
|---|
| 7805 | * @param {Array} values The values to remove.
|
|---|
| 7806 | * @returns {Array} Returns `array`.
|
|---|
| 7807 | * @example
|
|---|
| 7808 | *
|
|---|
| 7809 | * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
|
|---|
| 7810 | *
|
|---|
| 7811 | * _.pullAll(array, ['a', 'c']);
|
|---|
| 7812 | * console.log(array);
|
|---|
| 7813 | * // => ['b', 'b']
|
|---|
| 7814 | */
|
|---|
| 7815 | function pullAll(array, values) {
|
|---|
| 7816 | return (array && array.length && values && values.length)
|
|---|
| 7817 | ? basePullAll(array, values)
|
|---|
| 7818 | : array;
|
|---|
| 7819 | }
|
|---|
| 7820 |
|
|---|
| 7821 | /**
|
|---|
| 7822 | * This method is like `_.pullAll` except that it accepts `iteratee` which is
|
|---|
| 7823 | * invoked for each element of `array` and `values` to generate the criterion
|
|---|
| 7824 | * by which they're compared. The iteratee is invoked with one argument: (value).
|
|---|
| 7825 | *
|
|---|
| 7826 | * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
|
|---|
| 7827 | *
|
|---|
| 7828 | * @static
|
|---|
| 7829 | * @memberOf _
|
|---|
| 7830 | * @since 4.0.0
|
|---|
| 7831 | * @category Array
|
|---|
| 7832 | * @param {Array} array The array to modify.
|
|---|
| 7833 | * @param {Array} values The values to remove.
|
|---|
| 7834 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 7835 | * @returns {Array} Returns `array`.
|
|---|
| 7836 | * @example
|
|---|
| 7837 | *
|
|---|
| 7838 | * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
|
|---|
| 7839 | *
|
|---|
| 7840 | * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
|
|---|
| 7841 | * console.log(array);
|
|---|
| 7842 | * // => [{ 'x': 2 }]
|
|---|
| 7843 | */
|
|---|
| 7844 | function pullAllBy(array, values, iteratee) {
|
|---|
| 7845 | return (array && array.length && values && values.length)
|
|---|
| 7846 | ? basePullAll(array, values, getIteratee(iteratee, 2))
|
|---|
| 7847 | : array;
|
|---|
| 7848 | }
|
|---|
| 7849 |
|
|---|
| 7850 | /**
|
|---|
| 7851 | * This method is like `_.pullAll` except that it accepts `comparator` which
|
|---|
| 7852 | * is invoked to compare elements of `array` to `values`. The comparator is
|
|---|
| 7853 | * invoked with two arguments: (arrVal, othVal).
|
|---|
| 7854 | *
|
|---|
| 7855 | * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
|
|---|
| 7856 | *
|
|---|
| 7857 | * @static
|
|---|
| 7858 | * @memberOf _
|
|---|
| 7859 | * @since 4.6.0
|
|---|
| 7860 | * @category Array
|
|---|
| 7861 | * @param {Array} array The array to modify.
|
|---|
| 7862 | * @param {Array} values The values to remove.
|
|---|
| 7863 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 7864 | * @returns {Array} Returns `array`.
|
|---|
| 7865 | * @example
|
|---|
| 7866 | *
|
|---|
| 7867 | * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
|
|---|
| 7868 | *
|
|---|
| 7869 | * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
|
|---|
| 7870 | * console.log(array);
|
|---|
| 7871 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
|
|---|
| 7872 | */
|
|---|
| 7873 | function pullAllWith(array, values, comparator) {
|
|---|
| 7874 | return (array && array.length && values && values.length)
|
|---|
| 7875 | ? basePullAll(array, values, undefined, comparator)
|
|---|
| 7876 | : array;
|
|---|
| 7877 | }
|
|---|
| 7878 |
|
|---|
| 7879 | /**
|
|---|
| 7880 | * Removes elements from `array` corresponding to `indexes` and returns an
|
|---|
| 7881 | * array of removed elements.
|
|---|
| 7882 | *
|
|---|
| 7883 | * **Note:** Unlike `_.at`, this method mutates `array`.
|
|---|
| 7884 | *
|
|---|
| 7885 | * @static
|
|---|
| 7886 | * @memberOf _
|
|---|
| 7887 | * @since 3.0.0
|
|---|
| 7888 | * @category Array
|
|---|
| 7889 | * @param {Array} array The array to modify.
|
|---|
| 7890 | * @param {...(number|number[])} [indexes] The indexes of elements to remove.
|
|---|
| 7891 | * @returns {Array} Returns the new array of removed elements.
|
|---|
| 7892 | * @example
|
|---|
| 7893 | *
|
|---|
| 7894 | * var array = ['a', 'b', 'c', 'd'];
|
|---|
| 7895 | * var pulled = _.pullAt(array, [1, 3]);
|
|---|
| 7896 | *
|
|---|
| 7897 | * console.log(array);
|
|---|
| 7898 | * // => ['a', 'c']
|
|---|
| 7899 | *
|
|---|
| 7900 | * console.log(pulled);
|
|---|
| 7901 | * // => ['b', 'd']
|
|---|
| 7902 | */
|
|---|
| 7903 | var pullAt = flatRest(function(array, indexes) {
|
|---|
| 7904 | var length = array == null ? 0 : array.length,
|
|---|
| 7905 | result = baseAt(array, indexes);
|
|---|
| 7906 |
|
|---|
| 7907 | basePullAt(array, arrayMap(indexes, function(index) {
|
|---|
| 7908 | return isIndex(index, length) ? +index : index;
|
|---|
| 7909 | }).sort(compareAscending));
|
|---|
| 7910 |
|
|---|
| 7911 | return result;
|
|---|
| 7912 | });
|
|---|
| 7913 |
|
|---|
| 7914 | /**
|
|---|
| 7915 | * Removes all elements from `array` that `predicate` returns truthy for
|
|---|
| 7916 | * and returns an array of the removed elements. The predicate is invoked
|
|---|
| 7917 | * with three arguments: (value, index, array).
|
|---|
| 7918 | *
|
|---|
| 7919 | * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
|
|---|
| 7920 | * to pull elements from an array by value.
|
|---|
| 7921 | *
|
|---|
| 7922 | * @static
|
|---|
| 7923 | * @memberOf _
|
|---|
| 7924 | * @since 2.0.0
|
|---|
| 7925 | * @category Array
|
|---|
| 7926 | * @param {Array} array The array to modify.
|
|---|
| 7927 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 7928 | * @returns {Array} Returns the new array of removed elements.
|
|---|
| 7929 | * @example
|
|---|
| 7930 | *
|
|---|
| 7931 | * var array = [1, 2, 3, 4];
|
|---|
| 7932 | * var evens = _.remove(array, function(n) {
|
|---|
| 7933 | * return n % 2 == 0;
|
|---|
| 7934 | * });
|
|---|
| 7935 | *
|
|---|
| 7936 | * console.log(array);
|
|---|
| 7937 | * // => [1, 3]
|
|---|
| 7938 | *
|
|---|
| 7939 | * console.log(evens);
|
|---|
| 7940 | * // => [2, 4]
|
|---|
| 7941 | */
|
|---|
| 7942 | function remove(array, predicate) {
|
|---|
| 7943 | var result = [];
|
|---|
| 7944 | if (!(array && array.length)) {
|
|---|
| 7945 | return result;
|
|---|
| 7946 | }
|
|---|
| 7947 | var index = -1,
|
|---|
| 7948 | indexes = [],
|
|---|
| 7949 | length = array.length;
|
|---|
| 7950 |
|
|---|
| 7951 | predicate = getIteratee(predicate, 3);
|
|---|
| 7952 | while (++index < length) {
|
|---|
| 7953 | var value = array[index];
|
|---|
| 7954 | if (predicate(value, index, array)) {
|
|---|
| 7955 | result.push(value);
|
|---|
| 7956 | indexes.push(index);
|
|---|
| 7957 | }
|
|---|
| 7958 | }
|
|---|
| 7959 | basePullAt(array, indexes);
|
|---|
| 7960 | return result;
|
|---|
| 7961 | }
|
|---|
| 7962 |
|
|---|
| 7963 | /**
|
|---|
| 7964 | * Reverses `array` so that the first element becomes the last, the second
|
|---|
| 7965 | * element becomes the second to last, and so on.
|
|---|
| 7966 | *
|
|---|
| 7967 | * **Note:** This method mutates `array` and is based on
|
|---|
| 7968 | * [`Array#reverse`](https://mdn.io/Array/reverse).
|
|---|
| 7969 | *
|
|---|
| 7970 | * @static
|
|---|
| 7971 | * @memberOf _
|
|---|
| 7972 | * @since 4.0.0
|
|---|
| 7973 | * @category Array
|
|---|
| 7974 | * @param {Array} array The array to modify.
|
|---|
| 7975 | * @returns {Array} Returns `array`.
|
|---|
| 7976 | * @example
|
|---|
| 7977 | *
|
|---|
| 7978 | * var array = [1, 2, 3];
|
|---|
| 7979 | *
|
|---|
| 7980 | * _.reverse(array);
|
|---|
| 7981 | * // => [3, 2, 1]
|
|---|
| 7982 | *
|
|---|
| 7983 | * console.log(array);
|
|---|
| 7984 | * // => [3, 2, 1]
|
|---|
| 7985 | */
|
|---|
| 7986 | function reverse(array) {
|
|---|
| 7987 | return array == null ? array : nativeReverse.call(array);
|
|---|
| 7988 | }
|
|---|
| 7989 |
|
|---|
| 7990 | /**
|
|---|
| 7991 | * Creates a slice of `array` from `start` up to, but not including, `end`.
|
|---|
| 7992 | *
|
|---|
| 7993 | * **Note:** This method is used instead of
|
|---|
| 7994 | * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
|
|---|
| 7995 | * returned.
|
|---|
| 7996 | *
|
|---|
| 7997 | * @static
|
|---|
| 7998 | * @memberOf _
|
|---|
| 7999 | * @since 3.0.0
|
|---|
| 8000 | * @category Array
|
|---|
| 8001 | * @param {Array} array The array to slice.
|
|---|
| 8002 | * @param {number} [start=0] The start position.
|
|---|
| 8003 | * @param {number} [end=array.length] The end position.
|
|---|
| 8004 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 8005 | */
|
|---|
| 8006 | function slice(array, start, end) {
|
|---|
| 8007 | var length = array == null ? 0 : array.length;
|
|---|
| 8008 | if (!length) {
|
|---|
| 8009 | return [];
|
|---|
| 8010 | }
|
|---|
| 8011 | if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
|
|---|
| 8012 | start = 0;
|
|---|
| 8013 | end = length;
|
|---|
| 8014 | }
|
|---|
| 8015 | else {
|
|---|
| 8016 | start = start == null ? 0 : toInteger(start);
|
|---|
| 8017 | end = end === undefined ? length : toInteger(end);
|
|---|
| 8018 | }
|
|---|
| 8019 | return baseSlice(array, start, end);
|
|---|
| 8020 | }
|
|---|
| 8021 |
|
|---|
| 8022 | /**
|
|---|
| 8023 | * Uses a binary search to determine the lowest index at which `value`
|
|---|
| 8024 | * should be inserted into `array` in order to maintain its sort order.
|
|---|
| 8025 | *
|
|---|
| 8026 | * @static
|
|---|
| 8027 | * @memberOf _
|
|---|
| 8028 | * @since 0.1.0
|
|---|
| 8029 | * @category Array
|
|---|
| 8030 | * @param {Array} array The sorted array to inspect.
|
|---|
| 8031 | * @param {*} value The value to evaluate.
|
|---|
| 8032 | * @returns {number} Returns the index at which `value` should be inserted
|
|---|
| 8033 | * into `array`.
|
|---|
| 8034 | * @example
|
|---|
| 8035 | *
|
|---|
| 8036 | * _.sortedIndex([30, 50], 40);
|
|---|
| 8037 | * // => 1
|
|---|
| 8038 | */
|
|---|
| 8039 | function sortedIndex(array, value) {
|
|---|
| 8040 | return baseSortedIndex(array, value);
|
|---|
| 8041 | }
|
|---|
| 8042 |
|
|---|
| 8043 | /**
|
|---|
| 8044 | * This method is like `_.sortedIndex` except that it accepts `iteratee`
|
|---|
| 8045 | * which is invoked for `value` and each element of `array` to compute their
|
|---|
| 8046 | * sort ranking. The iteratee is invoked with one argument: (value).
|
|---|
| 8047 | *
|
|---|
| 8048 | * @static
|
|---|
| 8049 | * @memberOf _
|
|---|
| 8050 | * @since 4.0.0
|
|---|
| 8051 | * @category Array
|
|---|
| 8052 | * @param {Array} array The sorted array to inspect.
|
|---|
| 8053 | * @param {*} value The value to evaluate.
|
|---|
| 8054 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 8055 | * @returns {number} Returns the index at which `value` should be inserted
|
|---|
| 8056 | * into `array`.
|
|---|
| 8057 | * @example
|
|---|
| 8058 | *
|
|---|
| 8059 | * var objects = [{ 'x': 4 }, { 'x': 5 }];
|
|---|
| 8060 | *
|
|---|
| 8061 | * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
|
|---|
| 8062 | * // => 0
|
|---|
| 8063 | *
|
|---|
| 8064 | * // The `_.property` iteratee shorthand.
|
|---|
| 8065 | * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
|
|---|
| 8066 | * // => 0
|
|---|
| 8067 | */
|
|---|
| 8068 | function sortedIndexBy(array, value, iteratee) {
|
|---|
| 8069 | return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
|
|---|
| 8070 | }
|
|---|
| 8071 |
|
|---|
| 8072 | /**
|
|---|
| 8073 | * This method is like `_.indexOf` except that it performs a binary
|
|---|
| 8074 | * search on a sorted `array`.
|
|---|
| 8075 | *
|
|---|
| 8076 | * @static
|
|---|
| 8077 | * @memberOf _
|
|---|
| 8078 | * @since 4.0.0
|
|---|
| 8079 | * @category Array
|
|---|
| 8080 | * @param {Array} array The array to inspect.
|
|---|
| 8081 | * @param {*} value The value to search for.
|
|---|
| 8082 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 8083 | * @example
|
|---|
| 8084 | *
|
|---|
| 8085 | * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
|
|---|
| 8086 | * // => 1
|
|---|
| 8087 | */
|
|---|
| 8088 | function sortedIndexOf(array, value) {
|
|---|
| 8089 | var length = array == null ? 0 : array.length;
|
|---|
| 8090 | if (length) {
|
|---|
| 8091 | var index = baseSortedIndex(array, value);
|
|---|
| 8092 | if (index < length && eq(array[index], value)) {
|
|---|
| 8093 | return index;
|
|---|
| 8094 | }
|
|---|
| 8095 | }
|
|---|
| 8096 | return -1;
|
|---|
| 8097 | }
|
|---|
| 8098 |
|
|---|
| 8099 | /**
|
|---|
| 8100 | * This method is like `_.sortedIndex` except that it returns the highest
|
|---|
| 8101 | * index at which `value` should be inserted into `array` in order to
|
|---|
| 8102 | * maintain its sort order.
|
|---|
| 8103 | *
|
|---|
| 8104 | * @static
|
|---|
| 8105 | * @memberOf _
|
|---|
| 8106 | * @since 3.0.0
|
|---|
| 8107 | * @category Array
|
|---|
| 8108 | * @param {Array} array The sorted array to inspect.
|
|---|
| 8109 | * @param {*} value The value to evaluate.
|
|---|
| 8110 | * @returns {number} Returns the index at which `value` should be inserted
|
|---|
| 8111 | * into `array`.
|
|---|
| 8112 | * @example
|
|---|
| 8113 | *
|
|---|
| 8114 | * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
|
|---|
| 8115 | * // => 4
|
|---|
| 8116 | */
|
|---|
| 8117 | function sortedLastIndex(array, value) {
|
|---|
| 8118 | return baseSortedIndex(array, value, true);
|
|---|
| 8119 | }
|
|---|
| 8120 |
|
|---|
| 8121 | /**
|
|---|
| 8122 | * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
|
|---|
| 8123 | * which is invoked for `value` and each element of `array` to compute their
|
|---|
| 8124 | * sort ranking. The iteratee is invoked with one argument: (value).
|
|---|
| 8125 | *
|
|---|
| 8126 | * @static
|
|---|
| 8127 | * @memberOf _
|
|---|
| 8128 | * @since 4.0.0
|
|---|
| 8129 | * @category Array
|
|---|
| 8130 | * @param {Array} array The sorted array to inspect.
|
|---|
| 8131 | * @param {*} value The value to evaluate.
|
|---|
| 8132 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 8133 | * @returns {number} Returns the index at which `value` should be inserted
|
|---|
| 8134 | * into `array`.
|
|---|
| 8135 | * @example
|
|---|
| 8136 | *
|
|---|
| 8137 | * var objects = [{ 'x': 4 }, { 'x': 5 }];
|
|---|
| 8138 | *
|
|---|
| 8139 | * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
|
|---|
| 8140 | * // => 1
|
|---|
| 8141 | *
|
|---|
| 8142 | * // The `_.property` iteratee shorthand.
|
|---|
| 8143 | * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
|
|---|
| 8144 | * // => 1
|
|---|
| 8145 | */
|
|---|
| 8146 | function sortedLastIndexBy(array, value, iteratee) {
|
|---|
| 8147 | return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
|
|---|
| 8148 | }
|
|---|
| 8149 |
|
|---|
| 8150 | /**
|
|---|
| 8151 | * This method is like `_.lastIndexOf` except that it performs a binary
|
|---|
| 8152 | * search on a sorted `array`.
|
|---|
| 8153 | *
|
|---|
| 8154 | * @static
|
|---|
| 8155 | * @memberOf _
|
|---|
| 8156 | * @since 4.0.0
|
|---|
| 8157 | * @category Array
|
|---|
| 8158 | * @param {Array} array The array to inspect.
|
|---|
| 8159 | * @param {*} value The value to search for.
|
|---|
| 8160 | * @returns {number} Returns the index of the matched value, else `-1`.
|
|---|
| 8161 | * @example
|
|---|
| 8162 | *
|
|---|
| 8163 | * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
|
|---|
| 8164 | * // => 3
|
|---|
| 8165 | */
|
|---|
| 8166 | function sortedLastIndexOf(array, value) {
|
|---|
| 8167 | var length = array == null ? 0 : array.length;
|
|---|
| 8168 | if (length) {
|
|---|
| 8169 | var index = baseSortedIndex(array, value, true) - 1;
|
|---|
| 8170 | if (eq(array[index], value)) {
|
|---|
| 8171 | return index;
|
|---|
| 8172 | }
|
|---|
| 8173 | }
|
|---|
| 8174 | return -1;
|
|---|
| 8175 | }
|
|---|
| 8176 |
|
|---|
| 8177 | /**
|
|---|
| 8178 | * This method is like `_.uniq` except that it's designed and optimized
|
|---|
| 8179 | * for sorted arrays.
|
|---|
| 8180 | *
|
|---|
| 8181 | * @static
|
|---|
| 8182 | * @memberOf _
|
|---|
| 8183 | * @since 4.0.0
|
|---|
| 8184 | * @category Array
|
|---|
| 8185 | * @param {Array} array The array to inspect.
|
|---|
| 8186 | * @returns {Array} Returns the new duplicate free array.
|
|---|
| 8187 | * @example
|
|---|
| 8188 | *
|
|---|
| 8189 | * _.sortedUniq([1, 1, 2]);
|
|---|
| 8190 | * // => [1, 2]
|
|---|
| 8191 | */
|
|---|
| 8192 | function sortedUniq(array) {
|
|---|
| 8193 | return (array && array.length)
|
|---|
| 8194 | ? baseSortedUniq(array)
|
|---|
| 8195 | : [];
|
|---|
| 8196 | }
|
|---|
| 8197 |
|
|---|
| 8198 | /**
|
|---|
| 8199 | * This method is like `_.uniqBy` except that it's designed and optimized
|
|---|
| 8200 | * for sorted arrays.
|
|---|
| 8201 | *
|
|---|
| 8202 | * @static
|
|---|
| 8203 | * @memberOf _
|
|---|
| 8204 | * @since 4.0.0
|
|---|
| 8205 | * @category Array
|
|---|
| 8206 | * @param {Array} array The array to inspect.
|
|---|
| 8207 | * @param {Function} [iteratee] The iteratee invoked per element.
|
|---|
| 8208 | * @returns {Array} Returns the new duplicate free array.
|
|---|
| 8209 | * @example
|
|---|
| 8210 | *
|
|---|
| 8211 | * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
|
|---|
| 8212 | * // => [1.1, 2.3]
|
|---|
| 8213 | */
|
|---|
| 8214 | function sortedUniqBy(array, iteratee) {
|
|---|
| 8215 | return (array && array.length)
|
|---|
| 8216 | ? baseSortedUniq(array, getIteratee(iteratee, 2))
|
|---|
| 8217 | : [];
|
|---|
| 8218 | }
|
|---|
| 8219 |
|
|---|
| 8220 | /**
|
|---|
| 8221 | * Gets all but the first element of `array`.
|
|---|
| 8222 | *
|
|---|
| 8223 | * @static
|
|---|
| 8224 | * @memberOf _
|
|---|
| 8225 | * @since 4.0.0
|
|---|
| 8226 | * @category Array
|
|---|
| 8227 | * @param {Array} array The array to query.
|
|---|
| 8228 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 8229 | * @example
|
|---|
| 8230 | *
|
|---|
| 8231 | * _.tail([1, 2, 3]);
|
|---|
| 8232 | * // => [2, 3]
|
|---|
| 8233 | */
|
|---|
| 8234 | function tail(array) {
|
|---|
| 8235 | var length = array == null ? 0 : array.length;
|
|---|
| 8236 | return length ? baseSlice(array, 1, length) : [];
|
|---|
| 8237 | }
|
|---|
| 8238 |
|
|---|
| 8239 | /**
|
|---|
| 8240 | * Creates a slice of `array` with `n` elements taken from the beginning.
|
|---|
| 8241 | *
|
|---|
| 8242 | * @static
|
|---|
| 8243 | * @memberOf _
|
|---|
| 8244 | * @since 0.1.0
|
|---|
| 8245 | * @category Array
|
|---|
| 8246 | * @param {Array} array The array to query.
|
|---|
| 8247 | * @param {number} [n=1] The number of elements to take.
|
|---|
| 8248 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 8249 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 8250 | * @example
|
|---|
| 8251 | *
|
|---|
| 8252 | * _.take([1, 2, 3]);
|
|---|
| 8253 | * // => [1]
|
|---|
| 8254 | *
|
|---|
| 8255 | * _.take([1, 2, 3], 2);
|
|---|
| 8256 | * // => [1, 2]
|
|---|
| 8257 | *
|
|---|
| 8258 | * _.take([1, 2, 3], 5);
|
|---|
| 8259 | * // => [1, 2, 3]
|
|---|
| 8260 | *
|
|---|
| 8261 | * _.take([1, 2, 3], 0);
|
|---|
| 8262 | * // => []
|
|---|
| 8263 | */
|
|---|
| 8264 | function take(array, n, guard) {
|
|---|
| 8265 | if (!(array && array.length)) {
|
|---|
| 8266 | return [];
|
|---|
| 8267 | }
|
|---|
| 8268 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
|---|
| 8269 | return baseSlice(array, 0, n < 0 ? 0 : n);
|
|---|
| 8270 | }
|
|---|
| 8271 |
|
|---|
| 8272 | /**
|
|---|
| 8273 | * Creates a slice of `array` with `n` elements taken from the end.
|
|---|
| 8274 | *
|
|---|
| 8275 | * @static
|
|---|
| 8276 | * @memberOf _
|
|---|
| 8277 | * @since 3.0.0
|
|---|
| 8278 | * @category Array
|
|---|
| 8279 | * @param {Array} array The array to query.
|
|---|
| 8280 | * @param {number} [n=1] The number of elements to take.
|
|---|
| 8281 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 8282 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 8283 | * @example
|
|---|
| 8284 | *
|
|---|
| 8285 | * _.takeRight([1, 2, 3]);
|
|---|
| 8286 | * // => [3]
|
|---|
| 8287 | *
|
|---|
| 8288 | * _.takeRight([1, 2, 3], 2);
|
|---|
| 8289 | * // => [2, 3]
|
|---|
| 8290 | *
|
|---|
| 8291 | * _.takeRight([1, 2, 3], 5);
|
|---|
| 8292 | * // => [1, 2, 3]
|
|---|
| 8293 | *
|
|---|
| 8294 | * _.takeRight([1, 2, 3], 0);
|
|---|
| 8295 | * // => []
|
|---|
| 8296 | */
|
|---|
| 8297 | function takeRight(array, n, guard) {
|
|---|
| 8298 | var length = array == null ? 0 : array.length;
|
|---|
| 8299 | if (!length) {
|
|---|
| 8300 | return [];
|
|---|
| 8301 | }
|
|---|
| 8302 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
|---|
| 8303 | n = length - n;
|
|---|
| 8304 | return baseSlice(array, n < 0 ? 0 : n, length);
|
|---|
| 8305 | }
|
|---|
| 8306 |
|
|---|
| 8307 | /**
|
|---|
| 8308 | * Creates a slice of `array` with elements taken from the end. Elements are
|
|---|
| 8309 | * taken until `predicate` returns falsey. The predicate is invoked with
|
|---|
| 8310 | * three arguments: (value, index, array).
|
|---|
| 8311 | *
|
|---|
| 8312 | * @static
|
|---|
| 8313 | * @memberOf _
|
|---|
| 8314 | * @since 3.0.0
|
|---|
| 8315 | * @category Array
|
|---|
| 8316 | * @param {Array} array The array to query.
|
|---|
| 8317 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 8318 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 8319 | * @example
|
|---|
| 8320 | *
|
|---|
| 8321 | * var users = [
|
|---|
| 8322 | * { 'user': 'barney', 'active': true },
|
|---|
| 8323 | * { 'user': 'fred', 'active': false },
|
|---|
| 8324 | * { 'user': 'pebbles', 'active': false }
|
|---|
| 8325 | * ];
|
|---|
| 8326 | *
|
|---|
| 8327 | * _.takeRightWhile(users, function(o) { return !o.active; });
|
|---|
| 8328 | * // => objects for ['fred', 'pebbles']
|
|---|
| 8329 | *
|
|---|
| 8330 | * // The `_.matches` iteratee shorthand.
|
|---|
| 8331 | * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
|
|---|
| 8332 | * // => objects for ['pebbles']
|
|---|
| 8333 | *
|
|---|
| 8334 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 8335 | * _.takeRightWhile(users, ['active', false]);
|
|---|
| 8336 | * // => objects for ['fred', 'pebbles']
|
|---|
| 8337 | *
|
|---|
| 8338 | * // The `_.property` iteratee shorthand.
|
|---|
| 8339 | * _.takeRightWhile(users, 'active');
|
|---|
| 8340 | * // => []
|
|---|
| 8341 | */
|
|---|
| 8342 | function takeRightWhile(array, predicate) {
|
|---|
| 8343 | return (array && array.length)
|
|---|
| 8344 | ? baseWhile(array, getIteratee(predicate, 3), false, true)
|
|---|
| 8345 | : [];
|
|---|
| 8346 | }
|
|---|
| 8347 |
|
|---|
| 8348 | /**
|
|---|
| 8349 | * Creates a slice of `array` with elements taken from the beginning. Elements
|
|---|
| 8350 | * are taken until `predicate` returns falsey. The predicate is invoked with
|
|---|
| 8351 | * three arguments: (value, index, array).
|
|---|
| 8352 | *
|
|---|
| 8353 | * @static
|
|---|
| 8354 | * @memberOf _
|
|---|
| 8355 | * @since 3.0.0
|
|---|
| 8356 | * @category Array
|
|---|
| 8357 | * @param {Array} array The array to query.
|
|---|
| 8358 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 8359 | * @returns {Array} Returns the slice of `array`.
|
|---|
| 8360 | * @example
|
|---|
| 8361 | *
|
|---|
| 8362 | * var users = [
|
|---|
| 8363 | * { 'user': 'barney', 'active': false },
|
|---|
| 8364 | * { 'user': 'fred', 'active': false },
|
|---|
| 8365 | * { 'user': 'pebbles', 'active': true }
|
|---|
| 8366 | * ];
|
|---|
| 8367 | *
|
|---|
| 8368 | * _.takeWhile(users, function(o) { return !o.active; });
|
|---|
| 8369 | * // => objects for ['barney', 'fred']
|
|---|
| 8370 | *
|
|---|
| 8371 | * // The `_.matches` iteratee shorthand.
|
|---|
| 8372 | * _.takeWhile(users, { 'user': 'barney', 'active': false });
|
|---|
| 8373 | * // => objects for ['barney']
|
|---|
| 8374 | *
|
|---|
| 8375 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 8376 | * _.takeWhile(users, ['active', false]);
|
|---|
| 8377 | * // => objects for ['barney', 'fred']
|
|---|
| 8378 | *
|
|---|
| 8379 | * // The `_.property` iteratee shorthand.
|
|---|
| 8380 | * _.takeWhile(users, 'active');
|
|---|
| 8381 | * // => []
|
|---|
| 8382 | */
|
|---|
| 8383 | function takeWhile(array, predicate) {
|
|---|
| 8384 | return (array && array.length)
|
|---|
| 8385 | ? baseWhile(array, getIteratee(predicate, 3))
|
|---|
| 8386 | : [];
|
|---|
| 8387 | }
|
|---|
| 8388 |
|
|---|
| 8389 | /**
|
|---|
| 8390 | * Creates an array of unique values, in order, from all given arrays using
|
|---|
| 8391 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 8392 | * for equality comparisons.
|
|---|
| 8393 | *
|
|---|
| 8394 | * @static
|
|---|
| 8395 | * @memberOf _
|
|---|
| 8396 | * @since 0.1.0
|
|---|
| 8397 | * @category Array
|
|---|
| 8398 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 8399 | * @returns {Array} Returns the new array of combined values.
|
|---|
| 8400 | * @example
|
|---|
| 8401 | *
|
|---|
| 8402 | * _.union([2], [1, 2]);
|
|---|
| 8403 | * // => [2, 1]
|
|---|
| 8404 | */
|
|---|
| 8405 | var union = baseRest(function(arrays) {
|
|---|
| 8406 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
|
|---|
| 8407 | });
|
|---|
| 8408 |
|
|---|
| 8409 | /**
|
|---|
| 8410 | * This method is like `_.union` except that it accepts `iteratee` which is
|
|---|
| 8411 | * invoked for each element of each `arrays` to generate the criterion by
|
|---|
| 8412 | * which uniqueness is computed. Result values are chosen from the first
|
|---|
| 8413 | * array in which the value occurs. The iteratee is invoked with one argument:
|
|---|
| 8414 | * (value).
|
|---|
| 8415 | *
|
|---|
| 8416 | * @static
|
|---|
| 8417 | * @memberOf _
|
|---|
| 8418 | * @since 4.0.0
|
|---|
| 8419 | * @category Array
|
|---|
| 8420 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 8421 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 8422 | * @returns {Array} Returns the new array of combined values.
|
|---|
| 8423 | * @example
|
|---|
| 8424 | *
|
|---|
| 8425 | * _.unionBy([2.1], [1.2, 2.3], Math.floor);
|
|---|
| 8426 | * // => [2.1, 1.2]
|
|---|
| 8427 | *
|
|---|
| 8428 | * // The `_.property` iteratee shorthand.
|
|---|
| 8429 | * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
|---|
| 8430 | * // => [{ 'x': 1 }, { 'x': 2 }]
|
|---|
| 8431 | */
|
|---|
| 8432 | var unionBy = baseRest(function(arrays) {
|
|---|
| 8433 | var iteratee = last(arrays);
|
|---|
| 8434 | if (isArrayLikeObject(iteratee)) {
|
|---|
| 8435 | iteratee = undefined;
|
|---|
| 8436 | }
|
|---|
| 8437 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
|
|---|
| 8438 | });
|
|---|
| 8439 |
|
|---|
| 8440 | /**
|
|---|
| 8441 | * This method is like `_.union` except that it accepts `comparator` which
|
|---|
| 8442 | * is invoked to compare elements of `arrays`. Result values are chosen from
|
|---|
| 8443 | * the first array in which the value occurs. The comparator is invoked
|
|---|
| 8444 | * with two arguments: (arrVal, othVal).
|
|---|
| 8445 | *
|
|---|
| 8446 | * @static
|
|---|
| 8447 | * @memberOf _
|
|---|
| 8448 | * @since 4.0.0
|
|---|
| 8449 | * @category Array
|
|---|
| 8450 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 8451 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 8452 | * @returns {Array} Returns the new array of combined values.
|
|---|
| 8453 | * @example
|
|---|
| 8454 | *
|
|---|
| 8455 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
|---|
| 8456 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
|---|
| 8457 | *
|
|---|
| 8458 | * _.unionWith(objects, others, _.isEqual);
|
|---|
| 8459 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
|---|
| 8460 | */
|
|---|
| 8461 | var unionWith = baseRest(function(arrays) {
|
|---|
| 8462 | var comparator = last(arrays);
|
|---|
| 8463 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
|---|
| 8464 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
|
|---|
| 8465 | });
|
|---|
| 8466 |
|
|---|
| 8467 | /**
|
|---|
| 8468 | * Creates a duplicate-free version of an array, using
|
|---|
| 8469 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 8470 | * for equality comparisons, in which only the first occurrence of each element
|
|---|
| 8471 | * is kept. The order of result values is determined by the order they occur
|
|---|
| 8472 | * in the array.
|
|---|
| 8473 | *
|
|---|
| 8474 | * @static
|
|---|
| 8475 | * @memberOf _
|
|---|
| 8476 | * @since 0.1.0
|
|---|
| 8477 | * @category Array
|
|---|
| 8478 | * @param {Array} array The array to inspect.
|
|---|
| 8479 | * @returns {Array} Returns the new duplicate free array.
|
|---|
| 8480 | * @example
|
|---|
| 8481 | *
|
|---|
| 8482 | * _.uniq([2, 1, 2]);
|
|---|
| 8483 | * // => [2, 1]
|
|---|
| 8484 | */
|
|---|
| 8485 | function uniq(array) {
|
|---|
| 8486 | return (array && array.length) ? baseUniq(array) : [];
|
|---|
| 8487 | }
|
|---|
| 8488 |
|
|---|
| 8489 | /**
|
|---|
| 8490 | * This method is like `_.uniq` except that it accepts `iteratee` which is
|
|---|
| 8491 | * invoked for each element in `array` to generate the criterion by which
|
|---|
| 8492 | * uniqueness is computed. The order of result values is determined by the
|
|---|
| 8493 | * order they occur in the array. The iteratee is invoked with one argument:
|
|---|
| 8494 | * (value).
|
|---|
| 8495 | *
|
|---|
| 8496 | * @static
|
|---|
| 8497 | * @memberOf _
|
|---|
| 8498 | * @since 4.0.0
|
|---|
| 8499 | * @category Array
|
|---|
| 8500 | * @param {Array} array The array to inspect.
|
|---|
| 8501 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 8502 | * @returns {Array} Returns the new duplicate free array.
|
|---|
| 8503 | * @example
|
|---|
| 8504 | *
|
|---|
| 8505 | * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
|
|---|
| 8506 | * // => [2.1, 1.2]
|
|---|
| 8507 | *
|
|---|
| 8508 | * // The `_.property` iteratee shorthand.
|
|---|
| 8509 | * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
|---|
| 8510 | * // => [{ 'x': 1 }, { 'x': 2 }]
|
|---|
| 8511 | */
|
|---|
| 8512 | function uniqBy(array, iteratee) {
|
|---|
| 8513 | return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
|
|---|
| 8514 | }
|
|---|
| 8515 |
|
|---|
| 8516 | /**
|
|---|
| 8517 | * This method is like `_.uniq` except that it accepts `comparator` which
|
|---|
| 8518 | * is invoked to compare elements of `array`. The order of result values is
|
|---|
| 8519 | * determined by the order they occur in the array.The comparator is invoked
|
|---|
| 8520 | * with two arguments: (arrVal, othVal).
|
|---|
| 8521 | *
|
|---|
| 8522 | * @static
|
|---|
| 8523 | * @memberOf _
|
|---|
| 8524 | * @since 4.0.0
|
|---|
| 8525 | * @category Array
|
|---|
| 8526 | * @param {Array} array The array to inspect.
|
|---|
| 8527 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 8528 | * @returns {Array} Returns the new duplicate free array.
|
|---|
| 8529 | * @example
|
|---|
| 8530 | *
|
|---|
| 8531 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
|---|
| 8532 | *
|
|---|
| 8533 | * _.uniqWith(objects, _.isEqual);
|
|---|
| 8534 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
|
|---|
| 8535 | */
|
|---|
| 8536 | function uniqWith(array, comparator) {
|
|---|
| 8537 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
|---|
| 8538 | return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
|
|---|
| 8539 | }
|
|---|
| 8540 |
|
|---|
| 8541 | /**
|
|---|
| 8542 | * This method is like `_.zip` except that it accepts an array of grouped
|
|---|
| 8543 | * elements and creates an array regrouping the elements to their pre-zip
|
|---|
| 8544 | * configuration.
|
|---|
| 8545 | *
|
|---|
| 8546 | * @static
|
|---|
| 8547 | * @memberOf _
|
|---|
| 8548 | * @since 1.2.0
|
|---|
| 8549 | * @category Array
|
|---|
| 8550 | * @param {Array} array The array of grouped elements to process.
|
|---|
| 8551 | * @returns {Array} Returns the new array of regrouped elements.
|
|---|
| 8552 | * @example
|
|---|
| 8553 | *
|
|---|
| 8554 | * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
|
|---|
| 8555 | * // => [['a', 1, true], ['b', 2, false]]
|
|---|
| 8556 | *
|
|---|
| 8557 | * _.unzip(zipped);
|
|---|
| 8558 | * // => [['a', 'b'], [1, 2], [true, false]]
|
|---|
| 8559 | */
|
|---|
| 8560 | function unzip(array) {
|
|---|
| 8561 | if (!(array && array.length)) {
|
|---|
| 8562 | return [];
|
|---|
| 8563 | }
|
|---|
| 8564 | var length = 0;
|
|---|
| 8565 | array = arrayFilter(array, function(group) {
|
|---|
| 8566 | if (isArrayLikeObject(group)) {
|
|---|
| 8567 | length = nativeMax(group.length, length);
|
|---|
| 8568 | return true;
|
|---|
| 8569 | }
|
|---|
| 8570 | });
|
|---|
| 8571 | return baseTimes(length, function(index) {
|
|---|
| 8572 | return arrayMap(array, baseProperty(index));
|
|---|
| 8573 | });
|
|---|
| 8574 | }
|
|---|
| 8575 |
|
|---|
| 8576 | /**
|
|---|
| 8577 | * This method is like `_.unzip` except that it accepts `iteratee` to specify
|
|---|
| 8578 | * how regrouped values should be combined. The iteratee is invoked with the
|
|---|
| 8579 | * elements of each group: (...group).
|
|---|
| 8580 | *
|
|---|
| 8581 | * @static
|
|---|
| 8582 | * @memberOf _
|
|---|
| 8583 | * @since 3.8.0
|
|---|
| 8584 | * @category Array
|
|---|
| 8585 | * @param {Array} array The array of grouped elements to process.
|
|---|
| 8586 | * @param {Function} [iteratee=_.identity] The function to combine
|
|---|
| 8587 | * regrouped values.
|
|---|
| 8588 | * @returns {Array} Returns the new array of regrouped elements.
|
|---|
| 8589 | * @example
|
|---|
| 8590 | *
|
|---|
| 8591 | * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
|
|---|
| 8592 | * // => [[1, 10, 100], [2, 20, 200]]
|
|---|
| 8593 | *
|
|---|
| 8594 | * _.unzipWith(zipped, _.add);
|
|---|
| 8595 | * // => [3, 30, 300]
|
|---|
| 8596 | */
|
|---|
| 8597 | function unzipWith(array, iteratee) {
|
|---|
| 8598 | if (!(array && array.length)) {
|
|---|
| 8599 | return [];
|
|---|
| 8600 | }
|
|---|
| 8601 | var result = unzip(array);
|
|---|
| 8602 | if (iteratee == null) {
|
|---|
| 8603 | return result;
|
|---|
| 8604 | }
|
|---|
| 8605 | return arrayMap(result, function(group) {
|
|---|
| 8606 | return apply(iteratee, undefined, group);
|
|---|
| 8607 | });
|
|---|
| 8608 | }
|
|---|
| 8609 |
|
|---|
| 8610 | /**
|
|---|
| 8611 | * Creates an array excluding all given values using
|
|---|
| 8612 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 8613 | * for equality comparisons.
|
|---|
| 8614 | *
|
|---|
| 8615 | * **Note:** Unlike `_.pull`, this method returns a new array.
|
|---|
| 8616 | *
|
|---|
| 8617 | * @static
|
|---|
| 8618 | * @memberOf _
|
|---|
| 8619 | * @since 0.1.0
|
|---|
| 8620 | * @category Array
|
|---|
| 8621 | * @param {Array} array The array to inspect.
|
|---|
| 8622 | * @param {...*} [values] The values to exclude.
|
|---|
| 8623 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 8624 | * @see _.difference, _.xor
|
|---|
| 8625 | * @example
|
|---|
| 8626 | *
|
|---|
| 8627 | * _.without([2, 1, 2, 3], 1, 2);
|
|---|
| 8628 | * // => [3]
|
|---|
| 8629 | */
|
|---|
| 8630 | var without = baseRest(function(array, values) {
|
|---|
| 8631 | return isArrayLikeObject(array)
|
|---|
| 8632 | ? baseDifference(array, values)
|
|---|
| 8633 | : [];
|
|---|
| 8634 | });
|
|---|
| 8635 |
|
|---|
| 8636 | /**
|
|---|
| 8637 | * Creates an array of unique values that is the
|
|---|
| 8638 | * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
|
|---|
| 8639 | * of the given arrays. The order of result values is determined by the order
|
|---|
| 8640 | * they occur in the arrays.
|
|---|
| 8641 | *
|
|---|
| 8642 | * @static
|
|---|
| 8643 | * @memberOf _
|
|---|
| 8644 | * @since 2.4.0
|
|---|
| 8645 | * @category Array
|
|---|
| 8646 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 8647 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 8648 | * @see _.difference, _.without
|
|---|
| 8649 | * @example
|
|---|
| 8650 | *
|
|---|
| 8651 | * _.xor([2, 1], [2, 3]);
|
|---|
| 8652 | * // => [1, 3]
|
|---|
| 8653 | */
|
|---|
| 8654 | var xor = baseRest(function(arrays) {
|
|---|
| 8655 | return baseXor(arrayFilter(arrays, isArrayLikeObject));
|
|---|
| 8656 | });
|
|---|
| 8657 |
|
|---|
| 8658 | /**
|
|---|
| 8659 | * This method is like `_.xor` except that it accepts `iteratee` which is
|
|---|
| 8660 | * invoked for each element of each `arrays` to generate the criterion by
|
|---|
| 8661 | * which by which they're compared. The order of result values is determined
|
|---|
| 8662 | * by the order they occur in the arrays. The iteratee is invoked with one
|
|---|
| 8663 | * argument: (value).
|
|---|
| 8664 | *
|
|---|
| 8665 | * @static
|
|---|
| 8666 | * @memberOf _
|
|---|
| 8667 | * @since 4.0.0
|
|---|
| 8668 | * @category Array
|
|---|
| 8669 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 8670 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 8671 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 8672 | * @example
|
|---|
| 8673 | *
|
|---|
| 8674 | * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
|---|
| 8675 | * // => [1.2, 3.4]
|
|---|
| 8676 | *
|
|---|
| 8677 | * // The `_.property` iteratee shorthand.
|
|---|
| 8678 | * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
|---|
| 8679 | * // => [{ 'x': 2 }]
|
|---|
| 8680 | */
|
|---|
| 8681 | var xorBy = baseRest(function(arrays) {
|
|---|
| 8682 | var iteratee = last(arrays);
|
|---|
| 8683 | if (isArrayLikeObject(iteratee)) {
|
|---|
| 8684 | iteratee = undefined;
|
|---|
| 8685 | }
|
|---|
| 8686 | return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
|
|---|
| 8687 | });
|
|---|
| 8688 |
|
|---|
| 8689 | /**
|
|---|
| 8690 | * This method is like `_.xor` except that it accepts `comparator` which is
|
|---|
| 8691 | * invoked to compare elements of `arrays`. The order of result values is
|
|---|
| 8692 | * determined by the order they occur in the arrays. The comparator is invoked
|
|---|
| 8693 | * with two arguments: (arrVal, othVal).
|
|---|
| 8694 | *
|
|---|
| 8695 | * @static
|
|---|
| 8696 | * @memberOf _
|
|---|
| 8697 | * @since 4.0.0
|
|---|
| 8698 | * @category Array
|
|---|
| 8699 | * @param {...Array} [arrays] The arrays to inspect.
|
|---|
| 8700 | * @param {Function} [comparator] The comparator invoked per element.
|
|---|
| 8701 | * @returns {Array} Returns the new array of filtered values.
|
|---|
| 8702 | * @example
|
|---|
| 8703 | *
|
|---|
| 8704 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
|---|
| 8705 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
|---|
| 8706 | *
|
|---|
| 8707 | * _.xorWith(objects, others, _.isEqual);
|
|---|
| 8708 | * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
|---|
| 8709 | */
|
|---|
| 8710 | var xorWith = baseRest(function(arrays) {
|
|---|
| 8711 | var comparator = last(arrays);
|
|---|
| 8712 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
|---|
| 8713 | return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
|
|---|
| 8714 | });
|
|---|
| 8715 |
|
|---|
| 8716 | /**
|
|---|
| 8717 | * Creates an array of grouped elements, the first of which contains the
|
|---|
| 8718 | * first elements of the given arrays, the second of which contains the
|
|---|
| 8719 | * second elements of the given arrays, and so on.
|
|---|
| 8720 | *
|
|---|
| 8721 | * @static
|
|---|
| 8722 | * @memberOf _
|
|---|
| 8723 | * @since 0.1.0
|
|---|
| 8724 | * @category Array
|
|---|
| 8725 | * @param {...Array} [arrays] The arrays to process.
|
|---|
| 8726 | * @returns {Array} Returns the new array of grouped elements.
|
|---|
| 8727 | * @example
|
|---|
| 8728 | *
|
|---|
| 8729 | * _.zip(['a', 'b'], [1, 2], [true, false]);
|
|---|
| 8730 | * // => [['a', 1, true], ['b', 2, false]]
|
|---|
| 8731 | */
|
|---|
| 8732 | var zip = baseRest(unzip);
|
|---|
| 8733 |
|
|---|
| 8734 | /**
|
|---|
| 8735 | * This method is like `_.fromPairs` except that it accepts two arrays,
|
|---|
| 8736 | * one of property identifiers and one of corresponding values.
|
|---|
| 8737 | *
|
|---|
| 8738 | * @static
|
|---|
| 8739 | * @memberOf _
|
|---|
| 8740 | * @since 0.4.0
|
|---|
| 8741 | * @category Array
|
|---|
| 8742 | * @param {Array} [props=[]] The property identifiers.
|
|---|
| 8743 | * @param {Array} [values=[]] The property values.
|
|---|
| 8744 | * @returns {Object} Returns the new object.
|
|---|
| 8745 | * @example
|
|---|
| 8746 | *
|
|---|
| 8747 | * _.zipObject(['a', 'b'], [1, 2]);
|
|---|
| 8748 | * // => { 'a': 1, 'b': 2 }
|
|---|
| 8749 | */
|
|---|
| 8750 | function zipObject(props, values) {
|
|---|
| 8751 | return baseZipObject(props || [], values || [], assignValue);
|
|---|
| 8752 | }
|
|---|
| 8753 |
|
|---|
| 8754 | /**
|
|---|
| 8755 | * This method is like `_.zipObject` except that it supports property paths.
|
|---|
| 8756 | *
|
|---|
| 8757 | * @static
|
|---|
| 8758 | * @memberOf _
|
|---|
| 8759 | * @since 4.1.0
|
|---|
| 8760 | * @category Array
|
|---|
| 8761 | * @param {Array} [props=[]] The property identifiers.
|
|---|
| 8762 | * @param {Array} [values=[]] The property values.
|
|---|
| 8763 | * @returns {Object} Returns the new object.
|
|---|
| 8764 | * @example
|
|---|
| 8765 | *
|
|---|
| 8766 | * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
|
|---|
| 8767 | * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
|
|---|
| 8768 | */
|
|---|
| 8769 | function zipObjectDeep(props, values) {
|
|---|
| 8770 | return baseZipObject(props || [], values || [], baseSet);
|
|---|
| 8771 | }
|
|---|
| 8772 |
|
|---|
| 8773 | /**
|
|---|
| 8774 | * This method is like `_.zip` except that it accepts `iteratee` to specify
|
|---|
| 8775 | * how grouped values should be combined. The iteratee is invoked with the
|
|---|
| 8776 | * elements of each group: (...group).
|
|---|
| 8777 | *
|
|---|
| 8778 | * @static
|
|---|
| 8779 | * @memberOf _
|
|---|
| 8780 | * @since 3.8.0
|
|---|
| 8781 | * @category Array
|
|---|
| 8782 | * @param {...Array} [arrays] The arrays to process.
|
|---|
| 8783 | * @param {Function} [iteratee=_.identity] The function to combine
|
|---|
| 8784 | * grouped values.
|
|---|
| 8785 | * @returns {Array} Returns the new array of grouped elements.
|
|---|
| 8786 | * @example
|
|---|
| 8787 | *
|
|---|
| 8788 | * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
|
|---|
| 8789 | * return a + b + c;
|
|---|
| 8790 | * });
|
|---|
| 8791 | * // => [111, 222]
|
|---|
| 8792 | */
|
|---|
| 8793 | var zipWith = baseRest(function(arrays) {
|
|---|
| 8794 | var length = arrays.length,
|
|---|
| 8795 | iteratee = length > 1 ? arrays[length - 1] : undefined;
|
|---|
| 8796 |
|
|---|
| 8797 | iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
|
|---|
| 8798 | return unzipWith(arrays, iteratee);
|
|---|
| 8799 | });
|
|---|
| 8800 |
|
|---|
| 8801 | /*------------------------------------------------------------------------*/
|
|---|
| 8802 |
|
|---|
| 8803 | /**
|
|---|
| 8804 | * Creates a `lodash` wrapper instance that wraps `value` with explicit method
|
|---|
| 8805 | * chain sequences enabled. The result of such sequences must be unwrapped
|
|---|
| 8806 | * with `_#value`.
|
|---|
| 8807 | *
|
|---|
| 8808 | * @static
|
|---|
| 8809 | * @memberOf _
|
|---|
| 8810 | * @since 1.3.0
|
|---|
| 8811 | * @category Seq
|
|---|
| 8812 | * @param {*} value The value to wrap.
|
|---|
| 8813 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
|---|
| 8814 | * @example
|
|---|
| 8815 | *
|
|---|
| 8816 | * var users = [
|
|---|
| 8817 | * { 'user': 'barney', 'age': 36 },
|
|---|
| 8818 | * { 'user': 'fred', 'age': 40 },
|
|---|
| 8819 | * { 'user': 'pebbles', 'age': 1 }
|
|---|
| 8820 | * ];
|
|---|
| 8821 | *
|
|---|
| 8822 | * var youngest = _
|
|---|
| 8823 | * .chain(users)
|
|---|
| 8824 | * .sortBy('age')
|
|---|
| 8825 | * .map(function(o) {
|
|---|
| 8826 | * return o.user + ' is ' + o.age;
|
|---|
| 8827 | * })
|
|---|
| 8828 | * .head()
|
|---|
| 8829 | * .value();
|
|---|
| 8830 | * // => 'pebbles is 1'
|
|---|
| 8831 | */
|
|---|
| 8832 | function chain(value) {
|
|---|
| 8833 | var result = lodash(value);
|
|---|
| 8834 | result.__chain__ = true;
|
|---|
| 8835 | return result;
|
|---|
| 8836 | }
|
|---|
| 8837 |
|
|---|
| 8838 | /**
|
|---|
| 8839 | * This method invokes `interceptor` and returns `value`. The interceptor
|
|---|
| 8840 | * is invoked with one argument; (value). The purpose of this method is to
|
|---|
| 8841 | * "tap into" a method chain sequence in order to modify intermediate results.
|
|---|
| 8842 | *
|
|---|
| 8843 | * @static
|
|---|
| 8844 | * @memberOf _
|
|---|
| 8845 | * @since 0.1.0
|
|---|
| 8846 | * @category Seq
|
|---|
| 8847 | * @param {*} value The value to provide to `interceptor`.
|
|---|
| 8848 | * @param {Function} interceptor The function to invoke.
|
|---|
| 8849 | * @returns {*} Returns `value`.
|
|---|
| 8850 | * @example
|
|---|
| 8851 | *
|
|---|
| 8852 | * _([1, 2, 3])
|
|---|
| 8853 | * .tap(function(array) {
|
|---|
| 8854 | * // Mutate input array.
|
|---|
| 8855 | * array.pop();
|
|---|
| 8856 | * })
|
|---|
| 8857 | * .reverse()
|
|---|
| 8858 | * .value();
|
|---|
| 8859 | * // => [2, 1]
|
|---|
| 8860 | */
|
|---|
| 8861 | function tap(value, interceptor) {
|
|---|
| 8862 | interceptor(value);
|
|---|
| 8863 | return value;
|
|---|
| 8864 | }
|
|---|
| 8865 |
|
|---|
| 8866 | /**
|
|---|
| 8867 | * This method is like `_.tap` except that it returns the result of `interceptor`.
|
|---|
| 8868 | * The purpose of this method is to "pass thru" values replacing intermediate
|
|---|
| 8869 | * results in a method chain sequence.
|
|---|
| 8870 | *
|
|---|
| 8871 | * @static
|
|---|
| 8872 | * @memberOf _
|
|---|
| 8873 | * @since 3.0.0
|
|---|
| 8874 | * @category Seq
|
|---|
| 8875 | * @param {*} value The value to provide to `interceptor`.
|
|---|
| 8876 | * @param {Function} interceptor The function to invoke.
|
|---|
| 8877 | * @returns {*} Returns the result of `interceptor`.
|
|---|
| 8878 | * @example
|
|---|
| 8879 | *
|
|---|
| 8880 | * _(' abc ')
|
|---|
| 8881 | * .chain()
|
|---|
| 8882 | * .trim()
|
|---|
| 8883 | * .thru(function(value) {
|
|---|
| 8884 | * return [value];
|
|---|
| 8885 | * })
|
|---|
| 8886 | * .value();
|
|---|
| 8887 | * // => ['abc']
|
|---|
| 8888 | */
|
|---|
| 8889 | function thru(value, interceptor) {
|
|---|
| 8890 | return interceptor(value);
|
|---|
| 8891 | }
|
|---|
| 8892 |
|
|---|
| 8893 | /**
|
|---|
| 8894 | * This method is the wrapper version of `_.at`.
|
|---|
| 8895 | *
|
|---|
| 8896 | * @name at
|
|---|
| 8897 | * @memberOf _
|
|---|
| 8898 | * @since 1.0.0
|
|---|
| 8899 | * @category Seq
|
|---|
| 8900 | * @param {...(string|string[])} [paths] The property paths to pick.
|
|---|
| 8901 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
|---|
| 8902 | * @example
|
|---|
| 8903 | *
|
|---|
| 8904 | * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
|
|---|
| 8905 | *
|
|---|
| 8906 | * _(object).at(['a[0].b.c', 'a[1]']).value();
|
|---|
| 8907 | * // => [3, 4]
|
|---|
| 8908 | */
|
|---|
| 8909 | var wrapperAt = flatRest(function(paths) {
|
|---|
| 8910 | var length = paths.length,
|
|---|
| 8911 | start = length ? paths[0] : 0,
|
|---|
| 8912 | value = this.__wrapped__,
|
|---|
| 8913 | interceptor = function(object) { return baseAt(object, paths); };
|
|---|
| 8914 |
|
|---|
| 8915 | if (length > 1 || this.__actions__.length ||
|
|---|
| 8916 | !(value instanceof LazyWrapper) || !isIndex(start)) {
|
|---|
| 8917 | return this.thru(interceptor);
|
|---|
| 8918 | }
|
|---|
| 8919 | value = value.slice(start, +start + (length ? 1 : 0));
|
|---|
| 8920 | value.__actions__.push({
|
|---|
| 8921 | 'func': thru,
|
|---|
| 8922 | 'args': [interceptor],
|
|---|
| 8923 | 'thisArg': undefined
|
|---|
| 8924 | });
|
|---|
| 8925 | return new LodashWrapper(value, this.__chain__).thru(function(array) {
|
|---|
| 8926 | if (length && !array.length) {
|
|---|
| 8927 | array.push(undefined);
|
|---|
| 8928 | }
|
|---|
| 8929 | return array;
|
|---|
| 8930 | });
|
|---|
| 8931 | });
|
|---|
| 8932 |
|
|---|
| 8933 | /**
|
|---|
| 8934 | * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
|
|---|
| 8935 | *
|
|---|
| 8936 | * @name chain
|
|---|
| 8937 | * @memberOf _
|
|---|
| 8938 | * @since 0.1.0
|
|---|
| 8939 | * @category Seq
|
|---|
| 8940 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
|---|
| 8941 | * @example
|
|---|
| 8942 | *
|
|---|
| 8943 | * var users = [
|
|---|
| 8944 | * { 'user': 'barney', 'age': 36 },
|
|---|
| 8945 | * { 'user': 'fred', 'age': 40 }
|
|---|
| 8946 | * ];
|
|---|
| 8947 | *
|
|---|
| 8948 | * // A sequence without explicit chaining.
|
|---|
| 8949 | * _(users).head();
|
|---|
| 8950 | * // => { 'user': 'barney', 'age': 36 }
|
|---|
| 8951 | *
|
|---|
| 8952 | * // A sequence with explicit chaining.
|
|---|
| 8953 | * _(users)
|
|---|
| 8954 | * .chain()
|
|---|
| 8955 | * .head()
|
|---|
| 8956 | * .pick('user')
|
|---|
| 8957 | * .value();
|
|---|
| 8958 | * // => { 'user': 'barney' }
|
|---|
| 8959 | */
|
|---|
| 8960 | function wrapperChain() {
|
|---|
| 8961 | return chain(this);
|
|---|
| 8962 | }
|
|---|
| 8963 |
|
|---|
| 8964 | /**
|
|---|
| 8965 | * Executes the chain sequence and returns the wrapped result.
|
|---|
| 8966 | *
|
|---|
| 8967 | * @name commit
|
|---|
| 8968 | * @memberOf _
|
|---|
| 8969 | * @since 3.2.0
|
|---|
| 8970 | * @category Seq
|
|---|
| 8971 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
|---|
| 8972 | * @example
|
|---|
| 8973 | *
|
|---|
| 8974 | * var array = [1, 2];
|
|---|
| 8975 | * var wrapped = _(array).push(3);
|
|---|
| 8976 | *
|
|---|
| 8977 | * console.log(array);
|
|---|
| 8978 | * // => [1, 2]
|
|---|
| 8979 | *
|
|---|
| 8980 | * wrapped = wrapped.commit();
|
|---|
| 8981 | * console.log(array);
|
|---|
| 8982 | * // => [1, 2, 3]
|
|---|
| 8983 | *
|
|---|
| 8984 | * wrapped.last();
|
|---|
| 8985 | * // => 3
|
|---|
| 8986 | *
|
|---|
| 8987 | * console.log(array);
|
|---|
| 8988 | * // => [1, 2, 3]
|
|---|
| 8989 | */
|
|---|
| 8990 | function wrapperCommit() {
|
|---|
| 8991 | return new LodashWrapper(this.value(), this.__chain__);
|
|---|
| 8992 | }
|
|---|
| 8993 |
|
|---|
| 8994 | /**
|
|---|
| 8995 | * Gets the next value on a wrapped object following the
|
|---|
| 8996 | * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
|
|---|
| 8997 | *
|
|---|
| 8998 | * @name next
|
|---|
| 8999 | * @memberOf _
|
|---|
| 9000 | * @since 4.0.0
|
|---|
| 9001 | * @category Seq
|
|---|
| 9002 | * @returns {Object} Returns the next iterator value.
|
|---|
| 9003 | * @example
|
|---|
| 9004 | *
|
|---|
| 9005 | * var wrapped = _([1, 2]);
|
|---|
| 9006 | *
|
|---|
| 9007 | * wrapped.next();
|
|---|
| 9008 | * // => { 'done': false, 'value': 1 }
|
|---|
| 9009 | *
|
|---|
| 9010 | * wrapped.next();
|
|---|
| 9011 | * // => { 'done': false, 'value': 2 }
|
|---|
| 9012 | *
|
|---|
| 9013 | * wrapped.next();
|
|---|
| 9014 | * // => { 'done': true, 'value': undefined }
|
|---|
| 9015 | */
|
|---|
| 9016 | function wrapperNext() {
|
|---|
| 9017 | if (this.__values__ === undefined) {
|
|---|
| 9018 | this.__values__ = toArray(this.value());
|
|---|
| 9019 | }
|
|---|
| 9020 | var done = this.__index__ >= this.__values__.length,
|
|---|
| 9021 | value = done ? undefined : this.__values__[this.__index__++];
|
|---|
| 9022 |
|
|---|
| 9023 | return { 'done': done, 'value': value };
|
|---|
| 9024 | }
|
|---|
| 9025 |
|
|---|
| 9026 | /**
|
|---|
| 9027 | * Enables the wrapper to be iterable.
|
|---|
| 9028 | *
|
|---|
| 9029 | * @name Symbol.iterator
|
|---|
| 9030 | * @memberOf _
|
|---|
| 9031 | * @since 4.0.0
|
|---|
| 9032 | * @category Seq
|
|---|
| 9033 | * @returns {Object} Returns the wrapper object.
|
|---|
| 9034 | * @example
|
|---|
| 9035 | *
|
|---|
| 9036 | * var wrapped = _([1, 2]);
|
|---|
| 9037 | *
|
|---|
| 9038 | * wrapped[Symbol.iterator]() === wrapped;
|
|---|
| 9039 | * // => true
|
|---|
| 9040 | *
|
|---|
| 9041 | * Array.from(wrapped);
|
|---|
| 9042 | * // => [1, 2]
|
|---|
| 9043 | */
|
|---|
| 9044 | function wrapperToIterator() {
|
|---|
| 9045 | return this;
|
|---|
| 9046 | }
|
|---|
| 9047 |
|
|---|
| 9048 | /**
|
|---|
| 9049 | * Creates a clone of the chain sequence planting `value` as the wrapped value.
|
|---|
| 9050 | *
|
|---|
| 9051 | * @name plant
|
|---|
| 9052 | * @memberOf _
|
|---|
| 9053 | * @since 3.2.0
|
|---|
| 9054 | * @category Seq
|
|---|
| 9055 | * @param {*} value The value to plant.
|
|---|
| 9056 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
|---|
| 9057 | * @example
|
|---|
| 9058 | *
|
|---|
| 9059 | * function square(n) {
|
|---|
| 9060 | * return n * n;
|
|---|
| 9061 | * }
|
|---|
| 9062 | *
|
|---|
| 9063 | * var wrapped = _([1, 2]).map(square);
|
|---|
| 9064 | * var other = wrapped.plant([3, 4]);
|
|---|
| 9065 | *
|
|---|
| 9066 | * other.value();
|
|---|
| 9067 | * // => [9, 16]
|
|---|
| 9068 | *
|
|---|
| 9069 | * wrapped.value();
|
|---|
| 9070 | * // => [1, 4]
|
|---|
| 9071 | */
|
|---|
| 9072 | function wrapperPlant(value) {
|
|---|
| 9073 | var result,
|
|---|
| 9074 | parent = this;
|
|---|
| 9075 |
|
|---|
| 9076 | while (parent instanceof baseLodash) {
|
|---|
| 9077 | var clone = wrapperClone(parent);
|
|---|
| 9078 | clone.__index__ = 0;
|
|---|
| 9079 | clone.__values__ = undefined;
|
|---|
| 9080 | if (result) {
|
|---|
| 9081 | previous.__wrapped__ = clone;
|
|---|
| 9082 | } else {
|
|---|
| 9083 | result = clone;
|
|---|
| 9084 | }
|
|---|
| 9085 | var previous = clone;
|
|---|
| 9086 | parent = parent.__wrapped__;
|
|---|
| 9087 | }
|
|---|
| 9088 | previous.__wrapped__ = value;
|
|---|
| 9089 | return result;
|
|---|
| 9090 | }
|
|---|
| 9091 |
|
|---|
| 9092 | /**
|
|---|
| 9093 | * This method is the wrapper version of `_.reverse`.
|
|---|
| 9094 | *
|
|---|
| 9095 | * **Note:** This method mutates the wrapped array.
|
|---|
| 9096 | *
|
|---|
| 9097 | * @name reverse
|
|---|
| 9098 | * @memberOf _
|
|---|
| 9099 | * @since 0.1.0
|
|---|
| 9100 | * @category Seq
|
|---|
| 9101 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
|---|
| 9102 | * @example
|
|---|
| 9103 | *
|
|---|
| 9104 | * var array = [1, 2, 3];
|
|---|
| 9105 | *
|
|---|
| 9106 | * _(array).reverse().value()
|
|---|
| 9107 | * // => [3, 2, 1]
|
|---|
| 9108 | *
|
|---|
| 9109 | * console.log(array);
|
|---|
| 9110 | * // => [3, 2, 1]
|
|---|
| 9111 | */
|
|---|
| 9112 | function wrapperReverse() {
|
|---|
| 9113 | var value = this.__wrapped__;
|
|---|
| 9114 | if (value instanceof LazyWrapper) {
|
|---|
| 9115 | var wrapped = value;
|
|---|
| 9116 | if (this.__actions__.length) {
|
|---|
| 9117 | wrapped = new LazyWrapper(this);
|
|---|
| 9118 | }
|
|---|
| 9119 | wrapped = wrapped.reverse();
|
|---|
| 9120 | wrapped.__actions__.push({
|
|---|
| 9121 | 'func': thru,
|
|---|
| 9122 | 'args': [reverse],
|
|---|
| 9123 | 'thisArg': undefined
|
|---|
| 9124 | });
|
|---|
| 9125 | return new LodashWrapper(wrapped, this.__chain__);
|
|---|
| 9126 | }
|
|---|
| 9127 | return this.thru(reverse);
|
|---|
| 9128 | }
|
|---|
| 9129 |
|
|---|
| 9130 | /**
|
|---|
| 9131 | * Executes the chain sequence to resolve the unwrapped value.
|
|---|
| 9132 | *
|
|---|
| 9133 | * @name value
|
|---|
| 9134 | * @memberOf _
|
|---|
| 9135 | * @since 0.1.0
|
|---|
| 9136 | * @alias toJSON, valueOf
|
|---|
| 9137 | * @category Seq
|
|---|
| 9138 | * @returns {*} Returns the resolved unwrapped value.
|
|---|
| 9139 | * @example
|
|---|
| 9140 | *
|
|---|
| 9141 | * _([1, 2, 3]).value();
|
|---|
| 9142 | * // => [1, 2, 3]
|
|---|
| 9143 | */
|
|---|
| 9144 | function wrapperValue() {
|
|---|
| 9145 | return baseWrapperValue(this.__wrapped__, this.__actions__);
|
|---|
| 9146 | }
|
|---|
| 9147 |
|
|---|
| 9148 | /*------------------------------------------------------------------------*/
|
|---|
| 9149 |
|
|---|
| 9150 | /**
|
|---|
| 9151 | * Creates an object composed of keys generated from the results of running
|
|---|
| 9152 | * each element of `collection` thru `iteratee`. The corresponding value of
|
|---|
| 9153 | * each key is the number of times the key was returned by `iteratee`. The
|
|---|
| 9154 | * iteratee is invoked with one argument: (value).
|
|---|
| 9155 | *
|
|---|
| 9156 | * @static
|
|---|
| 9157 | * @memberOf _
|
|---|
| 9158 | * @since 0.5.0
|
|---|
| 9159 | * @category Collection
|
|---|
| 9160 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9161 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
|---|
| 9162 | * @returns {Object} Returns the composed aggregate object.
|
|---|
| 9163 | * @example
|
|---|
| 9164 | *
|
|---|
| 9165 | * _.countBy([6.1, 4.2, 6.3], Math.floor);
|
|---|
| 9166 | * // => { '4': 1, '6': 2 }
|
|---|
| 9167 | *
|
|---|
| 9168 | * // The `_.property` iteratee shorthand.
|
|---|
| 9169 | * _.countBy(['one', 'two', 'three'], 'length');
|
|---|
| 9170 | * // => { '3': 2, '5': 1 }
|
|---|
| 9171 | */
|
|---|
| 9172 | var countBy = createAggregator(function(result, value, key) {
|
|---|
| 9173 | if (hasOwnProperty.call(result, key)) {
|
|---|
| 9174 | ++result[key];
|
|---|
| 9175 | } else {
|
|---|
| 9176 | baseAssignValue(result, key, 1);
|
|---|
| 9177 | }
|
|---|
| 9178 | });
|
|---|
| 9179 |
|
|---|
| 9180 | /**
|
|---|
| 9181 | * Checks if `predicate` returns truthy for **all** elements of `collection`.
|
|---|
| 9182 | * Iteration is stopped once `predicate` returns falsey. The predicate is
|
|---|
| 9183 | * invoked with three arguments: (value, index|key, collection).
|
|---|
| 9184 | *
|
|---|
| 9185 | * **Note:** This method returns `true` for
|
|---|
| 9186 | * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
|
|---|
| 9187 | * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
|
|---|
| 9188 | * elements of empty collections.
|
|---|
| 9189 | *
|
|---|
| 9190 | * @static
|
|---|
| 9191 | * @memberOf _
|
|---|
| 9192 | * @since 0.1.0
|
|---|
| 9193 | * @category Collection
|
|---|
| 9194 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9195 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 9196 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 9197 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
|---|
| 9198 | * else `false`.
|
|---|
| 9199 | * @example
|
|---|
| 9200 | *
|
|---|
| 9201 | * _.every([true, 1, null, 'yes'], Boolean);
|
|---|
| 9202 | * // => false
|
|---|
| 9203 | *
|
|---|
| 9204 | * var users = [
|
|---|
| 9205 | * { 'user': 'barney', 'age': 36, 'active': false },
|
|---|
| 9206 | * { 'user': 'fred', 'age': 40, 'active': false }
|
|---|
| 9207 | * ];
|
|---|
| 9208 | *
|
|---|
| 9209 | * // The `_.matches` iteratee shorthand.
|
|---|
| 9210 | * _.every(users, { 'user': 'barney', 'active': false });
|
|---|
| 9211 | * // => false
|
|---|
| 9212 | *
|
|---|
| 9213 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 9214 | * _.every(users, ['active', false]);
|
|---|
| 9215 | * // => true
|
|---|
| 9216 | *
|
|---|
| 9217 | * // The `_.property` iteratee shorthand.
|
|---|
| 9218 | * _.every(users, 'active');
|
|---|
| 9219 | * // => false
|
|---|
| 9220 | */
|
|---|
| 9221 | function every(collection, predicate, guard) {
|
|---|
| 9222 | var func = isArray(collection) ? arrayEvery : baseEvery;
|
|---|
| 9223 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
|---|
| 9224 | predicate = undefined;
|
|---|
| 9225 | }
|
|---|
| 9226 | return func(collection, getIteratee(predicate, 3));
|
|---|
| 9227 | }
|
|---|
| 9228 |
|
|---|
| 9229 | /**
|
|---|
| 9230 | * Iterates over elements of `collection`, returning an array of all elements
|
|---|
| 9231 | * `predicate` returns truthy for. The predicate is invoked with three
|
|---|
| 9232 | * arguments: (value, index|key, collection).
|
|---|
| 9233 | *
|
|---|
| 9234 | * **Note:** Unlike `_.remove`, this method returns a new array.
|
|---|
| 9235 | *
|
|---|
| 9236 | * @static
|
|---|
| 9237 | * @memberOf _
|
|---|
| 9238 | * @since 0.1.0
|
|---|
| 9239 | * @category Collection
|
|---|
| 9240 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9241 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 9242 | * @returns {Array} Returns the new filtered array.
|
|---|
| 9243 | * @see _.reject
|
|---|
| 9244 | * @example
|
|---|
| 9245 | *
|
|---|
| 9246 | * var users = [
|
|---|
| 9247 | * { 'user': 'barney', 'age': 36, 'active': true },
|
|---|
| 9248 | * { 'user': 'fred', 'age': 40, 'active': false }
|
|---|
| 9249 | * ];
|
|---|
| 9250 | *
|
|---|
| 9251 | * _.filter(users, function(o) { return !o.active; });
|
|---|
| 9252 | * // => objects for ['fred']
|
|---|
| 9253 | *
|
|---|
| 9254 | * // The `_.matches` iteratee shorthand.
|
|---|
| 9255 | * _.filter(users, { 'age': 36, 'active': true });
|
|---|
| 9256 | * // => objects for ['barney']
|
|---|
| 9257 | *
|
|---|
| 9258 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 9259 | * _.filter(users, ['active', false]);
|
|---|
| 9260 | * // => objects for ['fred']
|
|---|
| 9261 | *
|
|---|
| 9262 | * // The `_.property` iteratee shorthand.
|
|---|
| 9263 | * _.filter(users, 'active');
|
|---|
| 9264 | * // => objects for ['barney']
|
|---|
| 9265 | *
|
|---|
| 9266 | * // Combining several predicates using `_.overEvery` or `_.overSome`.
|
|---|
| 9267 | * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
|
|---|
| 9268 | * // => objects for ['fred', 'barney']
|
|---|
| 9269 | */
|
|---|
| 9270 | function filter(collection, predicate) {
|
|---|
| 9271 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
|---|
| 9272 | return func(collection, getIteratee(predicate, 3));
|
|---|
| 9273 | }
|
|---|
| 9274 |
|
|---|
| 9275 | /**
|
|---|
| 9276 | * Iterates over elements of `collection`, returning the first element
|
|---|
| 9277 | * `predicate` returns truthy for. The predicate is invoked with three
|
|---|
| 9278 | * arguments: (value, index|key, collection).
|
|---|
| 9279 | *
|
|---|
| 9280 | * @static
|
|---|
| 9281 | * @memberOf _
|
|---|
| 9282 | * @since 0.1.0
|
|---|
| 9283 | * @category Collection
|
|---|
| 9284 | * @param {Array|Object} collection The collection to inspect.
|
|---|
| 9285 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 9286 | * @param {number} [fromIndex=0] The index to search from.
|
|---|
| 9287 | * @returns {*} Returns the matched element, else `undefined`.
|
|---|
| 9288 | * @example
|
|---|
| 9289 | *
|
|---|
| 9290 | * var users = [
|
|---|
| 9291 | * { 'user': 'barney', 'age': 36, 'active': true },
|
|---|
| 9292 | * { 'user': 'fred', 'age': 40, 'active': false },
|
|---|
| 9293 | * { 'user': 'pebbles', 'age': 1, 'active': true }
|
|---|
| 9294 | * ];
|
|---|
| 9295 | *
|
|---|
| 9296 | * _.find(users, function(o) { return o.age < 40; });
|
|---|
| 9297 | * // => object for 'barney'
|
|---|
| 9298 | *
|
|---|
| 9299 | * // The `_.matches` iteratee shorthand.
|
|---|
| 9300 | * _.find(users, { 'age': 1, 'active': true });
|
|---|
| 9301 | * // => object for 'pebbles'
|
|---|
| 9302 | *
|
|---|
| 9303 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 9304 | * _.find(users, ['active', false]);
|
|---|
| 9305 | * // => object for 'fred'
|
|---|
| 9306 | *
|
|---|
| 9307 | * // The `_.property` iteratee shorthand.
|
|---|
| 9308 | * _.find(users, 'active');
|
|---|
| 9309 | * // => object for 'barney'
|
|---|
| 9310 | */
|
|---|
| 9311 | var find = createFind(findIndex);
|
|---|
| 9312 |
|
|---|
| 9313 | /**
|
|---|
| 9314 | * This method is like `_.find` except that it iterates over elements of
|
|---|
| 9315 | * `collection` from right to left.
|
|---|
| 9316 | *
|
|---|
| 9317 | * @static
|
|---|
| 9318 | * @memberOf _
|
|---|
| 9319 | * @since 2.0.0
|
|---|
| 9320 | * @category Collection
|
|---|
| 9321 | * @param {Array|Object} collection The collection to inspect.
|
|---|
| 9322 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 9323 | * @param {number} [fromIndex=collection.length-1] The index to search from.
|
|---|
| 9324 | * @returns {*} Returns the matched element, else `undefined`.
|
|---|
| 9325 | * @example
|
|---|
| 9326 | *
|
|---|
| 9327 | * _.findLast([1, 2, 3, 4], function(n) {
|
|---|
| 9328 | * return n % 2 == 1;
|
|---|
| 9329 | * });
|
|---|
| 9330 | * // => 3
|
|---|
| 9331 | */
|
|---|
| 9332 | var findLast = createFind(findLastIndex);
|
|---|
| 9333 |
|
|---|
| 9334 | /**
|
|---|
| 9335 | * Creates a flattened array of values by running each element in `collection`
|
|---|
| 9336 | * thru `iteratee` and flattening the mapped results. The iteratee is invoked
|
|---|
| 9337 | * with three arguments: (value, index|key, collection).
|
|---|
| 9338 | *
|
|---|
| 9339 | * @static
|
|---|
| 9340 | * @memberOf _
|
|---|
| 9341 | * @since 4.0.0
|
|---|
| 9342 | * @category Collection
|
|---|
| 9343 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9344 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9345 | * @returns {Array} Returns the new flattened array.
|
|---|
| 9346 | * @example
|
|---|
| 9347 | *
|
|---|
| 9348 | * function duplicate(n) {
|
|---|
| 9349 | * return [n, n];
|
|---|
| 9350 | * }
|
|---|
| 9351 | *
|
|---|
| 9352 | * _.flatMap([1, 2], duplicate);
|
|---|
| 9353 | * // => [1, 1, 2, 2]
|
|---|
| 9354 | */
|
|---|
| 9355 | function flatMap(collection, iteratee) {
|
|---|
| 9356 | return baseFlatten(map(collection, iteratee), 1);
|
|---|
| 9357 | }
|
|---|
| 9358 |
|
|---|
| 9359 | /**
|
|---|
| 9360 | * This method is like `_.flatMap` except that it recursively flattens the
|
|---|
| 9361 | * mapped results.
|
|---|
| 9362 | *
|
|---|
| 9363 | * @static
|
|---|
| 9364 | * @memberOf _
|
|---|
| 9365 | * @since 4.7.0
|
|---|
| 9366 | * @category Collection
|
|---|
| 9367 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9368 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9369 | * @returns {Array} Returns the new flattened array.
|
|---|
| 9370 | * @example
|
|---|
| 9371 | *
|
|---|
| 9372 | * function duplicate(n) {
|
|---|
| 9373 | * return [[[n, n]]];
|
|---|
| 9374 | * }
|
|---|
| 9375 | *
|
|---|
| 9376 | * _.flatMapDeep([1, 2], duplicate);
|
|---|
| 9377 | * // => [1, 1, 2, 2]
|
|---|
| 9378 | */
|
|---|
| 9379 | function flatMapDeep(collection, iteratee) {
|
|---|
| 9380 | return baseFlatten(map(collection, iteratee), INFINITY);
|
|---|
| 9381 | }
|
|---|
| 9382 |
|
|---|
| 9383 | /**
|
|---|
| 9384 | * This method is like `_.flatMap` except that it recursively flattens the
|
|---|
| 9385 | * mapped results up to `depth` times.
|
|---|
| 9386 | *
|
|---|
| 9387 | * @static
|
|---|
| 9388 | * @memberOf _
|
|---|
| 9389 | * @since 4.7.0
|
|---|
| 9390 | * @category Collection
|
|---|
| 9391 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9392 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9393 | * @param {number} [depth=1] The maximum recursion depth.
|
|---|
| 9394 | * @returns {Array} Returns the new flattened array.
|
|---|
| 9395 | * @example
|
|---|
| 9396 | *
|
|---|
| 9397 | * function duplicate(n) {
|
|---|
| 9398 | * return [[[n, n]]];
|
|---|
| 9399 | * }
|
|---|
| 9400 | *
|
|---|
| 9401 | * _.flatMapDepth([1, 2], duplicate, 2);
|
|---|
| 9402 | * // => [[1, 1], [2, 2]]
|
|---|
| 9403 | */
|
|---|
| 9404 | function flatMapDepth(collection, iteratee, depth) {
|
|---|
| 9405 | depth = depth === undefined ? 1 : toInteger(depth);
|
|---|
| 9406 | return baseFlatten(map(collection, iteratee), depth);
|
|---|
| 9407 | }
|
|---|
| 9408 |
|
|---|
| 9409 | /**
|
|---|
| 9410 | * Iterates over elements of `collection` and invokes `iteratee` for each element.
|
|---|
| 9411 | * The iteratee is invoked with three arguments: (value, index|key, collection).
|
|---|
| 9412 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
|---|
| 9413 | *
|
|---|
| 9414 | * **Note:** As with other "Collections" methods, objects with a "length"
|
|---|
| 9415 | * property are iterated like arrays. To avoid this behavior use `_.forIn`
|
|---|
| 9416 | * or `_.forOwn` for object iteration.
|
|---|
| 9417 | *
|
|---|
| 9418 | * @static
|
|---|
| 9419 | * @memberOf _
|
|---|
| 9420 | * @since 0.1.0
|
|---|
| 9421 | * @alias each
|
|---|
| 9422 | * @category Collection
|
|---|
| 9423 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9424 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9425 | * @returns {Array|Object} Returns `collection`.
|
|---|
| 9426 | * @see _.forEachRight
|
|---|
| 9427 | * @example
|
|---|
| 9428 | *
|
|---|
| 9429 | * _.forEach([1, 2], function(value) {
|
|---|
| 9430 | * console.log(value);
|
|---|
| 9431 | * });
|
|---|
| 9432 | * // => Logs `1` then `2`.
|
|---|
| 9433 | *
|
|---|
| 9434 | * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
|
|---|
| 9435 | * console.log(key);
|
|---|
| 9436 | * });
|
|---|
| 9437 | * // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
|---|
| 9438 | */
|
|---|
| 9439 | function forEach(collection, iteratee) {
|
|---|
| 9440 | var func = isArray(collection) ? arrayEach : baseEach;
|
|---|
| 9441 | return func(collection, getIteratee(iteratee, 3));
|
|---|
| 9442 | }
|
|---|
| 9443 |
|
|---|
| 9444 | /**
|
|---|
| 9445 | * This method is like `_.forEach` except that it iterates over elements of
|
|---|
| 9446 | * `collection` from right to left.
|
|---|
| 9447 | *
|
|---|
| 9448 | * @static
|
|---|
| 9449 | * @memberOf _
|
|---|
| 9450 | * @since 2.0.0
|
|---|
| 9451 | * @alias eachRight
|
|---|
| 9452 | * @category Collection
|
|---|
| 9453 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9454 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9455 | * @returns {Array|Object} Returns `collection`.
|
|---|
| 9456 | * @see _.forEach
|
|---|
| 9457 | * @example
|
|---|
| 9458 | *
|
|---|
| 9459 | * _.forEachRight([1, 2], function(value) {
|
|---|
| 9460 | * console.log(value);
|
|---|
| 9461 | * });
|
|---|
| 9462 | * // => Logs `2` then `1`.
|
|---|
| 9463 | */
|
|---|
| 9464 | function forEachRight(collection, iteratee) {
|
|---|
| 9465 | var func = isArray(collection) ? arrayEachRight : baseEachRight;
|
|---|
| 9466 | return func(collection, getIteratee(iteratee, 3));
|
|---|
| 9467 | }
|
|---|
| 9468 |
|
|---|
| 9469 | /**
|
|---|
| 9470 | * Creates an object composed of keys generated from the results of running
|
|---|
| 9471 | * each element of `collection` thru `iteratee`. The order of grouped values
|
|---|
| 9472 | * is determined by the order they occur in `collection`. The corresponding
|
|---|
| 9473 | * value of each key is an array of elements responsible for generating the
|
|---|
| 9474 | * key. The iteratee is invoked with one argument: (value).
|
|---|
| 9475 | *
|
|---|
| 9476 | * @static
|
|---|
| 9477 | * @memberOf _
|
|---|
| 9478 | * @since 0.1.0
|
|---|
| 9479 | * @category Collection
|
|---|
| 9480 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9481 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
|---|
| 9482 | * @returns {Object} Returns the composed aggregate object.
|
|---|
| 9483 | * @example
|
|---|
| 9484 | *
|
|---|
| 9485 | * _.groupBy([6.1, 4.2, 6.3], Math.floor);
|
|---|
| 9486 | * // => { '4': [4.2], '6': [6.1, 6.3] }
|
|---|
| 9487 | *
|
|---|
| 9488 | * // The `_.property` iteratee shorthand.
|
|---|
| 9489 | * _.groupBy(['one', 'two', 'three'], 'length');
|
|---|
| 9490 | * // => { '3': ['one', 'two'], '5': ['three'] }
|
|---|
| 9491 | */
|
|---|
| 9492 | var groupBy = createAggregator(function(result, value, key) {
|
|---|
| 9493 | if (hasOwnProperty.call(result, key)) {
|
|---|
| 9494 | result[key].push(value);
|
|---|
| 9495 | } else {
|
|---|
| 9496 | baseAssignValue(result, key, [value]);
|
|---|
| 9497 | }
|
|---|
| 9498 | });
|
|---|
| 9499 |
|
|---|
| 9500 | /**
|
|---|
| 9501 | * Checks if `value` is in `collection`. If `collection` is a string, it's
|
|---|
| 9502 | * checked for a substring of `value`, otherwise
|
|---|
| 9503 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 9504 | * is used for equality comparisons. If `fromIndex` is negative, it's used as
|
|---|
| 9505 | * the offset from the end of `collection`.
|
|---|
| 9506 | *
|
|---|
| 9507 | * @static
|
|---|
| 9508 | * @memberOf _
|
|---|
| 9509 | * @since 0.1.0
|
|---|
| 9510 | * @category Collection
|
|---|
| 9511 | * @param {Array|Object|string} collection The collection to inspect.
|
|---|
| 9512 | * @param {*} value The value to search for.
|
|---|
| 9513 | * @param {number} [fromIndex=0] The index to search from.
|
|---|
| 9514 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
|---|
| 9515 | * @returns {boolean} Returns `true` if `value` is found, else `false`.
|
|---|
| 9516 | * @example
|
|---|
| 9517 | *
|
|---|
| 9518 | * _.includes([1, 2, 3], 1);
|
|---|
| 9519 | * // => true
|
|---|
| 9520 | *
|
|---|
| 9521 | * _.includes([1, 2, 3], 1, 2);
|
|---|
| 9522 | * // => false
|
|---|
| 9523 | *
|
|---|
| 9524 | * _.includes({ 'a': 1, 'b': 2 }, 1);
|
|---|
| 9525 | * // => true
|
|---|
| 9526 | *
|
|---|
| 9527 | * _.includes('abcd', 'bc');
|
|---|
| 9528 | * // => true
|
|---|
| 9529 | */
|
|---|
| 9530 | function includes(collection, value, fromIndex, guard) {
|
|---|
| 9531 | collection = isArrayLike(collection) ? collection : values(collection);
|
|---|
| 9532 | fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
|
|---|
| 9533 |
|
|---|
| 9534 | var length = collection.length;
|
|---|
| 9535 | if (fromIndex < 0) {
|
|---|
| 9536 | fromIndex = nativeMax(length + fromIndex, 0);
|
|---|
| 9537 | }
|
|---|
| 9538 | return isString(collection)
|
|---|
| 9539 | ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
|
|---|
| 9540 | : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
|
|---|
| 9541 | }
|
|---|
| 9542 |
|
|---|
| 9543 | /**
|
|---|
| 9544 | * Invokes the method at `path` of each element in `collection`, returning
|
|---|
| 9545 | * an array of the results of each invoked method. Any additional arguments
|
|---|
| 9546 | * are provided to each invoked method. If `path` is a function, it's invoked
|
|---|
| 9547 | * for, and `this` bound to, each element in `collection`.
|
|---|
| 9548 | *
|
|---|
| 9549 | * @static
|
|---|
| 9550 | * @memberOf _
|
|---|
| 9551 | * @since 4.0.0
|
|---|
| 9552 | * @category Collection
|
|---|
| 9553 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9554 | * @param {Array|Function|string} path The path of the method to invoke or
|
|---|
| 9555 | * the function invoked per iteration.
|
|---|
| 9556 | * @param {...*} [args] The arguments to invoke each method with.
|
|---|
| 9557 | * @returns {Array} Returns the array of results.
|
|---|
| 9558 | * @example
|
|---|
| 9559 | *
|
|---|
| 9560 | * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
|
|---|
| 9561 | * // => [[1, 5, 7], [1, 2, 3]]
|
|---|
| 9562 | *
|
|---|
| 9563 | * _.invokeMap([123, 456], String.prototype.split, '');
|
|---|
| 9564 | * // => [['1', '2', '3'], ['4', '5', '6']]
|
|---|
| 9565 | */
|
|---|
| 9566 | var invokeMap = baseRest(function(collection, path, args) {
|
|---|
| 9567 | var index = -1,
|
|---|
| 9568 | isFunc = typeof path == 'function',
|
|---|
| 9569 | result = isArrayLike(collection) ? Array(collection.length) : [];
|
|---|
| 9570 |
|
|---|
| 9571 | baseEach(collection, function(value) {
|
|---|
| 9572 | result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
|
|---|
| 9573 | });
|
|---|
| 9574 | return result;
|
|---|
| 9575 | });
|
|---|
| 9576 |
|
|---|
| 9577 | /**
|
|---|
| 9578 | * Creates an object composed of keys generated from the results of running
|
|---|
| 9579 | * each element of `collection` thru `iteratee`. The corresponding value of
|
|---|
| 9580 | * each key is the last element responsible for generating the key. The
|
|---|
| 9581 | * iteratee is invoked with one argument: (value).
|
|---|
| 9582 | *
|
|---|
| 9583 | * @static
|
|---|
| 9584 | * @memberOf _
|
|---|
| 9585 | * @since 4.0.0
|
|---|
| 9586 | * @category Collection
|
|---|
| 9587 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9588 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
|---|
| 9589 | * @returns {Object} Returns the composed aggregate object.
|
|---|
| 9590 | * @example
|
|---|
| 9591 | *
|
|---|
| 9592 | * var array = [
|
|---|
| 9593 | * { 'dir': 'left', 'code': 97 },
|
|---|
| 9594 | * { 'dir': 'right', 'code': 100 }
|
|---|
| 9595 | * ];
|
|---|
| 9596 | *
|
|---|
| 9597 | * _.keyBy(array, function(o) {
|
|---|
| 9598 | * return String.fromCharCode(o.code);
|
|---|
| 9599 | * });
|
|---|
| 9600 | * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
|---|
| 9601 | *
|
|---|
| 9602 | * _.keyBy(array, 'dir');
|
|---|
| 9603 | * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
|---|
| 9604 | */
|
|---|
| 9605 | var keyBy = createAggregator(function(result, value, key) {
|
|---|
| 9606 | baseAssignValue(result, key, value);
|
|---|
| 9607 | });
|
|---|
| 9608 |
|
|---|
| 9609 | /**
|
|---|
| 9610 | * Creates an array of values by running each element in `collection` thru
|
|---|
| 9611 | * `iteratee`. The iteratee is invoked with three arguments:
|
|---|
| 9612 | * (value, index|key, collection).
|
|---|
| 9613 | *
|
|---|
| 9614 | * Many lodash methods are guarded to work as iteratees for methods like
|
|---|
| 9615 | * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
|---|
| 9616 | *
|
|---|
| 9617 | * The guarded methods are:
|
|---|
| 9618 | * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
|
|---|
| 9619 | * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
|
|---|
| 9620 | * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
|
|---|
| 9621 | * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
|
|---|
| 9622 | *
|
|---|
| 9623 | * @static
|
|---|
| 9624 | * @memberOf _
|
|---|
| 9625 | * @since 0.1.0
|
|---|
| 9626 | * @category Collection
|
|---|
| 9627 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9628 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9629 | * @returns {Array} Returns the new mapped array.
|
|---|
| 9630 | * @example
|
|---|
| 9631 | *
|
|---|
| 9632 | * function square(n) {
|
|---|
| 9633 | * return n * n;
|
|---|
| 9634 | * }
|
|---|
| 9635 | *
|
|---|
| 9636 | * _.map([4, 8], square);
|
|---|
| 9637 | * // => [16, 64]
|
|---|
| 9638 | *
|
|---|
| 9639 | * _.map({ 'a': 4, 'b': 8 }, square);
|
|---|
| 9640 | * // => [16, 64] (iteration order is not guaranteed)
|
|---|
| 9641 | *
|
|---|
| 9642 | * var users = [
|
|---|
| 9643 | * { 'user': 'barney' },
|
|---|
| 9644 | * { 'user': 'fred' }
|
|---|
| 9645 | * ];
|
|---|
| 9646 | *
|
|---|
| 9647 | * // The `_.property` iteratee shorthand.
|
|---|
| 9648 | * _.map(users, 'user');
|
|---|
| 9649 | * // => ['barney', 'fred']
|
|---|
| 9650 | */
|
|---|
| 9651 | function map(collection, iteratee) {
|
|---|
| 9652 | var func = isArray(collection) ? arrayMap : baseMap;
|
|---|
| 9653 | return func(collection, getIteratee(iteratee, 3));
|
|---|
| 9654 | }
|
|---|
| 9655 |
|
|---|
| 9656 | /**
|
|---|
| 9657 | * This method is like `_.sortBy` except that it allows specifying the sort
|
|---|
| 9658 | * orders of the iteratees to sort by. If `orders` is unspecified, all values
|
|---|
| 9659 | * are sorted in ascending order. Otherwise, specify an order of "desc" for
|
|---|
| 9660 | * descending or "asc" for ascending sort order of corresponding values.
|
|---|
| 9661 | *
|
|---|
| 9662 | * @static
|
|---|
| 9663 | * @memberOf _
|
|---|
| 9664 | * @since 4.0.0
|
|---|
| 9665 | * @category Collection
|
|---|
| 9666 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9667 | * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
|
|---|
| 9668 | * The iteratees to sort by.
|
|---|
| 9669 | * @param {string[]} [orders] The sort orders of `iteratees`.
|
|---|
| 9670 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
|---|
| 9671 | * @returns {Array} Returns the new sorted array.
|
|---|
| 9672 | * @example
|
|---|
| 9673 | *
|
|---|
| 9674 | * var users = [
|
|---|
| 9675 | * { 'user': 'fred', 'age': 48 },
|
|---|
| 9676 | * { 'user': 'barney', 'age': 34 },
|
|---|
| 9677 | * { 'user': 'fred', 'age': 40 },
|
|---|
| 9678 | * { 'user': 'barney', 'age': 36 }
|
|---|
| 9679 | * ];
|
|---|
| 9680 | *
|
|---|
| 9681 | * // Sort by `user` in ascending order and by `age` in descending order.
|
|---|
| 9682 | * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
|
|---|
| 9683 | * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
|---|
| 9684 | */
|
|---|
| 9685 | function orderBy(collection, iteratees, orders, guard) {
|
|---|
| 9686 | if (collection == null) {
|
|---|
| 9687 | return [];
|
|---|
| 9688 | }
|
|---|
| 9689 | if (!isArray(iteratees)) {
|
|---|
| 9690 | iteratees = iteratees == null ? [] : [iteratees];
|
|---|
| 9691 | }
|
|---|
| 9692 | orders = guard ? undefined : orders;
|
|---|
| 9693 | if (!isArray(orders)) {
|
|---|
| 9694 | orders = orders == null ? [] : [orders];
|
|---|
| 9695 | }
|
|---|
| 9696 | return baseOrderBy(collection, iteratees, orders);
|
|---|
| 9697 | }
|
|---|
| 9698 |
|
|---|
| 9699 | /**
|
|---|
| 9700 | * Creates an array of elements split into two groups, the first of which
|
|---|
| 9701 | * contains elements `predicate` returns truthy for, the second of which
|
|---|
| 9702 | * contains elements `predicate` returns falsey for. The predicate is
|
|---|
| 9703 | * invoked with one argument: (value).
|
|---|
| 9704 | *
|
|---|
| 9705 | * @static
|
|---|
| 9706 | * @memberOf _
|
|---|
| 9707 | * @since 3.0.0
|
|---|
| 9708 | * @category Collection
|
|---|
| 9709 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9710 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 9711 | * @returns {Array} Returns the array of grouped elements.
|
|---|
| 9712 | * @example
|
|---|
| 9713 | *
|
|---|
| 9714 | * var users = [
|
|---|
| 9715 | * { 'user': 'barney', 'age': 36, 'active': false },
|
|---|
| 9716 | * { 'user': 'fred', 'age': 40, 'active': true },
|
|---|
| 9717 | * { 'user': 'pebbles', 'age': 1, 'active': false }
|
|---|
| 9718 | * ];
|
|---|
| 9719 | *
|
|---|
| 9720 | * _.partition(users, function(o) { return o.active; });
|
|---|
| 9721 | * // => objects for [['fred'], ['barney', 'pebbles']]
|
|---|
| 9722 | *
|
|---|
| 9723 | * // The `_.matches` iteratee shorthand.
|
|---|
| 9724 | * _.partition(users, { 'age': 1, 'active': false });
|
|---|
| 9725 | * // => objects for [['pebbles'], ['barney', 'fred']]
|
|---|
| 9726 | *
|
|---|
| 9727 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 9728 | * _.partition(users, ['active', false]);
|
|---|
| 9729 | * // => objects for [['barney', 'pebbles'], ['fred']]
|
|---|
| 9730 | *
|
|---|
| 9731 | * // The `_.property` iteratee shorthand.
|
|---|
| 9732 | * _.partition(users, 'active');
|
|---|
| 9733 | * // => objects for [['fred'], ['barney', 'pebbles']]
|
|---|
| 9734 | */
|
|---|
| 9735 | var partition = createAggregator(function(result, value, key) {
|
|---|
| 9736 | result[key ? 0 : 1].push(value);
|
|---|
| 9737 | }, function() { return [[], []]; });
|
|---|
| 9738 |
|
|---|
| 9739 | /**
|
|---|
| 9740 | * Reduces `collection` to a value which is the accumulated result of running
|
|---|
| 9741 | * each element in `collection` thru `iteratee`, where each successive
|
|---|
| 9742 | * invocation is supplied the return value of the previous. If `accumulator`
|
|---|
| 9743 | * is not given, the first element of `collection` is used as the initial
|
|---|
| 9744 | * value. The iteratee is invoked with four arguments:
|
|---|
| 9745 | * (accumulator, value, index|key, collection).
|
|---|
| 9746 | *
|
|---|
| 9747 | * Many lodash methods are guarded to work as iteratees for methods like
|
|---|
| 9748 | * `_.reduce`, `_.reduceRight`, and `_.transform`.
|
|---|
| 9749 | *
|
|---|
| 9750 | * The guarded methods are:
|
|---|
| 9751 | * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
|
|---|
| 9752 | * and `sortBy`
|
|---|
| 9753 | *
|
|---|
| 9754 | * @static
|
|---|
| 9755 | * @memberOf _
|
|---|
| 9756 | * @since 0.1.0
|
|---|
| 9757 | * @category Collection
|
|---|
| 9758 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9759 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9760 | * @param {*} [accumulator] The initial value.
|
|---|
| 9761 | * @returns {*} Returns the accumulated value.
|
|---|
| 9762 | * @see _.reduceRight
|
|---|
| 9763 | * @example
|
|---|
| 9764 | *
|
|---|
| 9765 | * _.reduce([1, 2], function(sum, n) {
|
|---|
| 9766 | * return sum + n;
|
|---|
| 9767 | * }, 0);
|
|---|
| 9768 | * // => 3
|
|---|
| 9769 | *
|
|---|
| 9770 | * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
|---|
| 9771 | * (result[value] || (result[value] = [])).push(key);
|
|---|
| 9772 | * return result;
|
|---|
| 9773 | * }, {});
|
|---|
| 9774 | * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
|
|---|
| 9775 | */
|
|---|
| 9776 | function reduce(collection, iteratee, accumulator) {
|
|---|
| 9777 | var func = isArray(collection) ? arrayReduce : baseReduce,
|
|---|
| 9778 | initAccum = arguments.length < 3;
|
|---|
| 9779 |
|
|---|
| 9780 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
|
|---|
| 9781 | }
|
|---|
| 9782 |
|
|---|
| 9783 | /**
|
|---|
| 9784 | * This method is like `_.reduce` except that it iterates over elements of
|
|---|
| 9785 | * `collection` from right to left.
|
|---|
| 9786 | *
|
|---|
| 9787 | * @static
|
|---|
| 9788 | * @memberOf _
|
|---|
| 9789 | * @since 0.1.0
|
|---|
| 9790 | * @category Collection
|
|---|
| 9791 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9792 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 9793 | * @param {*} [accumulator] The initial value.
|
|---|
| 9794 | * @returns {*} Returns the accumulated value.
|
|---|
| 9795 | * @see _.reduce
|
|---|
| 9796 | * @example
|
|---|
| 9797 | *
|
|---|
| 9798 | * var array = [[0, 1], [2, 3], [4, 5]];
|
|---|
| 9799 | *
|
|---|
| 9800 | * _.reduceRight(array, function(flattened, other) {
|
|---|
| 9801 | * return flattened.concat(other);
|
|---|
| 9802 | * }, []);
|
|---|
| 9803 | * // => [4, 5, 2, 3, 0, 1]
|
|---|
| 9804 | */
|
|---|
| 9805 | function reduceRight(collection, iteratee, accumulator) {
|
|---|
| 9806 | var func = isArray(collection) ? arrayReduceRight : baseReduce,
|
|---|
| 9807 | initAccum = arguments.length < 3;
|
|---|
| 9808 |
|
|---|
| 9809 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
|
|---|
| 9810 | }
|
|---|
| 9811 |
|
|---|
| 9812 | /**
|
|---|
| 9813 | * The opposite of `_.filter`; this method returns the elements of `collection`
|
|---|
| 9814 | * that `predicate` does **not** return truthy for.
|
|---|
| 9815 | *
|
|---|
| 9816 | * @static
|
|---|
| 9817 | * @memberOf _
|
|---|
| 9818 | * @since 0.1.0
|
|---|
| 9819 | * @category Collection
|
|---|
| 9820 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9821 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 9822 | * @returns {Array} Returns the new filtered array.
|
|---|
| 9823 | * @see _.filter
|
|---|
| 9824 | * @example
|
|---|
| 9825 | *
|
|---|
| 9826 | * var users = [
|
|---|
| 9827 | * { 'user': 'barney', 'age': 36, 'active': false },
|
|---|
| 9828 | * { 'user': 'fred', 'age': 40, 'active': true }
|
|---|
| 9829 | * ];
|
|---|
| 9830 | *
|
|---|
| 9831 | * _.reject(users, function(o) { return !o.active; });
|
|---|
| 9832 | * // => objects for ['fred']
|
|---|
| 9833 | *
|
|---|
| 9834 | * // The `_.matches` iteratee shorthand.
|
|---|
| 9835 | * _.reject(users, { 'age': 40, 'active': true });
|
|---|
| 9836 | * // => objects for ['barney']
|
|---|
| 9837 | *
|
|---|
| 9838 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 9839 | * _.reject(users, ['active', false]);
|
|---|
| 9840 | * // => objects for ['fred']
|
|---|
| 9841 | *
|
|---|
| 9842 | * // The `_.property` iteratee shorthand.
|
|---|
| 9843 | * _.reject(users, 'active');
|
|---|
| 9844 | * // => objects for ['barney']
|
|---|
| 9845 | */
|
|---|
| 9846 | function reject(collection, predicate) {
|
|---|
| 9847 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
|---|
| 9848 | return func(collection, negate(getIteratee(predicate, 3)));
|
|---|
| 9849 | }
|
|---|
| 9850 |
|
|---|
| 9851 | /**
|
|---|
| 9852 | * Gets a random element from `collection`.
|
|---|
| 9853 | *
|
|---|
| 9854 | * @static
|
|---|
| 9855 | * @memberOf _
|
|---|
| 9856 | * @since 2.0.0
|
|---|
| 9857 | * @category Collection
|
|---|
| 9858 | * @param {Array|Object} collection The collection to sample.
|
|---|
| 9859 | * @returns {*} Returns the random element.
|
|---|
| 9860 | * @example
|
|---|
| 9861 | *
|
|---|
| 9862 | * _.sample([1, 2, 3, 4]);
|
|---|
| 9863 | * // => 2
|
|---|
| 9864 | */
|
|---|
| 9865 | function sample(collection) {
|
|---|
| 9866 | var func = isArray(collection) ? arraySample : baseSample;
|
|---|
| 9867 | return func(collection);
|
|---|
| 9868 | }
|
|---|
| 9869 |
|
|---|
| 9870 | /**
|
|---|
| 9871 | * Gets `n` random elements at unique keys from `collection` up to the
|
|---|
| 9872 | * size of `collection`.
|
|---|
| 9873 | *
|
|---|
| 9874 | * @static
|
|---|
| 9875 | * @memberOf _
|
|---|
| 9876 | * @since 4.0.0
|
|---|
| 9877 | * @category Collection
|
|---|
| 9878 | * @param {Array|Object} collection The collection to sample.
|
|---|
| 9879 | * @param {number} [n=1] The number of elements to sample.
|
|---|
| 9880 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 9881 | * @returns {Array} Returns the random elements.
|
|---|
| 9882 | * @example
|
|---|
| 9883 | *
|
|---|
| 9884 | * _.sampleSize([1, 2, 3], 2);
|
|---|
| 9885 | * // => [3, 1]
|
|---|
| 9886 | *
|
|---|
| 9887 | * _.sampleSize([1, 2, 3], 4);
|
|---|
| 9888 | * // => [2, 3, 1]
|
|---|
| 9889 | */
|
|---|
| 9890 | function sampleSize(collection, n, guard) {
|
|---|
| 9891 | if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
|
|---|
| 9892 | n = 1;
|
|---|
| 9893 | } else {
|
|---|
| 9894 | n = toInteger(n);
|
|---|
| 9895 | }
|
|---|
| 9896 | var func = isArray(collection) ? arraySampleSize : baseSampleSize;
|
|---|
| 9897 | return func(collection, n);
|
|---|
| 9898 | }
|
|---|
| 9899 |
|
|---|
| 9900 | /**
|
|---|
| 9901 | * Creates an array of shuffled values, using a version of the
|
|---|
| 9902 | * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|---|
| 9903 | *
|
|---|
| 9904 | * @static
|
|---|
| 9905 | * @memberOf _
|
|---|
| 9906 | * @since 0.1.0
|
|---|
| 9907 | * @category Collection
|
|---|
| 9908 | * @param {Array|Object} collection The collection to shuffle.
|
|---|
| 9909 | * @returns {Array} Returns the new shuffled array.
|
|---|
| 9910 | * @example
|
|---|
| 9911 | *
|
|---|
| 9912 | * _.shuffle([1, 2, 3, 4]);
|
|---|
| 9913 | * // => [4, 1, 3, 2]
|
|---|
| 9914 | */
|
|---|
| 9915 | function shuffle(collection) {
|
|---|
| 9916 | var func = isArray(collection) ? arrayShuffle : baseShuffle;
|
|---|
| 9917 | return func(collection);
|
|---|
| 9918 | }
|
|---|
| 9919 |
|
|---|
| 9920 | /**
|
|---|
| 9921 | * Gets the size of `collection` by returning its length for array-like
|
|---|
| 9922 | * values or the number of own enumerable string keyed properties for objects.
|
|---|
| 9923 | *
|
|---|
| 9924 | * @static
|
|---|
| 9925 | * @memberOf _
|
|---|
| 9926 | * @since 0.1.0
|
|---|
| 9927 | * @category Collection
|
|---|
| 9928 | * @param {Array|Object|string} collection The collection to inspect.
|
|---|
| 9929 | * @returns {number} Returns the collection size.
|
|---|
| 9930 | * @example
|
|---|
| 9931 | *
|
|---|
| 9932 | * _.size([1, 2, 3]);
|
|---|
| 9933 | * // => 3
|
|---|
| 9934 | *
|
|---|
| 9935 | * _.size({ 'a': 1, 'b': 2 });
|
|---|
| 9936 | * // => 2
|
|---|
| 9937 | *
|
|---|
| 9938 | * _.size('pebbles');
|
|---|
| 9939 | * // => 7
|
|---|
| 9940 | */
|
|---|
| 9941 | function size(collection) {
|
|---|
| 9942 | if (collection == null) {
|
|---|
| 9943 | return 0;
|
|---|
| 9944 | }
|
|---|
| 9945 | if (isArrayLike(collection)) {
|
|---|
| 9946 | return isString(collection) ? stringSize(collection) : collection.length;
|
|---|
| 9947 | }
|
|---|
| 9948 | var tag = getTag(collection);
|
|---|
| 9949 | if (tag == mapTag || tag == setTag) {
|
|---|
| 9950 | return collection.size;
|
|---|
| 9951 | }
|
|---|
| 9952 | return baseKeys(collection).length;
|
|---|
| 9953 | }
|
|---|
| 9954 |
|
|---|
| 9955 | /**
|
|---|
| 9956 | * Checks if `predicate` returns truthy for **any** element of `collection`.
|
|---|
| 9957 | * Iteration is stopped once `predicate` returns truthy. The predicate is
|
|---|
| 9958 | * invoked with three arguments: (value, index|key, collection).
|
|---|
| 9959 | *
|
|---|
| 9960 | * @static
|
|---|
| 9961 | * @memberOf _
|
|---|
| 9962 | * @since 0.1.0
|
|---|
| 9963 | * @category Collection
|
|---|
| 9964 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 9965 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 9966 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 9967 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
|---|
| 9968 | * else `false`.
|
|---|
| 9969 | * @example
|
|---|
| 9970 | *
|
|---|
| 9971 | * _.some([null, 0, 'yes', false], Boolean);
|
|---|
| 9972 | * // => true
|
|---|
| 9973 | *
|
|---|
| 9974 | * var users = [
|
|---|
| 9975 | * { 'user': 'barney', 'active': true },
|
|---|
| 9976 | * { 'user': 'fred', 'active': false }
|
|---|
| 9977 | * ];
|
|---|
| 9978 | *
|
|---|
| 9979 | * // The `_.matches` iteratee shorthand.
|
|---|
| 9980 | * _.some(users, { 'user': 'barney', 'active': false });
|
|---|
| 9981 | * // => false
|
|---|
| 9982 | *
|
|---|
| 9983 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 9984 | * _.some(users, ['active', false]);
|
|---|
| 9985 | * // => true
|
|---|
| 9986 | *
|
|---|
| 9987 | * // The `_.property` iteratee shorthand.
|
|---|
| 9988 | * _.some(users, 'active');
|
|---|
| 9989 | * // => true
|
|---|
| 9990 | */
|
|---|
| 9991 | function some(collection, predicate, guard) {
|
|---|
| 9992 | var func = isArray(collection) ? arraySome : baseSome;
|
|---|
| 9993 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
|---|
| 9994 | predicate = undefined;
|
|---|
| 9995 | }
|
|---|
| 9996 | return func(collection, getIteratee(predicate, 3));
|
|---|
| 9997 | }
|
|---|
| 9998 |
|
|---|
| 9999 | /**
|
|---|
| 10000 | * Creates an array of elements, sorted in ascending order by the results of
|
|---|
| 10001 | * running each element in a collection thru each iteratee. This method
|
|---|
| 10002 | * performs a stable sort, that is, it preserves the original sort order of
|
|---|
| 10003 | * equal elements. The iteratees are invoked with one argument: (value).
|
|---|
| 10004 | *
|
|---|
| 10005 | * @static
|
|---|
| 10006 | * @memberOf _
|
|---|
| 10007 | * @since 0.1.0
|
|---|
| 10008 | * @category Collection
|
|---|
| 10009 | * @param {Array|Object} collection The collection to iterate over.
|
|---|
| 10010 | * @param {...(Function|Function[])} [iteratees=[_.identity]]
|
|---|
| 10011 | * The iteratees to sort by.
|
|---|
| 10012 | * @returns {Array} Returns the new sorted array.
|
|---|
| 10013 | * @example
|
|---|
| 10014 | *
|
|---|
| 10015 | * var users = [
|
|---|
| 10016 | * { 'user': 'fred', 'age': 48 },
|
|---|
| 10017 | * { 'user': 'barney', 'age': 36 },
|
|---|
| 10018 | * { 'user': 'fred', 'age': 30 },
|
|---|
| 10019 | * { 'user': 'barney', 'age': 34 }
|
|---|
| 10020 | * ];
|
|---|
| 10021 | *
|
|---|
| 10022 | * _.sortBy(users, [function(o) { return o.user; }]);
|
|---|
| 10023 | * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
|
|---|
| 10024 | *
|
|---|
| 10025 | * _.sortBy(users, ['user', 'age']);
|
|---|
| 10026 | * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
|
|---|
| 10027 | */
|
|---|
| 10028 | var sortBy = baseRest(function(collection, iteratees) {
|
|---|
| 10029 | if (collection == null) {
|
|---|
| 10030 | return [];
|
|---|
| 10031 | }
|
|---|
| 10032 | var length = iteratees.length;
|
|---|
| 10033 | if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
|
|---|
| 10034 | iteratees = [];
|
|---|
| 10035 | } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
|
|---|
| 10036 | iteratees = [iteratees[0]];
|
|---|
| 10037 | }
|
|---|
| 10038 | return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
|
|---|
| 10039 | });
|
|---|
| 10040 |
|
|---|
| 10041 | /*------------------------------------------------------------------------*/
|
|---|
| 10042 |
|
|---|
| 10043 | /**
|
|---|
| 10044 | * Gets the timestamp of the number of milliseconds that have elapsed since
|
|---|
| 10045 | * the Unix epoch (1 January 1970 00:00:00 UTC).
|
|---|
| 10046 | *
|
|---|
| 10047 | * @static
|
|---|
| 10048 | * @memberOf _
|
|---|
| 10049 | * @since 2.4.0
|
|---|
| 10050 | * @category Date
|
|---|
| 10051 | * @returns {number} Returns the timestamp.
|
|---|
| 10052 | * @example
|
|---|
| 10053 | *
|
|---|
| 10054 | * _.defer(function(stamp) {
|
|---|
| 10055 | * console.log(_.now() - stamp);
|
|---|
| 10056 | * }, _.now());
|
|---|
| 10057 | * // => Logs the number of milliseconds it took for the deferred invocation.
|
|---|
| 10058 | */
|
|---|
| 10059 | var now = ctxNow || function() {
|
|---|
| 10060 | return root.Date.now();
|
|---|
| 10061 | };
|
|---|
| 10062 |
|
|---|
| 10063 | /*------------------------------------------------------------------------*/
|
|---|
| 10064 |
|
|---|
| 10065 | /**
|
|---|
| 10066 | * The opposite of `_.before`; this method creates a function that invokes
|
|---|
| 10067 | * `func` once it's called `n` or more times.
|
|---|
| 10068 | *
|
|---|
| 10069 | * @static
|
|---|
| 10070 | * @memberOf _
|
|---|
| 10071 | * @since 0.1.0
|
|---|
| 10072 | * @category Function
|
|---|
| 10073 | * @param {number} n The number of calls before `func` is invoked.
|
|---|
| 10074 | * @param {Function} func The function to restrict.
|
|---|
| 10075 | * @returns {Function} Returns the new restricted function.
|
|---|
| 10076 | * @example
|
|---|
| 10077 | *
|
|---|
| 10078 | * var saves = ['profile', 'settings'];
|
|---|
| 10079 | *
|
|---|
| 10080 | * var done = _.after(saves.length, function() {
|
|---|
| 10081 | * console.log('done saving!');
|
|---|
| 10082 | * });
|
|---|
| 10083 | *
|
|---|
| 10084 | * _.forEach(saves, function(type) {
|
|---|
| 10085 | * asyncSave({ 'type': type, 'complete': done });
|
|---|
| 10086 | * });
|
|---|
| 10087 | * // => Logs 'done saving!' after the two async saves have completed.
|
|---|
| 10088 | */
|
|---|
| 10089 | function after(n, func) {
|
|---|
| 10090 | if (typeof func != 'function') {
|
|---|
| 10091 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 10092 | }
|
|---|
| 10093 | n = toInteger(n);
|
|---|
| 10094 | return function() {
|
|---|
| 10095 | if (--n < 1) {
|
|---|
| 10096 | return func.apply(this, arguments);
|
|---|
| 10097 | }
|
|---|
| 10098 | };
|
|---|
| 10099 | }
|
|---|
| 10100 |
|
|---|
| 10101 | /**
|
|---|
| 10102 | * Creates a function that invokes `func`, with up to `n` arguments,
|
|---|
| 10103 | * ignoring any additional arguments.
|
|---|
| 10104 | *
|
|---|
| 10105 | * @static
|
|---|
| 10106 | * @memberOf _
|
|---|
| 10107 | * @since 3.0.0
|
|---|
| 10108 | * @category Function
|
|---|
| 10109 | * @param {Function} func The function to cap arguments for.
|
|---|
| 10110 | * @param {number} [n=func.length] The arity cap.
|
|---|
| 10111 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 10112 | * @returns {Function} Returns the new capped function.
|
|---|
| 10113 | * @example
|
|---|
| 10114 | *
|
|---|
| 10115 | * _.map(['6', '8', '10'], _.ary(parseInt, 1));
|
|---|
| 10116 | * // => [6, 8, 10]
|
|---|
| 10117 | */
|
|---|
| 10118 | function ary(func, n, guard) {
|
|---|
| 10119 | n = guard ? undefined : n;
|
|---|
| 10120 | n = (func && n == null) ? func.length : n;
|
|---|
| 10121 | return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
|
|---|
| 10122 | }
|
|---|
| 10123 |
|
|---|
| 10124 | /**
|
|---|
| 10125 | * Creates a function that invokes `func`, with the `this` binding and arguments
|
|---|
| 10126 | * of the created function, while it's called less than `n` times. Subsequent
|
|---|
| 10127 | * calls to the created function return the result of the last `func` invocation.
|
|---|
| 10128 | *
|
|---|
| 10129 | * @static
|
|---|
| 10130 | * @memberOf _
|
|---|
| 10131 | * @since 3.0.0
|
|---|
| 10132 | * @category Function
|
|---|
| 10133 | * @param {number} n The number of calls at which `func` is no longer invoked.
|
|---|
| 10134 | * @param {Function} func The function to restrict.
|
|---|
| 10135 | * @returns {Function} Returns the new restricted function.
|
|---|
| 10136 | * @example
|
|---|
| 10137 | *
|
|---|
| 10138 | * jQuery(element).on('click', _.before(5, addContactToList));
|
|---|
| 10139 | * // => Allows adding up to 4 contacts to the list.
|
|---|
| 10140 | */
|
|---|
| 10141 | function before(n, func) {
|
|---|
| 10142 | var result;
|
|---|
| 10143 | if (typeof func != 'function') {
|
|---|
| 10144 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 10145 | }
|
|---|
| 10146 | n = toInteger(n);
|
|---|
| 10147 | return function() {
|
|---|
| 10148 | if (--n > 0) {
|
|---|
| 10149 | result = func.apply(this, arguments);
|
|---|
| 10150 | }
|
|---|
| 10151 | if (n <= 1) {
|
|---|
| 10152 | func = undefined;
|
|---|
| 10153 | }
|
|---|
| 10154 | return result;
|
|---|
| 10155 | };
|
|---|
| 10156 | }
|
|---|
| 10157 |
|
|---|
| 10158 | /**
|
|---|
| 10159 | * Creates a function that invokes `func` with the `this` binding of `thisArg`
|
|---|
| 10160 | * and `partials` prepended to the arguments it receives.
|
|---|
| 10161 | *
|
|---|
| 10162 | * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
|---|
| 10163 | * may be used as a placeholder for partially applied arguments.
|
|---|
| 10164 | *
|
|---|
| 10165 | * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
|
|---|
| 10166 | * property of bound functions.
|
|---|
| 10167 | *
|
|---|
| 10168 | * @static
|
|---|
| 10169 | * @memberOf _
|
|---|
| 10170 | * @since 0.1.0
|
|---|
| 10171 | * @category Function
|
|---|
| 10172 | * @param {Function} func The function to bind.
|
|---|
| 10173 | * @param {*} thisArg The `this` binding of `func`.
|
|---|
| 10174 | * @param {...*} [partials] The arguments to be partially applied.
|
|---|
| 10175 | * @returns {Function} Returns the new bound function.
|
|---|
| 10176 | * @example
|
|---|
| 10177 | *
|
|---|
| 10178 | * function greet(greeting, punctuation) {
|
|---|
| 10179 | * return greeting + ' ' + this.user + punctuation;
|
|---|
| 10180 | * }
|
|---|
| 10181 | *
|
|---|
| 10182 | * var object = { 'user': 'fred' };
|
|---|
| 10183 | *
|
|---|
| 10184 | * var bound = _.bind(greet, object, 'hi');
|
|---|
| 10185 | * bound('!');
|
|---|
| 10186 | * // => 'hi fred!'
|
|---|
| 10187 | *
|
|---|
| 10188 | * // Bound with placeholders.
|
|---|
| 10189 | * var bound = _.bind(greet, object, _, '!');
|
|---|
| 10190 | * bound('hi');
|
|---|
| 10191 | * // => 'hi fred!'
|
|---|
| 10192 | */
|
|---|
| 10193 | var bind = baseRest(function(func, thisArg, partials) {
|
|---|
| 10194 | var bitmask = WRAP_BIND_FLAG;
|
|---|
| 10195 | if (partials.length) {
|
|---|
| 10196 | var holders = replaceHolders(partials, getHolder(bind));
|
|---|
| 10197 | bitmask |= WRAP_PARTIAL_FLAG;
|
|---|
| 10198 | }
|
|---|
| 10199 | return createWrap(func, bitmask, thisArg, partials, holders);
|
|---|
| 10200 | });
|
|---|
| 10201 |
|
|---|
| 10202 | /**
|
|---|
| 10203 | * Creates a function that invokes the method at `object[key]` with `partials`
|
|---|
| 10204 | * prepended to the arguments it receives.
|
|---|
| 10205 | *
|
|---|
| 10206 | * This method differs from `_.bind` by allowing bound functions to reference
|
|---|
| 10207 | * methods that may be redefined or don't yet exist. See
|
|---|
| 10208 | * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
|
|---|
| 10209 | * for more details.
|
|---|
| 10210 | *
|
|---|
| 10211 | * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
|---|
| 10212 | * builds, may be used as a placeholder for partially applied arguments.
|
|---|
| 10213 | *
|
|---|
| 10214 | * @static
|
|---|
| 10215 | * @memberOf _
|
|---|
| 10216 | * @since 0.10.0
|
|---|
| 10217 | * @category Function
|
|---|
| 10218 | * @param {Object} object The object to invoke the method on.
|
|---|
| 10219 | * @param {string} key The key of the method.
|
|---|
| 10220 | * @param {...*} [partials] The arguments to be partially applied.
|
|---|
| 10221 | * @returns {Function} Returns the new bound function.
|
|---|
| 10222 | * @example
|
|---|
| 10223 | *
|
|---|
| 10224 | * var object = {
|
|---|
| 10225 | * 'user': 'fred',
|
|---|
| 10226 | * 'greet': function(greeting, punctuation) {
|
|---|
| 10227 | * return greeting + ' ' + this.user + punctuation;
|
|---|
| 10228 | * }
|
|---|
| 10229 | * };
|
|---|
| 10230 | *
|
|---|
| 10231 | * var bound = _.bindKey(object, 'greet', 'hi');
|
|---|
| 10232 | * bound('!');
|
|---|
| 10233 | * // => 'hi fred!'
|
|---|
| 10234 | *
|
|---|
| 10235 | * object.greet = function(greeting, punctuation) {
|
|---|
| 10236 | * return greeting + 'ya ' + this.user + punctuation;
|
|---|
| 10237 | * };
|
|---|
| 10238 | *
|
|---|
| 10239 | * bound('!');
|
|---|
| 10240 | * // => 'hiya fred!'
|
|---|
| 10241 | *
|
|---|
| 10242 | * // Bound with placeholders.
|
|---|
| 10243 | * var bound = _.bindKey(object, 'greet', _, '!');
|
|---|
| 10244 | * bound('hi');
|
|---|
| 10245 | * // => 'hiya fred!'
|
|---|
| 10246 | */
|
|---|
| 10247 | var bindKey = baseRest(function(object, key, partials) {
|
|---|
| 10248 | var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
|
|---|
| 10249 | if (partials.length) {
|
|---|
| 10250 | var holders = replaceHolders(partials, getHolder(bindKey));
|
|---|
| 10251 | bitmask |= WRAP_PARTIAL_FLAG;
|
|---|
| 10252 | }
|
|---|
| 10253 | return createWrap(key, bitmask, object, partials, holders);
|
|---|
| 10254 | });
|
|---|
| 10255 |
|
|---|
| 10256 | /**
|
|---|
| 10257 | * Creates a function that accepts arguments of `func` and either invokes
|
|---|
| 10258 | * `func` returning its result, if at least `arity` number of arguments have
|
|---|
| 10259 | * been provided, or returns a function that accepts the remaining `func`
|
|---|
| 10260 | * arguments, and so on. The arity of `func` may be specified if `func.length`
|
|---|
| 10261 | * is not sufficient.
|
|---|
| 10262 | *
|
|---|
| 10263 | * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
|---|
| 10264 | * may be used as a placeholder for provided arguments.
|
|---|
| 10265 | *
|
|---|
| 10266 | * **Note:** This method doesn't set the "length" property of curried functions.
|
|---|
| 10267 | *
|
|---|
| 10268 | * @static
|
|---|
| 10269 | * @memberOf _
|
|---|
| 10270 | * @since 2.0.0
|
|---|
| 10271 | * @category Function
|
|---|
| 10272 | * @param {Function} func The function to curry.
|
|---|
| 10273 | * @param {number} [arity=func.length] The arity of `func`.
|
|---|
| 10274 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 10275 | * @returns {Function} Returns the new curried function.
|
|---|
| 10276 | * @example
|
|---|
| 10277 | *
|
|---|
| 10278 | * var abc = function(a, b, c) {
|
|---|
| 10279 | * return [a, b, c];
|
|---|
| 10280 | * };
|
|---|
| 10281 | *
|
|---|
| 10282 | * var curried = _.curry(abc);
|
|---|
| 10283 | *
|
|---|
| 10284 | * curried(1)(2)(3);
|
|---|
| 10285 | * // => [1, 2, 3]
|
|---|
| 10286 | *
|
|---|
| 10287 | * curried(1, 2)(3);
|
|---|
| 10288 | * // => [1, 2, 3]
|
|---|
| 10289 | *
|
|---|
| 10290 | * curried(1, 2, 3);
|
|---|
| 10291 | * // => [1, 2, 3]
|
|---|
| 10292 | *
|
|---|
| 10293 | * // Curried with placeholders.
|
|---|
| 10294 | * curried(1)(_, 3)(2);
|
|---|
| 10295 | * // => [1, 2, 3]
|
|---|
| 10296 | */
|
|---|
| 10297 | function curry(func, arity, guard) {
|
|---|
| 10298 | arity = guard ? undefined : arity;
|
|---|
| 10299 | var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
|---|
| 10300 | result.placeholder = curry.placeholder;
|
|---|
| 10301 | return result;
|
|---|
| 10302 | }
|
|---|
| 10303 |
|
|---|
| 10304 | /**
|
|---|
| 10305 | * This method is like `_.curry` except that arguments are applied to `func`
|
|---|
| 10306 | * in the manner of `_.partialRight` instead of `_.partial`.
|
|---|
| 10307 | *
|
|---|
| 10308 | * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
|---|
| 10309 | * builds, may be used as a placeholder for provided arguments.
|
|---|
| 10310 | *
|
|---|
| 10311 | * **Note:** This method doesn't set the "length" property of curried functions.
|
|---|
| 10312 | *
|
|---|
| 10313 | * @static
|
|---|
| 10314 | * @memberOf _
|
|---|
| 10315 | * @since 3.0.0
|
|---|
| 10316 | * @category Function
|
|---|
| 10317 | * @param {Function} func The function to curry.
|
|---|
| 10318 | * @param {number} [arity=func.length] The arity of `func`.
|
|---|
| 10319 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 10320 | * @returns {Function} Returns the new curried function.
|
|---|
| 10321 | * @example
|
|---|
| 10322 | *
|
|---|
| 10323 | * var abc = function(a, b, c) {
|
|---|
| 10324 | * return [a, b, c];
|
|---|
| 10325 | * };
|
|---|
| 10326 | *
|
|---|
| 10327 | * var curried = _.curryRight(abc);
|
|---|
| 10328 | *
|
|---|
| 10329 | * curried(3)(2)(1);
|
|---|
| 10330 | * // => [1, 2, 3]
|
|---|
| 10331 | *
|
|---|
| 10332 | * curried(2, 3)(1);
|
|---|
| 10333 | * // => [1, 2, 3]
|
|---|
| 10334 | *
|
|---|
| 10335 | * curried(1, 2, 3);
|
|---|
| 10336 | * // => [1, 2, 3]
|
|---|
| 10337 | *
|
|---|
| 10338 | * // Curried with placeholders.
|
|---|
| 10339 | * curried(3)(1, _)(2);
|
|---|
| 10340 | * // => [1, 2, 3]
|
|---|
| 10341 | */
|
|---|
| 10342 | function curryRight(func, arity, guard) {
|
|---|
| 10343 | arity = guard ? undefined : arity;
|
|---|
| 10344 | var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
|---|
| 10345 | result.placeholder = curryRight.placeholder;
|
|---|
| 10346 | return result;
|
|---|
| 10347 | }
|
|---|
| 10348 |
|
|---|
| 10349 | /**
|
|---|
| 10350 | * Creates a debounced function that delays invoking `func` until after `wait`
|
|---|
| 10351 | * milliseconds have elapsed since the last time the debounced function was
|
|---|
| 10352 | * invoked. The debounced function comes with a `cancel` method to cancel
|
|---|
| 10353 | * delayed `func` invocations and a `flush` method to immediately invoke them.
|
|---|
| 10354 | * Provide `options` to indicate whether `func` should be invoked on the
|
|---|
| 10355 | * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
|
|---|
| 10356 | * with the last arguments provided to the debounced function. Subsequent
|
|---|
| 10357 | * calls to the debounced function return the result of the last `func`
|
|---|
| 10358 | * invocation.
|
|---|
| 10359 | *
|
|---|
| 10360 | * **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|---|
| 10361 | * invoked on the trailing edge of the timeout only if the debounced function
|
|---|
| 10362 | * is invoked more than once during the `wait` timeout.
|
|---|
| 10363 | *
|
|---|
| 10364 | * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|---|
| 10365 | * until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|---|
| 10366 | *
|
|---|
| 10367 | * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|---|
| 10368 | * for details over the differences between `_.debounce` and `_.throttle`.
|
|---|
| 10369 | *
|
|---|
| 10370 | * @static
|
|---|
| 10371 | * @memberOf _
|
|---|
| 10372 | * @since 0.1.0
|
|---|
| 10373 | * @category Function
|
|---|
| 10374 | * @param {Function} func The function to debounce.
|
|---|
| 10375 | * @param {number} [wait=0] The number of milliseconds to delay.
|
|---|
| 10376 | * @param {Object} [options={}] The options object.
|
|---|
| 10377 | * @param {boolean} [options.leading=false]
|
|---|
| 10378 | * Specify invoking on the leading edge of the timeout.
|
|---|
| 10379 | * @param {number} [options.maxWait]
|
|---|
| 10380 | * The maximum time `func` is allowed to be delayed before it's invoked.
|
|---|
| 10381 | * @param {boolean} [options.trailing=true]
|
|---|
| 10382 | * Specify invoking on the trailing edge of the timeout.
|
|---|
| 10383 | * @returns {Function} Returns the new debounced function.
|
|---|
| 10384 | * @example
|
|---|
| 10385 | *
|
|---|
| 10386 | * // Avoid costly calculations while the window size is in flux.
|
|---|
| 10387 | * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
|
|---|
| 10388 | *
|
|---|
| 10389 | * // Invoke `sendMail` when clicked, debouncing subsequent calls.
|
|---|
| 10390 | * jQuery(element).on('click', _.debounce(sendMail, 300, {
|
|---|
| 10391 | * 'leading': true,
|
|---|
| 10392 | * 'trailing': false
|
|---|
| 10393 | * }));
|
|---|
| 10394 | *
|
|---|
| 10395 | * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
|
|---|
| 10396 | * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
|
|---|
| 10397 | * var source = new EventSource('/stream');
|
|---|
| 10398 | * jQuery(source).on('message', debounced);
|
|---|
| 10399 | *
|
|---|
| 10400 | * // Cancel the trailing debounced invocation.
|
|---|
| 10401 | * jQuery(window).on('popstate', debounced.cancel);
|
|---|
| 10402 | */
|
|---|
| 10403 | function debounce(func, wait, options) {
|
|---|
| 10404 | var lastArgs,
|
|---|
| 10405 | lastThis,
|
|---|
| 10406 | maxWait,
|
|---|
| 10407 | result,
|
|---|
| 10408 | timerId,
|
|---|
| 10409 | lastCallTime,
|
|---|
| 10410 | lastInvokeTime = 0,
|
|---|
| 10411 | leading = false,
|
|---|
| 10412 | maxing = false,
|
|---|
| 10413 | trailing = true;
|
|---|
| 10414 |
|
|---|
| 10415 | if (typeof func != 'function') {
|
|---|
| 10416 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 10417 | }
|
|---|
| 10418 | wait = toNumber(wait) || 0;
|
|---|
| 10419 | if (isObject(options)) {
|
|---|
| 10420 | leading = !!options.leading;
|
|---|
| 10421 | maxing = 'maxWait' in options;
|
|---|
| 10422 | maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
|---|
| 10423 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|---|
| 10424 | }
|
|---|
| 10425 |
|
|---|
| 10426 | function invokeFunc(time) {
|
|---|
| 10427 | var args = lastArgs,
|
|---|
| 10428 | thisArg = lastThis;
|
|---|
| 10429 |
|
|---|
| 10430 | lastArgs = lastThis = undefined;
|
|---|
| 10431 | lastInvokeTime = time;
|
|---|
| 10432 | result = func.apply(thisArg, args);
|
|---|
| 10433 | return result;
|
|---|
| 10434 | }
|
|---|
| 10435 |
|
|---|
| 10436 | function leadingEdge(time) {
|
|---|
| 10437 | // Reset any `maxWait` timer.
|
|---|
| 10438 | lastInvokeTime = time;
|
|---|
| 10439 | // Start the timer for the trailing edge.
|
|---|
| 10440 | timerId = setTimeout(timerExpired, wait);
|
|---|
| 10441 | // Invoke the leading edge.
|
|---|
| 10442 | return leading ? invokeFunc(time) : result;
|
|---|
| 10443 | }
|
|---|
| 10444 |
|
|---|
| 10445 | function remainingWait(time) {
|
|---|
| 10446 | var timeSinceLastCall = time - lastCallTime,
|
|---|
| 10447 | timeSinceLastInvoke = time - lastInvokeTime,
|
|---|
| 10448 | timeWaiting = wait - timeSinceLastCall;
|
|---|
| 10449 |
|
|---|
| 10450 | return maxing
|
|---|
| 10451 | ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
|
|---|
| 10452 | : timeWaiting;
|
|---|
| 10453 | }
|
|---|
| 10454 |
|
|---|
| 10455 | function shouldInvoke(time) {
|
|---|
| 10456 | var timeSinceLastCall = time - lastCallTime,
|
|---|
| 10457 | timeSinceLastInvoke = time - lastInvokeTime;
|
|---|
| 10458 |
|
|---|
| 10459 | // Either this is the first call, activity has stopped and we're at the
|
|---|
| 10460 | // trailing edge, the system time has gone backwards and we're treating
|
|---|
| 10461 | // it as the trailing edge, or we've hit the `maxWait` limit.
|
|---|
| 10462 | return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
|
|---|
| 10463 | (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
|
|---|
| 10464 | }
|
|---|
| 10465 |
|
|---|
| 10466 | function timerExpired() {
|
|---|
| 10467 | var time = now();
|
|---|
| 10468 | if (shouldInvoke(time)) {
|
|---|
| 10469 | return trailingEdge(time);
|
|---|
| 10470 | }
|
|---|
| 10471 | // Restart the timer.
|
|---|
| 10472 | timerId = setTimeout(timerExpired, remainingWait(time));
|
|---|
| 10473 | }
|
|---|
| 10474 |
|
|---|
| 10475 | function trailingEdge(time) {
|
|---|
| 10476 | timerId = undefined;
|
|---|
| 10477 |
|
|---|
| 10478 | // Only invoke if we have `lastArgs` which means `func` has been
|
|---|
| 10479 | // debounced at least once.
|
|---|
| 10480 | if (trailing && lastArgs) {
|
|---|
| 10481 | return invokeFunc(time);
|
|---|
| 10482 | }
|
|---|
| 10483 | lastArgs = lastThis = undefined;
|
|---|
| 10484 | return result;
|
|---|
| 10485 | }
|
|---|
| 10486 |
|
|---|
| 10487 | function cancel() {
|
|---|
| 10488 | if (timerId !== undefined) {
|
|---|
| 10489 | clearTimeout(timerId);
|
|---|
| 10490 | }
|
|---|
| 10491 | lastInvokeTime = 0;
|
|---|
| 10492 | lastArgs = lastCallTime = lastThis = timerId = undefined;
|
|---|
| 10493 | }
|
|---|
| 10494 |
|
|---|
| 10495 | function flush() {
|
|---|
| 10496 | return timerId === undefined ? result : trailingEdge(now());
|
|---|
| 10497 | }
|
|---|
| 10498 |
|
|---|
| 10499 | function debounced() {
|
|---|
| 10500 | var time = now(),
|
|---|
| 10501 | isInvoking = shouldInvoke(time);
|
|---|
| 10502 |
|
|---|
| 10503 | lastArgs = arguments;
|
|---|
| 10504 | lastThis = this;
|
|---|
| 10505 | lastCallTime = time;
|
|---|
| 10506 |
|
|---|
| 10507 | if (isInvoking) {
|
|---|
| 10508 | if (timerId === undefined) {
|
|---|
| 10509 | return leadingEdge(lastCallTime);
|
|---|
| 10510 | }
|
|---|
| 10511 | if (maxing) {
|
|---|
| 10512 | // Handle invocations in a tight loop.
|
|---|
| 10513 | clearTimeout(timerId);
|
|---|
| 10514 | timerId = setTimeout(timerExpired, wait);
|
|---|
| 10515 | return invokeFunc(lastCallTime);
|
|---|
| 10516 | }
|
|---|
| 10517 | }
|
|---|
| 10518 | if (timerId === undefined) {
|
|---|
| 10519 | timerId = setTimeout(timerExpired, wait);
|
|---|
| 10520 | }
|
|---|
| 10521 | return result;
|
|---|
| 10522 | }
|
|---|
| 10523 | debounced.cancel = cancel;
|
|---|
| 10524 | debounced.flush = flush;
|
|---|
| 10525 | return debounced;
|
|---|
| 10526 | }
|
|---|
| 10527 |
|
|---|
| 10528 | /**
|
|---|
| 10529 | * Defers invoking the `func` until the current call stack has cleared. Any
|
|---|
| 10530 | * additional arguments are provided to `func` when it's invoked.
|
|---|
| 10531 | *
|
|---|
| 10532 | * @static
|
|---|
| 10533 | * @memberOf _
|
|---|
| 10534 | * @since 0.1.0
|
|---|
| 10535 | * @category Function
|
|---|
| 10536 | * @param {Function} func The function to defer.
|
|---|
| 10537 | * @param {...*} [args] The arguments to invoke `func` with.
|
|---|
| 10538 | * @returns {number} Returns the timer id.
|
|---|
| 10539 | * @example
|
|---|
| 10540 | *
|
|---|
| 10541 | * _.defer(function(text) {
|
|---|
| 10542 | * console.log(text);
|
|---|
| 10543 | * }, 'deferred');
|
|---|
| 10544 | * // => Logs 'deferred' after one millisecond.
|
|---|
| 10545 | */
|
|---|
| 10546 | var defer = baseRest(function(func, args) {
|
|---|
| 10547 | return baseDelay(func, 1, args);
|
|---|
| 10548 | });
|
|---|
| 10549 |
|
|---|
| 10550 | /**
|
|---|
| 10551 | * Invokes `func` after `wait` milliseconds. Any additional arguments are
|
|---|
| 10552 | * provided to `func` when it's invoked.
|
|---|
| 10553 | *
|
|---|
| 10554 | * @static
|
|---|
| 10555 | * @memberOf _
|
|---|
| 10556 | * @since 0.1.0
|
|---|
| 10557 | * @category Function
|
|---|
| 10558 | * @param {Function} func The function to delay.
|
|---|
| 10559 | * @param {number} wait The number of milliseconds to delay invocation.
|
|---|
| 10560 | * @param {...*} [args] The arguments to invoke `func` with.
|
|---|
| 10561 | * @returns {number} Returns the timer id.
|
|---|
| 10562 | * @example
|
|---|
| 10563 | *
|
|---|
| 10564 | * _.delay(function(text) {
|
|---|
| 10565 | * console.log(text);
|
|---|
| 10566 | * }, 1000, 'later');
|
|---|
| 10567 | * // => Logs 'later' after one second.
|
|---|
| 10568 | */
|
|---|
| 10569 | var delay = baseRest(function(func, wait, args) {
|
|---|
| 10570 | return baseDelay(func, toNumber(wait) || 0, args);
|
|---|
| 10571 | });
|
|---|
| 10572 |
|
|---|
| 10573 | /**
|
|---|
| 10574 | * Creates a function that invokes `func` with arguments reversed.
|
|---|
| 10575 | *
|
|---|
| 10576 | * @static
|
|---|
| 10577 | * @memberOf _
|
|---|
| 10578 | * @since 4.0.0
|
|---|
| 10579 | * @category Function
|
|---|
| 10580 | * @param {Function} func The function to flip arguments for.
|
|---|
| 10581 | * @returns {Function} Returns the new flipped function.
|
|---|
| 10582 | * @example
|
|---|
| 10583 | *
|
|---|
| 10584 | * var flipped = _.flip(function() {
|
|---|
| 10585 | * return _.toArray(arguments);
|
|---|
| 10586 | * });
|
|---|
| 10587 | *
|
|---|
| 10588 | * flipped('a', 'b', 'c', 'd');
|
|---|
| 10589 | * // => ['d', 'c', 'b', 'a']
|
|---|
| 10590 | */
|
|---|
| 10591 | function flip(func) {
|
|---|
| 10592 | return createWrap(func, WRAP_FLIP_FLAG);
|
|---|
| 10593 | }
|
|---|
| 10594 |
|
|---|
| 10595 | /**
|
|---|
| 10596 | * Creates a function that memoizes the result of `func`. If `resolver` is
|
|---|
| 10597 | * provided, it determines the cache key for storing the result based on the
|
|---|
| 10598 | * arguments provided to the memoized function. By default, the first argument
|
|---|
| 10599 | * provided to the memoized function is used as the map cache key. The `func`
|
|---|
| 10600 | * is invoked with the `this` binding of the memoized function.
|
|---|
| 10601 | *
|
|---|
| 10602 | * **Note:** The cache is exposed as the `cache` property on the memoized
|
|---|
| 10603 | * function. Its creation may be customized by replacing the `_.memoize.Cache`
|
|---|
| 10604 | * constructor with one whose instances implement the
|
|---|
| 10605 | * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
|
|---|
| 10606 | * method interface of `clear`, `delete`, `get`, `has`, and `set`.
|
|---|
| 10607 | *
|
|---|
| 10608 | * @static
|
|---|
| 10609 | * @memberOf _
|
|---|
| 10610 | * @since 0.1.0
|
|---|
| 10611 | * @category Function
|
|---|
| 10612 | * @param {Function} func The function to have its output memoized.
|
|---|
| 10613 | * @param {Function} [resolver] The function to resolve the cache key.
|
|---|
| 10614 | * @returns {Function} Returns the new memoized function.
|
|---|
| 10615 | * @example
|
|---|
| 10616 | *
|
|---|
| 10617 | * var object = { 'a': 1, 'b': 2 };
|
|---|
| 10618 | * var other = { 'c': 3, 'd': 4 };
|
|---|
| 10619 | *
|
|---|
| 10620 | * var values = _.memoize(_.values);
|
|---|
| 10621 | * values(object);
|
|---|
| 10622 | * // => [1, 2]
|
|---|
| 10623 | *
|
|---|
| 10624 | * values(other);
|
|---|
| 10625 | * // => [3, 4]
|
|---|
| 10626 | *
|
|---|
| 10627 | * object.a = 2;
|
|---|
| 10628 | * values(object);
|
|---|
| 10629 | * // => [1, 2]
|
|---|
| 10630 | *
|
|---|
| 10631 | * // Modify the result cache.
|
|---|
| 10632 | * values.cache.set(object, ['a', 'b']);
|
|---|
| 10633 | * values(object);
|
|---|
| 10634 | * // => ['a', 'b']
|
|---|
| 10635 | *
|
|---|
| 10636 | * // Replace `_.memoize.Cache`.
|
|---|
| 10637 | * _.memoize.Cache = WeakMap;
|
|---|
| 10638 | */
|
|---|
| 10639 | function memoize(func, resolver) {
|
|---|
| 10640 | if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
|---|
| 10641 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 10642 | }
|
|---|
| 10643 | var memoized = function() {
|
|---|
| 10644 | var args = arguments,
|
|---|
| 10645 | key = resolver ? resolver.apply(this, args) : args[0],
|
|---|
| 10646 | cache = memoized.cache;
|
|---|
| 10647 |
|
|---|
| 10648 | if (cache.has(key)) {
|
|---|
| 10649 | return cache.get(key);
|
|---|
| 10650 | }
|
|---|
| 10651 | var result = func.apply(this, args);
|
|---|
| 10652 | memoized.cache = cache.set(key, result) || cache;
|
|---|
| 10653 | return result;
|
|---|
| 10654 | };
|
|---|
| 10655 | memoized.cache = new (memoize.Cache || MapCache);
|
|---|
| 10656 | return memoized;
|
|---|
| 10657 | }
|
|---|
| 10658 |
|
|---|
| 10659 | // Expose `MapCache`.
|
|---|
| 10660 | memoize.Cache = MapCache;
|
|---|
| 10661 |
|
|---|
| 10662 | /**
|
|---|
| 10663 | * Creates a function that negates the result of the predicate `func`. The
|
|---|
| 10664 | * `func` predicate is invoked with the `this` binding and arguments of the
|
|---|
| 10665 | * created function.
|
|---|
| 10666 | *
|
|---|
| 10667 | * @static
|
|---|
| 10668 | * @memberOf _
|
|---|
| 10669 | * @since 3.0.0
|
|---|
| 10670 | * @category Function
|
|---|
| 10671 | * @param {Function} predicate The predicate to negate.
|
|---|
| 10672 | * @returns {Function} Returns the new negated function.
|
|---|
| 10673 | * @example
|
|---|
| 10674 | *
|
|---|
| 10675 | * function isEven(n) {
|
|---|
| 10676 | * return n % 2 == 0;
|
|---|
| 10677 | * }
|
|---|
| 10678 | *
|
|---|
| 10679 | * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
|
|---|
| 10680 | * // => [1, 3, 5]
|
|---|
| 10681 | */
|
|---|
| 10682 | function negate(predicate) {
|
|---|
| 10683 | if (typeof predicate != 'function') {
|
|---|
| 10684 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 10685 | }
|
|---|
| 10686 | return function() {
|
|---|
| 10687 | var args = arguments;
|
|---|
| 10688 | switch (args.length) {
|
|---|
| 10689 | case 0: return !predicate.call(this);
|
|---|
| 10690 | case 1: return !predicate.call(this, args[0]);
|
|---|
| 10691 | case 2: return !predicate.call(this, args[0], args[1]);
|
|---|
| 10692 | case 3: return !predicate.call(this, args[0], args[1], args[2]);
|
|---|
| 10693 | }
|
|---|
| 10694 | return !predicate.apply(this, args);
|
|---|
| 10695 | };
|
|---|
| 10696 | }
|
|---|
| 10697 |
|
|---|
| 10698 | /**
|
|---|
| 10699 | * Creates a function that is restricted to invoking `func` once. Repeat calls
|
|---|
| 10700 | * to the function return the value of the first invocation. The `func` is
|
|---|
| 10701 | * invoked with the `this` binding and arguments of the created function.
|
|---|
| 10702 | *
|
|---|
| 10703 | * @static
|
|---|
| 10704 | * @memberOf _
|
|---|
| 10705 | * @since 0.1.0
|
|---|
| 10706 | * @category Function
|
|---|
| 10707 | * @param {Function} func The function to restrict.
|
|---|
| 10708 | * @returns {Function} Returns the new restricted function.
|
|---|
| 10709 | * @example
|
|---|
| 10710 | *
|
|---|
| 10711 | * var initialize = _.once(createApplication);
|
|---|
| 10712 | * initialize();
|
|---|
| 10713 | * initialize();
|
|---|
| 10714 | * // => `createApplication` is invoked once
|
|---|
| 10715 | */
|
|---|
| 10716 | function once(func) {
|
|---|
| 10717 | return before(2, func);
|
|---|
| 10718 | }
|
|---|
| 10719 |
|
|---|
| 10720 | /**
|
|---|
| 10721 | * Creates a function that invokes `func` with its arguments transformed.
|
|---|
| 10722 | *
|
|---|
| 10723 | * @static
|
|---|
| 10724 | * @since 4.0.0
|
|---|
| 10725 | * @memberOf _
|
|---|
| 10726 | * @category Function
|
|---|
| 10727 | * @param {Function} func The function to wrap.
|
|---|
| 10728 | * @param {...(Function|Function[])} [transforms=[_.identity]]
|
|---|
| 10729 | * The argument transforms.
|
|---|
| 10730 | * @returns {Function} Returns the new function.
|
|---|
| 10731 | * @example
|
|---|
| 10732 | *
|
|---|
| 10733 | * function doubled(n) {
|
|---|
| 10734 | * return n * 2;
|
|---|
| 10735 | * }
|
|---|
| 10736 | *
|
|---|
| 10737 | * function square(n) {
|
|---|
| 10738 | * return n * n;
|
|---|
| 10739 | * }
|
|---|
| 10740 | *
|
|---|
| 10741 | * var func = _.overArgs(function(x, y) {
|
|---|
| 10742 | * return [x, y];
|
|---|
| 10743 | * }, [square, doubled]);
|
|---|
| 10744 | *
|
|---|
| 10745 | * func(9, 3);
|
|---|
| 10746 | * // => [81, 6]
|
|---|
| 10747 | *
|
|---|
| 10748 | * func(10, 5);
|
|---|
| 10749 | * // => [100, 10]
|
|---|
| 10750 | */
|
|---|
| 10751 | var overArgs = castRest(function(func, transforms) {
|
|---|
| 10752 | transforms = (transforms.length == 1 && isArray(transforms[0]))
|
|---|
| 10753 | ? arrayMap(transforms[0], baseUnary(getIteratee()))
|
|---|
| 10754 | : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
|
|---|
| 10755 |
|
|---|
| 10756 | var funcsLength = transforms.length;
|
|---|
| 10757 | return baseRest(function(args) {
|
|---|
| 10758 | var index = -1,
|
|---|
| 10759 | length = nativeMin(args.length, funcsLength);
|
|---|
| 10760 |
|
|---|
| 10761 | while (++index < length) {
|
|---|
| 10762 | args[index] = transforms[index].call(this, args[index]);
|
|---|
| 10763 | }
|
|---|
| 10764 | return apply(func, this, args);
|
|---|
| 10765 | });
|
|---|
| 10766 | });
|
|---|
| 10767 |
|
|---|
| 10768 | /**
|
|---|
| 10769 | * Creates a function that invokes `func` with `partials` prepended to the
|
|---|
| 10770 | * arguments it receives. This method is like `_.bind` except it does **not**
|
|---|
| 10771 | * alter the `this` binding.
|
|---|
| 10772 | *
|
|---|
| 10773 | * The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
|---|
| 10774 | * builds, may be used as a placeholder for partially applied arguments.
|
|---|
| 10775 | *
|
|---|
| 10776 | * **Note:** This method doesn't set the "length" property of partially
|
|---|
| 10777 | * applied functions.
|
|---|
| 10778 | *
|
|---|
| 10779 | * @static
|
|---|
| 10780 | * @memberOf _
|
|---|
| 10781 | * @since 0.2.0
|
|---|
| 10782 | * @category Function
|
|---|
| 10783 | * @param {Function} func The function to partially apply arguments to.
|
|---|
| 10784 | * @param {...*} [partials] The arguments to be partially applied.
|
|---|
| 10785 | * @returns {Function} Returns the new partially applied function.
|
|---|
| 10786 | * @example
|
|---|
| 10787 | *
|
|---|
| 10788 | * function greet(greeting, name) {
|
|---|
| 10789 | * return greeting + ' ' + name;
|
|---|
| 10790 | * }
|
|---|
| 10791 | *
|
|---|
| 10792 | * var sayHelloTo = _.partial(greet, 'hello');
|
|---|
| 10793 | * sayHelloTo('fred');
|
|---|
| 10794 | * // => 'hello fred'
|
|---|
| 10795 | *
|
|---|
| 10796 | * // Partially applied with placeholders.
|
|---|
| 10797 | * var greetFred = _.partial(greet, _, 'fred');
|
|---|
| 10798 | * greetFred('hi');
|
|---|
| 10799 | * // => 'hi fred'
|
|---|
| 10800 | */
|
|---|
| 10801 | var partial = baseRest(function(func, partials) {
|
|---|
| 10802 | var holders = replaceHolders(partials, getHolder(partial));
|
|---|
| 10803 | return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
|
|---|
| 10804 | });
|
|---|
| 10805 |
|
|---|
| 10806 | /**
|
|---|
| 10807 | * This method is like `_.partial` except that partially applied arguments
|
|---|
| 10808 | * are appended to the arguments it receives.
|
|---|
| 10809 | *
|
|---|
| 10810 | * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
|---|
| 10811 | * builds, may be used as a placeholder for partially applied arguments.
|
|---|
| 10812 | *
|
|---|
| 10813 | * **Note:** This method doesn't set the "length" property of partially
|
|---|
| 10814 | * applied functions.
|
|---|
| 10815 | *
|
|---|
| 10816 | * @static
|
|---|
| 10817 | * @memberOf _
|
|---|
| 10818 | * @since 1.0.0
|
|---|
| 10819 | * @category Function
|
|---|
| 10820 | * @param {Function} func The function to partially apply arguments to.
|
|---|
| 10821 | * @param {...*} [partials] The arguments to be partially applied.
|
|---|
| 10822 | * @returns {Function} Returns the new partially applied function.
|
|---|
| 10823 | * @example
|
|---|
| 10824 | *
|
|---|
| 10825 | * function greet(greeting, name) {
|
|---|
| 10826 | * return greeting + ' ' + name;
|
|---|
| 10827 | * }
|
|---|
| 10828 | *
|
|---|
| 10829 | * var greetFred = _.partialRight(greet, 'fred');
|
|---|
| 10830 | * greetFred('hi');
|
|---|
| 10831 | * // => 'hi fred'
|
|---|
| 10832 | *
|
|---|
| 10833 | * // Partially applied with placeholders.
|
|---|
| 10834 | * var sayHelloTo = _.partialRight(greet, 'hello', _);
|
|---|
| 10835 | * sayHelloTo('fred');
|
|---|
| 10836 | * // => 'hello fred'
|
|---|
| 10837 | */
|
|---|
| 10838 | var partialRight = baseRest(function(func, partials) {
|
|---|
| 10839 | var holders = replaceHolders(partials, getHolder(partialRight));
|
|---|
| 10840 | return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
|
|---|
| 10841 | });
|
|---|
| 10842 |
|
|---|
| 10843 | /**
|
|---|
| 10844 | * Creates a function that invokes `func` with arguments arranged according
|
|---|
| 10845 | * to the specified `indexes` where the argument value at the first index is
|
|---|
| 10846 | * provided as the first argument, the argument value at the second index is
|
|---|
| 10847 | * provided as the second argument, and so on.
|
|---|
| 10848 | *
|
|---|
| 10849 | * @static
|
|---|
| 10850 | * @memberOf _
|
|---|
| 10851 | * @since 3.0.0
|
|---|
| 10852 | * @category Function
|
|---|
| 10853 | * @param {Function} func The function to rearrange arguments for.
|
|---|
| 10854 | * @param {...(number|number[])} indexes The arranged argument indexes.
|
|---|
| 10855 | * @returns {Function} Returns the new function.
|
|---|
| 10856 | * @example
|
|---|
| 10857 | *
|
|---|
| 10858 | * var rearged = _.rearg(function(a, b, c) {
|
|---|
| 10859 | * return [a, b, c];
|
|---|
| 10860 | * }, [2, 0, 1]);
|
|---|
| 10861 | *
|
|---|
| 10862 | * rearged('b', 'c', 'a')
|
|---|
| 10863 | * // => ['a', 'b', 'c']
|
|---|
| 10864 | */
|
|---|
| 10865 | var rearg = flatRest(function(func, indexes) {
|
|---|
| 10866 | return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
|
|---|
| 10867 | });
|
|---|
| 10868 |
|
|---|
| 10869 | /**
|
|---|
| 10870 | * Creates a function that invokes `func` with the `this` binding of the
|
|---|
| 10871 | * created function and arguments from `start` and beyond provided as
|
|---|
| 10872 | * an array.
|
|---|
| 10873 | *
|
|---|
| 10874 | * **Note:** This method is based on the
|
|---|
| 10875 | * [rest parameter](https://mdn.io/rest_parameters).
|
|---|
| 10876 | *
|
|---|
| 10877 | * @static
|
|---|
| 10878 | * @memberOf _
|
|---|
| 10879 | * @since 4.0.0
|
|---|
| 10880 | * @category Function
|
|---|
| 10881 | * @param {Function} func The function to apply a rest parameter to.
|
|---|
| 10882 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
|---|
| 10883 | * @returns {Function} Returns the new function.
|
|---|
| 10884 | * @example
|
|---|
| 10885 | *
|
|---|
| 10886 | * var say = _.rest(function(what, names) {
|
|---|
| 10887 | * return what + ' ' + _.initial(names).join(', ') +
|
|---|
| 10888 | * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
|---|
| 10889 | * });
|
|---|
| 10890 | *
|
|---|
| 10891 | * say('hello', 'fred', 'barney', 'pebbles');
|
|---|
| 10892 | * // => 'hello fred, barney, & pebbles'
|
|---|
| 10893 | */
|
|---|
| 10894 | function rest(func, start) {
|
|---|
| 10895 | if (typeof func != 'function') {
|
|---|
| 10896 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 10897 | }
|
|---|
| 10898 | start = start === undefined ? start : toInteger(start);
|
|---|
| 10899 | return baseRest(func, start);
|
|---|
| 10900 | }
|
|---|
| 10901 |
|
|---|
| 10902 | /**
|
|---|
| 10903 | * Creates a function that invokes `func` with the `this` binding of the
|
|---|
| 10904 | * create function and an array of arguments much like
|
|---|
| 10905 | * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
|
|---|
| 10906 | *
|
|---|
| 10907 | * **Note:** This method is based on the
|
|---|
| 10908 | * [spread operator](https://mdn.io/spread_operator).
|
|---|
| 10909 | *
|
|---|
| 10910 | * @static
|
|---|
| 10911 | * @memberOf _
|
|---|
| 10912 | * @since 3.2.0
|
|---|
| 10913 | * @category Function
|
|---|
| 10914 | * @param {Function} func The function to spread arguments over.
|
|---|
| 10915 | * @param {number} [start=0] The start position of the spread.
|
|---|
| 10916 | * @returns {Function} Returns the new function.
|
|---|
| 10917 | * @example
|
|---|
| 10918 | *
|
|---|
| 10919 | * var say = _.spread(function(who, what) {
|
|---|
| 10920 | * return who + ' says ' + what;
|
|---|
| 10921 | * });
|
|---|
| 10922 | *
|
|---|
| 10923 | * say(['fred', 'hello']);
|
|---|
| 10924 | * // => 'fred says hello'
|
|---|
| 10925 | *
|
|---|
| 10926 | * var numbers = Promise.all([
|
|---|
| 10927 | * Promise.resolve(40),
|
|---|
| 10928 | * Promise.resolve(36)
|
|---|
| 10929 | * ]);
|
|---|
| 10930 | *
|
|---|
| 10931 | * numbers.then(_.spread(function(x, y) {
|
|---|
| 10932 | * return x + y;
|
|---|
| 10933 | * }));
|
|---|
| 10934 | * // => a Promise of 76
|
|---|
| 10935 | */
|
|---|
| 10936 | function spread(func, start) {
|
|---|
| 10937 | if (typeof func != 'function') {
|
|---|
| 10938 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 10939 | }
|
|---|
| 10940 | start = start == null ? 0 : nativeMax(toInteger(start), 0);
|
|---|
| 10941 | return baseRest(function(args) {
|
|---|
| 10942 | var array = args[start],
|
|---|
| 10943 | otherArgs = castSlice(args, 0, start);
|
|---|
| 10944 |
|
|---|
| 10945 | if (array) {
|
|---|
| 10946 | arrayPush(otherArgs, array);
|
|---|
| 10947 | }
|
|---|
| 10948 | return apply(func, this, otherArgs);
|
|---|
| 10949 | });
|
|---|
| 10950 | }
|
|---|
| 10951 |
|
|---|
| 10952 | /**
|
|---|
| 10953 | * Creates a throttled function that only invokes `func` at most once per
|
|---|
| 10954 | * every `wait` milliseconds. The throttled function comes with a `cancel`
|
|---|
| 10955 | * method to cancel delayed `func` invocations and a `flush` method to
|
|---|
| 10956 | * immediately invoke them. Provide `options` to indicate whether `func`
|
|---|
| 10957 | * should be invoked on the leading and/or trailing edge of the `wait`
|
|---|
| 10958 | * timeout. The `func` is invoked with the last arguments provided to the
|
|---|
| 10959 | * throttled function. Subsequent calls to the throttled function return the
|
|---|
| 10960 | * result of the last `func` invocation.
|
|---|
| 10961 | *
|
|---|
| 10962 | * **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|---|
| 10963 | * invoked on the trailing edge of the timeout only if the throttled function
|
|---|
| 10964 | * is invoked more than once during the `wait` timeout.
|
|---|
| 10965 | *
|
|---|
| 10966 | * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|---|
| 10967 | * until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|---|
| 10968 | *
|
|---|
| 10969 | * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|---|
| 10970 | * for details over the differences between `_.throttle` and `_.debounce`.
|
|---|
| 10971 | *
|
|---|
| 10972 | * @static
|
|---|
| 10973 | * @memberOf _
|
|---|
| 10974 | * @since 0.1.0
|
|---|
| 10975 | * @category Function
|
|---|
| 10976 | * @param {Function} func The function to throttle.
|
|---|
| 10977 | * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
|---|
| 10978 | * @param {Object} [options={}] The options object.
|
|---|
| 10979 | * @param {boolean} [options.leading=true]
|
|---|
| 10980 | * Specify invoking on the leading edge of the timeout.
|
|---|
| 10981 | * @param {boolean} [options.trailing=true]
|
|---|
| 10982 | * Specify invoking on the trailing edge of the timeout.
|
|---|
| 10983 | * @returns {Function} Returns the new throttled function.
|
|---|
| 10984 | * @example
|
|---|
| 10985 | *
|
|---|
| 10986 | * // Avoid excessively updating the position while scrolling.
|
|---|
| 10987 | * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
|---|
| 10988 | *
|
|---|
| 10989 | * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
|---|
| 10990 | * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
|---|
| 10991 | * jQuery(element).on('click', throttled);
|
|---|
| 10992 | *
|
|---|
| 10993 | * // Cancel the trailing throttled invocation.
|
|---|
| 10994 | * jQuery(window).on('popstate', throttled.cancel);
|
|---|
| 10995 | */
|
|---|
| 10996 | function throttle(func, wait, options) {
|
|---|
| 10997 | var leading = true,
|
|---|
| 10998 | trailing = true;
|
|---|
| 10999 |
|
|---|
| 11000 | if (typeof func != 'function') {
|
|---|
| 11001 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 11002 | }
|
|---|
| 11003 | if (isObject(options)) {
|
|---|
| 11004 | leading = 'leading' in options ? !!options.leading : leading;
|
|---|
| 11005 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|---|
| 11006 | }
|
|---|
| 11007 | return debounce(func, wait, {
|
|---|
| 11008 | 'leading': leading,
|
|---|
| 11009 | 'maxWait': wait,
|
|---|
| 11010 | 'trailing': trailing
|
|---|
| 11011 | });
|
|---|
| 11012 | }
|
|---|
| 11013 |
|
|---|
| 11014 | /**
|
|---|
| 11015 | * Creates a function that accepts up to one argument, ignoring any
|
|---|
| 11016 | * additional arguments.
|
|---|
| 11017 | *
|
|---|
| 11018 | * @static
|
|---|
| 11019 | * @memberOf _
|
|---|
| 11020 | * @since 4.0.0
|
|---|
| 11021 | * @category Function
|
|---|
| 11022 | * @param {Function} func The function to cap arguments for.
|
|---|
| 11023 | * @returns {Function} Returns the new capped function.
|
|---|
| 11024 | * @example
|
|---|
| 11025 | *
|
|---|
| 11026 | * _.map(['6', '8', '10'], _.unary(parseInt));
|
|---|
| 11027 | * // => [6, 8, 10]
|
|---|
| 11028 | */
|
|---|
| 11029 | function unary(func) {
|
|---|
| 11030 | return ary(func, 1);
|
|---|
| 11031 | }
|
|---|
| 11032 |
|
|---|
| 11033 | /**
|
|---|
| 11034 | * Creates a function that provides `value` to `wrapper` as its first
|
|---|
| 11035 | * argument. Any additional arguments provided to the function are appended
|
|---|
| 11036 | * to those provided to the `wrapper`. The wrapper is invoked with the `this`
|
|---|
| 11037 | * binding of the created function.
|
|---|
| 11038 | *
|
|---|
| 11039 | * @static
|
|---|
| 11040 | * @memberOf _
|
|---|
| 11041 | * @since 0.1.0
|
|---|
| 11042 | * @category Function
|
|---|
| 11043 | * @param {*} value The value to wrap.
|
|---|
| 11044 | * @param {Function} [wrapper=identity] The wrapper function.
|
|---|
| 11045 | * @returns {Function} Returns the new function.
|
|---|
| 11046 | * @example
|
|---|
| 11047 | *
|
|---|
| 11048 | * var p = _.wrap(_.escape, function(func, text) {
|
|---|
| 11049 | * return '<p>' + func(text) + '</p>';
|
|---|
| 11050 | * });
|
|---|
| 11051 | *
|
|---|
| 11052 | * p('fred, barney, & pebbles');
|
|---|
| 11053 | * // => '<p>fred, barney, & pebbles</p>'
|
|---|
| 11054 | */
|
|---|
| 11055 | function wrap(value, wrapper) {
|
|---|
| 11056 | return partial(castFunction(wrapper), value);
|
|---|
| 11057 | }
|
|---|
| 11058 |
|
|---|
| 11059 | /*------------------------------------------------------------------------*/
|
|---|
| 11060 |
|
|---|
| 11061 | /**
|
|---|
| 11062 | * Casts `value` as an array if it's not one.
|
|---|
| 11063 | *
|
|---|
| 11064 | * @static
|
|---|
| 11065 | * @memberOf _
|
|---|
| 11066 | * @since 4.4.0
|
|---|
| 11067 | * @category Lang
|
|---|
| 11068 | * @param {*} value The value to inspect.
|
|---|
| 11069 | * @returns {Array} Returns the cast array.
|
|---|
| 11070 | * @example
|
|---|
| 11071 | *
|
|---|
| 11072 | * _.castArray(1);
|
|---|
| 11073 | * // => [1]
|
|---|
| 11074 | *
|
|---|
| 11075 | * _.castArray({ 'a': 1 });
|
|---|
| 11076 | * // => [{ 'a': 1 }]
|
|---|
| 11077 | *
|
|---|
| 11078 | * _.castArray('abc');
|
|---|
| 11079 | * // => ['abc']
|
|---|
| 11080 | *
|
|---|
| 11081 | * _.castArray(null);
|
|---|
| 11082 | * // => [null]
|
|---|
| 11083 | *
|
|---|
| 11084 | * _.castArray(undefined);
|
|---|
| 11085 | * // => [undefined]
|
|---|
| 11086 | *
|
|---|
| 11087 | * _.castArray();
|
|---|
| 11088 | * // => []
|
|---|
| 11089 | *
|
|---|
| 11090 | * var array = [1, 2, 3];
|
|---|
| 11091 | * console.log(_.castArray(array) === array);
|
|---|
| 11092 | * // => true
|
|---|
| 11093 | */
|
|---|
| 11094 | function castArray() {
|
|---|
| 11095 | if (!arguments.length) {
|
|---|
| 11096 | return [];
|
|---|
| 11097 | }
|
|---|
| 11098 | var value = arguments[0];
|
|---|
| 11099 | return isArray(value) ? value : [value];
|
|---|
| 11100 | }
|
|---|
| 11101 |
|
|---|
| 11102 | /**
|
|---|
| 11103 | * Creates a shallow clone of `value`.
|
|---|
| 11104 | *
|
|---|
| 11105 | * **Note:** This method is loosely based on the
|
|---|
| 11106 | * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
|
|---|
| 11107 | * and supports cloning arrays, array buffers, booleans, date objects, maps,
|
|---|
| 11108 | * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
|
|---|
| 11109 | * arrays. The own enumerable properties of `arguments` objects are cloned
|
|---|
| 11110 | * as plain objects. An empty object is returned for uncloneable values such
|
|---|
| 11111 | * as error objects, functions, DOM nodes, and WeakMaps.
|
|---|
| 11112 | *
|
|---|
| 11113 | * @static
|
|---|
| 11114 | * @memberOf _
|
|---|
| 11115 | * @since 0.1.0
|
|---|
| 11116 | * @category Lang
|
|---|
| 11117 | * @param {*} value The value to clone.
|
|---|
| 11118 | * @returns {*} Returns the cloned value.
|
|---|
| 11119 | * @see _.cloneDeep
|
|---|
| 11120 | * @example
|
|---|
| 11121 | *
|
|---|
| 11122 | * var objects = [{ 'a': 1 }, { 'b': 2 }];
|
|---|
| 11123 | *
|
|---|
| 11124 | * var shallow = _.clone(objects);
|
|---|
| 11125 | * console.log(shallow[0] === objects[0]);
|
|---|
| 11126 | * // => true
|
|---|
| 11127 | */
|
|---|
| 11128 | function clone(value) {
|
|---|
| 11129 | return baseClone(value, CLONE_SYMBOLS_FLAG);
|
|---|
| 11130 | }
|
|---|
| 11131 |
|
|---|
| 11132 | /**
|
|---|
| 11133 | * This method is like `_.clone` except that it accepts `customizer` which
|
|---|
| 11134 | * is invoked to produce the cloned value. If `customizer` returns `undefined`,
|
|---|
| 11135 | * cloning is handled by the method instead. The `customizer` is invoked with
|
|---|
| 11136 | * up to four arguments; (value [, index|key, object, stack]).
|
|---|
| 11137 | *
|
|---|
| 11138 | * @static
|
|---|
| 11139 | * @memberOf _
|
|---|
| 11140 | * @since 4.0.0
|
|---|
| 11141 | * @category Lang
|
|---|
| 11142 | * @param {*} value The value to clone.
|
|---|
| 11143 | * @param {Function} [customizer] The function to customize cloning.
|
|---|
| 11144 | * @returns {*} Returns the cloned value.
|
|---|
| 11145 | * @see _.cloneDeepWith
|
|---|
| 11146 | * @example
|
|---|
| 11147 | *
|
|---|
| 11148 | * function customizer(value) {
|
|---|
| 11149 | * if (_.isElement(value)) {
|
|---|
| 11150 | * return value.cloneNode(false);
|
|---|
| 11151 | * }
|
|---|
| 11152 | * }
|
|---|
| 11153 | *
|
|---|
| 11154 | * var el = _.cloneWith(document.body, customizer);
|
|---|
| 11155 | *
|
|---|
| 11156 | * console.log(el === document.body);
|
|---|
| 11157 | * // => false
|
|---|
| 11158 | * console.log(el.nodeName);
|
|---|
| 11159 | * // => 'BODY'
|
|---|
| 11160 | * console.log(el.childNodes.length);
|
|---|
| 11161 | * // => 0
|
|---|
| 11162 | */
|
|---|
| 11163 | function cloneWith(value, customizer) {
|
|---|
| 11164 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
|---|
| 11165 | return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
|
|---|
| 11166 | }
|
|---|
| 11167 |
|
|---|
| 11168 | /**
|
|---|
| 11169 | * This method is like `_.clone` except that it recursively clones `value`.
|
|---|
| 11170 | *
|
|---|
| 11171 | * @static
|
|---|
| 11172 | * @memberOf _
|
|---|
| 11173 | * @since 1.0.0
|
|---|
| 11174 | * @category Lang
|
|---|
| 11175 | * @param {*} value The value to recursively clone.
|
|---|
| 11176 | * @returns {*} Returns the deep cloned value.
|
|---|
| 11177 | * @see _.clone
|
|---|
| 11178 | * @example
|
|---|
| 11179 | *
|
|---|
| 11180 | * var objects = [{ 'a': 1 }, { 'b': 2 }];
|
|---|
| 11181 | *
|
|---|
| 11182 | * var deep = _.cloneDeep(objects);
|
|---|
| 11183 | * console.log(deep[0] === objects[0]);
|
|---|
| 11184 | * // => false
|
|---|
| 11185 | */
|
|---|
| 11186 | function cloneDeep(value) {
|
|---|
| 11187 | return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
|
|---|
| 11188 | }
|
|---|
| 11189 |
|
|---|
| 11190 | /**
|
|---|
| 11191 | * This method is like `_.cloneWith` except that it recursively clones `value`.
|
|---|
| 11192 | *
|
|---|
| 11193 | * @static
|
|---|
| 11194 | * @memberOf _
|
|---|
| 11195 | * @since 4.0.0
|
|---|
| 11196 | * @category Lang
|
|---|
| 11197 | * @param {*} value The value to recursively clone.
|
|---|
| 11198 | * @param {Function} [customizer] The function to customize cloning.
|
|---|
| 11199 | * @returns {*} Returns the deep cloned value.
|
|---|
| 11200 | * @see _.cloneWith
|
|---|
| 11201 | * @example
|
|---|
| 11202 | *
|
|---|
| 11203 | * function customizer(value) {
|
|---|
| 11204 | * if (_.isElement(value)) {
|
|---|
| 11205 | * return value.cloneNode(true);
|
|---|
| 11206 | * }
|
|---|
| 11207 | * }
|
|---|
| 11208 | *
|
|---|
| 11209 | * var el = _.cloneDeepWith(document.body, customizer);
|
|---|
| 11210 | *
|
|---|
| 11211 | * console.log(el === document.body);
|
|---|
| 11212 | * // => false
|
|---|
| 11213 | * console.log(el.nodeName);
|
|---|
| 11214 | * // => 'BODY'
|
|---|
| 11215 | * console.log(el.childNodes.length);
|
|---|
| 11216 | * // => 20
|
|---|
| 11217 | */
|
|---|
| 11218 | function cloneDeepWith(value, customizer) {
|
|---|
| 11219 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
|---|
| 11220 | return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
|
|---|
| 11221 | }
|
|---|
| 11222 |
|
|---|
| 11223 | /**
|
|---|
| 11224 | * Checks if `object` conforms to `source` by invoking the predicate
|
|---|
| 11225 | * properties of `source` with the corresponding property values of `object`.
|
|---|
| 11226 | *
|
|---|
| 11227 | * **Note:** This method is equivalent to `_.conforms` when `source` is
|
|---|
| 11228 | * partially applied.
|
|---|
| 11229 | *
|
|---|
| 11230 | * @static
|
|---|
| 11231 | * @memberOf _
|
|---|
| 11232 | * @since 4.14.0
|
|---|
| 11233 | * @category Lang
|
|---|
| 11234 | * @param {Object} object The object to inspect.
|
|---|
| 11235 | * @param {Object} source The object of property predicates to conform to.
|
|---|
| 11236 | * @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
|---|
| 11237 | * @example
|
|---|
| 11238 | *
|
|---|
| 11239 | * var object = { 'a': 1, 'b': 2 };
|
|---|
| 11240 | *
|
|---|
| 11241 | * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
|
|---|
| 11242 | * // => true
|
|---|
| 11243 | *
|
|---|
| 11244 | * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
|
|---|
| 11245 | * // => false
|
|---|
| 11246 | */
|
|---|
| 11247 | function conformsTo(object, source) {
|
|---|
| 11248 | return source == null || baseConformsTo(object, source, keys(source));
|
|---|
| 11249 | }
|
|---|
| 11250 |
|
|---|
| 11251 | /**
|
|---|
| 11252 | * Performs a
|
|---|
| 11253 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|---|
| 11254 | * comparison between two values to determine if they are equivalent.
|
|---|
| 11255 | *
|
|---|
| 11256 | * @static
|
|---|
| 11257 | * @memberOf _
|
|---|
| 11258 | * @since 4.0.0
|
|---|
| 11259 | * @category Lang
|
|---|
| 11260 | * @param {*} value The value to compare.
|
|---|
| 11261 | * @param {*} other The other value to compare.
|
|---|
| 11262 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|---|
| 11263 | * @example
|
|---|
| 11264 | *
|
|---|
| 11265 | * var object = { 'a': 1 };
|
|---|
| 11266 | * var other = { 'a': 1 };
|
|---|
| 11267 | *
|
|---|
| 11268 | * _.eq(object, object);
|
|---|
| 11269 | * // => true
|
|---|
| 11270 | *
|
|---|
| 11271 | * _.eq(object, other);
|
|---|
| 11272 | * // => false
|
|---|
| 11273 | *
|
|---|
| 11274 | * _.eq('a', 'a');
|
|---|
| 11275 | * // => true
|
|---|
| 11276 | *
|
|---|
| 11277 | * _.eq('a', Object('a'));
|
|---|
| 11278 | * // => false
|
|---|
| 11279 | *
|
|---|
| 11280 | * _.eq(NaN, NaN);
|
|---|
| 11281 | * // => true
|
|---|
| 11282 | */
|
|---|
| 11283 | function eq(value, other) {
|
|---|
| 11284 | return value === other || (value !== value && other !== other);
|
|---|
| 11285 | }
|
|---|
| 11286 |
|
|---|
| 11287 | /**
|
|---|
| 11288 | * Checks if `value` is greater than `other`.
|
|---|
| 11289 | *
|
|---|
| 11290 | * @static
|
|---|
| 11291 | * @memberOf _
|
|---|
| 11292 | * @since 3.9.0
|
|---|
| 11293 | * @category Lang
|
|---|
| 11294 | * @param {*} value The value to compare.
|
|---|
| 11295 | * @param {*} other The other value to compare.
|
|---|
| 11296 | * @returns {boolean} Returns `true` if `value` is greater than `other`,
|
|---|
| 11297 | * else `false`.
|
|---|
| 11298 | * @see _.lt
|
|---|
| 11299 | * @example
|
|---|
| 11300 | *
|
|---|
| 11301 | * _.gt(3, 1);
|
|---|
| 11302 | * // => true
|
|---|
| 11303 | *
|
|---|
| 11304 | * _.gt(3, 3);
|
|---|
| 11305 | * // => false
|
|---|
| 11306 | *
|
|---|
| 11307 | * _.gt(1, 3);
|
|---|
| 11308 | * // => false
|
|---|
| 11309 | */
|
|---|
| 11310 | var gt = createRelationalOperation(baseGt);
|
|---|
| 11311 |
|
|---|
| 11312 | /**
|
|---|
| 11313 | * Checks if `value` is greater than or equal to `other`.
|
|---|
| 11314 | *
|
|---|
| 11315 | * @static
|
|---|
| 11316 | * @memberOf _
|
|---|
| 11317 | * @since 3.9.0
|
|---|
| 11318 | * @category Lang
|
|---|
| 11319 | * @param {*} value The value to compare.
|
|---|
| 11320 | * @param {*} other The other value to compare.
|
|---|
| 11321 | * @returns {boolean} Returns `true` if `value` is greater than or equal to
|
|---|
| 11322 | * `other`, else `false`.
|
|---|
| 11323 | * @see _.lte
|
|---|
| 11324 | * @example
|
|---|
| 11325 | *
|
|---|
| 11326 | * _.gte(3, 1);
|
|---|
| 11327 | * // => true
|
|---|
| 11328 | *
|
|---|
| 11329 | * _.gte(3, 3);
|
|---|
| 11330 | * // => true
|
|---|
| 11331 | *
|
|---|
| 11332 | * _.gte(1, 3);
|
|---|
| 11333 | * // => false
|
|---|
| 11334 | */
|
|---|
| 11335 | var gte = createRelationalOperation(function(value, other) {
|
|---|
| 11336 | return value >= other;
|
|---|
| 11337 | });
|
|---|
| 11338 |
|
|---|
| 11339 | /**
|
|---|
| 11340 | * Checks if `value` is likely an `arguments` object.
|
|---|
| 11341 | *
|
|---|
| 11342 | * @static
|
|---|
| 11343 | * @memberOf _
|
|---|
| 11344 | * @since 0.1.0
|
|---|
| 11345 | * @category Lang
|
|---|
| 11346 | * @param {*} value The value to check.
|
|---|
| 11347 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
|---|
| 11348 | * else `false`.
|
|---|
| 11349 | * @example
|
|---|
| 11350 | *
|
|---|
| 11351 | * _.isArguments(function() { return arguments; }());
|
|---|
| 11352 | * // => true
|
|---|
| 11353 | *
|
|---|
| 11354 | * _.isArguments([1, 2, 3]);
|
|---|
| 11355 | * // => false
|
|---|
| 11356 | */
|
|---|
| 11357 | var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
|
|---|
| 11358 | return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
|
|---|
| 11359 | !propertyIsEnumerable.call(value, 'callee');
|
|---|
| 11360 | };
|
|---|
| 11361 |
|
|---|
| 11362 | /**
|
|---|
| 11363 | * Checks if `value` is classified as an `Array` object.
|
|---|
| 11364 | *
|
|---|
| 11365 | * @static
|
|---|
| 11366 | * @memberOf _
|
|---|
| 11367 | * @since 0.1.0
|
|---|
| 11368 | * @category Lang
|
|---|
| 11369 | * @param {*} value The value to check.
|
|---|
| 11370 | * @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|---|
| 11371 | * @example
|
|---|
| 11372 | *
|
|---|
| 11373 | * _.isArray([1, 2, 3]);
|
|---|
| 11374 | * // => true
|
|---|
| 11375 | *
|
|---|
| 11376 | * _.isArray(document.body.children);
|
|---|
| 11377 | * // => false
|
|---|
| 11378 | *
|
|---|
| 11379 | * _.isArray('abc');
|
|---|
| 11380 | * // => false
|
|---|
| 11381 | *
|
|---|
| 11382 | * _.isArray(_.noop);
|
|---|
| 11383 | * // => false
|
|---|
| 11384 | */
|
|---|
| 11385 | var isArray = Array.isArray;
|
|---|
| 11386 |
|
|---|
| 11387 | /**
|
|---|
| 11388 | * Checks if `value` is classified as an `ArrayBuffer` object.
|
|---|
| 11389 | *
|
|---|
| 11390 | * @static
|
|---|
| 11391 | * @memberOf _
|
|---|
| 11392 | * @since 4.3.0
|
|---|
| 11393 | * @category Lang
|
|---|
| 11394 | * @param {*} value The value to check.
|
|---|
| 11395 | * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
|
|---|
| 11396 | * @example
|
|---|
| 11397 | *
|
|---|
| 11398 | * _.isArrayBuffer(new ArrayBuffer(2));
|
|---|
| 11399 | * // => true
|
|---|
| 11400 | *
|
|---|
| 11401 | * _.isArrayBuffer(new Array(2));
|
|---|
| 11402 | * // => false
|
|---|
| 11403 | */
|
|---|
| 11404 | var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
|
|---|
| 11405 |
|
|---|
| 11406 | /**
|
|---|
| 11407 | * Checks if `value` is array-like. A value is considered array-like if it's
|
|---|
| 11408 | * not a function and has a `value.length` that's an integer greater than or
|
|---|
| 11409 | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
|---|
| 11410 | *
|
|---|
| 11411 | * @static
|
|---|
| 11412 | * @memberOf _
|
|---|
| 11413 | * @since 4.0.0
|
|---|
| 11414 | * @category Lang
|
|---|
| 11415 | * @param {*} value The value to check.
|
|---|
| 11416 | * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|---|
| 11417 | * @example
|
|---|
| 11418 | *
|
|---|
| 11419 | * _.isArrayLike([1, 2, 3]);
|
|---|
| 11420 | * // => true
|
|---|
| 11421 | *
|
|---|
| 11422 | * _.isArrayLike(document.body.children);
|
|---|
| 11423 | * // => true
|
|---|
| 11424 | *
|
|---|
| 11425 | * _.isArrayLike('abc');
|
|---|
| 11426 | * // => true
|
|---|
| 11427 | *
|
|---|
| 11428 | * _.isArrayLike(_.noop);
|
|---|
| 11429 | * // => false
|
|---|
| 11430 | */
|
|---|
| 11431 | function isArrayLike(value) {
|
|---|
| 11432 | return value != null && isLength(value.length) && !isFunction(value);
|
|---|
| 11433 | }
|
|---|
| 11434 |
|
|---|
| 11435 | /**
|
|---|
| 11436 | * This method is like `_.isArrayLike` except that it also checks if `value`
|
|---|
| 11437 | * is an object.
|
|---|
| 11438 | *
|
|---|
| 11439 | * @static
|
|---|
| 11440 | * @memberOf _
|
|---|
| 11441 | * @since 4.0.0
|
|---|
| 11442 | * @category Lang
|
|---|
| 11443 | * @param {*} value The value to check.
|
|---|
| 11444 | * @returns {boolean} Returns `true` if `value` is an array-like object,
|
|---|
| 11445 | * else `false`.
|
|---|
| 11446 | * @example
|
|---|
| 11447 | *
|
|---|
| 11448 | * _.isArrayLikeObject([1, 2, 3]);
|
|---|
| 11449 | * // => true
|
|---|
| 11450 | *
|
|---|
| 11451 | * _.isArrayLikeObject(document.body.children);
|
|---|
| 11452 | * // => true
|
|---|
| 11453 | *
|
|---|
| 11454 | * _.isArrayLikeObject('abc');
|
|---|
| 11455 | * // => false
|
|---|
| 11456 | *
|
|---|
| 11457 | * _.isArrayLikeObject(_.noop);
|
|---|
| 11458 | * // => false
|
|---|
| 11459 | */
|
|---|
| 11460 | function isArrayLikeObject(value) {
|
|---|
| 11461 | return isObjectLike(value) && isArrayLike(value);
|
|---|
| 11462 | }
|
|---|
| 11463 |
|
|---|
| 11464 | /**
|
|---|
| 11465 | * Checks if `value` is classified as a boolean primitive or object.
|
|---|
| 11466 | *
|
|---|
| 11467 | * @static
|
|---|
| 11468 | * @memberOf _
|
|---|
| 11469 | * @since 0.1.0
|
|---|
| 11470 | * @category Lang
|
|---|
| 11471 | * @param {*} value The value to check.
|
|---|
| 11472 | * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
|
|---|
| 11473 | * @example
|
|---|
| 11474 | *
|
|---|
| 11475 | * _.isBoolean(false);
|
|---|
| 11476 | * // => true
|
|---|
| 11477 | *
|
|---|
| 11478 | * _.isBoolean(null);
|
|---|
| 11479 | * // => false
|
|---|
| 11480 | */
|
|---|
| 11481 | function isBoolean(value) {
|
|---|
| 11482 | return value === true || value === false ||
|
|---|
| 11483 | (isObjectLike(value) && baseGetTag(value) == boolTag);
|
|---|
| 11484 | }
|
|---|
| 11485 |
|
|---|
| 11486 | /**
|
|---|
| 11487 | * Checks if `value` is a buffer.
|
|---|
| 11488 | *
|
|---|
| 11489 | * @static
|
|---|
| 11490 | * @memberOf _
|
|---|
| 11491 | * @since 4.3.0
|
|---|
| 11492 | * @category Lang
|
|---|
| 11493 | * @param {*} value The value to check.
|
|---|
| 11494 | * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
|---|
| 11495 | * @example
|
|---|
| 11496 | *
|
|---|
| 11497 | * _.isBuffer(new Buffer(2));
|
|---|
| 11498 | * // => true
|
|---|
| 11499 | *
|
|---|
| 11500 | * _.isBuffer(new Uint8Array(2));
|
|---|
| 11501 | * // => false
|
|---|
| 11502 | */
|
|---|
| 11503 | var isBuffer = nativeIsBuffer || stubFalse;
|
|---|
| 11504 |
|
|---|
| 11505 | /**
|
|---|
| 11506 | * Checks if `value` is classified as a `Date` object.
|
|---|
| 11507 | *
|
|---|
| 11508 | * @static
|
|---|
| 11509 | * @memberOf _
|
|---|
| 11510 | * @since 0.1.0
|
|---|
| 11511 | * @category Lang
|
|---|
| 11512 | * @param {*} value The value to check.
|
|---|
| 11513 | * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
|---|
| 11514 | * @example
|
|---|
| 11515 | *
|
|---|
| 11516 | * _.isDate(new Date);
|
|---|
| 11517 | * // => true
|
|---|
| 11518 | *
|
|---|
| 11519 | * _.isDate('Mon April 23 2012');
|
|---|
| 11520 | * // => false
|
|---|
| 11521 | */
|
|---|
| 11522 | var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
|
|---|
| 11523 |
|
|---|
| 11524 | /**
|
|---|
| 11525 | * Checks if `value` is likely a DOM element.
|
|---|
| 11526 | *
|
|---|
| 11527 | * @static
|
|---|
| 11528 | * @memberOf _
|
|---|
| 11529 | * @since 0.1.0
|
|---|
| 11530 | * @category Lang
|
|---|
| 11531 | * @param {*} value The value to check.
|
|---|
| 11532 | * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
|
|---|
| 11533 | * @example
|
|---|
| 11534 | *
|
|---|
| 11535 | * _.isElement(document.body);
|
|---|
| 11536 | * // => true
|
|---|
| 11537 | *
|
|---|
| 11538 | * _.isElement('<body>');
|
|---|
| 11539 | * // => false
|
|---|
| 11540 | */
|
|---|
| 11541 | function isElement(value) {
|
|---|
| 11542 | return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
|
|---|
| 11543 | }
|
|---|
| 11544 |
|
|---|
| 11545 | /**
|
|---|
| 11546 | * Checks if `value` is an empty object, collection, map, or set.
|
|---|
| 11547 | *
|
|---|
| 11548 | * Objects are considered empty if they have no own enumerable string keyed
|
|---|
| 11549 | * properties.
|
|---|
| 11550 | *
|
|---|
| 11551 | * Array-like values such as `arguments` objects, arrays, buffers, strings, or
|
|---|
| 11552 | * jQuery-like collections are considered empty if they have a `length` of `0`.
|
|---|
| 11553 | * Similarly, maps and sets are considered empty if they have a `size` of `0`.
|
|---|
| 11554 | *
|
|---|
| 11555 | * @static
|
|---|
| 11556 | * @memberOf _
|
|---|
| 11557 | * @since 0.1.0
|
|---|
| 11558 | * @category Lang
|
|---|
| 11559 | * @param {*} value The value to check.
|
|---|
| 11560 | * @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
|---|
| 11561 | * @example
|
|---|
| 11562 | *
|
|---|
| 11563 | * _.isEmpty(null);
|
|---|
| 11564 | * // => true
|
|---|
| 11565 | *
|
|---|
| 11566 | * _.isEmpty(true);
|
|---|
| 11567 | * // => true
|
|---|
| 11568 | *
|
|---|
| 11569 | * _.isEmpty(1);
|
|---|
| 11570 | * // => true
|
|---|
| 11571 | *
|
|---|
| 11572 | * _.isEmpty([1, 2, 3]);
|
|---|
| 11573 | * // => false
|
|---|
| 11574 | *
|
|---|
| 11575 | * _.isEmpty({ 'a': 1 });
|
|---|
| 11576 | * // => false
|
|---|
| 11577 | */
|
|---|
| 11578 | function isEmpty(value) {
|
|---|
| 11579 | if (value == null) {
|
|---|
| 11580 | return true;
|
|---|
| 11581 | }
|
|---|
| 11582 | if (isArrayLike(value) &&
|
|---|
| 11583 | (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
|
|---|
| 11584 | isBuffer(value) || isTypedArray(value) || isArguments(value))) {
|
|---|
| 11585 | return !value.length;
|
|---|
| 11586 | }
|
|---|
| 11587 | var tag = getTag(value);
|
|---|
| 11588 | if (tag == mapTag || tag == setTag) {
|
|---|
| 11589 | return !value.size;
|
|---|
| 11590 | }
|
|---|
| 11591 | if (isPrototype(value)) {
|
|---|
| 11592 | return !baseKeys(value).length;
|
|---|
| 11593 | }
|
|---|
| 11594 | for (var key in value) {
|
|---|
| 11595 | if (hasOwnProperty.call(value, key)) {
|
|---|
| 11596 | return false;
|
|---|
| 11597 | }
|
|---|
| 11598 | }
|
|---|
| 11599 | return true;
|
|---|
| 11600 | }
|
|---|
| 11601 |
|
|---|
| 11602 | /**
|
|---|
| 11603 | * Performs a deep comparison between two values to determine if they are
|
|---|
| 11604 | * equivalent.
|
|---|
| 11605 | *
|
|---|
| 11606 | * **Note:** This method supports comparing arrays, array buffers, booleans,
|
|---|
| 11607 | * date objects, error objects, maps, numbers, `Object` objects, regexes,
|
|---|
| 11608 | * sets, strings, symbols, and typed arrays. `Object` objects are compared
|
|---|
| 11609 | * by their own, not inherited, enumerable properties. Functions and DOM
|
|---|
| 11610 | * nodes are compared by strict equality, i.e. `===`.
|
|---|
| 11611 | *
|
|---|
| 11612 | * @static
|
|---|
| 11613 | * @memberOf _
|
|---|
| 11614 | * @since 0.1.0
|
|---|
| 11615 | * @category Lang
|
|---|
| 11616 | * @param {*} value The value to compare.
|
|---|
| 11617 | * @param {*} other The other value to compare.
|
|---|
| 11618 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|---|
| 11619 | * @example
|
|---|
| 11620 | *
|
|---|
| 11621 | * var object = { 'a': 1 };
|
|---|
| 11622 | * var other = { 'a': 1 };
|
|---|
| 11623 | *
|
|---|
| 11624 | * _.isEqual(object, other);
|
|---|
| 11625 | * // => true
|
|---|
| 11626 | *
|
|---|
| 11627 | * object === other;
|
|---|
| 11628 | * // => false
|
|---|
| 11629 | */
|
|---|
| 11630 | function isEqual(value, other) {
|
|---|
| 11631 | return baseIsEqual(value, other);
|
|---|
| 11632 | }
|
|---|
| 11633 |
|
|---|
| 11634 | /**
|
|---|
| 11635 | * This method is like `_.isEqual` except that it accepts `customizer` which
|
|---|
| 11636 | * is invoked to compare values. If `customizer` returns `undefined`, comparisons
|
|---|
| 11637 | * are handled by the method instead. The `customizer` is invoked with up to
|
|---|
| 11638 | * six arguments: (objValue, othValue [, index|key, object, other, stack]).
|
|---|
| 11639 | *
|
|---|
| 11640 | * @static
|
|---|
| 11641 | * @memberOf _
|
|---|
| 11642 | * @since 4.0.0
|
|---|
| 11643 | * @category Lang
|
|---|
| 11644 | * @param {*} value The value to compare.
|
|---|
| 11645 | * @param {*} other The other value to compare.
|
|---|
| 11646 | * @param {Function} [customizer] The function to customize comparisons.
|
|---|
| 11647 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|---|
| 11648 | * @example
|
|---|
| 11649 | *
|
|---|
| 11650 | * function isGreeting(value) {
|
|---|
| 11651 | * return /^h(?:i|ello)$/.test(value);
|
|---|
| 11652 | * }
|
|---|
| 11653 | *
|
|---|
| 11654 | * function customizer(objValue, othValue) {
|
|---|
| 11655 | * if (isGreeting(objValue) && isGreeting(othValue)) {
|
|---|
| 11656 | * return true;
|
|---|
| 11657 | * }
|
|---|
| 11658 | * }
|
|---|
| 11659 | *
|
|---|
| 11660 | * var array = ['hello', 'goodbye'];
|
|---|
| 11661 | * var other = ['hi', 'goodbye'];
|
|---|
| 11662 | *
|
|---|
| 11663 | * _.isEqualWith(array, other, customizer);
|
|---|
| 11664 | * // => true
|
|---|
| 11665 | */
|
|---|
| 11666 | function isEqualWith(value, other, customizer) {
|
|---|
| 11667 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
|---|
| 11668 | var result = customizer ? customizer(value, other) : undefined;
|
|---|
| 11669 | return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
|
|---|
| 11670 | }
|
|---|
| 11671 |
|
|---|
| 11672 | /**
|
|---|
| 11673 | * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
|
|---|
| 11674 | * `SyntaxError`, `TypeError`, or `URIError` object.
|
|---|
| 11675 | *
|
|---|
| 11676 | * @static
|
|---|
| 11677 | * @memberOf _
|
|---|
| 11678 | * @since 3.0.0
|
|---|
| 11679 | * @category Lang
|
|---|
| 11680 | * @param {*} value The value to check.
|
|---|
| 11681 | * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
|
|---|
| 11682 | * @example
|
|---|
| 11683 | *
|
|---|
| 11684 | * _.isError(new Error);
|
|---|
| 11685 | * // => true
|
|---|
| 11686 | *
|
|---|
| 11687 | * _.isError(Error);
|
|---|
| 11688 | * // => false
|
|---|
| 11689 | */
|
|---|
| 11690 | function isError(value) {
|
|---|
| 11691 | if (!isObjectLike(value)) {
|
|---|
| 11692 | return false;
|
|---|
| 11693 | }
|
|---|
| 11694 | var tag = baseGetTag(value);
|
|---|
| 11695 | return tag == errorTag || tag == domExcTag ||
|
|---|
| 11696 | (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
|
|---|
| 11697 | }
|
|---|
| 11698 |
|
|---|
| 11699 | /**
|
|---|
| 11700 | * Checks if `value` is a finite primitive number.
|
|---|
| 11701 | *
|
|---|
| 11702 | * **Note:** This method is based on
|
|---|
| 11703 | * [`Number.isFinite`](https://mdn.io/Number/isFinite).
|
|---|
| 11704 | *
|
|---|
| 11705 | * @static
|
|---|
| 11706 | * @memberOf _
|
|---|
| 11707 | * @since 0.1.0
|
|---|
| 11708 | * @category Lang
|
|---|
| 11709 | * @param {*} value The value to check.
|
|---|
| 11710 | * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
|
|---|
| 11711 | * @example
|
|---|
| 11712 | *
|
|---|
| 11713 | * _.isFinite(3);
|
|---|
| 11714 | * // => true
|
|---|
| 11715 | *
|
|---|
| 11716 | * _.isFinite(Number.MIN_VALUE);
|
|---|
| 11717 | * // => true
|
|---|
| 11718 | *
|
|---|
| 11719 | * _.isFinite(Infinity);
|
|---|
| 11720 | * // => false
|
|---|
| 11721 | *
|
|---|
| 11722 | * _.isFinite('3');
|
|---|
| 11723 | * // => false
|
|---|
| 11724 | */
|
|---|
| 11725 | function isFinite(value) {
|
|---|
| 11726 | return typeof value == 'number' && nativeIsFinite(value);
|
|---|
| 11727 | }
|
|---|
| 11728 |
|
|---|
| 11729 | /**
|
|---|
| 11730 | * Checks if `value` is classified as a `Function` object.
|
|---|
| 11731 | *
|
|---|
| 11732 | * @static
|
|---|
| 11733 | * @memberOf _
|
|---|
| 11734 | * @since 0.1.0
|
|---|
| 11735 | * @category Lang
|
|---|
| 11736 | * @param {*} value The value to check.
|
|---|
| 11737 | * @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|---|
| 11738 | * @example
|
|---|
| 11739 | *
|
|---|
| 11740 | * _.isFunction(_);
|
|---|
| 11741 | * // => true
|
|---|
| 11742 | *
|
|---|
| 11743 | * _.isFunction(/abc/);
|
|---|
| 11744 | * // => false
|
|---|
| 11745 | */
|
|---|
| 11746 | function isFunction(value) {
|
|---|
| 11747 | if (!isObject(value)) {
|
|---|
| 11748 | return false;
|
|---|
| 11749 | }
|
|---|
| 11750 | // The use of `Object#toString` avoids issues with the `typeof` operator
|
|---|
| 11751 | // in Safari 9 which returns 'object' for typed arrays and other constructors.
|
|---|
| 11752 | var tag = baseGetTag(value);
|
|---|
| 11753 | return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|---|
| 11754 | }
|
|---|
| 11755 |
|
|---|
| 11756 | /**
|
|---|
| 11757 | * Checks if `value` is an integer.
|
|---|
| 11758 | *
|
|---|
| 11759 | * **Note:** This method is based on
|
|---|
| 11760 | * [`Number.isInteger`](https://mdn.io/Number/isInteger).
|
|---|
| 11761 | *
|
|---|
| 11762 | * @static
|
|---|
| 11763 | * @memberOf _
|
|---|
| 11764 | * @since 4.0.0
|
|---|
| 11765 | * @category Lang
|
|---|
| 11766 | * @param {*} value The value to check.
|
|---|
| 11767 | * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
|
|---|
| 11768 | * @example
|
|---|
| 11769 | *
|
|---|
| 11770 | * _.isInteger(3);
|
|---|
| 11771 | * // => true
|
|---|
| 11772 | *
|
|---|
| 11773 | * _.isInteger(Number.MIN_VALUE);
|
|---|
| 11774 | * // => false
|
|---|
| 11775 | *
|
|---|
| 11776 | * _.isInteger(Infinity);
|
|---|
| 11777 | * // => false
|
|---|
| 11778 | *
|
|---|
| 11779 | * _.isInteger('3');
|
|---|
| 11780 | * // => false
|
|---|
| 11781 | */
|
|---|
| 11782 | function isInteger(value) {
|
|---|
| 11783 | return typeof value == 'number' && value == toInteger(value);
|
|---|
| 11784 | }
|
|---|
| 11785 |
|
|---|
| 11786 | /**
|
|---|
| 11787 | * Checks if `value` is a valid array-like length.
|
|---|
| 11788 | *
|
|---|
| 11789 | * **Note:** This method is loosely based on
|
|---|
| 11790 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|---|
| 11791 | *
|
|---|
| 11792 | * @static
|
|---|
| 11793 | * @memberOf _
|
|---|
| 11794 | * @since 4.0.0
|
|---|
| 11795 | * @category Lang
|
|---|
| 11796 | * @param {*} value The value to check.
|
|---|
| 11797 | * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|---|
| 11798 | * @example
|
|---|
| 11799 | *
|
|---|
| 11800 | * _.isLength(3);
|
|---|
| 11801 | * // => true
|
|---|
| 11802 | *
|
|---|
| 11803 | * _.isLength(Number.MIN_VALUE);
|
|---|
| 11804 | * // => false
|
|---|
| 11805 | *
|
|---|
| 11806 | * _.isLength(Infinity);
|
|---|
| 11807 | * // => false
|
|---|
| 11808 | *
|
|---|
| 11809 | * _.isLength('3');
|
|---|
| 11810 | * // => false
|
|---|
| 11811 | */
|
|---|
| 11812 | function isLength(value) {
|
|---|
| 11813 | return typeof value == 'number' &&
|
|---|
| 11814 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|---|
| 11815 | }
|
|---|
| 11816 |
|
|---|
| 11817 | /**
|
|---|
| 11818 | * Checks if `value` is the
|
|---|
| 11819 | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|---|
| 11820 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|---|
| 11821 | *
|
|---|
| 11822 | * @static
|
|---|
| 11823 | * @memberOf _
|
|---|
| 11824 | * @since 0.1.0
|
|---|
| 11825 | * @category Lang
|
|---|
| 11826 | * @param {*} value The value to check.
|
|---|
| 11827 | * @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|---|
| 11828 | * @example
|
|---|
| 11829 | *
|
|---|
| 11830 | * _.isObject({});
|
|---|
| 11831 | * // => true
|
|---|
| 11832 | *
|
|---|
| 11833 | * _.isObject([1, 2, 3]);
|
|---|
| 11834 | * // => true
|
|---|
| 11835 | *
|
|---|
| 11836 | * _.isObject(_.noop);
|
|---|
| 11837 | * // => true
|
|---|
| 11838 | *
|
|---|
| 11839 | * _.isObject(null);
|
|---|
| 11840 | * // => false
|
|---|
| 11841 | */
|
|---|
| 11842 | function isObject(value) {
|
|---|
| 11843 | var type = typeof value;
|
|---|
| 11844 | return value != null && (type == 'object' || type == 'function');
|
|---|
| 11845 | }
|
|---|
| 11846 |
|
|---|
| 11847 | /**
|
|---|
| 11848 | * Checks if `value` is object-like. A value is object-like if it's not `null`
|
|---|
| 11849 | * and has a `typeof` result of "object".
|
|---|
| 11850 | *
|
|---|
| 11851 | * @static
|
|---|
| 11852 | * @memberOf _
|
|---|
| 11853 | * @since 4.0.0
|
|---|
| 11854 | * @category Lang
|
|---|
| 11855 | * @param {*} value The value to check.
|
|---|
| 11856 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
|---|
| 11857 | * @example
|
|---|
| 11858 | *
|
|---|
| 11859 | * _.isObjectLike({});
|
|---|
| 11860 | * // => true
|
|---|
| 11861 | *
|
|---|
| 11862 | * _.isObjectLike([1, 2, 3]);
|
|---|
| 11863 | * // => true
|
|---|
| 11864 | *
|
|---|
| 11865 | * _.isObjectLike(_.noop);
|
|---|
| 11866 | * // => false
|
|---|
| 11867 | *
|
|---|
| 11868 | * _.isObjectLike(null);
|
|---|
| 11869 | * // => false
|
|---|
| 11870 | */
|
|---|
| 11871 | function isObjectLike(value) {
|
|---|
| 11872 | return value != null && typeof value == 'object';
|
|---|
| 11873 | }
|
|---|
| 11874 |
|
|---|
| 11875 | /**
|
|---|
| 11876 | * Checks if `value` is classified as a `Map` object.
|
|---|
| 11877 | *
|
|---|
| 11878 | * @static
|
|---|
| 11879 | * @memberOf _
|
|---|
| 11880 | * @since 4.3.0
|
|---|
| 11881 | * @category Lang
|
|---|
| 11882 | * @param {*} value The value to check.
|
|---|
| 11883 | * @returns {boolean} Returns `true` if `value` is a map, else `false`.
|
|---|
| 11884 | * @example
|
|---|
| 11885 | *
|
|---|
| 11886 | * _.isMap(new Map);
|
|---|
| 11887 | * // => true
|
|---|
| 11888 | *
|
|---|
| 11889 | * _.isMap(new WeakMap);
|
|---|
| 11890 | * // => false
|
|---|
| 11891 | */
|
|---|
| 11892 | var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
|
|---|
| 11893 |
|
|---|
| 11894 | /**
|
|---|
| 11895 | * Performs a partial deep comparison between `object` and `source` to
|
|---|
| 11896 | * determine if `object` contains equivalent property values.
|
|---|
| 11897 | *
|
|---|
| 11898 | * **Note:** This method is equivalent to `_.matches` when `source` is
|
|---|
| 11899 | * partially applied.
|
|---|
| 11900 | *
|
|---|
| 11901 | * Partial comparisons will match empty array and empty object `source`
|
|---|
| 11902 | * values against any array or object value, respectively. See `_.isEqual`
|
|---|
| 11903 | * for a list of supported value comparisons.
|
|---|
| 11904 | *
|
|---|
| 11905 | * @static
|
|---|
| 11906 | * @memberOf _
|
|---|
| 11907 | * @since 3.0.0
|
|---|
| 11908 | * @category Lang
|
|---|
| 11909 | * @param {Object} object The object to inspect.
|
|---|
| 11910 | * @param {Object} source The object of property values to match.
|
|---|
| 11911 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|---|
| 11912 | * @example
|
|---|
| 11913 | *
|
|---|
| 11914 | * var object = { 'a': 1, 'b': 2 };
|
|---|
| 11915 | *
|
|---|
| 11916 | * _.isMatch(object, { 'b': 2 });
|
|---|
| 11917 | * // => true
|
|---|
| 11918 | *
|
|---|
| 11919 | * _.isMatch(object, { 'b': 1 });
|
|---|
| 11920 | * // => false
|
|---|
| 11921 | */
|
|---|
| 11922 | function isMatch(object, source) {
|
|---|
| 11923 | return object === source || baseIsMatch(object, source, getMatchData(source));
|
|---|
| 11924 | }
|
|---|
| 11925 |
|
|---|
| 11926 | /**
|
|---|
| 11927 | * This method is like `_.isMatch` except that it accepts `customizer` which
|
|---|
| 11928 | * is invoked to compare values. If `customizer` returns `undefined`, comparisons
|
|---|
| 11929 | * are handled by the method instead. The `customizer` is invoked with five
|
|---|
| 11930 | * arguments: (objValue, srcValue, index|key, object, source).
|
|---|
| 11931 | *
|
|---|
| 11932 | * @static
|
|---|
| 11933 | * @memberOf _
|
|---|
| 11934 | * @since 4.0.0
|
|---|
| 11935 | * @category Lang
|
|---|
| 11936 | * @param {Object} object The object to inspect.
|
|---|
| 11937 | * @param {Object} source The object of property values to match.
|
|---|
| 11938 | * @param {Function} [customizer] The function to customize comparisons.
|
|---|
| 11939 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|---|
| 11940 | * @example
|
|---|
| 11941 | *
|
|---|
| 11942 | * function isGreeting(value) {
|
|---|
| 11943 | * return /^h(?:i|ello)$/.test(value);
|
|---|
| 11944 | * }
|
|---|
| 11945 | *
|
|---|
| 11946 | * function customizer(objValue, srcValue) {
|
|---|
| 11947 | * if (isGreeting(objValue) && isGreeting(srcValue)) {
|
|---|
| 11948 | * return true;
|
|---|
| 11949 | * }
|
|---|
| 11950 | * }
|
|---|
| 11951 | *
|
|---|
| 11952 | * var object = { 'greeting': 'hello' };
|
|---|
| 11953 | * var source = { 'greeting': 'hi' };
|
|---|
| 11954 | *
|
|---|
| 11955 | * _.isMatchWith(object, source, customizer);
|
|---|
| 11956 | * // => true
|
|---|
| 11957 | */
|
|---|
| 11958 | function isMatchWith(object, source, customizer) {
|
|---|
| 11959 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
|---|
| 11960 | return baseIsMatch(object, source, getMatchData(source), customizer);
|
|---|
| 11961 | }
|
|---|
| 11962 |
|
|---|
| 11963 | /**
|
|---|
| 11964 | * Checks if `value` is `NaN`.
|
|---|
| 11965 | *
|
|---|
| 11966 | * **Note:** This method is based on
|
|---|
| 11967 | * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
|
|---|
| 11968 | * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
|
|---|
| 11969 | * `undefined` and other non-number values.
|
|---|
| 11970 | *
|
|---|
| 11971 | * @static
|
|---|
| 11972 | * @memberOf _
|
|---|
| 11973 | * @since 0.1.0
|
|---|
| 11974 | * @category Lang
|
|---|
| 11975 | * @param {*} value The value to check.
|
|---|
| 11976 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
|---|
| 11977 | * @example
|
|---|
| 11978 | *
|
|---|
| 11979 | * _.isNaN(NaN);
|
|---|
| 11980 | * // => true
|
|---|
| 11981 | *
|
|---|
| 11982 | * _.isNaN(new Number(NaN));
|
|---|
| 11983 | * // => true
|
|---|
| 11984 | *
|
|---|
| 11985 | * isNaN(undefined);
|
|---|
| 11986 | * // => true
|
|---|
| 11987 | *
|
|---|
| 11988 | * _.isNaN(undefined);
|
|---|
| 11989 | * // => false
|
|---|
| 11990 | */
|
|---|
| 11991 | function isNaN(value) {
|
|---|
| 11992 | // An `NaN` primitive is the only value that is not equal to itself.
|
|---|
| 11993 | // Perform the `toStringTag` check first to avoid errors with some
|
|---|
| 11994 | // ActiveX objects in IE.
|
|---|
| 11995 | return isNumber(value) && value != +value;
|
|---|
| 11996 | }
|
|---|
| 11997 |
|
|---|
| 11998 | /**
|
|---|
| 11999 | * Checks if `value` is a pristine native function.
|
|---|
| 12000 | *
|
|---|
| 12001 | * **Note:** This method can't reliably detect native functions in the presence
|
|---|
| 12002 | * of the core-js package because core-js circumvents this kind of detection.
|
|---|
| 12003 | * Despite multiple requests, the core-js maintainer has made it clear: any
|
|---|
| 12004 | * attempt to fix the detection will be obstructed. As a result, we're left
|
|---|
| 12005 | * with little choice but to throw an error. Unfortunately, this also affects
|
|---|
| 12006 | * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
|
|---|
| 12007 | * which rely on core-js.
|
|---|
| 12008 | *
|
|---|
| 12009 | * @static
|
|---|
| 12010 | * @memberOf _
|
|---|
| 12011 | * @since 3.0.0
|
|---|
| 12012 | * @category Lang
|
|---|
| 12013 | * @param {*} value The value to check.
|
|---|
| 12014 | * @returns {boolean} Returns `true` if `value` is a native function,
|
|---|
| 12015 | * else `false`.
|
|---|
| 12016 | * @example
|
|---|
| 12017 | *
|
|---|
| 12018 | * _.isNative(Array.prototype.push);
|
|---|
| 12019 | * // => true
|
|---|
| 12020 | *
|
|---|
| 12021 | * _.isNative(_);
|
|---|
| 12022 | * // => false
|
|---|
| 12023 | */
|
|---|
| 12024 | function isNative(value) {
|
|---|
| 12025 | if (isMaskable(value)) {
|
|---|
| 12026 | throw new Error(CORE_ERROR_TEXT);
|
|---|
| 12027 | }
|
|---|
| 12028 | return baseIsNative(value);
|
|---|
| 12029 | }
|
|---|
| 12030 |
|
|---|
| 12031 | /**
|
|---|
| 12032 | * Checks if `value` is `null`.
|
|---|
| 12033 | *
|
|---|
| 12034 | * @static
|
|---|
| 12035 | * @memberOf _
|
|---|
| 12036 | * @since 0.1.0
|
|---|
| 12037 | * @category Lang
|
|---|
| 12038 | * @param {*} value The value to check.
|
|---|
| 12039 | * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
|
|---|
| 12040 | * @example
|
|---|
| 12041 | *
|
|---|
| 12042 | * _.isNull(null);
|
|---|
| 12043 | * // => true
|
|---|
| 12044 | *
|
|---|
| 12045 | * _.isNull(void 0);
|
|---|
| 12046 | * // => false
|
|---|
| 12047 | */
|
|---|
| 12048 | function isNull(value) {
|
|---|
| 12049 | return value === null;
|
|---|
| 12050 | }
|
|---|
| 12051 |
|
|---|
| 12052 | /**
|
|---|
| 12053 | * Checks if `value` is `null` or `undefined`.
|
|---|
| 12054 | *
|
|---|
| 12055 | * @static
|
|---|
| 12056 | * @memberOf _
|
|---|
| 12057 | * @since 4.0.0
|
|---|
| 12058 | * @category Lang
|
|---|
| 12059 | * @param {*} value The value to check.
|
|---|
| 12060 | * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
|
|---|
| 12061 | * @example
|
|---|
| 12062 | *
|
|---|
| 12063 | * _.isNil(null);
|
|---|
| 12064 | * // => true
|
|---|
| 12065 | *
|
|---|
| 12066 | * _.isNil(void 0);
|
|---|
| 12067 | * // => true
|
|---|
| 12068 | *
|
|---|
| 12069 | * _.isNil(NaN);
|
|---|
| 12070 | * // => false
|
|---|
| 12071 | */
|
|---|
| 12072 | function isNil(value) {
|
|---|
| 12073 | return value == null;
|
|---|
| 12074 | }
|
|---|
| 12075 |
|
|---|
| 12076 | /**
|
|---|
| 12077 | * Checks if `value` is classified as a `Number` primitive or object.
|
|---|
| 12078 | *
|
|---|
| 12079 | * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
|
|---|
| 12080 | * classified as numbers, use the `_.isFinite` method.
|
|---|
| 12081 | *
|
|---|
| 12082 | * @static
|
|---|
| 12083 | * @memberOf _
|
|---|
| 12084 | * @since 0.1.0
|
|---|
| 12085 | * @category Lang
|
|---|
| 12086 | * @param {*} value The value to check.
|
|---|
| 12087 | * @returns {boolean} Returns `true` if `value` is a number, else `false`.
|
|---|
| 12088 | * @example
|
|---|
| 12089 | *
|
|---|
| 12090 | * _.isNumber(3);
|
|---|
| 12091 | * // => true
|
|---|
| 12092 | *
|
|---|
| 12093 | * _.isNumber(Number.MIN_VALUE);
|
|---|
| 12094 | * // => true
|
|---|
| 12095 | *
|
|---|
| 12096 | * _.isNumber(Infinity);
|
|---|
| 12097 | * // => true
|
|---|
| 12098 | *
|
|---|
| 12099 | * _.isNumber('3');
|
|---|
| 12100 | * // => false
|
|---|
| 12101 | */
|
|---|
| 12102 | function isNumber(value) {
|
|---|
| 12103 | return typeof value == 'number' ||
|
|---|
| 12104 | (isObjectLike(value) && baseGetTag(value) == numberTag);
|
|---|
| 12105 | }
|
|---|
| 12106 |
|
|---|
| 12107 | /**
|
|---|
| 12108 | * Checks if `value` is a plain object, that is, an object created by the
|
|---|
| 12109 | * `Object` constructor or one with a `[[Prototype]]` of `null`.
|
|---|
| 12110 | *
|
|---|
| 12111 | * @static
|
|---|
| 12112 | * @memberOf _
|
|---|
| 12113 | * @since 0.8.0
|
|---|
| 12114 | * @category Lang
|
|---|
| 12115 | * @param {*} value The value to check.
|
|---|
| 12116 | * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
|---|
| 12117 | * @example
|
|---|
| 12118 | *
|
|---|
| 12119 | * function Foo() {
|
|---|
| 12120 | * this.a = 1;
|
|---|
| 12121 | * }
|
|---|
| 12122 | *
|
|---|
| 12123 | * _.isPlainObject(new Foo);
|
|---|
| 12124 | * // => false
|
|---|
| 12125 | *
|
|---|
| 12126 | * _.isPlainObject([1, 2, 3]);
|
|---|
| 12127 | * // => false
|
|---|
| 12128 | *
|
|---|
| 12129 | * _.isPlainObject({ 'x': 0, 'y': 0 });
|
|---|
| 12130 | * // => true
|
|---|
| 12131 | *
|
|---|
| 12132 | * _.isPlainObject(Object.create(null));
|
|---|
| 12133 | * // => true
|
|---|
| 12134 | */
|
|---|
| 12135 | function isPlainObject(value) {
|
|---|
| 12136 | if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
|
|---|
| 12137 | return false;
|
|---|
| 12138 | }
|
|---|
| 12139 | var proto = getPrototype(value);
|
|---|
| 12140 | if (proto === null) {
|
|---|
| 12141 | return true;
|
|---|
| 12142 | }
|
|---|
| 12143 | var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
|
|---|
| 12144 | return typeof Ctor == 'function' && Ctor instanceof Ctor &&
|
|---|
| 12145 | funcToString.call(Ctor) == objectCtorString;
|
|---|
| 12146 | }
|
|---|
| 12147 |
|
|---|
| 12148 | /**
|
|---|
| 12149 | * Checks if `value` is classified as a `RegExp` object.
|
|---|
| 12150 | *
|
|---|
| 12151 | * @static
|
|---|
| 12152 | * @memberOf _
|
|---|
| 12153 | * @since 0.1.0
|
|---|
| 12154 | * @category Lang
|
|---|
| 12155 | * @param {*} value The value to check.
|
|---|
| 12156 | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
|
|---|
| 12157 | * @example
|
|---|
| 12158 | *
|
|---|
| 12159 | * _.isRegExp(/abc/);
|
|---|
| 12160 | * // => true
|
|---|
| 12161 | *
|
|---|
| 12162 | * _.isRegExp('/abc/');
|
|---|
| 12163 | * // => false
|
|---|
| 12164 | */
|
|---|
| 12165 | var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
|
|---|
| 12166 |
|
|---|
| 12167 | /**
|
|---|
| 12168 | * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
|
|---|
| 12169 | * double precision number which isn't the result of a rounded unsafe integer.
|
|---|
| 12170 | *
|
|---|
| 12171 | * **Note:** This method is based on
|
|---|
| 12172 | * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
|
|---|
| 12173 | *
|
|---|
| 12174 | * @static
|
|---|
| 12175 | * @memberOf _
|
|---|
| 12176 | * @since 4.0.0
|
|---|
| 12177 | * @category Lang
|
|---|
| 12178 | * @param {*} value The value to check.
|
|---|
| 12179 | * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
|
|---|
| 12180 | * @example
|
|---|
| 12181 | *
|
|---|
| 12182 | * _.isSafeInteger(3);
|
|---|
| 12183 | * // => true
|
|---|
| 12184 | *
|
|---|
| 12185 | * _.isSafeInteger(Number.MIN_VALUE);
|
|---|
| 12186 | * // => false
|
|---|
| 12187 | *
|
|---|
| 12188 | * _.isSafeInteger(Infinity);
|
|---|
| 12189 | * // => false
|
|---|
| 12190 | *
|
|---|
| 12191 | * _.isSafeInteger('3');
|
|---|
| 12192 | * // => false
|
|---|
| 12193 | */
|
|---|
| 12194 | function isSafeInteger(value) {
|
|---|
| 12195 | return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
|---|
| 12196 | }
|
|---|
| 12197 |
|
|---|
| 12198 | /**
|
|---|
| 12199 | * Checks if `value` is classified as a `Set` object.
|
|---|
| 12200 | *
|
|---|
| 12201 | * @static
|
|---|
| 12202 | * @memberOf _
|
|---|
| 12203 | * @since 4.3.0
|
|---|
| 12204 | * @category Lang
|
|---|
| 12205 | * @param {*} value The value to check.
|
|---|
| 12206 | * @returns {boolean} Returns `true` if `value` is a set, else `false`.
|
|---|
| 12207 | * @example
|
|---|
| 12208 | *
|
|---|
| 12209 | * _.isSet(new Set);
|
|---|
| 12210 | * // => true
|
|---|
| 12211 | *
|
|---|
| 12212 | * _.isSet(new WeakSet);
|
|---|
| 12213 | * // => false
|
|---|
| 12214 | */
|
|---|
| 12215 | var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
|---|
| 12216 |
|
|---|
| 12217 | /**
|
|---|
| 12218 | * Checks if `value` is classified as a `String` primitive or object.
|
|---|
| 12219 | *
|
|---|
| 12220 | * @static
|
|---|
| 12221 | * @since 0.1.0
|
|---|
| 12222 | * @memberOf _
|
|---|
| 12223 | * @category Lang
|
|---|
| 12224 | * @param {*} value The value to check.
|
|---|
| 12225 | * @returns {boolean} Returns `true` if `value` is a string, else `false`.
|
|---|
| 12226 | * @example
|
|---|
| 12227 | *
|
|---|
| 12228 | * _.isString('abc');
|
|---|
| 12229 | * // => true
|
|---|
| 12230 | *
|
|---|
| 12231 | * _.isString(1);
|
|---|
| 12232 | * // => false
|
|---|
| 12233 | */
|
|---|
| 12234 | function isString(value) {
|
|---|
| 12235 | return typeof value == 'string' ||
|
|---|
| 12236 | (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
|
|---|
| 12237 | }
|
|---|
| 12238 |
|
|---|
| 12239 | /**
|
|---|
| 12240 | * Checks if `value` is classified as a `Symbol` primitive or object.
|
|---|
| 12241 | *
|
|---|
| 12242 | * @static
|
|---|
| 12243 | * @memberOf _
|
|---|
| 12244 | * @since 4.0.0
|
|---|
| 12245 | * @category Lang
|
|---|
| 12246 | * @param {*} value The value to check.
|
|---|
| 12247 | * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
|---|
| 12248 | * @example
|
|---|
| 12249 | *
|
|---|
| 12250 | * _.isSymbol(Symbol.iterator);
|
|---|
| 12251 | * // => true
|
|---|
| 12252 | *
|
|---|
| 12253 | * _.isSymbol('abc');
|
|---|
| 12254 | * // => false
|
|---|
| 12255 | */
|
|---|
| 12256 | function isSymbol(value) {
|
|---|
| 12257 | return typeof value == 'symbol' ||
|
|---|
| 12258 | (isObjectLike(value) && baseGetTag(value) == symbolTag);
|
|---|
| 12259 | }
|
|---|
| 12260 |
|
|---|
| 12261 | /**
|
|---|
| 12262 | * Checks if `value` is classified as a typed array.
|
|---|
| 12263 | *
|
|---|
| 12264 | * @static
|
|---|
| 12265 | * @memberOf _
|
|---|
| 12266 | * @since 3.0.0
|
|---|
| 12267 | * @category Lang
|
|---|
| 12268 | * @param {*} value The value to check.
|
|---|
| 12269 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
|---|
| 12270 | * @example
|
|---|
| 12271 | *
|
|---|
| 12272 | * _.isTypedArray(new Uint8Array);
|
|---|
| 12273 | * // => true
|
|---|
| 12274 | *
|
|---|
| 12275 | * _.isTypedArray([]);
|
|---|
| 12276 | * // => false
|
|---|
| 12277 | */
|
|---|
| 12278 | var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
|
|---|
| 12279 |
|
|---|
| 12280 | /**
|
|---|
| 12281 | * Checks if `value` is `undefined`.
|
|---|
| 12282 | *
|
|---|
| 12283 | * @static
|
|---|
| 12284 | * @since 0.1.0
|
|---|
| 12285 | * @memberOf _
|
|---|
| 12286 | * @category Lang
|
|---|
| 12287 | * @param {*} value The value to check.
|
|---|
| 12288 | * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
|
|---|
| 12289 | * @example
|
|---|
| 12290 | *
|
|---|
| 12291 | * _.isUndefined(void 0);
|
|---|
| 12292 | * // => true
|
|---|
| 12293 | *
|
|---|
| 12294 | * _.isUndefined(null);
|
|---|
| 12295 | * // => false
|
|---|
| 12296 | */
|
|---|
| 12297 | function isUndefined(value) {
|
|---|
| 12298 | return value === undefined;
|
|---|
| 12299 | }
|
|---|
| 12300 |
|
|---|
| 12301 | /**
|
|---|
| 12302 | * Checks if `value` is classified as a `WeakMap` object.
|
|---|
| 12303 | *
|
|---|
| 12304 | * @static
|
|---|
| 12305 | * @memberOf _
|
|---|
| 12306 | * @since 4.3.0
|
|---|
| 12307 | * @category Lang
|
|---|
| 12308 | * @param {*} value The value to check.
|
|---|
| 12309 | * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
|
|---|
| 12310 | * @example
|
|---|
| 12311 | *
|
|---|
| 12312 | * _.isWeakMap(new WeakMap);
|
|---|
| 12313 | * // => true
|
|---|
| 12314 | *
|
|---|
| 12315 | * _.isWeakMap(new Map);
|
|---|
| 12316 | * // => false
|
|---|
| 12317 | */
|
|---|
| 12318 | function isWeakMap(value) {
|
|---|
| 12319 | return isObjectLike(value) && getTag(value) == weakMapTag;
|
|---|
| 12320 | }
|
|---|
| 12321 |
|
|---|
| 12322 | /**
|
|---|
| 12323 | * Checks if `value` is classified as a `WeakSet` object.
|
|---|
| 12324 | *
|
|---|
| 12325 | * @static
|
|---|
| 12326 | * @memberOf _
|
|---|
| 12327 | * @since 4.3.0
|
|---|
| 12328 | * @category Lang
|
|---|
| 12329 | * @param {*} value The value to check.
|
|---|
| 12330 | * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
|
|---|
| 12331 | * @example
|
|---|
| 12332 | *
|
|---|
| 12333 | * _.isWeakSet(new WeakSet);
|
|---|
| 12334 | * // => true
|
|---|
| 12335 | *
|
|---|
| 12336 | * _.isWeakSet(new Set);
|
|---|
| 12337 | * // => false
|
|---|
| 12338 | */
|
|---|
| 12339 | function isWeakSet(value) {
|
|---|
| 12340 | return isObjectLike(value) && baseGetTag(value) == weakSetTag;
|
|---|
| 12341 | }
|
|---|
| 12342 |
|
|---|
| 12343 | /**
|
|---|
| 12344 | * Checks if `value` is less than `other`.
|
|---|
| 12345 | *
|
|---|
| 12346 | * @static
|
|---|
| 12347 | * @memberOf _
|
|---|
| 12348 | * @since 3.9.0
|
|---|
| 12349 | * @category Lang
|
|---|
| 12350 | * @param {*} value The value to compare.
|
|---|
| 12351 | * @param {*} other The other value to compare.
|
|---|
| 12352 | * @returns {boolean} Returns `true` if `value` is less than `other`,
|
|---|
| 12353 | * else `false`.
|
|---|
| 12354 | * @see _.gt
|
|---|
| 12355 | * @example
|
|---|
| 12356 | *
|
|---|
| 12357 | * _.lt(1, 3);
|
|---|
| 12358 | * // => true
|
|---|
| 12359 | *
|
|---|
| 12360 | * _.lt(3, 3);
|
|---|
| 12361 | * // => false
|
|---|
| 12362 | *
|
|---|
| 12363 | * _.lt(3, 1);
|
|---|
| 12364 | * // => false
|
|---|
| 12365 | */
|
|---|
| 12366 | var lt = createRelationalOperation(baseLt);
|
|---|
| 12367 |
|
|---|
| 12368 | /**
|
|---|
| 12369 | * Checks if `value` is less than or equal to `other`.
|
|---|
| 12370 | *
|
|---|
| 12371 | * @static
|
|---|
| 12372 | * @memberOf _
|
|---|
| 12373 | * @since 3.9.0
|
|---|
| 12374 | * @category Lang
|
|---|
| 12375 | * @param {*} value The value to compare.
|
|---|
| 12376 | * @param {*} other The other value to compare.
|
|---|
| 12377 | * @returns {boolean} Returns `true` if `value` is less than or equal to
|
|---|
| 12378 | * `other`, else `false`.
|
|---|
| 12379 | * @see _.gte
|
|---|
| 12380 | * @example
|
|---|
| 12381 | *
|
|---|
| 12382 | * _.lte(1, 3);
|
|---|
| 12383 | * // => true
|
|---|
| 12384 | *
|
|---|
| 12385 | * _.lte(3, 3);
|
|---|
| 12386 | * // => true
|
|---|
| 12387 | *
|
|---|
| 12388 | * _.lte(3, 1);
|
|---|
| 12389 | * // => false
|
|---|
| 12390 | */
|
|---|
| 12391 | var lte = createRelationalOperation(function(value, other) {
|
|---|
| 12392 | return value <= other;
|
|---|
| 12393 | });
|
|---|
| 12394 |
|
|---|
| 12395 | /**
|
|---|
| 12396 | * Converts `value` to an array.
|
|---|
| 12397 | *
|
|---|
| 12398 | * @static
|
|---|
| 12399 | * @since 0.1.0
|
|---|
| 12400 | * @memberOf _
|
|---|
| 12401 | * @category Lang
|
|---|
| 12402 | * @param {*} value The value to convert.
|
|---|
| 12403 | * @returns {Array} Returns the converted array.
|
|---|
| 12404 | * @example
|
|---|
| 12405 | *
|
|---|
| 12406 | * _.toArray({ 'a': 1, 'b': 2 });
|
|---|
| 12407 | * // => [1, 2]
|
|---|
| 12408 | *
|
|---|
| 12409 | * _.toArray('abc');
|
|---|
| 12410 | * // => ['a', 'b', 'c']
|
|---|
| 12411 | *
|
|---|
| 12412 | * _.toArray(1);
|
|---|
| 12413 | * // => []
|
|---|
| 12414 | *
|
|---|
| 12415 | * _.toArray(null);
|
|---|
| 12416 | * // => []
|
|---|
| 12417 | */
|
|---|
| 12418 | function toArray(value) {
|
|---|
| 12419 | if (!value) {
|
|---|
| 12420 | return [];
|
|---|
| 12421 | }
|
|---|
| 12422 | if (isArrayLike(value)) {
|
|---|
| 12423 | return isString(value) ? stringToArray(value) : copyArray(value);
|
|---|
| 12424 | }
|
|---|
| 12425 | if (symIterator && value[symIterator]) {
|
|---|
| 12426 | return iteratorToArray(value[symIterator]());
|
|---|
| 12427 | }
|
|---|
| 12428 | var tag = getTag(value),
|
|---|
| 12429 | func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
|
|---|
| 12430 |
|
|---|
| 12431 | return func(value);
|
|---|
| 12432 | }
|
|---|
| 12433 |
|
|---|
| 12434 | /**
|
|---|
| 12435 | * Converts `value` to a finite number.
|
|---|
| 12436 | *
|
|---|
| 12437 | * @static
|
|---|
| 12438 | * @memberOf _
|
|---|
| 12439 | * @since 4.12.0
|
|---|
| 12440 | * @category Lang
|
|---|
| 12441 | * @param {*} value The value to convert.
|
|---|
| 12442 | * @returns {number} Returns the converted number.
|
|---|
| 12443 | * @example
|
|---|
| 12444 | *
|
|---|
| 12445 | * _.toFinite(3.2);
|
|---|
| 12446 | * // => 3.2
|
|---|
| 12447 | *
|
|---|
| 12448 | * _.toFinite(Number.MIN_VALUE);
|
|---|
| 12449 | * // => 5e-324
|
|---|
| 12450 | *
|
|---|
| 12451 | * _.toFinite(Infinity);
|
|---|
| 12452 | * // => 1.7976931348623157e+308
|
|---|
| 12453 | *
|
|---|
| 12454 | * _.toFinite('3.2');
|
|---|
| 12455 | * // => 3.2
|
|---|
| 12456 | */
|
|---|
| 12457 | function toFinite(value) {
|
|---|
| 12458 | if (!value) {
|
|---|
| 12459 | return value === 0 ? value : 0;
|
|---|
| 12460 | }
|
|---|
| 12461 | value = toNumber(value);
|
|---|
| 12462 | if (value === INFINITY || value === -INFINITY) {
|
|---|
| 12463 | var sign = (value < 0 ? -1 : 1);
|
|---|
| 12464 | return sign * MAX_INTEGER;
|
|---|
| 12465 | }
|
|---|
| 12466 | return value === value ? value : 0;
|
|---|
| 12467 | }
|
|---|
| 12468 |
|
|---|
| 12469 | /**
|
|---|
| 12470 | * Converts `value` to an integer.
|
|---|
| 12471 | *
|
|---|
| 12472 | * **Note:** This method is loosely based on
|
|---|
| 12473 | * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
|
|---|
| 12474 | *
|
|---|
| 12475 | * @static
|
|---|
| 12476 | * @memberOf _
|
|---|
| 12477 | * @since 4.0.0
|
|---|
| 12478 | * @category Lang
|
|---|
| 12479 | * @param {*} value The value to convert.
|
|---|
| 12480 | * @returns {number} Returns the converted integer.
|
|---|
| 12481 | * @example
|
|---|
| 12482 | *
|
|---|
| 12483 | * _.toInteger(3.2);
|
|---|
| 12484 | * // => 3
|
|---|
| 12485 | *
|
|---|
| 12486 | * _.toInteger(Number.MIN_VALUE);
|
|---|
| 12487 | * // => 0
|
|---|
| 12488 | *
|
|---|
| 12489 | * _.toInteger(Infinity);
|
|---|
| 12490 | * // => 1.7976931348623157e+308
|
|---|
| 12491 | *
|
|---|
| 12492 | * _.toInteger('3.2');
|
|---|
| 12493 | * // => 3
|
|---|
| 12494 | */
|
|---|
| 12495 | function toInteger(value) {
|
|---|
| 12496 | var result = toFinite(value),
|
|---|
| 12497 | remainder = result % 1;
|
|---|
| 12498 |
|
|---|
| 12499 | return result === result ? (remainder ? result - remainder : result) : 0;
|
|---|
| 12500 | }
|
|---|
| 12501 |
|
|---|
| 12502 | /**
|
|---|
| 12503 | * Converts `value` to an integer suitable for use as the length of an
|
|---|
| 12504 | * array-like object.
|
|---|
| 12505 | *
|
|---|
| 12506 | * **Note:** This method is based on
|
|---|
| 12507 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|---|
| 12508 | *
|
|---|
| 12509 | * @static
|
|---|
| 12510 | * @memberOf _
|
|---|
| 12511 | * @since 4.0.0
|
|---|
| 12512 | * @category Lang
|
|---|
| 12513 | * @param {*} value The value to convert.
|
|---|
| 12514 | * @returns {number} Returns the converted integer.
|
|---|
| 12515 | * @example
|
|---|
| 12516 | *
|
|---|
| 12517 | * _.toLength(3.2);
|
|---|
| 12518 | * // => 3
|
|---|
| 12519 | *
|
|---|
| 12520 | * _.toLength(Number.MIN_VALUE);
|
|---|
| 12521 | * // => 0
|
|---|
| 12522 | *
|
|---|
| 12523 | * _.toLength(Infinity);
|
|---|
| 12524 | * // => 4294967295
|
|---|
| 12525 | *
|
|---|
| 12526 | * _.toLength('3.2');
|
|---|
| 12527 | * // => 3
|
|---|
| 12528 | */
|
|---|
| 12529 | function toLength(value) {
|
|---|
| 12530 | return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
|
|---|
| 12531 | }
|
|---|
| 12532 |
|
|---|
| 12533 | /**
|
|---|
| 12534 | * Converts `value` to a number.
|
|---|
| 12535 | *
|
|---|
| 12536 | * @static
|
|---|
| 12537 | * @memberOf _
|
|---|
| 12538 | * @since 4.0.0
|
|---|
| 12539 | * @category Lang
|
|---|
| 12540 | * @param {*} value The value to process.
|
|---|
| 12541 | * @returns {number} Returns the number.
|
|---|
| 12542 | * @example
|
|---|
| 12543 | *
|
|---|
| 12544 | * _.toNumber(3.2);
|
|---|
| 12545 | * // => 3.2
|
|---|
| 12546 | *
|
|---|
| 12547 | * _.toNumber(Number.MIN_VALUE);
|
|---|
| 12548 | * // => 5e-324
|
|---|
| 12549 | *
|
|---|
| 12550 | * _.toNumber(Infinity);
|
|---|
| 12551 | * // => Infinity
|
|---|
| 12552 | *
|
|---|
| 12553 | * _.toNumber('3.2');
|
|---|
| 12554 | * // => 3.2
|
|---|
| 12555 | */
|
|---|
| 12556 | function toNumber(value) {
|
|---|
| 12557 | if (typeof value == 'number') {
|
|---|
| 12558 | return value;
|
|---|
| 12559 | }
|
|---|
| 12560 | if (isSymbol(value)) {
|
|---|
| 12561 | return NAN;
|
|---|
| 12562 | }
|
|---|
| 12563 | if (isObject(value)) {
|
|---|
| 12564 | var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
|---|
| 12565 | value = isObject(other) ? (other + '') : other;
|
|---|
| 12566 | }
|
|---|
| 12567 | if (typeof value != 'string') {
|
|---|
| 12568 | return value === 0 ? value : +value;
|
|---|
| 12569 | }
|
|---|
| 12570 | value = baseTrim(value);
|
|---|
| 12571 | var isBinary = reIsBinary.test(value);
|
|---|
| 12572 | return (isBinary || reIsOctal.test(value))
|
|---|
| 12573 | ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
|---|
| 12574 | : (reIsBadHex.test(value) ? NAN : +value);
|
|---|
| 12575 | }
|
|---|
| 12576 |
|
|---|
| 12577 | /**
|
|---|
| 12578 | * Converts `value` to a plain object flattening inherited enumerable string
|
|---|
| 12579 | * keyed properties of `value` to own properties of the plain object.
|
|---|
| 12580 | *
|
|---|
| 12581 | * @static
|
|---|
| 12582 | * @memberOf _
|
|---|
| 12583 | * @since 3.0.0
|
|---|
| 12584 | * @category Lang
|
|---|
| 12585 | * @param {*} value The value to convert.
|
|---|
| 12586 | * @returns {Object} Returns the converted plain object.
|
|---|
| 12587 | * @example
|
|---|
| 12588 | *
|
|---|
| 12589 | * function Foo() {
|
|---|
| 12590 | * this.b = 2;
|
|---|
| 12591 | * }
|
|---|
| 12592 | *
|
|---|
| 12593 | * Foo.prototype.c = 3;
|
|---|
| 12594 | *
|
|---|
| 12595 | * _.assign({ 'a': 1 }, new Foo);
|
|---|
| 12596 | * // => { 'a': 1, 'b': 2 }
|
|---|
| 12597 | *
|
|---|
| 12598 | * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
|
|---|
| 12599 | * // => { 'a': 1, 'b': 2, 'c': 3 }
|
|---|
| 12600 | */
|
|---|
| 12601 | function toPlainObject(value) {
|
|---|
| 12602 | return copyObject(value, keysIn(value));
|
|---|
| 12603 | }
|
|---|
| 12604 |
|
|---|
| 12605 | /**
|
|---|
| 12606 | * Converts `value` to a safe integer. A safe integer can be compared and
|
|---|
| 12607 | * represented correctly.
|
|---|
| 12608 | *
|
|---|
| 12609 | * @static
|
|---|
| 12610 | * @memberOf _
|
|---|
| 12611 | * @since 4.0.0
|
|---|
| 12612 | * @category Lang
|
|---|
| 12613 | * @param {*} value The value to convert.
|
|---|
| 12614 | * @returns {number} Returns the converted integer.
|
|---|
| 12615 | * @example
|
|---|
| 12616 | *
|
|---|
| 12617 | * _.toSafeInteger(3.2);
|
|---|
| 12618 | * // => 3
|
|---|
| 12619 | *
|
|---|
| 12620 | * _.toSafeInteger(Number.MIN_VALUE);
|
|---|
| 12621 | * // => 0
|
|---|
| 12622 | *
|
|---|
| 12623 | * _.toSafeInteger(Infinity);
|
|---|
| 12624 | * // => 9007199254740991
|
|---|
| 12625 | *
|
|---|
| 12626 | * _.toSafeInteger('3.2');
|
|---|
| 12627 | * // => 3
|
|---|
| 12628 | */
|
|---|
| 12629 | function toSafeInteger(value) {
|
|---|
| 12630 | return value
|
|---|
| 12631 | ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
|
|---|
| 12632 | : (value === 0 ? value : 0);
|
|---|
| 12633 | }
|
|---|
| 12634 |
|
|---|
| 12635 | /**
|
|---|
| 12636 | * Converts `value` to a string. An empty string is returned for `null`
|
|---|
| 12637 | * and `undefined` values. The sign of `-0` is preserved.
|
|---|
| 12638 | *
|
|---|
| 12639 | * @static
|
|---|
| 12640 | * @memberOf _
|
|---|
| 12641 | * @since 4.0.0
|
|---|
| 12642 | * @category Lang
|
|---|
| 12643 | * @param {*} value The value to convert.
|
|---|
| 12644 | * @returns {string} Returns the converted string.
|
|---|
| 12645 | * @example
|
|---|
| 12646 | *
|
|---|
| 12647 | * _.toString(null);
|
|---|
| 12648 | * // => ''
|
|---|
| 12649 | *
|
|---|
| 12650 | * _.toString(-0);
|
|---|
| 12651 | * // => '-0'
|
|---|
| 12652 | *
|
|---|
| 12653 | * _.toString([1, 2, 3]);
|
|---|
| 12654 | * // => '1,2,3'
|
|---|
| 12655 | */
|
|---|
| 12656 | function toString(value) {
|
|---|
| 12657 | return value == null ? '' : baseToString(value);
|
|---|
| 12658 | }
|
|---|
| 12659 |
|
|---|
| 12660 | /*------------------------------------------------------------------------*/
|
|---|
| 12661 |
|
|---|
| 12662 | /**
|
|---|
| 12663 | * Assigns own enumerable string keyed properties of source objects to the
|
|---|
| 12664 | * destination object. Source objects are applied from left to right.
|
|---|
| 12665 | * Subsequent sources overwrite property assignments of previous sources.
|
|---|
| 12666 | *
|
|---|
| 12667 | * **Note:** This method mutates `object` and is loosely based on
|
|---|
| 12668 | * [`Object.assign`](https://mdn.io/Object/assign).
|
|---|
| 12669 | *
|
|---|
| 12670 | * @static
|
|---|
| 12671 | * @memberOf _
|
|---|
| 12672 | * @since 0.10.0
|
|---|
| 12673 | * @category Object
|
|---|
| 12674 | * @param {Object} object The destination object.
|
|---|
| 12675 | * @param {...Object} [sources] The source objects.
|
|---|
| 12676 | * @returns {Object} Returns `object`.
|
|---|
| 12677 | * @see _.assignIn
|
|---|
| 12678 | * @example
|
|---|
| 12679 | *
|
|---|
| 12680 | * function Foo() {
|
|---|
| 12681 | * this.a = 1;
|
|---|
| 12682 | * }
|
|---|
| 12683 | *
|
|---|
| 12684 | * function Bar() {
|
|---|
| 12685 | * this.c = 3;
|
|---|
| 12686 | * }
|
|---|
| 12687 | *
|
|---|
| 12688 | * Foo.prototype.b = 2;
|
|---|
| 12689 | * Bar.prototype.d = 4;
|
|---|
| 12690 | *
|
|---|
| 12691 | * _.assign({ 'a': 0 }, new Foo, new Bar);
|
|---|
| 12692 | * // => { 'a': 1, 'c': 3 }
|
|---|
| 12693 | */
|
|---|
| 12694 | var assign = createAssigner(function(object, source) {
|
|---|
| 12695 | if (isPrototype(source) || isArrayLike(source)) {
|
|---|
| 12696 | copyObject(source, keys(source), object);
|
|---|
| 12697 | return;
|
|---|
| 12698 | }
|
|---|
| 12699 | for (var key in source) {
|
|---|
| 12700 | if (hasOwnProperty.call(source, key)) {
|
|---|
| 12701 | assignValue(object, key, source[key]);
|
|---|
| 12702 | }
|
|---|
| 12703 | }
|
|---|
| 12704 | });
|
|---|
| 12705 |
|
|---|
| 12706 | /**
|
|---|
| 12707 | * This method is like `_.assign` except that it iterates over own and
|
|---|
| 12708 | * inherited source properties.
|
|---|
| 12709 | *
|
|---|
| 12710 | * **Note:** This method mutates `object`.
|
|---|
| 12711 | *
|
|---|
| 12712 | * @static
|
|---|
| 12713 | * @memberOf _
|
|---|
| 12714 | * @since 4.0.0
|
|---|
| 12715 | * @alias extend
|
|---|
| 12716 | * @category Object
|
|---|
| 12717 | * @param {Object} object The destination object.
|
|---|
| 12718 | * @param {...Object} [sources] The source objects.
|
|---|
| 12719 | * @returns {Object} Returns `object`.
|
|---|
| 12720 | * @see _.assign
|
|---|
| 12721 | * @example
|
|---|
| 12722 | *
|
|---|
| 12723 | * function Foo() {
|
|---|
| 12724 | * this.a = 1;
|
|---|
| 12725 | * }
|
|---|
| 12726 | *
|
|---|
| 12727 | * function Bar() {
|
|---|
| 12728 | * this.c = 3;
|
|---|
| 12729 | * }
|
|---|
| 12730 | *
|
|---|
| 12731 | * Foo.prototype.b = 2;
|
|---|
| 12732 | * Bar.prototype.d = 4;
|
|---|
| 12733 | *
|
|---|
| 12734 | * _.assignIn({ 'a': 0 }, new Foo, new Bar);
|
|---|
| 12735 | * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
|---|
| 12736 | */
|
|---|
| 12737 | var assignIn = createAssigner(function(object, source) {
|
|---|
| 12738 | copyObject(source, keysIn(source), object);
|
|---|
| 12739 | });
|
|---|
| 12740 |
|
|---|
| 12741 | /**
|
|---|
| 12742 | * This method is like `_.assignIn` except that it accepts `customizer`
|
|---|
| 12743 | * which is invoked to produce the assigned values. If `customizer` returns
|
|---|
| 12744 | * `undefined`, assignment is handled by the method instead. The `customizer`
|
|---|
| 12745 | * is invoked with five arguments: (objValue, srcValue, key, object, source).
|
|---|
| 12746 | *
|
|---|
| 12747 | * **Note:** This method mutates `object`.
|
|---|
| 12748 | *
|
|---|
| 12749 | * @static
|
|---|
| 12750 | * @memberOf _
|
|---|
| 12751 | * @since 4.0.0
|
|---|
| 12752 | * @alias extendWith
|
|---|
| 12753 | * @category Object
|
|---|
| 12754 | * @param {Object} object The destination object.
|
|---|
| 12755 | * @param {...Object} sources The source objects.
|
|---|
| 12756 | * @param {Function} [customizer] The function to customize assigned values.
|
|---|
| 12757 | * @returns {Object} Returns `object`.
|
|---|
| 12758 | * @see _.assignWith
|
|---|
| 12759 | * @example
|
|---|
| 12760 | *
|
|---|
| 12761 | * function customizer(objValue, srcValue) {
|
|---|
| 12762 | * return _.isUndefined(objValue) ? srcValue : objValue;
|
|---|
| 12763 | * }
|
|---|
| 12764 | *
|
|---|
| 12765 | * var defaults = _.partialRight(_.assignInWith, customizer);
|
|---|
| 12766 | *
|
|---|
| 12767 | * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
|---|
| 12768 | * // => { 'a': 1, 'b': 2 }
|
|---|
| 12769 | */
|
|---|
| 12770 | var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
|
|---|
| 12771 | copyObject(source, keysIn(source), object, customizer);
|
|---|
| 12772 | });
|
|---|
| 12773 |
|
|---|
| 12774 | /**
|
|---|
| 12775 | * This method is like `_.assign` except that it accepts `customizer`
|
|---|
| 12776 | * which is invoked to produce the assigned values. If `customizer` returns
|
|---|
| 12777 | * `undefined`, assignment is handled by the method instead. The `customizer`
|
|---|
| 12778 | * is invoked with five arguments: (objValue, srcValue, key, object, source).
|
|---|
| 12779 | *
|
|---|
| 12780 | * **Note:** This method mutates `object`.
|
|---|
| 12781 | *
|
|---|
| 12782 | * @static
|
|---|
| 12783 | * @memberOf _
|
|---|
| 12784 | * @since 4.0.0
|
|---|
| 12785 | * @category Object
|
|---|
| 12786 | * @param {Object} object The destination object.
|
|---|
| 12787 | * @param {...Object} sources The source objects.
|
|---|
| 12788 | * @param {Function} [customizer] The function to customize assigned values.
|
|---|
| 12789 | * @returns {Object} Returns `object`.
|
|---|
| 12790 | * @see _.assignInWith
|
|---|
| 12791 | * @example
|
|---|
| 12792 | *
|
|---|
| 12793 | * function customizer(objValue, srcValue) {
|
|---|
| 12794 | * return _.isUndefined(objValue) ? srcValue : objValue;
|
|---|
| 12795 | * }
|
|---|
| 12796 | *
|
|---|
| 12797 | * var defaults = _.partialRight(_.assignWith, customizer);
|
|---|
| 12798 | *
|
|---|
| 12799 | * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
|---|
| 12800 | * // => { 'a': 1, 'b': 2 }
|
|---|
| 12801 | */
|
|---|
| 12802 | var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
|
|---|
| 12803 | copyObject(source, keys(source), object, customizer);
|
|---|
| 12804 | });
|
|---|
| 12805 |
|
|---|
| 12806 | /**
|
|---|
| 12807 | * Creates an array of values corresponding to `paths` of `object`.
|
|---|
| 12808 | *
|
|---|
| 12809 | * @static
|
|---|
| 12810 | * @memberOf _
|
|---|
| 12811 | * @since 1.0.0
|
|---|
| 12812 | * @category Object
|
|---|
| 12813 | * @param {Object} object The object to iterate over.
|
|---|
| 12814 | * @param {...(string|string[])} [paths] The property paths to pick.
|
|---|
| 12815 | * @returns {Array} Returns the picked values.
|
|---|
| 12816 | * @example
|
|---|
| 12817 | *
|
|---|
| 12818 | * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
|
|---|
| 12819 | *
|
|---|
| 12820 | * _.at(object, ['a[0].b.c', 'a[1]']);
|
|---|
| 12821 | * // => [3, 4]
|
|---|
| 12822 | */
|
|---|
| 12823 | var at = flatRest(baseAt);
|
|---|
| 12824 |
|
|---|
| 12825 | /**
|
|---|
| 12826 | * Creates an object that inherits from the `prototype` object. If a
|
|---|
| 12827 | * `properties` object is given, its own enumerable string keyed properties
|
|---|
| 12828 | * are assigned to the created object.
|
|---|
| 12829 | *
|
|---|
| 12830 | * @static
|
|---|
| 12831 | * @memberOf _
|
|---|
| 12832 | * @since 2.3.0
|
|---|
| 12833 | * @category Object
|
|---|
| 12834 | * @param {Object} prototype The object to inherit from.
|
|---|
| 12835 | * @param {Object} [properties] The properties to assign to the object.
|
|---|
| 12836 | * @returns {Object} Returns the new object.
|
|---|
| 12837 | * @example
|
|---|
| 12838 | *
|
|---|
| 12839 | * function Shape() {
|
|---|
| 12840 | * this.x = 0;
|
|---|
| 12841 | * this.y = 0;
|
|---|
| 12842 | * }
|
|---|
| 12843 | *
|
|---|
| 12844 | * function Circle() {
|
|---|
| 12845 | * Shape.call(this);
|
|---|
| 12846 | * }
|
|---|
| 12847 | *
|
|---|
| 12848 | * Circle.prototype = _.create(Shape.prototype, {
|
|---|
| 12849 | * 'constructor': Circle
|
|---|
| 12850 | * });
|
|---|
| 12851 | *
|
|---|
| 12852 | * var circle = new Circle;
|
|---|
| 12853 | * circle instanceof Circle;
|
|---|
| 12854 | * // => true
|
|---|
| 12855 | *
|
|---|
| 12856 | * circle instanceof Shape;
|
|---|
| 12857 | * // => true
|
|---|
| 12858 | */
|
|---|
| 12859 | function create(prototype, properties) {
|
|---|
| 12860 | var result = baseCreate(prototype);
|
|---|
| 12861 | return properties == null ? result : baseAssign(result, properties);
|
|---|
| 12862 | }
|
|---|
| 12863 |
|
|---|
| 12864 | /**
|
|---|
| 12865 | * Assigns own and inherited enumerable string keyed properties of source
|
|---|
| 12866 | * objects to the destination object for all destination properties that
|
|---|
| 12867 | * resolve to `undefined`. Source objects are applied from left to right.
|
|---|
| 12868 | * Once a property is set, additional values of the same property are ignored.
|
|---|
| 12869 | *
|
|---|
| 12870 | * **Note:** This method mutates `object`.
|
|---|
| 12871 | *
|
|---|
| 12872 | * @static
|
|---|
| 12873 | * @since 0.1.0
|
|---|
| 12874 | * @memberOf _
|
|---|
| 12875 | * @category Object
|
|---|
| 12876 | * @param {Object} object The destination object.
|
|---|
| 12877 | * @param {...Object} [sources] The source objects.
|
|---|
| 12878 | * @returns {Object} Returns `object`.
|
|---|
| 12879 | * @see _.defaultsDeep
|
|---|
| 12880 | * @example
|
|---|
| 12881 | *
|
|---|
| 12882 | * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
|---|
| 12883 | * // => { 'a': 1, 'b': 2 }
|
|---|
| 12884 | */
|
|---|
| 12885 | var defaults = baseRest(function(object, sources) {
|
|---|
| 12886 | object = Object(object);
|
|---|
| 12887 |
|
|---|
| 12888 | var index = -1;
|
|---|
| 12889 | var length = sources.length;
|
|---|
| 12890 | var guard = length > 2 ? sources[2] : undefined;
|
|---|
| 12891 |
|
|---|
| 12892 | if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
|---|
| 12893 | length = 1;
|
|---|
| 12894 | }
|
|---|
| 12895 |
|
|---|
| 12896 | while (++index < length) {
|
|---|
| 12897 | var source = sources[index];
|
|---|
| 12898 | var props = keysIn(source);
|
|---|
| 12899 | var propsIndex = -1;
|
|---|
| 12900 | var propsLength = props.length;
|
|---|
| 12901 |
|
|---|
| 12902 | while (++propsIndex < propsLength) {
|
|---|
| 12903 | var key = props[propsIndex];
|
|---|
| 12904 | var value = object[key];
|
|---|
| 12905 |
|
|---|
| 12906 | if (value === undefined ||
|
|---|
| 12907 | (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
|---|
| 12908 | object[key] = source[key];
|
|---|
| 12909 | }
|
|---|
| 12910 | }
|
|---|
| 12911 | }
|
|---|
| 12912 |
|
|---|
| 12913 | return object;
|
|---|
| 12914 | });
|
|---|
| 12915 |
|
|---|
| 12916 | /**
|
|---|
| 12917 | * This method is like `_.defaults` except that it recursively assigns
|
|---|
| 12918 | * default properties.
|
|---|
| 12919 | *
|
|---|
| 12920 | * **Note:** This method mutates `object`.
|
|---|
| 12921 | *
|
|---|
| 12922 | * @static
|
|---|
| 12923 | * @memberOf _
|
|---|
| 12924 | * @since 3.10.0
|
|---|
| 12925 | * @category Object
|
|---|
| 12926 | * @param {Object} object The destination object.
|
|---|
| 12927 | * @param {...Object} [sources] The source objects.
|
|---|
| 12928 | * @returns {Object} Returns `object`.
|
|---|
| 12929 | * @see _.defaults
|
|---|
| 12930 | * @example
|
|---|
| 12931 | *
|
|---|
| 12932 | * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
|
|---|
| 12933 | * // => { 'a': { 'b': 2, 'c': 3 } }
|
|---|
| 12934 | */
|
|---|
| 12935 | var defaultsDeep = baseRest(function(args) {
|
|---|
| 12936 | args.push(undefined, customDefaultsMerge);
|
|---|
| 12937 | return apply(mergeWith, undefined, args);
|
|---|
| 12938 | });
|
|---|
| 12939 |
|
|---|
| 12940 | /**
|
|---|
| 12941 | * This method is like `_.find` except that it returns the key of the first
|
|---|
| 12942 | * element `predicate` returns truthy for instead of the element itself.
|
|---|
| 12943 | *
|
|---|
| 12944 | * @static
|
|---|
| 12945 | * @memberOf _
|
|---|
| 12946 | * @since 1.1.0
|
|---|
| 12947 | * @category Object
|
|---|
| 12948 | * @param {Object} object The object to inspect.
|
|---|
| 12949 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 12950 | * @returns {string|undefined} Returns the key of the matched element,
|
|---|
| 12951 | * else `undefined`.
|
|---|
| 12952 | * @example
|
|---|
| 12953 | *
|
|---|
| 12954 | * var users = {
|
|---|
| 12955 | * 'barney': { 'age': 36, 'active': true },
|
|---|
| 12956 | * 'fred': { 'age': 40, 'active': false },
|
|---|
| 12957 | * 'pebbles': { 'age': 1, 'active': true }
|
|---|
| 12958 | * };
|
|---|
| 12959 | *
|
|---|
| 12960 | * _.findKey(users, function(o) { return o.age < 40; });
|
|---|
| 12961 | * // => 'barney' (iteration order is not guaranteed)
|
|---|
| 12962 | *
|
|---|
| 12963 | * // The `_.matches` iteratee shorthand.
|
|---|
| 12964 | * _.findKey(users, { 'age': 1, 'active': true });
|
|---|
| 12965 | * // => 'pebbles'
|
|---|
| 12966 | *
|
|---|
| 12967 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 12968 | * _.findKey(users, ['active', false]);
|
|---|
| 12969 | * // => 'fred'
|
|---|
| 12970 | *
|
|---|
| 12971 | * // The `_.property` iteratee shorthand.
|
|---|
| 12972 | * _.findKey(users, 'active');
|
|---|
| 12973 | * // => 'barney'
|
|---|
| 12974 | */
|
|---|
| 12975 | function findKey(object, predicate) {
|
|---|
| 12976 | return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
|
|---|
| 12977 | }
|
|---|
| 12978 |
|
|---|
| 12979 | /**
|
|---|
| 12980 | * This method is like `_.findKey` except that it iterates over elements of
|
|---|
| 12981 | * a collection in the opposite order.
|
|---|
| 12982 | *
|
|---|
| 12983 | * @static
|
|---|
| 12984 | * @memberOf _
|
|---|
| 12985 | * @since 2.0.0
|
|---|
| 12986 | * @category Object
|
|---|
| 12987 | * @param {Object} object The object to inspect.
|
|---|
| 12988 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
|---|
| 12989 | * @returns {string|undefined} Returns the key of the matched element,
|
|---|
| 12990 | * else `undefined`.
|
|---|
| 12991 | * @example
|
|---|
| 12992 | *
|
|---|
| 12993 | * var users = {
|
|---|
| 12994 | * 'barney': { 'age': 36, 'active': true },
|
|---|
| 12995 | * 'fred': { 'age': 40, 'active': false },
|
|---|
| 12996 | * 'pebbles': { 'age': 1, 'active': true }
|
|---|
| 12997 | * };
|
|---|
| 12998 | *
|
|---|
| 12999 | * _.findLastKey(users, function(o) { return o.age < 40; });
|
|---|
| 13000 | * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
|
|---|
| 13001 | *
|
|---|
| 13002 | * // The `_.matches` iteratee shorthand.
|
|---|
| 13003 | * _.findLastKey(users, { 'age': 36, 'active': true });
|
|---|
| 13004 | * // => 'barney'
|
|---|
| 13005 | *
|
|---|
| 13006 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 13007 | * _.findLastKey(users, ['active', false]);
|
|---|
| 13008 | * // => 'fred'
|
|---|
| 13009 | *
|
|---|
| 13010 | * // The `_.property` iteratee shorthand.
|
|---|
| 13011 | * _.findLastKey(users, 'active');
|
|---|
| 13012 | * // => 'pebbles'
|
|---|
| 13013 | */
|
|---|
| 13014 | function findLastKey(object, predicate) {
|
|---|
| 13015 | return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
|
|---|
| 13016 | }
|
|---|
| 13017 |
|
|---|
| 13018 | /**
|
|---|
| 13019 | * Iterates over own and inherited enumerable string keyed properties of an
|
|---|
| 13020 | * object and invokes `iteratee` for each property. The iteratee is invoked
|
|---|
| 13021 | * with three arguments: (value, key, object). Iteratee functions may exit
|
|---|
| 13022 | * iteration early by explicitly returning `false`.
|
|---|
| 13023 | *
|
|---|
| 13024 | * @static
|
|---|
| 13025 | * @memberOf _
|
|---|
| 13026 | * @since 0.3.0
|
|---|
| 13027 | * @category Object
|
|---|
| 13028 | * @param {Object} object The object to iterate over.
|
|---|
| 13029 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 13030 | * @returns {Object} Returns `object`.
|
|---|
| 13031 | * @see _.forInRight
|
|---|
| 13032 | * @example
|
|---|
| 13033 | *
|
|---|
| 13034 | * function Foo() {
|
|---|
| 13035 | * this.a = 1;
|
|---|
| 13036 | * this.b = 2;
|
|---|
| 13037 | * }
|
|---|
| 13038 | *
|
|---|
| 13039 | * Foo.prototype.c = 3;
|
|---|
| 13040 | *
|
|---|
| 13041 | * _.forIn(new Foo, function(value, key) {
|
|---|
| 13042 | * console.log(key);
|
|---|
| 13043 | * });
|
|---|
| 13044 | * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
|
|---|
| 13045 | */
|
|---|
| 13046 | function forIn(object, iteratee) {
|
|---|
| 13047 | return object == null
|
|---|
| 13048 | ? object
|
|---|
| 13049 | : baseFor(object, getIteratee(iteratee, 3), keysIn);
|
|---|
| 13050 | }
|
|---|
| 13051 |
|
|---|
| 13052 | /**
|
|---|
| 13053 | * This method is like `_.forIn` except that it iterates over properties of
|
|---|
| 13054 | * `object` in the opposite order.
|
|---|
| 13055 | *
|
|---|
| 13056 | * @static
|
|---|
| 13057 | * @memberOf _
|
|---|
| 13058 | * @since 2.0.0
|
|---|
| 13059 | * @category Object
|
|---|
| 13060 | * @param {Object} object The object to iterate over.
|
|---|
| 13061 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 13062 | * @returns {Object} Returns `object`.
|
|---|
| 13063 | * @see _.forIn
|
|---|
| 13064 | * @example
|
|---|
| 13065 | *
|
|---|
| 13066 | * function Foo() {
|
|---|
| 13067 | * this.a = 1;
|
|---|
| 13068 | * this.b = 2;
|
|---|
| 13069 | * }
|
|---|
| 13070 | *
|
|---|
| 13071 | * Foo.prototype.c = 3;
|
|---|
| 13072 | *
|
|---|
| 13073 | * _.forInRight(new Foo, function(value, key) {
|
|---|
| 13074 | * console.log(key);
|
|---|
| 13075 | * });
|
|---|
| 13076 | * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
|
|---|
| 13077 | */
|
|---|
| 13078 | function forInRight(object, iteratee) {
|
|---|
| 13079 | return object == null
|
|---|
| 13080 | ? object
|
|---|
| 13081 | : baseForRight(object, getIteratee(iteratee, 3), keysIn);
|
|---|
| 13082 | }
|
|---|
| 13083 |
|
|---|
| 13084 | /**
|
|---|
| 13085 | * Iterates over own enumerable string keyed properties of an object and
|
|---|
| 13086 | * invokes `iteratee` for each property. The iteratee is invoked with three
|
|---|
| 13087 | * arguments: (value, key, object). Iteratee functions may exit iteration
|
|---|
| 13088 | * early by explicitly returning `false`.
|
|---|
| 13089 | *
|
|---|
| 13090 | * @static
|
|---|
| 13091 | * @memberOf _
|
|---|
| 13092 | * @since 0.3.0
|
|---|
| 13093 | * @category Object
|
|---|
| 13094 | * @param {Object} object The object to iterate over.
|
|---|
| 13095 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 13096 | * @returns {Object} Returns `object`.
|
|---|
| 13097 | * @see _.forOwnRight
|
|---|
| 13098 | * @example
|
|---|
| 13099 | *
|
|---|
| 13100 | * function Foo() {
|
|---|
| 13101 | * this.a = 1;
|
|---|
| 13102 | * this.b = 2;
|
|---|
| 13103 | * }
|
|---|
| 13104 | *
|
|---|
| 13105 | * Foo.prototype.c = 3;
|
|---|
| 13106 | *
|
|---|
| 13107 | * _.forOwn(new Foo, function(value, key) {
|
|---|
| 13108 | * console.log(key);
|
|---|
| 13109 | * });
|
|---|
| 13110 | * // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
|---|
| 13111 | */
|
|---|
| 13112 | function forOwn(object, iteratee) {
|
|---|
| 13113 | return object && baseForOwn(object, getIteratee(iteratee, 3));
|
|---|
| 13114 | }
|
|---|
| 13115 |
|
|---|
| 13116 | /**
|
|---|
| 13117 | * This method is like `_.forOwn` except that it iterates over properties of
|
|---|
| 13118 | * `object` in the opposite order.
|
|---|
| 13119 | *
|
|---|
| 13120 | * @static
|
|---|
| 13121 | * @memberOf _
|
|---|
| 13122 | * @since 2.0.0
|
|---|
| 13123 | * @category Object
|
|---|
| 13124 | * @param {Object} object The object to iterate over.
|
|---|
| 13125 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 13126 | * @returns {Object} Returns `object`.
|
|---|
| 13127 | * @see _.forOwn
|
|---|
| 13128 | * @example
|
|---|
| 13129 | *
|
|---|
| 13130 | * function Foo() {
|
|---|
| 13131 | * this.a = 1;
|
|---|
| 13132 | * this.b = 2;
|
|---|
| 13133 | * }
|
|---|
| 13134 | *
|
|---|
| 13135 | * Foo.prototype.c = 3;
|
|---|
| 13136 | *
|
|---|
| 13137 | * _.forOwnRight(new Foo, function(value, key) {
|
|---|
| 13138 | * console.log(key);
|
|---|
| 13139 | * });
|
|---|
| 13140 | * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
|
|---|
| 13141 | */
|
|---|
| 13142 | function forOwnRight(object, iteratee) {
|
|---|
| 13143 | return object && baseForOwnRight(object, getIteratee(iteratee, 3));
|
|---|
| 13144 | }
|
|---|
| 13145 |
|
|---|
| 13146 | /**
|
|---|
| 13147 | * Creates an array of function property names from own enumerable properties
|
|---|
| 13148 | * of `object`.
|
|---|
| 13149 | *
|
|---|
| 13150 | * @static
|
|---|
| 13151 | * @since 0.1.0
|
|---|
| 13152 | * @memberOf _
|
|---|
| 13153 | * @category Object
|
|---|
| 13154 | * @param {Object} object The object to inspect.
|
|---|
| 13155 | * @returns {Array} Returns the function names.
|
|---|
| 13156 | * @see _.functionsIn
|
|---|
| 13157 | * @example
|
|---|
| 13158 | *
|
|---|
| 13159 | * function Foo() {
|
|---|
| 13160 | * this.a = _.constant('a');
|
|---|
| 13161 | * this.b = _.constant('b');
|
|---|
| 13162 | * }
|
|---|
| 13163 | *
|
|---|
| 13164 | * Foo.prototype.c = _.constant('c');
|
|---|
| 13165 | *
|
|---|
| 13166 | * _.functions(new Foo);
|
|---|
| 13167 | * // => ['a', 'b']
|
|---|
| 13168 | */
|
|---|
| 13169 | function functions(object) {
|
|---|
| 13170 | return object == null ? [] : baseFunctions(object, keys(object));
|
|---|
| 13171 | }
|
|---|
| 13172 |
|
|---|
| 13173 | /**
|
|---|
| 13174 | * Creates an array of function property names from own and inherited
|
|---|
| 13175 | * enumerable properties of `object`.
|
|---|
| 13176 | *
|
|---|
| 13177 | * @static
|
|---|
| 13178 | * @memberOf _
|
|---|
| 13179 | * @since 4.0.0
|
|---|
| 13180 | * @category Object
|
|---|
| 13181 | * @param {Object} object The object to inspect.
|
|---|
| 13182 | * @returns {Array} Returns the function names.
|
|---|
| 13183 | * @see _.functions
|
|---|
| 13184 | * @example
|
|---|
| 13185 | *
|
|---|
| 13186 | * function Foo() {
|
|---|
| 13187 | * this.a = _.constant('a');
|
|---|
| 13188 | * this.b = _.constant('b');
|
|---|
| 13189 | * }
|
|---|
| 13190 | *
|
|---|
| 13191 | * Foo.prototype.c = _.constant('c');
|
|---|
| 13192 | *
|
|---|
| 13193 | * _.functionsIn(new Foo);
|
|---|
| 13194 | * // => ['a', 'b', 'c']
|
|---|
| 13195 | */
|
|---|
| 13196 | function functionsIn(object) {
|
|---|
| 13197 | return object == null ? [] : baseFunctions(object, keysIn(object));
|
|---|
| 13198 | }
|
|---|
| 13199 |
|
|---|
| 13200 | /**
|
|---|
| 13201 | * Gets the value at `path` of `object`. If the resolved value is
|
|---|
| 13202 | * `undefined`, the `defaultValue` is returned in its place.
|
|---|
| 13203 | *
|
|---|
| 13204 | * @static
|
|---|
| 13205 | * @memberOf _
|
|---|
| 13206 | * @since 3.7.0
|
|---|
| 13207 | * @category Object
|
|---|
| 13208 | * @param {Object} object The object to query.
|
|---|
| 13209 | * @param {Array|string} path The path of the property to get.
|
|---|
| 13210 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
|---|
| 13211 | * @returns {*} Returns the resolved value.
|
|---|
| 13212 | * @example
|
|---|
| 13213 | *
|
|---|
| 13214 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|---|
| 13215 | *
|
|---|
| 13216 | * _.get(object, 'a[0].b.c');
|
|---|
| 13217 | * // => 3
|
|---|
| 13218 | *
|
|---|
| 13219 | * _.get(object, ['a', '0', 'b', 'c']);
|
|---|
| 13220 | * // => 3
|
|---|
| 13221 | *
|
|---|
| 13222 | * _.get(object, 'a.b.c', 'default');
|
|---|
| 13223 | * // => 'default'
|
|---|
| 13224 | */
|
|---|
| 13225 | function get(object, path, defaultValue) {
|
|---|
| 13226 | var result = object == null ? undefined : baseGet(object, path);
|
|---|
| 13227 | return result === undefined ? defaultValue : result;
|
|---|
| 13228 | }
|
|---|
| 13229 |
|
|---|
| 13230 | /**
|
|---|
| 13231 | * Checks if `path` is a direct property of `object`.
|
|---|
| 13232 | *
|
|---|
| 13233 | * @static
|
|---|
| 13234 | * @since 0.1.0
|
|---|
| 13235 | * @memberOf _
|
|---|
| 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 = { 'a': { 'b': 2 } };
|
|---|
| 13243 | * var other = _.create({ 'a': _.create({ 'b': 2 }) });
|
|---|
| 13244 | *
|
|---|
| 13245 | * _.has(object, 'a');
|
|---|
| 13246 | * // => true
|
|---|
| 13247 | *
|
|---|
| 13248 | * _.has(object, 'a.b');
|
|---|
| 13249 | * // => true
|
|---|
| 13250 | *
|
|---|
| 13251 | * _.has(object, ['a', 'b']);
|
|---|
| 13252 | * // => true
|
|---|
| 13253 | *
|
|---|
| 13254 | * _.has(other, 'a');
|
|---|
| 13255 | * // => false
|
|---|
| 13256 | */
|
|---|
| 13257 | function has(object, path) {
|
|---|
| 13258 | return object != null && hasPath(object, path, baseHas);
|
|---|
| 13259 | }
|
|---|
| 13260 |
|
|---|
| 13261 | /**
|
|---|
| 13262 | * Checks if `path` is a direct or inherited property of `object`.
|
|---|
| 13263 | *
|
|---|
| 13264 | * @static
|
|---|
| 13265 | * @memberOf _
|
|---|
| 13266 | * @since 4.0.0
|
|---|
| 13267 | * @category Object
|
|---|
| 13268 | * @param {Object} object The object to query.
|
|---|
| 13269 | * @param {Array|string} path The path to check.
|
|---|
| 13270 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
|---|
| 13271 | * @example
|
|---|
| 13272 | *
|
|---|
| 13273 | * var object = _.create({ 'a': _.create({ 'b': 2 }) });
|
|---|
| 13274 | *
|
|---|
| 13275 | * _.hasIn(object, 'a');
|
|---|
| 13276 | * // => true
|
|---|
| 13277 | *
|
|---|
| 13278 | * _.hasIn(object, 'a.b');
|
|---|
| 13279 | * // => true
|
|---|
| 13280 | *
|
|---|
| 13281 | * _.hasIn(object, ['a', 'b']);
|
|---|
| 13282 | * // => true
|
|---|
| 13283 | *
|
|---|
| 13284 | * _.hasIn(object, 'b');
|
|---|
| 13285 | * // => false
|
|---|
| 13286 | */
|
|---|
| 13287 | function hasIn(object, path) {
|
|---|
| 13288 | return object != null && hasPath(object, path, baseHasIn);
|
|---|
| 13289 | }
|
|---|
| 13290 |
|
|---|
| 13291 | /**
|
|---|
| 13292 | * Creates an object composed of the inverted keys and values of `object`.
|
|---|
| 13293 | * If `object` contains duplicate values, subsequent values overwrite
|
|---|
| 13294 | * property assignments of previous values.
|
|---|
| 13295 | *
|
|---|
| 13296 | * @static
|
|---|
| 13297 | * @memberOf _
|
|---|
| 13298 | * @since 0.7.0
|
|---|
| 13299 | * @category Object
|
|---|
| 13300 | * @param {Object} object The object to invert.
|
|---|
| 13301 | * @returns {Object} Returns the new inverted object.
|
|---|
| 13302 | * @example
|
|---|
| 13303 | *
|
|---|
| 13304 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
|---|
| 13305 | *
|
|---|
| 13306 | * _.invert(object);
|
|---|
| 13307 | * // => { '1': 'c', '2': 'b' }
|
|---|
| 13308 | */
|
|---|
| 13309 | var invert = createInverter(function(result, value, key) {
|
|---|
| 13310 | if (value != null &&
|
|---|
| 13311 | typeof value.toString != 'function') {
|
|---|
| 13312 | value = nativeObjectToString.call(value);
|
|---|
| 13313 | }
|
|---|
| 13314 |
|
|---|
| 13315 | result[value] = key;
|
|---|
| 13316 | }, constant(identity));
|
|---|
| 13317 |
|
|---|
| 13318 | /**
|
|---|
| 13319 | * This method is like `_.invert` except that the inverted object is generated
|
|---|
| 13320 | * from the results of running each element of `object` thru `iteratee`. The
|
|---|
| 13321 | * corresponding inverted value of each inverted key is an array of keys
|
|---|
| 13322 | * responsible for generating the inverted value. The iteratee is invoked
|
|---|
| 13323 | * with one argument: (value).
|
|---|
| 13324 | *
|
|---|
| 13325 | * @static
|
|---|
| 13326 | * @memberOf _
|
|---|
| 13327 | * @since 4.1.0
|
|---|
| 13328 | * @category Object
|
|---|
| 13329 | * @param {Object} object The object to invert.
|
|---|
| 13330 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 13331 | * @returns {Object} Returns the new inverted object.
|
|---|
| 13332 | * @example
|
|---|
| 13333 | *
|
|---|
| 13334 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
|---|
| 13335 | *
|
|---|
| 13336 | * _.invertBy(object);
|
|---|
| 13337 | * // => { '1': ['a', 'c'], '2': ['b'] }
|
|---|
| 13338 | *
|
|---|
| 13339 | * _.invertBy(object, function(value) {
|
|---|
| 13340 | * return 'group' + value;
|
|---|
| 13341 | * });
|
|---|
| 13342 | * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
|---|
| 13343 | */
|
|---|
| 13344 | var invertBy = createInverter(function(result, value, key) {
|
|---|
| 13345 | if (value != null &&
|
|---|
| 13346 | typeof value.toString != 'function') {
|
|---|
| 13347 | value = nativeObjectToString.call(value);
|
|---|
| 13348 | }
|
|---|
| 13349 |
|
|---|
| 13350 | if (hasOwnProperty.call(result, value)) {
|
|---|
| 13351 | result[value].push(key);
|
|---|
| 13352 | } else {
|
|---|
| 13353 | result[value] = [key];
|
|---|
| 13354 | }
|
|---|
| 13355 | }, getIteratee);
|
|---|
| 13356 |
|
|---|
| 13357 | /**
|
|---|
| 13358 | * Invokes the method at `path` of `object`.
|
|---|
| 13359 | *
|
|---|
| 13360 | * @static
|
|---|
| 13361 | * @memberOf _
|
|---|
| 13362 | * @since 4.0.0
|
|---|
| 13363 | * @category Object
|
|---|
| 13364 | * @param {Object} object The object to query.
|
|---|
| 13365 | * @param {Array|string} path The path of the method to invoke.
|
|---|
| 13366 | * @param {...*} [args] The arguments to invoke the method with.
|
|---|
| 13367 | * @returns {*} Returns the result of the invoked method.
|
|---|
| 13368 | * @example
|
|---|
| 13369 | *
|
|---|
| 13370 | * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
|
|---|
| 13371 | *
|
|---|
| 13372 | * _.invoke(object, 'a[0].b.c.slice', 1, 3);
|
|---|
| 13373 | * // => [2, 3]
|
|---|
| 13374 | */
|
|---|
| 13375 | var invoke = baseRest(baseInvoke);
|
|---|
| 13376 |
|
|---|
| 13377 | /**
|
|---|
| 13378 | * Creates an array of the own enumerable property names of `object`.
|
|---|
| 13379 | *
|
|---|
| 13380 | * **Note:** Non-object values are coerced to objects. See the
|
|---|
| 13381 | * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
|---|
| 13382 | * for more details.
|
|---|
| 13383 | *
|
|---|
| 13384 | * @static
|
|---|
| 13385 | * @since 0.1.0
|
|---|
| 13386 | * @memberOf _
|
|---|
| 13387 | * @category Object
|
|---|
| 13388 | * @param {Object} object The object to query.
|
|---|
| 13389 | * @returns {Array} Returns the array of property names.
|
|---|
| 13390 | * @example
|
|---|
| 13391 | *
|
|---|
| 13392 | * function Foo() {
|
|---|
| 13393 | * this.a = 1;
|
|---|
| 13394 | * this.b = 2;
|
|---|
| 13395 | * }
|
|---|
| 13396 | *
|
|---|
| 13397 | * Foo.prototype.c = 3;
|
|---|
| 13398 | *
|
|---|
| 13399 | * _.keys(new Foo);
|
|---|
| 13400 | * // => ['a', 'b'] (iteration order is not guaranteed)
|
|---|
| 13401 | *
|
|---|
| 13402 | * _.keys('hi');
|
|---|
| 13403 | * // => ['0', '1']
|
|---|
| 13404 | */
|
|---|
| 13405 | function keys(object) {
|
|---|
| 13406 | return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
|---|
| 13407 | }
|
|---|
| 13408 |
|
|---|
| 13409 | /**
|
|---|
| 13410 | * Creates an array of the own and inherited enumerable property names of `object`.
|
|---|
| 13411 | *
|
|---|
| 13412 | * **Note:** Non-object values are coerced to objects.
|
|---|
| 13413 | *
|
|---|
| 13414 | * @static
|
|---|
| 13415 | * @memberOf _
|
|---|
| 13416 | * @since 3.0.0
|
|---|
| 13417 | * @category Object
|
|---|
| 13418 | * @param {Object} object The object to query.
|
|---|
| 13419 | * @returns {Array} Returns the array of property names.
|
|---|
| 13420 | * @example
|
|---|
| 13421 | *
|
|---|
| 13422 | * function Foo() {
|
|---|
| 13423 | * this.a = 1;
|
|---|
| 13424 | * this.b = 2;
|
|---|
| 13425 | * }
|
|---|
| 13426 | *
|
|---|
| 13427 | * Foo.prototype.c = 3;
|
|---|
| 13428 | *
|
|---|
| 13429 | * _.keysIn(new Foo);
|
|---|
| 13430 | * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
|---|
| 13431 | */
|
|---|
| 13432 | function keysIn(object) {
|
|---|
| 13433 | return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
|
|---|
| 13434 | }
|
|---|
| 13435 |
|
|---|
| 13436 | /**
|
|---|
| 13437 | * The opposite of `_.mapValues`; this method creates an object with the
|
|---|
| 13438 | * same values as `object` and keys generated by running each own enumerable
|
|---|
| 13439 | * string keyed property of `object` thru `iteratee`. The iteratee is invoked
|
|---|
| 13440 | * with three arguments: (value, key, object).
|
|---|
| 13441 | *
|
|---|
| 13442 | * @static
|
|---|
| 13443 | * @memberOf _
|
|---|
| 13444 | * @since 3.8.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 _.mapValues
|
|---|
| 13450 | * @example
|
|---|
| 13451 | *
|
|---|
| 13452 | * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
|
|---|
| 13453 | * return key + value;
|
|---|
| 13454 | * });
|
|---|
| 13455 | * // => { 'a1': 1, 'b2': 2 }
|
|---|
| 13456 | */
|
|---|
| 13457 | function mapKeys(object, iteratee) {
|
|---|
| 13458 | var result = {};
|
|---|
| 13459 | iteratee = getIteratee(iteratee, 3);
|
|---|
| 13460 |
|
|---|
| 13461 | baseForOwn(object, function(value, key, object) {
|
|---|
| 13462 | baseAssignValue(result, iteratee(value, key, object), value);
|
|---|
| 13463 | });
|
|---|
| 13464 | return result;
|
|---|
| 13465 | }
|
|---|
| 13466 |
|
|---|
| 13467 | /**
|
|---|
| 13468 | * Creates an object with the same keys as `object` and values generated
|
|---|
| 13469 | * by running each own enumerable string keyed property of `object` thru
|
|---|
| 13470 | * `iteratee`. The iteratee is invoked with three arguments:
|
|---|
| 13471 | * (value, key, object).
|
|---|
| 13472 | *
|
|---|
| 13473 | * @static
|
|---|
| 13474 | * @memberOf _
|
|---|
| 13475 | * @since 2.4.0
|
|---|
| 13476 | * @category Object
|
|---|
| 13477 | * @param {Object} object The object to iterate over.
|
|---|
| 13478 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 13479 | * @returns {Object} Returns the new mapped object.
|
|---|
| 13480 | * @see _.mapKeys
|
|---|
| 13481 | * @example
|
|---|
| 13482 | *
|
|---|
| 13483 | * var users = {
|
|---|
| 13484 | * 'fred': { 'user': 'fred', 'age': 40 },
|
|---|
| 13485 | * 'pebbles': { 'user': 'pebbles', 'age': 1 }
|
|---|
| 13486 | * };
|
|---|
| 13487 | *
|
|---|
| 13488 | * _.mapValues(users, function(o) { return o.age; });
|
|---|
| 13489 | * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
|---|
| 13490 | *
|
|---|
| 13491 | * // The `_.property` iteratee shorthand.
|
|---|
| 13492 | * _.mapValues(users, 'age');
|
|---|
| 13493 | * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
|---|
| 13494 | */
|
|---|
| 13495 | function mapValues(object, iteratee) {
|
|---|
| 13496 | var result = {};
|
|---|
| 13497 | iteratee = getIteratee(iteratee, 3);
|
|---|
| 13498 |
|
|---|
| 13499 | baseForOwn(object, function(value, key, object) {
|
|---|
| 13500 | baseAssignValue(result, key, iteratee(value, key, object));
|
|---|
| 13501 | });
|
|---|
| 13502 | return result;
|
|---|
| 13503 | }
|
|---|
| 13504 |
|
|---|
| 13505 | /**
|
|---|
| 13506 | * This method is like `_.assign` except that it recursively merges own and
|
|---|
| 13507 | * inherited enumerable string keyed properties of source objects into the
|
|---|
| 13508 | * destination object. Source properties that resolve to `undefined` are
|
|---|
| 13509 | * skipped if a destination value exists. Array and plain object properties
|
|---|
| 13510 | * are merged recursively. Other objects and value types are overridden by
|
|---|
| 13511 | * assignment. Source objects are applied from left to right. Subsequent
|
|---|
| 13512 | * sources overwrite property assignments of previous sources.
|
|---|
| 13513 | *
|
|---|
| 13514 | * **Note:** This method mutates `object`.
|
|---|
| 13515 | *
|
|---|
| 13516 | * @static
|
|---|
| 13517 | * @memberOf _
|
|---|
| 13518 | * @since 0.5.0
|
|---|
| 13519 | * @category Object
|
|---|
| 13520 | * @param {Object} object The destination object.
|
|---|
| 13521 | * @param {...Object} [sources] The source objects.
|
|---|
| 13522 | * @returns {Object} Returns `object`.
|
|---|
| 13523 | * @example
|
|---|
| 13524 | *
|
|---|
| 13525 | * var object = {
|
|---|
| 13526 | * 'a': [{ 'b': 2 }, { 'd': 4 }]
|
|---|
| 13527 | * };
|
|---|
| 13528 | *
|
|---|
| 13529 | * var other = {
|
|---|
| 13530 | * 'a': [{ 'c': 3 }, { 'e': 5 }]
|
|---|
| 13531 | * };
|
|---|
| 13532 | *
|
|---|
| 13533 | * _.merge(object, other);
|
|---|
| 13534 | * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
|
|---|
| 13535 | */
|
|---|
| 13536 | var merge = createAssigner(function(object, source, srcIndex) {
|
|---|
| 13537 | baseMerge(object, source, srcIndex);
|
|---|
| 13538 | });
|
|---|
| 13539 |
|
|---|
| 13540 | /**
|
|---|
| 13541 | * This method is like `_.merge` except that it accepts `customizer` which
|
|---|
| 13542 | * is invoked to produce the merged values of the destination and source
|
|---|
| 13543 | * properties. If `customizer` returns `undefined`, merging is handled by the
|
|---|
| 13544 | * method instead. The `customizer` is invoked with six arguments:
|
|---|
| 13545 | * (objValue, srcValue, key, object, source, stack).
|
|---|
| 13546 | *
|
|---|
| 13547 | * **Note:** This method mutates `object`.
|
|---|
| 13548 | *
|
|---|
| 13549 | * @static
|
|---|
| 13550 | * @memberOf _
|
|---|
| 13551 | * @since 4.0.0
|
|---|
| 13552 | * @category Object
|
|---|
| 13553 | * @param {Object} object The destination object.
|
|---|
| 13554 | * @param {...Object} sources The source objects.
|
|---|
| 13555 | * @param {Function} customizer The function to customize assigned values.
|
|---|
| 13556 | * @returns {Object} Returns `object`.
|
|---|
| 13557 | * @example
|
|---|
| 13558 | *
|
|---|
| 13559 | * function customizer(objValue, srcValue) {
|
|---|
| 13560 | * if (_.isArray(objValue)) {
|
|---|
| 13561 | * return objValue.concat(srcValue);
|
|---|
| 13562 | * }
|
|---|
| 13563 | * }
|
|---|
| 13564 | *
|
|---|
| 13565 | * var object = { 'a': [1], 'b': [2] };
|
|---|
| 13566 | * var other = { 'a': [3], 'b': [4] };
|
|---|
| 13567 | *
|
|---|
| 13568 | * _.mergeWith(object, other, customizer);
|
|---|
| 13569 | * // => { 'a': [1, 3], 'b': [2, 4] }
|
|---|
| 13570 | */
|
|---|
| 13571 | var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
|
|---|
| 13572 | baseMerge(object, source, srcIndex, customizer);
|
|---|
| 13573 | });
|
|---|
| 13574 |
|
|---|
| 13575 | /**
|
|---|
| 13576 | * The opposite of `_.pick`; this method creates an object composed of the
|
|---|
| 13577 | * own and inherited enumerable property paths of `object` that are not omitted.
|
|---|
| 13578 | *
|
|---|
| 13579 | * **Note:** This method is considerably slower than `_.pick`.
|
|---|
| 13580 | *
|
|---|
| 13581 | * @static
|
|---|
| 13582 | * @since 0.1.0
|
|---|
| 13583 | * @memberOf _
|
|---|
| 13584 | * @category Object
|
|---|
| 13585 | * @param {Object} object The source object.
|
|---|
| 13586 | * @param {...(string|string[])} [paths] The property paths to omit.
|
|---|
| 13587 | * @returns {Object} Returns the new object.
|
|---|
| 13588 | * @example
|
|---|
| 13589 | *
|
|---|
| 13590 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
|---|
| 13591 | *
|
|---|
| 13592 | * _.omit(object, ['a', 'c']);
|
|---|
| 13593 | * // => { 'b': '2' }
|
|---|
| 13594 | */
|
|---|
| 13595 | var omit = flatRest(function(object, paths) {
|
|---|
| 13596 | var result = {};
|
|---|
| 13597 | if (object == null) {
|
|---|
| 13598 | return result;
|
|---|
| 13599 | }
|
|---|
| 13600 | var isDeep = false;
|
|---|
| 13601 | paths = arrayMap(paths, function(path) {
|
|---|
| 13602 | path = castPath(path, object);
|
|---|
| 13603 | isDeep || (isDeep = path.length > 1);
|
|---|
| 13604 | return path;
|
|---|
| 13605 | });
|
|---|
| 13606 | copyObject(object, getAllKeysIn(object), result);
|
|---|
| 13607 | if (isDeep) {
|
|---|
| 13608 | result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
|
|---|
| 13609 | }
|
|---|
| 13610 | var length = paths.length;
|
|---|
| 13611 | while (length--) {
|
|---|
| 13612 | baseUnset(result, paths[length]);
|
|---|
| 13613 | }
|
|---|
| 13614 | return result;
|
|---|
| 13615 | });
|
|---|
| 13616 |
|
|---|
| 13617 | /**
|
|---|
| 13618 | * The opposite of `_.pickBy`; this method creates an object composed of
|
|---|
| 13619 | * the own and inherited enumerable string keyed properties of `object` that
|
|---|
| 13620 | * `predicate` doesn't return truthy for. The predicate is invoked with two
|
|---|
| 13621 | * arguments: (value, key).
|
|---|
| 13622 | *
|
|---|
| 13623 | * @static
|
|---|
| 13624 | * @memberOf _
|
|---|
| 13625 | * @since 4.0.0
|
|---|
| 13626 | * @category Object
|
|---|
| 13627 | * @param {Object} object The source object.
|
|---|
| 13628 | * @param {Function} [predicate=_.identity] The function invoked per property.
|
|---|
| 13629 | * @returns {Object} Returns the new object.
|
|---|
| 13630 | * @example
|
|---|
| 13631 | *
|
|---|
| 13632 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
|---|
| 13633 | *
|
|---|
| 13634 | * _.omitBy(object, _.isNumber);
|
|---|
| 13635 | * // => { 'b': '2' }
|
|---|
| 13636 | */
|
|---|
| 13637 | function omitBy(object, predicate) {
|
|---|
| 13638 | return pickBy(object, negate(getIteratee(predicate)));
|
|---|
| 13639 | }
|
|---|
| 13640 |
|
|---|
| 13641 | /**
|
|---|
| 13642 | * Creates an object composed of the picked `object` properties.
|
|---|
| 13643 | *
|
|---|
| 13644 | * @static
|
|---|
| 13645 | * @since 0.1.0
|
|---|
| 13646 | * @memberOf _
|
|---|
| 13647 | * @category Object
|
|---|
| 13648 | * @param {Object} object The source object.
|
|---|
| 13649 | * @param {...(string|string[])} [paths] The property paths to pick.
|
|---|
| 13650 | * @returns {Object} Returns the new object.
|
|---|
| 13651 | * @example
|
|---|
| 13652 | *
|
|---|
| 13653 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
|---|
| 13654 | *
|
|---|
| 13655 | * _.pick(object, ['a', 'c']);
|
|---|
| 13656 | * // => { 'a': 1, 'c': 3 }
|
|---|
| 13657 | */
|
|---|
| 13658 | var pick = flatRest(function(object, paths) {
|
|---|
| 13659 | return object == null ? {} : basePick(object, paths);
|
|---|
| 13660 | });
|
|---|
| 13661 |
|
|---|
| 13662 | /**
|
|---|
| 13663 | * Creates an object composed of the `object` properties `predicate` returns
|
|---|
| 13664 | * truthy for. The predicate is invoked with two arguments: (value, key).
|
|---|
| 13665 | *
|
|---|
| 13666 | * @static
|
|---|
| 13667 | * @memberOf _
|
|---|
| 13668 | * @since 4.0.0
|
|---|
| 13669 | * @category Object
|
|---|
| 13670 | * @param {Object} object The source object.
|
|---|
| 13671 | * @param {Function} [predicate=_.identity] The function invoked per property.
|
|---|
| 13672 | * @returns {Object} Returns the new object.
|
|---|
| 13673 | * @example
|
|---|
| 13674 | *
|
|---|
| 13675 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
|---|
| 13676 | *
|
|---|
| 13677 | * _.pickBy(object, _.isNumber);
|
|---|
| 13678 | * // => { 'a': 1, 'c': 3 }
|
|---|
| 13679 | */
|
|---|
| 13680 | function pickBy(object, predicate) {
|
|---|
| 13681 | if (object == null) {
|
|---|
| 13682 | return {};
|
|---|
| 13683 | }
|
|---|
| 13684 | var props = arrayMap(getAllKeysIn(object), function(prop) {
|
|---|
| 13685 | return [prop];
|
|---|
| 13686 | });
|
|---|
| 13687 | predicate = getIteratee(predicate);
|
|---|
| 13688 | return basePickBy(object, props, function(value, path) {
|
|---|
| 13689 | return predicate(value, path[0]);
|
|---|
| 13690 | });
|
|---|
| 13691 | }
|
|---|
| 13692 |
|
|---|
| 13693 | /**
|
|---|
| 13694 | * This method is like `_.get` except that if the resolved value is a
|
|---|
| 13695 | * function it's invoked with the `this` binding of its parent object and
|
|---|
| 13696 | * its result is returned.
|
|---|
| 13697 | *
|
|---|
| 13698 | * @static
|
|---|
| 13699 | * @since 0.1.0
|
|---|
| 13700 | * @memberOf _
|
|---|
| 13701 | * @category Object
|
|---|
| 13702 | * @param {Object} object The object to query.
|
|---|
| 13703 | * @param {Array|string} path The path of the property to resolve.
|
|---|
| 13704 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
|---|
| 13705 | * @returns {*} Returns the resolved value.
|
|---|
| 13706 | * @example
|
|---|
| 13707 | *
|
|---|
| 13708 | * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
|
|---|
| 13709 | *
|
|---|
| 13710 | * _.result(object, 'a[0].b.c1');
|
|---|
| 13711 | * // => 3
|
|---|
| 13712 | *
|
|---|
| 13713 | * _.result(object, 'a[0].b.c2');
|
|---|
| 13714 | * // => 4
|
|---|
| 13715 | *
|
|---|
| 13716 | * _.result(object, 'a[0].b.c3', 'default');
|
|---|
| 13717 | * // => 'default'
|
|---|
| 13718 | *
|
|---|
| 13719 | * _.result(object, 'a[0].b.c3', _.constant('default'));
|
|---|
| 13720 | * // => 'default'
|
|---|
| 13721 | */
|
|---|
| 13722 | function result(object, path, defaultValue) {
|
|---|
| 13723 | path = castPath(path, object);
|
|---|
| 13724 |
|
|---|
| 13725 | var index = -1,
|
|---|
| 13726 | length = path.length;
|
|---|
| 13727 |
|
|---|
| 13728 | // Ensure the loop is entered when path is empty.
|
|---|
| 13729 | if (!length) {
|
|---|
| 13730 | length = 1;
|
|---|
| 13731 | object = undefined;
|
|---|
| 13732 | }
|
|---|
| 13733 | while (++index < length) {
|
|---|
| 13734 | var value = object == null ? undefined : object[toKey(path[index])];
|
|---|
| 13735 | if (value === undefined) {
|
|---|
| 13736 | index = length;
|
|---|
| 13737 | value = defaultValue;
|
|---|
| 13738 | }
|
|---|
| 13739 | object = isFunction(value) ? value.call(object) : value;
|
|---|
| 13740 | }
|
|---|
| 13741 | return object;
|
|---|
| 13742 | }
|
|---|
| 13743 |
|
|---|
| 13744 | /**
|
|---|
| 13745 | * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
|
|---|
| 13746 | * it's created. Arrays are created for missing index properties while objects
|
|---|
| 13747 | * are created for all other missing properties. Use `_.setWith` to customize
|
|---|
| 13748 | * `path` creation.
|
|---|
| 13749 | *
|
|---|
| 13750 | * **Note:** This method mutates `object`.
|
|---|
| 13751 | *
|
|---|
| 13752 | * @static
|
|---|
| 13753 | * @memberOf _
|
|---|
| 13754 | * @since 3.7.0
|
|---|
| 13755 | * @category Object
|
|---|
| 13756 | * @param {Object} object The object to modify.
|
|---|
| 13757 | * @param {Array|string} path The path of the property to set.
|
|---|
| 13758 | * @param {*} value The value to set.
|
|---|
| 13759 | * @returns {Object} Returns `object`.
|
|---|
| 13760 | * @example
|
|---|
| 13761 | *
|
|---|
| 13762 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|---|
| 13763 | *
|
|---|
| 13764 | * _.set(object, 'a[0].b.c', 4);
|
|---|
| 13765 | * console.log(object.a[0].b.c);
|
|---|
| 13766 | * // => 4
|
|---|
| 13767 | *
|
|---|
| 13768 | * _.set(object, ['x', '0', 'y', 'z'], 5);
|
|---|
| 13769 | * console.log(object.x[0].y.z);
|
|---|
| 13770 | * // => 5
|
|---|
| 13771 | */
|
|---|
| 13772 | function set(object, path, value) {
|
|---|
| 13773 | return object == null ? object : baseSet(object, path, value);
|
|---|
| 13774 | }
|
|---|
| 13775 |
|
|---|
| 13776 | /**
|
|---|
| 13777 | * This method is like `_.set` except that it accepts `customizer` which is
|
|---|
| 13778 | * invoked to produce the objects of `path`. If `customizer` returns `undefined`
|
|---|
| 13779 | * path creation is handled by the method instead. The `customizer` is invoked
|
|---|
| 13780 | * with three arguments: (nsValue, key, nsObject).
|
|---|
| 13781 | *
|
|---|
| 13782 | * **Note:** This method mutates `object`.
|
|---|
| 13783 | *
|
|---|
| 13784 | * @static
|
|---|
| 13785 | * @memberOf _
|
|---|
| 13786 | * @since 4.0.0
|
|---|
| 13787 | * @category Object
|
|---|
| 13788 | * @param {Object} object The object to modify.
|
|---|
| 13789 | * @param {Array|string} path The path of the property to set.
|
|---|
| 13790 | * @param {*} value The value to set.
|
|---|
| 13791 | * @param {Function} [customizer] The function to customize assigned values.
|
|---|
| 13792 | * @returns {Object} Returns `object`.
|
|---|
| 13793 | * @example
|
|---|
| 13794 | *
|
|---|
| 13795 | * var object = {};
|
|---|
| 13796 | *
|
|---|
| 13797 | * _.setWith(object, '[0][1]', 'a', Object);
|
|---|
| 13798 | * // => { '0': { '1': 'a' } }
|
|---|
| 13799 | */
|
|---|
| 13800 | function setWith(object, path, value, customizer) {
|
|---|
| 13801 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
|---|
| 13802 | return object == null ? object : baseSet(object, path, value, customizer);
|
|---|
| 13803 | }
|
|---|
| 13804 |
|
|---|
| 13805 | /**
|
|---|
| 13806 | * Creates an array of own enumerable string keyed-value pairs for `object`
|
|---|
| 13807 | * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
|
|---|
| 13808 | * entries are returned.
|
|---|
| 13809 | *
|
|---|
| 13810 | * @static
|
|---|
| 13811 | * @memberOf _
|
|---|
| 13812 | * @since 4.0.0
|
|---|
| 13813 | * @alias entries
|
|---|
| 13814 | * @category Object
|
|---|
| 13815 | * @param {Object} object The object to query.
|
|---|
| 13816 | * @returns {Array} Returns the key-value pairs.
|
|---|
| 13817 | * @example
|
|---|
| 13818 | *
|
|---|
| 13819 | * function Foo() {
|
|---|
| 13820 | * this.a = 1;
|
|---|
| 13821 | * this.b = 2;
|
|---|
| 13822 | * }
|
|---|
| 13823 | *
|
|---|
| 13824 | * Foo.prototype.c = 3;
|
|---|
| 13825 | *
|
|---|
| 13826 | * _.toPairs(new Foo);
|
|---|
| 13827 | * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
|
|---|
| 13828 | */
|
|---|
| 13829 | var toPairs = createToPairs(keys);
|
|---|
| 13830 |
|
|---|
| 13831 | /**
|
|---|
| 13832 | * Creates an array of own and inherited enumerable string keyed-value pairs
|
|---|
| 13833 | * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
|
|---|
| 13834 | * or set, its entries are returned.
|
|---|
| 13835 | *
|
|---|
| 13836 | * @static
|
|---|
| 13837 | * @memberOf _
|
|---|
| 13838 | * @since 4.0.0
|
|---|
| 13839 | * @alias entriesIn
|
|---|
| 13840 | * @category Object
|
|---|
| 13841 | * @param {Object} object The object to query.
|
|---|
| 13842 | * @returns {Array} Returns the key-value pairs.
|
|---|
| 13843 | * @example
|
|---|
| 13844 | *
|
|---|
| 13845 | * function Foo() {
|
|---|
| 13846 | * this.a = 1;
|
|---|
| 13847 | * this.b = 2;
|
|---|
| 13848 | * }
|
|---|
| 13849 | *
|
|---|
| 13850 | * Foo.prototype.c = 3;
|
|---|
| 13851 | *
|
|---|
| 13852 | * _.toPairsIn(new Foo);
|
|---|
| 13853 | * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
|
|---|
| 13854 | */
|
|---|
| 13855 | var toPairsIn = createToPairs(keysIn);
|
|---|
| 13856 |
|
|---|
| 13857 | /**
|
|---|
| 13858 | * An alternative to `_.reduce`; this method transforms `object` to a new
|
|---|
| 13859 | * `accumulator` object which is the result of running each of its own
|
|---|
| 13860 | * enumerable string keyed properties thru `iteratee`, with each invocation
|
|---|
| 13861 | * potentially mutating the `accumulator` object. If `accumulator` is not
|
|---|
| 13862 | * provided, a new object with the same `[[Prototype]]` will be used. The
|
|---|
| 13863 | * iteratee is invoked with four arguments: (accumulator, value, key, object).
|
|---|
| 13864 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
|---|
| 13865 | *
|
|---|
| 13866 | * @static
|
|---|
| 13867 | * @memberOf _
|
|---|
| 13868 | * @since 1.3.0
|
|---|
| 13869 | * @category Object
|
|---|
| 13870 | * @param {Object} object The object to iterate over.
|
|---|
| 13871 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 13872 | * @param {*} [accumulator] The custom accumulator value.
|
|---|
| 13873 | * @returns {*} Returns the accumulated value.
|
|---|
| 13874 | * @example
|
|---|
| 13875 | *
|
|---|
| 13876 | * _.transform([2, 3, 4], function(result, n) {
|
|---|
| 13877 | * result.push(n *= n);
|
|---|
| 13878 | * return n % 2 == 0;
|
|---|
| 13879 | * }, []);
|
|---|
| 13880 | * // => [4, 9]
|
|---|
| 13881 | *
|
|---|
| 13882 | * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
|---|
| 13883 | * (result[value] || (result[value] = [])).push(key);
|
|---|
| 13884 | * }, {});
|
|---|
| 13885 | * // => { '1': ['a', 'c'], '2': ['b'] }
|
|---|
| 13886 | */
|
|---|
| 13887 | function transform(object, iteratee, accumulator) {
|
|---|
| 13888 | var isArr = isArray(object),
|
|---|
| 13889 | isArrLike = isArr || isBuffer(object) || isTypedArray(object);
|
|---|
| 13890 |
|
|---|
| 13891 | iteratee = getIteratee(iteratee, 4);
|
|---|
| 13892 | if (accumulator == null) {
|
|---|
| 13893 | var Ctor = object && object.constructor;
|
|---|
| 13894 | if (isArrLike) {
|
|---|
| 13895 | accumulator = isArr ? new Ctor : [];
|
|---|
| 13896 | }
|
|---|
| 13897 | else if (isObject(object)) {
|
|---|
| 13898 | accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
|
|---|
| 13899 | }
|
|---|
| 13900 | else {
|
|---|
| 13901 | accumulator = {};
|
|---|
| 13902 | }
|
|---|
| 13903 | }
|
|---|
| 13904 | (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
|
|---|
| 13905 | return iteratee(accumulator, value, index, object);
|
|---|
| 13906 | });
|
|---|
| 13907 | return accumulator;
|
|---|
| 13908 | }
|
|---|
| 13909 |
|
|---|
| 13910 | /**
|
|---|
| 13911 | * Removes the property at `path` of `object`.
|
|---|
| 13912 | *
|
|---|
| 13913 | * **Note:** This method mutates `object`.
|
|---|
| 13914 | *
|
|---|
| 13915 | * @static
|
|---|
| 13916 | * @memberOf _
|
|---|
| 13917 | * @since 4.0.0
|
|---|
| 13918 | * @category Object
|
|---|
| 13919 | * @param {Object} object The object to modify.
|
|---|
| 13920 | * @param {Array|string} path The path of the property to unset.
|
|---|
| 13921 | * @returns {boolean} Returns `true` if the property is deleted, else `false`.
|
|---|
| 13922 | * @example
|
|---|
| 13923 | *
|
|---|
| 13924 | * var object = { 'a': [{ 'b': { 'c': 7 } }] };
|
|---|
| 13925 | * _.unset(object, 'a[0].b.c');
|
|---|
| 13926 | * // => true
|
|---|
| 13927 | *
|
|---|
| 13928 | * console.log(object);
|
|---|
| 13929 | * // => { 'a': [{ 'b': {} }] };
|
|---|
| 13930 | *
|
|---|
| 13931 | * _.unset(object, ['a', '0', 'b', 'c']);
|
|---|
| 13932 | * // => true
|
|---|
| 13933 | *
|
|---|
| 13934 | * console.log(object);
|
|---|
| 13935 | * // => { 'a': [{ 'b': {} }] };
|
|---|
| 13936 | */
|
|---|
| 13937 | function unset(object, path) {
|
|---|
| 13938 | return object == null ? true : baseUnset(object, path);
|
|---|
| 13939 | }
|
|---|
| 13940 |
|
|---|
| 13941 | /**
|
|---|
| 13942 | * This method is like `_.set` except that accepts `updater` to produce the
|
|---|
| 13943 | * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
|
|---|
| 13944 | * is invoked with one argument: (value).
|
|---|
| 13945 | *
|
|---|
| 13946 | * **Note:** This method mutates `object`.
|
|---|
| 13947 | *
|
|---|
| 13948 | * @static
|
|---|
| 13949 | * @memberOf _
|
|---|
| 13950 | * @since 4.6.0
|
|---|
| 13951 | * @category Object
|
|---|
| 13952 | * @param {Object} object The object to modify.
|
|---|
| 13953 | * @param {Array|string} path The path of the property to set.
|
|---|
| 13954 | * @param {Function} updater The function to produce the updated value.
|
|---|
| 13955 | * @returns {Object} Returns `object`.
|
|---|
| 13956 | * @example
|
|---|
| 13957 | *
|
|---|
| 13958 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|---|
| 13959 | *
|
|---|
| 13960 | * _.update(object, 'a[0].b.c', function(n) { return n * n; });
|
|---|
| 13961 | * console.log(object.a[0].b.c);
|
|---|
| 13962 | * // => 9
|
|---|
| 13963 | *
|
|---|
| 13964 | * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
|
|---|
| 13965 | * console.log(object.x[0].y.z);
|
|---|
| 13966 | * // => 0
|
|---|
| 13967 | */
|
|---|
| 13968 | function update(object, path, updater) {
|
|---|
| 13969 | return object == null ? object : baseUpdate(object, path, castFunction(updater));
|
|---|
| 13970 | }
|
|---|
| 13971 |
|
|---|
| 13972 | /**
|
|---|
| 13973 | * This method is like `_.update` except that it accepts `customizer` which is
|
|---|
| 13974 | * invoked to produce the objects of `path`. If `customizer` returns `undefined`
|
|---|
| 13975 | * path creation is handled by the method instead. The `customizer` is invoked
|
|---|
| 13976 | * with three arguments: (nsValue, key, nsObject).
|
|---|
| 13977 | *
|
|---|
| 13978 | * **Note:** This method mutates `object`.
|
|---|
| 13979 | *
|
|---|
| 13980 | * @static
|
|---|
| 13981 | * @memberOf _
|
|---|
| 13982 | * @since 4.6.0
|
|---|
| 13983 | * @category Object
|
|---|
| 13984 | * @param {Object} object The object to modify.
|
|---|
| 13985 | * @param {Array|string} path The path of the property to set.
|
|---|
| 13986 | * @param {Function} updater The function to produce the updated value.
|
|---|
| 13987 | * @param {Function} [customizer] The function to customize assigned values.
|
|---|
| 13988 | * @returns {Object} Returns `object`.
|
|---|
| 13989 | * @example
|
|---|
| 13990 | *
|
|---|
| 13991 | * var object = {};
|
|---|
| 13992 | *
|
|---|
| 13993 | * _.updateWith(object, '[0][1]', _.constant('a'), Object);
|
|---|
| 13994 | * // => { '0': { '1': 'a' } }
|
|---|
| 13995 | */
|
|---|
| 13996 | function updateWith(object, path, updater, customizer) {
|
|---|
| 13997 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
|---|
| 13998 | return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
|
|---|
| 13999 | }
|
|---|
| 14000 |
|
|---|
| 14001 | /**
|
|---|
| 14002 | * Creates an array of the own enumerable string keyed property values of `object`.
|
|---|
| 14003 | *
|
|---|
| 14004 | * **Note:** Non-object values are coerced to objects.
|
|---|
| 14005 | *
|
|---|
| 14006 | * @static
|
|---|
| 14007 | * @since 0.1.0
|
|---|
| 14008 | * @memberOf _
|
|---|
| 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 | * _.values(new Foo);
|
|---|
| 14022 | * // => [1, 2] (iteration order is not guaranteed)
|
|---|
| 14023 | *
|
|---|
| 14024 | * _.values('hi');
|
|---|
| 14025 | * // => ['h', 'i']
|
|---|
| 14026 | */
|
|---|
| 14027 | function values(object) {
|
|---|
| 14028 | return object == null ? [] : baseValues(object, keys(object));
|
|---|
| 14029 | }
|
|---|
| 14030 |
|
|---|
| 14031 | /**
|
|---|
| 14032 | * Creates an array of the own and inherited enumerable string keyed property
|
|---|
| 14033 | * values of `object`.
|
|---|
| 14034 | *
|
|---|
| 14035 | * **Note:** Non-object values are coerced to objects.
|
|---|
| 14036 | *
|
|---|
| 14037 | * @static
|
|---|
| 14038 | * @memberOf _
|
|---|
| 14039 | * @since 3.0.0
|
|---|
| 14040 | * @category Object
|
|---|
| 14041 | * @param {Object} object The object to query.
|
|---|
| 14042 | * @returns {Array} Returns the array of property values.
|
|---|
| 14043 | * @example
|
|---|
| 14044 | *
|
|---|
| 14045 | * function Foo() {
|
|---|
| 14046 | * this.a = 1;
|
|---|
| 14047 | * this.b = 2;
|
|---|
| 14048 | * }
|
|---|
| 14049 | *
|
|---|
| 14050 | * Foo.prototype.c = 3;
|
|---|
| 14051 | *
|
|---|
| 14052 | * _.valuesIn(new Foo);
|
|---|
| 14053 | * // => [1, 2, 3] (iteration order is not guaranteed)
|
|---|
| 14054 | */
|
|---|
| 14055 | function valuesIn(object) {
|
|---|
| 14056 | return object == null ? [] : baseValues(object, keysIn(object));
|
|---|
| 14057 | }
|
|---|
| 14058 |
|
|---|
| 14059 | /*------------------------------------------------------------------------*/
|
|---|
| 14060 |
|
|---|
| 14061 | /**
|
|---|
| 14062 | * Clamps `number` within the inclusive `lower` and `upper` bounds.
|
|---|
| 14063 | *
|
|---|
| 14064 | * @static
|
|---|
| 14065 | * @memberOf _
|
|---|
| 14066 | * @since 4.0.0
|
|---|
| 14067 | * @category Number
|
|---|
| 14068 | * @param {number} number The number to clamp.
|
|---|
| 14069 | * @param {number} [lower] The lower bound.
|
|---|
| 14070 | * @param {number} upper The upper bound.
|
|---|
| 14071 | * @returns {number} Returns the clamped number.
|
|---|
| 14072 | * @example
|
|---|
| 14073 | *
|
|---|
| 14074 | * _.clamp(-10, -5, 5);
|
|---|
| 14075 | * // => -5
|
|---|
| 14076 | *
|
|---|
| 14077 | * _.clamp(10, -5, 5);
|
|---|
| 14078 | * // => 5
|
|---|
| 14079 | */
|
|---|
| 14080 | function clamp(number, lower, upper) {
|
|---|
| 14081 | if (upper === undefined) {
|
|---|
| 14082 | upper = lower;
|
|---|
| 14083 | lower = undefined;
|
|---|
| 14084 | }
|
|---|
| 14085 | if (upper !== undefined) {
|
|---|
| 14086 | upper = toNumber(upper);
|
|---|
| 14087 | upper = upper === upper ? upper : 0;
|
|---|
| 14088 | }
|
|---|
| 14089 | if (lower !== undefined) {
|
|---|
| 14090 | lower = toNumber(lower);
|
|---|
| 14091 | lower = lower === lower ? lower : 0;
|
|---|
| 14092 | }
|
|---|
| 14093 | return baseClamp(toNumber(number), lower, upper);
|
|---|
| 14094 | }
|
|---|
| 14095 |
|
|---|
| 14096 | /**
|
|---|
| 14097 | * Checks if `n` is between `start` and up to, but not including, `end`. If
|
|---|
| 14098 | * `end` is not specified, it's set to `start` with `start` then set to `0`.
|
|---|
| 14099 | * If `start` is greater than `end` the params are swapped to support
|
|---|
| 14100 | * negative ranges.
|
|---|
| 14101 | *
|
|---|
| 14102 | * @static
|
|---|
| 14103 | * @memberOf _
|
|---|
| 14104 | * @since 3.3.0
|
|---|
| 14105 | * @category Number
|
|---|
| 14106 | * @param {number} number The number to check.
|
|---|
| 14107 | * @param {number} [start=0] The start of the range.
|
|---|
| 14108 | * @param {number} end The end of the range.
|
|---|
| 14109 | * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
|
|---|
| 14110 | * @see _.range, _.rangeRight
|
|---|
| 14111 | * @example
|
|---|
| 14112 | *
|
|---|
| 14113 | * _.inRange(3, 2, 4);
|
|---|
| 14114 | * // => true
|
|---|
| 14115 | *
|
|---|
| 14116 | * _.inRange(4, 8);
|
|---|
| 14117 | * // => true
|
|---|
| 14118 | *
|
|---|
| 14119 | * _.inRange(4, 2);
|
|---|
| 14120 | * // => false
|
|---|
| 14121 | *
|
|---|
| 14122 | * _.inRange(2, 2);
|
|---|
| 14123 | * // => false
|
|---|
| 14124 | *
|
|---|
| 14125 | * _.inRange(1.2, 2);
|
|---|
| 14126 | * // => true
|
|---|
| 14127 | *
|
|---|
| 14128 | * _.inRange(5.2, 4);
|
|---|
| 14129 | * // => false
|
|---|
| 14130 | *
|
|---|
| 14131 | * _.inRange(-3, -2, -6);
|
|---|
| 14132 | * // => true
|
|---|
| 14133 | */
|
|---|
| 14134 | function inRange(number, start, end) {
|
|---|
| 14135 | start = toFinite(start);
|
|---|
| 14136 | if (end === undefined) {
|
|---|
| 14137 | end = start;
|
|---|
| 14138 | start = 0;
|
|---|
| 14139 | } else {
|
|---|
| 14140 | end = toFinite(end);
|
|---|
| 14141 | }
|
|---|
| 14142 | number = toNumber(number);
|
|---|
| 14143 | return baseInRange(number, start, end);
|
|---|
| 14144 | }
|
|---|
| 14145 |
|
|---|
| 14146 | /**
|
|---|
| 14147 | * Produces a random number between the inclusive `lower` and `upper` bounds.
|
|---|
| 14148 | * If only one argument is provided a number between `0` and the given number
|
|---|
| 14149 | * is returned. If `floating` is `true`, or either `lower` or `upper` are
|
|---|
| 14150 | * floats, a floating-point number is returned instead of an integer.
|
|---|
| 14151 | *
|
|---|
| 14152 | * **Note:** JavaScript follows the IEEE-754 standard for resolving
|
|---|
| 14153 | * floating-point values which can produce unexpected results.
|
|---|
| 14154 | *
|
|---|
| 14155 | * **Note:** If `lower` is greater than `upper`, the values are swapped.
|
|---|
| 14156 | *
|
|---|
| 14157 | * @static
|
|---|
| 14158 | * @memberOf _
|
|---|
| 14159 | * @since 0.7.0
|
|---|
| 14160 | * @category Number
|
|---|
| 14161 | * @param {number} [lower=0] The lower bound.
|
|---|
| 14162 | * @param {number} [upper=1] The upper bound.
|
|---|
| 14163 | * @param {boolean} [floating] Specify returning a floating-point number.
|
|---|
| 14164 | * @returns {number} Returns the random number.
|
|---|
| 14165 | * @example
|
|---|
| 14166 | *
|
|---|
| 14167 | * _.random(0, 5);
|
|---|
| 14168 | * // => an integer between 0 and 5
|
|---|
| 14169 | *
|
|---|
| 14170 | * // when lower is greater than upper the values are swapped
|
|---|
| 14171 | * _.random(5, 0);
|
|---|
| 14172 | * // => an integer between 0 and 5
|
|---|
| 14173 | *
|
|---|
| 14174 | * _.random(5);
|
|---|
| 14175 | * // => also an integer between 0 and 5
|
|---|
| 14176 | *
|
|---|
| 14177 | * _.random(-5);
|
|---|
| 14178 | * // => an integer between -5 and 0
|
|---|
| 14179 | *
|
|---|
| 14180 | * _.random(5, true);
|
|---|
| 14181 | * // => a floating-point number between 0 and 5
|
|---|
| 14182 | *
|
|---|
| 14183 | * _.random(1.2, 5.2);
|
|---|
| 14184 | * // => a floating-point number between 1.2 and 5.2
|
|---|
| 14185 | */
|
|---|
| 14186 | function random(lower, upper, floating) {
|
|---|
| 14187 | if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
|
|---|
| 14188 | upper = floating = undefined;
|
|---|
| 14189 | }
|
|---|
| 14190 | if (floating === undefined) {
|
|---|
| 14191 | if (typeof upper == 'boolean') {
|
|---|
| 14192 | floating = upper;
|
|---|
| 14193 | upper = undefined;
|
|---|
| 14194 | }
|
|---|
| 14195 | else if (typeof lower == 'boolean') {
|
|---|
| 14196 | floating = lower;
|
|---|
| 14197 | lower = undefined;
|
|---|
| 14198 | }
|
|---|
| 14199 | }
|
|---|
| 14200 | if (lower === undefined && upper === undefined) {
|
|---|
| 14201 | lower = 0;
|
|---|
| 14202 | upper = 1;
|
|---|
| 14203 | }
|
|---|
| 14204 | else {
|
|---|
| 14205 | lower = toFinite(lower);
|
|---|
| 14206 | if (upper === undefined) {
|
|---|
| 14207 | upper = lower;
|
|---|
| 14208 | lower = 0;
|
|---|
| 14209 | } else {
|
|---|
| 14210 | upper = toFinite(upper);
|
|---|
| 14211 | }
|
|---|
| 14212 | }
|
|---|
| 14213 | if (lower > upper) {
|
|---|
| 14214 | var temp = lower;
|
|---|
| 14215 | lower = upper;
|
|---|
| 14216 | upper = temp;
|
|---|
| 14217 | }
|
|---|
| 14218 | if (floating || lower % 1 || upper % 1) {
|
|---|
| 14219 | var rand = nativeRandom();
|
|---|
| 14220 | return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
|
|---|
| 14221 | }
|
|---|
| 14222 | return baseRandom(lower, upper);
|
|---|
| 14223 | }
|
|---|
| 14224 |
|
|---|
| 14225 | /*------------------------------------------------------------------------*/
|
|---|
| 14226 |
|
|---|
| 14227 | /**
|
|---|
| 14228 | * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
|
|---|
| 14229 | *
|
|---|
| 14230 | * @static
|
|---|
| 14231 | * @memberOf _
|
|---|
| 14232 | * @since 3.0.0
|
|---|
| 14233 | * @category String
|
|---|
| 14234 | * @param {string} [string=''] The string to convert.
|
|---|
| 14235 | * @returns {string} Returns the camel cased string.
|
|---|
| 14236 | * @example
|
|---|
| 14237 | *
|
|---|
| 14238 | * _.camelCase('Foo Bar');
|
|---|
| 14239 | * // => 'fooBar'
|
|---|
| 14240 | *
|
|---|
| 14241 | * _.camelCase('--foo-bar--');
|
|---|
| 14242 | * // => 'fooBar'
|
|---|
| 14243 | *
|
|---|
| 14244 | * _.camelCase('__FOO_BAR__');
|
|---|
| 14245 | * // => 'fooBar'
|
|---|
| 14246 | */
|
|---|
| 14247 | var camelCase = createCompounder(function(result, word, index) {
|
|---|
| 14248 | word = word.toLowerCase();
|
|---|
| 14249 | return result + (index ? capitalize(word) : word);
|
|---|
| 14250 | });
|
|---|
| 14251 |
|
|---|
| 14252 | /**
|
|---|
| 14253 | * Converts the first character of `string` to upper case and the remaining
|
|---|
| 14254 | * to lower case.
|
|---|
| 14255 | *
|
|---|
| 14256 | * @static
|
|---|
| 14257 | * @memberOf _
|
|---|
| 14258 | * @since 3.0.0
|
|---|
| 14259 | * @category String
|
|---|
| 14260 | * @param {string} [string=''] The string to capitalize.
|
|---|
| 14261 | * @returns {string} Returns the capitalized string.
|
|---|
| 14262 | * @example
|
|---|
| 14263 | *
|
|---|
| 14264 | * _.capitalize('FRED');
|
|---|
| 14265 | * // => 'Fred'
|
|---|
| 14266 | */
|
|---|
| 14267 | function capitalize(string) {
|
|---|
| 14268 | return upperFirst(toString(string).toLowerCase());
|
|---|
| 14269 | }
|
|---|
| 14270 |
|
|---|
| 14271 | /**
|
|---|
| 14272 | * Deburrs `string` by converting
|
|---|
| 14273 | * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
|---|
| 14274 | * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
|
|---|
| 14275 | * letters to basic Latin letters and removing
|
|---|
| 14276 | * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
|---|
| 14277 | *
|
|---|
| 14278 | * @static
|
|---|
| 14279 | * @memberOf _
|
|---|
| 14280 | * @since 3.0.0
|
|---|
| 14281 | * @category String
|
|---|
| 14282 | * @param {string} [string=''] The string to deburr.
|
|---|
| 14283 | * @returns {string} Returns the deburred string.
|
|---|
| 14284 | * @example
|
|---|
| 14285 | *
|
|---|
| 14286 | * _.deburr('déjà vu');
|
|---|
| 14287 | * // => 'deja vu'
|
|---|
| 14288 | */
|
|---|
| 14289 | function deburr(string) {
|
|---|
| 14290 | string = toString(string);
|
|---|
| 14291 | return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
|
|---|
| 14292 | }
|
|---|
| 14293 |
|
|---|
| 14294 | /**
|
|---|
| 14295 | * Checks if `string` ends with the given target string.
|
|---|
| 14296 | *
|
|---|
| 14297 | * @static
|
|---|
| 14298 | * @memberOf _
|
|---|
| 14299 | * @since 3.0.0
|
|---|
| 14300 | * @category String
|
|---|
| 14301 | * @param {string} [string=''] The string to inspect.
|
|---|
| 14302 | * @param {string} [target] The string to search for.
|
|---|
| 14303 | * @param {number} [position=string.length] The position to search up to.
|
|---|
| 14304 | * @returns {boolean} Returns `true` if `string` ends with `target`,
|
|---|
| 14305 | * else `false`.
|
|---|
| 14306 | * @example
|
|---|
| 14307 | *
|
|---|
| 14308 | * _.endsWith('abc', 'c');
|
|---|
| 14309 | * // => true
|
|---|
| 14310 | *
|
|---|
| 14311 | * _.endsWith('abc', 'b');
|
|---|
| 14312 | * // => false
|
|---|
| 14313 | *
|
|---|
| 14314 | * _.endsWith('abc', 'b', 2);
|
|---|
| 14315 | * // => true
|
|---|
| 14316 | */
|
|---|
| 14317 | function endsWith(string, target, position) {
|
|---|
| 14318 | string = toString(string);
|
|---|
| 14319 | target = baseToString(target);
|
|---|
| 14320 |
|
|---|
| 14321 | var length = string.length;
|
|---|
| 14322 | position = position === undefined
|
|---|
| 14323 | ? length
|
|---|
| 14324 | : baseClamp(toInteger(position), 0, length);
|
|---|
| 14325 |
|
|---|
| 14326 | var end = position;
|
|---|
| 14327 | position -= target.length;
|
|---|
| 14328 | return position >= 0 && string.slice(position, end) == target;
|
|---|
| 14329 | }
|
|---|
| 14330 |
|
|---|
| 14331 | /**
|
|---|
| 14332 | * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
|
|---|
| 14333 | * corresponding HTML entities.
|
|---|
| 14334 | *
|
|---|
| 14335 | * **Note:** No other characters are escaped. To escape additional
|
|---|
| 14336 | * characters use a third-party library like [_he_](https://mths.be/he).
|
|---|
| 14337 | *
|
|---|
| 14338 | * Though the ">" character is escaped for symmetry, characters like
|
|---|
| 14339 | * ">" and "/" don't need escaping in HTML and have no special meaning
|
|---|
| 14340 | * unless they're part of a tag or unquoted attribute value. See
|
|---|
| 14341 | * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
|
|---|
| 14342 | * (under "semi-related fun fact") for more details.
|
|---|
| 14343 | *
|
|---|
| 14344 | * When working with HTML you should always
|
|---|
| 14345 | * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
|
|---|
| 14346 | * XSS vectors.
|
|---|
| 14347 | *
|
|---|
| 14348 | * @static
|
|---|
| 14349 | * @since 0.1.0
|
|---|
| 14350 | * @memberOf _
|
|---|
| 14351 | * @category String
|
|---|
| 14352 | * @param {string} [string=''] The string to escape.
|
|---|
| 14353 | * @returns {string} Returns the escaped string.
|
|---|
| 14354 | * @example
|
|---|
| 14355 | *
|
|---|
| 14356 | * _.escape('fred, barney, & pebbles');
|
|---|
| 14357 | * // => 'fred, barney, & pebbles'
|
|---|
| 14358 | */
|
|---|
| 14359 | function escape(string) {
|
|---|
| 14360 | string = toString(string);
|
|---|
| 14361 | return (string && reHasUnescapedHtml.test(string))
|
|---|
| 14362 | ? string.replace(reUnescapedHtml, escapeHtmlChar)
|
|---|
| 14363 | : string;
|
|---|
| 14364 | }
|
|---|
| 14365 |
|
|---|
| 14366 | /**
|
|---|
| 14367 | * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
|
|---|
| 14368 | * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
|
|---|
| 14369 | *
|
|---|
| 14370 | * @static
|
|---|
| 14371 | * @memberOf _
|
|---|
| 14372 | * @since 3.0.0
|
|---|
| 14373 | * @category String
|
|---|
| 14374 | * @param {string} [string=''] The string to escape.
|
|---|
| 14375 | * @returns {string} Returns the escaped string.
|
|---|
| 14376 | * @example
|
|---|
| 14377 | *
|
|---|
| 14378 | * _.escapeRegExp('[lodash](https://lodash.com/)');
|
|---|
| 14379 | * // => '\[lodash\]\(https://lodash\.com/\)'
|
|---|
| 14380 | */
|
|---|
| 14381 | function escapeRegExp(string) {
|
|---|
| 14382 | string = toString(string);
|
|---|
| 14383 | return (string && reHasRegExpChar.test(string))
|
|---|
| 14384 | ? string.replace(reRegExpChar, '\\$&')
|
|---|
| 14385 | : string;
|
|---|
| 14386 | }
|
|---|
| 14387 |
|
|---|
| 14388 | /**
|
|---|
| 14389 | * Converts `string` to
|
|---|
| 14390 | * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
|
|---|
| 14391 | *
|
|---|
| 14392 | * @static
|
|---|
| 14393 | * @memberOf _
|
|---|
| 14394 | * @since 3.0.0
|
|---|
| 14395 | * @category String
|
|---|
| 14396 | * @param {string} [string=''] The string to convert.
|
|---|
| 14397 | * @returns {string} Returns the kebab cased string.
|
|---|
| 14398 | * @example
|
|---|
| 14399 | *
|
|---|
| 14400 | * _.kebabCase('Foo Bar');
|
|---|
| 14401 | * // => 'foo-bar'
|
|---|
| 14402 | *
|
|---|
| 14403 | * _.kebabCase('fooBar');
|
|---|
| 14404 | * // => 'foo-bar'
|
|---|
| 14405 | *
|
|---|
| 14406 | * _.kebabCase('__FOO_BAR__');
|
|---|
| 14407 | * // => 'foo-bar'
|
|---|
| 14408 | */
|
|---|
| 14409 | var kebabCase = createCompounder(function(result, word, index) {
|
|---|
| 14410 | return result + (index ? '-' : '') + word.toLowerCase();
|
|---|
| 14411 | });
|
|---|
| 14412 |
|
|---|
| 14413 | /**
|
|---|
| 14414 | * Converts `string`, as space separated words, to lower case.
|
|---|
| 14415 | *
|
|---|
| 14416 | * @static
|
|---|
| 14417 | * @memberOf _
|
|---|
| 14418 | * @since 4.0.0
|
|---|
| 14419 | * @category String
|
|---|
| 14420 | * @param {string} [string=''] The string to convert.
|
|---|
| 14421 | * @returns {string} Returns the lower cased string.
|
|---|
| 14422 | * @example
|
|---|
| 14423 | *
|
|---|
| 14424 | * _.lowerCase('--Foo-Bar--');
|
|---|
| 14425 | * // => 'foo bar'
|
|---|
| 14426 | *
|
|---|
| 14427 | * _.lowerCase('fooBar');
|
|---|
| 14428 | * // => 'foo bar'
|
|---|
| 14429 | *
|
|---|
| 14430 | * _.lowerCase('__FOO_BAR__');
|
|---|
| 14431 | * // => 'foo bar'
|
|---|
| 14432 | */
|
|---|
| 14433 | var lowerCase = createCompounder(function(result, word, index) {
|
|---|
| 14434 | return result + (index ? ' ' : '') + word.toLowerCase();
|
|---|
| 14435 | });
|
|---|
| 14436 |
|
|---|
| 14437 | /**
|
|---|
| 14438 | * Converts the first character of `string` to lower case.
|
|---|
| 14439 | *
|
|---|
| 14440 | * @static
|
|---|
| 14441 | * @memberOf _
|
|---|
| 14442 | * @since 4.0.0
|
|---|
| 14443 | * @category String
|
|---|
| 14444 | * @param {string} [string=''] The string to convert.
|
|---|
| 14445 | * @returns {string} Returns the converted string.
|
|---|
| 14446 | * @example
|
|---|
| 14447 | *
|
|---|
| 14448 | * _.lowerFirst('Fred');
|
|---|
| 14449 | * // => 'fred'
|
|---|
| 14450 | *
|
|---|
| 14451 | * _.lowerFirst('FRED');
|
|---|
| 14452 | * // => 'fRED'
|
|---|
| 14453 | */
|
|---|
| 14454 | var lowerFirst = createCaseFirst('toLowerCase');
|
|---|
| 14455 |
|
|---|
| 14456 | /**
|
|---|
| 14457 | * Pads `string` on the left and right sides if it's shorter than `length`.
|
|---|
| 14458 | * Padding characters are truncated if they can't be evenly divided by `length`.
|
|---|
| 14459 | *
|
|---|
| 14460 | * @static
|
|---|
| 14461 | * @memberOf _
|
|---|
| 14462 | * @since 3.0.0
|
|---|
| 14463 | * @category String
|
|---|
| 14464 | * @param {string} [string=''] The string to pad.
|
|---|
| 14465 | * @param {number} [length=0] The padding length.
|
|---|
| 14466 | * @param {string} [chars=' '] The string used as padding.
|
|---|
| 14467 | * @returns {string} Returns the padded string.
|
|---|
| 14468 | * @example
|
|---|
| 14469 | *
|
|---|
| 14470 | * _.pad('abc', 8);
|
|---|
| 14471 | * // => ' abc '
|
|---|
| 14472 | *
|
|---|
| 14473 | * _.pad('abc', 8, '_-');
|
|---|
| 14474 | * // => '_-abc_-_'
|
|---|
| 14475 | *
|
|---|
| 14476 | * _.pad('abc', 3);
|
|---|
| 14477 | * // => 'abc'
|
|---|
| 14478 | */
|
|---|
| 14479 | function pad(string, length, chars) {
|
|---|
| 14480 | string = toString(string);
|
|---|
| 14481 | length = toInteger(length);
|
|---|
| 14482 |
|
|---|
| 14483 | var strLength = length ? stringSize(string) : 0;
|
|---|
| 14484 | if (!length || strLength >= length) {
|
|---|
| 14485 | return string;
|
|---|
| 14486 | }
|
|---|
| 14487 | var mid = (length - strLength) / 2;
|
|---|
| 14488 | return (
|
|---|
| 14489 | createPadding(nativeFloor(mid), chars) +
|
|---|
| 14490 | string +
|
|---|
| 14491 | createPadding(nativeCeil(mid), chars)
|
|---|
| 14492 | );
|
|---|
| 14493 | }
|
|---|
| 14494 |
|
|---|
| 14495 | /**
|
|---|
| 14496 | * Pads `string` on the right side if it's shorter than `length`. Padding
|
|---|
| 14497 | * characters are truncated if they exceed `length`.
|
|---|
| 14498 | *
|
|---|
| 14499 | * @static
|
|---|
| 14500 | * @memberOf _
|
|---|
| 14501 | * @since 4.0.0
|
|---|
| 14502 | * @category String
|
|---|
| 14503 | * @param {string} [string=''] The string to pad.
|
|---|
| 14504 | * @param {number} [length=0] The padding length.
|
|---|
| 14505 | * @param {string} [chars=' '] The string used as padding.
|
|---|
| 14506 | * @returns {string} Returns the padded string.
|
|---|
| 14507 | * @example
|
|---|
| 14508 | *
|
|---|
| 14509 | * _.padEnd('abc', 6);
|
|---|
| 14510 | * // => 'abc '
|
|---|
| 14511 | *
|
|---|
| 14512 | * _.padEnd('abc', 6, '_-');
|
|---|
| 14513 | * // => 'abc_-_'
|
|---|
| 14514 | *
|
|---|
| 14515 | * _.padEnd('abc', 3);
|
|---|
| 14516 | * // => 'abc'
|
|---|
| 14517 | */
|
|---|
| 14518 | function padEnd(string, length, chars) {
|
|---|
| 14519 | string = toString(string);
|
|---|
| 14520 | length = toInteger(length);
|
|---|
| 14521 |
|
|---|
| 14522 | var strLength = length ? stringSize(string) : 0;
|
|---|
| 14523 | return (length && strLength < length)
|
|---|
| 14524 | ? (string + createPadding(length - strLength, chars))
|
|---|
| 14525 | : string;
|
|---|
| 14526 | }
|
|---|
| 14527 |
|
|---|
| 14528 | /**
|
|---|
| 14529 | * Pads `string` on the left side if it's shorter than `length`. Padding
|
|---|
| 14530 | * characters are truncated if they exceed `length`.
|
|---|
| 14531 | *
|
|---|
| 14532 | * @static
|
|---|
| 14533 | * @memberOf _
|
|---|
| 14534 | * @since 4.0.0
|
|---|
| 14535 | * @category String
|
|---|
| 14536 | * @param {string} [string=''] The string to pad.
|
|---|
| 14537 | * @param {number} [length=0] The padding length.
|
|---|
| 14538 | * @param {string} [chars=' '] The string used as padding.
|
|---|
| 14539 | * @returns {string} Returns the padded string.
|
|---|
| 14540 | * @example
|
|---|
| 14541 | *
|
|---|
| 14542 | * _.padStart('abc', 6);
|
|---|
| 14543 | * // => ' abc'
|
|---|
| 14544 | *
|
|---|
| 14545 | * _.padStart('abc', 6, '_-');
|
|---|
| 14546 | * // => '_-_abc'
|
|---|
| 14547 | *
|
|---|
| 14548 | * _.padStart('abc', 3);
|
|---|
| 14549 | * // => 'abc'
|
|---|
| 14550 | */
|
|---|
| 14551 | function padStart(string, length, chars) {
|
|---|
| 14552 | string = toString(string);
|
|---|
| 14553 | length = toInteger(length);
|
|---|
| 14554 |
|
|---|
| 14555 | var strLength = length ? stringSize(string) : 0;
|
|---|
| 14556 | return (length && strLength < length)
|
|---|
| 14557 | ? (createPadding(length - strLength, chars) + string)
|
|---|
| 14558 | : string;
|
|---|
| 14559 | }
|
|---|
| 14560 |
|
|---|
| 14561 | /**
|
|---|
| 14562 | * Converts `string` to an integer of the specified radix. If `radix` is
|
|---|
| 14563 | * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
|
|---|
| 14564 | * hexadecimal, in which case a `radix` of `16` is used.
|
|---|
| 14565 | *
|
|---|
| 14566 | * **Note:** This method aligns with the
|
|---|
| 14567 | * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
|
|---|
| 14568 | *
|
|---|
| 14569 | * @static
|
|---|
| 14570 | * @memberOf _
|
|---|
| 14571 | * @since 1.1.0
|
|---|
| 14572 | * @category String
|
|---|
| 14573 | * @param {string} string The string to convert.
|
|---|
| 14574 | * @param {number} [radix=10] The radix to interpret `value` by.
|
|---|
| 14575 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 14576 | * @returns {number} Returns the converted integer.
|
|---|
| 14577 | * @example
|
|---|
| 14578 | *
|
|---|
| 14579 | * _.parseInt('08');
|
|---|
| 14580 | * // => 8
|
|---|
| 14581 | *
|
|---|
| 14582 | * _.map(['6', '08', '10'], _.parseInt);
|
|---|
| 14583 | * // => [6, 8, 10]
|
|---|
| 14584 | */
|
|---|
| 14585 | function parseInt(string, radix, guard) {
|
|---|
| 14586 | if (guard || radix == null) {
|
|---|
| 14587 | radix = 0;
|
|---|
| 14588 | } else if (radix) {
|
|---|
| 14589 | radix = +radix;
|
|---|
| 14590 | }
|
|---|
| 14591 | return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
|
|---|
| 14592 | }
|
|---|
| 14593 |
|
|---|
| 14594 | /**
|
|---|
| 14595 | * Repeats the given string `n` times.
|
|---|
| 14596 | *
|
|---|
| 14597 | * @static
|
|---|
| 14598 | * @memberOf _
|
|---|
| 14599 | * @since 3.0.0
|
|---|
| 14600 | * @category String
|
|---|
| 14601 | * @param {string} [string=''] The string to repeat.
|
|---|
| 14602 | * @param {number} [n=1] The number of times to repeat the string.
|
|---|
| 14603 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 14604 | * @returns {string} Returns the repeated string.
|
|---|
| 14605 | * @example
|
|---|
| 14606 | *
|
|---|
| 14607 | * _.repeat('*', 3);
|
|---|
| 14608 | * // => '***'
|
|---|
| 14609 | *
|
|---|
| 14610 | * _.repeat('abc', 2);
|
|---|
| 14611 | * // => 'abcabc'
|
|---|
| 14612 | *
|
|---|
| 14613 | * _.repeat('abc', 0);
|
|---|
| 14614 | * // => ''
|
|---|
| 14615 | */
|
|---|
| 14616 | function repeat(string, n, guard) {
|
|---|
| 14617 | if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
|
|---|
| 14618 | n = 1;
|
|---|
| 14619 | } else {
|
|---|
| 14620 | n = toInteger(n);
|
|---|
| 14621 | }
|
|---|
| 14622 | return baseRepeat(toString(string), n);
|
|---|
| 14623 | }
|
|---|
| 14624 |
|
|---|
| 14625 | /**
|
|---|
| 14626 | * Replaces matches for `pattern` in `string` with `replacement`.
|
|---|
| 14627 | *
|
|---|
| 14628 | * **Note:** This method is based on
|
|---|
| 14629 | * [`String#replace`](https://mdn.io/String/replace).
|
|---|
| 14630 | *
|
|---|
| 14631 | * @static
|
|---|
| 14632 | * @memberOf _
|
|---|
| 14633 | * @since 4.0.0
|
|---|
| 14634 | * @category String
|
|---|
| 14635 | * @param {string} [string=''] The string to modify.
|
|---|
| 14636 | * @param {RegExp|string} pattern The pattern to replace.
|
|---|
| 14637 | * @param {Function|string} replacement The match replacement.
|
|---|
| 14638 | * @returns {string} Returns the modified string.
|
|---|
| 14639 | * @example
|
|---|
| 14640 | *
|
|---|
| 14641 | * _.replace('Hi Fred', 'Fred', 'Barney');
|
|---|
| 14642 | * // => 'Hi Barney'
|
|---|
| 14643 | */
|
|---|
| 14644 | function replace() {
|
|---|
| 14645 | var args = arguments,
|
|---|
| 14646 | string = toString(args[0]);
|
|---|
| 14647 |
|
|---|
| 14648 | return args.length < 3 ? string : string.replace(args[1], args[2]);
|
|---|
| 14649 | }
|
|---|
| 14650 |
|
|---|
| 14651 | /**
|
|---|
| 14652 | * Converts `string` to
|
|---|
| 14653 | * [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
|---|
| 14654 | *
|
|---|
| 14655 | * @static
|
|---|
| 14656 | * @memberOf _
|
|---|
| 14657 | * @since 3.0.0
|
|---|
| 14658 | * @category String
|
|---|
| 14659 | * @param {string} [string=''] The string to convert.
|
|---|
| 14660 | * @returns {string} Returns the snake cased string.
|
|---|
| 14661 | * @example
|
|---|
| 14662 | *
|
|---|
| 14663 | * _.snakeCase('Foo Bar');
|
|---|
| 14664 | * // => 'foo_bar'
|
|---|
| 14665 | *
|
|---|
| 14666 | * _.snakeCase('fooBar');
|
|---|
| 14667 | * // => 'foo_bar'
|
|---|
| 14668 | *
|
|---|
| 14669 | * _.snakeCase('--FOO-BAR--');
|
|---|
| 14670 | * // => 'foo_bar'
|
|---|
| 14671 | */
|
|---|
| 14672 | var snakeCase = createCompounder(function(result, word, index) {
|
|---|
| 14673 | return result + (index ? '_' : '') + word.toLowerCase();
|
|---|
| 14674 | });
|
|---|
| 14675 |
|
|---|
| 14676 | /**
|
|---|
| 14677 | * Splits `string` by `separator`.
|
|---|
| 14678 | *
|
|---|
| 14679 | * **Note:** This method is based on
|
|---|
| 14680 | * [`String#split`](https://mdn.io/String/split).
|
|---|
| 14681 | *
|
|---|
| 14682 | * @static
|
|---|
| 14683 | * @memberOf _
|
|---|
| 14684 | * @since 4.0.0
|
|---|
| 14685 | * @category String
|
|---|
| 14686 | * @param {string} [string=''] The string to split.
|
|---|
| 14687 | * @param {RegExp|string} separator The separator pattern to split by.
|
|---|
| 14688 | * @param {number} [limit] The length to truncate results to.
|
|---|
| 14689 | * @returns {Array} Returns the string segments.
|
|---|
| 14690 | * @example
|
|---|
| 14691 | *
|
|---|
| 14692 | * _.split('a-b-c', '-', 2);
|
|---|
| 14693 | * // => ['a', 'b']
|
|---|
| 14694 | */
|
|---|
| 14695 | function split(string, separator, limit) {
|
|---|
| 14696 | if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
|
|---|
| 14697 | separator = limit = undefined;
|
|---|
| 14698 | }
|
|---|
| 14699 | limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
|
|---|
| 14700 | if (!limit) {
|
|---|
| 14701 | return [];
|
|---|
| 14702 | }
|
|---|
| 14703 | string = toString(string);
|
|---|
| 14704 | if (string && (
|
|---|
| 14705 | typeof separator == 'string' ||
|
|---|
| 14706 | (separator != null && !isRegExp(separator))
|
|---|
| 14707 | )) {
|
|---|
| 14708 | separator = baseToString(separator);
|
|---|
| 14709 | if (!separator && hasUnicode(string)) {
|
|---|
| 14710 | return castSlice(stringToArray(string), 0, limit);
|
|---|
| 14711 | }
|
|---|
| 14712 | }
|
|---|
| 14713 | return string.split(separator, limit);
|
|---|
| 14714 | }
|
|---|
| 14715 |
|
|---|
| 14716 | /**
|
|---|
| 14717 | * Converts `string` to
|
|---|
| 14718 | * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
|
|---|
| 14719 | *
|
|---|
| 14720 | * @static
|
|---|
| 14721 | * @memberOf _
|
|---|
| 14722 | * @since 3.1.0
|
|---|
| 14723 | * @category String
|
|---|
| 14724 | * @param {string} [string=''] The string to convert.
|
|---|
| 14725 | * @returns {string} Returns the start cased string.
|
|---|
| 14726 | * @example
|
|---|
| 14727 | *
|
|---|
| 14728 | * _.startCase('--foo-bar--');
|
|---|
| 14729 | * // => 'Foo Bar'
|
|---|
| 14730 | *
|
|---|
| 14731 | * _.startCase('fooBar');
|
|---|
| 14732 | * // => 'Foo Bar'
|
|---|
| 14733 | *
|
|---|
| 14734 | * _.startCase('__FOO_BAR__');
|
|---|
| 14735 | * // => 'FOO BAR'
|
|---|
| 14736 | */
|
|---|
| 14737 | var startCase = createCompounder(function(result, word, index) {
|
|---|
| 14738 | return result + (index ? ' ' : '') + upperFirst(word);
|
|---|
| 14739 | });
|
|---|
| 14740 |
|
|---|
| 14741 | /**
|
|---|
| 14742 | * Checks if `string` starts with the given target string.
|
|---|
| 14743 | *
|
|---|
| 14744 | * @static
|
|---|
| 14745 | * @memberOf _
|
|---|
| 14746 | * @since 3.0.0
|
|---|
| 14747 | * @category String
|
|---|
| 14748 | * @param {string} [string=''] The string to inspect.
|
|---|
| 14749 | * @param {string} [target] The string to search for.
|
|---|
| 14750 | * @param {number} [position=0] The position to search from.
|
|---|
| 14751 | * @returns {boolean} Returns `true` if `string` starts with `target`,
|
|---|
| 14752 | * else `false`.
|
|---|
| 14753 | * @example
|
|---|
| 14754 | *
|
|---|
| 14755 | * _.startsWith('abc', 'a');
|
|---|
| 14756 | * // => true
|
|---|
| 14757 | *
|
|---|
| 14758 | * _.startsWith('abc', 'b');
|
|---|
| 14759 | * // => false
|
|---|
| 14760 | *
|
|---|
| 14761 | * _.startsWith('abc', 'b', 1);
|
|---|
| 14762 | * // => true
|
|---|
| 14763 | */
|
|---|
| 14764 | function startsWith(string, target, position) {
|
|---|
| 14765 | string = toString(string);
|
|---|
| 14766 | position = position == null
|
|---|
| 14767 | ? 0
|
|---|
| 14768 | : baseClamp(toInteger(position), 0, string.length);
|
|---|
| 14769 |
|
|---|
| 14770 | target = baseToString(target);
|
|---|
| 14771 | return string.slice(position, position + target.length) == target;
|
|---|
| 14772 | }
|
|---|
| 14773 |
|
|---|
| 14774 | /**
|
|---|
| 14775 | * Creates a compiled template function that can interpolate data properties
|
|---|
| 14776 | * in "interpolate" delimiters, HTML-escape interpolated data properties in
|
|---|
| 14777 | * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
|
|---|
| 14778 | * properties may be accessed as free variables in the template. If a setting
|
|---|
| 14779 | * object is given, it takes precedence over `_.templateSettings` values.
|
|---|
| 14780 | *
|
|---|
| 14781 | * **Security:** `_.template` is insecure and should not be used. It will be
|
|---|
| 14782 | * removed in Lodash v5. Avoid untrusted input. See
|
|---|
| 14783 | * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md).
|
|---|
| 14784 | *
|
|---|
| 14785 | * **Note:** In the development build `_.template` utilizes
|
|---|
| 14786 | * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
|
|---|
| 14787 | * for easier debugging.
|
|---|
| 14788 | *
|
|---|
| 14789 | * For more information on precompiling templates see
|
|---|
| 14790 | * [lodash's custom builds documentation](https://lodash.com/custom-builds).
|
|---|
| 14791 | *
|
|---|
| 14792 | * For more information on Chrome extension sandboxes see
|
|---|
| 14793 | * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
|
|---|
| 14794 | *
|
|---|
| 14795 | * @static
|
|---|
| 14796 | * @since 0.1.0
|
|---|
| 14797 | * @memberOf _
|
|---|
| 14798 | * @category String
|
|---|
| 14799 | * @param {string} [string=''] The template string.
|
|---|
| 14800 | * @param {Object} [options={}] The options object.
|
|---|
| 14801 | * @param {RegExp} [options.escape=_.templateSettings.escape]
|
|---|
| 14802 | * The HTML "escape" delimiter.
|
|---|
| 14803 | * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
|
|---|
| 14804 | * The "evaluate" delimiter.
|
|---|
| 14805 | * @param {Object} [options.imports=_.templateSettings.imports]
|
|---|
| 14806 | * An object to import into the template as free variables.
|
|---|
| 14807 | * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
|
|---|
| 14808 | * The "interpolate" delimiter.
|
|---|
| 14809 | * @param {string} [options.sourceURL='lodash.templateSources[n]']
|
|---|
| 14810 | * The sourceURL of the compiled template.
|
|---|
| 14811 | * @param {string} [options.variable='obj']
|
|---|
| 14812 | * The data object variable name.
|
|---|
| 14813 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 14814 | * @returns {Function} Returns the compiled template function.
|
|---|
| 14815 | * @example
|
|---|
| 14816 | *
|
|---|
| 14817 | * // Use the "interpolate" delimiter to create a compiled template.
|
|---|
| 14818 | * var compiled = _.template('hello <%= user %>!');
|
|---|
| 14819 | * compiled({ 'user': 'fred' });
|
|---|
| 14820 | * // => 'hello fred!'
|
|---|
| 14821 | *
|
|---|
| 14822 | * // Use the HTML "escape" delimiter to escape data property values.
|
|---|
| 14823 | * var compiled = _.template('<b><%- value %></b>');
|
|---|
| 14824 | * compiled({ 'value': '<script>' });
|
|---|
| 14825 | * // => '<b><script></b>'
|
|---|
| 14826 | *
|
|---|
| 14827 | * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
|
|---|
| 14828 | * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
|---|
| 14829 | * compiled({ 'users': ['fred', 'barney'] });
|
|---|
| 14830 | * // => '<li>fred</li><li>barney</li>'
|
|---|
| 14831 | *
|
|---|
| 14832 | * // Use the internal `print` function in "evaluate" delimiters.
|
|---|
| 14833 | * var compiled = _.template('<% print("hello " + user); %>!');
|
|---|
| 14834 | * compiled({ 'user': 'barney' });
|
|---|
| 14835 | * // => 'hello barney!'
|
|---|
| 14836 | *
|
|---|
| 14837 | * // Use the ES template literal delimiter as an "interpolate" delimiter.
|
|---|
| 14838 | * // Disable support by replacing the "interpolate" delimiter.
|
|---|
| 14839 | * var compiled = _.template('hello ${ user }!');
|
|---|
| 14840 | * compiled({ 'user': 'pebbles' });
|
|---|
| 14841 | * // => 'hello pebbles!'
|
|---|
| 14842 | *
|
|---|
| 14843 | * // Use backslashes to treat delimiters as plain text.
|
|---|
| 14844 | * var compiled = _.template('<%= "\\<%- value %\\>" %>');
|
|---|
| 14845 | * compiled({ 'value': 'ignored' });
|
|---|
| 14846 | * // => '<%- value %>'
|
|---|
| 14847 | *
|
|---|
| 14848 | * // Use the `imports` option to import `jQuery` as `jq`.
|
|---|
| 14849 | * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
|
|---|
| 14850 | * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
|
|---|
| 14851 | * compiled({ 'users': ['fred', 'barney'] });
|
|---|
| 14852 | * // => '<li>fred</li><li>barney</li>'
|
|---|
| 14853 | *
|
|---|
| 14854 | * // Use the `sourceURL` option to specify a custom sourceURL for the template.
|
|---|
| 14855 | * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
|
|---|
| 14856 | * compiled(data);
|
|---|
| 14857 | * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
|
|---|
| 14858 | *
|
|---|
| 14859 | * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
|
|---|
| 14860 | * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
|
|---|
| 14861 | * compiled.source;
|
|---|
| 14862 | * // => function(data) {
|
|---|
| 14863 | * // var __t, __p = '';
|
|---|
| 14864 | * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
|
|---|
| 14865 | * // return __p;
|
|---|
| 14866 | * // }
|
|---|
| 14867 | *
|
|---|
| 14868 | * // Use custom template delimiters.
|
|---|
| 14869 | * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|---|
| 14870 | * var compiled = _.template('hello {{ user }}!');
|
|---|
| 14871 | * compiled({ 'user': 'mustache' });
|
|---|
| 14872 | * // => 'hello mustache!'
|
|---|
| 14873 | *
|
|---|
| 14874 | * // Use the `source` property to inline compiled templates for meaningful
|
|---|
| 14875 | * // line numbers in error messages and stack traces.
|
|---|
| 14876 | * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
|
|---|
| 14877 | * var JST = {\
|
|---|
| 14878 | * "main": ' + _.template(mainText).source + '\
|
|---|
| 14879 | * };\
|
|---|
| 14880 | * ');
|
|---|
| 14881 | */
|
|---|
| 14882 | function template(string, options, guard) {
|
|---|
| 14883 | // Based on John Resig's `tmpl` implementation
|
|---|
| 14884 | // (http://ejohn.org/blog/javascript-micro-templating/)
|
|---|
| 14885 | // and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
|---|
| 14886 | var settings = lodash.templateSettings;
|
|---|
| 14887 |
|
|---|
| 14888 | if (guard && isIterateeCall(string, options, guard)) {
|
|---|
| 14889 | options = undefined;
|
|---|
| 14890 | }
|
|---|
| 14891 | string = toString(string);
|
|---|
| 14892 | options = assignWith({}, options, settings, customDefaultsAssignIn);
|
|---|
| 14893 |
|
|---|
| 14894 | var imports = assignWith({}, options.imports, settings.imports, customDefaultsAssignIn),
|
|---|
| 14895 | importsKeys = keys(imports),
|
|---|
| 14896 | importsValues = baseValues(imports, importsKeys);
|
|---|
| 14897 |
|
|---|
| 14898 | arrayEach(importsKeys, function(key) {
|
|---|
| 14899 | if (reForbiddenIdentifierChars.test(key)) {
|
|---|
| 14900 | throw new Error(INVALID_TEMPL_IMPORTS_ERROR_TEXT);
|
|---|
| 14901 | }
|
|---|
| 14902 | });
|
|---|
| 14903 |
|
|---|
| 14904 | var isEscaping,
|
|---|
| 14905 | isEvaluating,
|
|---|
| 14906 | index = 0,
|
|---|
| 14907 | interpolate = options.interpolate || reNoMatch,
|
|---|
| 14908 | source = "__p += '";
|
|---|
| 14909 |
|
|---|
| 14910 | // Compile the regexp to match each delimiter.
|
|---|
| 14911 | var reDelimiters = RegExp(
|
|---|
| 14912 | (options.escape || reNoMatch).source + '|' +
|
|---|
| 14913 | interpolate.source + '|' +
|
|---|
| 14914 | (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
|
|---|
| 14915 | (options.evaluate || reNoMatch).source + '|$'
|
|---|
| 14916 | , 'g');
|
|---|
| 14917 |
|
|---|
| 14918 | // Use a sourceURL for easier debugging.
|
|---|
| 14919 | // The sourceURL gets injected into the source that's eval-ed, so be careful
|
|---|
| 14920 | // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
|
|---|
| 14921 | // and escape the comment, thus injecting code that gets evaled.
|
|---|
| 14922 | var sourceURL = '//# sourceURL=' +
|
|---|
| 14923 | (hasOwnProperty.call(options, 'sourceURL')
|
|---|
| 14924 | ? (options.sourceURL + '').replace(/\s/g, ' ')
|
|---|
| 14925 | : ('lodash.templateSources[' + (++templateCounter) + ']')
|
|---|
| 14926 | ) + '\n';
|
|---|
| 14927 |
|
|---|
| 14928 | string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
|
|---|
| 14929 | interpolateValue || (interpolateValue = esTemplateValue);
|
|---|
| 14930 |
|
|---|
| 14931 | // Escape characters that can't be included in string literals.
|
|---|
| 14932 | source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
|
|---|
| 14933 |
|
|---|
| 14934 | // Replace delimiters with snippets.
|
|---|
| 14935 | if (escapeValue) {
|
|---|
| 14936 | isEscaping = true;
|
|---|
| 14937 | source += "' +\n__e(" + escapeValue + ") +\n'";
|
|---|
| 14938 | }
|
|---|
| 14939 | if (evaluateValue) {
|
|---|
| 14940 | isEvaluating = true;
|
|---|
| 14941 | source += "';\n" + evaluateValue + ";\n__p += '";
|
|---|
| 14942 | }
|
|---|
| 14943 | if (interpolateValue) {
|
|---|
| 14944 | source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
|
|---|
| 14945 | }
|
|---|
| 14946 | index = offset + match.length;
|
|---|
| 14947 |
|
|---|
| 14948 | // The JS engine embedded in Adobe products needs `match` returned in
|
|---|
| 14949 | // order to produce the correct `offset` value.
|
|---|
| 14950 | return match;
|
|---|
| 14951 | });
|
|---|
| 14952 |
|
|---|
| 14953 | source += "';\n";
|
|---|
| 14954 |
|
|---|
| 14955 | // If `variable` is not specified wrap a with-statement around the generated
|
|---|
| 14956 | // code to add the data object to the top of the scope chain.
|
|---|
| 14957 | var variable = hasOwnProperty.call(options, 'variable') && options.variable;
|
|---|
| 14958 | if (!variable) {
|
|---|
| 14959 | source = 'with (obj) {\n' + source + '\n}\n';
|
|---|
| 14960 | }
|
|---|
| 14961 | // Throw an error if a forbidden character was found in `variable`, to prevent
|
|---|
| 14962 | // potential command injection attacks.
|
|---|
| 14963 | else if (reForbiddenIdentifierChars.test(variable)) {
|
|---|
| 14964 | throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
|
|---|
| 14965 | }
|
|---|
| 14966 |
|
|---|
| 14967 | // Cleanup code by stripping empty strings.
|
|---|
| 14968 | source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
|---|
| 14969 | .replace(reEmptyStringMiddle, '$1')
|
|---|
| 14970 | .replace(reEmptyStringTrailing, '$1;');
|
|---|
| 14971 |
|
|---|
| 14972 | // Frame code as the function body.
|
|---|
| 14973 | source = 'function(' + (variable || 'obj') + ') {\n' +
|
|---|
| 14974 | (variable
|
|---|
| 14975 | ? ''
|
|---|
| 14976 | : 'obj || (obj = {});\n'
|
|---|
| 14977 | ) +
|
|---|
| 14978 | "var __t, __p = ''" +
|
|---|
| 14979 | (isEscaping
|
|---|
| 14980 | ? ', __e = _.escape'
|
|---|
| 14981 | : ''
|
|---|
| 14982 | ) +
|
|---|
| 14983 | (isEvaluating
|
|---|
| 14984 | ? ', __j = Array.prototype.join;\n' +
|
|---|
| 14985 | "function print() { __p += __j.call(arguments, '') }\n"
|
|---|
| 14986 | : ';\n'
|
|---|
| 14987 | ) +
|
|---|
| 14988 | source +
|
|---|
| 14989 | 'return __p\n}';
|
|---|
| 14990 |
|
|---|
| 14991 | var result = attempt(function() {
|
|---|
| 14992 | return Function(importsKeys, sourceURL + 'return ' + source)
|
|---|
| 14993 | .apply(undefined, importsValues);
|
|---|
| 14994 | });
|
|---|
| 14995 |
|
|---|
| 14996 | // Provide the compiled function's source by its `toString` method or
|
|---|
| 14997 | // the `source` property as a convenience for inlining compiled templates.
|
|---|
| 14998 | result.source = source;
|
|---|
| 14999 | if (isError(result)) {
|
|---|
| 15000 | throw result;
|
|---|
| 15001 | }
|
|---|
| 15002 | return result;
|
|---|
| 15003 | }
|
|---|
| 15004 |
|
|---|
| 15005 | /**
|
|---|
| 15006 | * Converts `string`, as a whole, to lower case just like
|
|---|
| 15007 | * [String#toLowerCase](https://mdn.io/toLowerCase).
|
|---|
| 15008 | *
|
|---|
| 15009 | * @static
|
|---|
| 15010 | * @memberOf _
|
|---|
| 15011 | * @since 4.0.0
|
|---|
| 15012 | * @category String
|
|---|
| 15013 | * @param {string} [string=''] The string to convert.
|
|---|
| 15014 | * @returns {string} Returns the lower cased string.
|
|---|
| 15015 | * @example
|
|---|
| 15016 | *
|
|---|
| 15017 | * _.toLower('--Foo-Bar--');
|
|---|
| 15018 | * // => '--foo-bar--'
|
|---|
| 15019 | *
|
|---|
| 15020 | * _.toLower('fooBar');
|
|---|
| 15021 | * // => 'foobar'
|
|---|
| 15022 | *
|
|---|
| 15023 | * _.toLower('__FOO_BAR__');
|
|---|
| 15024 | * // => '__foo_bar__'
|
|---|
| 15025 | */
|
|---|
| 15026 | function toLower(value) {
|
|---|
| 15027 | return toString(value).toLowerCase();
|
|---|
| 15028 | }
|
|---|
| 15029 |
|
|---|
| 15030 | /**
|
|---|
| 15031 | * Converts `string`, as a whole, to upper case just like
|
|---|
| 15032 | * [String#toUpperCase](https://mdn.io/toUpperCase).
|
|---|
| 15033 | *
|
|---|
| 15034 | * @static
|
|---|
| 15035 | * @memberOf _
|
|---|
| 15036 | * @since 4.0.0
|
|---|
| 15037 | * @category String
|
|---|
| 15038 | * @param {string} [string=''] The string to convert.
|
|---|
| 15039 | * @returns {string} Returns the upper cased string.
|
|---|
| 15040 | * @example
|
|---|
| 15041 | *
|
|---|
| 15042 | * _.toUpper('--foo-bar--');
|
|---|
| 15043 | * // => '--FOO-BAR--'
|
|---|
| 15044 | *
|
|---|
| 15045 | * _.toUpper('fooBar');
|
|---|
| 15046 | * // => 'FOOBAR'
|
|---|
| 15047 | *
|
|---|
| 15048 | * _.toUpper('__foo_bar__');
|
|---|
| 15049 | * // => '__FOO_BAR__'
|
|---|
| 15050 | */
|
|---|
| 15051 | function toUpper(value) {
|
|---|
| 15052 | return toString(value).toUpperCase();
|
|---|
| 15053 | }
|
|---|
| 15054 |
|
|---|
| 15055 | /**
|
|---|
| 15056 | * Removes leading and trailing whitespace or specified characters from `string`.
|
|---|
| 15057 | *
|
|---|
| 15058 | * @static
|
|---|
| 15059 | * @memberOf _
|
|---|
| 15060 | * @since 3.0.0
|
|---|
| 15061 | * @category String
|
|---|
| 15062 | * @param {string} [string=''] The string to trim.
|
|---|
| 15063 | * @param {string} [chars=whitespace] The characters to trim.
|
|---|
| 15064 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 15065 | * @returns {string} Returns the trimmed string.
|
|---|
| 15066 | * @example
|
|---|
| 15067 | *
|
|---|
| 15068 | * _.trim(' abc ');
|
|---|
| 15069 | * // => 'abc'
|
|---|
| 15070 | *
|
|---|
| 15071 | * _.trim('-_-abc-_-', '_-');
|
|---|
| 15072 | * // => 'abc'
|
|---|
| 15073 | *
|
|---|
| 15074 | * _.map([' foo ', ' bar '], _.trim);
|
|---|
| 15075 | * // => ['foo', 'bar']
|
|---|
| 15076 | */
|
|---|
| 15077 | function trim(string, chars, guard) {
|
|---|
| 15078 | string = toString(string);
|
|---|
| 15079 | if (string && (guard || chars === undefined)) {
|
|---|
| 15080 | return baseTrim(string);
|
|---|
| 15081 | }
|
|---|
| 15082 | if (!string || !(chars = baseToString(chars))) {
|
|---|
| 15083 | return string;
|
|---|
| 15084 | }
|
|---|
| 15085 | var strSymbols = stringToArray(string),
|
|---|
| 15086 | chrSymbols = stringToArray(chars),
|
|---|
| 15087 | start = charsStartIndex(strSymbols, chrSymbols),
|
|---|
| 15088 | end = charsEndIndex(strSymbols, chrSymbols) + 1;
|
|---|
| 15089 |
|
|---|
| 15090 | return castSlice(strSymbols, start, end).join('');
|
|---|
| 15091 | }
|
|---|
| 15092 |
|
|---|
| 15093 | /**
|
|---|
| 15094 | * Removes trailing whitespace or specified characters from `string`.
|
|---|
| 15095 | *
|
|---|
| 15096 | * @static
|
|---|
| 15097 | * @memberOf _
|
|---|
| 15098 | * @since 4.0.0
|
|---|
| 15099 | * @category String
|
|---|
| 15100 | * @param {string} [string=''] The string to trim.
|
|---|
| 15101 | * @param {string} [chars=whitespace] The characters to trim.
|
|---|
| 15102 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 15103 | * @returns {string} Returns the trimmed string.
|
|---|
| 15104 | * @example
|
|---|
| 15105 | *
|
|---|
| 15106 | * _.trimEnd(' abc ');
|
|---|
| 15107 | * // => ' abc'
|
|---|
| 15108 | *
|
|---|
| 15109 | * _.trimEnd('-_-abc-_-', '_-');
|
|---|
| 15110 | * // => '-_-abc'
|
|---|
| 15111 | */
|
|---|
| 15112 | function trimEnd(string, chars, guard) {
|
|---|
| 15113 | string = toString(string);
|
|---|
| 15114 | if (string && (guard || chars === undefined)) {
|
|---|
| 15115 | return string.slice(0, trimmedEndIndex(string) + 1);
|
|---|
| 15116 | }
|
|---|
| 15117 | if (!string || !(chars = baseToString(chars))) {
|
|---|
| 15118 | return string;
|
|---|
| 15119 | }
|
|---|
| 15120 | var strSymbols = stringToArray(string),
|
|---|
| 15121 | end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
|
|---|
| 15122 |
|
|---|
| 15123 | return castSlice(strSymbols, 0, end).join('');
|
|---|
| 15124 | }
|
|---|
| 15125 |
|
|---|
| 15126 | /**
|
|---|
| 15127 | * Removes leading whitespace or specified characters from `string`.
|
|---|
| 15128 | *
|
|---|
| 15129 | * @static
|
|---|
| 15130 | * @memberOf _
|
|---|
| 15131 | * @since 4.0.0
|
|---|
| 15132 | * @category String
|
|---|
| 15133 | * @param {string} [string=''] The string to trim.
|
|---|
| 15134 | * @param {string} [chars=whitespace] The characters to trim.
|
|---|
| 15135 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 15136 | * @returns {string} Returns the trimmed string.
|
|---|
| 15137 | * @example
|
|---|
| 15138 | *
|
|---|
| 15139 | * _.trimStart(' abc ');
|
|---|
| 15140 | * // => 'abc '
|
|---|
| 15141 | *
|
|---|
| 15142 | * _.trimStart('-_-abc-_-', '_-');
|
|---|
| 15143 | * // => 'abc-_-'
|
|---|
| 15144 | */
|
|---|
| 15145 | function trimStart(string, chars, guard) {
|
|---|
| 15146 | string = toString(string);
|
|---|
| 15147 | if (string && (guard || chars === undefined)) {
|
|---|
| 15148 | return string.replace(reTrimStart, '');
|
|---|
| 15149 | }
|
|---|
| 15150 | if (!string || !(chars = baseToString(chars))) {
|
|---|
| 15151 | return string;
|
|---|
| 15152 | }
|
|---|
| 15153 | var strSymbols = stringToArray(string),
|
|---|
| 15154 | start = charsStartIndex(strSymbols, stringToArray(chars));
|
|---|
| 15155 |
|
|---|
| 15156 | return castSlice(strSymbols, start).join('');
|
|---|
| 15157 | }
|
|---|
| 15158 |
|
|---|
| 15159 | /**
|
|---|
| 15160 | * Truncates `string` if it's longer than the given maximum string length.
|
|---|
| 15161 | * The last characters of the truncated string are replaced with the omission
|
|---|
| 15162 | * string which defaults to "...".
|
|---|
| 15163 | *
|
|---|
| 15164 | * @static
|
|---|
| 15165 | * @memberOf _
|
|---|
| 15166 | * @since 4.0.0
|
|---|
| 15167 | * @category String
|
|---|
| 15168 | * @param {string} [string=''] The string to truncate.
|
|---|
| 15169 | * @param {Object} [options={}] The options object.
|
|---|
| 15170 | * @param {number} [options.length=30] The maximum string length.
|
|---|
| 15171 | * @param {string} [options.omission='...'] The string to indicate text is omitted.
|
|---|
| 15172 | * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
|
|---|
| 15173 | * @returns {string} Returns the truncated string.
|
|---|
| 15174 | * @example
|
|---|
| 15175 | *
|
|---|
| 15176 | * _.truncate('hi-diddly-ho there, neighborino');
|
|---|
| 15177 | * // => 'hi-diddly-ho there, neighbo...'
|
|---|
| 15178 | *
|
|---|
| 15179 | * _.truncate('hi-diddly-ho there, neighborino', {
|
|---|
| 15180 | * 'length': 24,
|
|---|
| 15181 | * 'separator': ' '
|
|---|
| 15182 | * });
|
|---|
| 15183 | * // => 'hi-diddly-ho there,...'
|
|---|
| 15184 | *
|
|---|
| 15185 | * _.truncate('hi-diddly-ho there, neighborino', {
|
|---|
| 15186 | * 'length': 24,
|
|---|
| 15187 | * 'separator': /,? +/
|
|---|
| 15188 | * });
|
|---|
| 15189 | * // => 'hi-diddly-ho there...'
|
|---|
| 15190 | *
|
|---|
| 15191 | * _.truncate('hi-diddly-ho there, neighborino', {
|
|---|
| 15192 | * 'omission': ' [...]'
|
|---|
| 15193 | * });
|
|---|
| 15194 | * // => 'hi-diddly-ho there, neig [...]'
|
|---|
| 15195 | */
|
|---|
| 15196 | function truncate(string, options) {
|
|---|
| 15197 | var length = DEFAULT_TRUNC_LENGTH,
|
|---|
| 15198 | omission = DEFAULT_TRUNC_OMISSION;
|
|---|
| 15199 |
|
|---|
| 15200 | if (isObject(options)) {
|
|---|
| 15201 | var separator = 'separator' in options ? options.separator : separator;
|
|---|
| 15202 | length = 'length' in options ? toInteger(options.length) : length;
|
|---|
| 15203 | omission = 'omission' in options ? baseToString(options.omission) : omission;
|
|---|
| 15204 | }
|
|---|
| 15205 | string = toString(string);
|
|---|
| 15206 |
|
|---|
| 15207 | var strLength = string.length;
|
|---|
| 15208 | if (hasUnicode(string)) {
|
|---|
| 15209 | var strSymbols = stringToArray(string);
|
|---|
| 15210 | strLength = strSymbols.length;
|
|---|
| 15211 | }
|
|---|
| 15212 | if (length >= strLength) {
|
|---|
| 15213 | return string;
|
|---|
| 15214 | }
|
|---|
| 15215 | var end = length - stringSize(omission);
|
|---|
| 15216 | if (end < 1) {
|
|---|
| 15217 | return omission;
|
|---|
| 15218 | }
|
|---|
| 15219 | var result = strSymbols
|
|---|
| 15220 | ? castSlice(strSymbols, 0, end).join('')
|
|---|
| 15221 | : string.slice(0, end);
|
|---|
| 15222 |
|
|---|
| 15223 | if (separator === undefined) {
|
|---|
| 15224 | return result + omission;
|
|---|
| 15225 | }
|
|---|
| 15226 | if (strSymbols) {
|
|---|
| 15227 | end += (result.length - end);
|
|---|
| 15228 | }
|
|---|
| 15229 | if (isRegExp(separator)) {
|
|---|
| 15230 | if (string.slice(end).search(separator)) {
|
|---|
| 15231 | var match,
|
|---|
| 15232 | substring = result;
|
|---|
| 15233 |
|
|---|
| 15234 | if (!separator.global) {
|
|---|
| 15235 | separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
|
|---|
| 15236 | }
|
|---|
| 15237 | separator.lastIndex = 0;
|
|---|
| 15238 | while ((match = separator.exec(substring))) {
|
|---|
| 15239 | var newEnd = match.index;
|
|---|
| 15240 | }
|
|---|
| 15241 | result = result.slice(0, newEnd === undefined ? end : newEnd);
|
|---|
| 15242 | }
|
|---|
| 15243 | } else if (string.indexOf(baseToString(separator), end) != end) {
|
|---|
| 15244 | var index = result.lastIndexOf(separator);
|
|---|
| 15245 | if (index > -1) {
|
|---|
| 15246 | result = result.slice(0, index);
|
|---|
| 15247 | }
|
|---|
| 15248 | }
|
|---|
| 15249 | return result + omission;
|
|---|
| 15250 | }
|
|---|
| 15251 |
|
|---|
| 15252 | /**
|
|---|
| 15253 | * The inverse of `_.escape`; this method converts the HTML entities
|
|---|
| 15254 | * `&`, `<`, `>`, `"`, and `'` in `string` to
|
|---|
| 15255 | * their corresponding characters.
|
|---|
| 15256 | *
|
|---|
| 15257 | * **Note:** No other HTML entities are unescaped. To unescape additional
|
|---|
| 15258 | * HTML entities use a third-party library like [_he_](https://mths.be/he).
|
|---|
| 15259 | *
|
|---|
| 15260 | * @static
|
|---|
| 15261 | * @memberOf _
|
|---|
| 15262 | * @since 0.6.0
|
|---|
| 15263 | * @category String
|
|---|
| 15264 | * @param {string} [string=''] The string to unescape.
|
|---|
| 15265 | * @returns {string} Returns the unescaped string.
|
|---|
| 15266 | * @example
|
|---|
| 15267 | *
|
|---|
| 15268 | * _.unescape('fred, barney, & pebbles');
|
|---|
| 15269 | * // => 'fred, barney, & pebbles'
|
|---|
| 15270 | */
|
|---|
| 15271 | function unescape(string) {
|
|---|
| 15272 | string = toString(string);
|
|---|
| 15273 | return (string && reHasEscapedHtml.test(string))
|
|---|
| 15274 | ? string.replace(reEscapedHtml, unescapeHtmlChar)
|
|---|
| 15275 | : string;
|
|---|
| 15276 | }
|
|---|
| 15277 |
|
|---|
| 15278 | /**
|
|---|
| 15279 | * Converts `string`, as space separated words, to upper case.
|
|---|
| 15280 | *
|
|---|
| 15281 | * @static
|
|---|
| 15282 | * @memberOf _
|
|---|
| 15283 | * @since 4.0.0
|
|---|
| 15284 | * @category String
|
|---|
| 15285 | * @param {string} [string=''] The string to convert.
|
|---|
| 15286 | * @returns {string} Returns the upper cased string.
|
|---|
| 15287 | * @example
|
|---|
| 15288 | *
|
|---|
| 15289 | * _.upperCase('--foo-bar');
|
|---|
| 15290 | * // => 'FOO BAR'
|
|---|
| 15291 | *
|
|---|
| 15292 | * _.upperCase('fooBar');
|
|---|
| 15293 | * // => 'FOO BAR'
|
|---|
| 15294 | *
|
|---|
| 15295 | * _.upperCase('__foo_bar__');
|
|---|
| 15296 | * // => 'FOO BAR'
|
|---|
| 15297 | */
|
|---|
| 15298 | var upperCase = createCompounder(function(result, word, index) {
|
|---|
| 15299 | return result + (index ? ' ' : '') + word.toUpperCase();
|
|---|
| 15300 | });
|
|---|
| 15301 |
|
|---|
| 15302 | /**
|
|---|
| 15303 | * Converts the first character of `string` to upper case.
|
|---|
| 15304 | *
|
|---|
| 15305 | * @static
|
|---|
| 15306 | * @memberOf _
|
|---|
| 15307 | * @since 4.0.0
|
|---|
| 15308 | * @category String
|
|---|
| 15309 | * @param {string} [string=''] The string to convert.
|
|---|
| 15310 | * @returns {string} Returns the converted string.
|
|---|
| 15311 | * @example
|
|---|
| 15312 | *
|
|---|
| 15313 | * _.upperFirst('fred');
|
|---|
| 15314 | * // => 'Fred'
|
|---|
| 15315 | *
|
|---|
| 15316 | * _.upperFirst('FRED');
|
|---|
| 15317 | * // => 'FRED'
|
|---|
| 15318 | */
|
|---|
| 15319 | var upperFirst = createCaseFirst('toUpperCase');
|
|---|
| 15320 |
|
|---|
| 15321 | /**
|
|---|
| 15322 | * Splits `string` into an array of its words.
|
|---|
| 15323 | *
|
|---|
| 15324 | * @static
|
|---|
| 15325 | * @memberOf _
|
|---|
| 15326 | * @since 3.0.0
|
|---|
| 15327 | * @category String
|
|---|
| 15328 | * @param {string} [string=''] The string to inspect.
|
|---|
| 15329 | * @param {RegExp|string} [pattern] The pattern to match words.
|
|---|
| 15330 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
|---|
| 15331 | * @returns {Array} Returns the words of `string`.
|
|---|
| 15332 | * @example
|
|---|
| 15333 | *
|
|---|
| 15334 | * _.words('fred, barney, & pebbles');
|
|---|
| 15335 | * // => ['fred', 'barney', 'pebbles']
|
|---|
| 15336 | *
|
|---|
| 15337 | * _.words('fred, barney, & pebbles', /[^, ]+/g);
|
|---|
| 15338 | * // => ['fred', 'barney', '&', 'pebbles']
|
|---|
| 15339 | */
|
|---|
| 15340 | function words(string, pattern, guard) {
|
|---|
| 15341 | string = toString(string);
|
|---|
| 15342 | pattern = guard ? undefined : pattern;
|
|---|
| 15343 |
|
|---|
| 15344 | if (pattern === undefined) {
|
|---|
| 15345 | return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
|
|---|
| 15346 | }
|
|---|
| 15347 | return string.match(pattern) || [];
|
|---|
| 15348 | }
|
|---|
| 15349 |
|
|---|
| 15350 | /*------------------------------------------------------------------------*/
|
|---|
| 15351 |
|
|---|
| 15352 | /**
|
|---|
| 15353 | * Attempts to invoke `func`, returning either the result or the caught error
|
|---|
| 15354 | * object. Any additional arguments are provided to `func` when it's invoked.
|
|---|
| 15355 | *
|
|---|
| 15356 | * @static
|
|---|
| 15357 | * @memberOf _
|
|---|
| 15358 | * @since 3.0.0
|
|---|
| 15359 | * @category Util
|
|---|
| 15360 | * @param {Function} func The function to attempt.
|
|---|
| 15361 | * @param {...*} [args] The arguments to invoke `func` with.
|
|---|
| 15362 | * @returns {*} Returns the `func` result or error object.
|
|---|
| 15363 | * @example
|
|---|
| 15364 | *
|
|---|
| 15365 | * // Avoid throwing errors for invalid selectors.
|
|---|
| 15366 | * var elements = _.attempt(function(selector) {
|
|---|
| 15367 | * return document.querySelectorAll(selector);
|
|---|
| 15368 | * }, '>_>');
|
|---|
| 15369 | *
|
|---|
| 15370 | * if (_.isError(elements)) {
|
|---|
| 15371 | * elements = [];
|
|---|
| 15372 | * }
|
|---|
| 15373 | */
|
|---|
| 15374 | var attempt = baseRest(function(func, args) {
|
|---|
| 15375 | try {
|
|---|
| 15376 | return apply(func, undefined, args);
|
|---|
| 15377 | } catch (e) {
|
|---|
| 15378 | return isError(e) ? e : new Error(e);
|
|---|
| 15379 | }
|
|---|
| 15380 | });
|
|---|
| 15381 |
|
|---|
| 15382 | /**
|
|---|
| 15383 | * Binds methods of an object to the object itself, overwriting the existing
|
|---|
| 15384 | * method.
|
|---|
| 15385 | *
|
|---|
| 15386 | * **Note:** This method doesn't set the "length" property of bound functions.
|
|---|
| 15387 | *
|
|---|
| 15388 | * @static
|
|---|
| 15389 | * @since 0.1.0
|
|---|
| 15390 | * @memberOf _
|
|---|
| 15391 | * @category Util
|
|---|
| 15392 | * @param {Object} object The object to bind and assign the bound methods to.
|
|---|
| 15393 | * @param {...(string|string[])} methodNames The object method names to bind.
|
|---|
| 15394 | * @returns {Object} Returns `object`.
|
|---|
| 15395 | * @example
|
|---|
| 15396 | *
|
|---|
| 15397 | * var view = {
|
|---|
| 15398 | * 'label': 'docs',
|
|---|
| 15399 | * 'click': function() {
|
|---|
| 15400 | * console.log('clicked ' + this.label);
|
|---|
| 15401 | * }
|
|---|
| 15402 | * };
|
|---|
| 15403 | *
|
|---|
| 15404 | * _.bindAll(view, ['click']);
|
|---|
| 15405 | * jQuery(element).on('click', view.click);
|
|---|
| 15406 | * // => Logs 'clicked docs' when clicked.
|
|---|
| 15407 | */
|
|---|
| 15408 | var bindAll = flatRest(function(object, methodNames) {
|
|---|
| 15409 | arrayEach(methodNames, function(key) {
|
|---|
| 15410 | key = toKey(key);
|
|---|
| 15411 | baseAssignValue(object, key, bind(object[key], object));
|
|---|
| 15412 | });
|
|---|
| 15413 | return object;
|
|---|
| 15414 | });
|
|---|
| 15415 |
|
|---|
| 15416 | /**
|
|---|
| 15417 | * Creates a function that iterates over `pairs` and invokes the corresponding
|
|---|
| 15418 | * function of the first predicate to return truthy. The predicate-function
|
|---|
| 15419 | * pairs are invoked with the `this` binding and arguments of the created
|
|---|
| 15420 | * function.
|
|---|
| 15421 | *
|
|---|
| 15422 | * @static
|
|---|
| 15423 | * @memberOf _
|
|---|
| 15424 | * @since 4.0.0
|
|---|
| 15425 | * @category Util
|
|---|
| 15426 | * @param {Array} pairs The predicate-function pairs.
|
|---|
| 15427 | * @returns {Function} Returns the new composite function.
|
|---|
| 15428 | * @example
|
|---|
| 15429 | *
|
|---|
| 15430 | * var func = _.cond([
|
|---|
| 15431 | * [_.matches({ 'a': 1 }), _.constant('matches A')],
|
|---|
| 15432 | * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
|
|---|
| 15433 | * [_.stubTrue, _.constant('no match')]
|
|---|
| 15434 | * ]);
|
|---|
| 15435 | *
|
|---|
| 15436 | * func({ 'a': 1, 'b': 2 });
|
|---|
| 15437 | * // => 'matches A'
|
|---|
| 15438 | *
|
|---|
| 15439 | * func({ 'a': 0, 'b': 1 });
|
|---|
| 15440 | * // => 'matches B'
|
|---|
| 15441 | *
|
|---|
| 15442 | * func({ 'a': '1', 'b': '2' });
|
|---|
| 15443 | * // => 'no match'
|
|---|
| 15444 | */
|
|---|
| 15445 | function cond(pairs) {
|
|---|
| 15446 | var length = pairs == null ? 0 : pairs.length,
|
|---|
| 15447 | toIteratee = getIteratee();
|
|---|
| 15448 |
|
|---|
| 15449 | pairs = !length ? [] : arrayMap(pairs, function(pair) {
|
|---|
| 15450 | if (typeof pair[1] != 'function') {
|
|---|
| 15451 | throw new TypeError(FUNC_ERROR_TEXT);
|
|---|
| 15452 | }
|
|---|
| 15453 | return [toIteratee(pair[0]), pair[1]];
|
|---|
| 15454 | });
|
|---|
| 15455 |
|
|---|
| 15456 | return baseRest(function(args) {
|
|---|
| 15457 | var index = -1;
|
|---|
| 15458 | while (++index < length) {
|
|---|
| 15459 | var pair = pairs[index];
|
|---|
| 15460 | if (apply(pair[0], this, args)) {
|
|---|
| 15461 | return apply(pair[1], this, args);
|
|---|
| 15462 | }
|
|---|
| 15463 | }
|
|---|
| 15464 | });
|
|---|
| 15465 | }
|
|---|
| 15466 |
|
|---|
| 15467 | /**
|
|---|
| 15468 | * Creates a function that invokes the predicate properties of `source` with
|
|---|
| 15469 | * the corresponding property values of a given object, returning `true` if
|
|---|
| 15470 | * all predicates return truthy, else `false`.
|
|---|
| 15471 | *
|
|---|
| 15472 | * **Note:** The created function is equivalent to `_.conformsTo` with
|
|---|
| 15473 | * `source` partially applied.
|
|---|
| 15474 | *
|
|---|
| 15475 | * @static
|
|---|
| 15476 | * @memberOf _
|
|---|
| 15477 | * @since 4.0.0
|
|---|
| 15478 | * @category Util
|
|---|
| 15479 | * @param {Object} source The object of property predicates to conform to.
|
|---|
| 15480 | * @returns {Function} Returns the new spec function.
|
|---|
| 15481 | * @example
|
|---|
| 15482 | *
|
|---|
| 15483 | * var objects = [
|
|---|
| 15484 | * { 'a': 2, 'b': 1 },
|
|---|
| 15485 | * { 'a': 1, 'b': 2 }
|
|---|
| 15486 | * ];
|
|---|
| 15487 | *
|
|---|
| 15488 | * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
|
|---|
| 15489 | * // => [{ 'a': 1, 'b': 2 }]
|
|---|
| 15490 | */
|
|---|
| 15491 | function conforms(source) {
|
|---|
| 15492 | return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
|
|---|
| 15493 | }
|
|---|
| 15494 |
|
|---|
| 15495 | /**
|
|---|
| 15496 | * Creates a function that returns `value`.
|
|---|
| 15497 | *
|
|---|
| 15498 | * @static
|
|---|
| 15499 | * @memberOf _
|
|---|
| 15500 | * @since 2.4.0
|
|---|
| 15501 | * @category Util
|
|---|
| 15502 | * @param {*} value The value to return from the new function.
|
|---|
| 15503 | * @returns {Function} Returns the new constant function.
|
|---|
| 15504 | * @example
|
|---|
| 15505 | *
|
|---|
| 15506 | * var objects = _.times(2, _.constant({ 'a': 1 }));
|
|---|
| 15507 | *
|
|---|
| 15508 | * console.log(objects);
|
|---|
| 15509 | * // => [{ 'a': 1 }, { 'a': 1 }]
|
|---|
| 15510 | *
|
|---|
| 15511 | * console.log(objects[0] === objects[1]);
|
|---|
| 15512 | * // => true
|
|---|
| 15513 | */
|
|---|
| 15514 | function constant(value) {
|
|---|
| 15515 | return function() {
|
|---|
| 15516 | return value;
|
|---|
| 15517 | };
|
|---|
| 15518 | }
|
|---|
| 15519 |
|
|---|
| 15520 | /**
|
|---|
| 15521 | * Checks `value` to determine whether a default value should be returned in
|
|---|
| 15522 | * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
|
|---|
| 15523 | * or `undefined`.
|
|---|
| 15524 | *
|
|---|
| 15525 | * @static
|
|---|
| 15526 | * @memberOf _
|
|---|
| 15527 | * @since 4.14.0
|
|---|
| 15528 | * @category Util
|
|---|
| 15529 | * @param {*} value The value to check.
|
|---|
| 15530 | * @param {*} defaultValue The default value.
|
|---|
| 15531 | * @returns {*} Returns the resolved value.
|
|---|
| 15532 | * @example
|
|---|
| 15533 | *
|
|---|
| 15534 | * _.defaultTo(1, 10);
|
|---|
| 15535 | * // => 1
|
|---|
| 15536 | *
|
|---|
| 15537 | * _.defaultTo(undefined, 10);
|
|---|
| 15538 | * // => 10
|
|---|
| 15539 | */
|
|---|
| 15540 | function defaultTo(value, defaultValue) {
|
|---|
| 15541 | return (value == null || value !== value) ? defaultValue : value;
|
|---|
| 15542 | }
|
|---|
| 15543 |
|
|---|
| 15544 | /**
|
|---|
| 15545 | * Creates a function that returns the result of invoking the given functions
|
|---|
| 15546 | * with the `this` binding of the created function, where each successive
|
|---|
| 15547 | * invocation is supplied the return value of the previous.
|
|---|
| 15548 | *
|
|---|
| 15549 | * @static
|
|---|
| 15550 | * @memberOf _
|
|---|
| 15551 | * @since 3.0.0
|
|---|
| 15552 | * @category Util
|
|---|
| 15553 | * @param {...(Function|Function[])} [funcs] The functions to invoke.
|
|---|
| 15554 | * @returns {Function} Returns the new composite function.
|
|---|
| 15555 | * @see _.flowRight
|
|---|
| 15556 | * @example
|
|---|
| 15557 | *
|
|---|
| 15558 | * function square(n) {
|
|---|
| 15559 | * return n * n;
|
|---|
| 15560 | * }
|
|---|
| 15561 | *
|
|---|
| 15562 | * var addSquare = _.flow([_.add, square]);
|
|---|
| 15563 | * addSquare(1, 2);
|
|---|
| 15564 | * // => 9
|
|---|
| 15565 | */
|
|---|
| 15566 | var flow = createFlow();
|
|---|
| 15567 |
|
|---|
| 15568 | /**
|
|---|
| 15569 | * This method is like `_.flow` except that it creates a function that
|
|---|
| 15570 | * invokes the given functions from right to left.
|
|---|
| 15571 | *
|
|---|
| 15572 | * @static
|
|---|
| 15573 | * @since 3.0.0
|
|---|
| 15574 | * @memberOf _
|
|---|
| 15575 | * @category Util
|
|---|
| 15576 | * @param {...(Function|Function[])} [funcs] The functions to invoke.
|
|---|
| 15577 | * @returns {Function} Returns the new composite function.
|
|---|
| 15578 | * @see _.flow
|
|---|
| 15579 | * @example
|
|---|
| 15580 | *
|
|---|
| 15581 | * function square(n) {
|
|---|
| 15582 | * return n * n;
|
|---|
| 15583 | * }
|
|---|
| 15584 | *
|
|---|
| 15585 | * var addSquare = _.flowRight([square, _.add]);
|
|---|
| 15586 | * addSquare(1, 2);
|
|---|
| 15587 | * // => 9
|
|---|
| 15588 | */
|
|---|
| 15589 | var flowRight = createFlow(true);
|
|---|
| 15590 |
|
|---|
| 15591 | /**
|
|---|
| 15592 | * This method returns the first argument it receives.
|
|---|
| 15593 | *
|
|---|
| 15594 | * @static
|
|---|
| 15595 | * @since 0.1.0
|
|---|
| 15596 | * @memberOf _
|
|---|
| 15597 | * @category Util
|
|---|
| 15598 | * @param {*} value Any value.
|
|---|
| 15599 | * @returns {*} Returns `value`.
|
|---|
| 15600 | * @example
|
|---|
| 15601 | *
|
|---|
| 15602 | * var object = { 'a': 1 };
|
|---|
| 15603 | *
|
|---|
| 15604 | * console.log(_.identity(object) === object);
|
|---|
| 15605 | * // => true
|
|---|
| 15606 | */
|
|---|
| 15607 | function identity(value) {
|
|---|
| 15608 | return value;
|
|---|
| 15609 | }
|
|---|
| 15610 |
|
|---|
| 15611 | /**
|
|---|
| 15612 | * Creates a function that invokes `func` with the arguments of the created
|
|---|
| 15613 | * function. If `func` is a property name, the created function returns the
|
|---|
| 15614 | * property value for a given element. If `func` is an array or object, the
|
|---|
| 15615 | * created function returns `true` for elements that contain the equivalent
|
|---|
| 15616 | * source properties, otherwise it returns `false`.
|
|---|
| 15617 | *
|
|---|
| 15618 | * @static
|
|---|
| 15619 | * @since 4.0.0
|
|---|
| 15620 | * @memberOf _
|
|---|
| 15621 | * @category Util
|
|---|
| 15622 | * @param {*} [func=_.identity] The value to convert to a callback.
|
|---|
| 15623 | * @returns {Function} Returns the callback.
|
|---|
| 15624 | * @example
|
|---|
| 15625 | *
|
|---|
| 15626 | * var users = [
|
|---|
| 15627 | * { 'user': 'barney', 'age': 36, 'active': true },
|
|---|
| 15628 | * { 'user': 'fred', 'age': 40, 'active': false }
|
|---|
| 15629 | * ];
|
|---|
| 15630 | *
|
|---|
| 15631 | * // The `_.matches` iteratee shorthand.
|
|---|
| 15632 | * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
|
|---|
| 15633 | * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
|
|---|
| 15634 | *
|
|---|
| 15635 | * // The `_.matchesProperty` iteratee shorthand.
|
|---|
| 15636 | * _.filter(users, _.iteratee(['user', 'fred']));
|
|---|
| 15637 | * // => [{ 'user': 'fred', 'age': 40 }]
|
|---|
| 15638 | *
|
|---|
| 15639 | * // The `_.property` iteratee shorthand.
|
|---|
| 15640 | * _.map(users, _.iteratee('user'));
|
|---|
| 15641 | * // => ['barney', 'fred']
|
|---|
| 15642 | *
|
|---|
| 15643 | * // Create custom iteratee shorthands.
|
|---|
| 15644 | * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
|
|---|
| 15645 | * return !_.isRegExp(func) ? iteratee(func) : function(string) {
|
|---|
| 15646 | * return func.test(string);
|
|---|
| 15647 | * };
|
|---|
| 15648 | * });
|
|---|
| 15649 | *
|
|---|
| 15650 | * _.filter(['abc', 'def'], /ef/);
|
|---|
| 15651 | * // => ['def']
|
|---|
| 15652 | */
|
|---|
| 15653 | function iteratee(func) {
|
|---|
| 15654 | return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
|
|---|
| 15655 | }
|
|---|
| 15656 |
|
|---|
| 15657 | /**
|
|---|
| 15658 | * Creates a function that performs a partial deep comparison between a given
|
|---|
| 15659 | * object and `source`, returning `true` if the given object has equivalent
|
|---|
| 15660 | * property values, else `false`.
|
|---|
| 15661 | *
|
|---|
| 15662 | * **Note:** The created function is equivalent to `_.isMatch` with `source`
|
|---|
| 15663 | * partially applied.
|
|---|
| 15664 | *
|
|---|
| 15665 | * Partial comparisons will match empty array and empty object `source`
|
|---|
| 15666 | * values against any array or object value, respectively. See `_.isEqual`
|
|---|
| 15667 | * for a list of supported value comparisons.
|
|---|
| 15668 | *
|
|---|
| 15669 | * **Note:** Multiple values can be checked by combining several matchers
|
|---|
| 15670 | * using `_.overSome`
|
|---|
| 15671 | *
|
|---|
| 15672 | * @static
|
|---|
| 15673 | * @memberOf _
|
|---|
| 15674 | * @since 3.0.0
|
|---|
| 15675 | * @category Util
|
|---|
| 15676 | * @param {Object} source The object of property values to match.
|
|---|
| 15677 | * @returns {Function} Returns the new spec function.
|
|---|
| 15678 | * @example
|
|---|
| 15679 | *
|
|---|
| 15680 | * var objects = [
|
|---|
| 15681 | * { 'a': 1, 'b': 2, 'c': 3 },
|
|---|
| 15682 | * { 'a': 4, 'b': 5, 'c': 6 }
|
|---|
| 15683 | * ];
|
|---|
| 15684 | *
|
|---|
| 15685 | * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
|
|---|
| 15686 | * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
|
|---|
| 15687 | *
|
|---|
| 15688 | * // Checking for several possible values
|
|---|
| 15689 | * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
|
|---|
| 15690 | * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
|
|---|
| 15691 | */
|
|---|
| 15692 | function matches(source) {
|
|---|
| 15693 | return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
|
|---|
| 15694 | }
|
|---|
| 15695 |
|
|---|
| 15696 | /**
|
|---|
| 15697 | * Creates a function that performs a partial deep comparison between the
|
|---|
| 15698 | * value at `path` of a given object to `srcValue`, returning `true` if the
|
|---|
| 15699 | * object value is equivalent, else `false`.
|
|---|
| 15700 | *
|
|---|
| 15701 | * **Note:** Partial comparisons will match empty array and empty object
|
|---|
| 15702 | * `srcValue` values against any array or object value, respectively. See
|
|---|
| 15703 | * `_.isEqual` for a list of supported value comparisons.
|
|---|
| 15704 | *
|
|---|
| 15705 | * **Note:** Multiple values can be checked by combining several matchers
|
|---|
| 15706 | * using `_.overSome`
|
|---|
| 15707 | *
|
|---|
| 15708 | * @static
|
|---|
| 15709 | * @memberOf _
|
|---|
| 15710 | * @since 3.2.0
|
|---|
| 15711 | * @category Util
|
|---|
| 15712 | * @param {Array|string} path The path of the property to get.
|
|---|
| 15713 | * @param {*} srcValue The value to match.
|
|---|
| 15714 | * @returns {Function} Returns the new spec function.
|
|---|
| 15715 | * @example
|
|---|
| 15716 | *
|
|---|
| 15717 | * var objects = [
|
|---|
| 15718 | * { 'a': 1, 'b': 2, 'c': 3 },
|
|---|
| 15719 | * { 'a': 4, 'b': 5, 'c': 6 }
|
|---|
| 15720 | * ];
|
|---|
| 15721 | *
|
|---|
| 15722 | * _.find(objects, _.matchesProperty('a', 4));
|
|---|
| 15723 | * // => { 'a': 4, 'b': 5, 'c': 6 }
|
|---|
| 15724 | *
|
|---|
| 15725 | * // Checking for several possible values
|
|---|
| 15726 | * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
|
|---|
| 15727 | * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
|
|---|
| 15728 | */
|
|---|
| 15729 | function matchesProperty(path, srcValue) {
|
|---|
| 15730 | return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
|
|---|
| 15731 | }
|
|---|
| 15732 |
|
|---|
| 15733 | /**
|
|---|
| 15734 | * Creates a function that invokes the method at `path` of a given object.
|
|---|
| 15735 | * Any additional arguments are provided to the invoked method.
|
|---|
| 15736 | *
|
|---|
| 15737 | * @static
|
|---|
| 15738 | * @memberOf _
|
|---|
| 15739 | * @since 3.7.0
|
|---|
| 15740 | * @category Util
|
|---|
| 15741 | * @param {Array|string} path The path of the method to invoke.
|
|---|
| 15742 | * @param {...*} [args] The arguments to invoke the method with.
|
|---|
| 15743 | * @returns {Function} Returns the new invoker function.
|
|---|
| 15744 | * @example
|
|---|
| 15745 | *
|
|---|
| 15746 | * var objects = [
|
|---|
| 15747 | * { 'a': { 'b': _.constant(2) } },
|
|---|
| 15748 | * { 'a': { 'b': _.constant(1) } }
|
|---|
| 15749 | * ];
|
|---|
| 15750 | *
|
|---|
| 15751 | * _.map(objects, _.method('a.b'));
|
|---|
| 15752 | * // => [2, 1]
|
|---|
| 15753 | *
|
|---|
| 15754 | * _.map(objects, _.method(['a', 'b']));
|
|---|
| 15755 | * // => [2, 1]
|
|---|
| 15756 | */
|
|---|
| 15757 | var method = baseRest(function(path, args) {
|
|---|
| 15758 | return function(object) {
|
|---|
| 15759 | return baseInvoke(object, path, args);
|
|---|
| 15760 | };
|
|---|
| 15761 | });
|
|---|
| 15762 |
|
|---|
| 15763 | /**
|
|---|
| 15764 | * The opposite of `_.method`; this method creates a function that invokes
|
|---|
| 15765 | * the method at a given path of `object`. Any additional arguments are
|
|---|
| 15766 | * provided to the invoked method.
|
|---|
| 15767 | *
|
|---|
| 15768 | * @static
|
|---|
| 15769 | * @memberOf _
|
|---|
| 15770 | * @since 3.7.0
|
|---|
| 15771 | * @category Util
|
|---|
| 15772 | * @param {Object} object The object to query.
|
|---|
| 15773 | * @param {...*} [args] The arguments to invoke the method with.
|
|---|
| 15774 | * @returns {Function} Returns the new invoker function.
|
|---|
| 15775 | * @example
|
|---|
| 15776 | *
|
|---|
| 15777 | * var array = _.times(3, _.constant),
|
|---|
| 15778 | * object = { 'a': array, 'b': array, 'c': array };
|
|---|
| 15779 | *
|
|---|
| 15780 | * _.map(['a[2]', 'c[0]'], _.methodOf(object));
|
|---|
| 15781 | * // => [2, 0]
|
|---|
| 15782 | *
|
|---|
| 15783 | * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
|
|---|
| 15784 | * // => [2, 0]
|
|---|
| 15785 | */
|
|---|
| 15786 | var methodOf = baseRest(function(object, args) {
|
|---|
| 15787 | return function(path) {
|
|---|
| 15788 | return baseInvoke(object, path, args);
|
|---|
| 15789 | };
|
|---|
| 15790 | });
|
|---|
| 15791 |
|
|---|
| 15792 | /**
|
|---|
| 15793 | * Adds all own enumerable string keyed function properties of a source
|
|---|
| 15794 | * object to the destination object. If `object` is a function, then methods
|
|---|
| 15795 | * are added to its prototype as well.
|
|---|
| 15796 | *
|
|---|
| 15797 | * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
|
|---|
| 15798 | * avoid conflicts caused by modifying the original.
|
|---|
| 15799 | *
|
|---|
| 15800 | * @static
|
|---|
| 15801 | * @since 0.1.0
|
|---|
| 15802 | * @memberOf _
|
|---|
| 15803 | * @category Util
|
|---|
| 15804 | * @param {Function|Object} [object=lodash] The destination object.
|
|---|
| 15805 | * @param {Object} source The object of functions to add.
|
|---|
| 15806 | * @param {Object} [options={}] The options object.
|
|---|
| 15807 | * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
|
|---|
| 15808 | * @returns {Function|Object} Returns `object`.
|
|---|
| 15809 | * @example
|
|---|
| 15810 | *
|
|---|
| 15811 | * function vowels(string) {
|
|---|
| 15812 | * return _.filter(string, function(v) {
|
|---|
| 15813 | * return /[aeiou]/i.test(v);
|
|---|
| 15814 | * });
|
|---|
| 15815 | * }
|
|---|
| 15816 | *
|
|---|
| 15817 | * _.mixin({ 'vowels': vowels });
|
|---|
| 15818 | * _.vowels('fred');
|
|---|
| 15819 | * // => ['e']
|
|---|
| 15820 | *
|
|---|
| 15821 | * _('fred').vowels().value();
|
|---|
| 15822 | * // => ['e']
|
|---|
| 15823 | *
|
|---|
| 15824 | * _.mixin({ 'vowels': vowels }, { 'chain': false });
|
|---|
| 15825 | * _('fred').vowels();
|
|---|
| 15826 | * // => ['e']
|
|---|
| 15827 | */
|
|---|
| 15828 | function mixin(object, source, options) {
|
|---|
| 15829 | var props = keys(source),
|
|---|
| 15830 | methodNames = baseFunctions(source, props);
|
|---|
| 15831 |
|
|---|
| 15832 | if (options == null &&
|
|---|
| 15833 | !(isObject(source) && (methodNames.length || !props.length))) {
|
|---|
| 15834 | options = source;
|
|---|
| 15835 | source = object;
|
|---|
| 15836 | object = this;
|
|---|
| 15837 | methodNames = baseFunctions(source, keys(source));
|
|---|
| 15838 | }
|
|---|
| 15839 | var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
|
|---|
| 15840 | isFunc = isFunction(object);
|
|---|
| 15841 |
|
|---|
| 15842 | arrayEach(methodNames, function(methodName) {
|
|---|
| 15843 | var func = source[methodName];
|
|---|
| 15844 | object[methodName] = func;
|
|---|
| 15845 | if (isFunc) {
|
|---|
| 15846 | object.prototype[methodName] = function() {
|
|---|
| 15847 | var chainAll = this.__chain__;
|
|---|
| 15848 | if (chain || chainAll) {
|
|---|
| 15849 | var result = object(this.__wrapped__),
|
|---|
| 15850 | actions = result.__actions__ = copyArray(this.__actions__);
|
|---|
| 15851 |
|
|---|
| 15852 | actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
|---|
| 15853 | result.__chain__ = chainAll;
|
|---|
| 15854 | return result;
|
|---|
| 15855 | }
|
|---|
| 15856 | return func.apply(object, arrayPush([this.value()], arguments));
|
|---|
| 15857 | };
|
|---|
| 15858 | }
|
|---|
| 15859 | });
|
|---|
| 15860 |
|
|---|
| 15861 | return object;
|
|---|
| 15862 | }
|
|---|
| 15863 |
|
|---|
| 15864 | /**
|
|---|
| 15865 | * Reverts the `_` variable to its previous value and returns a reference to
|
|---|
| 15866 | * the `lodash` function.
|
|---|
| 15867 | *
|
|---|
| 15868 | * @static
|
|---|
| 15869 | * @since 0.1.0
|
|---|
| 15870 | * @memberOf _
|
|---|
| 15871 | * @category Util
|
|---|
| 15872 | * @returns {Function} Returns the `lodash` function.
|
|---|
| 15873 | * @example
|
|---|
| 15874 | *
|
|---|
| 15875 | * var lodash = _.noConflict();
|
|---|
| 15876 | */
|
|---|
| 15877 | function noConflict() {
|
|---|
| 15878 | if (root._ === this) {
|
|---|
| 15879 | root._ = oldDash;
|
|---|
| 15880 | }
|
|---|
| 15881 | return this;
|
|---|
| 15882 | }
|
|---|
| 15883 |
|
|---|
| 15884 | /**
|
|---|
| 15885 | * This method returns `undefined`.
|
|---|
| 15886 | *
|
|---|
| 15887 | * @static
|
|---|
| 15888 | * @memberOf _
|
|---|
| 15889 | * @since 2.3.0
|
|---|
| 15890 | * @category Util
|
|---|
| 15891 | * @example
|
|---|
| 15892 | *
|
|---|
| 15893 | * _.times(2, _.noop);
|
|---|
| 15894 | * // => [undefined, undefined]
|
|---|
| 15895 | */
|
|---|
| 15896 | function noop() {
|
|---|
| 15897 | // No operation performed.
|
|---|
| 15898 | }
|
|---|
| 15899 |
|
|---|
| 15900 | /**
|
|---|
| 15901 | * Creates a function that gets the argument at index `n`. If `n` is negative,
|
|---|
| 15902 | * the nth argument from the end is returned.
|
|---|
| 15903 | *
|
|---|
| 15904 | * @static
|
|---|
| 15905 | * @memberOf _
|
|---|
| 15906 | * @since 4.0.0
|
|---|
| 15907 | * @category Util
|
|---|
| 15908 | * @param {number} [n=0] The index of the argument to return.
|
|---|
| 15909 | * @returns {Function} Returns the new pass-thru function.
|
|---|
| 15910 | * @example
|
|---|
| 15911 | *
|
|---|
| 15912 | * var func = _.nthArg(1);
|
|---|
| 15913 | * func('a', 'b', 'c', 'd');
|
|---|
| 15914 | * // => 'b'
|
|---|
| 15915 | *
|
|---|
| 15916 | * var func = _.nthArg(-2);
|
|---|
| 15917 | * func('a', 'b', 'c', 'd');
|
|---|
| 15918 | * // => 'c'
|
|---|
| 15919 | */
|
|---|
| 15920 | function nthArg(n) {
|
|---|
| 15921 | n = toInteger(n);
|
|---|
| 15922 | return baseRest(function(args) {
|
|---|
| 15923 | return baseNth(args, n);
|
|---|
| 15924 | });
|
|---|
| 15925 | }
|
|---|
| 15926 |
|
|---|
| 15927 | /**
|
|---|
| 15928 | * Creates a function that invokes `iteratees` with the arguments it receives
|
|---|
| 15929 | * and returns their results.
|
|---|
| 15930 | *
|
|---|
| 15931 | * @static
|
|---|
| 15932 | * @memberOf _
|
|---|
| 15933 | * @since 4.0.0
|
|---|
| 15934 | * @category Util
|
|---|
| 15935 | * @param {...(Function|Function[])} [iteratees=[_.identity]]
|
|---|
| 15936 | * The iteratees to invoke.
|
|---|
| 15937 | * @returns {Function} Returns the new function.
|
|---|
| 15938 | * @example
|
|---|
| 15939 | *
|
|---|
| 15940 | * var func = _.over([Math.max, Math.min]);
|
|---|
| 15941 | *
|
|---|
| 15942 | * func(1, 2, 3, 4);
|
|---|
| 15943 | * // => [4, 1]
|
|---|
| 15944 | */
|
|---|
| 15945 | var over = createOver(arrayMap);
|
|---|
| 15946 |
|
|---|
| 15947 | /**
|
|---|
| 15948 | * Creates a function that checks if **all** of the `predicates` return
|
|---|
| 15949 | * truthy when invoked with the arguments it receives.
|
|---|
| 15950 | *
|
|---|
| 15951 | * Following shorthands are possible for providing predicates.
|
|---|
| 15952 | * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
|
|---|
| 15953 | * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
|
|---|
| 15954 | *
|
|---|
| 15955 | * @static
|
|---|
| 15956 | * @memberOf _
|
|---|
| 15957 | * @since 4.0.0
|
|---|
| 15958 | * @category Util
|
|---|
| 15959 | * @param {...(Function|Function[])} [predicates=[_.identity]]
|
|---|
| 15960 | * The predicates to check.
|
|---|
| 15961 | * @returns {Function} Returns the new function.
|
|---|
| 15962 | * @example
|
|---|
| 15963 | *
|
|---|
| 15964 | * var func = _.overEvery([Boolean, isFinite]);
|
|---|
| 15965 | *
|
|---|
| 15966 | * func('1');
|
|---|
| 15967 | * // => true
|
|---|
| 15968 | *
|
|---|
| 15969 | * func(null);
|
|---|
| 15970 | * // => false
|
|---|
| 15971 | *
|
|---|
| 15972 | * func(NaN);
|
|---|
| 15973 | * // => false
|
|---|
| 15974 | */
|
|---|
| 15975 | var overEvery = createOver(arrayEvery);
|
|---|
| 15976 |
|
|---|
| 15977 | /**
|
|---|
| 15978 | * Creates a function that checks if **any** of the `predicates` return
|
|---|
| 15979 | * truthy when invoked with the arguments it receives.
|
|---|
| 15980 | *
|
|---|
| 15981 | * Following shorthands are possible for providing predicates.
|
|---|
| 15982 | * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
|
|---|
| 15983 | * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
|
|---|
| 15984 | *
|
|---|
| 15985 | * @static
|
|---|
| 15986 | * @memberOf _
|
|---|
| 15987 | * @since 4.0.0
|
|---|
| 15988 | * @category Util
|
|---|
| 15989 | * @param {...(Function|Function[])} [predicates=[_.identity]]
|
|---|
| 15990 | * The predicates to check.
|
|---|
| 15991 | * @returns {Function} Returns the new function.
|
|---|
| 15992 | * @example
|
|---|
| 15993 | *
|
|---|
| 15994 | * var func = _.overSome([Boolean, isFinite]);
|
|---|
| 15995 | *
|
|---|
| 15996 | * func('1');
|
|---|
| 15997 | * // => true
|
|---|
| 15998 | *
|
|---|
| 15999 | * func(null);
|
|---|
| 16000 | * // => true
|
|---|
| 16001 | *
|
|---|
| 16002 | * func(NaN);
|
|---|
| 16003 | * // => false
|
|---|
| 16004 | *
|
|---|
| 16005 | * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
|
|---|
| 16006 | * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
|
|---|
| 16007 | */
|
|---|
| 16008 | var overSome = createOver(arraySome);
|
|---|
| 16009 |
|
|---|
| 16010 | /**
|
|---|
| 16011 | * Creates a function that returns the value at `path` of a given object.
|
|---|
| 16012 | *
|
|---|
| 16013 | * @static
|
|---|
| 16014 | * @memberOf _
|
|---|
| 16015 | * @since 2.4.0
|
|---|
| 16016 | * @category Util
|
|---|
| 16017 | * @param {Array|string} path The path of the property to get.
|
|---|
| 16018 | * @returns {Function} Returns the new accessor function.
|
|---|
| 16019 | * @example
|
|---|
| 16020 | *
|
|---|
| 16021 | * var objects = [
|
|---|
| 16022 | * { 'a': { 'b': 2 } },
|
|---|
| 16023 | * { 'a': { 'b': 1 } }
|
|---|
| 16024 | * ];
|
|---|
| 16025 | *
|
|---|
| 16026 | * _.map(objects, _.property('a.b'));
|
|---|
| 16027 | * // => [2, 1]
|
|---|
| 16028 | *
|
|---|
| 16029 | * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
|
|---|
| 16030 | * // => [1, 2]
|
|---|
| 16031 | */
|
|---|
| 16032 | function property(path) {
|
|---|
| 16033 | return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
|
|---|
| 16034 | }
|
|---|
| 16035 |
|
|---|
| 16036 | /**
|
|---|
| 16037 | * The opposite of `_.property`; this method creates a function that returns
|
|---|
| 16038 | * the value at a given path of `object`.
|
|---|
| 16039 | *
|
|---|
| 16040 | * @static
|
|---|
| 16041 | * @memberOf _
|
|---|
| 16042 | * @since 3.0.0
|
|---|
| 16043 | * @category Util
|
|---|
| 16044 | * @param {Object} object The object to query.
|
|---|
| 16045 | * @returns {Function} Returns the new accessor function.
|
|---|
| 16046 | * @example
|
|---|
| 16047 | *
|
|---|
| 16048 | * var array = [0, 1, 2],
|
|---|
| 16049 | * object = { 'a': array, 'b': array, 'c': array };
|
|---|
| 16050 | *
|
|---|
| 16051 | * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
|
|---|
| 16052 | * // => [2, 0]
|
|---|
| 16053 | *
|
|---|
| 16054 | * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
|
|---|
| 16055 | * // => [2, 0]
|
|---|
| 16056 | */
|
|---|
| 16057 | function propertyOf(object) {
|
|---|
| 16058 | return function(path) {
|
|---|
| 16059 | return object == null ? undefined : baseGet(object, path);
|
|---|
| 16060 | };
|
|---|
| 16061 | }
|
|---|
| 16062 |
|
|---|
| 16063 | /**
|
|---|
| 16064 | * Creates an array of numbers (positive and/or negative) progressing from
|
|---|
| 16065 | * `start` up to, but not including, `end`. A step of `-1` is used if a negative
|
|---|
| 16066 | * `start` is specified without an `end` or `step`. If `end` is not specified,
|
|---|
| 16067 | * it's set to `start` with `start` then set to `0`.
|
|---|
| 16068 | *
|
|---|
| 16069 | * **Note:** JavaScript follows the IEEE-754 standard for resolving
|
|---|
| 16070 | * floating-point values which can produce unexpected results.
|
|---|
| 16071 | *
|
|---|
| 16072 | * @static
|
|---|
| 16073 | * @since 0.1.0
|
|---|
| 16074 | * @memberOf _
|
|---|
| 16075 | * @category Util
|
|---|
| 16076 | * @param {number} [start=0] The start of the range.
|
|---|
| 16077 | * @param {number} end The end of the range.
|
|---|
| 16078 | * @param {number} [step=1] The value to increment or decrement by.
|
|---|
| 16079 | * @returns {Array} Returns the range of numbers.
|
|---|
| 16080 | * @see _.inRange, _.rangeRight
|
|---|
| 16081 | * @example
|
|---|
| 16082 | *
|
|---|
| 16083 | * _.range(4);
|
|---|
| 16084 | * // => [0, 1, 2, 3]
|
|---|
| 16085 | *
|
|---|
| 16086 | * _.range(-4);
|
|---|
| 16087 | * // => [0, -1, -2, -3]
|
|---|
| 16088 | *
|
|---|
| 16089 | * _.range(1, 5);
|
|---|
| 16090 | * // => [1, 2, 3, 4]
|
|---|
| 16091 | *
|
|---|
| 16092 | * _.range(0, 20, 5);
|
|---|
| 16093 | * // => [0, 5, 10, 15]
|
|---|
| 16094 | *
|
|---|
| 16095 | * _.range(0, -4, -1);
|
|---|
| 16096 | * // => [0, -1, -2, -3]
|
|---|
| 16097 | *
|
|---|
| 16098 | * _.range(1, 4, 0);
|
|---|
| 16099 | * // => [1, 1, 1]
|
|---|
| 16100 | *
|
|---|
| 16101 | * _.range(0);
|
|---|
| 16102 | * // => []
|
|---|
| 16103 | */
|
|---|
| 16104 | var range = createRange();
|
|---|
| 16105 |
|
|---|
| 16106 | /**
|
|---|
| 16107 | * This method is like `_.range` except that it populates values in
|
|---|
| 16108 | * descending order.
|
|---|
| 16109 | *
|
|---|
| 16110 | * @static
|
|---|
| 16111 | * @memberOf _
|
|---|
| 16112 | * @since 4.0.0
|
|---|
| 16113 | * @category Util
|
|---|
| 16114 | * @param {number} [start=0] The start of the range.
|
|---|
| 16115 | * @param {number} end The end of the range.
|
|---|
| 16116 | * @param {number} [step=1] The value to increment or decrement by.
|
|---|
| 16117 | * @returns {Array} Returns the range of numbers.
|
|---|
| 16118 | * @see _.inRange, _.range
|
|---|
| 16119 | * @example
|
|---|
| 16120 | *
|
|---|
| 16121 | * _.rangeRight(4);
|
|---|
| 16122 | * // => [3, 2, 1, 0]
|
|---|
| 16123 | *
|
|---|
| 16124 | * _.rangeRight(-4);
|
|---|
| 16125 | * // => [-3, -2, -1, 0]
|
|---|
| 16126 | *
|
|---|
| 16127 | * _.rangeRight(1, 5);
|
|---|
| 16128 | * // => [4, 3, 2, 1]
|
|---|
| 16129 | *
|
|---|
| 16130 | * _.rangeRight(0, 20, 5);
|
|---|
| 16131 | * // => [15, 10, 5, 0]
|
|---|
| 16132 | *
|
|---|
| 16133 | * _.rangeRight(0, -4, -1);
|
|---|
| 16134 | * // => [-3, -2, -1, 0]
|
|---|
| 16135 | *
|
|---|
| 16136 | * _.rangeRight(1, 4, 0);
|
|---|
| 16137 | * // => [1, 1, 1]
|
|---|
| 16138 | *
|
|---|
| 16139 | * _.rangeRight(0);
|
|---|
| 16140 | * // => []
|
|---|
| 16141 | */
|
|---|
| 16142 | var rangeRight = createRange(true);
|
|---|
| 16143 |
|
|---|
| 16144 | /**
|
|---|
| 16145 | * This method returns a new empty array.
|
|---|
| 16146 | *
|
|---|
| 16147 | * @static
|
|---|
| 16148 | * @memberOf _
|
|---|
| 16149 | * @since 4.13.0
|
|---|
| 16150 | * @category Util
|
|---|
| 16151 | * @returns {Array} Returns the new empty array.
|
|---|
| 16152 | * @example
|
|---|
| 16153 | *
|
|---|
| 16154 | * var arrays = _.times(2, _.stubArray);
|
|---|
| 16155 | *
|
|---|
| 16156 | * console.log(arrays);
|
|---|
| 16157 | * // => [[], []]
|
|---|
| 16158 | *
|
|---|
| 16159 | * console.log(arrays[0] === arrays[1]);
|
|---|
| 16160 | * // => false
|
|---|
| 16161 | */
|
|---|
| 16162 | function stubArray() {
|
|---|
| 16163 | return [];
|
|---|
| 16164 | }
|
|---|
| 16165 |
|
|---|
| 16166 | /**
|
|---|
| 16167 | * This method returns `false`.
|
|---|
| 16168 | *
|
|---|
| 16169 | * @static
|
|---|
| 16170 | * @memberOf _
|
|---|
| 16171 | * @since 4.13.0
|
|---|
| 16172 | * @category Util
|
|---|
| 16173 | * @returns {boolean} Returns `false`.
|
|---|
| 16174 | * @example
|
|---|
| 16175 | *
|
|---|
| 16176 | * _.times(2, _.stubFalse);
|
|---|
| 16177 | * // => [false, false]
|
|---|
| 16178 | */
|
|---|
| 16179 | function stubFalse() {
|
|---|
| 16180 | return false;
|
|---|
| 16181 | }
|
|---|
| 16182 |
|
|---|
| 16183 | /**
|
|---|
| 16184 | * This method returns a new empty object.
|
|---|
| 16185 | *
|
|---|
| 16186 | * @static
|
|---|
| 16187 | * @memberOf _
|
|---|
| 16188 | * @since 4.13.0
|
|---|
| 16189 | * @category Util
|
|---|
| 16190 | * @returns {Object} Returns the new empty object.
|
|---|
| 16191 | * @example
|
|---|
| 16192 | *
|
|---|
| 16193 | * var objects = _.times(2, _.stubObject);
|
|---|
| 16194 | *
|
|---|
| 16195 | * console.log(objects);
|
|---|
| 16196 | * // => [{}, {}]
|
|---|
| 16197 | *
|
|---|
| 16198 | * console.log(objects[0] === objects[1]);
|
|---|
| 16199 | * // => false
|
|---|
| 16200 | */
|
|---|
| 16201 | function stubObject() {
|
|---|
| 16202 | return {};
|
|---|
| 16203 | }
|
|---|
| 16204 |
|
|---|
| 16205 | /**
|
|---|
| 16206 | * This method returns an empty string.
|
|---|
| 16207 | *
|
|---|
| 16208 | * @static
|
|---|
| 16209 | * @memberOf _
|
|---|
| 16210 | * @since 4.13.0
|
|---|
| 16211 | * @category Util
|
|---|
| 16212 | * @returns {string} Returns the empty string.
|
|---|
| 16213 | * @example
|
|---|
| 16214 | *
|
|---|
| 16215 | * _.times(2, _.stubString);
|
|---|
| 16216 | * // => ['', '']
|
|---|
| 16217 | */
|
|---|
| 16218 | function stubString() {
|
|---|
| 16219 | return '';
|
|---|
| 16220 | }
|
|---|
| 16221 |
|
|---|
| 16222 | /**
|
|---|
| 16223 | * This method returns `true`.
|
|---|
| 16224 | *
|
|---|
| 16225 | * @static
|
|---|
| 16226 | * @memberOf _
|
|---|
| 16227 | * @since 4.13.0
|
|---|
| 16228 | * @category Util
|
|---|
| 16229 | * @returns {boolean} Returns `true`.
|
|---|
| 16230 | * @example
|
|---|
| 16231 | *
|
|---|
| 16232 | * _.times(2, _.stubTrue);
|
|---|
| 16233 | * // => [true, true]
|
|---|
| 16234 | */
|
|---|
| 16235 | function stubTrue() {
|
|---|
| 16236 | return true;
|
|---|
| 16237 | }
|
|---|
| 16238 |
|
|---|
| 16239 | /**
|
|---|
| 16240 | * Invokes the iteratee `n` times, returning an array of the results of
|
|---|
| 16241 | * each invocation. The iteratee is invoked with one argument; (index).
|
|---|
| 16242 | *
|
|---|
| 16243 | * @static
|
|---|
| 16244 | * @since 0.1.0
|
|---|
| 16245 | * @memberOf _
|
|---|
| 16246 | * @category Util
|
|---|
| 16247 | * @param {number} n The number of times to invoke `iteratee`.
|
|---|
| 16248 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
|---|
| 16249 | * @returns {Array} Returns the array of results.
|
|---|
| 16250 | * @example
|
|---|
| 16251 | *
|
|---|
| 16252 | * _.times(3, String);
|
|---|
| 16253 | * // => ['0', '1', '2']
|
|---|
| 16254 | *
|
|---|
| 16255 | * _.times(4, _.constant(0));
|
|---|
| 16256 | * // => [0, 0, 0, 0]
|
|---|
| 16257 | */
|
|---|
| 16258 | function times(n, iteratee) {
|
|---|
| 16259 | n = toInteger(n);
|
|---|
| 16260 | if (n < 1 || n > MAX_SAFE_INTEGER) {
|
|---|
| 16261 | return [];
|
|---|
| 16262 | }
|
|---|
| 16263 | var index = MAX_ARRAY_LENGTH,
|
|---|
| 16264 | length = nativeMin(n, MAX_ARRAY_LENGTH);
|
|---|
| 16265 |
|
|---|
| 16266 | iteratee = getIteratee(iteratee);
|
|---|
| 16267 | n -= MAX_ARRAY_LENGTH;
|
|---|
| 16268 |
|
|---|
| 16269 | var result = baseTimes(length, iteratee);
|
|---|
| 16270 | while (++index < n) {
|
|---|
| 16271 | iteratee(index);
|
|---|
| 16272 | }
|
|---|
| 16273 | return result;
|
|---|
| 16274 | }
|
|---|
| 16275 |
|
|---|
| 16276 | /**
|
|---|
| 16277 | * Converts `value` to a property path array.
|
|---|
| 16278 | *
|
|---|
| 16279 | * @static
|
|---|
| 16280 | * @memberOf _
|
|---|
| 16281 | * @since 4.0.0
|
|---|
| 16282 | * @category Util
|
|---|
| 16283 | * @param {*} value The value to convert.
|
|---|
| 16284 | * @returns {Array} Returns the new property path array.
|
|---|
| 16285 | * @example
|
|---|
| 16286 | *
|
|---|
| 16287 | * _.toPath('a.b.c');
|
|---|
| 16288 | * // => ['a', 'b', 'c']
|
|---|
| 16289 | *
|
|---|
| 16290 | * _.toPath('a[0].b.c');
|
|---|
| 16291 | * // => ['a', '0', 'b', 'c']
|
|---|
| 16292 | */
|
|---|
| 16293 | function toPath(value) {
|
|---|
| 16294 | if (isArray(value)) {
|
|---|
| 16295 | return arrayMap(value, toKey);
|
|---|
| 16296 | }
|
|---|
| 16297 | return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
|
|---|
| 16298 | }
|
|---|
| 16299 |
|
|---|
| 16300 | /**
|
|---|
| 16301 | * Generates a unique ID. If `prefix` is given, the ID is appended to it.
|
|---|
| 16302 | *
|
|---|
| 16303 | * @static
|
|---|
| 16304 | * @since 0.1.0
|
|---|
| 16305 | * @memberOf _
|
|---|
| 16306 | * @category Util
|
|---|
| 16307 | * @param {string} [prefix=''] The value to prefix the ID with.
|
|---|
| 16308 | * @returns {string} Returns the unique ID.
|
|---|
| 16309 | * @example
|
|---|
| 16310 | *
|
|---|
| 16311 | * _.uniqueId('contact_');
|
|---|
| 16312 | * // => 'contact_104'
|
|---|
| 16313 | *
|
|---|
| 16314 | * _.uniqueId();
|
|---|
| 16315 | * // => '105'
|
|---|
| 16316 | */
|
|---|
| 16317 | function uniqueId(prefix) {
|
|---|
| 16318 | var id = ++idCounter;
|
|---|
| 16319 | return toString(prefix) + id;
|
|---|
| 16320 | }
|
|---|
| 16321 |
|
|---|
| 16322 | /*------------------------------------------------------------------------*/
|
|---|
| 16323 |
|
|---|
| 16324 | /**
|
|---|
| 16325 | * Adds two numbers.
|
|---|
| 16326 | *
|
|---|
| 16327 | * @static
|
|---|
| 16328 | * @memberOf _
|
|---|
| 16329 | * @since 3.4.0
|
|---|
| 16330 | * @category Math
|
|---|
| 16331 | * @param {number} augend The first number in an addition.
|
|---|
| 16332 | * @param {number} addend The second number in an addition.
|
|---|
| 16333 | * @returns {number} Returns the total.
|
|---|
| 16334 | * @example
|
|---|
| 16335 | *
|
|---|
| 16336 | * _.add(6, 4);
|
|---|
| 16337 | * // => 10
|
|---|
| 16338 | */
|
|---|
| 16339 | var add = createMathOperation(function(augend, addend) {
|
|---|
| 16340 | return augend + addend;
|
|---|
| 16341 | }, 0);
|
|---|
| 16342 |
|
|---|
| 16343 | /**
|
|---|
| 16344 | * Computes `number` rounded up to `precision`.
|
|---|
| 16345 | *
|
|---|
| 16346 | * @static
|
|---|
| 16347 | * @memberOf _
|
|---|
| 16348 | * @since 3.10.0
|
|---|
| 16349 | * @category Math
|
|---|
| 16350 | * @param {number} number The number to round up.
|
|---|
| 16351 | * @param {number} [precision=0] The precision to round up to.
|
|---|
| 16352 | * @returns {number} Returns the rounded up number.
|
|---|
| 16353 | * @example
|
|---|
| 16354 | *
|
|---|
| 16355 | * _.ceil(4.006);
|
|---|
| 16356 | * // => 5
|
|---|
| 16357 | *
|
|---|
| 16358 | * _.ceil(6.004, 2);
|
|---|
| 16359 | * // => 6.01
|
|---|
| 16360 | *
|
|---|
| 16361 | * _.ceil(6040, -2);
|
|---|
| 16362 | * // => 6100
|
|---|
| 16363 | */
|
|---|
| 16364 | var ceil = createRound('ceil');
|
|---|
| 16365 |
|
|---|
| 16366 | /**
|
|---|
| 16367 | * Divide two numbers.
|
|---|
| 16368 | *
|
|---|
| 16369 | * @static
|
|---|
| 16370 | * @memberOf _
|
|---|
| 16371 | * @since 4.7.0
|
|---|
| 16372 | * @category Math
|
|---|
| 16373 | * @param {number} dividend The first number in a division.
|
|---|
| 16374 | * @param {number} divisor The second number in a division.
|
|---|
| 16375 | * @returns {number} Returns the quotient.
|
|---|
| 16376 | * @example
|
|---|
| 16377 | *
|
|---|
| 16378 | * _.divide(6, 4);
|
|---|
| 16379 | * // => 1.5
|
|---|
| 16380 | */
|
|---|
| 16381 | var divide = createMathOperation(function(dividend, divisor) {
|
|---|
| 16382 | return dividend / divisor;
|
|---|
| 16383 | }, 1);
|
|---|
| 16384 |
|
|---|
| 16385 | /**
|
|---|
| 16386 | * Computes `number` rounded down to `precision`.
|
|---|
| 16387 | *
|
|---|
| 16388 | * @static
|
|---|
| 16389 | * @memberOf _
|
|---|
| 16390 | * @since 3.10.0
|
|---|
| 16391 | * @category Math
|
|---|
| 16392 | * @param {number} number The number to round down.
|
|---|
| 16393 | * @param {number} [precision=0] The precision to round down to.
|
|---|
| 16394 | * @returns {number} Returns the rounded down number.
|
|---|
| 16395 | * @example
|
|---|
| 16396 | *
|
|---|
| 16397 | * _.floor(4.006);
|
|---|
| 16398 | * // => 4
|
|---|
| 16399 | *
|
|---|
| 16400 | * _.floor(0.046, 2);
|
|---|
| 16401 | * // => 0.04
|
|---|
| 16402 | *
|
|---|
| 16403 | * _.floor(4060, -2);
|
|---|
| 16404 | * // => 4000
|
|---|
| 16405 | */
|
|---|
| 16406 | var floor = createRound('floor');
|
|---|
| 16407 |
|
|---|
| 16408 | /**
|
|---|
| 16409 | * Computes the maximum value of `array`. If `array` is empty or falsey,
|
|---|
| 16410 | * `undefined` is returned.
|
|---|
| 16411 | *
|
|---|
| 16412 | * @static
|
|---|
| 16413 | * @since 0.1.0
|
|---|
| 16414 | * @memberOf _
|
|---|
| 16415 | * @category Math
|
|---|
| 16416 | * @param {Array} array The array to iterate over.
|
|---|
| 16417 | * @returns {*} Returns the maximum value.
|
|---|
| 16418 | * @example
|
|---|
| 16419 | *
|
|---|
| 16420 | * _.max([4, 2, 8, 6]);
|
|---|
| 16421 | * // => 8
|
|---|
| 16422 | *
|
|---|
| 16423 | * _.max([]);
|
|---|
| 16424 | * // => undefined
|
|---|
| 16425 | */
|
|---|
| 16426 | function max(array) {
|
|---|
| 16427 | return (array && array.length)
|
|---|
| 16428 | ? baseExtremum(array, identity, baseGt)
|
|---|
| 16429 | : undefined;
|
|---|
| 16430 | }
|
|---|
| 16431 |
|
|---|
| 16432 | /**
|
|---|
| 16433 | * This method is like `_.max` except that it accepts `iteratee` which is
|
|---|
| 16434 | * invoked for each element in `array` to generate the criterion by which
|
|---|
| 16435 | * the value is ranked. The iteratee is invoked with one argument: (value).
|
|---|
| 16436 | *
|
|---|
| 16437 | * @static
|
|---|
| 16438 | * @memberOf _
|
|---|
| 16439 | * @since 4.0.0
|
|---|
| 16440 | * @category Math
|
|---|
| 16441 | * @param {Array} array The array to iterate over.
|
|---|
| 16442 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 16443 | * @returns {*} Returns the maximum value.
|
|---|
| 16444 | * @example
|
|---|
| 16445 | *
|
|---|
| 16446 | * var objects = [{ 'n': 1 }, { 'n': 2 }];
|
|---|
| 16447 | *
|
|---|
| 16448 | * _.maxBy(objects, function(o) { return o.n; });
|
|---|
| 16449 | * // => { 'n': 2 }
|
|---|
| 16450 | *
|
|---|
| 16451 | * // The `_.property` iteratee shorthand.
|
|---|
| 16452 | * _.maxBy(objects, 'n');
|
|---|
| 16453 | * // => { 'n': 2 }
|
|---|
| 16454 | */
|
|---|
| 16455 | function maxBy(array, iteratee) {
|
|---|
| 16456 | return (array && array.length)
|
|---|
| 16457 | ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
|
|---|
| 16458 | : undefined;
|
|---|
| 16459 | }
|
|---|
| 16460 |
|
|---|
| 16461 | /**
|
|---|
| 16462 | * Computes the mean of the values in `array`.
|
|---|
| 16463 | *
|
|---|
| 16464 | * @static
|
|---|
| 16465 | * @memberOf _
|
|---|
| 16466 | * @since 4.0.0
|
|---|
| 16467 | * @category Math
|
|---|
| 16468 | * @param {Array} array The array to iterate over.
|
|---|
| 16469 | * @returns {number} Returns the mean.
|
|---|
| 16470 | * @example
|
|---|
| 16471 | *
|
|---|
| 16472 | * _.mean([4, 2, 8, 6]);
|
|---|
| 16473 | * // => 5
|
|---|
| 16474 | */
|
|---|
| 16475 | function mean(array) {
|
|---|
| 16476 | return baseMean(array, identity);
|
|---|
| 16477 | }
|
|---|
| 16478 |
|
|---|
| 16479 | /**
|
|---|
| 16480 | * This method is like `_.mean` except that it accepts `iteratee` which is
|
|---|
| 16481 | * invoked for each element in `array` to generate the value to be averaged.
|
|---|
| 16482 | * The iteratee is invoked with one argument: (value).
|
|---|
| 16483 | *
|
|---|
| 16484 | * @static
|
|---|
| 16485 | * @memberOf _
|
|---|
| 16486 | * @since 4.7.0
|
|---|
| 16487 | * @category Math
|
|---|
| 16488 | * @param {Array} array The array to iterate over.
|
|---|
| 16489 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 16490 | * @returns {number} Returns the mean.
|
|---|
| 16491 | * @example
|
|---|
| 16492 | *
|
|---|
| 16493 | * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
|
|---|
| 16494 | *
|
|---|
| 16495 | * _.meanBy(objects, function(o) { return o.n; });
|
|---|
| 16496 | * // => 5
|
|---|
| 16497 | *
|
|---|
| 16498 | * // The `_.property` iteratee shorthand.
|
|---|
| 16499 | * _.meanBy(objects, 'n');
|
|---|
| 16500 | * // => 5
|
|---|
| 16501 | */
|
|---|
| 16502 | function meanBy(array, iteratee) {
|
|---|
| 16503 | return baseMean(array, getIteratee(iteratee, 2));
|
|---|
| 16504 | }
|
|---|
| 16505 |
|
|---|
| 16506 | /**
|
|---|
| 16507 | * Computes the minimum value of `array`. If `array` is empty or falsey,
|
|---|
| 16508 | * `undefined` is returned.
|
|---|
| 16509 | *
|
|---|
| 16510 | * @static
|
|---|
| 16511 | * @since 0.1.0
|
|---|
| 16512 | * @memberOf _
|
|---|
| 16513 | * @category Math
|
|---|
| 16514 | * @param {Array} array The array to iterate over.
|
|---|
| 16515 | * @returns {*} Returns the minimum value.
|
|---|
| 16516 | * @example
|
|---|
| 16517 | *
|
|---|
| 16518 | * _.min([4, 2, 8, 6]);
|
|---|
| 16519 | * // => 2
|
|---|
| 16520 | *
|
|---|
| 16521 | * _.min([]);
|
|---|
| 16522 | * // => undefined
|
|---|
| 16523 | */
|
|---|
| 16524 | function min(array) {
|
|---|
| 16525 | return (array && array.length)
|
|---|
| 16526 | ? baseExtremum(array, identity, baseLt)
|
|---|
| 16527 | : undefined;
|
|---|
| 16528 | }
|
|---|
| 16529 |
|
|---|
| 16530 | /**
|
|---|
| 16531 | * This method is like `_.min` except that it accepts `iteratee` which is
|
|---|
| 16532 | * invoked for each element in `array` to generate the criterion by which
|
|---|
| 16533 | * the value is ranked. The iteratee is invoked with one argument: (value).
|
|---|
| 16534 | *
|
|---|
| 16535 | * @static
|
|---|
| 16536 | * @memberOf _
|
|---|
| 16537 | * @since 4.0.0
|
|---|
| 16538 | * @category Math
|
|---|
| 16539 | * @param {Array} array The array to iterate over.
|
|---|
| 16540 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 16541 | * @returns {*} Returns the minimum value.
|
|---|
| 16542 | * @example
|
|---|
| 16543 | *
|
|---|
| 16544 | * var objects = [{ 'n': 1 }, { 'n': 2 }];
|
|---|
| 16545 | *
|
|---|
| 16546 | * _.minBy(objects, function(o) { return o.n; });
|
|---|
| 16547 | * // => { 'n': 1 }
|
|---|
| 16548 | *
|
|---|
| 16549 | * // The `_.property` iteratee shorthand.
|
|---|
| 16550 | * _.minBy(objects, 'n');
|
|---|
| 16551 | * // => { 'n': 1 }
|
|---|
| 16552 | */
|
|---|
| 16553 | function minBy(array, iteratee) {
|
|---|
| 16554 | return (array && array.length)
|
|---|
| 16555 | ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
|
|---|
| 16556 | : undefined;
|
|---|
| 16557 | }
|
|---|
| 16558 |
|
|---|
| 16559 | /**
|
|---|
| 16560 | * Multiply two numbers.
|
|---|
| 16561 | *
|
|---|
| 16562 | * @static
|
|---|
| 16563 | * @memberOf _
|
|---|
| 16564 | * @since 4.7.0
|
|---|
| 16565 | * @category Math
|
|---|
| 16566 | * @param {number} multiplier The first number in a multiplication.
|
|---|
| 16567 | * @param {number} multiplicand The second number in a multiplication.
|
|---|
| 16568 | * @returns {number} Returns the product.
|
|---|
| 16569 | * @example
|
|---|
| 16570 | *
|
|---|
| 16571 | * _.multiply(6, 4);
|
|---|
| 16572 | * // => 24
|
|---|
| 16573 | */
|
|---|
| 16574 | var multiply = createMathOperation(function(multiplier, multiplicand) {
|
|---|
| 16575 | return multiplier * multiplicand;
|
|---|
| 16576 | }, 1);
|
|---|
| 16577 |
|
|---|
| 16578 | /**
|
|---|
| 16579 | * Computes `number` rounded to `precision`.
|
|---|
| 16580 | *
|
|---|
| 16581 | * @static
|
|---|
| 16582 | * @memberOf _
|
|---|
| 16583 | * @since 3.10.0
|
|---|
| 16584 | * @category Math
|
|---|
| 16585 | * @param {number} number The number to round.
|
|---|
| 16586 | * @param {number} [precision=0] The precision to round to.
|
|---|
| 16587 | * @returns {number} Returns the rounded number.
|
|---|
| 16588 | * @example
|
|---|
| 16589 | *
|
|---|
| 16590 | * _.round(4.006);
|
|---|
| 16591 | * // => 4
|
|---|
| 16592 | *
|
|---|
| 16593 | * _.round(4.006, 2);
|
|---|
| 16594 | * // => 4.01
|
|---|
| 16595 | *
|
|---|
| 16596 | * _.round(4060, -2);
|
|---|
| 16597 | * // => 4100
|
|---|
| 16598 | */
|
|---|
| 16599 | var round = createRound('round');
|
|---|
| 16600 |
|
|---|
| 16601 | /**
|
|---|
| 16602 | * Subtract two numbers.
|
|---|
| 16603 | *
|
|---|
| 16604 | * @static
|
|---|
| 16605 | * @memberOf _
|
|---|
| 16606 | * @since 4.0.0
|
|---|
| 16607 | * @category Math
|
|---|
| 16608 | * @param {number} minuend The first number in a subtraction.
|
|---|
| 16609 | * @param {number} subtrahend The second number in a subtraction.
|
|---|
| 16610 | * @returns {number} Returns the difference.
|
|---|
| 16611 | * @example
|
|---|
| 16612 | *
|
|---|
| 16613 | * _.subtract(6, 4);
|
|---|
| 16614 | * // => 2
|
|---|
| 16615 | */
|
|---|
| 16616 | var subtract = createMathOperation(function(minuend, subtrahend) {
|
|---|
| 16617 | return minuend - subtrahend;
|
|---|
| 16618 | }, 0);
|
|---|
| 16619 |
|
|---|
| 16620 | /**
|
|---|
| 16621 | * Computes the sum of the values in `array`.
|
|---|
| 16622 | *
|
|---|
| 16623 | * @static
|
|---|
| 16624 | * @memberOf _
|
|---|
| 16625 | * @since 3.4.0
|
|---|
| 16626 | * @category Math
|
|---|
| 16627 | * @param {Array} array The array to iterate over.
|
|---|
| 16628 | * @returns {number} Returns the sum.
|
|---|
| 16629 | * @example
|
|---|
| 16630 | *
|
|---|
| 16631 | * _.sum([4, 2, 8, 6]);
|
|---|
| 16632 | * // => 20
|
|---|
| 16633 | */
|
|---|
| 16634 | function sum(array) {
|
|---|
| 16635 | return (array && array.length)
|
|---|
| 16636 | ? baseSum(array, identity)
|
|---|
| 16637 | : 0;
|
|---|
| 16638 | }
|
|---|
| 16639 |
|
|---|
| 16640 | /**
|
|---|
| 16641 | * This method is like `_.sum` except that it accepts `iteratee` which is
|
|---|
| 16642 | * invoked for each element in `array` to generate the value to be summed.
|
|---|
| 16643 | * The iteratee is invoked with one argument: (value).
|
|---|
| 16644 | *
|
|---|
| 16645 | * @static
|
|---|
| 16646 | * @memberOf _
|
|---|
| 16647 | * @since 4.0.0
|
|---|
| 16648 | * @category Math
|
|---|
| 16649 | * @param {Array} array The array to iterate over.
|
|---|
| 16650 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
|---|
| 16651 | * @returns {number} Returns the sum.
|
|---|
| 16652 | * @example
|
|---|
| 16653 | *
|
|---|
| 16654 | * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
|
|---|
| 16655 | *
|
|---|
| 16656 | * _.sumBy(objects, function(o) { return o.n; });
|
|---|
| 16657 | * // => 20
|
|---|
| 16658 | *
|
|---|
| 16659 | * // The `_.property` iteratee shorthand.
|
|---|
| 16660 | * _.sumBy(objects, 'n');
|
|---|
| 16661 | * // => 20
|
|---|
| 16662 | */
|
|---|
| 16663 | function sumBy(array, iteratee) {
|
|---|
| 16664 | return (array && array.length)
|
|---|
| 16665 | ? baseSum(array, getIteratee(iteratee, 2))
|
|---|
| 16666 | : 0;
|
|---|
| 16667 | }
|
|---|
| 16668 |
|
|---|
| 16669 | /*------------------------------------------------------------------------*/
|
|---|
| 16670 |
|
|---|
| 16671 | // Add methods that return wrapped values in chain sequences.
|
|---|
| 16672 | lodash.after = after;
|
|---|
| 16673 | lodash.ary = ary;
|
|---|
| 16674 | lodash.assign = assign;
|
|---|
| 16675 | lodash.assignIn = assignIn;
|
|---|
| 16676 | lodash.assignInWith = assignInWith;
|
|---|
| 16677 | lodash.assignWith = assignWith;
|
|---|
| 16678 | lodash.at = at;
|
|---|
| 16679 | lodash.before = before;
|
|---|
| 16680 | lodash.bind = bind;
|
|---|
| 16681 | lodash.bindAll = bindAll;
|
|---|
| 16682 | lodash.bindKey = bindKey;
|
|---|
| 16683 | lodash.castArray = castArray;
|
|---|
| 16684 | lodash.chain = chain;
|
|---|
| 16685 | lodash.chunk = chunk;
|
|---|
| 16686 | lodash.compact = compact;
|
|---|
| 16687 | lodash.concat = concat;
|
|---|
| 16688 | lodash.cond = cond;
|
|---|
| 16689 | lodash.conforms = conforms;
|
|---|
| 16690 | lodash.constant = constant;
|
|---|
| 16691 | lodash.countBy = countBy;
|
|---|
| 16692 | lodash.create = create;
|
|---|
| 16693 | lodash.curry = curry;
|
|---|
| 16694 | lodash.curryRight = curryRight;
|
|---|
| 16695 | lodash.debounce = debounce;
|
|---|
| 16696 | lodash.defaults = defaults;
|
|---|
| 16697 | lodash.defaultsDeep = defaultsDeep;
|
|---|
| 16698 | lodash.defer = defer;
|
|---|
| 16699 | lodash.delay = delay;
|
|---|
| 16700 | lodash.difference = difference;
|
|---|
| 16701 | lodash.differenceBy = differenceBy;
|
|---|
| 16702 | lodash.differenceWith = differenceWith;
|
|---|
| 16703 | lodash.drop = drop;
|
|---|
| 16704 | lodash.dropRight = dropRight;
|
|---|
| 16705 | lodash.dropRightWhile = dropRightWhile;
|
|---|
| 16706 | lodash.dropWhile = dropWhile;
|
|---|
| 16707 | lodash.fill = fill;
|
|---|
| 16708 | lodash.filter = filter;
|
|---|
| 16709 | lodash.flatMap = flatMap;
|
|---|
| 16710 | lodash.flatMapDeep = flatMapDeep;
|
|---|
| 16711 | lodash.flatMapDepth = flatMapDepth;
|
|---|
| 16712 | lodash.flatten = flatten;
|
|---|
| 16713 | lodash.flattenDeep = flattenDeep;
|
|---|
| 16714 | lodash.flattenDepth = flattenDepth;
|
|---|
| 16715 | lodash.flip = flip;
|
|---|
| 16716 | lodash.flow = flow;
|
|---|
| 16717 | lodash.flowRight = flowRight;
|
|---|
| 16718 | lodash.fromPairs = fromPairs;
|
|---|
| 16719 | lodash.functions = functions;
|
|---|
| 16720 | lodash.functionsIn = functionsIn;
|
|---|
| 16721 | lodash.groupBy = groupBy;
|
|---|
| 16722 | lodash.initial = initial;
|
|---|
| 16723 | lodash.intersection = intersection;
|
|---|
| 16724 | lodash.intersectionBy = intersectionBy;
|
|---|
| 16725 | lodash.intersectionWith = intersectionWith;
|
|---|
| 16726 | lodash.invert = invert;
|
|---|
| 16727 | lodash.invertBy = invertBy;
|
|---|
| 16728 | lodash.invokeMap = invokeMap;
|
|---|
| 16729 | lodash.iteratee = iteratee;
|
|---|
| 16730 | lodash.keyBy = keyBy;
|
|---|
| 16731 | lodash.keys = keys;
|
|---|
| 16732 | lodash.keysIn = keysIn;
|
|---|
| 16733 | lodash.map = map;
|
|---|
| 16734 | lodash.mapKeys = mapKeys;
|
|---|
| 16735 | lodash.mapValues = mapValues;
|
|---|
| 16736 | lodash.matches = matches;
|
|---|
| 16737 | lodash.matchesProperty = matchesProperty;
|
|---|
| 16738 | lodash.memoize = memoize;
|
|---|
| 16739 | lodash.merge = merge;
|
|---|
| 16740 | lodash.mergeWith = mergeWith;
|
|---|
| 16741 | lodash.method = method;
|
|---|
| 16742 | lodash.methodOf = methodOf;
|
|---|
| 16743 | lodash.mixin = mixin;
|
|---|
| 16744 | lodash.negate = negate;
|
|---|
| 16745 | lodash.nthArg = nthArg;
|
|---|
| 16746 | lodash.omit = omit;
|
|---|
| 16747 | lodash.omitBy = omitBy;
|
|---|
| 16748 | lodash.once = once;
|
|---|
| 16749 | lodash.orderBy = orderBy;
|
|---|
| 16750 | lodash.over = over;
|
|---|
| 16751 | lodash.overArgs = overArgs;
|
|---|
| 16752 | lodash.overEvery = overEvery;
|
|---|
| 16753 | lodash.overSome = overSome;
|
|---|
| 16754 | lodash.partial = partial;
|
|---|
| 16755 | lodash.partialRight = partialRight;
|
|---|
| 16756 | lodash.partition = partition;
|
|---|
| 16757 | lodash.pick = pick;
|
|---|
| 16758 | lodash.pickBy = pickBy;
|
|---|
| 16759 | lodash.property = property;
|
|---|
| 16760 | lodash.propertyOf = propertyOf;
|
|---|
| 16761 | lodash.pull = pull;
|
|---|
| 16762 | lodash.pullAll = pullAll;
|
|---|
| 16763 | lodash.pullAllBy = pullAllBy;
|
|---|
| 16764 | lodash.pullAllWith = pullAllWith;
|
|---|
| 16765 | lodash.pullAt = pullAt;
|
|---|
| 16766 | lodash.range = range;
|
|---|
| 16767 | lodash.rangeRight = rangeRight;
|
|---|
| 16768 | lodash.rearg = rearg;
|
|---|
| 16769 | lodash.reject = reject;
|
|---|
| 16770 | lodash.remove = remove;
|
|---|
| 16771 | lodash.rest = rest;
|
|---|
| 16772 | lodash.reverse = reverse;
|
|---|
| 16773 | lodash.sampleSize = sampleSize;
|
|---|
| 16774 | lodash.set = set;
|
|---|
| 16775 | lodash.setWith = setWith;
|
|---|
| 16776 | lodash.shuffle = shuffle;
|
|---|
| 16777 | lodash.slice = slice;
|
|---|
| 16778 | lodash.sortBy = sortBy;
|
|---|
| 16779 | lodash.sortedUniq = sortedUniq;
|
|---|
| 16780 | lodash.sortedUniqBy = sortedUniqBy;
|
|---|
| 16781 | lodash.split = split;
|
|---|
| 16782 | lodash.spread = spread;
|
|---|
| 16783 | lodash.tail = tail;
|
|---|
| 16784 | lodash.take = take;
|
|---|
| 16785 | lodash.takeRight = takeRight;
|
|---|
| 16786 | lodash.takeRightWhile = takeRightWhile;
|
|---|
| 16787 | lodash.takeWhile = takeWhile;
|
|---|
| 16788 | lodash.tap = tap;
|
|---|
| 16789 | lodash.throttle = throttle;
|
|---|
| 16790 | lodash.thru = thru;
|
|---|
| 16791 | lodash.toArray = toArray;
|
|---|
| 16792 | lodash.toPairs = toPairs;
|
|---|
| 16793 | lodash.toPairsIn = toPairsIn;
|
|---|
| 16794 | lodash.toPath = toPath;
|
|---|
| 16795 | lodash.toPlainObject = toPlainObject;
|
|---|
| 16796 | lodash.transform = transform;
|
|---|
| 16797 | lodash.unary = unary;
|
|---|
| 16798 | lodash.union = union;
|
|---|
| 16799 | lodash.unionBy = unionBy;
|
|---|
| 16800 | lodash.unionWith = unionWith;
|
|---|
| 16801 | lodash.uniq = uniq;
|
|---|
| 16802 | lodash.uniqBy = uniqBy;
|
|---|
| 16803 | lodash.uniqWith = uniqWith;
|
|---|
| 16804 | lodash.unset = unset;
|
|---|
| 16805 | lodash.unzip = unzip;
|
|---|
| 16806 | lodash.unzipWith = unzipWith;
|
|---|
| 16807 | lodash.update = update;
|
|---|
| 16808 | lodash.updateWith = updateWith;
|
|---|
| 16809 | lodash.values = values;
|
|---|
| 16810 | lodash.valuesIn = valuesIn;
|
|---|
| 16811 | lodash.without = without;
|
|---|
| 16812 | lodash.words = words;
|
|---|
| 16813 | lodash.wrap = wrap;
|
|---|
| 16814 | lodash.xor = xor;
|
|---|
| 16815 | lodash.xorBy = xorBy;
|
|---|
| 16816 | lodash.xorWith = xorWith;
|
|---|
| 16817 | lodash.zip = zip;
|
|---|
| 16818 | lodash.zipObject = zipObject;
|
|---|
| 16819 | lodash.zipObjectDeep = zipObjectDeep;
|
|---|
| 16820 | lodash.zipWith = zipWith;
|
|---|
| 16821 |
|
|---|
| 16822 | // Add aliases.
|
|---|
| 16823 | lodash.entries = toPairs;
|
|---|
| 16824 | lodash.entriesIn = toPairsIn;
|
|---|
| 16825 | lodash.extend = assignIn;
|
|---|
| 16826 | lodash.extendWith = assignInWith;
|
|---|
| 16827 |
|
|---|
| 16828 | // Add methods to `lodash.prototype`.
|
|---|
| 16829 | mixin(lodash, lodash);
|
|---|
| 16830 |
|
|---|
| 16831 | /*------------------------------------------------------------------------*/
|
|---|
| 16832 |
|
|---|
| 16833 | // Add methods that return unwrapped values in chain sequences.
|
|---|
| 16834 | lodash.add = add;
|
|---|
| 16835 | lodash.attempt = attempt;
|
|---|
| 16836 | lodash.camelCase = camelCase;
|
|---|
| 16837 | lodash.capitalize = capitalize;
|
|---|
| 16838 | lodash.ceil = ceil;
|
|---|
| 16839 | lodash.clamp = clamp;
|
|---|
| 16840 | lodash.clone = clone;
|
|---|
| 16841 | lodash.cloneDeep = cloneDeep;
|
|---|
| 16842 | lodash.cloneDeepWith = cloneDeepWith;
|
|---|
| 16843 | lodash.cloneWith = cloneWith;
|
|---|
| 16844 | lodash.conformsTo = conformsTo;
|
|---|
| 16845 | lodash.deburr = deburr;
|
|---|
| 16846 | lodash.defaultTo = defaultTo;
|
|---|
| 16847 | lodash.divide = divide;
|
|---|
| 16848 | lodash.endsWith = endsWith;
|
|---|
| 16849 | lodash.eq = eq;
|
|---|
| 16850 | lodash.escape = escape;
|
|---|
| 16851 | lodash.escapeRegExp = escapeRegExp;
|
|---|
| 16852 | lodash.every = every;
|
|---|
| 16853 | lodash.find = find;
|
|---|
| 16854 | lodash.findIndex = findIndex;
|
|---|
| 16855 | lodash.findKey = findKey;
|
|---|
| 16856 | lodash.findLast = findLast;
|
|---|
| 16857 | lodash.findLastIndex = findLastIndex;
|
|---|
| 16858 | lodash.findLastKey = findLastKey;
|
|---|
| 16859 | lodash.floor = floor;
|
|---|
| 16860 | lodash.forEach = forEach;
|
|---|
| 16861 | lodash.forEachRight = forEachRight;
|
|---|
| 16862 | lodash.forIn = forIn;
|
|---|
| 16863 | lodash.forInRight = forInRight;
|
|---|
| 16864 | lodash.forOwn = forOwn;
|
|---|
| 16865 | lodash.forOwnRight = forOwnRight;
|
|---|
| 16866 | lodash.get = get;
|
|---|
| 16867 | lodash.gt = gt;
|
|---|
| 16868 | lodash.gte = gte;
|
|---|
| 16869 | lodash.has = has;
|
|---|
| 16870 | lodash.hasIn = hasIn;
|
|---|
| 16871 | lodash.head = head;
|
|---|
| 16872 | lodash.identity = identity;
|
|---|
| 16873 | lodash.includes = includes;
|
|---|
| 16874 | lodash.indexOf = indexOf;
|
|---|
| 16875 | lodash.inRange = inRange;
|
|---|
| 16876 | lodash.invoke = invoke;
|
|---|
| 16877 | lodash.isArguments = isArguments;
|
|---|
| 16878 | lodash.isArray = isArray;
|
|---|
| 16879 | lodash.isArrayBuffer = isArrayBuffer;
|
|---|
| 16880 | lodash.isArrayLike = isArrayLike;
|
|---|
| 16881 | lodash.isArrayLikeObject = isArrayLikeObject;
|
|---|
| 16882 | lodash.isBoolean = isBoolean;
|
|---|
| 16883 | lodash.isBuffer = isBuffer;
|
|---|
| 16884 | lodash.isDate = isDate;
|
|---|
| 16885 | lodash.isElement = isElement;
|
|---|
| 16886 | lodash.isEmpty = isEmpty;
|
|---|
| 16887 | lodash.isEqual = isEqual;
|
|---|
| 16888 | lodash.isEqualWith = isEqualWith;
|
|---|
| 16889 | lodash.isError = isError;
|
|---|
| 16890 | lodash.isFinite = isFinite;
|
|---|
| 16891 | lodash.isFunction = isFunction;
|
|---|
| 16892 | lodash.isInteger = isInteger;
|
|---|
| 16893 | lodash.isLength = isLength;
|
|---|
| 16894 | lodash.isMap = isMap;
|
|---|
| 16895 | lodash.isMatch = isMatch;
|
|---|
| 16896 | lodash.isMatchWith = isMatchWith;
|
|---|
| 16897 | lodash.isNaN = isNaN;
|
|---|
| 16898 | lodash.isNative = isNative;
|
|---|
| 16899 | lodash.isNil = isNil;
|
|---|
| 16900 | lodash.isNull = isNull;
|
|---|
| 16901 | lodash.isNumber = isNumber;
|
|---|
| 16902 | lodash.isObject = isObject;
|
|---|
| 16903 | lodash.isObjectLike = isObjectLike;
|
|---|
| 16904 | lodash.isPlainObject = isPlainObject;
|
|---|
| 16905 | lodash.isRegExp = isRegExp;
|
|---|
| 16906 | lodash.isSafeInteger = isSafeInteger;
|
|---|
| 16907 | lodash.isSet = isSet;
|
|---|
| 16908 | lodash.isString = isString;
|
|---|
| 16909 | lodash.isSymbol = isSymbol;
|
|---|
| 16910 | lodash.isTypedArray = isTypedArray;
|
|---|
| 16911 | lodash.isUndefined = isUndefined;
|
|---|
| 16912 | lodash.isWeakMap = isWeakMap;
|
|---|
| 16913 | lodash.isWeakSet = isWeakSet;
|
|---|
| 16914 | lodash.join = join;
|
|---|
| 16915 | lodash.kebabCase = kebabCase;
|
|---|
| 16916 | lodash.last = last;
|
|---|
| 16917 | lodash.lastIndexOf = lastIndexOf;
|
|---|
| 16918 | lodash.lowerCase = lowerCase;
|
|---|
| 16919 | lodash.lowerFirst = lowerFirst;
|
|---|
| 16920 | lodash.lt = lt;
|
|---|
| 16921 | lodash.lte = lte;
|
|---|
| 16922 | lodash.max = max;
|
|---|
| 16923 | lodash.maxBy = maxBy;
|
|---|
| 16924 | lodash.mean = mean;
|
|---|
| 16925 | lodash.meanBy = meanBy;
|
|---|
| 16926 | lodash.min = min;
|
|---|
| 16927 | lodash.minBy = minBy;
|
|---|
| 16928 | lodash.stubArray = stubArray;
|
|---|
| 16929 | lodash.stubFalse = stubFalse;
|
|---|
| 16930 | lodash.stubObject = stubObject;
|
|---|
| 16931 | lodash.stubString = stubString;
|
|---|
| 16932 | lodash.stubTrue = stubTrue;
|
|---|
| 16933 | lodash.multiply = multiply;
|
|---|
| 16934 | lodash.nth = nth;
|
|---|
| 16935 | lodash.noConflict = noConflict;
|
|---|
| 16936 | lodash.noop = noop;
|
|---|
| 16937 | lodash.now = now;
|
|---|
| 16938 | lodash.pad = pad;
|
|---|
| 16939 | lodash.padEnd = padEnd;
|
|---|
| 16940 | lodash.padStart = padStart;
|
|---|
| 16941 | lodash.parseInt = parseInt;
|
|---|
| 16942 | lodash.random = random;
|
|---|
| 16943 | lodash.reduce = reduce;
|
|---|
| 16944 | lodash.reduceRight = reduceRight;
|
|---|
| 16945 | lodash.repeat = repeat;
|
|---|
| 16946 | lodash.replace = replace;
|
|---|
| 16947 | lodash.result = result;
|
|---|
| 16948 | lodash.round = round;
|
|---|
| 16949 | lodash.runInContext = runInContext;
|
|---|
| 16950 | lodash.sample = sample;
|
|---|
| 16951 | lodash.size = size;
|
|---|
| 16952 | lodash.snakeCase = snakeCase;
|
|---|
| 16953 | lodash.some = some;
|
|---|
| 16954 | lodash.sortedIndex = sortedIndex;
|
|---|
| 16955 | lodash.sortedIndexBy = sortedIndexBy;
|
|---|
| 16956 | lodash.sortedIndexOf = sortedIndexOf;
|
|---|
| 16957 | lodash.sortedLastIndex = sortedLastIndex;
|
|---|
| 16958 | lodash.sortedLastIndexBy = sortedLastIndexBy;
|
|---|
| 16959 | lodash.sortedLastIndexOf = sortedLastIndexOf;
|
|---|
| 16960 | lodash.startCase = startCase;
|
|---|
| 16961 | lodash.startsWith = startsWith;
|
|---|
| 16962 | lodash.subtract = subtract;
|
|---|
| 16963 | lodash.sum = sum;
|
|---|
| 16964 | lodash.sumBy = sumBy;
|
|---|
| 16965 | lodash.template = template;
|
|---|
| 16966 | lodash.times = times;
|
|---|
| 16967 | lodash.toFinite = toFinite;
|
|---|
| 16968 | lodash.toInteger = toInteger;
|
|---|
| 16969 | lodash.toLength = toLength;
|
|---|
| 16970 | lodash.toLower = toLower;
|
|---|
| 16971 | lodash.toNumber = toNumber;
|
|---|
| 16972 | lodash.toSafeInteger = toSafeInteger;
|
|---|
| 16973 | lodash.toString = toString;
|
|---|
| 16974 | lodash.toUpper = toUpper;
|
|---|
| 16975 | lodash.trim = trim;
|
|---|
| 16976 | lodash.trimEnd = trimEnd;
|
|---|
| 16977 | lodash.trimStart = trimStart;
|
|---|
| 16978 | lodash.truncate = truncate;
|
|---|
| 16979 | lodash.unescape = unescape;
|
|---|
| 16980 | lodash.uniqueId = uniqueId;
|
|---|
| 16981 | lodash.upperCase = upperCase;
|
|---|
| 16982 | lodash.upperFirst = upperFirst;
|
|---|
| 16983 |
|
|---|
| 16984 | // Add aliases.
|
|---|
| 16985 | lodash.each = forEach;
|
|---|
| 16986 | lodash.eachRight = forEachRight;
|
|---|
| 16987 | lodash.first = head;
|
|---|
| 16988 |
|
|---|
| 16989 | mixin(lodash, (function() {
|
|---|
| 16990 | var source = {};
|
|---|
| 16991 | baseForOwn(lodash, function(func, methodName) {
|
|---|
| 16992 | if (!hasOwnProperty.call(lodash.prototype, methodName)) {
|
|---|
| 16993 | source[methodName] = func;
|
|---|
| 16994 | }
|
|---|
| 16995 | });
|
|---|
| 16996 | return source;
|
|---|
| 16997 | }()), { 'chain': false });
|
|---|
| 16998 |
|
|---|
| 16999 | /*------------------------------------------------------------------------*/
|
|---|
| 17000 |
|
|---|
| 17001 | /**
|
|---|
| 17002 | * The semantic version number.
|
|---|
| 17003 | *
|
|---|
| 17004 | * @static
|
|---|
| 17005 | * @memberOf _
|
|---|
| 17006 | * @type {string}
|
|---|
| 17007 | */
|
|---|
| 17008 | lodash.VERSION = VERSION;
|
|---|
| 17009 |
|
|---|
| 17010 | // Assign default placeholders.
|
|---|
| 17011 | arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
|
|---|
| 17012 | lodash[methodName].placeholder = lodash;
|
|---|
| 17013 | });
|
|---|
| 17014 |
|
|---|
| 17015 | // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
|
|---|
| 17016 | arrayEach(['drop', 'take'], function(methodName, index) {
|
|---|
| 17017 | LazyWrapper.prototype[methodName] = function(n) {
|
|---|
| 17018 | n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
|
|---|
| 17019 |
|
|---|
| 17020 | var result = (this.__filtered__ && !index)
|
|---|
| 17021 | ? new LazyWrapper(this)
|
|---|
| 17022 | : this.clone();
|
|---|
| 17023 |
|
|---|
| 17024 | if (result.__filtered__) {
|
|---|
| 17025 | result.__takeCount__ = nativeMin(n, result.__takeCount__);
|
|---|
| 17026 | } else {
|
|---|
| 17027 | result.__views__.push({
|
|---|
| 17028 | 'size': nativeMin(n, MAX_ARRAY_LENGTH),
|
|---|
| 17029 | 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
|
|---|
| 17030 | });
|
|---|
| 17031 | }
|
|---|
| 17032 | return result;
|
|---|
| 17033 | };
|
|---|
| 17034 |
|
|---|
| 17035 | LazyWrapper.prototype[methodName + 'Right'] = function(n) {
|
|---|
| 17036 | return this.reverse()[methodName](n).reverse();
|
|---|
| 17037 | };
|
|---|
| 17038 | });
|
|---|
| 17039 |
|
|---|
| 17040 | // Add `LazyWrapper` methods that accept an `iteratee` value.
|
|---|
| 17041 | arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
|
|---|
| 17042 | var type = index + 1,
|
|---|
| 17043 | isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
|
|---|
| 17044 |
|
|---|
| 17045 | LazyWrapper.prototype[methodName] = function(iteratee) {
|
|---|
| 17046 | var result = this.clone();
|
|---|
| 17047 | result.__iteratees__.push({
|
|---|
| 17048 | 'iteratee': getIteratee(iteratee, 3),
|
|---|
| 17049 | 'type': type
|
|---|
| 17050 | });
|
|---|
| 17051 | result.__filtered__ = result.__filtered__ || isFilter;
|
|---|
| 17052 | return result;
|
|---|
| 17053 | };
|
|---|
| 17054 | });
|
|---|
| 17055 |
|
|---|
| 17056 | // Add `LazyWrapper` methods for `_.head` and `_.last`.
|
|---|
| 17057 | arrayEach(['head', 'last'], function(methodName, index) {
|
|---|
| 17058 | var takeName = 'take' + (index ? 'Right' : '');
|
|---|
| 17059 |
|
|---|
| 17060 | LazyWrapper.prototype[methodName] = function() {
|
|---|
| 17061 | return this[takeName](1).value()[0];
|
|---|
| 17062 | };
|
|---|
| 17063 | });
|
|---|
| 17064 |
|
|---|
| 17065 | // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
|
|---|
| 17066 | arrayEach(['initial', 'tail'], function(methodName, index) {
|
|---|
| 17067 | var dropName = 'drop' + (index ? '' : 'Right');
|
|---|
| 17068 |
|
|---|
| 17069 | LazyWrapper.prototype[methodName] = function() {
|
|---|
| 17070 | return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
|
|---|
| 17071 | };
|
|---|
| 17072 | });
|
|---|
| 17073 |
|
|---|
| 17074 | LazyWrapper.prototype.compact = function() {
|
|---|
| 17075 | return this.filter(identity);
|
|---|
| 17076 | };
|
|---|
| 17077 |
|
|---|
| 17078 | LazyWrapper.prototype.find = function(predicate) {
|
|---|
| 17079 | return this.filter(predicate).head();
|
|---|
| 17080 | };
|
|---|
| 17081 |
|
|---|
| 17082 | LazyWrapper.prototype.findLast = function(predicate) {
|
|---|
| 17083 | return this.reverse().find(predicate);
|
|---|
| 17084 | };
|
|---|
| 17085 |
|
|---|
| 17086 | LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
|
|---|
| 17087 | if (typeof path == 'function') {
|
|---|
| 17088 | return new LazyWrapper(this);
|
|---|
| 17089 | }
|
|---|
| 17090 | return this.map(function(value) {
|
|---|
| 17091 | return baseInvoke(value, path, args);
|
|---|
| 17092 | });
|
|---|
| 17093 | });
|
|---|
| 17094 |
|
|---|
| 17095 | LazyWrapper.prototype.reject = function(predicate) {
|
|---|
| 17096 | return this.filter(negate(getIteratee(predicate)));
|
|---|
| 17097 | };
|
|---|
| 17098 |
|
|---|
| 17099 | LazyWrapper.prototype.slice = function(start, end) {
|
|---|
| 17100 | start = toInteger(start);
|
|---|
| 17101 |
|
|---|
| 17102 | var result = this;
|
|---|
| 17103 | if (result.__filtered__ && (start > 0 || end < 0)) {
|
|---|
| 17104 | return new LazyWrapper(result);
|
|---|
| 17105 | }
|
|---|
| 17106 | if (start < 0) {
|
|---|
| 17107 | result = result.takeRight(-start);
|
|---|
| 17108 | } else if (start) {
|
|---|
| 17109 | result = result.drop(start);
|
|---|
| 17110 | }
|
|---|
| 17111 | if (end !== undefined) {
|
|---|
| 17112 | end = toInteger(end);
|
|---|
| 17113 | result = end < 0 ? result.dropRight(-end) : result.take(end - start);
|
|---|
| 17114 | }
|
|---|
| 17115 | return result;
|
|---|
| 17116 | };
|
|---|
| 17117 |
|
|---|
| 17118 | LazyWrapper.prototype.takeRightWhile = function(predicate) {
|
|---|
| 17119 | return this.reverse().takeWhile(predicate).reverse();
|
|---|
| 17120 | };
|
|---|
| 17121 |
|
|---|
| 17122 | LazyWrapper.prototype.toArray = function() {
|
|---|
| 17123 | return this.take(MAX_ARRAY_LENGTH);
|
|---|
| 17124 | };
|
|---|
| 17125 |
|
|---|
| 17126 | // Add `LazyWrapper` methods to `lodash.prototype`.
|
|---|
| 17127 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
|---|
| 17128 | var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
|
|---|
| 17129 | isTaker = /^(?:head|last)$/.test(methodName),
|
|---|
| 17130 | lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
|
|---|
| 17131 | retUnwrapped = isTaker || /^find/.test(methodName);
|
|---|
| 17132 |
|
|---|
| 17133 | if (!lodashFunc) {
|
|---|
| 17134 | return;
|
|---|
| 17135 | }
|
|---|
| 17136 | lodash.prototype[methodName] = function() {
|
|---|
| 17137 | var value = this.__wrapped__,
|
|---|
| 17138 | args = isTaker ? [1] : arguments,
|
|---|
| 17139 | isLazy = value instanceof LazyWrapper,
|
|---|
| 17140 | iteratee = args[0],
|
|---|
| 17141 | useLazy = isLazy || isArray(value);
|
|---|
| 17142 |
|
|---|
| 17143 | var interceptor = function(value) {
|
|---|
| 17144 | var result = lodashFunc.apply(lodash, arrayPush([value], args));
|
|---|
| 17145 | return (isTaker && chainAll) ? result[0] : result;
|
|---|
| 17146 | };
|
|---|
| 17147 |
|
|---|
| 17148 | if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
|
|---|
| 17149 | // Avoid lazy use if the iteratee has a "length" value other than `1`.
|
|---|
| 17150 | isLazy = useLazy = false;
|
|---|
| 17151 | }
|
|---|
| 17152 | var chainAll = this.__chain__,
|
|---|
| 17153 | isHybrid = !!this.__actions__.length,
|
|---|
| 17154 | isUnwrapped = retUnwrapped && !chainAll,
|
|---|
| 17155 | onlyLazy = isLazy && !isHybrid;
|
|---|
| 17156 |
|
|---|
| 17157 | if (!retUnwrapped && useLazy) {
|
|---|
| 17158 | value = onlyLazy ? value : new LazyWrapper(this);
|
|---|
| 17159 | var result = func.apply(value, args);
|
|---|
| 17160 | result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
|
|---|
| 17161 | return new LodashWrapper(result, chainAll);
|
|---|
| 17162 | }
|
|---|
| 17163 | if (isUnwrapped && onlyLazy) {
|
|---|
| 17164 | return func.apply(this, args);
|
|---|
| 17165 | }
|
|---|
| 17166 | result = this.thru(interceptor);
|
|---|
| 17167 | return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
|
|---|
| 17168 | };
|
|---|
| 17169 | });
|
|---|
| 17170 |
|
|---|
| 17171 | // Add `Array` methods to `lodash.prototype`.
|
|---|
| 17172 | arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
|
|---|
| 17173 | var func = arrayProto[methodName],
|
|---|
| 17174 | chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
|
|---|
| 17175 | retUnwrapped = /^(?:pop|shift)$/.test(methodName);
|
|---|
| 17176 |
|
|---|
| 17177 | lodash.prototype[methodName] = function() {
|
|---|
| 17178 | var args = arguments;
|
|---|
| 17179 | if (retUnwrapped && !this.__chain__) {
|
|---|
| 17180 | var value = this.value();
|
|---|
| 17181 | return func.apply(isArray(value) ? value : [], args);
|
|---|
| 17182 | }
|
|---|
| 17183 | return this[chainName](function(value) {
|
|---|
| 17184 | return func.apply(isArray(value) ? value : [], args);
|
|---|
| 17185 | });
|
|---|
| 17186 | };
|
|---|
| 17187 | });
|
|---|
| 17188 |
|
|---|
| 17189 | // Map minified method names to their real names.
|
|---|
| 17190 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
|---|
| 17191 | var lodashFunc = lodash[methodName];
|
|---|
| 17192 | if (lodashFunc) {
|
|---|
| 17193 | var key = lodashFunc.name + '';
|
|---|
| 17194 | if (!hasOwnProperty.call(realNames, key)) {
|
|---|
| 17195 | realNames[key] = [];
|
|---|
| 17196 | }
|
|---|
| 17197 | realNames[key].push({ 'name': methodName, 'func': lodashFunc });
|
|---|
| 17198 | }
|
|---|
| 17199 | });
|
|---|
| 17200 |
|
|---|
| 17201 | realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
|
|---|
| 17202 | 'name': 'wrapper',
|
|---|
| 17203 | 'func': undefined
|
|---|
| 17204 | }];
|
|---|
| 17205 |
|
|---|
| 17206 | // Add methods to `LazyWrapper`.
|
|---|
| 17207 | LazyWrapper.prototype.clone = lazyClone;
|
|---|
| 17208 | LazyWrapper.prototype.reverse = lazyReverse;
|
|---|
| 17209 | LazyWrapper.prototype.value = lazyValue;
|
|---|
| 17210 |
|
|---|
| 17211 | // Add chain sequence methods to the `lodash` wrapper.
|
|---|
| 17212 | lodash.prototype.at = wrapperAt;
|
|---|
| 17213 | lodash.prototype.chain = wrapperChain;
|
|---|
| 17214 | lodash.prototype.commit = wrapperCommit;
|
|---|
| 17215 | lodash.prototype.next = wrapperNext;
|
|---|
| 17216 | lodash.prototype.plant = wrapperPlant;
|
|---|
| 17217 | lodash.prototype.reverse = wrapperReverse;
|
|---|
| 17218 | lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
|---|
| 17219 |
|
|---|
| 17220 | // Add lazy aliases.
|
|---|
| 17221 | lodash.prototype.first = lodash.prototype.head;
|
|---|
| 17222 |
|
|---|
| 17223 | if (symIterator) {
|
|---|
| 17224 | lodash.prototype[symIterator] = wrapperToIterator;
|
|---|
| 17225 | }
|
|---|
| 17226 | return lodash;
|
|---|
| 17227 | });
|
|---|
| 17228 |
|
|---|
| 17229 | /*--------------------------------------------------------------------------*/
|
|---|
| 17230 |
|
|---|
| 17231 | // Export lodash.
|
|---|
| 17232 | var _ = runInContext();
|
|---|
| 17233 |
|
|---|
| 17234 | // Some AMD build optimizers, like r.js, check for condition patterns like:
|
|---|
| 17235 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
|---|
| 17236 | // Expose Lodash on the global object to prevent errors when Lodash is
|
|---|
| 17237 | // loaded by a script tag in the presence of an AMD loader.
|
|---|
| 17238 | // See http://requirejs.org/docs/errors.html#mismatch for more details.
|
|---|
| 17239 | // Use `_.noConflict` to remove Lodash from the global object.
|
|---|
| 17240 | root._ = _;
|
|---|
| 17241 |
|
|---|
| 17242 | // Define as an anonymous module so, through path mapping, it can be
|
|---|
| 17243 | // referenced as the "underscore" module.
|
|---|
| 17244 | define(function() {
|
|---|
| 17245 | return _;
|
|---|
| 17246 | });
|
|---|
| 17247 | }
|
|---|
| 17248 | // Check for `exports` after `define` in case a build optimizer adds it.
|
|---|
| 17249 | else if (freeModule) {
|
|---|
| 17250 | // Export for Node.js.
|
|---|
| 17251 | (freeModule.exports = _)._ = _;
|
|---|
| 17252 | // Export for CommonJS support.
|
|---|
| 17253 | freeExports._ = _;
|
|---|
| 17254 | }
|
|---|
| 17255 | else {
|
|---|
| 17256 | // Export to the global object.
|
|---|
| 17257 | root._ = _;
|
|---|
| 17258 | }
|
|---|
| 17259 | }.call(this));
|
|---|