root / HServer / 00.Server / 00.Program / node_modules / lodash / lodash.js
이력 | 보기 | 이력해설 | 다운로드 (527 KB)
| 1 | 39 | HKM | /**
|
|---|---|---|---|
| 2 | * @license
|
||
| 3 | * Lodash <https://lodash.com/>
|
||
| 4 | * Copyright JS Foundation and other contributors <https://js.foundation/>
|
||
| 5 | * Released under MIT license <https://lodash.com/license>
|
||
| 6 | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
||
| 7 | * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||
| 8 | */
|
||
| 9 | ;(function() {
|
||
| 10 | |||
| 11 | /** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||
| 12 | var undefined; |
||
| 13 | |||
| 14 | /** Used as the semantic version number. */
|
||
| 15 | var VERSION = '4.17.5'; |
||
| 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 | |||
| 24 | /** Used to stand-in for `undefined` hash values. */
|
||
| 25 | var HASH_UNDEFINED = '__lodash_hash_undefined__'; |
||
| 26 | |||
| 27 | /** Used as the maximum memoize cache size. */
|
||
| 28 | var MAX_MEMOIZE_SIZE = 500; |
||
| 29 | |||
| 30 | /** Used as the internal argument placeholder. */
|
||
| 31 | var PLACEHOLDER = '__lodash_placeholder__'; |
||
| 32 | |||
| 33 | /** Used to compose bitmasks for cloning. */
|
||
| 34 | var CLONE_DEEP_FLAG = 1, |
||
| 35 | CLONE_FLAT_FLAG = 2,
|
||
| 36 | CLONE_SYMBOLS_FLAG = 4;
|
||
| 37 | |||
| 38 | /** Used to compose bitmasks for value comparisons. */
|
||
| 39 | var COMPARE_PARTIAL_FLAG = 1, |
||
| 40 | COMPARE_UNORDERED_FLAG = 2;
|
||
| 41 | |||
| 42 | /** Used to compose bitmasks for function metadata. */
|
||
| 43 | var WRAP_BIND_FLAG = 1, |
||
| 44 | WRAP_BIND_KEY_FLAG = 2,
|
||
| 45 | WRAP_CURRY_BOUND_FLAG = 4,
|
||
| 46 | WRAP_CURRY_FLAG = 8,
|
||
| 47 | WRAP_CURRY_RIGHT_FLAG = 16,
|
||
| 48 | WRAP_PARTIAL_FLAG = 32,
|
||
| 49 | WRAP_PARTIAL_RIGHT_FLAG = 64,
|
||
| 50 | WRAP_ARY_FLAG = 128,
|
||
| 51 | WRAP_REARG_FLAG = 256,
|
||
| 52 | WRAP_FLIP_FLAG = 512;
|
||
| 53 | |||
| 54 | /** Used as default options for `_.truncate`. */
|
||
| 55 | var DEFAULT_TRUNC_LENGTH = 30, |
||
| 56 | DEFAULT_TRUNC_OMISSION = '...';
|
||
| 57 | |||
| 58 | /** Used to detect hot functions by number of calls within a span of milliseconds. */
|
||
| 59 | var HOT_COUNT = 800, |
||
| 60 | HOT_SPAN = 16;
|
||
| 61 | |||
| 62 | /** Used to indicate the type of lazy iteratees. */
|
||
| 63 | var LAZY_FILTER_FLAG = 1, |
||
| 64 | LAZY_MAP_FLAG = 2,
|
||
| 65 | LAZY_WHILE_FLAG = 3;
|
||
| 66 | |||
| 67 | /** Used as references for various `Number` constants. */
|
||
| 68 | var INFINITY = 1 / 0, |
||
| 69 | MAX_SAFE_INTEGER = 9007199254740991,
|
||
| 70 | MAX_INTEGER = 1.7976931348623157e+308,
|
||
| 71 | NAN = 0 / 0; |
||
| 72 | |||
| 73 | /** Used as references for the maximum length and index of an array. */
|
||
| 74 | var MAX_ARRAY_LENGTH = 4294967295, |
||
| 75 | MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
|
||
| 76 | HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
||
| 77 | |||
| 78 | /** Used to associate wrap methods with their bit flags. */
|
||
| 79 | var wrapFlags = [
|
||
| 80 | ['ary', WRAP_ARY_FLAG],
|
||
| 81 | ['bind', WRAP_BIND_FLAG],
|
||
| 82 | ['bindKey', WRAP_BIND_KEY_FLAG],
|
||
| 83 | ['curry', WRAP_CURRY_FLAG],
|
||
| 84 | ['curryRight', WRAP_CURRY_RIGHT_FLAG],
|
||
| 85 | ['flip', WRAP_FLIP_FLAG],
|
||
| 86 | ['partial', WRAP_PARTIAL_FLAG],
|
||
| 87 | ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
|
||
| 88 | ['rearg', WRAP_REARG_FLAG]
|
||
| 89 | ]; |
||
| 90 | |||
| 91 | /** `Object#toString` result references. */
|
||
| 92 | var argsTag = '[object Arguments]', |
||
| 93 | arrayTag = '[object Array]',
|
||
| 94 | asyncTag = '[object AsyncFunction]',
|
||
| 95 | boolTag = '[object Boolean]',
|
||
| 96 | dateTag = '[object Date]',
|
||
| 97 | domExcTag = '[object DOMException]',
|
||
| 98 | errorTag = '[object Error]',
|
||
| 99 | funcTag = '[object Function]',
|
||
| 100 | genTag = '[object GeneratorFunction]',
|
||
| 101 | mapTag = '[object Map]',
|
||
| 102 | numberTag = '[object Number]',
|
||
| 103 | nullTag = '[object Null]',
|
||
| 104 | objectTag = '[object Object]',
|
||
| 105 | promiseTag = '[object Promise]',
|
||
| 106 | proxyTag = '[object Proxy]',
|
||
| 107 | regexpTag = '[object RegExp]',
|
||
| 108 | setTag = '[object Set]',
|
||
| 109 | stringTag = '[object String]',
|
||
| 110 | symbolTag = '[object Symbol]',
|
||
| 111 | undefinedTag = '[object Undefined]',
|
||
| 112 | weakMapTag = '[object WeakMap]',
|
||
| 113 | weakSetTag = '[object WeakSet]';
|
||
| 114 | |||
| 115 | var arrayBufferTag = '[object ArrayBuffer]', |
||
| 116 | dataViewTag = '[object DataView]',
|
||
| 117 | float32Tag = '[object Float32Array]',
|
||
| 118 | float64Tag = '[object Float64Array]',
|
||
| 119 | int8Tag = '[object Int8Array]',
|
||
| 120 | int16Tag = '[object Int16Array]',
|
||
| 121 | int32Tag = '[object Int32Array]',
|
||
| 122 | uint8Tag = '[object Uint8Array]',
|
||
| 123 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
||
| 124 | uint16Tag = '[object Uint16Array]',
|
||
| 125 | uint32Tag = '[object Uint32Array]';
|
||
| 126 | |||
| 127 | /** Used to match empty string literals in compiled template source. */
|
||
| 128 | var reEmptyStringLeading = /\b__p \+= '';/g, |
||
| 129 | reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
||
| 130 | reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
|
||
| 131 | |||
| 132 | /** Used to match HTML entities and HTML characters. */
|
||
| 133 | var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, |
||
| 134 | reUnescapedHtml = /[&<>"']/g,
|
||
| 135 | reHasEscapedHtml = RegExp(reEscapedHtml.source), |
||
| 136 | reHasUnescapedHtml = RegExp(reUnescapedHtml.source); |
||
| 137 | |||
| 138 | /** Used to match template delimiters. */
|
||
| 139 | var reEscape = /<%-([\s\S]+?)%>/g, |
||
| 140 | reEvaluate = /<%([\s\S]+?)%>/g,
|
||
| 141 | reInterpolate = /<%=([\s\S]+?)%>/g;
|
||
| 142 | |||
| 143 | /** Used to match property names within property paths. */
|
||
| 144 | var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, |
||
| 145 | reIsPlainProp = /^\w*$/,
|
||
| 146 | rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
||
| 147 | |||
| 148 | /**
|
||
| 149 | * Used to match `RegExp`
|
||
| 150 | * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
||
| 151 | */
|
||
| 152 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, |
||
| 153 | reHasRegExpChar = RegExp(reRegExpChar.source); |
||
| 154 | |||
| 155 | /** Used to match leading and trailing whitespace. */
|
||
| 156 | var reTrim = /^\s+|\s+$/g, |
||
| 157 | reTrimStart = /^\s+/,
|
||
| 158 | reTrimEnd = /\s+$/;
|
||
| 159 | |||
| 160 | /** Used to match wrap detail comments. */
|
||
| 161 | var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, |
||
| 162 | reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
|
||
| 163 | reSplitDetails = /,? & /;
|
||
| 164 | |||
| 165 | /** Used to match words composed of alphanumeric characters. */
|
||
| 166 | var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; |
||
| 167 | |||
| 168 | /** Used to match backslashes in property paths. */
|
||
| 169 | var reEscapeChar = /\\(\\)?/g; |
||
| 170 | |||
| 171 | /**
|
||
| 172 | * Used to match
|
||
| 173 | * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
|
||
| 174 | */
|
||
| 175 | var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; |
||
| 176 | |||
| 177 | /** Used to match `RegExp` flags from their coerced string values. */
|
||
| 178 | var reFlags = /\w*$/; |
||
| 179 | |||
| 180 | /** Used to detect bad signed hexadecimal string values. */
|
||
| 181 | var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; |
||
| 182 | |||
| 183 | /** Used to detect binary string values. */
|
||
| 184 | var reIsBinary = /^0b[01]+$/i; |
||
| 185 | |||
| 186 | /** Used to detect host constructors (Safari). */
|
||
| 187 | var reIsHostCtor = /^\[object .+?Constructor\]$/; |
||
| 188 | |||
| 189 | /** Used to detect octal string values. */
|
||
| 190 | var reIsOctal = /^0o[0-7]+$/i; |
||
| 191 | |||
| 192 | /** Used to detect unsigned integer values. */
|
||
| 193 | var reIsUint = /^(?:0|[1-9]\d*)$/; |
||
| 194 | |||
| 195 | /** Used to match Latin Unicode letters (excluding mathematical operators). */
|
||
| 196 | var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; |
||
| 197 | |||
| 198 | /** Used to ensure capturing order of template delimiters. */
|
||
| 199 | var reNoMatch = /($^)/; |
||
| 200 | |||
| 201 | /** Used to match unescaped characters in compiled string literals. */
|
||
| 202 | var reUnescapedString = /['\n\r\u2028\u2029\\]/g; |
||
| 203 | |||
| 204 | /** Used to compose unicode character classes. */
|
||
| 205 | var rsAstralRange = '\\ud800-\\udfff', |
||
| 206 | rsComboMarksRange = '\\u0300-\\u036f',
|
||
| 207 | reComboHalfMarksRange = '\\ufe20-\\ufe2f',
|
||
| 208 | rsComboSymbolsRange = '\\u20d0-\\u20ff',
|
||
| 209 | rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, |
||
| 210 | rsDingbatRange = '\\u2700-\\u27bf',
|
||
| 211 | rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
|
||
| 212 | rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
|
||
| 213 | rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
|
||
| 214 | rsPunctuationRange = '\\u2000-\\u206f',
|
||
| 215 | 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',
|
||
| 216 | rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
|
||
| 217 | rsVarRange = '\\ufe0e\\ufe0f',
|
||
| 218 | rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; |
||
| 219 | |||
| 220 | /** Used to compose unicode capture groups. */
|
||
| 221 | var rsApos = "['\u2019]", |
||
| 222 | rsAstral = '[' + rsAstralRange + ']', |
||
| 223 | rsBreak = '[' + rsBreakRange + ']', |
||
| 224 | rsCombo = '[' + rsComboRange + ']', |
||
| 225 | rsDigits = '\\d+',
|
||
| 226 | rsDingbat = '[' + rsDingbatRange + ']', |
||
| 227 | rsLower = '[' + rsLowerRange + ']', |
||
| 228 | rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', |
||
| 229 | rsFitz = '\\ud83c[\\udffb-\\udfff]',
|
||
| 230 | rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', |
||
| 231 | rsNonAstral = '[^' + rsAstralRange + ']', |
||
| 232 | rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
|
||
| 233 | rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
|
||
| 234 | rsUpper = '[' + rsUpperRange + ']', |
||
| 235 | rsZWJ = '\\u200d';
|
||
| 236 | |||
| 237 | /** Used to compose unicode regexes. */
|
||
| 238 | var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', |
||
| 239 | rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', |
||
| 240 | rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', |
||
| 241 | rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', |
||
| 242 | reOptMod = rsModifier + '?',
|
||
| 243 | rsOptVar = '[' + rsVarRange + ']?', |
||
| 244 | rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', |
||
| 245 | rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
|
||
| 246 | rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
|
||
| 247 | rsSeq = rsOptVar + reOptMod + rsOptJoin, |
||
| 248 | rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, |
||
| 249 | rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; |
||
| 250 | |||
| 251 | /** Used to match apostrophes. */
|
||
| 252 | var reApos = RegExp(rsApos, 'g'); |
||
| 253 | |||
| 254 | /**
|
||
| 255 | * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
|
||
| 256 | * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
|
||
| 257 | */
|
||
| 258 | var reComboMark = RegExp(rsCombo, 'g'); |
||
| 259 | |||
| 260 | /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
|
||
| 261 | var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); |
||
| 262 | |||
| 263 | /** Used to match complex or compound words. */
|
||
| 264 | var reUnicodeWord = RegExp([
|
||
| 265 | rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', |
||
| 266 | rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', |
||
| 267 | rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, |
||
| 268 | rsUpper + '+' + rsOptContrUpper,
|
||
| 269 | rsOrdUpper, |
||
| 270 | rsOrdLower, |
||
| 271 | rsDigits, |
||
| 272 | rsEmoji |
||
| 273 | ].join('|'), 'g'); |
||
| 274 | |||
| 275 | /** 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/). */
|
||
| 276 | var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); |
||
| 277 | |||
| 278 | /** Used to detect strings that need a more robust regexp to match words. */
|
||
| 279 | 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 ]/; |
||
| 280 | |||
| 281 | /** Used to assign default `context` object properties. */
|
||
| 282 | var contextProps = [
|
||
| 283 | 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', |
||
| 284 | 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', |
||
| 285 | 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', |
||
| 286 | 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', |
||
| 287 | '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' |
||
| 288 | ]; |
||
| 289 | |||
| 290 | /** Used to make template sourceURLs easier to identify. */
|
||
| 291 | var templateCounter = -1; |
||
| 292 | |||
| 293 | /** Used to identify `toStringTag` values of typed arrays. */
|
||
| 294 | var typedArrayTags = {};
|
||
| 295 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = |
||
| 296 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = |
||
| 297 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = |
||
| 298 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = |
||
| 299 | typedArrayTags[uint32Tag] = true;
|
||
| 300 | typedArrayTags[argsTag] = typedArrayTags[arrayTag] = |
||
| 301 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = |
||
| 302 | typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = |
||
| 303 | typedArrayTags[errorTag] = typedArrayTags[funcTag] = |
||
| 304 | typedArrayTags[mapTag] = typedArrayTags[numberTag] = |
||
| 305 | typedArrayTags[objectTag] = typedArrayTags[regexpTag] = |
||
| 306 | typedArrayTags[setTag] = typedArrayTags[stringTag] = |
||
| 307 | typedArrayTags[weakMapTag] = false;
|
||
| 308 | |||
| 309 | /** Used to identify `toStringTag` values supported by `_.clone`. */
|
||
| 310 | var cloneableTags = {};
|
||
| 311 | cloneableTags[argsTag] = cloneableTags[arrayTag] = |
||
| 312 | cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = |
||
| 313 | cloneableTags[boolTag] = cloneableTags[dateTag] = |
||
| 314 | cloneableTags[float32Tag] = cloneableTags[float64Tag] = |
||
| 315 | cloneableTags[int8Tag] = cloneableTags[int16Tag] = |
||
| 316 | cloneableTags[int32Tag] = cloneableTags[mapTag] = |
||
| 317 | cloneableTags[numberTag] = cloneableTags[objectTag] = |
||
| 318 | cloneableTags[regexpTag] = cloneableTags[setTag] = |
||
| 319 | cloneableTags[stringTag] = cloneableTags[symbolTag] = |
||
| 320 | cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = |
||
| 321 | cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
||
| 322 | cloneableTags[errorTag] = cloneableTags[funcTag] = |
||
| 323 | cloneableTags[weakMapTag] = false;
|
||
| 324 | |||
| 325 | /** Used to map Latin Unicode letters to basic Latin letters. */
|
||
| 326 | var deburredLetters = {
|
||
| 327 | // Latin-1 Supplement block.
|
||
| 328 | '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', |
||
| 329 | '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', |
||
| 330 | '\xc7': 'C', '\xe7': 'c', |
||
| 331 | '\xd0': 'D', '\xf0': 'd', |
||
| 332 | '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', |
||
| 333 | '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', |
||
| 334 | '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', |
||
| 335 | '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', |
||
| 336 | '\xd1': 'N', '\xf1': 'n', |
||
| 337 | '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', |
||
| 338 | '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', |
||
| 339 | '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', |
||
| 340 | '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', |
||
| 341 | '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', |
||
| 342 | '\xc6': 'Ae', '\xe6': 'ae', |
||
| 343 | '\xde': 'Th', '\xfe': 'th', |
||
| 344 | '\xdf': 'ss', |
||
| 345 | // Latin Extended-A block.
|
||
| 346 | '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', |
||
| 347 | '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', |
||
| 348 | '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', |
||
| 349 | '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', |
||
| 350 | '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', |
||
| 351 | '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', |
||
| 352 | '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', |
||
| 353 | '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', |
||
| 354 | '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', |
||
| 355 | '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', |
||
| 356 | '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', |
||
| 357 | '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', |
||
| 358 | '\u0134': 'J', '\u0135': 'j', |
||
| 359 | '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', |
||
| 360 | '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', |
||
| 361 | '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', |
||
| 362 | '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', |
||
| 363 | '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', |
||
| 364 | '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', |
||
| 365 | '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', |
||
| 366 | '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', |
||
| 367 | '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', |
||
| 368 | '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', |
||
| 369 | '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', |
||
| 370 | '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', |
||
| 371 | '\u0163': 't', '\u0165': 't', '\u0167': 't', |
||
| 372 | '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', |
||
| 373 | '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', |
||
| 374 | '\u0174': 'W', '\u0175': 'w', |
||
| 375 | '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', |
||
| 376 | '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', |
||
| 377 | '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', |
||
| 378 | '\u0132': 'IJ', '\u0133': 'ij', |
||
| 379 | '\u0152': 'Oe', '\u0153': 'oe', |
||
| 380 | '\u0149': "'n", '\u017f': 's' |
||
| 381 | }; |
||
| 382 | |||
| 383 | /** Used to map characters to HTML entities. */
|
||
| 384 | var htmlEscapes = {
|
||
| 385 | '&': '&', |
||
| 386 | '<': '<', |
||
| 387 | '>': '>', |
||
| 388 | '"': '"', |
||
| 389 | "'": ''' |
||
| 390 | }; |
||
| 391 | |||
| 392 | /** Used to map HTML entities to characters. */
|
||
| 393 | var htmlUnescapes = {
|
||
| 394 | '&': '&', |
||
| 395 | '<': '<', |
||
| 396 | '>': '>', |
||
| 397 | '"': '"', |
||
| 398 | ''': "'" |
||
| 399 | }; |
||
| 400 | |||
| 401 | /** Used to escape characters for inclusion in compiled string literals. */
|
||
| 402 | var stringEscapes = {
|
||
| 403 | '\\': '\\', |
||
| 404 | "'": "'", |
||
| 405 | '\n': 'n', |
||
| 406 | '\r': 'r', |
||
| 407 | '\u2028': 'u2028', |
||
| 408 | '\u2029': 'u2029' |
||
| 409 | }; |
||
| 410 | |||
| 411 | /** Built-in method references without a dependency on `root`. */
|
||
| 412 | var freeParseFloat = parseFloat,
|
||
| 413 | freeParseInt = parseInt; |
||
| 414 | |||
| 415 | /** Detect free variable `global` from Node.js. */
|
||
| 416 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; |
||
| 417 | |||
| 418 | /** Detect free variable `self`. */
|
||
| 419 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self; |
||
| 420 | |||
| 421 | /** Used as a reference to the global object. */
|
||
| 422 | var root = freeGlobal || freeSelf || Function('return this')(); |
||
| 423 | |||
| 424 | /** Detect free variable `exports`. */
|
||
| 425 | var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; |
||
| 426 | |||
| 427 | /** Detect free variable `module`. */
|
||
| 428 | var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; |
||
| 429 | |||
| 430 | /** Detect the popular CommonJS extension `module.exports`. */
|
||
| 431 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
||
| 432 | |||
| 433 | /** Detect free variable `process` from Node.js. */
|
||
| 434 | var freeProcess = moduleExports && freeGlobal.process;
|
||
| 435 | |||
| 436 | /** Used to access faster Node.js helpers. */
|
||
| 437 | var nodeUtil = (function() { |
||
| 438 | try {
|
||
| 439 | return freeProcess && freeProcess.binding && freeProcess.binding('util'); |
||
| 440 | } catch (e) {}
|
||
| 441 | }()); |
||
| 442 | |||
| 443 | /* Node.js helper references. */
|
||
| 444 | var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
|
||
| 445 | nodeIsDate = nodeUtil && nodeUtil.isDate, |
||
| 446 | nodeIsMap = nodeUtil && nodeUtil.isMap, |
||
| 447 | nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, |
||
| 448 | nodeIsSet = nodeUtil && nodeUtil.isSet, |
||
| 449 | nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; |
||
| 450 | |||
| 451 | /*--------------------------------------------------------------------------*/
|
||
| 452 | |||
| 453 | /**
|
||
| 454 | * A faster alternative to `Function#apply`, this function invokes `func`
|
||
| 455 | * with the `this` binding of `thisArg` and the arguments of `args`.
|
||
| 456 | *
|
||
| 457 | * @private
|
||
| 458 | * @param {Function} func The function to invoke.
|
||
| 459 | * @param {*} thisArg The `this` binding of `func`.
|
||
| 460 | * @param {Array} args The arguments to invoke `func` with.
|
||
| 461 | * @returns {*} Returns the result of `func`.
|
||
| 462 | */
|
||
| 463 | function apply(func, thisArg, args) { |
||
| 464 | switch (args.length) {
|
||
| 465 | case 0: return func.call(thisArg); |
||
| 466 | case 1: return func.call(thisArg, args[0]); |
||
| 467 | case 2: return func.call(thisArg, args[0], args[1]); |
||
| 468 | case 3: return func.call(thisArg, args[0], args[1], args[2]); |
||
| 469 | } |
||
| 470 | return func.apply(thisArg, args);
|
||
| 471 | } |
||
| 472 | |||
| 473 | /**
|
||
| 474 | * A specialized version of `baseAggregator` for arrays.
|
||
| 475 | *
|
||
| 476 | * @private
|
||
| 477 | * @param {Array} [array] The array to iterate over.
|
||
| 478 | * @param {Function} setter The function to set `accumulator` values.
|
||
| 479 | * @param {Function} iteratee The iteratee to transform keys.
|
||
| 480 | * @param {Object} accumulator The initial aggregated object.
|
||
| 481 | * @returns {Function} Returns `accumulator`.
|
||
| 482 | */
|
||
| 483 | function arrayAggregator(array, setter, iteratee, accumulator) { |
||
| 484 | var index = -1, |
||
| 485 | length = array == null ? 0 : array.length; |
||
| 486 | |||
| 487 | while (++index < length) {
|
||
| 488 | var value = array[index];
|
||
| 489 | setter(accumulator, value, iteratee(value), array); |
||
| 490 | } |
||
| 491 | return accumulator;
|
||
| 492 | } |
||
| 493 | |||
| 494 | /**
|
||
| 495 | * A specialized version of `_.forEach` for arrays without support for
|
||
| 496 | * iteratee shorthands.
|
||
| 497 | *
|
||
| 498 | * @private
|
||
| 499 | * @param {Array} [array] The array to iterate over.
|
||
| 500 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 501 | * @returns {Array} Returns `array`.
|
||
| 502 | */
|
||
| 503 | function arrayEach(array, iteratee) { |
||
| 504 | var index = -1, |
||
| 505 | length = array == null ? 0 : array.length; |
||
| 506 | |||
| 507 | while (++index < length) {
|
||
| 508 | if (iteratee(array[index], index, array) === false) { |
||
| 509 | break;
|
||
| 510 | } |
||
| 511 | } |
||
| 512 | return array;
|
||
| 513 | } |
||
| 514 | |||
| 515 | /**
|
||
| 516 | * A specialized version of `_.forEachRight` for arrays without support for
|
||
| 517 | * iteratee shorthands.
|
||
| 518 | *
|
||
| 519 | * @private
|
||
| 520 | * @param {Array} [array] The array to iterate over.
|
||
| 521 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 522 | * @returns {Array} Returns `array`.
|
||
| 523 | */
|
||
| 524 | function arrayEachRight(array, iteratee) { |
||
| 525 | var length = array == null ? 0 : array.length; |
||
| 526 | |||
| 527 | while (length--) {
|
||
| 528 | if (iteratee(array[length], length, array) === false) { |
||
| 529 | break;
|
||
| 530 | } |
||
| 531 | } |
||
| 532 | return array;
|
||
| 533 | } |
||
| 534 | |||
| 535 | /**
|
||
| 536 | * A specialized version of `_.every` for arrays without support for
|
||
| 537 | * iteratee shorthands.
|
||
| 538 | *
|
||
| 539 | * @private
|
||
| 540 | * @param {Array} [array] The array to iterate over.
|
||
| 541 | * @param {Function} predicate The function invoked per iteration.
|
||
| 542 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
||
| 543 | * else `false`.
|
||
| 544 | */
|
||
| 545 | function arrayEvery(array, predicate) { |
||
| 546 | var index = -1, |
||
| 547 | length = array == null ? 0 : array.length; |
||
| 548 | |||
| 549 | while (++index < length) {
|
||
| 550 | if (!predicate(array[index], index, array)) {
|
||
| 551 | return false; |
||
| 552 | } |
||
| 553 | } |
||
| 554 | return true; |
||
| 555 | } |
||
| 556 | |||
| 557 | /**
|
||
| 558 | * A specialized version of `_.filter` for arrays without support for
|
||
| 559 | * iteratee shorthands.
|
||
| 560 | *
|
||
| 561 | * @private
|
||
| 562 | * @param {Array} [array] The array to iterate over.
|
||
| 563 | * @param {Function} predicate The function invoked per iteration.
|
||
| 564 | * @returns {Array} Returns the new filtered array.
|
||
| 565 | */
|
||
| 566 | function arrayFilter(array, predicate) { |
||
| 567 | var index = -1, |
||
| 568 | length = array == null ? 0 : array.length, |
||
| 569 | resIndex = 0,
|
||
| 570 | result = []; |
||
| 571 | |||
| 572 | while (++index < length) {
|
||
| 573 | var value = array[index];
|
||
| 574 | if (predicate(value, index, array)) {
|
||
| 575 | result[resIndex++] = value; |
||
| 576 | } |
||
| 577 | } |
||
| 578 | return result;
|
||
| 579 | } |
||
| 580 | |||
| 581 | /**
|
||
| 582 | * A specialized version of `_.includes` for arrays without support for
|
||
| 583 | * specifying an index to search from.
|
||
| 584 | *
|
||
| 585 | * @private
|
||
| 586 | * @param {Array} [array] The array to inspect.
|
||
| 587 | * @param {*} target The value to search for.
|
||
| 588 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
||
| 589 | */
|
||
| 590 | function arrayIncludes(array, value) { |
||
| 591 | var length = array == null ? 0 : array.length; |
||
| 592 | return !!length && baseIndexOf(array, value, 0) > -1; |
||
| 593 | } |
||
| 594 | |||
| 595 | /**
|
||
| 596 | * This function is like `arrayIncludes` except that it accepts a comparator.
|
||
| 597 | *
|
||
| 598 | * @private
|
||
| 599 | * @param {Array} [array] The array to inspect.
|
||
| 600 | * @param {*} target The value to search for.
|
||
| 601 | * @param {Function} comparator The comparator invoked per element.
|
||
| 602 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
||
| 603 | */
|
||
| 604 | function arrayIncludesWith(array, value, comparator) { |
||
| 605 | var index = -1, |
||
| 606 | length = array == null ? 0 : array.length; |
||
| 607 | |||
| 608 | while (++index < length) {
|
||
| 609 | if (comparator(value, array[index])) {
|
||
| 610 | return true; |
||
| 611 | } |
||
| 612 | } |
||
| 613 | return false; |
||
| 614 | } |
||
| 615 | |||
| 616 | /**
|
||
| 617 | * A specialized version of `_.map` for arrays without support for iteratee
|
||
| 618 | * shorthands.
|
||
| 619 | *
|
||
| 620 | * @private
|
||
| 621 | * @param {Array} [array] The array to iterate over.
|
||
| 622 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 623 | * @returns {Array} Returns the new mapped array.
|
||
| 624 | */
|
||
| 625 | function arrayMap(array, iteratee) { |
||
| 626 | var index = -1, |
||
| 627 | length = array == null ? 0 : array.length, |
||
| 628 | result = Array(length); |
||
| 629 | |||
| 630 | while (++index < length) {
|
||
| 631 | result[index] = iteratee(array[index], index, array); |
||
| 632 | } |
||
| 633 | return result;
|
||
| 634 | } |
||
| 635 | |||
| 636 | /**
|
||
| 637 | * Appends the elements of `values` to `array`.
|
||
| 638 | *
|
||
| 639 | * @private
|
||
| 640 | * @param {Array} array The array to modify.
|
||
| 641 | * @param {Array} values The values to append.
|
||
| 642 | * @returns {Array} Returns `array`.
|
||
| 643 | */
|
||
| 644 | function arrayPush(array, values) { |
||
| 645 | var index = -1, |
||
| 646 | length = values.length, |
||
| 647 | offset = array.length; |
||
| 648 | |||
| 649 | while (++index < length) {
|
||
| 650 | array[offset + index] = values[index]; |
||
| 651 | } |
||
| 652 | return array;
|
||
| 653 | } |
||
| 654 | |||
| 655 | /**
|
||
| 656 | * A specialized version of `_.reduce` for arrays without support for
|
||
| 657 | * iteratee shorthands.
|
||
| 658 | *
|
||
| 659 | * @private
|
||
| 660 | * @param {Array} [array] The array to iterate over.
|
||
| 661 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 662 | * @param {*} [accumulator] The initial value.
|
||
| 663 | * @param {boolean} [initAccum] Specify using the first element of `array` as
|
||
| 664 | * the initial value.
|
||
| 665 | * @returns {*} Returns the accumulated value.
|
||
| 666 | */
|
||
| 667 | function arrayReduce(array, iteratee, accumulator, initAccum) { |
||
| 668 | var index = -1, |
||
| 669 | length = array == null ? 0 : array.length; |
||
| 670 | |||
| 671 | if (initAccum && length) {
|
||
| 672 | accumulator = array[++index]; |
||
| 673 | } |
||
| 674 | while (++index < length) {
|
||
| 675 | accumulator = iteratee(accumulator, array[index], index, array); |
||
| 676 | } |
||
| 677 | return accumulator;
|
||
| 678 | } |
||
| 679 | |||
| 680 | /**
|
||
| 681 | * A specialized version of `_.reduceRight` for arrays without support for
|
||
| 682 | * iteratee shorthands.
|
||
| 683 | *
|
||
| 684 | * @private
|
||
| 685 | * @param {Array} [array] The array to iterate over.
|
||
| 686 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 687 | * @param {*} [accumulator] The initial value.
|
||
| 688 | * @param {boolean} [initAccum] Specify using the last element of `array` as
|
||
| 689 | * the initial value.
|
||
| 690 | * @returns {*} Returns the accumulated value.
|
||
| 691 | */
|
||
| 692 | function arrayReduceRight(array, iteratee, accumulator, initAccum) { |
||
| 693 | var length = array == null ? 0 : array.length; |
||
| 694 | if (initAccum && length) {
|
||
| 695 | accumulator = array[--length]; |
||
| 696 | } |
||
| 697 | while (length--) {
|
||
| 698 | accumulator = iteratee(accumulator, array[length], length, array); |
||
| 699 | } |
||
| 700 | return accumulator;
|
||
| 701 | } |
||
| 702 | |||
| 703 | /**
|
||
| 704 | * A specialized version of `_.some` for arrays without support for iteratee
|
||
| 705 | * shorthands.
|
||
| 706 | *
|
||
| 707 | * @private
|
||
| 708 | * @param {Array} [array] The array to iterate over.
|
||
| 709 | * @param {Function} predicate The function invoked per iteration.
|
||
| 710 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
||
| 711 | * else `false`.
|
||
| 712 | */
|
||
| 713 | function arraySome(array, predicate) { |
||
| 714 | var index = -1, |
||
| 715 | length = array == null ? 0 : array.length; |
||
| 716 | |||
| 717 | while (++index < length) {
|
||
| 718 | if (predicate(array[index], index, array)) {
|
||
| 719 | return true; |
||
| 720 | } |
||
| 721 | } |
||
| 722 | return false; |
||
| 723 | } |
||
| 724 | |||
| 725 | /**
|
||
| 726 | * Gets the size of an ASCII `string`.
|
||
| 727 | *
|
||
| 728 | * @private
|
||
| 729 | * @param {string} string The string inspect.
|
||
| 730 | * @returns {number} Returns the string size.
|
||
| 731 | */
|
||
| 732 | var asciiSize = baseProperty('length'); |
||
| 733 | |||
| 734 | /**
|
||
| 735 | * Converts an ASCII `string` to an array.
|
||
| 736 | *
|
||
| 737 | * @private
|
||
| 738 | * @param {string} string The string to convert.
|
||
| 739 | * @returns {Array} Returns the converted array.
|
||
| 740 | */
|
||
| 741 | function asciiToArray(string) { |
||
| 742 | return string.split(''); |
||
| 743 | } |
||
| 744 | |||
| 745 | /**
|
||
| 746 | * Splits an ASCII `string` into an array of its words.
|
||
| 747 | *
|
||
| 748 | * @private
|
||
| 749 | * @param {string} The string to inspect.
|
||
| 750 | * @returns {Array} Returns the words of `string`.
|
||
| 751 | */
|
||
| 752 | function asciiWords(string) { |
||
| 753 | return string.match(reAsciiWord) || [];
|
||
| 754 | } |
||
| 755 | |||
| 756 | /**
|
||
| 757 | * The base implementation of methods like `_.findKey` and `_.findLastKey`,
|
||
| 758 | * without support for iteratee shorthands, which iterates over `collection`
|
||
| 759 | * using `eachFunc`.
|
||
| 760 | *
|
||
| 761 | * @private
|
||
| 762 | * @param {Array|Object} collection The collection to inspect.
|
||
| 763 | * @param {Function} predicate The function invoked per iteration.
|
||
| 764 | * @param {Function} eachFunc The function to iterate over `collection`.
|
||
| 765 | * @returns {*} Returns the found element or its key, else `undefined`.
|
||
| 766 | */
|
||
| 767 | function baseFindKey(collection, predicate, eachFunc) { |
||
| 768 | var result;
|
||
| 769 | eachFunc(collection, function(value, key, collection) {
|
||
| 770 | if (predicate(value, key, collection)) {
|
||
| 771 | result = key; |
||
| 772 | return false; |
||
| 773 | } |
||
| 774 | }); |
||
| 775 | return result;
|
||
| 776 | } |
||
| 777 | |||
| 778 | /**
|
||
| 779 | * The base implementation of `_.findIndex` and `_.findLastIndex` without
|
||
| 780 | * support for iteratee shorthands.
|
||
| 781 | *
|
||
| 782 | * @private
|
||
| 783 | * @param {Array} array The array to inspect.
|
||
| 784 | * @param {Function} predicate The function invoked per iteration.
|
||
| 785 | * @param {number} fromIndex The index to search from.
|
||
| 786 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
||
| 787 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 788 | */
|
||
| 789 | function baseFindIndex(array, predicate, fromIndex, fromRight) { |
||
| 790 | var length = array.length,
|
||
| 791 | index = fromIndex + (fromRight ? 1 : -1); |
||
| 792 | |||
| 793 | while ((fromRight ? index-- : ++index < length)) {
|
||
| 794 | if (predicate(array[index], index, array)) {
|
||
| 795 | return index;
|
||
| 796 | } |
||
| 797 | } |
||
| 798 | return -1; |
||
| 799 | } |
||
| 800 | |||
| 801 | /**
|
||
| 802 | * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
|
||
| 803 | *
|
||
| 804 | * @private
|
||
| 805 | * @param {Array} array The array to inspect.
|
||
| 806 | * @param {*} value The value to search for.
|
||
| 807 | * @param {number} fromIndex The index to search from.
|
||
| 808 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 809 | */
|
||
| 810 | function baseIndexOf(array, value, fromIndex) { |
||
| 811 | return value === value
|
||
| 812 | ? strictIndexOf(array, value, fromIndex) |
||
| 813 | : baseFindIndex(array, baseIsNaN, fromIndex); |
||
| 814 | } |
||
| 815 | |||
| 816 | /**
|
||
| 817 | * This function is like `baseIndexOf` except that it accepts a comparator.
|
||
| 818 | *
|
||
| 819 | * @private
|
||
| 820 | * @param {Array} array The array to inspect.
|
||
| 821 | * @param {*} value The value to search for.
|
||
| 822 | * @param {number} fromIndex The index to search from.
|
||
| 823 | * @param {Function} comparator The comparator invoked per element.
|
||
| 824 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 825 | */
|
||
| 826 | function baseIndexOfWith(array, value, fromIndex, comparator) { |
||
| 827 | var index = fromIndex - 1, |
||
| 828 | length = array.length; |
||
| 829 | |||
| 830 | while (++index < length) {
|
||
| 831 | if (comparator(array[index], value)) {
|
||
| 832 | return index;
|
||
| 833 | } |
||
| 834 | } |
||
| 835 | return -1; |
||
| 836 | } |
||
| 837 | |||
| 838 | /**
|
||
| 839 | * The base implementation of `_.isNaN` without support for number objects.
|
||
| 840 | *
|
||
| 841 | * @private
|
||
| 842 | * @param {*} value The value to check.
|
||
| 843 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
||
| 844 | */
|
||
| 845 | function baseIsNaN(value) { |
||
| 846 | return value !== value;
|
||
| 847 | } |
||
| 848 | |||
| 849 | /**
|
||
| 850 | * The base implementation of `_.mean` and `_.meanBy` without support for
|
||
| 851 | * iteratee shorthands.
|
||
| 852 | *
|
||
| 853 | * @private
|
||
| 854 | * @param {Array} array The array to iterate over.
|
||
| 855 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 856 | * @returns {number} Returns the mean.
|
||
| 857 | */
|
||
| 858 | function baseMean(array, iteratee) { |
||
| 859 | var length = array == null ? 0 : array.length; |
||
| 860 | return length ? (baseSum(array, iteratee) / length) : NAN;
|
||
| 861 | } |
||
| 862 | |||
| 863 | /**
|
||
| 864 | * The base implementation of `_.property` without support for deep paths.
|
||
| 865 | *
|
||
| 866 | * @private
|
||
| 867 | * @param {string} key The key of the property to get.
|
||
| 868 | * @returns {Function} Returns the new accessor function.
|
||
| 869 | */
|
||
| 870 | function baseProperty(key) { |
||
| 871 | return function(object) { |
||
| 872 | return object == null ? undefined : object[key]; |
||
| 873 | }; |
||
| 874 | } |
||
| 875 | |||
| 876 | /**
|
||
| 877 | * The base implementation of `_.propertyOf` without support for deep paths.
|
||
| 878 | *
|
||
| 879 | * @private
|
||
| 880 | * @param {Object} object The object to query.
|
||
| 881 | * @returns {Function} Returns the new accessor function.
|
||
| 882 | */
|
||
| 883 | function basePropertyOf(object) { |
||
| 884 | return function(key) { |
||
| 885 | return object == null ? undefined : object[key]; |
||
| 886 | }; |
||
| 887 | } |
||
| 888 | |||
| 889 | /**
|
||
| 890 | * The base implementation of `_.reduce` and `_.reduceRight`, without support
|
||
| 891 | * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
|
||
| 892 | *
|
||
| 893 | * @private
|
||
| 894 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 895 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 896 | * @param {*} accumulator The initial value.
|
||
| 897 | * @param {boolean} initAccum Specify using the first or last element of
|
||
| 898 | * `collection` as the initial value.
|
||
| 899 | * @param {Function} eachFunc The function to iterate over `collection`.
|
||
| 900 | * @returns {*} Returns the accumulated value.
|
||
| 901 | */
|
||
| 902 | function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { |
||
| 903 | eachFunc(collection, function(value, index, collection) {
|
||
| 904 | accumulator = initAccum |
||
| 905 | ? (initAccum = false, value)
|
||
| 906 | : iteratee(accumulator, value, index, collection); |
||
| 907 | }); |
||
| 908 | return accumulator;
|
||
| 909 | } |
||
| 910 | |||
| 911 | /**
|
||
| 912 | * The base implementation of `_.sortBy` which uses `comparer` to define the
|
||
| 913 | * sort order of `array` and replaces criteria objects with their corresponding
|
||
| 914 | * values.
|
||
| 915 | *
|
||
| 916 | * @private
|
||
| 917 | * @param {Array} array The array to sort.
|
||
| 918 | * @param {Function} comparer The function to define sort order.
|
||
| 919 | * @returns {Array} Returns `array`.
|
||
| 920 | */
|
||
| 921 | function baseSortBy(array, comparer) { |
||
| 922 | var length = array.length;
|
||
| 923 | |||
| 924 | array.sort(comparer); |
||
| 925 | while (length--) {
|
||
| 926 | array[length] = array[length].value; |
||
| 927 | } |
||
| 928 | return array;
|
||
| 929 | } |
||
| 930 | |||
| 931 | /**
|
||
| 932 | * The base implementation of `_.sum` and `_.sumBy` without support for
|
||
| 933 | * iteratee shorthands.
|
||
| 934 | *
|
||
| 935 | * @private
|
||
| 936 | * @param {Array} array The array to iterate over.
|
||
| 937 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 938 | * @returns {number} Returns the sum.
|
||
| 939 | */
|
||
| 940 | function baseSum(array, iteratee) { |
||
| 941 | var result,
|
||
| 942 | index = -1,
|
||
| 943 | length = array.length; |
||
| 944 | |||
| 945 | while (++index < length) {
|
||
| 946 | var current = iteratee(array[index]);
|
||
| 947 | if (current !== undefined) { |
||
| 948 | result = result === undefined ? current : (result + current);
|
||
| 949 | } |
||
| 950 | } |
||
| 951 | return result;
|
||
| 952 | } |
||
| 953 | |||
| 954 | /**
|
||
| 955 | * The base implementation of `_.times` without support for iteratee shorthands
|
||
| 956 | * or max array length checks.
|
||
| 957 | *
|
||
| 958 | * @private
|
||
| 959 | * @param {number} n The number of times to invoke `iteratee`.
|
||
| 960 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 961 | * @returns {Array} Returns the array of results.
|
||
| 962 | */
|
||
| 963 | function baseTimes(n, iteratee) { |
||
| 964 | var index = -1, |
||
| 965 | result = Array(n); |
||
| 966 | |||
| 967 | while (++index < n) {
|
||
| 968 | result[index] = iteratee(index); |
||
| 969 | } |
||
| 970 | return result;
|
||
| 971 | } |
||
| 972 | |||
| 973 | /**
|
||
| 974 | * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
|
||
| 975 | * of key-value pairs for `object` corresponding to the property names of `props`.
|
||
| 976 | *
|
||
| 977 | * @private
|
||
| 978 | * @param {Object} object The object to query.
|
||
| 979 | * @param {Array} props The property names to get values for.
|
||
| 980 | * @returns {Object} Returns the key-value pairs.
|
||
| 981 | */
|
||
| 982 | function baseToPairs(object, props) { |
||
| 983 | return arrayMap(props, function(key) { |
||
| 984 | return [key, object[key]];
|
||
| 985 | }); |
||
| 986 | } |
||
| 987 | |||
| 988 | /**
|
||
| 989 | * The base implementation of `_.unary` without support for storing metadata.
|
||
| 990 | *
|
||
| 991 | * @private
|
||
| 992 | * @param {Function} func The function to cap arguments for.
|
||
| 993 | * @returns {Function} Returns the new capped function.
|
||
| 994 | */
|
||
| 995 | function baseUnary(func) { |
||
| 996 | return function(value) { |
||
| 997 | return func(value);
|
||
| 998 | }; |
||
| 999 | } |
||
| 1000 | |||
| 1001 | /**
|
||
| 1002 | * The base implementation of `_.values` and `_.valuesIn` which creates an
|
||
| 1003 | * array of `object` property values corresponding to the property names
|
||
| 1004 | * of `props`.
|
||
| 1005 | *
|
||
| 1006 | * @private
|
||
| 1007 | * @param {Object} object The object to query.
|
||
| 1008 | * @param {Array} props The property names to get values for.
|
||
| 1009 | * @returns {Object} Returns the array of property values.
|
||
| 1010 | */
|
||
| 1011 | function baseValues(object, props) { |
||
| 1012 | return arrayMap(props, function(key) { |
||
| 1013 | return object[key];
|
||
| 1014 | }); |
||
| 1015 | } |
||
| 1016 | |||
| 1017 | /**
|
||
| 1018 | * Checks if a `cache` value for `key` exists.
|
||
| 1019 | *
|
||
| 1020 | * @private
|
||
| 1021 | * @param {Object} cache The cache to query.
|
||
| 1022 | * @param {string} key The key of the entry to check.
|
||
| 1023 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
||
| 1024 | */
|
||
| 1025 | function cacheHas(cache, key) { |
||
| 1026 | return cache.has(key);
|
||
| 1027 | } |
||
| 1028 | |||
| 1029 | /**
|
||
| 1030 | * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
|
||
| 1031 | * that is not found in the character symbols.
|
||
| 1032 | *
|
||
| 1033 | * @private
|
||
| 1034 | * @param {Array} strSymbols The string symbols to inspect.
|
||
| 1035 | * @param {Array} chrSymbols The character symbols to find.
|
||
| 1036 | * @returns {number} Returns the index of the first unmatched string symbol.
|
||
| 1037 | */
|
||
| 1038 | function charsStartIndex(strSymbols, chrSymbols) { |
||
| 1039 | var index = -1, |
||
| 1040 | length = strSymbols.length; |
||
| 1041 | |||
| 1042 | while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} |
||
| 1043 | return index;
|
||
| 1044 | } |
||
| 1045 | |||
| 1046 | /**
|
||
| 1047 | * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
|
||
| 1048 | * that is not found in the character symbols.
|
||
| 1049 | *
|
||
| 1050 | * @private
|
||
| 1051 | * @param {Array} strSymbols The string symbols to inspect.
|
||
| 1052 | * @param {Array} chrSymbols The character symbols to find.
|
||
| 1053 | * @returns {number} Returns the index of the last unmatched string symbol.
|
||
| 1054 | */
|
||
| 1055 | function charsEndIndex(strSymbols, chrSymbols) { |
||
| 1056 | var index = strSymbols.length;
|
||
| 1057 | |||
| 1058 | while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} |
||
| 1059 | return index;
|
||
| 1060 | } |
||
| 1061 | |||
| 1062 | /**
|
||
| 1063 | * Gets the number of `placeholder` occurrences in `array`.
|
||
| 1064 | *
|
||
| 1065 | * @private
|
||
| 1066 | * @param {Array} array The array to inspect.
|
||
| 1067 | * @param {*} placeholder The placeholder to search for.
|
||
| 1068 | * @returns {number} Returns the placeholder count.
|
||
| 1069 | */
|
||
| 1070 | function countHolders(array, placeholder) { |
||
| 1071 | var length = array.length,
|
||
| 1072 | result = 0;
|
||
| 1073 | |||
| 1074 | while (length--) {
|
||
| 1075 | if (array[length] === placeholder) {
|
||
| 1076 | ++result; |
||
| 1077 | } |
||
| 1078 | } |
||
| 1079 | return result;
|
||
| 1080 | } |
||
| 1081 | |||
| 1082 | /**
|
||
| 1083 | * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
|
||
| 1084 | * letters to basic Latin letters.
|
||
| 1085 | *
|
||
| 1086 | * @private
|
||
| 1087 | * @param {string} letter The matched letter to deburr.
|
||
| 1088 | * @returns {string} Returns the deburred letter.
|
||
| 1089 | */
|
||
| 1090 | var deburrLetter = basePropertyOf(deburredLetters);
|
||
| 1091 | |||
| 1092 | /**
|
||
| 1093 | * Used by `_.escape` to convert characters to HTML entities.
|
||
| 1094 | *
|
||
| 1095 | * @private
|
||
| 1096 | * @param {string} chr The matched character to escape.
|
||
| 1097 | * @returns {string} Returns the escaped character.
|
||
| 1098 | */
|
||
| 1099 | var escapeHtmlChar = basePropertyOf(htmlEscapes);
|
||
| 1100 | |||
| 1101 | /**
|
||
| 1102 | * Used by `_.template` to escape characters for inclusion in compiled string literals.
|
||
| 1103 | *
|
||
| 1104 | * @private
|
||
| 1105 | * @param {string} chr The matched character to escape.
|
||
| 1106 | * @returns {string} Returns the escaped character.
|
||
| 1107 | */
|
||
| 1108 | function escapeStringChar(chr) { |
||
| 1109 | return '\\' + stringEscapes[chr]; |
||
| 1110 | } |
||
| 1111 | |||
| 1112 | /**
|
||
| 1113 | * Gets the value at `key` of `object`.
|
||
| 1114 | *
|
||
| 1115 | * @private
|
||
| 1116 | * @param {Object} [object] The object to query.
|
||
| 1117 | * @param {string} key The key of the property to get.
|
||
| 1118 | * @returns {*} Returns the property value.
|
||
| 1119 | */
|
||
| 1120 | function getValue(object, key) { |
||
| 1121 | return object == null ? undefined : object[key]; |
||
| 1122 | } |
||
| 1123 | |||
| 1124 | /**
|
||
| 1125 | * Checks if `string` contains Unicode symbols.
|
||
| 1126 | *
|
||
| 1127 | * @private
|
||
| 1128 | * @param {string} string The string to inspect.
|
||
| 1129 | * @returns {boolean} Returns `true` if a symbol is found, else `false`.
|
||
| 1130 | */
|
||
| 1131 | function hasUnicode(string) { |
||
| 1132 | return reHasUnicode.test(string);
|
||
| 1133 | } |
||
| 1134 | |||
| 1135 | /**
|
||
| 1136 | * Checks if `string` contains a word composed of Unicode symbols.
|
||
| 1137 | *
|
||
| 1138 | * @private
|
||
| 1139 | * @param {string} string The string to inspect.
|
||
| 1140 | * @returns {boolean} Returns `true` if a word is found, else `false`.
|
||
| 1141 | */
|
||
| 1142 | function hasUnicodeWord(string) { |
||
| 1143 | return reHasUnicodeWord.test(string);
|
||
| 1144 | } |
||
| 1145 | |||
| 1146 | /**
|
||
| 1147 | * Converts `iterator` to an array.
|
||
| 1148 | *
|
||
| 1149 | * @private
|
||
| 1150 | * @param {Object} iterator The iterator to convert.
|
||
| 1151 | * @returns {Array} Returns the converted array.
|
||
| 1152 | */
|
||
| 1153 | function iteratorToArray(iterator) { |
||
| 1154 | var data,
|
||
| 1155 | result = []; |
||
| 1156 | |||
| 1157 | while (!(data = iterator.next()).done) {
|
||
| 1158 | result.push(data.value); |
||
| 1159 | } |
||
| 1160 | return result;
|
||
| 1161 | } |
||
| 1162 | |||
| 1163 | /**
|
||
| 1164 | * Converts `map` to its key-value pairs.
|
||
| 1165 | *
|
||
| 1166 | * @private
|
||
| 1167 | * @param {Object} map The map to convert.
|
||
| 1168 | * @returns {Array} Returns the key-value pairs.
|
||
| 1169 | */
|
||
| 1170 | function mapToArray(map) { |
||
| 1171 | var index = -1, |
||
| 1172 | result = Array(map.size); |
||
| 1173 | |||
| 1174 | map.forEach(function(value, key) {
|
||
| 1175 | result[++index] = [key, value]; |
||
| 1176 | }); |
||
| 1177 | return result;
|
||
| 1178 | } |
||
| 1179 | |||
| 1180 | /**
|
||
| 1181 | * Creates a unary function that invokes `func` with its argument transformed.
|
||
| 1182 | *
|
||
| 1183 | * @private
|
||
| 1184 | * @param {Function} func The function to wrap.
|
||
| 1185 | * @param {Function} transform The argument transform.
|
||
| 1186 | * @returns {Function} Returns the new function.
|
||
| 1187 | */
|
||
| 1188 | function overArg(func, transform) { |
||
| 1189 | return function(arg) { |
||
| 1190 | return func(transform(arg));
|
||
| 1191 | }; |
||
| 1192 | } |
||
| 1193 | |||
| 1194 | /**
|
||
| 1195 | * Replaces all `placeholder` elements in `array` with an internal placeholder
|
||
| 1196 | * and returns an array of their indexes.
|
||
| 1197 | *
|
||
| 1198 | * @private
|
||
| 1199 | * @param {Array} array The array to modify.
|
||
| 1200 | * @param {*} placeholder The placeholder to replace.
|
||
| 1201 | * @returns {Array} Returns the new array of placeholder indexes.
|
||
| 1202 | */
|
||
| 1203 | function replaceHolders(array, placeholder) { |
||
| 1204 | var index = -1, |
||
| 1205 | length = array.length, |
||
| 1206 | resIndex = 0,
|
||
| 1207 | result = []; |
||
| 1208 | |||
| 1209 | while (++index < length) {
|
||
| 1210 | var value = array[index];
|
||
| 1211 | if (value === placeholder || value === PLACEHOLDER) {
|
||
| 1212 | array[index] = PLACEHOLDER; |
||
| 1213 | result[resIndex++] = index; |
||
| 1214 | } |
||
| 1215 | } |
||
| 1216 | return result;
|
||
| 1217 | } |
||
| 1218 | |||
| 1219 | /**
|
||
| 1220 | * Gets the value at `key`, unless `key` is "__proto__".
|
||
| 1221 | *
|
||
| 1222 | * @private
|
||
| 1223 | * @param {Object} object The object to query.
|
||
| 1224 | * @param {string} key The key of the property to get.
|
||
| 1225 | * @returns {*} Returns the property value.
|
||
| 1226 | */
|
||
| 1227 | function safeGet(object, key) { |
||
| 1228 | return key == '__proto__' |
||
| 1229 | ? undefined
|
||
| 1230 | : object[key]; |
||
| 1231 | } |
||
| 1232 | |||
| 1233 | /**
|
||
| 1234 | * Converts `set` to an array of its values.
|
||
| 1235 | *
|
||
| 1236 | * @private
|
||
| 1237 | * @param {Object} set The set to convert.
|
||
| 1238 | * @returns {Array} Returns the values.
|
||
| 1239 | */
|
||
| 1240 | function setToArray(set) { |
||
| 1241 | var index = -1, |
||
| 1242 | result = Array(set.size); |
||
| 1243 | |||
| 1244 | set.forEach(function(value) {
|
||
| 1245 | result[++index] = value; |
||
| 1246 | }); |
||
| 1247 | return result;
|
||
| 1248 | } |
||
| 1249 | |||
| 1250 | /**
|
||
| 1251 | * Converts `set` to its value-value pairs.
|
||
| 1252 | *
|
||
| 1253 | * @private
|
||
| 1254 | * @param {Object} set The set to convert.
|
||
| 1255 | * @returns {Array} Returns the value-value pairs.
|
||
| 1256 | */
|
||
| 1257 | function setToPairs(set) { |
||
| 1258 | var index = -1, |
||
| 1259 | result = Array(set.size); |
||
| 1260 | |||
| 1261 | set.forEach(function(value) {
|
||
| 1262 | result[++index] = [value, value]; |
||
| 1263 | }); |
||
| 1264 | return result;
|
||
| 1265 | } |
||
| 1266 | |||
| 1267 | /**
|
||
| 1268 | * A specialized version of `_.indexOf` which performs strict equality
|
||
| 1269 | * comparisons of values, i.e. `===`.
|
||
| 1270 | *
|
||
| 1271 | * @private
|
||
| 1272 | * @param {Array} array The array to inspect.
|
||
| 1273 | * @param {*} value The value to search for.
|
||
| 1274 | * @param {number} fromIndex The index to search from.
|
||
| 1275 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 1276 | */
|
||
| 1277 | function strictIndexOf(array, value, fromIndex) { |
||
| 1278 | var index = fromIndex - 1, |
||
| 1279 | length = array.length; |
||
| 1280 | |||
| 1281 | while (++index < length) {
|
||
| 1282 | if (array[index] === value) {
|
||
| 1283 | return index;
|
||
| 1284 | } |
||
| 1285 | } |
||
| 1286 | return -1; |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | /**
|
||
| 1290 | * A specialized version of `_.lastIndexOf` 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 strictLastIndexOf(array, value, fromIndex) { |
||
| 1300 | var index = fromIndex + 1; |
||
| 1301 | while (index--) {
|
||
| 1302 | if (array[index] === value) {
|
||
| 1303 | return index;
|
||
| 1304 | } |
||
| 1305 | } |
||
| 1306 | return index;
|
||
| 1307 | } |
||
| 1308 | |||
| 1309 | /**
|
||
| 1310 | * Gets the number of symbols in `string`.
|
||
| 1311 | *
|
||
| 1312 | * @private
|
||
| 1313 | * @param {string} string The string to inspect.
|
||
| 1314 | * @returns {number} Returns the string size.
|
||
| 1315 | */
|
||
| 1316 | function stringSize(string) { |
||
| 1317 | return hasUnicode(string)
|
||
| 1318 | ? unicodeSize(string) |
||
| 1319 | : asciiSize(string); |
||
| 1320 | } |
||
| 1321 | |||
| 1322 | /**
|
||
| 1323 | * Converts `string` to an array.
|
||
| 1324 | *
|
||
| 1325 | * @private
|
||
| 1326 | * @param {string} string The string to convert.
|
||
| 1327 | * @returns {Array} Returns the converted array.
|
||
| 1328 | */
|
||
| 1329 | function stringToArray(string) { |
||
| 1330 | return hasUnicode(string)
|
||
| 1331 | ? unicodeToArray(string) |
||
| 1332 | : asciiToArray(string); |
||
| 1333 | } |
||
| 1334 | |||
| 1335 | /**
|
||
| 1336 | * Used by `_.unescape` to convert HTML entities to characters.
|
||
| 1337 | *
|
||
| 1338 | * @private
|
||
| 1339 | * @param {string} chr The matched character to unescape.
|
||
| 1340 | * @returns {string} Returns the unescaped character.
|
||
| 1341 | */
|
||
| 1342 | var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
|
||
| 1343 | |||
| 1344 | /**
|
||
| 1345 | * Gets the size of a Unicode `string`.
|
||
| 1346 | *
|
||
| 1347 | * @private
|
||
| 1348 | * @param {string} string The string inspect.
|
||
| 1349 | * @returns {number} Returns the string size.
|
||
| 1350 | */
|
||
| 1351 | function unicodeSize(string) { |
||
| 1352 | var result = reUnicode.lastIndex = 0; |
||
| 1353 | while (reUnicode.test(string)) {
|
||
| 1354 | ++result; |
||
| 1355 | } |
||
| 1356 | return result;
|
||
| 1357 | } |
||
| 1358 | |||
| 1359 | /**
|
||
| 1360 | * Converts a Unicode `string` to an array.
|
||
| 1361 | *
|
||
| 1362 | * @private
|
||
| 1363 | * @param {string} string The string to convert.
|
||
| 1364 | * @returns {Array} Returns the converted array.
|
||
| 1365 | */
|
||
| 1366 | function unicodeToArray(string) { |
||
| 1367 | return string.match(reUnicode) || [];
|
||
| 1368 | } |
||
| 1369 | |||
| 1370 | /**
|
||
| 1371 | * Splits a Unicode `string` into an array of its words.
|
||
| 1372 | *
|
||
| 1373 | * @private
|
||
| 1374 | * @param {string} The string to inspect.
|
||
| 1375 | * @returns {Array} Returns the words of `string`.
|
||
| 1376 | */
|
||
| 1377 | function unicodeWords(string) { |
||
| 1378 | return string.match(reUnicodeWord) || [];
|
||
| 1379 | } |
||
| 1380 | |||
| 1381 | /*--------------------------------------------------------------------------*/
|
||
| 1382 | |||
| 1383 | /**
|
||
| 1384 | * Create a new pristine `lodash` function using the `context` object.
|
||
| 1385 | *
|
||
| 1386 | * @static
|
||
| 1387 | * @memberOf _
|
||
| 1388 | * @since 1.1.0
|
||
| 1389 | * @category Util
|
||
| 1390 | * @param {Object} [context=root] The context object.
|
||
| 1391 | * @returns {Function} Returns a new `lodash` function.
|
||
| 1392 | * @example
|
||
| 1393 | *
|
||
| 1394 | * _.mixin({ 'foo': _.constant('foo') });
|
||
| 1395 | *
|
||
| 1396 | * var lodash = _.runInContext();
|
||
| 1397 | * lodash.mixin({ 'bar': lodash.constant('bar') });
|
||
| 1398 | *
|
||
| 1399 | * _.isFunction(_.foo);
|
||
| 1400 | * // => true
|
||
| 1401 | * _.isFunction(_.bar);
|
||
| 1402 | * // => false
|
||
| 1403 | *
|
||
| 1404 | * lodash.isFunction(lodash.foo);
|
||
| 1405 | * // => false
|
||
| 1406 | * lodash.isFunction(lodash.bar);
|
||
| 1407 | * // => true
|
||
| 1408 | *
|
||
| 1409 | * // Create a suped-up `defer` in Node.js.
|
||
| 1410 | * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
|
||
| 1411 | */
|
||
| 1412 | var runInContext = (function runInContext(context) { |
||
| 1413 | context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
|
||
| 1414 | |||
| 1415 | /** Built-in constructor references. */
|
||
| 1416 | var Array = context.Array,
|
||
| 1417 | Date = context.Date, |
||
| 1418 | Error = context.Error, |
||
| 1419 | Function = context.Function, |
||
| 1420 | Math = context.Math, |
||
| 1421 | Object = context.Object, |
||
| 1422 | RegExp = context.RegExp, |
||
| 1423 | String = context.String, |
||
| 1424 | TypeError = context.TypeError; |
||
| 1425 | |||
| 1426 | /** Used for built-in method references. */
|
||
| 1427 | var arrayProto = Array.prototype,
|
||
| 1428 | funcProto = Function.prototype, |
||
| 1429 | objectProto = Object.prototype; |
||
| 1430 | |||
| 1431 | /** Used to detect overreaching core-js shims. */
|
||
| 1432 | var coreJsData = context['__core-js_shared__']; |
||
| 1433 | |||
| 1434 | /** Used to resolve the decompiled source of functions. */
|
||
| 1435 | var funcToString = funcProto.toString;
|
||
| 1436 | |||
| 1437 | /** Used to check objects for own properties. */
|
||
| 1438 | var hasOwnProperty = objectProto.hasOwnProperty;
|
||
| 1439 | |||
| 1440 | /** Used to generate unique IDs. */
|
||
| 1441 | var idCounter = 0; |
||
| 1442 | |||
| 1443 | /** Used to detect methods masquerading as native. */
|
||
| 1444 | var maskSrcKey = (function() { |
||
| 1445 | var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); |
||
| 1446 | return uid ? ('Symbol(src)_1.' + uid) : ''; |
||
| 1447 | }()); |
||
| 1448 | |||
| 1449 | /**
|
||
| 1450 | * Used to resolve the
|
||
| 1451 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
||
| 1452 | * of values.
|
||
| 1453 | */
|
||
| 1454 | var nativeObjectToString = objectProto.toString;
|
||
| 1455 | |||
| 1456 | /** Used to infer the `Object` constructor. */
|
||
| 1457 | var objectCtorString = funcToString.call(Object);
|
||
| 1458 | |||
| 1459 | /** Used to restore the original `_` reference in `_.noConflict`. */
|
||
| 1460 | var oldDash = root._;
|
||
| 1461 | |||
| 1462 | /** Used to detect if a method is native. */
|
||
| 1463 | var reIsNative = RegExp('^' + |
||
| 1464 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
||
| 1465 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' |
||
| 1466 | ); |
||
| 1467 | |||
| 1468 | /** Built-in value references. */
|
||
| 1469 | var Buffer = moduleExports ? context.Buffer : undefined, |
||
| 1470 | Symbol = context.Symbol, |
||
| 1471 | Uint8Array = context.Uint8Array, |
||
| 1472 | allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
|
||
| 1473 | getPrototype = overArg(Object.getPrototypeOf, Object), |
||
| 1474 | objectCreate = Object.create, |
||
| 1475 | propertyIsEnumerable = objectProto.propertyIsEnumerable, |
||
| 1476 | splice = arrayProto.splice, |
||
| 1477 | spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
|
||
| 1478 | symIterator = Symbol ? Symbol.iterator : undefined,
|
||
| 1479 | symToStringTag = Symbol ? Symbol.toStringTag : undefined;
|
||
| 1480 | |||
| 1481 | var defineProperty = (function() { |
||
| 1482 | try {
|
||
| 1483 | var func = getNative(Object, 'defineProperty'); |
||
| 1484 | func({}, '', {});
|
||
| 1485 | return func;
|
||
| 1486 | } catch (e) {}
|
||
| 1487 | }()); |
||
| 1488 | |||
| 1489 | /** Mocked built-ins. */
|
||
| 1490 | var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
|
||
| 1491 | ctxNow = Date && Date.now !== root.Date.now && Date.now, |
||
| 1492 | ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout; |
||
| 1493 | |||
| 1494 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
||
| 1495 | var nativeCeil = Math.ceil,
|
||
| 1496 | nativeFloor = Math.floor, |
||
| 1497 | nativeGetSymbols = Object.getOwnPropertySymbols, |
||
| 1498 | nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
|
||
| 1499 | nativeIsFinite = context.isFinite, |
||
| 1500 | nativeJoin = arrayProto.join, |
||
| 1501 | nativeKeys = overArg(Object.keys, Object), |
||
| 1502 | nativeMax = Math.max, |
||
| 1503 | nativeMin = Math.min, |
||
| 1504 | nativeNow = Date.now, |
||
| 1505 | nativeParseInt = context.parseInt, |
||
| 1506 | nativeRandom = Math.random, |
||
| 1507 | nativeReverse = arrayProto.reverse; |
||
| 1508 | |||
| 1509 | /* Built-in method references that are verified to be native. */
|
||
| 1510 | var DataView = getNative(context, 'DataView'), |
||
| 1511 | Map = getNative(context, 'Map'),
|
||
| 1512 | Promise = getNative(context, 'Promise'),
|
||
| 1513 | Set = getNative(context, 'Set'),
|
||
| 1514 | WeakMap = getNative(context, 'WeakMap'),
|
||
| 1515 | nativeCreate = getNative(Object, 'create');
|
||
| 1516 | |||
| 1517 | /** Used to store function metadata. */
|
||
| 1518 | var metaMap = WeakMap && new WeakMap; |
||
| 1519 | |||
| 1520 | /** Used to lookup unminified function names. */
|
||
| 1521 | var realNames = {};
|
||
| 1522 | |||
| 1523 | /** Used to detect maps, sets, and weakmaps. */
|
||
| 1524 | var dataViewCtorString = toSource(DataView),
|
||
| 1525 | mapCtorString = toSource(Map), |
||
| 1526 | promiseCtorString = toSource(Promise), |
||
| 1527 | setCtorString = toSource(Set), |
||
| 1528 | weakMapCtorString = toSource(WeakMap); |
||
| 1529 | |||
| 1530 | /** Used to convert symbols to primitives and strings. */
|
||
| 1531 | var symbolProto = Symbol ? Symbol.prototype : undefined, |
||
| 1532 | symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
|
||
| 1533 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
||
| 1534 | |||
| 1535 | /*------------------------------------------------------------------------*/
|
||
| 1536 | |||
| 1537 | /**
|
||
| 1538 | * Creates a `lodash` object which wraps `value` to enable implicit method
|
||
| 1539 | * chain sequences. Methods that operate on and return arrays, collections,
|
||
| 1540 | * and functions can be chained together. Methods that retrieve a single value
|
||
| 1541 | * or may return a primitive value will automatically end the chain sequence
|
||
| 1542 | * and return the unwrapped value. Otherwise, the value must be unwrapped
|
||
| 1543 | * with `_#value`.
|
||
| 1544 | *
|
||
| 1545 | * Explicit chain sequences, which must be unwrapped with `_#value`, may be
|
||
| 1546 | * enabled using `_.chain`.
|
||
| 1547 | *
|
||
| 1548 | * The execution of chained methods is lazy, that is, it's deferred until
|
||
| 1549 | * `_#value` is implicitly or explicitly called.
|
||
| 1550 | *
|
||
| 1551 | * Lazy evaluation allows several methods to support shortcut fusion.
|
||
| 1552 | * Shortcut fusion is an optimization to merge iteratee calls; this avoids
|
||
| 1553 | * the creation of intermediate arrays and can greatly reduce the number of
|
||
| 1554 | * iteratee executions. Sections of a chain sequence qualify for shortcut
|
||
| 1555 | * fusion if the section is applied to an array and iteratees accept only
|
||
| 1556 | * one argument. The heuristic for whether a section qualifies for shortcut
|
||
| 1557 | * fusion is subject to change.
|
||
| 1558 | *
|
||
| 1559 | * Chaining is supported in custom builds as long as the `_#value` method is
|
||
| 1560 | * directly or indirectly included in the build.
|
||
| 1561 | *
|
||
| 1562 | * In addition to lodash methods, wrappers have `Array` and `String` methods.
|
||
| 1563 | *
|
||
| 1564 | * The wrapper `Array` methods are:
|
||
| 1565 | * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
|
||
| 1566 | *
|
||
| 1567 | * The wrapper `String` methods are:
|
||
| 1568 | * `replace` and `split`
|
||
| 1569 | *
|
||
| 1570 | * The wrapper methods that support shortcut fusion are:
|
||
| 1571 | * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
|
||
| 1572 | * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
|
||
| 1573 | * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
|
||
| 1574 | *
|
||
| 1575 | * The chainable wrapper methods are:
|
||
| 1576 | * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
|
||
| 1577 | * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
|
||
| 1578 | * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
|
||
| 1579 | * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
|
||
| 1580 | * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
|
||
| 1581 | * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
|
||
| 1582 | * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
|
||
| 1583 | * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
|
||
| 1584 | * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
|
||
| 1585 | * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
|
||
| 1586 | * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
|
||
| 1587 | * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
|
||
| 1588 | * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
|
||
| 1589 | * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
|
||
| 1590 | * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
|
||
| 1591 | * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
|
||
| 1592 | * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
|
||
| 1593 | * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
|
||
| 1594 | * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
|
||
| 1595 | * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
|
||
| 1596 | * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
|
||
| 1597 | * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
|
||
| 1598 | * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
|
||
| 1599 | * `zipObject`, `zipObjectDeep`, and `zipWith`
|
||
| 1600 | *
|
||
| 1601 | * The wrapper methods that are **not** chainable by default are:
|
||
| 1602 | * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
|
||
| 1603 | * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
|
||
| 1604 | * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
|
||
| 1605 | * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
|
||
| 1606 | * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
|
||
| 1607 | * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
|
||
| 1608 | * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
|
||
| 1609 | * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
|
||
| 1610 | * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
|
||
| 1611 | * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
|
||
| 1612 | * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
|
||
| 1613 | * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
|
||
| 1614 | * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
|
||
| 1615 | * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
|
||
| 1616 | * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
|
||
| 1617 | * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
|
||
| 1618 | * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
|
||
| 1619 | * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
|
||
| 1620 | * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
|
||
| 1621 | * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
|
||
| 1622 | * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
|
||
| 1623 | * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
|
||
| 1624 | * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
|
||
| 1625 | * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
|
||
| 1626 | * `upperFirst`, `value`, and `words`
|
||
| 1627 | *
|
||
| 1628 | * @name _
|
||
| 1629 | * @constructor
|
||
| 1630 | * @category Seq
|
||
| 1631 | * @param {*} value The value to wrap in a `lodash` instance.
|
||
| 1632 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
||
| 1633 | * @example
|
||
| 1634 | *
|
||
| 1635 | * function square(n) {
|
||
| 1636 | * return n * n;
|
||
| 1637 | * }
|
||
| 1638 | *
|
||
| 1639 | * var wrapped = _([1, 2, 3]);
|
||
| 1640 | *
|
||
| 1641 | * // Returns an unwrapped value.
|
||
| 1642 | * wrapped.reduce(_.add);
|
||
| 1643 | * // => 6
|
||
| 1644 | *
|
||
| 1645 | * // Returns a wrapped value.
|
||
| 1646 | * var squares = wrapped.map(square);
|
||
| 1647 | *
|
||
| 1648 | * _.isArray(squares);
|
||
| 1649 | * // => false
|
||
| 1650 | *
|
||
| 1651 | * _.isArray(squares.value());
|
||
| 1652 | * // => true
|
||
| 1653 | */
|
||
| 1654 | function lodash(value) { |
||
| 1655 | if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { |
||
| 1656 | if (value instanceof LodashWrapper) { |
||
| 1657 | return value;
|
||
| 1658 | } |
||
| 1659 | if (hasOwnProperty.call(value, '__wrapped__')) { |
||
| 1660 | return wrapperClone(value);
|
||
| 1661 | } |
||
| 1662 | } |
||
| 1663 | return new LodashWrapper(value); |
||
| 1664 | } |
||
| 1665 | |||
| 1666 | /**
|
||
| 1667 | * The base implementation of `_.create` without support for assigning
|
||
| 1668 | * properties to the created object.
|
||
| 1669 | *
|
||
| 1670 | * @private
|
||
| 1671 | * @param {Object} proto The object to inherit from.
|
||
| 1672 | * @returns {Object} Returns the new object.
|
||
| 1673 | */
|
||
| 1674 | var baseCreate = (function() { |
||
| 1675 | function object() {} |
||
| 1676 | return function(proto) { |
||
| 1677 | if (!isObject(proto)) {
|
||
| 1678 | return {};
|
||
| 1679 | } |
||
| 1680 | if (objectCreate) {
|
||
| 1681 | return objectCreate(proto);
|
||
| 1682 | } |
||
| 1683 | object.prototype = proto; |
||
| 1684 | var result = new object; |
||
| 1685 | object.prototype = undefined;
|
||
| 1686 | return result;
|
||
| 1687 | }; |
||
| 1688 | }()); |
||
| 1689 | |||
| 1690 | /**
|
||
| 1691 | * The function whose prototype chain sequence wrappers inherit from.
|
||
| 1692 | *
|
||
| 1693 | * @private
|
||
| 1694 | */
|
||
| 1695 | function baseLodash() { |
||
| 1696 | // No operation performed.
|
||
| 1697 | } |
||
| 1698 | |||
| 1699 | /**
|
||
| 1700 | * The base constructor for creating `lodash` wrapper objects.
|
||
| 1701 | *
|
||
| 1702 | * @private
|
||
| 1703 | * @param {*} value The value to wrap.
|
||
| 1704 | * @param {boolean} [chainAll] Enable explicit method chain sequences.
|
||
| 1705 | */
|
||
| 1706 | function LodashWrapper(value, chainAll) { |
||
| 1707 | this.__wrapped__ = value;
|
||
| 1708 | this.__actions__ = [];
|
||
| 1709 | this.__chain__ = !!chainAll;
|
||
| 1710 | this.__index__ = 0; |
||
| 1711 | this.__values__ = undefined; |
||
| 1712 | } |
||
| 1713 | |||
| 1714 | /**
|
||
| 1715 | * By default, the template delimiters used by lodash are like those in
|
||
| 1716 | * embedded Ruby (ERB) as well as ES2015 template strings. Change the
|
||
| 1717 | * following template settings to use alternative delimiters.
|
||
| 1718 | *
|
||
| 1719 | * @static
|
||
| 1720 | * @memberOf _
|
||
| 1721 | * @type {Object}
|
||
| 1722 | */
|
||
| 1723 | lodash.templateSettings = {
|
||
| 1724 | |||
| 1725 | /**
|
||
| 1726 | * Used to detect `data` property values to be HTML-escaped.
|
||
| 1727 | *
|
||
| 1728 | * @memberOf _.templateSettings
|
||
| 1729 | * @type {RegExp}
|
||
| 1730 | */
|
||
| 1731 | 'escape': reEscape,
|
||
| 1732 | |||
| 1733 | /**
|
||
| 1734 | * Used to detect code to be evaluated.
|
||
| 1735 | *
|
||
| 1736 | * @memberOf _.templateSettings
|
||
| 1737 | * @type {RegExp}
|
||
| 1738 | */
|
||
| 1739 | 'evaluate': reEvaluate,
|
||
| 1740 | |||
| 1741 | /**
|
||
| 1742 | * Used to detect `data` property values to inject.
|
||
| 1743 | *
|
||
| 1744 | * @memberOf _.templateSettings
|
||
| 1745 | * @type {RegExp}
|
||
| 1746 | */
|
||
| 1747 | 'interpolate': reInterpolate,
|
||
| 1748 | |||
| 1749 | /**
|
||
| 1750 | * Used to reference the data object in the template text.
|
||
| 1751 | *
|
||
| 1752 | * @memberOf _.templateSettings
|
||
| 1753 | * @type {string}
|
||
| 1754 | */
|
||
| 1755 | 'variable': '', |
||
| 1756 | |||
| 1757 | /**
|
||
| 1758 | * Used to import variables into the compiled template.
|
||
| 1759 | *
|
||
| 1760 | * @memberOf _.templateSettings
|
||
| 1761 | * @type {Object}
|
||
| 1762 | */
|
||
| 1763 | 'imports': {
|
||
| 1764 | |||
| 1765 | /**
|
||
| 1766 | * A reference to the `lodash` function.
|
||
| 1767 | *
|
||
| 1768 | * @memberOf _.templateSettings.imports
|
||
| 1769 | * @type {Function}
|
||
| 1770 | */
|
||
| 1771 | '_': lodash
|
||
| 1772 | } |
||
| 1773 | }; |
||
| 1774 | |||
| 1775 | // Ensure wrappers are instances of `baseLodash`.
|
||
| 1776 | lodash.prototype = baseLodash.prototype; |
||
| 1777 | lodash.prototype.constructor = lodash; |
||
| 1778 | |||
| 1779 | LodashWrapper.prototype = baseCreate(baseLodash.prototype); |
||
| 1780 | LodashWrapper.prototype.constructor = LodashWrapper; |
||
| 1781 | |||
| 1782 | /*------------------------------------------------------------------------*/
|
||
| 1783 | |||
| 1784 | /**
|
||
| 1785 | * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
|
||
| 1786 | *
|
||
| 1787 | * @private
|
||
| 1788 | * @constructor
|
||
| 1789 | * @param {*} value The value to wrap.
|
||
| 1790 | */
|
||
| 1791 | function LazyWrapper(value) { |
||
| 1792 | this.__wrapped__ = value;
|
||
| 1793 | this.__actions__ = [];
|
||
| 1794 | this.__dir__ = 1; |
||
| 1795 | this.__filtered__ = false; |
||
| 1796 | this.__iteratees__ = [];
|
||
| 1797 | this.__takeCount__ = MAX_ARRAY_LENGTH;
|
||
| 1798 | this.__views__ = [];
|
||
| 1799 | } |
||
| 1800 | |||
| 1801 | /**
|
||
| 1802 | * Creates a clone of the lazy wrapper object.
|
||
| 1803 | *
|
||
| 1804 | * @private
|
||
| 1805 | * @name clone
|
||
| 1806 | * @memberOf LazyWrapper
|
||
| 1807 | * @returns {Object} Returns the cloned `LazyWrapper` object.
|
||
| 1808 | */
|
||
| 1809 | function lazyClone() { |
||
| 1810 | var result = new LazyWrapper(this.__wrapped__); |
||
| 1811 | result.__actions__ = copyArray(this.__actions__);
|
||
| 1812 | result.__dir__ = this.__dir__;
|
||
| 1813 | result.__filtered__ = this.__filtered__;
|
||
| 1814 | result.__iteratees__ = copyArray(this.__iteratees__);
|
||
| 1815 | result.__takeCount__ = this.__takeCount__;
|
||
| 1816 | result.__views__ = copyArray(this.__views__);
|
||
| 1817 | return result;
|
||
| 1818 | } |
||
| 1819 | |||
| 1820 | /**
|
||
| 1821 | * Reverses the direction of lazy iteration.
|
||
| 1822 | *
|
||
| 1823 | * @private
|
||
| 1824 | * @name reverse
|
||
| 1825 | * @memberOf LazyWrapper
|
||
| 1826 | * @returns {Object} Returns the new reversed `LazyWrapper` object.
|
||
| 1827 | */
|
||
| 1828 | function lazyReverse() { |
||
| 1829 | if (this.__filtered__) { |
||
| 1830 | var result = new LazyWrapper(this); |
||
| 1831 | result.__dir__ = -1;
|
||
| 1832 | result.__filtered__ = true;
|
||
| 1833 | } else {
|
||
| 1834 | result = this.clone();
|
||
| 1835 | result.__dir__ *= -1;
|
||
| 1836 | } |
||
| 1837 | return result;
|
||
| 1838 | } |
||
| 1839 | |||
| 1840 | /**
|
||
| 1841 | * Extracts the unwrapped value from its lazy wrapper.
|
||
| 1842 | *
|
||
| 1843 | * @private
|
||
| 1844 | * @name value
|
||
| 1845 | * @memberOf LazyWrapper
|
||
| 1846 | * @returns {*} Returns the unwrapped value.
|
||
| 1847 | */
|
||
| 1848 | function lazyValue() { |
||
| 1849 | var array = this.__wrapped__.value(), |
||
| 1850 | dir = this.__dir__,
|
||
| 1851 | isArr = isArray(array), |
||
| 1852 | isRight = dir < 0,
|
||
| 1853 | arrLength = isArr ? array.length : 0,
|
||
| 1854 | view = getView(0, arrLength, this.__views__), |
||
| 1855 | start = view.start, |
||
| 1856 | end = view.end, |
||
| 1857 | length = end - start, |
||
| 1858 | index = isRight ? end : (start - 1),
|
||
| 1859 | iteratees = this.__iteratees__,
|
||
| 1860 | iterLength = iteratees.length, |
||
| 1861 | resIndex = 0,
|
||
| 1862 | takeCount = nativeMin(length, this.__takeCount__);
|
||
| 1863 | |||
| 1864 | if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
|
||
| 1865 | return baseWrapperValue(array, this.__actions__); |
||
| 1866 | } |
||
| 1867 | var result = [];
|
||
| 1868 | |||
| 1869 | outer: |
||
| 1870 | while (length-- && resIndex < takeCount) {
|
||
| 1871 | index += dir; |
||
| 1872 | |||
| 1873 | var iterIndex = -1, |
||
| 1874 | value = array[index]; |
||
| 1875 | |||
| 1876 | while (++iterIndex < iterLength) {
|
||
| 1877 | var data = iteratees[iterIndex],
|
||
| 1878 | iteratee = data.iteratee, |
||
| 1879 | type = data.type, |
||
| 1880 | computed = iteratee(value); |
||
| 1881 | |||
| 1882 | if (type == LAZY_MAP_FLAG) {
|
||
| 1883 | value = computed; |
||
| 1884 | } else if (!computed) { |
||
| 1885 | if (type == LAZY_FILTER_FLAG) {
|
||
| 1886 | continue outer;
|
||
| 1887 | } else {
|
||
| 1888 | break outer;
|
||
| 1889 | } |
||
| 1890 | } |
||
| 1891 | } |
||
| 1892 | result[resIndex++] = value; |
||
| 1893 | } |
||
| 1894 | return result;
|
||
| 1895 | } |
||
| 1896 | |||
| 1897 | // Ensure `LazyWrapper` is an instance of `baseLodash`.
|
||
| 1898 | LazyWrapper.prototype = baseCreate(baseLodash.prototype); |
||
| 1899 | LazyWrapper.prototype.constructor = LazyWrapper; |
||
| 1900 | |||
| 1901 | /*------------------------------------------------------------------------*/
|
||
| 1902 | |||
| 1903 | /**
|
||
| 1904 | * Creates a hash object.
|
||
| 1905 | *
|
||
| 1906 | * @private
|
||
| 1907 | * @constructor
|
||
| 1908 | * @param {Array} [entries] The key-value pairs to cache.
|
||
| 1909 | */
|
||
| 1910 | function Hash(entries) { |
||
| 1911 | var index = -1, |
||
| 1912 | length = entries == null ? 0 : entries.length; |
||
| 1913 | |||
| 1914 | this.clear();
|
||
| 1915 | while (++index < length) {
|
||
| 1916 | var entry = entries[index];
|
||
| 1917 | this.set(entry[0], entry[1]); |
||
| 1918 | } |
||
| 1919 | } |
||
| 1920 | |||
| 1921 | /**
|
||
| 1922 | * Removes all key-value entries from the hash.
|
||
| 1923 | *
|
||
| 1924 | * @private
|
||
| 1925 | * @name clear
|
||
| 1926 | * @memberOf Hash
|
||
| 1927 | */
|
||
| 1928 | function hashClear() { |
||
| 1929 | this.__data__ = nativeCreate ? nativeCreate(null) : {}; |
||
| 1930 | this.size = 0; |
||
| 1931 | } |
||
| 1932 | |||
| 1933 | /**
|
||
| 1934 | * Removes `key` and its value from the hash.
|
||
| 1935 | *
|
||
| 1936 | * @private
|
||
| 1937 | * @name delete
|
||
| 1938 | * @memberOf Hash
|
||
| 1939 | * @param {Object} hash The hash to modify.
|
||
| 1940 | * @param {string} key The key of the value to remove.
|
||
| 1941 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
||
| 1942 | */
|
||
| 1943 | function hashDelete(key) { |
||
| 1944 | var result = this.has(key) && delete this.__data__[key]; |
||
| 1945 | this.size -= result ? 1 : 0; |
||
| 1946 | return result;
|
||
| 1947 | } |
||
| 1948 | |||
| 1949 | /**
|
||
| 1950 | * Gets the hash value for `key`.
|
||
| 1951 | *
|
||
| 1952 | * @private
|
||
| 1953 | * @name get
|
||
| 1954 | * @memberOf Hash
|
||
| 1955 | * @param {string} key The key of the value to get.
|
||
| 1956 | * @returns {*} Returns the entry value.
|
||
| 1957 | */
|
||
| 1958 | function hashGet(key) { |
||
| 1959 | var data = this.__data__; |
||
| 1960 | if (nativeCreate) {
|
||
| 1961 | var result = data[key];
|
||
| 1962 | return result === HASH_UNDEFINED ? undefined : result; |
||
| 1963 | } |
||
| 1964 | return hasOwnProperty.call(data, key) ? data[key] : undefined; |
||
| 1965 | } |
||
| 1966 | |||
| 1967 | /**
|
||
| 1968 | * Checks if a hash value for `key` exists.
|
||
| 1969 | *
|
||
| 1970 | * @private
|
||
| 1971 | * @name has
|
||
| 1972 | * @memberOf Hash
|
||
| 1973 | * @param {string} key The key of the entry to check.
|
||
| 1974 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
||
| 1975 | */
|
||
| 1976 | function hashHas(key) { |
||
| 1977 | var data = this.__data__; |
||
| 1978 | return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key); |
||
| 1979 | } |
||
| 1980 | |||
| 1981 | /**
|
||
| 1982 | * Sets the hash `key` to `value`.
|
||
| 1983 | *
|
||
| 1984 | * @private
|
||
| 1985 | * @name set
|
||
| 1986 | * @memberOf Hash
|
||
| 1987 | * @param {string} key The key of the value to set.
|
||
| 1988 | * @param {*} value The value to set.
|
||
| 1989 | * @returns {Object} Returns the hash instance.
|
||
| 1990 | */
|
||
| 1991 | function hashSet(key, value) { |
||
| 1992 | var data = this.__data__; |
||
| 1993 | this.size += this.has(key) ? 0 : 1; |
||
| 1994 | data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
||
| 1995 | return this; |
||
| 1996 | } |
||
| 1997 | |||
| 1998 | // Add methods to `Hash`.
|
||
| 1999 | Hash.prototype.clear = hashClear; |
||
| 2000 | Hash.prototype['delete'] = hashDelete;
|
||
| 2001 | Hash.prototype.get = hashGet; |
||
| 2002 | Hash.prototype.has = hashHas; |
||
| 2003 | Hash.prototype.set = hashSet; |
||
| 2004 | |||
| 2005 | /*------------------------------------------------------------------------*/
|
||
| 2006 | |||
| 2007 | /**
|
||
| 2008 | * Creates an list cache object.
|
||
| 2009 | *
|
||
| 2010 | * @private
|
||
| 2011 | * @constructor
|
||
| 2012 | * @param {Array} [entries] The key-value pairs to cache.
|
||
| 2013 | */
|
||
| 2014 | function ListCache(entries) { |
||
| 2015 | var index = -1, |
||
| 2016 | length = entries == null ? 0 : entries.length; |
||
| 2017 | |||
| 2018 | this.clear();
|
||
| 2019 | while (++index < length) {
|
||
| 2020 | var entry = entries[index];
|
||
| 2021 | this.set(entry[0], entry[1]); |
||
| 2022 | } |
||
| 2023 | } |
||
| 2024 | |||
| 2025 | /**
|
||
| 2026 | * Removes all key-value entries from the list cache.
|
||
| 2027 | *
|
||
| 2028 | * @private
|
||
| 2029 | * @name clear
|
||
| 2030 | * @memberOf ListCache
|
||
| 2031 | */
|
||
| 2032 | function listCacheClear() { |
||
| 2033 | this.__data__ = [];
|
||
| 2034 | this.size = 0; |
||
| 2035 | } |
||
| 2036 | |||
| 2037 | /**
|
||
| 2038 | * Removes `key` and its value from the list cache.
|
||
| 2039 | *
|
||
| 2040 | * @private
|
||
| 2041 | * @name delete
|
||
| 2042 | * @memberOf ListCache
|
||
| 2043 | * @param {string} key The key of the value to remove.
|
||
| 2044 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
||
| 2045 | */
|
||
| 2046 | function listCacheDelete(key) { |
||
| 2047 | var data = this.__data__, |
||
| 2048 | index = assocIndexOf(data, key); |
||
| 2049 | |||
| 2050 | if (index < 0) { |
||
| 2051 | return false; |
||
| 2052 | } |
||
| 2053 | var lastIndex = data.length - 1; |
||
| 2054 | if (index == lastIndex) {
|
||
| 2055 | data.pop(); |
||
| 2056 | } else {
|
||
| 2057 | splice.call(data, index, 1);
|
||
| 2058 | } |
||
| 2059 | --this.size;
|
||
| 2060 | return true; |
||
| 2061 | } |
||
| 2062 | |||
| 2063 | /**
|
||
| 2064 | * Gets the list cache value for `key`.
|
||
| 2065 | *
|
||
| 2066 | * @private
|
||
| 2067 | * @name get
|
||
| 2068 | * @memberOf ListCache
|
||
| 2069 | * @param {string} key The key of the value to get.
|
||
| 2070 | * @returns {*} Returns the entry value.
|
||
| 2071 | */
|
||
| 2072 | function listCacheGet(key) { |
||
| 2073 | var data = this.__data__, |
||
| 2074 | index = assocIndexOf(data, key); |
||
| 2075 | |||
| 2076 | return index < 0 ? undefined : data[index][1]; |
||
| 2077 | } |
||
| 2078 | |||
| 2079 | /**
|
||
| 2080 | * Checks if a list cache value for `key` exists.
|
||
| 2081 | *
|
||
| 2082 | * @private
|
||
| 2083 | * @name has
|
||
| 2084 | * @memberOf ListCache
|
||
| 2085 | * @param {string} key The key of the entry to check.
|
||
| 2086 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
||
| 2087 | */
|
||
| 2088 | function listCacheHas(key) { |
||
| 2089 | return assocIndexOf(this.__data__, key) > -1; |
||
| 2090 | } |
||
| 2091 | |||
| 2092 | /**
|
||
| 2093 | * Sets the list cache `key` to `value`.
|
||
| 2094 | *
|
||
| 2095 | * @private
|
||
| 2096 | * @name set
|
||
| 2097 | * @memberOf ListCache
|
||
| 2098 | * @param {string} key The key of the value to set.
|
||
| 2099 | * @param {*} value The value to set.
|
||
| 2100 | * @returns {Object} Returns the list cache instance.
|
||
| 2101 | */
|
||
| 2102 | function listCacheSet(key, value) { |
||
| 2103 | var data = this.__data__, |
||
| 2104 | index = assocIndexOf(data, key); |
||
| 2105 | |||
| 2106 | if (index < 0) { |
||
| 2107 | ++this.size;
|
||
| 2108 | data.push([key, value]); |
||
| 2109 | } else {
|
||
| 2110 | data[index][1] = value;
|
||
| 2111 | } |
||
| 2112 | return this; |
||
| 2113 | } |
||
| 2114 | |||
| 2115 | // Add methods to `ListCache`.
|
||
| 2116 | ListCache.prototype.clear = listCacheClear; |
||
| 2117 | ListCache.prototype['delete'] = listCacheDelete;
|
||
| 2118 | ListCache.prototype.get = listCacheGet; |
||
| 2119 | ListCache.prototype.has = listCacheHas; |
||
| 2120 | ListCache.prototype.set = listCacheSet; |
||
| 2121 | |||
| 2122 | /*------------------------------------------------------------------------*/
|
||
| 2123 | |||
| 2124 | /**
|
||
| 2125 | * Creates a map cache object to store key-value pairs.
|
||
| 2126 | *
|
||
| 2127 | * @private
|
||
| 2128 | * @constructor
|
||
| 2129 | * @param {Array} [entries] The key-value pairs to cache.
|
||
| 2130 | */
|
||
| 2131 | function MapCache(entries) { |
||
| 2132 | var index = -1, |
||
| 2133 | length = entries == null ? 0 : entries.length; |
||
| 2134 | |||
| 2135 | this.clear();
|
||
| 2136 | while (++index < length) {
|
||
| 2137 | var entry = entries[index];
|
||
| 2138 | this.set(entry[0], entry[1]); |
||
| 2139 | } |
||
| 2140 | } |
||
| 2141 | |||
| 2142 | /**
|
||
| 2143 | * Removes all key-value entries from the map.
|
||
| 2144 | *
|
||
| 2145 | * @private
|
||
| 2146 | * @name clear
|
||
| 2147 | * @memberOf MapCache
|
||
| 2148 | */
|
||
| 2149 | function mapCacheClear() { |
||
| 2150 | this.size = 0; |
||
| 2151 | this.__data__ = {
|
||
| 2152 | 'hash': new Hash, |
||
| 2153 | 'map': new (Map || ListCache), |
||
| 2154 | 'string': new Hash |
||
| 2155 | }; |
||
| 2156 | } |
||
| 2157 | |||
| 2158 | /**
|
||
| 2159 | * Removes `key` and its value from the map.
|
||
| 2160 | *
|
||
| 2161 | * @private
|
||
| 2162 | * @name delete
|
||
| 2163 | * @memberOf MapCache
|
||
| 2164 | * @param {string} key The key of the value to remove.
|
||
| 2165 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
||
| 2166 | */
|
||
| 2167 | function mapCacheDelete(key) { |
||
| 2168 | var result = getMapData(this, key)['delete'](key); |
||
| 2169 | this.size -= result ? 1 : 0; |
||
| 2170 | return result;
|
||
| 2171 | } |
||
| 2172 | |||
| 2173 | /**
|
||
| 2174 | * Gets the map value for `key`.
|
||
| 2175 | *
|
||
| 2176 | * @private
|
||
| 2177 | * @name get
|
||
| 2178 | * @memberOf MapCache
|
||
| 2179 | * @param {string} key The key of the value to get.
|
||
| 2180 | * @returns {*} Returns the entry value.
|
||
| 2181 | */
|
||
| 2182 | function mapCacheGet(key) { |
||
| 2183 | return getMapData(this, key).get(key); |
||
| 2184 | } |
||
| 2185 | |||
| 2186 | /**
|
||
| 2187 | * Checks if a map value for `key` exists.
|
||
| 2188 | *
|
||
| 2189 | * @private
|
||
| 2190 | * @name has
|
||
| 2191 | * @memberOf MapCache
|
||
| 2192 | * @param {string} key The key of the entry to check.
|
||
| 2193 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
||
| 2194 | */
|
||
| 2195 | function mapCacheHas(key) { |
||
| 2196 | return getMapData(this, key).has(key); |
||
| 2197 | } |
||
| 2198 | |||
| 2199 | /**
|
||
| 2200 | * Sets the map `key` to `value`.
|
||
| 2201 | *
|
||
| 2202 | * @private
|
||
| 2203 | * @name set
|
||
| 2204 | * @memberOf MapCache
|
||
| 2205 | * @param {string} key The key of the value to set.
|
||
| 2206 | * @param {*} value The value to set.
|
||
| 2207 | * @returns {Object} Returns the map cache instance.
|
||
| 2208 | */
|
||
| 2209 | function mapCacheSet(key, value) { |
||
| 2210 | var data = getMapData(this, key), |
||
| 2211 | size = data.size; |
||
| 2212 | |||
| 2213 | data.set(key, value); |
||
| 2214 | this.size += data.size == size ? 0 : 1; |
||
| 2215 | return this; |
||
| 2216 | } |
||
| 2217 | |||
| 2218 | // Add methods to `MapCache`.
|
||
| 2219 | MapCache.prototype.clear = mapCacheClear; |
||
| 2220 | MapCache.prototype['delete'] = mapCacheDelete;
|
||
| 2221 | MapCache.prototype.get = mapCacheGet; |
||
| 2222 | MapCache.prototype.has = mapCacheHas; |
||
| 2223 | MapCache.prototype.set = mapCacheSet; |
||
| 2224 | |||
| 2225 | /*------------------------------------------------------------------------*/
|
||
| 2226 | |||
| 2227 | /**
|
||
| 2228 | *
|
||
| 2229 | * Creates an array cache object to store unique values.
|
||
| 2230 | *
|
||
| 2231 | * @private
|
||
| 2232 | * @constructor
|
||
| 2233 | * @param {Array} [values] The values to cache.
|
||
| 2234 | */
|
||
| 2235 | function SetCache(values) { |
||
| 2236 | var index = -1, |
||
| 2237 | length = values == null ? 0 : values.length; |
||
| 2238 | |||
| 2239 | this.__data__ = new MapCache; |
||
| 2240 | while (++index < length) {
|
||
| 2241 | this.add(values[index]);
|
||
| 2242 | } |
||
| 2243 | } |
||
| 2244 | |||
| 2245 | /**
|
||
| 2246 | * Adds `value` to the array cache.
|
||
| 2247 | *
|
||
| 2248 | * @private
|
||
| 2249 | * @name add
|
||
| 2250 | * @memberOf SetCache
|
||
| 2251 | * @alias push
|
||
| 2252 | * @param {*} value The value to cache.
|
||
| 2253 | * @returns {Object} Returns the cache instance.
|
||
| 2254 | */
|
||
| 2255 | function setCacheAdd(value) { |
||
| 2256 | this.__data__.set(value, HASH_UNDEFINED);
|
||
| 2257 | return this; |
||
| 2258 | } |
||
| 2259 | |||
| 2260 | /**
|
||
| 2261 | * Checks if `value` is in the array cache.
|
||
| 2262 | *
|
||
| 2263 | * @private
|
||
| 2264 | * @name has
|
||
| 2265 | * @memberOf SetCache
|
||
| 2266 | * @param {*} value The value to search for.
|
||
| 2267 | * @returns {number} Returns `true` if `value` is found, else `false`.
|
||
| 2268 | */
|
||
| 2269 | function setCacheHas(value) { |
||
| 2270 | return this.__data__.has(value); |
||
| 2271 | } |
||
| 2272 | |||
| 2273 | // Add methods to `SetCache`.
|
||
| 2274 | SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; |
||
| 2275 | SetCache.prototype.has = setCacheHas; |
||
| 2276 | |||
| 2277 | /*------------------------------------------------------------------------*/
|
||
| 2278 | |||
| 2279 | /**
|
||
| 2280 | * Creates a stack cache object to store key-value pairs.
|
||
| 2281 | *
|
||
| 2282 | * @private
|
||
| 2283 | * @constructor
|
||
| 2284 | * @param {Array} [entries] The key-value pairs to cache.
|
||
| 2285 | */
|
||
| 2286 | function Stack(entries) { |
||
| 2287 | var data = this.__data__ = new ListCache(entries); |
||
| 2288 | this.size = data.size;
|
||
| 2289 | } |
||
| 2290 | |||
| 2291 | /**
|
||
| 2292 | * Removes all key-value entries from the stack.
|
||
| 2293 | *
|
||
| 2294 | * @private
|
||
| 2295 | * @name clear
|
||
| 2296 | * @memberOf Stack
|
||
| 2297 | */
|
||
| 2298 | function stackClear() { |
||
| 2299 | this.__data__ = new ListCache; |
||
| 2300 | this.size = 0; |
||
| 2301 | } |
||
| 2302 | |||
| 2303 | /**
|
||
| 2304 | * Removes `key` and its value from the stack.
|
||
| 2305 | *
|
||
| 2306 | * @private
|
||
| 2307 | * @name delete
|
||
| 2308 | * @memberOf Stack
|
||
| 2309 | * @param {string} key The key of the value to remove.
|
||
| 2310 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
||
| 2311 | */
|
||
| 2312 | function stackDelete(key) { |
||
| 2313 | var data = this.__data__, |
||
| 2314 | result = data['delete'](key);
|
||
| 2315 | |||
| 2316 | this.size = data.size;
|
||
| 2317 | return result;
|
||
| 2318 | } |
||
| 2319 | |||
| 2320 | /**
|
||
| 2321 | * Gets the stack value for `key`.
|
||
| 2322 | *
|
||
| 2323 | * @private
|
||
| 2324 | * @name get
|
||
| 2325 | * @memberOf Stack
|
||
| 2326 | * @param {string} key The key of the value to get.
|
||
| 2327 | * @returns {*} Returns the entry value.
|
||
| 2328 | */
|
||
| 2329 | function stackGet(key) { |
||
| 2330 | return this.__data__.get(key); |
||
| 2331 | } |
||
| 2332 | |||
| 2333 | /**
|
||
| 2334 | * Checks if a stack value for `key` exists.
|
||
| 2335 | *
|
||
| 2336 | * @private
|
||
| 2337 | * @name has
|
||
| 2338 | * @memberOf Stack
|
||
| 2339 | * @param {string} key The key of the entry to check.
|
||
| 2340 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
||
| 2341 | */
|
||
| 2342 | function stackHas(key) { |
||
| 2343 | return this.__data__.has(key); |
||
| 2344 | } |
||
| 2345 | |||
| 2346 | /**
|
||
| 2347 | * Sets the stack `key` to `value`.
|
||
| 2348 | *
|
||
| 2349 | * @private
|
||
| 2350 | * @name set
|
||
| 2351 | * @memberOf Stack
|
||
| 2352 | * @param {string} key The key of the value to set.
|
||
| 2353 | * @param {*} value The value to set.
|
||
| 2354 | * @returns {Object} Returns the stack cache instance.
|
||
| 2355 | */
|
||
| 2356 | function stackSet(key, value) { |
||
| 2357 | var data = this.__data__; |
||
| 2358 | if (data instanceof ListCache) { |
||
| 2359 | var pairs = data.__data__;
|
||
| 2360 | if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { |
||
| 2361 | pairs.push([key, value]); |
||
| 2362 | this.size = ++data.size;
|
||
| 2363 | return this; |
||
| 2364 | } |
||
| 2365 | data = this.__data__ = new MapCache(pairs); |
||
| 2366 | } |
||
| 2367 | data.set(key, value); |
||
| 2368 | this.size = data.size;
|
||
| 2369 | return this; |
||
| 2370 | } |
||
| 2371 | |||
| 2372 | // Add methods to `Stack`.
|
||
| 2373 | Stack.prototype.clear = stackClear; |
||
| 2374 | Stack.prototype['delete'] = stackDelete;
|
||
| 2375 | Stack.prototype.get = stackGet; |
||
| 2376 | Stack.prototype.has = stackHas; |
||
| 2377 | Stack.prototype.set = stackSet; |
||
| 2378 | |||
| 2379 | /*------------------------------------------------------------------------*/
|
||
| 2380 | |||
| 2381 | /**
|
||
| 2382 | * Creates an array of the enumerable property names of the array-like `value`.
|
||
| 2383 | *
|
||
| 2384 | * @private
|
||
| 2385 | * @param {*} value The value to query.
|
||
| 2386 | * @param {boolean} inherited Specify returning inherited property names.
|
||
| 2387 | * @returns {Array} Returns the array of property names.
|
||
| 2388 | */
|
||
| 2389 | function arrayLikeKeys(value, inherited) { |
||
| 2390 | var isArr = isArray(value),
|
||
| 2391 | isArg = !isArr && isArguments(value), |
||
| 2392 | isBuff = !isArr && !isArg && isBuffer(value), |
||
| 2393 | isType = !isArr && !isArg && !isBuff && isTypedArray(value), |
||
| 2394 | skipIndexes = isArr || isArg || isBuff || isType, |
||
| 2395 | result = skipIndexes ? baseTimes(value.length, String) : [], |
||
| 2396 | length = result.length; |
||
| 2397 | |||
| 2398 | for (var key in value) { |
||
| 2399 | if ((inherited || hasOwnProperty.call(value, key)) &&
|
||
| 2400 | !(skipIndexes && ( |
||
| 2401 | // Safari 9 has enumerable `arguments.length` in strict mode.
|
||
| 2402 | key == 'length' ||
|
||
| 2403 | // Node.js 0.10 has enumerable non-index properties on buffers.
|
||
| 2404 | (isBuff && (key == 'offset' || key == 'parent')) || |
||
| 2405 | // PhantomJS 2 has enumerable non-index properties on typed arrays.
|
||
| 2406 | (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || |
||
| 2407 | // Skip index properties.
|
||
| 2408 | isIndex(key, length) |
||
| 2409 | ))) {
|
||
| 2410 | result.push(key); |
||
| 2411 | } |
||
| 2412 | } |
||
| 2413 | return result;
|
||
| 2414 | } |
||
| 2415 | |||
| 2416 | /**
|
||
| 2417 | * A specialized version of `_.sample` for arrays.
|
||
| 2418 | *
|
||
| 2419 | * @private
|
||
| 2420 | * @param {Array} array The array to sample.
|
||
| 2421 | * @returns {*} Returns the random element.
|
||
| 2422 | */
|
||
| 2423 | function arraySample(array) { |
||
| 2424 | var length = array.length;
|
||
| 2425 | return length ? array[baseRandom(0, length - 1)] : undefined; |
||
| 2426 | } |
||
| 2427 | |||
| 2428 | /**
|
||
| 2429 | * A specialized version of `_.sampleSize` for arrays.
|
||
| 2430 | *
|
||
| 2431 | * @private
|
||
| 2432 | * @param {Array} array The array to sample.
|
||
| 2433 | * @param {number} n The number of elements to sample.
|
||
| 2434 | * @returns {Array} Returns the random elements.
|
||
| 2435 | */
|
||
| 2436 | function arraySampleSize(array, n) { |
||
| 2437 | return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); |
||
| 2438 | } |
||
| 2439 | |||
| 2440 | /**
|
||
| 2441 | * A specialized version of `_.shuffle` for arrays.
|
||
| 2442 | *
|
||
| 2443 | * @private
|
||
| 2444 | * @param {Array} array The array to shuffle.
|
||
| 2445 | * @returns {Array} Returns the new shuffled array.
|
||
| 2446 | */
|
||
| 2447 | function arrayShuffle(array) { |
||
| 2448 | return shuffleSelf(copyArray(array));
|
||
| 2449 | } |
||
| 2450 | |||
| 2451 | /**
|
||
| 2452 | * This function is like `assignValue` except that it doesn't assign
|
||
| 2453 | * `undefined` values.
|
||
| 2454 | *
|
||
| 2455 | * @private
|
||
| 2456 | * @param {Object} object The object to modify.
|
||
| 2457 | * @param {string} key The key of the property to assign.
|
||
| 2458 | * @param {*} value The value to assign.
|
||
| 2459 | */
|
||
| 2460 | function assignMergeValue(object, key, value) { |
||
| 2461 | if ((value !== undefined && !eq(object[key], value)) || |
||
| 2462 | (value === undefined && !(key in object))) { |
||
| 2463 | baseAssignValue(object, key, value); |
||
| 2464 | } |
||
| 2465 | } |
||
| 2466 | |||
| 2467 | /**
|
||
| 2468 | * Assigns `value` to `key` of `object` if the existing value is not equivalent
|
||
| 2469 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 2470 | * for equality comparisons.
|
||
| 2471 | *
|
||
| 2472 | * @private
|
||
| 2473 | * @param {Object} object The object to modify.
|
||
| 2474 | * @param {string} key The key of the property to assign.
|
||
| 2475 | * @param {*} value The value to assign.
|
||
| 2476 | */
|
||
| 2477 | function assignValue(object, key, value) { |
||
| 2478 | var objValue = object[key];
|
||
| 2479 | if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
||
| 2480 | (value === undefined && !(key in object))) { |
||
| 2481 | baseAssignValue(object, key, value); |
||
| 2482 | } |
||
| 2483 | } |
||
| 2484 | |||
| 2485 | /**
|
||
| 2486 | * Gets the index at which the `key` is found in `array` of key-value pairs.
|
||
| 2487 | *
|
||
| 2488 | * @private
|
||
| 2489 | * @param {Array} array The array to inspect.
|
||
| 2490 | * @param {*} key The key to search for.
|
||
| 2491 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 2492 | */
|
||
| 2493 | function assocIndexOf(array, key) { |
||
| 2494 | var length = array.length;
|
||
| 2495 | while (length--) {
|
||
| 2496 | if (eq(array[length][0], key)) { |
||
| 2497 | return length;
|
||
| 2498 | } |
||
| 2499 | } |
||
| 2500 | return -1; |
||
| 2501 | } |
||
| 2502 | |||
| 2503 | /**
|
||
| 2504 | * Aggregates elements of `collection` on `accumulator` with keys transformed
|
||
| 2505 | * by `iteratee` and values set by `setter`.
|
||
| 2506 | *
|
||
| 2507 | * @private
|
||
| 2508 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 2509 | * @param {Function} setter The function to set `accumulator` values.
|
||
| 2510 | * @param {Function} iteratee The iteratee to transform keys.
|
||
| 2511 | * @param {Object} accumulator The initial aggregated object.
|
||
| 2512 | * @returns {Function} Returns `accumulator`.
|
||
| 2513 | */
|
||
| 2514 | function baseAggregator(collection, setter, iteratee, accumulator) { |
||
| 2515 | baseEach(collection, function(value, key, collection) {
|
||
| 2516 | setter(accumulator, value, iteratee(value), collection); |
||
| 2517 | }); |
||
| 2518 | return accumulator;
|
||
| 2519 | } |
||
| 2520 | |||
| 2521 | /**
|
||
| 2522 | * The base implementation of `_.assign` without support for multiple sources
|
||
| 2523 | * or `customizer` functions.
|
||
| 2524 | *
|
||
| 2525 | * @private
|
||
| 2526 | * @param {Object} object The destination object.
|
||
| 2527 | * @param {Object} source The source object.
|
||
| 2528 | * @returns {Object} Returns `object`.
|
||
| 2529 | */
|
||
| 2530 | function baseAssign(object, source) { |
||
| 2531 | return object && copyObject(source, keys(source), object);
|
||
| 2532 | } |
||
| 2533 | |||
| 2534 | /**
|
||
| 2535 | * The base implementation of `_.assignIn` without support for multiple sources
|
||
| 2536 | * or `customizer` functions.
|
||
| 2537 | *
|
||
| 2538 | * @private
|
||
| 2539 | * @param {Object} object The destination object.
|
||
| 2540 | * @param {Object} source The source object.
|
||
| 2541 | * @returns {Object} Returns `object`.
|
||
| 2542 | */
|
||
| 2543 | function baseAssignIn(object, source) { |
||
| 2544 | return object && copyObject(source, keysIn(source), object);
|
||
| 2545 | } |
||
| 2546 | |||
| 2547 | /**
|
||
| 2548 | * The base implementation of `assignValue` and `assignMergeValue` without
|
||
| 2549 | * value checks.
|
||
| 2550 | *
|
||
| 2551 | * @private
|
||
| 2552 | * @param {Object} object The object to modify.
|
||
| 2553 | * @param {string} key The key of the property to assign.
|
||
| 2554 | * @param {*} value The value to assign.
|
||
| 2555 | */
|
||
| 2556 | function baseAssignValue(object, key, value) { |
||
| 2557 | if (key == '__proto__' && defineProperty) { |
||
| 2558 | defineProperty(object, key, {
|
||
| 2559 | 'configurable': true, |
||
| 2560 | 'enumerable': true, |
||
| 2561 | 'value': value,
|
||
| 2562 | 'writable': true |
||
| 2563 | }); |
||
| 2564 | } else {
|
||
| 2565 | object[key] = value; |
||
| 2566 | } |
||
| 2567 | } |
||
| 2568 | |||
| 2569 | /**
|
||
| 2570 | * The base implementation of `_.at` without support for individual paths.
|
||
| 2571 | *
|
||
| 2572 | * @private
|
||
| 2573 | * @param {Object} object The object to iterate over.
|
||
| 2574 | * @param {string[]} paths The property paths to pick.
|
||
| 2575 | * @returns {Array} Returns the picked elements.
|
||
| 2576 | */
|
||
| 2577 | function baseAt(object, paths) { |
||
| 2578 | var index = -1, |
||
| 2579 | length = paths.length, |
||
| 2580 | result = Array(length), |
||
| 2581 | skip = object == null;
|
||
| 2582 | |||
| 2583 | while (++index < length) {
|
||
| 2584 | result[index] = skip ? undefined : get(object, paths[index]);
|
||
| 2585 | } |
||
| 2586 | return result;
|
||
| 2587 | } |
||
| 2588 | |||
| 2589 | /**
|
||
| 2590 | * The base implementation of `_.clamp` which doesn't coerce arguments.
|
||
| 2591 | *
|
||
| 2592 | * @private
|
||
| 2593 | * @param {number} number The number to clamp.
|
||
| 2594 | * @param {number} [lower] The lower bound.
|
||
| 2595 | * @param {number} upper The upper bound.
|
||
| 2596 | * @returns {number} Returns the clamped number.
|
||
| 2597 | */
|
||
| 2598 | function baseClamp(number, lower, upper) { |
||
| 2599 | if (number === number) {
|
||
| 2600 | if (upper !== undefined) { |
||
| 2601 | number = number <= upper ? number : upper; |
||
| 2602 | } |
||
| 2603 | if (lower !== undefined) { |
||
| 2604 | number = number >= lower ? number : lower; |
||
| 2605 | } |
||
| 2606 | } |
||
| 2607 | return number;
|
||
| 2608 | } |
||
| 2609 | |||
| 2610 | /**
|
||
| 2611 | * The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
||
| 2612 | * traversed objects.
|
||
| 2613 | *
|
||
| 2614 | * @private
|
||
| 2615 | * @param {*} value The value to clone.
|
||
| 2616 | * @param {boolean} bitmask The bitmask flags.
|
||
| 2617 | * 1 - Deep clone
|
||
| 2618 | * 2 - Flatten inherited properties
|
||
| 2619 | * 4 - Clone symbols
|
||
| 2620 | * @param {Function} [customizer] The function to customize cloning.
|
||
| 2621 | * @param {string} [key] The key of `value`.
|
||
| 2622 | * @param {Object} [object] The parent object of `value`.
|
||
| 2623 | * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
||
| 2624 | * @returns {*} Returns the cloned value.
|
||
| 2625 | */
|
||
| 2626 | function baseClone(value, bitmask, customizer, key, object, stack) { |
||
| 2627 | var result,
|
||
| 2628 | isDeep = bitmask & CLONE_DEEP_FLAG, |
||
| 2629 | isFlat = bitmask & CLONE_FLAT_FLAG, |
||
| 2630 | isFull = bitmask & CLONE_SYMBOLS_FLAG; |
||
| 2631 | |||
| 2632 | if (customizer) {
|
||
| 2633 | result = object ? customizer(value, key, object, stack) : customizer(value); |
||
| 2634 | } |
||
| 2635 | if (result !== undefined) { |
||
| 2636 | return result;
|
||
| 2637 | } |
||
| 2638 | if (!isObject(value)) {
|
||
| 2639 | return value;
|
||
| 2640 | } |
||
| 2641 | var isArr = isArray(value);
|
||
| 2642 | if (isArr) {
|
||
| 2643 | result = initCloneArray(value); |
||
| 2644 | if (!isDeep) {
|
||
| 2645 | return copyArray(value, result);
|
||
| 2646 | } |
||
| 2647 | } else {
|
||
| 2648 | var tag = getTag(value),
|
||
| 2649 | isFunc = tag == funcTag || tag == genTag; |
||
| 2650 | |||
| 2651 | if (isBuffer(value)) {
|
||
| 2652 | return cloneBuffer(value, isDeep);
|
||
| 2653 | } |
||
| 2654 | if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
||
| 2655 | result = (isFlat || isFunc) ? {} : initCloneObject(value);
|
||
| 2656 | if (!isDeep) {
|
||
| 2657 | return isFlat
|
||
| 2658 | ? copySymbolsIn(value, baseAssignIn(result, value)) |
||
| 2659 | : copySymbols(value, baseAssign(result, value)); |
||
| 2660 | } |
||
| 2661 | } else {
|
||
| 2662 | if (!cloneableTags[tag]) {
|
||
| 2663 | return object ? value : {};
|
||
| 2664 | } |
||
| 2665 | result = initCloneByTag(value, tag, isDeep); |
||
| 2666 | } |
||
| 2667 | } |
||
| 2668 | // Check for circular references and return its corresponding clone.
|
||
| 2669 | stack || (stack = new Stack);
|
||
| 2670 | var stacked = stack.get(value);
|
||
| 2671 | if (stacked) {
|
||
| 2672 | return stacked;
|
||
| 2673 | } |
||
| 2674 | stack.set(value, result); |
||
| 2675 | |||
| 2676 | if (isSet(value)) {
|
||
| 2677 | value.forEach(function(subValue) {
|
||
| 2678 | result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)); |
||
| 2679 | }); |
||
| 2680 | |||
| 2681 | return result;
|
||
| 2682 | } |
||
| 2683 | |||
| 2684 | if (isMap(value)) {
|
||
| 2685 | value.forEach(function(subValue, key) {
|
||
| 2686 | result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)); |
||
| 2687 | }); |
||
| 2688 | |||
| 2689 | return result;
|
||
| 2690 | } |
||
| 2691 | |||
| 2692 | var keysFunc = isFull
|
||
| 2693 | ? (isFlat ? getAllKeysIn : getAllKeys) |
||
| 2694 | : (isFlat ? keysIn : keys); |
||
| 2695 | |||
| 2696 | var props = isArr ? undefined : keysFunc(value); |
||
| 2697 | arrayEach(props || value, function(subValue, key) {
|
||
| 2698 | if (props) {
|
||
| 2699 | key = subValue; |
||
| 2700 | subValue = value[key]; |
||
| 2701 | } |
||
| 2702 | // Recursively populate clone (susceptible to call stack limits).
|
||
| 2703 | assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack)); |
||
| 2704 | }); |
||
| 2705 | return result;
|
||
| 2706 | } |
||
| 2707 | |||
| 2708 | /**
|
||
| 2709 | * The base implementation of `_.conforms` which doesn't clone `source`.
|
||
| 2710 | *
|
||
| 2711 | * @private
|
||
| 2712 | * @param {Object} source The object of property predicates to conform to.
|
||
| 2713 | * @returns {Function} Returns the new spec function.
|
||
| 2714 | */
|
||
| 2715 | function baseConforms(source) { |
||
| 2716 | var props = keys(source);
|
||
| 2717 | return function(object) { |
||
| 2718 | return baseConformsTo(object, source, props);
|
||
| 2719 | }; |
||
| 2720 | } |
||
| 2721 | |||
| 2722 | /**
|
||
| 2723 | * The base implementation of `_.conformsTo` which accepts `props` to check.
|
||
| 2724 | *
|
||
| 2725 | * @private
|
||
| 2726 | * @param {Object} object The object to inspect.
|
||
| 2727 | * @param {Object} source The object of property predicates to conform to.
|
||
| 2728 | * @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
||
| 2729 | */
|
||
| 2730 | function baseConformsTo(object, source, props) { |
||
| 2731 | var length = props.length;
|
||
| 2732 | if (object == null) { |
||
| 2733 | return !length;
|
||
| 2734 | } |
||
| 2735 | object = Object(object); |
||
| 2736 | while (length--) {
|
||
| 2737 | var key = props[length],
|
||
| 2738 | predicate = source[key], |
||
| 2739 | value = object[key]; |
||
| 2740 | |||
| 2741 | if ((value === undefined && !(key in object)) || !predicate(value)) { |
||
| 2742 | return false; |
||
| 2743 | } |
||
| 2744 | } |
||
| 2745 | return true; |
||
| 2746 | } |
||
| 2747 | |||
| 2748 | /**
|
||
| 2749 | * The base implementation of `_.delay` and `_.defer` which accepts `args`
|
||
| 2750 | * to provide to `func`.
|
||
| 2751 | *
|
||
| 2752 | * @private
|
||
| 2753 | * @param {Function} func The function to delay.
|
||
| 2754 | * @param {number} wait The number of milliseconds to delay invocation.
|
||
| 2755 | * @param {Array} args The arguments to provide to `func`.
|
||
| 2756 | * @returns {number|Object} Returns the timer id or timeout object.
|
||
| 2757 | */
|
||
| 2758 | function baseDelay(func, wait, args) { |
||
| 2759 | if (typeof func != 'function') { |
||
| 2760 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 2761 | } |
||
| 2762 | return setTimeout(function() { func.apply(undefined, args); }, wait); |
||
| 2763 | } |
||
| 2764 | |||
| 2765 | /**
|
||
| 2766 | * The base implementation of methods like `_.difference` without support
|
||
| 2767 | * for excluding multiple arrays or iteratee shorthands.
|
||
| 2768 | *
|
||
| 2769 | * @private
|
||
| 2770 | * @param {Array} array The array to inspect.
|
||
| 2771 | * @param {Array} values The values to exclude.
|
||
| 2772 | * @param {Function} [iteratee] The iteratee invoked per element.
|
||
| 2773 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 2774 | * @returns {Array} Returns the new array of filtered values.
|
||
| 2775 | */
|
||
| 2776 | function baseDifference(array, values, iteratee, comparator) { |
||
| 2777 | var index = -1, |
||
| 2778 | includes = arrayIncludes, |
||
| 2779 | isCommon = true,
|
||
| 2780 | length = array.length, |
||
| 2781 | result = [], |
||
| 2782 | valuesLength = values.length; |
||
| 2783 | |||
| 2784 | if (!length) {
|
||
| 2785 | return result;
|
||
| 2786 | } |
||
| 2787 | if (iteratee) {
|
||
| 2788 | values = arrayMap(values, baseUnary(iteratee)); |
||
| 2789 | } |
||
| 2790 | if (comparator) {
|
||
| 2791 | includes = arrayIncludesWith; |
||
| 2792 | isCommon = false;
|
||
| 2793 | } |
||
| 2794 | else if (values.length >= LARGE_ARRAY_SIZE) { |
||
| 2795 | includes = cacheHas; |
||
| 2796 | isCommon = false;
|
||
| 2797 | values = new SetCache(values);
|
||
| 2798 | } |
||
| 2799 | outer: |
||
| 2800 | while (++index < length) {
|
||
| 2801 | var value = array[index],
|
||
| 2802 | computed = iteratee == null ? value : iteratee(value);
|
||
| 2803 | |||
| 2804 | value = (comparator || value !== 0) ? value : 0; |
||
| 2805 | if (isCommon && computed === computed) {
|
||
| 2806 | var valuesIndex = valuesLength;
|
||
| 2807 | while (valuesIndex--) {
|
||
| 2808 | if (values[valuesIndex] === computed) {
|
||
| 2809 | continue outer;
|
||
| 2810 | } |
||
| 2811 | } |
||
| 2812 | result.push(value); |
||
| 2813 | } |
||
| 2814 | else if (!includes(values, computed, comparator)) { |
||
| 2815 | result.push(value); |
||
| 2816 | } |
||
| 2817 | } |
||
| 2818 | return result;
|
||
| 2819 | } |
||
| 2820 | |||
| 2821 | /**
|
||
| 2822 | * The base implementation of `_.forEach` without support for iteratee shorthands.
|
||
| 2823 | *
|
||
| 2824 | * @private
|
||
| 2825 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 2826 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 2827 | * @returns {Array|Object} Returns `collection`.
|
||
| 2828 | */
|
||
| 2829 | var baseEach = createBaseEach(baseForOwn);
|
||
| 2830 | |||
| 2831 | /**
|
||
| 2832 | * The base implementation of `_.forEachRight` without support for iteratee shorthands.
|
||
| 2833 | *
|
||
| 2834 | * @private
|
||
| 2835 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 2836 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 2837 | * @returns {Array|Object} Returns `collection`.
|
||
| 2838 | */
|
||
| 2839 | var baseEachRight = createBaseEach(baseForOwnRight, true); |
||
| 2840 | |||
| 2841 | /**
|
||
| 2842 | * The base implementation of `_.every` without support for iteratee shorthands.
|
||
| 2843 | *
|
||
| 2844 | * @private
|
||
| 2845 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 2846 | * @param {Function} predicate The function invoked per iteration.
|
||
| 2847 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
||
| 2848 | * else `false`
|
||
| 2849 | */
|
||
| 2850 | function baseEvery(collection, predicate) { |
||
| 2851 | var result = true; |
||
| 2852 | baseEach(collection, function(value, index, collection) {
|
||
| 2853 | result = !!predicate(value, index, collection); |
||
| 2854 | return result;
|
||
| 2855 | }); |
||
| 2856 | return result;
|
||
| 2857 | } |
||
| 2858 | |||
| 2859 | /**
|
||
| 2860 | * The base implementation of methods like `_.max` and `_.min` which accepts a
|
||
| 2861 | * `comparator` to determine the extremum value.
|
||
| 2862 | *
|
||
| 2863 | * @private
|
||
| 2864 | * @param {Array} array The array to iterate over.
|
||
| 2865 | * @param {Function} iteratee The iteratee invoked per iteration.
|
||
| 2866 | * @param {Function} comparator The comparator used to compare values.
|
||
| 2867 | * @returns {*} Returns the extremum value.
|
||
| 2868 | */
|
||
| 2869 | function baseExtremum(array, iteratee, comparator) { |
||
| 2870 | var index = -1, |
||
| 2871 | length = array.length; |
||
| 2872 | |||
| 2873 | while (++index < length) {
|
||
| 2874 | var value = array[index],
|
||
| 2875 | current = iteratee(value); |
||
| 2876 | |||
| 2877 | if (current != null && (computed === undefined |
||
| 2878 | ? (current === current && !isSymbol(current)) |
||
| 2879 | : comparator(current, computed) |
||
| 2880 | )) {
|
||
| 2881 | var computed = current,
|
||
| 2882 | result = value; |
||
| 2883 | } |
||
| 2884 | } |
||
| 2885 | return result;
|
||
| 2886 | } |
||
| 2887 | |||
| 2888 | /**
|
||
| 2889 | * The base implementation of `_.fill` without an iteratee call guard.
|
||
| 2890 | *
|
||
| 2891 | * @private
|
||
| 2892 | * @param {Array} array The array to fill.
|
||
| 2893 | * @param {*} value The value to fill `array` with.
|
||
| 2894 | * @param {number} [start=0] The start position.
|
||
| 2895 | * @param {number} [end=array.length] The end position.
|
||
| 2896 | * @returns {Array} Returns `array`.
|
||
| 2897 | */
|
||
| 2898 | function baseFill(array, value, start, end) { |
||
| 2899 | var length = array.length;
|
||
| 2900 | |||
| 2901 | start = toInteger(start); |
||
| 2902 | if (start < 0) { |
||
| 2903 | start = -start > length ? 0 : (length + start);
|
||
| 2904 | } |
||
| 2905 | end = (end === undefined || end > length) ? length : toInteger(end);
|
||
| 2906 | if (end < 0) { |
||
| 2907 | end += length; |
||
| 2908 | } |
||
| 2909 | end = start > end ? 0 : toLength(end);
|
||
| 2910 | while (start < end) {
|
||
| 2911 | array[start++] = value; |
||
| 2912 | } |
||
| 2913 | return array;
|
||
| 2914 | } |
||
| 2915 | |||
| 2916 | /**
|
||
| 2917 | * The base implementation of `_.filter` without support for iteratee shorthands.
|
||
| 2918 | *
|
||
| 2919 | * @private
|
||
| 2920 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 2921 | * @param {Function} predicate The function invoked per iteration.
|
||
| 2922 | * @returns {Array} Returns the new filtered array.
|
||
| 2923 | */
|
||
| 2924 | function baseFilter(collection, predicate) { |
||
| 2925 | var result = [];
|
||
| 2926 | baseEach(collection, function(value, index, collection) {
|
||
| 2927 | if (predicate(value, index, collection)) {
|
||
| 2928 | result.push(value); |
||
| 2929 | } |
||
| 2930 | }); |
||
| 2931 | return result;
|
||
| 2932 | } |
||
| 2933 | |||
| 2934 | /**
|
||
| 2935 | * The base implementation of `_.flatten` with support for restricting flattening.
|
||
| 2936 | *
|
||
| 2937 | * @private
|
||
| 2938 | * @param {Array} array The array to flatten.
|
||
| 2939 | * @param {number} depth The maximum recursion depth.
|
||
| 2940 | * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
|
||
| 2941 | * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
|
||
| 2942 | * @param {Array} [result=[]] The initial result value.
|
||
| 2943 | * @returns {Array} Returns the new flattened array.
|
||
| 2944 | */
|
||
| 2945 | function baseFlatten(array, depth, predicate, isStrict, result) { |
||
| 2946 | var index = -1, |
||
| 2947 | length = array.length; |
||
| 2948 | |||
| 2949 | predicate || (predicate = isFlattenable); |
||
| 2950 | result || (result = []); |
||
| 2951 | |||
| 2952 | while (++index < length) {
|
||
| 2953 | var value = array[index];
|
||
| 2954 | if (depth > 0 && predicate(value)) { |
||
| 2955 | if (depth > 1) { |
||
| 2956 | // Recursively flatten arrays (susceptible to call stack limits).
|
||
| 2957 | baseFlatten(value, depth - 1, predicate, isStrict, result);
|
||
| 2958 | } else {
|
||
| 2959 | arrayPush(result, value); |
||
| 2960 | } |
||
| 2961 | } else if (!isStrict) { |
||
| 2962 | result[result.length] = value; |
||
| 2963 | } |
||
| 2964 | } |
||
| 2965 | return result;
|
||
| 2966 | } |
||
| 2967 | |||
| 2968 | /**
|
||
| 2969 | * The base implementation of `baseForOwn` which iterates over `object`
|
||
| 2970 | * properties returned by `keysFunc` and invokes `iteratee` for each property.
|
||
| 2971 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
||
| 2972 | *
|
||
| 2973 | * @private
|
||
| 2974 | * @param {Object} object The object to iterate over.
|
||
| 2975 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 2976 | * @param {Function} keysFunc The function to get the keys of `object`.
|
||
| 2977 | * @returns {Object} Returns `object`.
|
||
| 2978 | */
|
||
| 2979 | var baseFor = createBaseFor();
|
||
| 2980 | |||
| 2981 | /**
|
||
| 2982 | * This function is like `baseFor` except that it iterates over properties
|
||
| 2983 | * in the opposite order.
|
||
| 2984 | *
|
||
| 2985 | * @private
|
||
| 2986 | * @param {Object} object The object to iterate over.
|
||
| 2987 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 2988 | * @param {Function} keysFunc The function to get the keys of `object`.
|
||
| 2989 | * @returns {Object} Returns `object`.
|
||
| 2990 | */
|
||
| 2991 | var baseForRight = createBaseFor(true); |
||
| 2992 | |||
| 2993 | /**
|
||
| 2994 | * The base implementation of `_.forOwn` without support for iteratee shorthands.
|
||
| 2995 | *
|
||
| 2996 | * @private
|
||
| 2997 | * @param {Object} object The object to iterate over.
|
||
| 2998 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 2999 | * @returns {Object} Returns `object`.
|
||
| 3000 | */
|
||
| 3001 | function baseForOwn(object, iteratee) { |
||
| 3002 | return object && baseFor(object, iteratee, keys);
|
||
| 3003 | } |
||
| 3004 | |||
| 3005 | /**
|
||
| 3006 | * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
|
||
| 3007 | *
|
||
| 3008 | * @private
|
||
| 3009 | * @param {Object} object The object to iterate over.
|
||
| 3010 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 3011 | * @returns {Object} Returns `object`.
|
||
| 3012 | */
|
||
| 3013 | function baseForOwnRight(object, iteratee) { |
||
| 3014 | return object && baseForRight(object, iteratee, keys);
|
||
| 3015 | } |
||
| 3016 | |||
| 3017 | /**
|
||
| 3018 | * The base implementation of `_.functions` which creates an array of
|
||
| 3019 | * `object` function property names filtered from `props`.
|
||
| 3020 | *
|
||
| 3021 | * @private
|
||
| 3022 | * @param {Object} object The object to inspect.
|
||
| 3023 | * @param {Array} props The property names to filter.
|
||
| 3024 | * @returns {Array} Returns the function names.
|
||
| 3025 | */
|
||
| 3026 | function baseFunctions(object, props) { |
||
| 3027 | return arrayFilter(props, function(key) { |
||
| 3028 | return isFunction(object[key]);
|
||
| 3029 | }); |
||
| 3030 | } |
||
| 3031 | |||
| 3032 | /**
|
||
| 3033 | * The base implementation of `_.get` without support for default values.
|
||
| 3034 | *
|
||
| 3035 | * @private
|
||
| 3036 | * @param {Object} object The object to query.
|
||
| 3037 | * @param {Array|string} path The path of the property to get.
|
||
| 3038 | * @returns {*} Returns the resolved value.
|
||
| 3039 | */
|
||
| 3040 | function baseGet(object, path) { |
||
| 3041 | path = castPath(path, object); |
||
| 3042 | |||
| 3043 | var index = 0, |
||
| 3044 | length = path.length; |
||
| 3045 | |||
| 3046 | while (object != null && index < length) { |
||
| 3047 | object = object[toKey(path[index++])]; |
||
| 3048 | } |
||
| 3049 | return (index && index == length) ? object : undefined; |
||
| 3050 | } |
||
| 3051 | |||
| 3052 | /**
|
||
| 3053 | * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
||
| 3054 | * `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
||
| 3055 | * symbols of `object`.
|
||
| 3056 | *
|
||
| 3057 | * @private
|
||
| 3058 | * @param {Object} object The object to query.
|
||
| 3059 | * @param {Function} keysFunc The function to get the keys of `object`.
|
||
| 3060 | * @param {Function} symbolsFunc The function to get the symbols of `object`.
|
||
| 3061 | * @returns {Array} Returns the array of property names and symbols.
|
||
| 3062 | */
|
||
| 3063 | function baseGetAllKeys(object, keysFunc, symbolsFunc) { |
||
| 3064 | var result = keysFunc(object);
|
||
| 3065 | return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
||
| 3066 | } |
||
| 3067 | |||
| 3068 | /**
|
||
| 3069 | * The base implementation of `getTag` without fallbacks for buggy environments.
|
||
| 3070 | *
|
||
| 3071 | * @private
|
||
| 3072 | * @param {*} value The value to query.
|
||
| 3073 | * @returns {string} Returns the `toStringTag`.
|
||
| 3074 | */
|
||
| 3075 | function baseGetTag(value) { |
||
| 3076 | if (value == null) { |
||
| 3077 | return value === undefined ? undefinedTag : nullTag; |
||
| 3078 | } |
||
| 3079 | return (symToStringTag && symToStringTag in Object(value)) |
||
| 3080 | ? getRawTag(value) |
||
| 3081 | : objectToString(value); |
||
| 3082 | } |
||
| 3083 | |||
| 3084 | /**
|
||
| 3085 | * The base implementation of `_.gt` which doesn't coerce arguments.
|
||
| 3086 | *
|
||
| 3087 | * @private
|
||
| 3088 | * @param {*} value The value to compare.
|
||
| 3089 | * @param {*} other The other value to compare.
|
||
| 3090 | * @returns {boolean} Returns `true` if `value` is greater than `other`,
|
||
| 3091 | * else `false`.
|
||
| 3092 | */
|
||
| 3093 | function baseGt(value, other) { |
||
| 3094 | return value > other;
|
||
| 3095 | } |
||
| 3096 | |||
| 3097 | /**
|
||
| 3098 | * The base implementation of `_.has` without support for deep paths.
|
||
| 3099 | *
|
||
| 3100 | * @private
|
||
| 3101 | * @param {Object} [object] The object to query.
|
||
| 3102 | * @param {Array|string} key The key to check.
|
||
| 3103 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
||
| 3104 | */
|
||
| 3105 | function baseHas(object, key) { |
||
| 3106 | return object != null && hasOwnProperty.call(object, key); |
||
| 3107 | } |
||
| 3108 | |||
| 3109 | /**
|
||
| 3110 | * The base implementation of `_.hasIn` without support for deep paths.
|
||
| 3111 | *
|
||
| 3112 | * @private
|
||
| 3113 | * @param {Object} [object] The object to query.
|
||
| 3114 | * @param {Array|string} key The key to check.
|
||
| 3115 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
||
| 3116 | */
|
||
| 3117 | function baseHasIn(object, key) { |
||
| 3118 | return object != null && key in Object(object); |
||
| 3119 | } |
||
| 3120 | |||
| 3121 | /**
|
||
| 3122 | * The base implementation of `_.inRange` which doesn't coerce arguments.
|
||
| 3123 | *
|
||
| 3124 | * @private
|
||
| 3125 | * @param {number} number The number to check.
|
||
| 3126 | * @param {number} start The start of the range.
|
||
| 3127 | * @param {number} end The end of the range.
|
||
| 3128 | * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
|
||
| 3129 | */
|
||
| 3130 | function baseInRange(number, start, end) { |
||
| 3131 | return number >= nativeMin(start, end) && number < nativeMax(start, end);
|
||
| 3132 | } |
||
| 3133 | |||
| 3134 | /**
|
||
| 3135 | * The base implementation of methods like `_.intersection`, without support
|
||
| 3136 | * for iteratee shorthands, that accepts an array of arrays to inspect.
|
||
| 3137 | *
|
||
| 3138 | * @private
|
||
| 3139 | * @param {Array} arrays The arrays to inspect.
|
||
| 3140 | * @param {Function} [iteratee] The iteratee invoked per element.
|
||
| 3141 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 3142 | * @returns {Array} Returns the new array of shared values.
|
||
| 3143 | */
|
||
| 3144 | function baseIntersection(arrays, iteratee, comparator) { |
||
| 3145 | var includes = comparator ? arrayIncludesWith : arrayIncludes,
|
||
| 3146 | length = arrays[0].length,
|
||
| 3147 | othLength = arrays.length, |
||
| 3148 | othIndex = othLength, |
||
| 3149 | caches = Array(othLength), |
||
| 3150 | maxLength = Infinity,
|
||
| 3151 | result = []; |
||
| 3152 | |||
| 3153 | while (othIndex--) {
|
||
| 3154 | var array = arrays[othIndex];
|
||
| 3155 | if (othIndex && iteratee) {
|
||
| 3156 | array = arrayMap(array, baseUnary(iteratee)); |
||
| 3157 | } |
||
| 3158 | maxLength = nativeMin(array.length, maxLength); |
||
| 3159 | caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) |
||
| 3160 | ? new SetCache(othIndex && array)
|
||
| 3161 | : undefined;
|
||
| 3162 | } |
||
| 3163 | array = arrays[0];
|
||
| 3164 | |||
| 3165 | var index = -1, |
||
| 3166 | seen = caches[0];
|
||
| 3167 | |||
| 3168 | outer: |
||
| 3169 | while (++index < length && result.length < maxLength) {
|
||
| 3170 | var value = array[index],
|
||
| 3171 | computed = iteratee ? iteratee(value) : value; |
||
| 3172 | |||
| 3173 | value = (comparator || value !== 0) ? value : 0; |
||
| 3174 | if (!(seen
|
||
| 3175 | ? cacheHas(seen, computed) |
||
| 3176 | : includes(result, computed, comparator) |
||
| 3177 | )) {
|
||
| 3178 | othIndex = othLength; |
||
| 3179 | while (--othIndex) {
|
||
| 3180 | var cache = caches[othIndex];
|
||
| 3181 | if (!(cache
|
||
| 3182 | ? cacheHas(cache, computed) |
||
| 3183 | : includes(arrays[othIndex], computed, comparator)) |
||
| 3184 | ) {
|
||
| 3185 | continue outer;
|
||
| 3186 | } |
||
| 3187 | } |
||
| 3188 | if (seen) {
|
||
| 3189 | seen.push(computed); |
||
| 3190 | } |
||
| 3191 | result.push(value); |
||
| 3192 | } |
||
| 3193 | } |
||
| 3194 | return result;
|
||
| 3195 | } |
||
| 3196 | |||
| 3197 | /**
|
||
| 3198 | * The base implementation of `_.invert` and `_.invertBy` which inverts
|
||
| 3199 | * `object` with values transformed by `iteratee` and set by `setter`.
|
||
| 3200 | *
|
||
| 3201 | * @private
|
||
| 3202 | * @param {Object} object The object to iterate over.
|
||
| 3203 | * @param {Function} setter The function to set `accumulator` values.
|
||
| 3204 | * @param {Function} iteratee The iteratee to transform values.
|
||
| 3205 | * @param {Object} accumulator The initial inverted object.
|
||
| 3206 | * @returns {Function} Returns `accumulator`.
|
||
| 3207 | */
|
||
| 3208 | function baseInverter(object, setter, iteratee, accumulator) { |
||
| 3209 | baseForOwn(object, function(value, key, object) {
|
||
| 3210 | setter(accumulator, iteratee(value), key, object); |
||
| 3211 | }); |
||
| 3212 | return accumulator;
|
||
| 3213 | } |
||
| 3214 | |||
| 3215 | /**
|
||
| 3216 | * The base implementation of `_.invoke` without support for individual
|
||
| 3217 | * method arguments.
|
||
| 3218 | *
|
||
| 3219 | * @private
|
||
| 3220 | * @param {Object} object The object to query.
|
||
| 3221 | * @param {Array|string} path The path of the method to invoke.
|
||
| 3222 | * @param {Array} args The arguments to invoke the method with.
|
||
| 3223 | * @returns {*} Returns the result of the invoked method.
|
||
| 3224 | */
|
||
| 3225 | function baseInvoke(object, path, args) { |
||
| 3226 | path = castPath(path, object); |
||
| 3227 | object = parent(object, path); |
||
| 3228 | var func = object == null ? object : object[toKey(last(path))]; |
||
| 3229 | return func == null ? undefined : apply(func, object, args); |
||
| 3230 | } |
||
| 3231 | |||
| 3232 | /**
|
||
| 3233 | * The base implementation of `_.isArguments`.
|
||
| 3234 | *
|
||
| 3235 | * @private
|
||
| 3236 | * @param {*} value The value to check.
|
||
| 3237 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
||
| 3238 | */
|
||
| 3239 | function baseIsArguments(value) { |
||
| 3240 | return isObjectLike(value) && baseGetTag(value) == argsTag;
|
||
| 3241 | } |
||
| 3242 | |||
| 3243 | /**
|
||
| 3244 | * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
|
||
| 3245 | *
|
||
| 3246 | * @private
|
||
| 3247 | * @param {*} value The value to check.
|
||
| 3248 | * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
|
||
| 3249 | */
|
||
| 3250 | function baseIsArrayBuffer(value) { |
||
| 3251 | return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
|
||
| 3252 | } |
||
| 3253 | |||
| 3254 | /**
|
||
| 3255 | * The base implementation of `_.isDate` without Node.js optimizations.
|
||
| 3256 | *
|
||
| 3257 | * @private
|
||
| 3258 | * @param {*} value The value to check.
|
||
| 3259 | * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
||
| 3260 | */
|
||
| 3261 | function baseIsDate(value) { |
||
| 3262 | return isObjectLike(value) && baseGetTag(value) == dateTag;
|
||
| 3263 | } |
||
| 3264 | |||
| 3265 | /**
|
||
| 3266 | * The base implementation of `_.isEqual` which supports partial comparisons
|
||
| 3267 | * and tracks traversed objects.
|
||
| 3268 | *
|
||
| 3269 | * @private
|
||
| 3270 | * @param {*} value The value to compare.
|
||
| 3271 | * @param {*} other The other value to compare.
|
||
| 3272 | * @param {boolean} bitmask The bitmask flags.
|
||
| 3273 | * 1 - Unordered comparison
|
||
| 3274 | * 2 - Partial comparison
|
||
| 3275 | * @param {Function} [customizer] The function to customize comparisons.
|
||
| 3276 | * @param {Object} [stack] Tracks traversed `value` and `other` objects.
|
||
| 3277 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
||
| 3278 | */
|
||
| 3279 | function baseIsEqual(value, other, bitmask, customizer, stack) { |
||
| 3280 | if (value === other) {
|
||
| 3281 | return true; |
||
| 3282 | } |
||
| 3283 | if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) { |
||
| 3284 | return value !== value && other !== other;
|
||
| 3285 | } |
||
| 3286 | return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
||
| 3287 | } |
||
| 3288 | |||
| 3289 | /**
|
||
| 3290 | * A specialized version of `baseIsEqual` for arrays and objects which performs
|
||
| 3291 | * deep comparisons and tracks traversed objects enabling objects with circular
|
||
| 3292 | * references to be compared.
|
||
| 3293 | *
|
||
| 3294 | * @private
|
||
| 3295 | * @param {Object} object The object to compare.
|
||
| 3296 | * @param {Object} other The other object to compare.
|
||
| 3297 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
||
| 3298 | * @param {Function} customizer The function to customize comparisons.
|
||
| 3299 | * @param {Function} equalFunc The function to determine equivalents of values.
|
||
| 3300 | * @param {Object} [stack] Tracks traversed `object` and `other` objects.
|
||
| 3301 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
||
| 3302 | */
|
||
| 3303 | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { |
||
| 3304 | var objIsArr = isArray(object),
|
||
| 3305 | othIsArr = isArray(other), |
||
| 3306 | objTag = objIsArr ? arrayTag : getTag(object), |
||
| 3307 | othTag = othIsArr ? arrayTag : getTag(other); |
||
| 3308 | |||
| 3309 | objTag = objTag == argsTag ? objectTag : objTag; |
||
| 3310 | othTag = othTag == argsTag ? objectTag : othTag; |
||
| 3311 | |||
| 3312 | var objIsObj = objTag == objectTag,
|
||
| 3313 | othIsObj = othTag == objectTag, |
||
| 3314 | isSameTag = objTag == othTag; |
||
| 3315 | |||
| 3316 | if (isSameTag && isBuffer(object)) {
|
||
| 3317 | if (!isBuffer(other)) {
|
||
| 3318 | return false; |
||
| 3319 | } |
||
| 3320 | objIsArr = true;
|
||
| 3321 | objIsObj = false;
|
||
| 3322 | } |
||
| 3323 | if (isSameTag && !objIsObj) {
|
||
| 3324 | stack || (stack = new Stack);
|
||
| 3325 | return (objIsArr || isTypedArray(object))
|
||
| 3326 | ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) |
||
| 3327 | : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack); |
||
| 3328 | } |
||
| 3329 | if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
|
||
| 3330 | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), |
||
| 3331 | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
||
| 3332 | |||
| 3333 | if (objIsWrapped || othIsWrapped) {
|
||
| 3334 | var objUnwrapped = objIsWrapped ? object.value() : object,
|
||
| 3335 | othUnwrapped = othIsWrapped ? other.value() : other; |
||
| 3336 | |||
| 3337 | stack || (stack = new Stack);
|
||
| 3338 | return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
|
||
| 3339 | } |
||
| 3340 | } |
||
| 3341 | if (!isSameTag) {
|
||
| 3342 | return false; |
||
| 3343 | } |
||
| 3344 | stack || (stack = new Stack);
|
||
| 3345 | return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
|
||
| 3346 | } |
||
| 3347 | |||
| 3348 | /**
|
||
| 3349 | * The base implementation of `_.isMap` without Node.js optimizations.
|
||
| 3350 | *
|
||
| 3351 | * @private
|
||
| 3352 | * @param {*} value The value to check.
|
||
| 3353 | * @returns {boolean} Returns `true` if `value` is a map, else `false`.
|
||
| 3354 | */
|
||
| 3355 | function baseIsMap(value) { |
||
| 3356 | return isObjectLike(value) && getTag(value) == mapTag;
|
||
| 3357 | } |
||
| 3358 | |||
| 3359 | /**
|
||
| 3360 | * The base implementation of `_.isMatch` without support for iteratee shorthands.
|
||
| 3361 | *
|
||
| 3362 | * @private
|
||
| 3363 | * @param {Object} object The object to inspect.
|
||
| 3364 | * @param {Object} source The object of property values to match.
|
||
| 3365 | * @param {Array} matchData The property names, values, and compare flags to match.
|
||
| 3366 | * @param {Function} [customizer] The function to customize comparisons.
|
||
| 3367 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
||
| 3368 | */
|
||
| 3369 | function baseIsMatch(object, source, matchData, customizer) { |
||
| 3370 | var index = matchData.length,
|
||
| 3371 | length = index, |
||
| 3372 | noCustomizer = !customizer; |
||
| 3373 | |||
| 3374 | if (object == null) { |
||
| 3375 | return !length;
|
||
| 3376 | } |
||
| 3377 | object = Object(object); |
||
| 3378 | while (index--) {
|
||
| 3379 | var data = matchData[index];
|
||
| 3380 | if ((noCustomizer && data[2]) |
||
| 3381 | ? data[1] !== object[data[0]] |
||
| 3382 | : !(data[0] in object) |
||
| 3383 | ) {
|
||
| 3384 | return false; |
||
| 3385 | } |
||
| 3386 | } |
||
| 3387 | while (++index < length) {
|
||
| 3388 | data = matchData[index]; |
||
| 3389 | var key = data[0], |
||
| 3390 | objValue = object[key], |
||
| 3391 | srcValue = data[1];
|
||
| 3392 | |||
| 3393 | if (noCustomizer && data[2]) { |
||
| 3394 | if (objValue === undefined && !(key in object)) { |
||
| 3395 | return false; |
||
| 3396 | } |
||
| 3397 | } else {
|
||
| 3398 | var stack = new Stack; |
||
| 3399 | if (customizer) {
|
||
| 3400 | var result = customizer(objValue, srcValue, key, object, source, stack);
|
||
| 3401 | } |
||
| 3402 | if (!(result === undefined |
||
| 3403 | ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) |
||
| 3404 | : result |
||
| 3405 | )) {
|
||
| 3406 | return false; |
||
| 3407 | } |
||
| 3408 | } |
||
| 3409 | } |
||
| 3410 | return true; |
||
| 3411 | } |
||
| 3412 | |||
| 3413 | /**
|
||
| 3414 | * The base implementation of `_.isNative` without bad shim checks.
|
||
| 3415 | *
|
||
| 3416 | * @private
|
||
| 3417 | * @param {*} value The value to check.
|
||
| 3418 | * @returns {boolean} Returns `true` if `value` is a native function,
|
||
| 3419 | * else `false`.
|
||
| 3420 | */
|
||
| 3421 | function baseIsNative(value) { |
||
| 3422 | if (!isObject(value) || isMasked(value)) {
|
||
| 3423 | return false; |
||
| 3424 | } |
||
| 3425 | var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
||
| 3426 | return pattern.test(toSource(value));
|
||
| 3427 | } |
||
| 3428 | |||
| 3429 | /**
|
||
| 3430 | * The base implementation of `_.isRegExp` without Node.js optimizations.
|
||
| 3431 | *
|
||
| 3432 | * @private
|
||
| 3433 | * @param {*} value The value to check.
|
||
| 3434 | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
|
||
| 3435 | */
|
||
| 3436 | function baseIsRegExp(value) { |
||
| 3437 | return isObjectLike(value) && baseGetTag(value) == regexpTag;
|
||
| 3438 | } |
||
| 3439 | |||
| 3440 | /**
|
||
| 3441 | * The base implementation of `_.isSet` without Node.js optimizations.
|
||
| 3442 | *
|
||
| 3443 | * @private
|
||
| 3444 | * @param {*} value The value to check.
|
||
| 3445 | * @returns {boolean} Returns `true` if `value` is a set, else `false`.
|
||
| 3446 | */
|
||
| 3447 | function baseIsSet(value) { |
||
| 3448 | return isObjectLike(value) && getTag(value) == setTag;
|
||
| 3449 | } |
||
| 3450 | |||
| 3451 | /**
|
||
| 3452 | * The base implementation of `_.isTypedArray` without Node.js optimizations.
|
||
| 3453 | *
|
||
| 3454 | * @private
|
||
| 3455 | * @param {*} value The value to check.
|
||
| 3456 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
||
| 3457 | */
|
||
| 3458 | function baseIsTypedArray(value) { |
||
| 3459 | return isObjectLike(value) &&
|
||
| 3460 | isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; |
||
| 3461 | } |
||
| 3462 | |||
| 3463 | /**
|
||
| 3464 | * The base implementation of `_.iteratee`.
|
||
| 3465 | *
|
||
| 3466 | * @private
|
||
| 3467 | * @param {*} [value=_.identity] The value to convert to an iteratee.
|
||
| 3468 | * @returns {Function} Returns the iteratee.
|
||
| 3469 | */
|
||
| 3470 | function baseIteratee(value) { |
||
| 3471 | // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
|
||
| 3472 | // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
|
||
| 3473 | if (typeof value == 'function') { |
||
| 3474 | return value;
|
||
| 3475 | } |
||
| 3476 | if (value == null) { |
||
| 3477 | return identity;
|
||
| 3478 | } |
||
| 3479 | if (typeof value == 'object') { |
||
| 3480 | return isArray(value)
|
||
| 3481 | ? baseMatchesProperty(value[0], value[1]) |
||
| 3482 | : baseMatches(value); |
||
| 3483 | } |
||
| 3484 | return property(value);
|
||
| 3485 | } |
||
| 3486 | |||
| 3487 | /**
|
||
| 3488 | * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
||
| 3489 | *
|
||
| 3490 | * @private
|
||
| 3491 | * @param {Object} object The object to query.
|
||
| 3492 | * @returns {Array} Returns the array of property names.
|
||
| 3493 | */
|
||
| 3494 | function baseKeys(object) { |
||
| 3495 | if (!isPrototype(object)) {
|
||
| 3496 | return nativeKeys(object);
|
||
| 3497 | } |
||
| 3498 | var result = [];
|
||
| 3499 | for (var key in Object(object)) { |
||
| 3500 | if (hasOwnProperty.call(object, key) && key != 'constructor') { |
||
| 3501 | result.push(key); |
||
| 3502 | } |
||
| 3503 | } |
||
| 3504 | return result;
|
||
| 3505 | } |
||
| 3506 | |||
| 3507 | /**
|
||
| 3508 | * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
|
||
| 3509 | *
|
||
| 3510 | * @private
|
||
| 3511 | * @param {Object} object The object to query.
|
||
| 3512 | * @returns {Array} Returns the array of property names.
|
||
| 3513 | */
|
||
| 3514 | function baseKeysIn(object) { |
||
| 3515 | if (!isObject(object)) {
|
||
| 3516 | return nativeKeysIn(object);
|
||
| 3517 | } |
||
| 3518 | var isProto = isPrototype(object),
|
||
| 3519 | result = []; |
||
| 3520 | |||
| 3521 | for (var key in object) { |
||
| 3522 | if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { |
||
| 3523 | result.push(key); |
||
| 3524 | } |
||
| 3525 | } |
||
| 3526 | return result;
|
||
| 3527 | } |
||
| 3528 | |||
| 3529 | /**
|
||
| 3530 | * The base implementation of `_.lt` which doesn't coerce arguments.
|
||
| 3531 | *
|
||
| 3532 | * @private
|
||
| 3533 | * @param {*} value The value to compare.
|
||
| 3534 | * @param {*} other The other value to compare.
|
||
| 3535 | * @returns {boolean} Returns `true` if `value` is less than `other`,
|
||
| 3536 | * else `false`.
|
||
| 3537 | */
|
||
| 3538 | function baseLt(value, other) { |
||
| 3539 | return value < other;
|
||
| 3540 | } |
||
| 3541 | |||
| 3542 | /**
|
||
| 3543 | * The base implementation of `_.map` without support for iteratee shorthands.
|
||
| 3544 | *
|
||
| 3545 | * @private
|
||
| 3546 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 3547 | * @param {Function} iteratee The function invoked per iteration.
|
||
| 3548 | * @returns {Array} Returns the new mapped array.
|
||
| 3549 | */
|
||
| 3550 | function baseMap(collection, iteratee) { |
||
| 3551 | var index = -1, |
||
| 3552 | result = isArrayLike(collection) ? Array(collection.length) : []; |
||
| 3553 | |||
| 3554 | baseEach(collection, function(value, key, collection) {
|
||
| 3555 | result[++index] = iteratee(value, key, collection); |
||
| 3556 | }); |
||
| 3557 | return result;
|
||
| 3558 | } |
||
| 3559 | |||
| 3560 | /**
|
||
| 3561 | * The base implementation of `_.matches` which doesn't clone `source`.
|
||
| 3562 | *
|
||
| 3563 | * @private
|
||
| 3564 | * @param {Object} source The object of property values to match.
|
||
| 3565 | * @returns {Function} Returns the new spec function.
|
||
| 3566 | */
|
||
| 3567 | function baseMatches(source) { |
||
| 3568 | var matchData = getMatchData(source);
|
||
| 3569 | if (matchData.length == 1 && matchData[0][2]) { |
||
| 3570 | return matchesStrictComparable(matchData[0][0], matchData[0][1]); |
||
| 3571 | } |
||
| 3572 | return function(object) { |
||
| 3573 | return object === source || baseIsMatch(object, source, matchData);
|
||
| 3574 | }; |
||
| 3575 | } |
||
| 3576 | |||
| 3577 | /**
|
||
| 3578 | * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
|
||
| 3579 | *
|
||
| 3580 | * @private
|
||
| 3581 | * @param {string} path The path of the property to get.
|
||
| 3582 | * @param {*} srcValue The value to match.
|
||
| 3583 | * @returns {Function} Returns the new spec function.
|
||
| 3584 | */
|
||
| 3585 | function baseMatchesProperty(path, srcValue) { |
||
| 3586 | if (isKey(path) && isStrictComparable(srcValue)) {
|
||
| 3587 | return matchesStrictComparable(toKey(path), srcValue);
|
||
| 3588 | } |
||
| 3589 | return function(object) { |
||
| 3590 | var objValue = get(object, path);
|
||
| 3591 | return (objValue === undefined && objValue === srcValue) |
||
| 3592 | ? hasIn(object, path) |
||
| 3593 | : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG); |
||
| 3594 | }; |
||
| 3595 | } |
||
| 3596 | |||
| 3597 | /**
|
||
| 3598 | * The base implementation of `_.merge` without support for multiple sources.
|
||
| 3599 | *
|
||
| 3600 | * @private
|
||
| 3601 | * @param {Object} object The destination object.
|
||
| 3602 | * @param {Object} source The source object.
|
||
| 3603 | * @param {number} srcIndex The index of `source`.
|
||
| 3604 | * @param {Function} [customizer] The function to customize merged values.
|
||
| 3605 | * @param {Object} [stack] Tracks traversed source values and their merged
|
||
| 3606 | * counterparts.
|
||
| 3607 | */
|
||
| 3608 | function baseMerge(object, source, srcIndex, customizer, stack) { |
||
| 3609 | if (object === source) {
|
||
| 3610 | return;
|
||
| 3611 | } |
||
| 3612 | baseFor(source, function(srcValue, key) {
|
||
| 3613 | if (isObject(srcValue)) {
|
||
| 3614 | stack || (stack = new Stack);
|
||
| 3615 | baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); |
||
| 3616 | } |
||
| 3617 | else {
|
||
| 3618 | var newValue = customizer
|
||
| 3619 | ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
|
||
| 3620 | : undefined;
|
||
| 3621 | |||
| 3622 | if (newValue === undefined) { |
||
| 3623 | newValue = srcValue; |
||
| 3624 | } |
||
| 3625 | assignMergeValue(object, key, newValue); |
||
| 3626 | } |
||
| 3627 | }, keysIn); |
||
| 3628 | } |
||
| 3629 | |||
| 3630 | /**
|
||
| 3631 | * A specialized version of `baseMerge` for arrays and objects which performs
|
||
| 3632 | * deep merges and tracks traversed objects enabling objects with circular
|
||
| 3633 | * references to be merged.
|
||
| 3634 | *
|
||
| 3635 | * @private
|
||
| 3636 | * @param {Object} object The destination object.
|
||
| 3637 | * @param {Object} source The source object.
|
||
| 3638 | * @param {string} key The key of the value to merge.
|
||
| 3639 | * @param {number} srcIndex The index of `source`.
|
||
| 3640 | * @param {Function} mergeFunc The function to merge values.
|
||
| 3641 | * @param {Function} [customizer] The function to customize assigned values.
|
||
| 3642 | * @param {Object} [stack] Tracks traversed source values and their merged
|
||
| 3643 | * counterparts.
|
||
| 3644 | */
|
||
| 3645 | function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { |
||
| 3646 | var objValue = safeGet(object, key),
|
||
| 3647 | srcValue = safeGet(source, key), |
||
| 3648 | stacked = stack.get(srcValue); |
||
| 3649 | |||
| 3650 | if (stacked) {
|
||
| 3651 | assignMergeValue(object, key, stacked); |
||
| 3652 | return;
|
||
| 3653 | } |
||
| 3654 | var newValue = customizer
|
||
| 3655 | ? customizer(objValue, srcValue, (key + ''), object, source, stack)
|
||
| 3656 | : undefined;
|
||
| 3657 | |||
| 3658 | var isCommon = newValue === undefined; |
||
| 3659 | |||
| 3660 | if (isCommon) {
|
||
| 3661 | var isArr = isArray(srcValue),
|
||
| 3662 | isBuff = !isArr && isBuffer(srcValue), |
||
| 3663 | isTyped = !isArr && !isBuff && isTypedArray(srcValue); |
||
| 3664 | |||
| 3665 | newValue = srcValue; |
||
| 3666 | if (isArr || isBuff || isTyped) {
|
||
| 3667 | if (isArray(objValue)) {
|
||
| 3668 | newValue = objValue; |
||
| 3669 | } |
||
| 3670 | else if (isArrayLikeObject(objValue)) { |
||
| 3671 | newValue = copyArray(objValue); |
||
| 3672 | } |
||
| 3673 | else if (isBuff) { |
||
| 3674 | isCommon = false;
|
||
| 3675 | newValue = cloneBuffer(srcValue, true);
|
||
| 3676 | } |
||
| 3677 | else if (isTyped) { |
||
| 3678 | isCommon = false;
|
||
| 3679 | newValue = cloneTypedArray(srcValue, true);
|
||
| 3680 | } |
||
| 3681 | else {
|
||
| 3682 | newValue = []; |
||
| 3683 | } |
||
| 3684 | } |
||
| 3685 | else if (isPlainObject(srcValue) || isArguments(srcValue)) { |
||
| 3686 | newValue = objValue; |
||
| 3687 | if (isArguments(objValue)) {
|
||
| 3688 | newValue = toPlainObject(objValue); |
||
| 3689 | } |
||
| 3690 | else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { |
||
| 3691 | newValue = initCloneObject(srcValue); |
||
| 3692 | } |
||
| 3693 | } |
||
| 3694 | else {
|
||
| 3695 | isCommon = false;
|
||
| 3696 | } |
||
| 3697 | } |
||
| 3698 | if (isCommon) {
|
||
| 3699 | // Recursively merge objects and arrays (susceptible to call stack limits).
|
||
| 3700 | stack.set(srcValue, newValue); |
||
| 3701 | mergeFunc(newValue, srcValue, srcIndex, customizer, stack); |
||
| 3702 | stack['delete'](srcValue);
|
||
| 3703 | } |
||
| 3704 | assignMergeValue(object, key, newValue); |
||
| 3705 | } |
||
| 3706 | |||
| 3707 | /**
|
||
| 3708 | * The base implementation of `_.nth` which doesn't coerce arguments.
|
||
| 3709 | *
|
||
| 3710 | * @private
|
||
| 3711 | * @param {Array} array The array to query.
|
||
| 3712 | * @param {number} n The index of the element to return.
|
||
| 3713 | * @returns {*} Returns the nth element of `array`.
|
||
| 3714 | */
|
||
| 3715 | function baseNth(array, n) { |
||
| 3716 | var length = array.length;
|
||
| 3717 | if (!length) {
|
||
| 3718 | return;
|
||
| 3719 | } |
||
| 3720 | n += n < 0 ? length : 0; |
||
| 3721 | return isIndex(n, length) ? array[n] : undefined; |
||
| 3722 | } |
||
| 3723 | |||
| 3724 | /**
|
||
| 3725 | * The base implementation of `_.orderBy` without param guards.
|
||
| 3726 | *
|
||
| 3727 | * @private
|
||
| 3728 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 3729 | * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
||
| 3730 | * @param {string[]} orders The sort orders of `iteratees`.
|
||
| 3731 | * @returns {Array} Returns the new sorted array.
|
||
| 3732 | */
|
||
| 3733 | function baseOrderBy(collection, iteratees, orders) { |
||
| 3734 | var index = -1; |
||
| 3735 | iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee())); |
||
| 3736 | |||
| 3737 | var result = baseMap(collection, function(value, key, collection) { |
||
| 3738 | var criteria = arrayMap(iteratees, function(iteratee) { |
||
| 3739 | return iteratee(value);
|
||
| 3740 | }); |
||
| 3741 | return { 'criteria': criteria, 'index': ++index, 'value': value }; |
||
| 3742 | }); |
||
| 3743 | |||
| 3744 | return baseSortBy(result, function(object, other) { |
||
| 3745 | return compareMultiple(object, other, orders);
|
||
| 3746 | }); |
||
| 3747 | } |
||
| 3748 | |||
| 3749 | /**
|
||
| 3750 | * The base implementation of `_.pick` without support for individual
|
||
| 3751 | * property identifiers.
|
||
| 3752 | *
|
||
| 3753 | * @private
|
||
| 3754 | * @param {Object} object The source object.
|
||
| 3755 | * @param {string[]} paths The property paths to pick.
|
||
| 3756 | * @returns {Object} Returns the new object.
|
||
| 3757 | */
|
||
| 3758 | function basePick(object, paths) { |
||
| 3759 | return basePickBy(object, paths, function(value, path) { |
||
| 3760 | return hasIn(object, path);
|
||
| 3761 | }); |
||
| 3762 | } |
||
| 3763 | |||
| 3764 | /**
|
||
| 3765 | * The base implementation of `_.pickBy` without support for iteratee shorthands.
|
||
| 3766 | *
|
||
| 3767 | * @private
|
||
| 3768 | * @param {Object} object The source object.
|
||
| 3769 | * @param {string[]} paths The property paths to pick.
|
||
| 3770 | * @param {Function} predicate The function invoked per property.
|
||
| 3771 | * @returns {Object} Returns the new object.
|
||
| 3772 | */
|
||
| 3773 | function basePickBy(object, paths, predicate) { |
||
| 3774 | var index = -1, |
||
| 3775 | length = paths.length, |
||
| 3776 | result = {};
|
||
| 3777 | |||
| 3778 | while (++index < length) {
|
||
| 3779 | var path = paths[index],
|
||
| 3780 | value = baseGet(object, path); |
||
| 3781 | |||
| 3782 | if (predicate(value, path)) {
|
||
| 3783 | baseSet(result, castPath(path, object), value); |
||
| 3784 | } |
||
| 3785 | } |
||
| 3786 | return result;
|
||
| 3787 | } |
||
| 3788 | |||
| 3789 | /**
|
||
| 3790 | * A specialized version of `baseProperty` which supports deep paths.
|
||
| 3791 | *
|
||
| 3792 | * @private
|
||
| 3793 | * @param {Array|string} path The path of the property to get.
|
||
| 3794 | * @returns {Function} Returns the new accessor function.
|
||
| 3795 | */
|
||
| 3796 | function basePropertyDeep(path) { |
||
| 3797 | return function(object) { |
||
| 3798 | return baseGet(object, path);
|
||
| 3799 | }; |
||
| 3800 | } |
||
| 3801 | |||
| 3802 | /**
|
||
| 3803 | * The base implementation of `_.pullAllBy` without support for iteratee
|
||
| 3804 | * shorthands.
|
||
| 3805 | *
|
||
| 3806 | * @private
|
||
| 3807 | * @param {Array} array The array to modify.
|
||
| 3808 | * @param {Array} values The values to remove.
|
||
| 3809 | * @param {Function} [iteratee] The iteratee invoked per element.
|
||
| 3810 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 3811 | * @returns {Array} Returns `array`.
|
||
| 3812 | */
|
||
| 3813 | function basePullAll(array, values, iteratee, comparator) { |
||
| 3814 | var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
|
||
| 3815 | index = -1,
|
||
| 3816 | length = values.length, |
||
| 3817 | seen = array; |
||
| 3818 | |||
| 3819 | if (array === values) {
|
||
| 3820 | values = copyArray(values); |
||
| 3821 | } |
||
| 3822 | if (iteratee) {
|
||
| 3823 | seen = arrayMap(array, baseUnary(iteratee)); |
||
| 3824 | } |
||
| 3825 | while (++index < length) {
|
||
| 3826 | var fromIndex = 0, |
||
| 3827 | value = values[index], |
||
| 3828 | computed = iteratee ? iteratee(value) : value; |
||
| 3829 | |||
| 3830 | while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { |
||
| 3831 | if (seen !== array) {
|
||
| 3832 | splice.call(seen, fromIndex, 1);
|
||
| 3833 | } |
||
| 3834 | splice.call(array, fromIndex, 1);
|
||
| 3835 | } |
||
| 3836 | } |
||
| 3837 | return array;
|
||
| 3838 | } |
||
| 3839 | |||
| 3840 | /**
|
||
| 3841 | * The base implementation of `_.pullAt` without support for individual
|
||
| 3842 | * indexes or capturing the removed elements.
|
||
| 3843 | *
|
||
| 3844 | * @private
|
||
| 3845 | * @param {Array} array The array to modify.
|
||
| 3846 | * @param {number[]} indexes The indexes of elements to remove.
|
||
| 3847 | * @returns {Array} Returns `array`.
|
||
| 3848 | */
|
||
| 3849 | function basePullAt(array, indexes) { |
||
| 3850 | var length = array ? indexes.length : 0, |
||
| 3851 | lastIndex = length - 1;
|
||
| 3852 | |||
| 3853 | while (length--) {
|
||
| 3854 | var index = indexes[length];
|
||
| 3855 | if (length == lastIndex || index !== previous) {
|
||
| 3856 | var previous = index;
|
||
| 3857 | if (isIndex(index)) {
|
||
| 3858 | splice.call(array, index, 1);
|
||
| 3859 | } else {
|
||
| 3860 | baseUnset(array, index); |
||
| 3861 | } |
||
| 3862 | } |
||
| 3863 | } |
||
| 3864 | return array;
|
||
| 3865 | } |
||
| 3866 | |||
| 3867 | /**
|
||
| 3868 | * The base implementation of `_.random` without support for returning
|
||
| 3869 | * floating-point numbers.
|
||
| 3870 | *
|
||
| 3871 | * @private
|
||
| 3872 | * @param {number} lower The lower bound.
|
||
| 3873 | * @param {number} upper The upper bound.
|
||
| 3874 | * @returns {number} Returns the random number.
|
||
| 3875 | */
|
||
| 3876 | function baseRandom(lower, upper) { |
||
| 3877 | return lower + nativeFloor(nativeRandom() * (upper - lower + 1)); |
||
| 3878 | } |
||
| 3879 | |||
| 3880 | /**
|
||
| 3881 | * The base implementation of `_.range` and `_.rangeRight` which doesn't
|
||
| 3882 | * coerce arguments.
|
||
| 3883 | *
|
||
| 3884 | * @private
|
||
| 3885 | * @param {number} start The start of the range.
|
||
| 3886 | * @param {number} end The end of the range.
|
||
| 3887 | * @param {number} step The value to increment or decrement by.
|
||
| 3888 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
||
| 3889 | * @returns {Array} Returns the range of numbers.
|
||
| 3890 | */
|
||
| 3891 | function baseRange(start, end, step, fromRight) { |
||
| 3892 | var index = -1, |
||
| 3893 | length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), |
||
| 3894 | result = Array(length); |
||
| 3895 | |||
| 3896 | while (length--) {
|
||
| 3897 | result[fromRight ? length : ++index] = start; |
||
| 3898 | start += step; |
||
| 3899 | } |
||
| 3900 | return result;
|
||
| 3901 | } |
||
| 3902 | |||
| 3903 | /**
|
||
| 3904 | * The base implementation of `_.repeat` which doesn't coerce arguments.
|
||
| 3905 | *
|
||
| 3906 | * @private
|
||
| 3907 | * @param {string} string The string to repeat.
|
||
| 3908 | * @param {number} n The number of times to repeat the string.
|
||
| 3909 | * @returns {string} Returns the repeated string.
|
||
| 3910 | */
|
||
| 3911 | function baseRepeat(string, n) { |
||
| 3912 | var result = ''; |
||
| 3913 | if (!string || n < 1 || n > MAX_SAFE_INTEGER) { |
||
| 3914 | return result;
|
||
| 3915 | } |
||
| 3916 | // Leverage the exponentiation by squaring algorithm for a faster repeat.
|
||
| 3917 | // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
|
||
| 3918 | do {
|
||
| 3919 | if (n % 2) { |
||
| 3920 | result += string; |
||
| 3921 | } |
||
| 3922 | n = nativeFloor(n / 2);
|
||
| 3923 | if (n) {
|
||
| 3924 | string += string; |
||
| 3925 | } |
||
| 3926 | } while (n);
|
||
| 3927 | |||
| 3928 | return result;
|
||
| 3929 | } |
||
| 3930 | |||
| 3931 | /**
|
||
| 3932 | * The base implementation of `_.rest` which doesn't validate or coerce arguments.
|
||
| 3933 | *
|
||
| 3934 | * @private
|
||
| 3935 | * @param {Function} func The function to apply a rest parameter to.
|
||
| 3936 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
||
| 3937 | * @returns {Function} Returns the new function.
|
||
| 3938 | */
|
||
| 3939 | function baseRest(func, start) { |
||
| 3940 | return setToString(overRest(func, start, identity), func + ''); |
||
| 3941 | } |
||
| 3942 | |||
| 3943 | /**
|
||
| 3944 | * The base implementation of `_.sample`.
|
||
| 3945 | *
|
||
| 3946 | * @private
|
||
| 3947 | * @param {Array|Object} collection The collection to sample.
|
||
| 3948 | * @returns {*} Returns the random element.
|
||
| 3949 | */
|
||
| 3950 | function baseSample(collection) { |
||
| 3951 | return arraySample(values(collection));
|
||
| 3952 | } |
||
| 3953 | |||
| 3954 | /**
|
||
| 3955 | * The base implementation of `_.sampleSize` without param guards.
|
||
| 3956 | *
|
||
| 3957 | * @private
|
||
| 3958 | * @param {Array|Object} collection The collection to sample.
|
||
| 3959 | * @param {number} n The number of elements to sample.
|
||
| 3960 | * @returns {Array} Returns the random elements.
|
||
| 3961 | */
|
||
| 3962 | function baseSampleSize(collection, n) { |
||
| 3963 | var array = values(collection);
|
||
| 3964 | return shuffleSelf(array, baseClamp(n, 0, array.length)); |
||
| 3965 | } |
||
| 3966 | |||
| 3967 | /**
|
||
| 3968 | * The base implementation of `_.set`.
|
||
| 3969 | *
|
||
| 3970 | * @private
|
||
| 3971 | * @param {Object} object The object to modify.
|
||
| 3972 | * @param {Array|string} path The path of the property to set.
|
||
| 3973 | * @param {*} value The value to set.
|
||
| 3974 | * @param {Function} [customizer] The function to customize path creation.
|
||
| 3975 | * @returns {Object} Returns `object`.
|
||
| 3976 | */
|
||
| 3977 | function baseSet(object, path, value, customizer) { |
||
| 3978 | if (!isObject(object)) {
|
||
| 3979 | return object;
|
||
| 3980 | } |
||
| 3981 | path = castPath(path, object); |
||
| 3982 | |||
| 3983 | var index = -1, |
||
| 3984 | length = path.length, |
||
| 3985 | lastIndex = length - 1,
|
||
| 3986 | nested = object; |
||
| 3987 | |||
| 3988 | while (nested != null && ++index < length) { |
||
| 3989 | var key = toKey(path[index]),
|
||
| 3990 | newValue = value; |
||
| 3991 | |||
| 3992 | if (index != lastIndex) {
|
||
| 3993 | var objValue = nested[key];
|
||
| 3994 | newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
||
| 3995 | if (newValue === undefined) { |
||
| 3996 | newValue = isObject(objValue) |
||
| 3997 | ? objValue |
||
| 3998 | : (isIndex(path[index + 1]) ? [] : {});
|
||
| 3999 | } |
||
| 4000 | } |
||
| 4001 | assignValue(nested, key, newValue); |
||
| 4002 | nested = nested[key]; |
||
| 4003 | } |
||
| 4004 | return object;
|
||
| 4005 | } |
||
| 4006 | |||
| 4007 | /**
|
||
| 4008 | * The base implementation of `setData` without support for hot loop shorting.
|
||
| 4009 | *
|
||
| 4010 | * @private
|
||
| 4011 | * @param {Function} func The function to associate metadata with.
|
||
| 4012 | * @param {*} data The metadata.
|
||
| 4013 | * @returns {Function} Returns `func`.
|
||
| 4014 | */
|
||
| 4015 | var baseSetData = !metaMap ? identity : function(func, data) { |
||
| 4016 | metaMap.set(func, data); |
||
| 4017 | return func;
|
||
| 4018 | }; |
||
| 4019 | |||
| 4020 | /**
|
||
| 4021 | * The base implementation of `setToString` without support for hot loop shorting.
|
||
| 4022 | *
|
||
| 4023 | * @private
|
||
| 4024 | * @param {Function} func The function to modify.
|
||
| 4025 | * @param {Function} string The `toString` result.
|
||
| 4026 | * @returns {Function} Returns `func`.
|
||
| 4027 | */
|
||
| 4028 | var baseSetToString = !defineProperty ? identity : function(func, string) { |
||
| 4029 | return defineProperty(func, 'toString', { |
||
| 4030 | 'configurable': true, |
||
| 4031 | 'enumerable': false, |
||
| 4032 | 'value': constant(string),
|
||
| 4033 | 'writable': true |
||
| 4034 | }); |
||
| 4035 | }; |
||
| 4036 | |||
| 4037 | /**
|
||
| 4038 | * The base implementation of `_.shuffle`.
|
||
| 4039 | *
|
||
| 4040 | * @private
|
||
| 4041 | * @param {Array|Object} collection The collection to shuffle.
|
||
| 4042 | * @returns {Array} Returns the new shuffled array.
|
||
| 4043 | */
|
||
| 4044 | function baseShuffle(collection) { |
||
| 4045 | return shuffleSelf(values(collection));
|
||
| 4046 | } |
||
| 4047 | |||
| 4048 | /**
|
||
| 4049 | * The base implementation of `_.slice` without an iteratee call guard.
|
||
| 4050 | *
|
||
| 4051 | * @private
|
||
| 4052 | * @param {Array} array The array to slice.
|
||
| 4053 | * @param {number} [start=0] The start position.
|
||
| 4054 | * @param {number} [end=array.length] The end position.
|
||
| 4055 | * @returns {Array} Returns the slice of `array`.
|
||
| 4056 | */
|
||
| 4057 | function baseSlice(array, start, end) { |
||
| 4058 | var index = -1, |
||
| 4059 | length = array.length; |
||
| 4060 | |||
| 4061 | if (start < 0) { |
||
| 4062 | start = -start > length ? 0 : (length + start);
|
||
| 4063 | } |
||
| 4064 | end = end > length ? length : end; |
||
| 4065 | if (end < 0) { |
||
| 4066 | end += length; |
||
| 4067 | } |
||
| 4068 | length = start > end ? 0 : ((end - start) >>> 0); |
||
| 4069 | start >>>= 0;
|
||
| 4070 | |||
| 4071 | var result = Array(length);
|
||
| 4072 | while (++index < length) {
|
||
| 4073 | result[index] = array[index + start]; |
||
| 4074 | } |
||
| 4075 | return result;
|
||
| 4076 | } |
||
| 4077 | |||
| 4078 | /**
|
||
| 4079 | * The base implementation of `_.some` without support for iteratee shorthands.
|
||
| 4080 | *
|
||
| 4081 | * @private
|
||
| 4082 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 4083 | * @param {Function} predicate The function invoked per iteration.
|
||
| 4084 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
||
| 4085 | * else `false`.
|
||
| 4086 | */
|
||
| 4087 | function baseSome(collection, predicate) { |
||
| 4088 | var result;
|
||
| 4089 | |||
| 4090 | baseEach(collection, function(value, index, collection) {
|
||
| 4091 | result = predicate(value, index, collection); |
||
| 4092 | return !result;
|
||
| 4093 | }); |
||
| 4094 | return !!result;
|
||
| 4095 | } |
||
| 4096 | |||
| 4097 | /**
|
||
| 4098 | * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
|
||
| 4099 | * performs a binary search of `array` to determine the index at which `value`
|
||
| 4100 | * should be inserted into `array` in order to maintain its sort order.
|
||
| 4101 | *
|
||
| 4102 | * @private
|
||
| 4103 | * @param {Array} array The sorted array to inspect.
|
||
| 4104 | * @param {*} value The value to evaluate.
|
||
| 4105 | * @param {boolean} [retHighest] Specify returning the highest qualified index.
|
||
| 4106 | * @returns {number} Returns the index at which `value` should be inserted
|
||
| 4107 | * into `array`.
|
||
| 4108 | */
|
||
| 4109 | function baseSortedIndex(array, value, retHighest) { |
||
| 4110 | var low = 0, |
||
| 4111 | high = array == null ? low : array.length;
|
||
| 4112 | |||
| 4113 | if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { |
||
| 4114 | while (low < high) {
|
||
| 4115 | var mid = (low + high) >>> 1, |
||
| 4116 | computed = array[mid]; |
||
| 4117 | |||
| 4118 | if (computed !== null && !isSymbol(computed) && |
||
| 4119 | (retHighest ? (computed <= value) : (computed < value))) {
|
||
| 4120 | low = mid + 1;
|
||
| 4121 | } else {
|
||
| 4122 | high = mid; |
||
| 4123 | } |
||
| 4124 | } |
||
| 4125 | return high;
|
||
| 4126 | } |
||
| 4127 | return baseSortedIndexBy(array, value, identity, retHighest);
|
||
| 4128 | } |
||
| 4129 | |||
| 4130 | /**
|
||
| 4131 | * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
|
||
| 4132 | * which invokes `iteratee` for `value` and each element of `array` to compute
|
||
| 4133 | * their sort ranking. The iteratee is invoked with one argument; (value).
|
||
| 4134 | *
|
||
| 4135 | * @private
|
||
| 4136 | * @param {Array} array The sorted array to inspect.
|
||
| 4137 | * @param {*} value The value to evaluate.
|
||
| 4138 | * @param {Function} iteratee The iteratee invoked per element.
|
||
| 4139 | * @param {boolean} [retHighest] Specify returning the highest qualified index.
|
||
| 4140 | * @returns {number} Returns the index at which `value` should be inserted
|
||
| 4141 | * into `array`.
|
||
| 4142 | */
|
||
| 4143 | function baseSortedIndexBy(array, value, iteratee, retHighest) { |
||
| 4144 | value = iteratee(value); |
||
| 4145 | |||
| 4146 | var low = 0, |
||
| 4147 | high = array == null ? 0 : array.length, |
||
| 4148 | valIsNaN = value !== value, |
||
| 4149 | valIsNull = value === null,
|
||
| 4150 | valIsSymbol = isSymbol(value), |
||
| 4151 | valIsUndefined = value === undefined;
|
||
| 4152 | |||
| 4153 | while (low < high) {
|
||
| 4154 | var mid = nativeFloor((low + high) / 2), |
||
| 4155 | computed = iteratee(array[mid]), |
||
| 4156 | othIsDefined = computed !== undefined,
|
||
| 4157 | othIsNull = computed === null,
|
||
| 4158 | othIsReflexive = computed === computed, |
||
| 4159 | othIsSymbol = isSymbol(computed); |
||
| 4160 | |||
| 4161 | if (valIsNaN) {
|
||
| 4162 | var setLow = retHighest || othIsReflexive;
|
||
| 4163 | } else if (valIsUndefined) { |
||
| 4164 | setLow = othIsReflexive && (retHighest || othIsDefined); |
||
| 4165 | } else if (valIsNull) { |
||
| 4166 | setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull); |
||
| 4167 | } else if (valIsSymbol) { |
||
| 4168 | setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol); |
||
| 4169 | } else if (othIsNull || othIsSymbol) { |
||
| 4170 | setLow = false;
|
||
| 4171 | } else {
|
||
| 4172 | setLow = retHighest ? (computed <= value) : (computed < value); |
||
| 4173 | } |
||
| 4174 | if (setLow) {
|
||
| 4175 | low = mid + 1;
|
||
| 4176 | } else {
|
||
| 4177 | high = mid; |
||
| 4178 | } |
||
| 4179 | } |
||
| 4180 | return nativeMin(high, MAX_ARRAY_INDEX);
|
||
| 4181 | } |
||
| 4182 | |||
| 4183 | /**
|
||
| 4184 | * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
|
||
| 4185 | * support for iteratee shorthands.
|
||
| 4186 | *
|
||
| 4187 | * @private
|
||
| 4188 | * @param {Array} array The array to inspect.
|
||
| 4189 | * @param {Function} [iteratee] The iteratee invoked per element.
|
||
| 4190 | * @returns {Array} Returns the new duplicate free array.
|
||
| 4191 | */
|
||
| 4192 | function baseSortedUniq(array, iteratee) { |
||
| 4193 | var index = -1, |
||
| 4194 | length = array.length, |
||
| 4195 | resIndex = 0,
|
||
| 4196 | result = []; |
||
| 4197 | |||
| 4198 | while (++index < length) {
|
||
| 4199 | var value = array[index],
|
||
| 4200 | computed = iteratee ? iteratee(value) : value; |
||
| 4201 | |||
| 4202 | if (!index || !eq(computed, seen)) {
|
||
| 4203 | var seen = computed;
|
||
| 4204 | result[resIndex++] = value === 0 ? 0 : value; |
||
| 4205 | } |
||
| 4206 | } |
||
| 4207 | return result;
|
||
| 4208 | } |
||
| 4209 | |||
| 4210 | /**
|
||
| 4211 | * The base implementation of `_.toNumber` which doesn't ensure correct
|
||
| 4212 | * conversions of binary, hexadecimal, or octal string values.
|
||
| 4213 | *
|
||
| 4214 | * @private
|
||
| 4215 | * @param {*} value The value to process.
|
||
| 4216 | * @returns {number} Returns the number.
|
||
| 4217 | */
|
||
| 4218 | function baseToNumber(value) { |
||
| 4219 | if (typeof value == 'number') { |
||
| 4220 | return value;
|
||
| 4221 | } |
||
| 4222 | if (isSymbol(value)) {
|
||
| 4223 | return NAN;
|
||
| 4224 | } |
||
| 4225 | return +value;
|
||
| 4226 | } |
||
| 4227 | |||
| 4228 | /**
|
||
| 4229 | * The base implementation of `_.toString` which doesn't convert nullish
|
||
| 4230 | * values to empty strings.
|
||
| 4231 | *
|
||
| 4232 | * @private
|
||
| 4233 | * @param {*} value The value to process.
|
||
| 4234 | * @returns {string} Returns the string.
|
||
| 4235 | */
|
||
| 4236 | function baseToString(value) { |
||
| 4237 | // Exit early for strings to avoid a performance hit in some environments.
|
||
| 4238 | if (typeof value == 'string') { |
||
| 4239 | return value;
|
||
| 4240 | } |
||
| 4241 | if (isArray(value)) {
|
||
| 4242 | // Recursively convert values (susceptible to call stack limits).
|
||
| 4243 | return arrayMap(value, baseToString) + ''; |
||
| 4244 | } |
||
| 4245 | if (isSymbol(value)) {
|
||
| 4246 | return symbolToString ? symbolToString.call(value) : ''; |
||
| 4247 | } |
||
| 4248 | var result = (value + ''); |
||
| 4249 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; |
||
| 4250 | } |
||
| 4251 | |||
| 4252 | /**
|
||
| 4253 | * The base implementation of `_.uniqBy` without support for iteratee shorthands.
|
||
| 4254 | *
|
||
| 4255 | * @private
|
||
| 4256 | * @param {Array} array The array to inspect.
|
||
| 4257 | * @param {Function} [iteratee] The iteratee invoked per element.
|
||
| 4258 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 4259 | * @returns {Array} Returns the new duplicate free array.
|
||
| 4260 | */
|
||
| 4261 | function baseUniq(array, iteratee, comparator) { |
||
| 4262 | var index = -1, |
||
| 4263 | includes = arrayIncludes, |
||
| 4264 | length = array.length, |
||
| 4265 | isCommon = true,
|
||
| 4266 | result = [], |
||
| 4267 | seen = result; |
||
| 4268 | |||
| 4269 | if (comparator) {
|
||
| 4270 | isCommon = false;
|
||
| 4271 | includes = arrayIncludesWith; |
||
| 4272 | } |
||
| 4273 | else if (length >= LARGE_ARRAY_SIZE) { |
||
| 4274 | var set = iteratee ? null : createSet(array); |
||
| 4275 | if (set) {
|
||
| 4276 | return setToArray(set);
|
||
| 4277 | } |
||
| 4278 | isCommon = false;
|
||
| 4279 | includes = cacheHas; |
||
| 4280 | seen = new SetCache;
|
||
| 4281 | } |
||
| 4282 | else {
|
||
| 4283 | seen = iteratee ? [] : result; |
||
| 4284 | } |
||
| 4285 | outer: |
||
| 4286 | while (++index < length) {
|
||
| 4287 | var value = array[index],
|
||
| 4288 | computed = iteratee ? iteratee(value) : value; |
||
| 4289 | |||
| 4290 | value = (comparator || value !== 0) ? value : 0; |
||
| 4291 | if (isCommon && computed === computed) {
|
||
| 4292 | var seenIndex = seen.length;
|
||
| 4293 | while (seenIndex--) {
|
||
| 4294 | if (seen[seenIndex] === computed) {
|
||
| 4295 | continue outer;
|
||
| 4296 | } |
||
| 4297 | } |
||
| 4298 | if (iteratee) {
|
||
| 4299 | seen.push(computed); |
||
| 4300 | } |
||
| 4301 | result.push(value); |
||
| 4302 | } |
||
| 4303 | else if (!includes(seen, computed, comparator)) { |
||
| 4304 | if (seen !== result) {
|
||
| 4305 | seen.push(computed); |
||
| 4306 | } |
||
| 4307 | result.push(value); |
||
| 4308 | } |
||
| 4309 | } |
||
| 4310 | return result;
|
||
| 4311 | } |
||
| 4312 | |||
| 4313 | /**
|
||
| 4314 | * The base implementation of `_.unset`.
|
||
| 4315 | *
|
||
| 4316 | * @private
|
||
| 4317 | * @param {Object} object The object to modify.
|
||
| 4318 | * @param {Array|string} path The property path to unset.
|
||
| 4319 | * @returns {boolean} Returns `true` if the property is deleted, else `false`.
|
||
| 4320 | */
|
||
| 4321 | function baseUnset(object, path) { |
||
| 4322 | path = castPath(path, object); |
||
| 4323 | object = parent(object, path); |
||
| 4324 | return object == null || delete object[toKey(last(path))]; |
||
| 4325 | } |
||
| 4326 | |||
| 4327 | /**
|
||
| 4328 | * The base implementation of `_.update`.
|
||
| 4329 | *
|
||
| 4330 | * @private
|
||
| 4331 | * @param {Object} object The object to modify.
|
||
| 4332 | * @param {Array|string} path The path of the property to update.
|
||
| 4333 | * @param {Function} updater The function to produce the updated value.
|
||
| 4334 | * @param {Function} [customizer] The function to customize path creation.
|
||
| 4335 | * @returns {Object} Returns `object`.
|
||
| 4336 | */
|
||
| 4337 | function baseUpdate(object, path, updater, customizer) { |
||
| 4338 | return baseSet(object, path, updater(baseGet(object, path)), customizer);
|
||
| 4339 | } |
||
| 4340 | |||
| 4341 | /**
|
||
| 4342 | * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
|
||
| 4343 | * without support for iteratee shorthands.
|
||
| 4344 | *
|
||
| 4345 | * @private
|
||
| 4346 | * @param {Array} array The array to query.
|
||
| 4347 | * @param {Function} predicate The function invoked per iteration.
|
||
| 4348 | * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
|
||
| 4349 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
||
| 4350 | * @returns {Array} Returns the slice of `array`.
|
||
| 4351 | */
|
||
| 4352 | function baseWhile(array, predicate, isDrop, fromRight) { |
||
| 4353 | var length = array.length,
|
||
| 4354 | index = fromRight ? length : -1;
|
||
| 4355 | |||
| 4356 | while ((fromRight ? index-- : ++index < length) &&
|
||
| 4357 | predicate(array[index], index, array)) {}
|
||
| 4358 | |||
| 4359 | return isDrop
|
||
| 4360 | ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) |
||
| 4361 | : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)); |
||
| 4362 | } |
||
| 4363 | |||
| 4364 | /**
|
||
| 4365 | * The base implementation of `wrapperValue` which returns the result of
|
||
| 4366 | * performing a sequence of actions on the unwrapped `value`, where each
|
||
| 4367 | * successive action is supplied the return value of the previous.
|
||
| 4368 | *
|
||
| 4369 | * @private
|
||
| 4370 | * @param {*} value The unwrapped value.
|
||
| 4371 | * @param {Array} actions Actions to perform to resolve the unwrapped value.
|
||
| 4372 | * @returns {*} Returns the resolved value.
|
||
| 4373 | */
|
||
| 4374 | function baseWrapperValue(value, actions) { |
||
| 4375 | var result = value;
|
||
| 4376 | if (result instanceof LazyWrapper) { |
||
| 4377 | result = result.value(); |
||
| 4378 | } |
||
| 4379 | return arrayReduce(actions, function(result, action) { |
||
| 4380 | return action.func.apply(action.thisArg, arrayPush([result], action.args));
|
||
| 4381 | }, result); |
||
| 4382 | } |
||
| 4383 | |||
| 4384 | /**
|
||
| 4385 | * The base implementation of methods like `_.xor`, without support for
|
||
| 4386 | * iteratee shorthands, that accepts an array of arrays to inspect.
|
||
| 4387 | *
|
||
| 4388 | * @private
|
||
| 4389 | * @param {Array} arrays The arrays to inspect.
|
||
| 4390 | * @param {Function} [iteratee] The iteratee invoked per element.
|
||
| 4391 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 4392 | * @returns {Array} Returns the new array of values.
|
||
| 4393 | */
|
||
| 4394 | function baseXor(arrays, iteratee, comparator) { |
||
| 4395 | var length = arrays.length;
|
||
| 4396 | if (length < 2) { |
||
| 4397 | return length ? baseUniq(arrays[0]) : []; |
||
| 4398 | } |
||
| 4399 | var index = -1, |
||
| 4400 | result = Array(length); |
||
| 4401 | |||
| 4402 | while (++index < length) {
|
||
| 4403 | var array = arrays[index],
|
||
| 4404 | othIndex = -1;
|
||
| 4405 | |||
| 4406 | while (++othIndex < length) {
|
||
| 4407 | if (othIndex != index) {
|
||
| 4408 | result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator); |
||
| 4409 | } |
||
| 4410 | } |
||
| 4411 | } |
||
| 4412 | return baseUniq(baseFlatten(result, 1), iteratee, comparator); |
||
| 4413 | } |
||
| 4414 | |||
| 4415 | /**
|
||
| 4416 | * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
|
||
| 4417 | *
|
||
| 4418 | * @private
|
||
| 4419 | * @param {Array} props The property identifiers.
|
||
| 4420 | * @param {Array} values The property values.
|
||
| 4421 | * @param {Function} assignFunc The function to assign values.
|
||
| 4422 | * @returns {Object} Returns the new object.
|
||
| 4423 | */
|
||
| 4424 | function baseZipObject(props, values, assignFunc) { |
||
| 4425 | var index = -1, |
||
| 4426 | length = props.length, |
||
| 4427 | valsLength = values.length, |
||
| 4428 | result = {};
|
||
| 4429 | |||
| 4430 | while (++index < length) {
|
||
| 4431 | var value = index < valsLength ? values[index] : undefined; |
||
| 4432 | assignFunc(result, props[index], value); |
||
| 4433 | } |
||
| 4434 | return result;
|
||
| 4435 | } |
||
| 4436 | |||
| 4437 | /**
|
||
| 4438 | * Casts `value` to an empty array if it's not an array like object.
|
||
| 4439 | *
|
||
| 4440 | * @private
|
||
| 4441 | * @param {*} value The value to inspect.
|
||
| 4442 | * @returns {Array|Object} Returns the cast array-like object.
|
||
| 4443 | */
|
||
| 4444 | function castArrayLikeObject(value) { |
||
| 4445 | return isArrayLikeObject(value) ? value : [];
|
||
| 4446 | } |
||
| 4447 | |||
| 4448 | /**
|
||
| 4449 | * Casts `value` to `identity` if it's not a function.
|
||
| 4450 | *
|
||
| 4451 | * @private
|
||
| 4452 | * @param {*} value The value to inspect.
|
||
| 4453 | * @returns {Function} Returns cast function.
|
||
| 4454 | */
|
||
| 4455 | function castFunction(value) { |
||
| 4456 | return typeof value == 'function' ? value : identity; |
||
| 4457 | } |
||
| 4458 | |||
| 4459 | /**
|
||
| 4460 | * Casts `value` to a path array if it's not one.
|
||
| 4461 | *
|
||
| 4462 | * @private
|
||
| 4463 | * @param {*} value The value to inspect.
|
||
| 4464 | * @param {Object} [object] The object to query keys on.
|
||
| 4465 | * @returns {Array} Returns the cast property path array.
|
||
| 4466 | */
|
||
| 4467 | function castPath(value, object) { |
||
| 4468 | if (isArray(value)) {
|
||
| 4469 | return value;
|
||
| 4470 | } |
||
| 4471 | return isKey(value, object) ? [value] : stringToPath(toString(value));
|
||
| 4472 | } |
||
| 4473 | |||
| 4474 | /**
|
||
| 4475 | * A `baseRest` alias which can be replaced with `identity` by module
|
||
| 4476 | * replacement plugins.
|
||
| 4477 | *
|
||
| 4478 | * @private
|
||
| 4479 | * @type {Function}
|
||
| 4480 | * @param {Function} func The function to apply a rest parameter to.
|
||
| 4481 | * @returns {Function} Returns the new function.
|
||
| 4482 | */
|
||
| 4483 | var castRest = baseRest;
|
||
| 4484 | |||
| 4485 | /**
|
||
| 4486 | * Casts `array` to a slice if it's needed.
|
||
| 4487 | *
|
||
| 4488 | * @private
|
||
| 4489 | * @param {Array} array The array to inspect.
|
||
| 4490 | * @param {number} start The start position.
|
||
| 4491 | * @param {number} [end=array.length] The end position.
|
||
| 4492 | * @returns {Array} Returns the cast slice.
|
||
| 4493 | */
|
||
| 4494 | function castSlice(array, start, end) { |
||
| 4495 | var length = array.length;
|
||
| 4496 | end = end === undefined ? length : end;
|
||
| 4497 | return (!start && end >= length) ? array : baseSlice(array, start, end);
|
||
| 4498 | } |
||
| 4499 | |||
| 4500 | /**
|
||
| 4501 | * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
|
||
| 4502 | *
|
||
| 4503 | * @private
|
||
| 4504 | * @param {number|Object} id The timer id or timeout object of the timer to clear.
|
||
| 4505 | */
|
||
| 4506 | var clearTimeout = ctxClearTimeout || function(id) { |
||
| 4507 | return root.clearTimeout(id);
|
||
| 4508 | }; |
||
| 4509 | |||
| 4510 | /**
|
||
| 4511 | * Creates a clone of `buffer`.
|
||
| 4512 | *
|
||
| 4513 | * @private
|
||
| 4514 | * @param {Buffer} buffer The buffer to clone.
|
||
| 4515 | * @param {boolean} [isDeep] Specify a deep clone.
|
||
| 4516 | * @returns {Buffer} Returns the cloned buffer.
|
||
| 4517 | */
|
||
| 4518 | function cloneBuffer(buffer, isDeep) { |
||
| 4519 | if (isDeep) {
|
||
| 4520 | return buffer.slice();
|
||
| 4521 | } |
||
| 4522 | var length = buffer.length,
|
||
| 4523 | result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
|
||
| 4524 | |||
| 4525 | buffer.copy(result); |
||
| 4526 | return result;
|
||
| 4527 | } |
||
| 4528 | |||
| 4529 | /**
|
||
| 4530 | * Creates a clone of `arrayBuffer`.
|
||
| 4531 | *
|
||
| 4532 | * @private
|
||
| 4533 | * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
|
||
| 4534 | * @returns {ArrayBuffer} Returns the cloned array buffer.
|
||
| 4535 | */
|
||
| 4536 | function cloneArrayBuffer(arrayBuffer) { |
||
| 4537 | var result = new arrayBuffer.constructor(arrayBuffer.byteLength); |
||
| 4538 | new Uint8Array(result).set(new Uint8Array(arrayBuffer)); |
||
| 4539 | return result;
|
||
| 4540 | } |
||
| 4541 | |||
| 4542 | /**
|
||
| 4543 | * Creates a clone of `dataView`.
|
||
| 4544 | *
|
||
| 4545 | * @private
|
||
| 4546 | * @param {Object} dataView The data view to clone.
|
||
| 4547 | * @param {boolean} [isDeep] Specify a deep clone.
|
||
| 4548 | * @returns {Object} Returns the cloned data view.
|
||
| 4549 | */
|
||
| 4550 | function cloneDataView(dataView, isDeep) { |
||
| 4551 | var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
|
||
| 4552 | return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); |
||
| 4553 | } |
||
| 4554 | |||
| 4555 | /**
|
||
| 4556 | * Creates a clone of `regexp`.
|
||
| 4557 | *
|
||
| 4558 | * @private
|
||
| 4559 | * @param {Object} regexp The regexp to clone.
|
||
| 4560 | * @returns {Object} Returns the cloned regexp.
|
||
| 4561 | */
|
||
| 4562 | function cloneRegExp(regexp) { |
||
| 4563 | var result = new regexp.constructor(regexp.source, reFlags.exec(regexp)); |
||
| 4564 | result.lastIndex = regexp.lastIndex; |
||
| 4565 | return result;
|
||
| 4566 | } |
||
| 4567 | |||
| 4568 | /**
|
||
| 4569 | * Creates a clone of the `symbol` object.
|
||
| 4570 | *
|
||
| 4571 | * @private
|
||
| 4572 | * @param {Object} symbol The symbol object to clone.
|
||
| 4573 | * @returns {Object} Returns the cloned symbol object.
|
||
| 4574 | */
|
||
| 4575 | function cloneSymbol(symbol) { |
||
| 4576 | return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
||
| 4577 | } |
||
| 4578 | |||
| 4579 | /**
|
||
| 4580 | * Creates a clone of `typedArray`.
|
||
| 4581 | *
|
||
| 4582 | * @private
|
||
| 4583 | * @param {Object} typedArray The typed array to clone.
|
||
| 4584 | * @param {boolean} [isDeep] Specify a deep clone.
|
||
| 4585 | * @returns {Object} Returns the cloned typed array.
|
||
| 4586 | */
|
||
| 4587 | function cloneTypedArray(typedArray, isDeep) { |
||
| 4588 | var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
||
| 4589 | return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length); |
||
| 4590 | } |
||
| 4591 | |||
| 4592 | /**
|
||
| 4593 | * Compares values to sort them in ascending order.
|
||
| 4594 | *
|
||
| 4595 | * @private
|
||
| 4596 | * @param {*} value The value to compare.
|
||
| 4597 | * @param {*} other The other value to compare.
|
||
| 4598 | * @returns {number} Returns the sort order indicator for `value`.
|
||
| 4599 | */
|
||
| 4600 | function compareAscending(value, other) { |
||
| 4601 | if (value !== other) {
|
||
| 4602 | var valIsDefined = value !== undefined, |
||
| 4603 | valIsNull = value === null,
|
||
| 4604 | valIsReflexive = value === value, |
||
| 4605 | valIsSymbol = isSymbol(value); |
||
| 4606 | |||
| 4607 | var othIsDefined = other !== undefined, |
||
| 4608 | othIsNull = other === null,
|
||
| 4609 | othIsReflexive = other === other, |
||
| 4610 | othIsSymbol = isSymbol(other); |
||
| 4611 | |||
| 4612 | if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
|
||
| 4613 | (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || |
||
| 4614 | (valIsNull && othIsDefined && othIsReflexive) || |
||
| 4615 | (!valIsDefined && othIsReflexive) || |
||
| 4616 | !valIsReflexive) {
|
||
| 4617 | return 1; |
||
| 4618 | } |
||
| 4619 | if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
|
||
| 4620 | (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || |
||
| 4621 | (othIsNull && valIsDefined && valIsReflexive) || |
||
| 4622 | (!othIsDefined && valIsReflexive) || |
||
| 4623 | !othIsReflexive) {
|
||
| 4624 | return -1; |
||
| 4625 | } |
||
| 4626 | } |
||
| 4627 | return 0; |
||
| 4628 | } |
||
| 4629 | |||
| 4630 | /**
|
||
| 4631 | * Used by `_.orderBy` to compare multiple properties of a value to another
|
||
| 4632 | * and stable sort them.
|
||
| 4633 | *
|
||
| 4634 | * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
|
||
| 4635 | * specify an order of "desc" for descending or "asc" for ascending sort order
|
||
| 4636 | * of corresponding values.
|
||
| 4637 | *
|
||
| 4638 | * @private
|
||
| 4639 | * @param {Object} object The object to compare.
|
||
| 4640 | * @param {Object} other The other object to compare.
|
||
| 4641 | * @param {boolean[]|string[]} orders The order to sort by for each property.
|
||
| 4642 | * @returns {number} Returns the sort order indicator for `object`.
|
||
| 4643 | */
|
||
| 4644 | function compareMultiple(object, other, orders) { |
||
| 4645 | var index = -1, |
||
| 4646 | objCriteria = object.criteria, |
||
| 4647 | othCriteria = other.criteria, |
||
| 4648 | length = objCriteria.length, |
||
| 4649 | ordersLength = orders.length; |
||
| 4650 | |||
| 4651 | while (++index < length) {
|
||
| 4652 | var result = compareAscending(objCriteria[index], othCriteria[index]);
|
||
| 4653 | if (result) {
|
||
| 4654 | if (index >= ordersLength) {
|
||
| 4655 | return result;
|
||
| 4656 | } |
||
| 4657 | var order = orders[index];
|
||
| 4658 | return result * (order == 'desc' ? -1 : 1); |
||
| 4659 | } |
||
| 4660 | } |
||
| 4661 | // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
||
| 4662 | // that causes it, under certain circumstances, to provide the same value for
|
||
| 4663 | // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
|
||
| 4664 | // for more details.
|
||
| 4665 | //
|
||
| 4666 | // This also ensures a stable sort in V8 and other engines.
|
||
| 4667 | // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
|
||
| 4668 | return object.index - other.index;
|
||
| 4669 | } |
||
| 4670 | |||
| 4671 | /**
|
||
| 4672 | * Creates an array that is the composition of partially applied arguments,
|
||
| 4673 | * placeholders, and provided arguments into a single array of arguments.
|
||
| 4674 | *
|
||
| 4675 | * @private
|
||
| 4676 | * @param {Array} args The provided arguments.
|
||
| 4677 | * @param {Array} partials The arguments to prepend to those provided.
|
||
| 4678 | * @param {Array} holders The `partials` placeholder indexes.
|
||
| 4679 | * @params {boolean} [isCurried] Specify composing for a curried function.
|
||
| 4680 | * @returns {Array} Returns the new array of composed arguments.
|
||
| 4681 | */
|
||
| 4682 | function composeArgs(args, partials, holders, isCurried) { |
||
| 4683 | var argsIndex = -1, |
||
| 4684 | argsLength = args.length, |
||
| 4685 | holdersLength = holders.length, |
||
| 4686 | leftIndex = -1,
|
||
| 4687 | leftLength = partials.length, |
||
| 4688 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
||
| 4689 | result = Array(leftLength + rangeLength), |
||
| 4690 | isUncurried = !isCurried; |
||
| 4691 | |||
| 4692 | while (++leftIndex < leftLength) {
|
||
| 4693 | result[leftIndex] = partials[leftIndex]; |
||
| 4694 | } |
||
| 4695 | while (++argsIndex < holdersLength) {
|
||
| 4696 | if (isUncurried || argsIndex < argsLength) {
|
||
| 4697 | result[holders[argsIndex]] = args[argsIndex]; |
||
| 4698 | } |
||
| 4699 | } |
||
| 4700 | while (rangeLength--) {
|
||
| 4701 | result[leftIndex++] = args[argsIndex++]; |
||
| 4702 | } |
||
| 4703 | return result;
|
||
| 4704 | } |
||
| 4705 | |||
| 4706 | /**
|
||
| 4707 | * This function is like `composeArgs` except that the arguments composition
|
||
| 4708 | * is tailored for `_.partialRight`.
|
||
| 4709 | *
|
||
| 4710 | * @private
|
||
| 4711 | * @param {Array} args The provided arguments.
|
||
| 4712 | * @param {Array} partials The arguments to append to those provided.
|
||
| 4713 | * @param {Array} holders The `partials` placeholder indexes.
|
||
| 4714 | * @params {boolean} [isCurried] Specify composing for a curried function.
|
||
| 4715 | * @returns {Array} Returns the new array of composed arguments.
|
||
| 4716 | */
|
||
| 4717 | function composeArgsRight(args, partials, holders, isCurried) { |
||
| 4718 | var argsIndex = -1, |
||
| 4719 | argsLength = args.length, |
||
| 4720 | holdersIndex = -1,
|
||
| 4721 | holdersLength = holders.length, |
||
| 4722 | rightIndex = -1,
|
||
| 4723 | rightLength = partials.length, |
||
| 4724 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
||
| 4725 | result = Array(rangeLength + rightLength), |
||
| 4726 | isUncurried = !isCurried; |
||
| 4727 | |||
| 4728 | while (++argsIndex < rangeLength) {
|
||
| 4729 | result[argsIndex] = args[argsIndex]; |
||
| 4730 | } |
||
| 4731 | var offset = argsIndex;
|
||
| 4732 | while (++rightIndex < rightLength) {
|
||
| 4733 | result[offset + rightIndex] = partials[rightIndex]; |
||
| 4734 | } |
||
| 4735 | while (++holdersIndex < holdersLength) {
|
||
| 4736 | if (isUncurried || argsIndex < argsLength) {
|
||
| 4737 | result[offset + holders[holdersIndex]] = args[argsIndex++]; |
||
| 4738 | } |
||
| 4739 | } |
||
| 4740 | return result;
|
||
| 4741 | } |
||
| 4742 | |||
| 4743 | /**
|
||
| 4744 | * Copies the values of `source` to `array`.
|
||
| 4745 | *
|
||
| 4746 | * @private
|
||
| 4747 | * @param {Array} source The array to copy values from.
|
||
| 4748 | * @param {Array} [array=[]] The array to copy values to.
|
||
| 4749 | * @returns {Array} Returns `array`.
|
||
| 4750 | */
|
||
| 4751 | function copyArray(source, array) { |
||
| 4752 | var index = -1, |
||
| 4753 | length = source.length; |
||
| 4754 | |||
| 4755 | array || (array = Array(length)); |
||
| 4756 | while (++index < length) {
|
||
| 4757 | array[index] = source[index]; |
||
| 4758 | } |
||
| 4759 | return array;
|
||
| 4760 | } |
||
| 4761 | |||
| 4762 | /**
|
||
| 4763 | * Copies properties of `source` to `object`.
|
||
| 4764 | *
|
||
| 4765 | * @private
|
||
| 4766 | * @param {Object} source The object to copy properties from.
|
||
| 4767 | * @param {Array} props The property identifiers to copy.
|
||
| 4768 | * @param {Object} [object={}] The object to copy properties to.
|
||
| 4769 | * @param {Function} [customizer] The function to customize copied values.
|
||
| 4770 | * @returns {Object} Returns `object`.
|
||
| 4771 | */
|
||
| 4772 | function copyObject(source, props, object, customizer) { |
||
| 4773 | var isNew = !object;
|
||
| 4774 | object || (object = {});
|
||
| 4775 | |||
| 4776 | var index = -1, |
||
| 4777 | length = props.length; |
||
| 4778 | |||
| 4779 | while (++index < length) {
|
||
| 4780 | var key = props[index];
|
||
| 4781 | |||
| 4782 | var newValue = customizer
|
||
| 4783 | ? customizer(object[key], source[key], key, object, source) |
||
| 4784 | : undefined;
|
||
| 4785 | |||
| 4786 | if (newValue === undefined) { |
||
| 4787 | newValue = source[key]; |
||
| 4788 | } |
||
| 4789 | if (isNew) {
|
||
| 4790 | baseAssignValue(object, key, newValue); |
||
| 4791 | } else {
|
||
| 4792 | assignValue(object, key, newValue); |
||
| 4793 | } |
||
| 4794 | } |
||
| 4795 | return object;
|
||
| 4796 | } |
||
| 4797 | |||
| 4798 | /**
|
||
| 4799 | * Copies own symbols of `source` to `object`.
|
||
| 4800 | *
|
||
| 4801 | * @private
|
||
| 4802 | * @param {Object} source The object to copy symbols from.
|
||
| 4803 | * @param {Object} [object={}] The object to copy symbols to.
|
||
| 4804 | * @returns {Object} Returns `object`.
|
||
| 4805 | */
|
||
| 4806 | function copySymbols(source, object) { |
||
| 4807 | return copyObject(source, getSymbols(source), object);
|
||
| 4808 | } |
||
| 4809 | |||
| 4810 | /**
|
||
| 4811 | * Copies own and inherited symbols of `source` to `object`.
|
||
| 4812 | *
|
||
| 4813 | * @private
|
||
| 4814 | * @param {Object} source The object to copy symbols from.
|
||
| 4815 | * @param {Object} [object={}] The object to copy symbols to.
|
||
| 4816 | * @returns {Object} Returns `object`.
|
||
| 4817 | */
|
||
| 4818 | function copySymbolsIn(source, object) { |
||
| 4819 | return copyObject(source, getSymbolsIn(source), object);
|
||
| 4820 | } |
||
| 4821 | |||
| 4822 | /**
|
||
| 4823 | * Creates a function like `_.groupBy`.
|
||
| 4824 | *
|
||
| 4825 | * @private
|
||
| 4826 | * @param {Function} setter The function to set accumulator values.
|
||
| 4827 | * @param {Function} [initializer] The accumulator object initializer.
|
||
| 4828 | * @returns {Function} Returns the new aggregator function.
|
||
| 4829 | */
|
||
| 4830 | function createAggregator(setter, initializer) { |
||
| 4831 | return function(collection, iteratee) { |
||
| 4832 | var func = isArray(collection) ? arrayAggregator : baseAggregator,
|
||
| 4833 | accumulator = initializer ? initializer() : {};
|
||
| 4834 | |||
| 4835 | return func(collection, setter, getIteratee(iteratee, 2), accumulator); |
||
| 4836 | }; |
||
| 4837 | } |
||
| 4838 | |||
| 4839 | /**
|
||
| 4840 | * Creates a function like `_.assign`.
|
||
| 4841 | *
|
||
| 4842 | * @private
|
||
| 4843 | * @param {Function} assigner The function to assign values.
|
||
| 4844 | * @returns {Function} Returns the new assigner function.
|
||
| 4845 | */
|
||
| 4846 | function createAssigner(assigner) { |
||
| 4847 | return baseRest(function(object, sources) { |
||
| 4848 | var index = -1, |
||
| 4849 | length = sources.length, |
||
| 4850 | customizer = length > 1 ? sources[length - 1] : undefined, |
||
| 4851 | guard = length > 2 ? sources[2] : undefined; |
||
| 4852 | |||
| 4853 | customizer = (assigner.length > 3 && typeof customizer == 'function') |
||
| 4854 | ? (length--, customizer) |
||
| 4855 | : undefined;
|
||
| 4856 | |||
| 4857 | if (guard && isIterateeCall(sources[0], sources[1], guard)) { |
||
| 4858 | customizer = length < 3 ? undefined : customizer; |
||
| 4859 | length = 1;
|
||
| 4860 | } |
||
| 4861 | object = Object(object); |
||
| 4862 | while (++index < length) {
|
||
| 4863 | var source = sources[index];
|
||
| 4864 | if (source) {
|
||
| 4865 | assigner(object, source, index, customizer); |
||
| 4866 | } |
||
| 4867 | } |
||
| 4868 | return object;
|
||
| 4869 | }); |
||
| 4870 | } |
||
| 4871 | |||
| 4872 | /**
|
||
| 4873 | * Creates a `baseEach` or `baseEachRight` function.
|
||
| 4874 | *
|
||
| 4875 | * @private
|
||
| 4876 | * @param {Function} eachFunc The function to iterate over a collection.
|
||
| 4877 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
||
| 4878 | * @returns {Function} Returns the new base function.
|
||
| 4879 | */
|
||
| 4880 | function createBaseEach(eachFunc, fromRight) { |
||
| 4881 | return function(collection, iteratee) { |
||
| 4882 | if (collection == null) { |
||
| 4883 | return collection;
|
||
| 4884 | } |
||
| 4885 | if (!isArrayLike(collection)) {
|
||
| 4886 | return eachFunc(collection, iteratee);
|
||
| 4887 | } |
||
| 4888 | var length = collection.length,
|
||
| 4889 | index = fromRight ? length : -1,
|
||
| 4890 | iterable = Object(collection); |
||
| 4891 | |||
| 4892 | while ((fromRight ? index-- : ++index < length)) {
|
||
| 4893 | if (iteratee(iterable[index], index, iterable) === false) { |
||
| 4894 | break;
|
||
| 4895 | } |
||
| 4896 | } |
||
| 4897 | return collection;
|
||
| 4898 | }; |
||
| 4899 | } |
||
| 4900 | |||
| 4901 | /**
|
||
| 4902 | * Creates a base function for methods like `_.forIn` and `_.forOwn`.
|
||
| 4903 | *
|
||
| 4904 | * @private
|
||
| 4905 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
||
| 4906 | * @returns {Function} Returns the new base function.
|
||
| 4907 | */
|
||
| 4908 | function createBaseFor(fromRight) { |
||
| 4909 | return function(object, iteratee, keysFunc) { |
||
| 4910 | var index = -1, |
||
| 4911 | iterable = Object(object), |
||
| 4912 | props = keysFunc(object), |
||
| 4913 | length = props.length; |
||
| 4914 | |||
| 4915 | while (length--) {
|
||
| 4916 | var key = props[fromRight ? length : ++index];
|
||
| 4917 | if (iteratee(iterable[key], key, iterable) === false) { |
||
| 4918 | break;
|
||
| 4919 | } |
||
| 4920 | } |
||
| 4921 | return object;
|
||
| 4922 | }; |
||
| 4923 | } |
||
| 4924 | |||
| 4925 | /**
|
||
| 4926 | * Creates a function that wraps `func` to invoke it with the optional `this`
|
||
| 4927 | * binding of `thisArg`.
|
||
| 4928 | *
|
||
| 4929 | * @private
|
||
| 4930 | * @param {Function} func The function to wrap.
|
||
| 4931 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||
| 4932 | * @param {*} [thisArg] The `this` binding of `func`.
|
||
| 4933 | * @returns {Function} Returns the new wrapped function.
|
||
| 4934 | */
|
||
| 4935 | function createBind(func, bitmask, thisArg) { |
||
| 4936 | var isBind = bitmask & WRAP_BIND_FLAG,
|
||
| 4937 | Ctor = createCtor(func); |
||
| 4938 | |||
| 4939 | function wrapper() { |
||
| 4940 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; |
||
| 4941 | return fn.apply(isBind ? thisArg : this, arguments); |
||
| 4942 | } |
||
| 4943 | return wrapper;
|
||
| 4944 | } |
||
| 4945 | |||
| 4946 | /**
|
||
| 4947 | * Creates a function like `_.lowerFirst`.
|
||
| 4948 | *
|
||
| 4949 | * @private
|
||
| 4950 | * @param {string} methodName The name of the `String` case method to use.
|
||
| 4951 | * @returns {Function} Returns the new case function.
|
||
| 4952 | */
|
||
| 4953 | function createCaseFirst(methodName) { |
||
| 4954 | return function(string) { |
||
| 4955 | string = toString(string); |
||
| 4956 | |||
| 4957 | var strSymbols = hasUnicode(string)
|
||
| 4958 | ? stringToArray(string) |
||
| 4959 | : undefined;
|
||
| 4960 | |||
| 4961 | var chr = strSymbols
|
||
| 4962 | ? strSymbols[0]
|
||
| 4963 | : string.charAt(0);
|
||
| 4964 | |||
| 4965 | var trailing = strSymbols
|
||
| 4966 | ? castSlice(strSymbols, 1).join('') |
||
| 4967 | : string.slice(1);
|
||
| 4968 | |||
| 4969 | return chr[methodName]() + trailing;
|
||
| 4970 | }; |
||
| 4971 | } |
||
| 4972 | |||
| 4973 | /**
|
||
| 4974 | * Creates a function like `_.camelCase`.
|
||
| 4975 | *
|
||
| 4976 | * @private
|
||
| 4977 | * @param {Function} callback The function to combine each word.
|
||
| 4978 | * @returns {Function} Returns the new compounder function.
|
||
| 4979 | */
|
||
| 4980 | function createCompounder(callback) { |
||
| 4981 | return function(string) { |
||
| 4982 | return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); |
||
| 4983 | }; |
||
| 4984 | } |
||
| 4985 | |||
| 4986 | /**
|
||
| 4987 | * Creates a function that produces an instance of `Ctor` regardless of
|
||
| 4988 | * whether it was invoked as part of a `new` expression or by `call` or `apply`.
|
||
| 4989 | *
|
||
| 4990 | * @private
|
||
| 4991 | * @param {Function} Ctor The constructor to wrap.
|
||
| 4992 | * @returns {Function} Returns the new wrapped function.
|
||
| 4993 | */
|
||
| 4994 | function createCtor(Ctor) { |
||
| 4995 | return function() { |
||
| 4996 | // Use a `switch` statement to work with class constructors. See
|
||
| 4997 | // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
||
| 4998 | // for more details.
|
||
| 4999 | var args = arguments; |
||
| 5000 | switch (args.length) {
|
||
| 5001 | case 0: return new Ctor; |
||
| 5002 | case 1: return new Ctor(args[0]); |
||
| 5003 | case 2: return new Ctor(args[0], args[1]); |
||
| 5004 | case 3: return new Ctor(args[0], args[1], args[2]); |
||
| 5005 | case 4: return new Ctor(args[0], args[1], args[2], args[3]); |
||
| 5006 | case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); |
||
| 5007 | case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); |
||
| 5008 | case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); |
||
| 5009 | } |
||
| 5010 | var thisBinding = baseCreate(Ctor.prototype),
|
||
| 5011 | result = Ctor.apply(thisBinding, args); |
||
| 5012 | |||
| 5013 | // Mimic the constructor's `return` behavior.
|
||
| 5014 | // See https://es5.github.io/#x13.2.2 for more details.
|
||
| 5015 | return isObject(result) ? result : thisBinding;
|
||
| 5016 | }; |
||
| 5017 | } |
||
| 5018 | |||
| 5019 | /**
|
||
| 5020 | * Creates a function that wraps `func` to enable currying.
|
||
| 5021 | *
|
||
| 5022 | * @private
|
||
| 5023 | * @param {Function} func The function to wrap.
|
||
| 5024 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||
| 5025 | * @param {number} arity The arity of `func`.
|
||
| 5026 | * @returns {Function} Returns the new wrapped function.
|
||
| 5027 | */
|
||
| 5028 | function createCurry(func, bitmask, arity) { |
||
| 5029 | var Ctor = createCtor(func);
|
||
| 5030 | |||
| 5031 | function wrapper() { |
||
| 5032 | var length = arguments.length, |
||
| 5033 | args = Array(length), |
||
| 5034 | index = length, |
||
| 5035 | placeholder = getHolder(wrapper); |
||
| 5036 | |||
| 5037 | while (index--) {
|
||
| 5038 | args[index] = arguments[index];
|
||
| 5039 | } |
||
| 5040 | var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) |
||
| 5041 | ? [] |
||
| 5042 | : replaceHolders(args, placeholder); |
||
| 5043 | |||
| 5044 | length -= holders.length; |
||
| 5045 | if (length < arity) {
|
||
| 5046 | return createRecurry(
|
||
| 5047 | func, bitmask, createHybrid, wrapper.placeholder, undefined,
|
||
| 5048 | args, holders, undefined, undefined, arity - length); |
||
| 5049 | } |
||
| 5050 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; |
||
| 5051 | return apply(fn, this, args); |
||
| 5052 | } |
||
| 5053 | return wrapper;
|
||
| 5054 | } |
||
| 5055 | |||
| 5056 | /**
|
||
| 5057 | * Creates a `_.find` or `_.findLast` function.
|
||
| 5058 | *
|
||
| 5059 | * @private
|
||
| 5060 | * @param {Function} findIndexFunc The function to find the collection index.
|
||
| 5061 | * @returns {Function} Returns the new find function.
|
||
| 5062 | */
|
||
| 5063 | function createFind(findIndexFunc) { |
||
| 5064 | return function(collection, predicate, fromIndex) { |
||
| 5065 | var iterable = Object(collection);
|
||
| 5066 | if (!isArrayLike(collection)) {
|
||
| 5067 | var iteratee = getIteratee(predicate, 3); |
||
| 5068 | collection = keys(collection); |
||
| 5069 | predicate = function(key) { return iteratee(iterable[key], key, iterable); }; |
||
| 5070 | } |
||
| 5071 | var index = findIndexFunc(collection, predicate, fromIndex);
|
||
| 5072 | return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined; |
||
| 5073 | }; |
||
| 5074 | } |
||
| 5075 | |||
| 5076 | /**
|
||
| 5077 | * Creates a `_.flow` or `_.flowRight` function.
|
||
| 5078 | *
|
||
| 5079 | * @private
|
||
| 5080 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
||
| 5081 | * @returns {Function} Returns the new flow function.
|
||
| 5082 | */
|
||
| 5083 | function createFlow(fromRight) { |
||
| 5084 | return flatRest(function(funcs) { |
||
| 5085 | var length = funcs.length,
|
||
| 5086 | index = length, |
||
| 5087 | prereq = LodashWrapper.prototype.thru; |
||
| 5088 | |||
| 5089 | if (fromRight) {
|
||
| 5090 | funcs.reverse(); |
||
| 5091 | } |
||
| 5092 | while (index--) {
|
||
| 5093 | var func = funcs[index];
|
||
| 5094 | if (typeof func != 'function') { |
||
| 5095 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 5096 | } |
||
| 5097 | if (prereq && !wrapper && getFuncName(func) == 'wrapper') { |
||
| 5098 | var wrapper = new LodashWrapper([], true); |
||
| 5099 | } |
||
| 5100 | } |
||
| 5101 | index = wrapper ? index : length; |
||
| 5102 | while (++index < length) {
|
||
| 5103 | func = funcs[index]; |
||
| 5104 | |||
| 5105 | var funcName = getFuncName(func),
|
||
| 5106 | data = funcName == 'wrapper' ? getData(func) : undefined; |
||
| 5107 | |||
| 5108 | if (data && isLaziable(data[0]) && |
||
| 5109 | data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
|
||
| 5110 | !data[4].length && data[9] == 1 |
||
| 5111 | ) {
|
||
| 5112 | wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); |
||
| 5113 | } else {
|
||
| 5114 | wrapper = (func.length == 1 && isLaziable(func))
|
||
| 5115 | ? wrapper[funcName]() |
||
| 5116 | : wrapper.thru(func); |
||
| 5117 | } |
||
| 5118 | } |
||
| 5119 | return function() { |
||
| 5120 | var args = arguments, |
||
| 5121 | value = args[0];
|
||
| 5122 | |||
| 5123 | if (wrapper && args.length == 1 && isArray(value)) { |
||
| 5124 | return wrapper.plant(value).value();
|
||
| 5125 | } |
||
| 5126 | var index = 0, |
||
| 5127 | result = length ? funcs[index].apply(this, args) : value;
|
||
| 5128 | |||
| 5129 | while (++index < length) {
|
||
| 5130 | result = funcs[index].call(this, result);
|
||
| 5131 | } |
||
| 5132 | return result;
|
||
| 5133 | }; |
||
| 5134 | }); |
||
| 5135 | } |
||
| 5136 | |||
| 5137 | /**
|
||
| 5138 | * Creates a function that wraps `func` to invoke it with optional `this`
|
||
| 5139 | * binding of `thisArg`, partial application, and currying.
|
||
| 5140 | *
|
||
| 5141 | * @private
|
||
| 5142 | * @param {Function|string} func The function or method name to wrap.
|
||
| 5143 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||
| 5144 | * @param {*} [thisArg] The `this` binding of `func`.
|
||
| 5145 | * @param {Array} [partials] The arguments to prepend to those provided to
|
||
| 5146 | * the new function.
|
||
| 5147 | * @param {Array} [holders] The `partials` placeholder indexes.
|
||
| 5148 | * @param {Array} [partialsRight] The arguments to append to those provided
|
||
| 5149 | * to the new function.
|
||
| 5150 | * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
|
||
| 5151 | * @param {Array} [argPos] The argument positions of the new function.
|
||
| 5152 | * @param {number} [ary] The arity cap of `func`.
|
||
| 5153 | * @param {number} [arity] The arity of `func`.
|
||
| 5154 | * @returns {Function} Returns the new wrapped function.
|
||
| 5155 | */
|
||
| 5156 | function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { |
||
| 5157 | var isAry = bitmask & WRAP_ARY_FLAG,
|
||
| 5158 | isBind = bitmask & WRAP_BIND_FLAG, |
||
| 5159 | isBindKey = bitmask & WRAP_BIND_KEY_FLAG, |
||
| 5160 | isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), |
||
| 5161 | isFlip = bitmask & WRAP_FLIP_FLAG, |
||
| 5162 | Ctor = isBindKey ? undefined : createCtor(func);
|
||
| 5163 | |||
| 5164 | function wrapper() { |
||
| 5165 | var length = arguments.length, |
||
| 5166 | args = Array(length), |
||
| 5167 | index = length; |
||
| 5168 | |||
| 5169 | while (index--) {
|
||
| 5170 | args[index] = arguments[index];
|
||
| 5171 | } |
||
| 5172 | if (isCurried) {
|
||
| 5173 | var placeholder = getHolder(wrapper),
|
||
| 5174 | holdersCount = countHolders(args, placeholder); |
||
| 5175 | } |
||
| 5176 | if (partials) {
|
||
| 5177 | args = composeArgs(args, partials, holders, isCurried); |
||
| 5178 | } |
||
| 5179 | if (partialsRight) {
|
||
| 5180 | args = composeArgsRight(args, partialsRight, holdersRight, isCurried); |
||
| 5181 | } |
||
| 5182 | length -= holdersCount; |
||
| 5183 | if (isCurried && length < arity) {
|
||
| 5184 | var newHolders = replaceHolders(args, placeholder);
|
||
| 5185 | return createRecurry(
|
||
| 5186 | func, bitmask, createHybrid, wrapper.placeholder, thisArg, |
||
| 5187 | args, newHolders, argPos, ary, arity - length |
||
| 5188 | ); |
||
| 5189 | } |
||
| 5190 | var thisBinding = isBind ? thisArg : this, |
||
| 5191 | fn = isBindKey ? thisBinding[func] : func; |
||
| 5192 | |||
| 5193 | length = args.length; |
||
| 5194 | if (argPos) {
|
||
| 5195 | args = reorder(args, argPos); |
||
| 5196 | } else if (isFlip && length > 1) { |
||
| 5197 | args.reverse(); |
||
| 5198 | } |
||
| 5199 | if (isAry && ary < length) {
|
||
| 5200 | args.length = ary; |
||
| 5201 | } |
||
| 5202 | if (this && this !== root && this instanceof wrapper) { |
||
| 5203 | fn = Ctor || createCtor(fn); |
||
| 5204 | } |
||
| 5205 | return fn.apply(thisBinding, args);
|
||
| 5206 | } |
||
| 5207 | return wrapper;
|
||
| 5208 | } |
||
| 5209 | |||
| 5210 | /**
|
||
| 5211 | * Creates a function like `_.invertBy`.
|
||
| 5212 | *
|
||
| 5213 | * @private
|
||
| 5214 | * @param {Function} setter The function to set accumulator values.
|
||
| 5215 | * @param {Function} toIteratee The function to resolve iteratees.
|
||
| 5216 | * @returns {Function} Returns the new inverter function.
|
||
| 5217 | */
|
||
| 5218 | function createInverter(setter, toIteratee) { |
||
| 5219 | return function(object, iteratee) { |
||
| 5220 | return baseInverter(object, setter, toIteratee(iteratee), {});
|
||
| 5221 | }; |
||
| 5222 | } |
||
| 5223 | |||
| 5224 | /**
|
||
| 5225 | * Creates a function that performs a mathematical operation on two values.
|
||
| 5226 | *
|
||
| 5227 | * @private
|
||
| 5228 | * @param {Function} operator The function to perform the operation.
|
||
| 5229 | * @param {number} [defaultValue] The value used for `undefined` arguments.
|
||
| 5230 | * @returns {Function} Returns the new mathematical operation function.
|
||
| 5231 | */
|
||
| 5232 | function createMathOperation(operator, defaultValue) { |
||
| 5233 | return function(value, other) { |
||
| 5234 | var result;
|
||
| 5235 | if (value === undefined && other === undefined) { |
||
| 5236 | return defaultValue;
|
||
| 5237 | } |
||
| 5238 | if (value !== undefined) { |
||
| 5239 | result = value; |
||
| 5240 | } |
||
| 5241 | if (other !== undefined) { |
||
| 5242 | if (result === undefined) { |
||
| 5243 | return other;
|
||
| 5244 | } |
||
| 5245 | if (typeof value == 'string' || typeof other == 'string') { |
||
| 5246 | value = baseToString(value); |
||
| 5247 | other = baseToString(other); |
||
| 5248 | } else {
|
||
| 5249 | value = baseToNumber(value); |
||
| 5250 | other = baseToNumber(other); |
||
| 5251 | } |
||
| 5252 | result = operator(value, other); |
||
| 5253 | } |
||
| 5254 | return result;
|
||
| 5255 | }; |
||
| 5256 | } |
||
| 5257 | |||
| 5258 | /**
|
||
| 5259 | * Creates a function like `_.over`.
|
||
| 5260 | *
|
||
| 5261 | * @private
|
||
| 5262 | * @param {Function} arrayFunc The function to iterate over iteratees.
|
||
| 5263 | * @returns {Function} Returns the new over function.
|
||
| 5264 | */
|
||
| 5265 | function createOver(arrayFunc) { |
||
| 5266 | return flatRest(function(iteratees) { |
||
| 5267 | iteratees = arrayMap(iteratees, baseUnary(getIteratee())); |
||
| 5268 | return baseRest(function(args) { |
||
| 5269 | var thisArg = this; |
||
| 5270 | return arrayFunc(iteratees, function(iteratee) { |
||
| 5271 | return apply(iteratee, thisArg, args);
|
||
| 5272 | }); |
||
| 5273 | }); |
||
| 5274 | }); |
||
| 5275 | } |
||
| 5276 | |||
| 5277 | /**
|
||
| 5278 | * Creates the padding for `string` based on `length`. The `chars` string
|
||
| 5279 | * is truncated if the number of characters exceeds `length`.
|
||
| 5280 | *
|
||
| 5281 | * @private
|
||
| 5282 | * @param {number} length The padding length.
|
||
| 5283 | * @param {string} [chars=' '] The string used as padding.
|
||
| 5284 | * @returns {string} Returns the padding for `string`.
|
||
| 5285 | */
|
||
| 5286 | function createPadding(length, chars) { |
||
| 5287 | chars = chars === undefined ? ' ' : baseToString(chars); |
||
| 5288 | |||
| 5289 | var charsLength = chars.length;
|
||
| 5290 | if (charsLength < 2) { |
||
| 5291 | return charsLength ? baseRepeat(chars, length) : chars;
|
||
| 5292 | } |
||
| 5293 | var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
|
||
| 5294 | return hasUnicode(chars)
|
||
| 5295 | ? castSlice(stringToArray(result), 0, length).join('') |
||
| 5296 | : result.slice(0, length);
|
||
| 5297 | } |
||
| 5298 | |||
| 5299 | /**
|
||
| 5300 | * Creates a function that wraps `func` to invoke it with the `this` binding
|
||
| 5301 | * of `thisArg` and `partials` prepended to the arguments it receives.
|
||
| 5302 | *
|
||
| 5303 | * @private
|
||
| 5304 | * @param {Function} func The function to wrap.
|
||
| 5305 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||
| 5306 | * @param {*} thisArg The `this` binding of `func`.
|
||
| 5307 | * @param {Array} partials The arguments to prepend to those provided to
|
||
| 5308 | * the new function.
|
||
| 5309 | * @returns {Function} Returns the new wrapped function.
|
||
| 5310 | */
|
||
| 5311 | function createPartial(func, bitmask, thisArg, partials) { |
||
| 5312 | var isBind = bitmask & WRAP_BIND_FLAG,
|
||
| 5313 | Ctor = createCtor(func); |
||
| 5314 | |||
| 5315 | function wrapper() { |
||
| 5316 | var argsIndex = -1, |
||
| 5317 | argsLength = arguments.length,
|
||
| 5318 | leftIndex = -1,
|
||
| 5319 | leftLength = partials.length, |
||
| 5320 | args = Array(leftLength + argsLength), |
||
| 5321 | fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; |
||
| 5322 | |||
| 5323 | while (++leftIndex < leftLength) {
|
||
| 5324 | args[leftIndex] = partials[leftIndex]; |
||
| 5325 | } |
||
| 5326 | while (argsLength--) {
|
||
| 5327 | args[leftIndex++] = arguments[++argsIndex];
|
||
| 5328 | } |
||
| 5329 | return apply(fn, isBind ? thisArg : this, args); |
||
| 5330 | } |
||
| 5331 | return wrapper;
|
||
| 5332 | } |
||
| 5333 | |||
| 5334 | /**
|
||
| 5335 | * Creates a `_.range` or `_.rangeRight` function.
|
||
| 5336 | *
|
||
| 5337 | * @private
|
||
| 5338 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
||
| 5339 | * @returns {Function} Returns the new range function.
|
||
| 5340 | */
|
||
| 5341 | function createRange(fromRight) { |
||
| 5342 | return function(start, end, step) { |
||
| 5343 | if (step && typeof step != 'number' && isIterateeCall(start, end, step)) { |
||
| 5344 | end = step = undefined;
|
||
| 5345 | } |
||
| 5346 | // Ensure the sign of `-0` is preserved.
|
||
| 5347 | start = toFinite(start); |
||
| 5348 | if (end === undefined) { |
||
| 5349 | end = start; |
||
| 5350 | start = 0;
|
||
| 5351 | } else {
|
||
| 5352 | end = toFinite(end); |
||
| 5353 | } |
||
| 5354 | step = step === undefined ? (start < end ? 1 : -1) : toFinite(step); |
||
| 5355 | return baseRange(start, end, step, fromRight);
|
||
| 5356 | }; |
||
| 5357 | } |
||
| 5358 | |||
| 5359 | /**
|
||
| 5360 | * Creates a function that performs a relational operation on two values.
|
||
| 5361 | *
|
||
| 5362 | * @private
|
||
| 5363 | * @param {Function} operator The function to perform the operation.
|
||
| 5364 | * @returns {Function} Returns the new relational operation function.
|
||
| 5365 | */
|
||
| 5366 | function createRelationalOperation(operator) { |
||
| 5367 | return function(value, other) { |
||
| 5368 | if (!(typeof value == 'string' && typeof other == 'string')) { |
||
| 5369 | value = toNumber(value); |
||
| 5370 | other = toNumber(other); |
||
| 5371 | } |
||
| 5372 | return operator(value, other);
|
||
| 5373 | }; |
||
| 5374 | } |
||
| 5375 | |||
| 5376 | /**
|
||
| 5377 | * Creates a function that wraps `func` to continue currying.
|
||
| 5378 | *
|
||
| 5379 | * @private
|
||
| 5380 | * @param {Function} func The function to wrap.
|
||
| 5381 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||
| 5382 | * @param {Function} wrapFunc The function to create the `func` wrapper.
|
||
| 5383 | * @param {*} placeholder The placeholder value.
|
||
| 5384 | * @param {*} [thisArg] The `this` binding of `func`.
|
||
| 5385 | * @param {Array} [partials] The arguments to prepend to those provided to
|
||
| 5386 | * the new function.
|
||
| 5387 | * @param {Array} [holders] The `partials` placeholder indexes.
|
||
| 5388 | * @param {Array} [argPos] The argument positions of the new function.
|
||
| 5389 | * @param {number} [ary] The arity cap of `func`.
|
||
| 5390 | * @param {number} [arity] The arity of `func`.
|
||
| 5391 | * @returns {Function} Returns the new wrapped function.
|
||
| 5392 | */
|
||
| 5393 | function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { |
||
| 5394 | var isCurry = bitmask & WRAP_CURRY_FLAG,
|
||
| 5395 | newHolders = isCurry ? holders : undefined,
|
||
| 5396 | newHoldersRight = isCurry ? undefined : holders,
|
||
| 5397 | newPartials = isCurry ? partials : undefined,
|
||
| 5398 | newPartialsRight = isCurry ? undefined : partials;
|
||
| 5399 | |||
| 5400 | bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); |
||
| 5401 | bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); |
||
| 5402 | |||
| 5403 | if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
|
||
| 5404 | bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG); |
||
| 5405 | } |
||
| 5406 | var newData = [
|
||
| 5407 | func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, |
||
| 5408 | newHoldersRight, argPos, ary, arity |
||
| 5409 | ]; |
||
| 5410 | |||
| 5411 | var result = wrapFunc.apply(undefined, newData); |
||
| 5412 | if (isLaziable(func)) {
|
||
| 5413 | setData(result, newData); |
||
| 5414 | } |
||
| 5415 | result.placeholder = placeholder; |
||
| 5416 | return setWrapToString(result, func, bitmask);
|
||
| 5417 | } |
||
| 5418 | |||
| 5419 | /**
|
||
| 5420 | * Creates a function like `_.round`.
|
||
| 5421 | *
|
||
| 5422 | * @private
|
||
| 5423 | * @param {string} methodName The name of the `Math` method to use when rounding.
|
||
| 5424 | * @returns {Function} Returns the new round function.
|
||
| 5425 | */
|
||
| 5426 | function createRound(methodName) { |
||
| 5427 | var func = Math[methodName];
|
||
| 5428 | return function(number, precision) { |
||
| 5429 | number = toNumber(number); |
||
| 5430 | precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); |
||
| 5431 | if (precision) {
|
||
| 5432 | // Shift with exponential notation to avoid floating-point issues.
|
||
| 5433 | // See [MDN](https://mdn.io/round#Examples) for more details.
|
||
| 5434 | var pair = (toString(number) + 'e').split('e'), |
||
| 5435 | value = func(pair[0] + 'e' + (+pair[1] + precision)); |
||
| 5436 | |||
| 5437 | pair = (toString(value) + 'e').split('e'); |
||
| 5438 | return +(pair[0] + 'e' + (+pair[1] - precision)); |
||
| 5439 | } |
||
| 5440 | return func(number);
|
||
| 5441 | }; |
||
| 5442 | } |
||
| 5443 | |||
| 5444 | /**
|
||
| 5445 | * Creates a set object of `values`.
|
||
| 5446 | *
|
||
| 5447 | * @private
|
||
| 5448 | * @param {Array} values The values to add to the set.
|
||
| 5449 | * @returns {Object} Returns the new set.
|
||
| 5450 | */
|
||
| 5451 | var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { |
||
| 5452 | return new Set(values); |
||
| 5453 | }; |
||
| 5454 | |||
| 5455 | /**
|
||
| 5456 | * Creates a `_.toPairs` or `_.toPairsIn` function.
|
||
| 5457 | *
|
||
| 5458 | * @private
|
||
| 5459 | * @param {Function} keysFunc The function to get the keys of a given object.
|
||
| 5460 | * @returns {Function} Returns the new pairs function.
|
||
| 5461 | */
|
||
| 5462 | function createToPairs(keysFunc) { |
||
| 5463 | return function(object) { |
||
| 5464 | var tag = getTag(object);
|
||
| 5465 | if (tag == mapTag) {
|
||
| 5466 | return mapToArray(object);
|
||
| 5467 | } |
||
| 5468 | if (tag == setTag) {
|
||
| 5469 | return setToPairs(object);
|
||
| 5470 | } |
||
| 5471 | return baseToPairs(object, keysFunc(object));
|
||
| 5472 | }; |
||
| 5473 | } |
||
| 5474 | |||
| 5475 | /**
|
||
| 5476 | * Creates a function that either curries or invokes `func` with optional
|
||
| 5477 | * `this` binding and partially applied arguments.
|
||
| 5478 | *
|
||
| 5479 | * @private
|
||
| 5480 | * @param {Function|string} func The function or method name to wrap.
|
||
| 5481 | * @param {number} bitmask The bitmask flags.
|
||
| 5482 | * 1 - `_.bind`
|
||
| 5483 | * 2 - `_.bindKey`
|
||
| 5484 | * 4 - `_.curry` or `_.curryRight` of a bound function
|
||
| 5485 | * 8 - `_.curry`
|
||
| 5486 | * 16 - `_.curryRight`
|
||
| 5487 | * 32 - `_.partial`
|
||
| 5488 | * 64 - `_.partialRight`
|
||
| 5489 | * 128 - `_.rearg`
|
||
| 5490 | * 256 - `_.ary`
|
||
| 5491 | * 512 - `_.flip`
|
||
| 5492 | * @param {*} [thisArg] The `this` binding of `func`.
|
||
| 5493 | * @param {Array} [partials] The arguments to be partially applied.
|
||
| 5494 | * @param {Array} [holders] The `partials` placeholder indexes.
|
||
| 5495 | * @param {Array} [argPos] The argument positions of the new function.
|
||
| 5496 | * @param {number} [ary] The arity cap of `func`.
|
||
| 5497 | * @param {number} [arity] The arity of `func`.
|
||
| 5498 | * @returns {Function} Returns the new wrapped function.
|
||
| 5499 | */
|
||
| 5500 | function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { |
||
| 5501 | var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
|
||
| 5502 | if (!isBindKey && typeof func != 'function') { |
||
| 5503 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 5504 | } |
||
| 5505 | var length = partials ? partials.length : 0; |
||
| 5506 | if (!length) {
|
||
| 5507 | bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG); |
||
| 5508 | partials = holders = undefined;
|
||
| 5509 | } |
||
| 5510 | ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0); |
||
| 5511 | arity = arity === undefined ? arity : toInteger(arity);
|
||
| 5512 | length -= holders ? holders.length : 0;
|
||
| 5513 | |||
| 5514 | if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
|
||
| 5515 | var partialsRight = partials,
|
||
| 5516 | holdersRight = holders; |
||
| 5517 | |||
| 5518 | partials = holders = undefined;
|
||
| 5519 | } |
||
| 5520 | var data = isBindKey ? undefined : getData(func); |
||
| 5521 | |||
| 5522 | var newData = [
|
||
| 5523 | func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, |
||
| 5524 | argPos, ary, arity |
||
| 5525 | ]; |
||
| 5526 | |||
| 5527 | if (data) {
|
||
| 5528 | mergeData(newData, data); |
||
| 5529 | } |
||
| 5530 | func = newData[0];
|
||
| 5531 | bitmask = newData[1];
|
||
| 5532 | thisArg = newData[2];
|
||
| 5533 | partials = newData[3];
|
||
| 5534 | holders = newData[4];
|
||
| 5535 | arity = newData[9] = newData[9] === undefined |
||
| 5536 | ? (isBindKey ? 0 : func.length)
|
||
| 5537 | : nativeMax(newData[9] - length, 0); |
||
| 5538 | |||
| 5539 | if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
|
||
| 5540 | bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG); |
||
| 5541 | } |
||
| 5542 | if (!bitmask || bitmask == WRAP_BIND_FLAG) {
|
||
| 5543 | var result = createBind(func, bitmask, thisArg);
|
||
| 5544 | } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) { |
||
| 5545 | result = createCurry(func, bitmask, arity); |
||
| 5546 | } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) { |
||
| 5547 | result = createPartial(func, bitmask, thisArg, partials); |
||
| 5548 | } else {
|
||
| 5549 | result = createHybrid.apply(undefined, newData);
|
||
| 5550 | } |
||
| 5551 | var setter = data ? baseSetData : setData;
|
||
| 5552 | return setWrapToString(setter(result, newData), func, bitmask);
|
||
| 5553 | } |
||
| 5554 | |||
| 5555 | /**
|
||
| 5556 | * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
|
||
| 5557 | * of source objects to the destination object for all destination properties
|
||
| 5558 | * that resolve to `undefined`.
|
||
| 5559 | *
|
||
| 5560 | * @private
|
||
| 5561 | * @param {*} objValue The destination value.
|
||
| 5562 | * @param {*} srcValue The source value.
|
||
| 5563 | * @param {string} key The key of the property to assign.
|
||
| 5564 | * @param {Object} object The parent object of `objValue`.
|
||
| 5565 | * @returns {*} Returns the value to assign.
|
||
| 5566 | */
|
||
| 5567 | function customDefaultsAssignIn(objValue, srcValue, key, object) { |
||
| 5568 | if (objValue === undefined || |
||
| 5569 | (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
||
| 5570 | return srcValue;
|
||
| 5571 | } |
||
| 5572 | return objValue;
|
||
| 5573 | } |
||
| 5574 | |||
| 5575 | /**
|
||
| 5576 | * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
|
||
| 5577 | * objects into destination objects that are passed thru.
|
||
| 5578 | *
|
||
| 5579 | * @private
|
||
| 5580 | * @param {*} objValue The destination value.
|
||
| 5581 | * @param {*} srcValue The source value.
|
||
| 5582 | * @param {string} key The key of the property to merge.
|
||
| 5583 | * @param {Object} object The parent object of `objValue`.
|
||
| 5584 | * @param {Object} source The parent object of `srcValue`.
|
||
| 5585 | * @param {Object} [stack] Tracks traversed source values and their merged
|
||
| 5586 | * counterparts.
|
||
| 5587 | * @returns {*} Returns the value to assign.
|
||
| 5588 | */
|
||
| 5589 | function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { |
||
| 5590 | if (isObject(objValue) && isObject(srcValue)) {
|
||
| 5591 | // Recursively merge objects and arrays (susceptible to call stack limits).
|
||
| 5592 | stack.set(srcValue, objValue); |
||
| 5593 | baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
|
||
| 5594 | stack['delete'](srcValue);
|
||
| 5595 | } |
||
| 5596 | return objValue;
|
||
| 5597 | } |
||
| 5598 | |||
| 5599 | /**
|
||
| 5600 | * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
|
||
| 5601 | * objects.
|
||
| 5602 | *
|
||
| 5603 | * @private
|
||
| 5604 | * @param {*} value The value to inspect.
|
||
| 5605 | * @param {string} key The key of the property to inspect.
|
||
| 5606 | * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
|
||
| 5607 | */
|
||
| 5608 | function customOmitClone(value) { |
||
| 5609 | return isPlainObject(value) ? undefined : value; |
||
| 5610 | } |
||
| 5611 | |||
| 5612 | /**
|
||
| 5613 | * A specialized version of `baseIsEqualDeep` for arrays with support for
|
||
| 5614 | * partial deep comparisons.
|
||
| 5615 | *
|
||
| 5616 | * @private
|
||
| 5617 | * @param {Array} array The array to compare.
|
||
| 5618 | * @param {Array} other The other array to compare.
|
||
| 5619 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
||
| 5620 | * @param {Function} customizer The function to customize comparisons.
|
||
| 5621 | * @param {Function} equalFunc The function to determine equivalents of values.
|
||
| 5622 | * @param {Object} stack Tracks traversed `array` and `other` objects.
|
||
| 5623 | * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
|
||
| 5624 | */
|
||
| 5625 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { |
||
| 5626 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
||
| 5627 | arrLength = array.length, |
||
| 5628 | othLength = other.length; |
||
| 5629 | |||
| 5630 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
||
| 5631 | return false; |
||
| 5632 | } |
||
| 5633 | // Assume cyclic values are equal.
|
||
| 5634 | var stacked = stack.get(array);
|
||
| 5635 | if (stacked && stack.get(other)) {
|
||
| 5636 | return stacked == other;
|
||
| 5637 | } |
||
| 5638 | var index = -1, |
||
| 5639 | result = true,
|
||
| 5640 | seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined; |
||
| 5641 | |||
| 5642 | stack.set(array, other); |
||
| 5643 | stack.set(other, array); |
||
| 5644 | |||
| 5645 | // Ignore non-index properties.
|
||
| 5646 | while (++index < arrLength) {
|
||
| 5647 | var arrValue = array[index],
|
||
| 5648 | othValue = other[index]; |
||
| 5649 | |||
| 5650 | if (customizer) {
|
||
| 5651 | var compared = isPartial
|
||
| 5652 | ? customizer(othValue, arrValue, index, other, array, stack) |
||
| 5653 | : customizer(arrValue, othValue, index, array, other, stack); |
||
| 5654 | } |
||
| 5655 | if (compared !== undefined) { |
||
| 5656 | if (compared) {
|
||
| 5657 | continue;
|
||
| 5658 | } |
||
| 5659 | result = false;
|
||
| 5660 | break;
|
||
| 5661 | } |
||
| 5662 | // Recursively compare arrays (susceptible to call stack limits).
|
||
| 5663 | if (seen) {
|
||
| 5664 | if (!arraySome(other, function(othValue, othIndex) { |
||
| 5665 | if (!cacheHas(seen, othIndex) &&
|
||
| 5666 | (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
||
| 5667 | return seen.push(othIndex);
|
||
| 5668 | } |
||
| 5669 | })) {
|
||
| 5670 | result = false;
|
||
| 5671 | break;
|
||
| 5672 | } |
||
| 5673 | } else if (!( |
||
| 5674 | arrValue === othValue || |
||
| 5675 | equalFunc(arrValue, othValue, bitmask, customizer, stack) |
||
| 5676 | )) {
|
||
| 5677 | result = false;
|
||
| 5678 | break;
|
||
| 5679 | } |
||
| 5680 | } |
||
| 5681 | stack['delete'](array);
|
||
| 5682 | stack['delete'](other);
|
||
| 5683 | return result;
|
||
| 5684 | } |
||
| 5685 | |||
| 5686 | /**
|
||
| 5687 | * A specialized version of `baseIsEqualDeep` for comparing objects of
|
||
| 5688 | * the same `toStringTag`.
|
||
| 5689 | *
|
||
| 5690 | * **Note:** This function only supports comparing values with tags of
|
||
| 5691 | * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
||
| 5692 | *
|
||
| 5693 | * @private
|
||
| 5694 | * @param {Object} object The object to compare.
|
||
| 5695 | * @param {Object} other The other object to compare.
|
||
| 5696 | * @param {string} tag The `toStringTag` of the objects to compare.
|
||
| 5697 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
||
| 5698 | * @param {Function} customizer The function to customize comparisons.
|
||
| 5699 | * @param {Function} equalFunc The function to determine equivalents of values.
|
||
| 5700 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
||
| 5701 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
||
| 5702 | */
|
||
| 5703 | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { |
||
| 5704 | switch (tag) {
|
||
| 5705 | case dataViewTag:
|
||
| 5706 | if ((object.byteLength != other.byteLength) ||
|
||
| 5707 | (object.byteOffset != other.byteOffset)) {
|
||
| 5708 | return false; |
||
| 5709 | } |
||
| 5710 | object = object.buffer; |
||
| 5711 | other = other.buffer; |
||
| 5712 | |||
| 5713 | case arrayBufferTag:
|
||
| 5714 | if ((object.byteLength != other.byteLength) ||
|
||
| 5715 | !equalFunc(new Uint8Array(object), new Uint8Array(other))) { |
||
| 5716 | return false; |
||
| 5717 | } |
||
| 5718 | return true; |
||
| 5719 | |||
| 5720 | case boolTag:
|
||
| 5721 | case dateTag:
|
||
| 5722 | case numberTag:
|
||
| 5723 | // Coerce booleans to `1` or `0` and dates to milliseconds.
|
||
| 5724 | // Invalid dates are coerced to `NaN`.
|
||
| 5725 | return eq(+object, +other);
|
||
| 5726 | |||
| 5727 | case errorTag:
|
||
| 5728 | return object.name == other.name && object.message == other.message;
|
||
| 5729 | |||
| 5730 | case regexpTag:
|
||
| 5731 | case stringTag:
|
||
| 5732 | // Coerce regexes to strings and treat strings, primitives and objects,
|
||
| 5733 | // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
|
||
| 5734 | // for more details.
|
||
| 5735 | return object == (other + ''); |
||
| 5736 | |||
| 5737 | case mapTag:
|
||
| 5738 | var convert = mapToArray;
|
||
| 5739 | |||
| 5740 | case setTag:
|
||
| 5741 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
|
||
| 5742 | convert || (convert = setToArray); |
||
| 5743 | |||
| 5744 | if (object.size != other.size && !isPartial) {
|
||
| 5745 | return false; |
||
| 5746 | } |
||
| 5747 | // Assume cyclic values are equal.
|
||
| 5748 | var stacked = stack.get(object);
|
||
| 5749 | if (stacked) {
|
||
| 5750 | return stacked == other;
|
||
| 5751 | } |
||
| 5752 | bitmask |= COMPARE_UNORDERED_FLAG; |
||
| 5753 | |||
| 5754 | // Recursively compare objects (susceptible to call stack limits).
|
||
| 5755 | stack.set(object, other); |
||
| 5756 | var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
|
||
| 5757 | stack['delete'](object);
|
||
| 5758 | return result;
|
||
| 5759 | |||
| 5760 | case symbolTag:
|
||
| 5761 | if (symbolValueOf) {
|
||
| 5762 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
||
| 5763 | } |
||
| 5764 | } |
||
| 5765 | return false; |
||
| 5766 | } |
||
| 5767 | |||
| 5768 | /**
|
||
| 5769 | * A specialized version of `baseIsEqualDeep` for objects with support for
|
||
| 5770 | * partial deep comparisons.
|
||
| 5771 | *
|
||
| 5772 | * @private
|
||
| 5773 | * @param {Object} object The object to compare.
|
||
| 5774 | * @param {Object} other The other object to compare.
|
||
| 5775 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
||
| 5776 | * @param {Function} customizer The function to customize comparisons.
|
||
| 5777 | * @param {Function} equalFunc The function to determine equivalents of values.
|
||
| 5778 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
||
| 5779 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
||
| 5780 | */
|
||
| 5781 | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { |
||
| 5782 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
||
| 5783 | objProps = getAllKeys(object), |
||
| 5784 | objLength = objProps.length, |
||
| 5785 | othProps = getAllKeys(other), |
||
| 5786 | othLength = othProps.length; |
||
| 5787 | |||
| 5788 | if (objLength != othLength && !isPartial) {
|
||
| 5789 | return false; |
||
| 5790 | } |
||
| 5791 | var index = objLength;
|
||
| 5792 | while (index--) {
|
||
| 5793 | var key = objProps[index];
|
||
| 5794 | if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { |
||
| 5795 | return false; |
||
| 5796 | } |
||
| 5797 | } |
||
| 5798 | // Assume cyclic values are equal.
|
||
| 5799 | var stacked = stack.get(object);
|
||
| 5800 | if (stacked && stack.get(other)) {
|
||
| 5801 | return stacked == other;
|
||
| 5802 | } |
||
| 5803 | var result = true; |
||
| 5804 | stack.set(object, other); |
||
| 5805 | stack.set(other, object); |
||
| 5806 | |||
| 5807 | var skipCtor = isPartial;
|
||
| 5808 | while (++index < objLength) {
|
||
| 5809 | key = objProps[index]; |
||
| 5810 | var objValue = object[key],
|
||
| 5811 | othValue = other[key]; |
||
| 5812 | |||
| 5813 | if (customizer) {
|
||
| 5814 | var compared = isPartial
|
||
| 5815 | ? customizer(othValue, objValue, key, other, object, stack) |
||
| 5816 | : customizer(objValue, othValue, key, object, other, stack); |
||
| 5817 | } |
||
| 5818 | // Recursively compare objects (susceptible to call stack limits).
|
||
| 5819 | if (!(compared === undefined |
||
| 5820 | ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) |
||
| 5821 | : compared |
||
| 5822 | )) {
|
||
| 5823 | result = false;
|
||
| 5824 | break;
|
||
| 5825 | } |
||
| 5826 | skipCtor || (skipCtor = key == 'constructor');
|
||
| 5827 | } |
||
| 5828 | if (result && !skipCtor) {
|
||
| 5829 | var objCtor = object.constructor,
|
||
| 5830 | othCtor = other.constructor; |
||
| 5831 | |||
| 5832 | // Non `Object` object instances with different constructors are not equal.
|
||
| 5833 | if (objCtor != othCtor &&
|
||
| 5834 | ('constructor' in object && 'constructor' in other) && |
||
| 5835 | !(typeof objCtor == 'function' && objCtor instanceof objCtor && |
||
| 5836 | typeof othCtor == 'function' && othCtor instanceof othCtor)) { |
||
| 5837 | result = false;
|
||
| 5838 | } |
||
| 5839 | } |
||
| 5840 | stack['delete'](object);
|
||
| 5841 | stack['delete'](other);
|
||
| 5842 | return result;
|
||
| 5843 | } |
||
| 5844 | |||
| 5845 | /**
|
||
| 5846 | * A specialized version of `baseRest` which flattens the rest array.
|
||
| 5847 | *
|
||
| 5848 | * @private
|
||
| 5849 | * @param {Function} func The function to apply a rest parameter to.
|
||
| 5850 | * @returns {Function} Returns the new function.
|
||
| 5851 | */
|
||
| 5852 | function flatRest(func) { |
||
| 5853 | return setToString(overRest(func, undefined, flatten), func + ''); |
||
| 5854 | } |
||
| 5855 | |||
| 5856 | /**
|
||
| 5857 | * Creates an array of own enumerable property names and symbols of `object`.
|
||
| 5858 | *
|
||
| 5859 | * @private
|
||
| 5860 | * @param {Object} object The object to query.
|
||
| 5861 | * @returns {Array} Returns the array of property names and symbols.
|
||
| 5862 | */
|
||
| 5863 | function getAllKeys(object) { |
||
| 5864 | return baseGetAllKeys(object, keys, getSymbols);
|
||
| 5865 | } |
||
| 5866 | |||
| 5867 | /**
|
||
| 5868 | * Creates an array of own and inherited enumerable property names and
|
||
| 5869 | * symbols of `object`.
|
||
| 5870 | *
|
||
| 5871 | * @private
|
||
| 5872 | * @param {Object} object The object to query.
|
||
| 5873 | * @returns {Array} Returns the array of property names and symbols.
|
||
| 5874 | */
|
||
| 5875 | function getAllKeysIn(object) { |
||
| 5876 | return baseGetAllKeys(object, keysIn, getSymbolsIn);
|
||
| 5877 | } |
||
| 5878 | |||
| 5879 | /**
|
||
| 5880 | * Gets metadata for `func`.
|
||
| 5881 | *
|
||
| 5882 | * @private
|
||
| 5883 | * @param {Function} func The function to query.
|
||
| 5884 | * @returns {*} Returns the metadata for `func`.
|
||
| 5885 | */
|
||
| 5886 | var getData = !metaMap ? noop : function(func) { |
||
| 5887 | return metaMap.get(func);
|
||
| 5888 | }; |
||
| 5889 | |||
| 5890 | /**
|
||
| 5891 | * Gets the name of `func`.
|
||
| 5892 | *
|
||
| 5893 | * @private
|
||
| 5894 | * @param {Function} func The function to query.
|
||
| 5895 | * @returns {string} Returns the function name.
|
||
| 5896 | */
|
||
| 5897 | function getFuncName(func) { |
||
| 5898 | var result = (func.name + ''), |
||
| 5899 | array = realNames[result], |
||
| 5900 | length = hasOwnProperty.call(realNames, result) ? array.length : 0;
|
||
| 5901 | |||
| 5902 | while (length--) {
|
||
| 5903 | var data = array[length],
|
||
| 5904 | otherFunc = data.func; |
||
| 5905 | if (otherFunc == null || otherFunc == func) { |
||
| 5906 | return data.name;
|
||
| 5907 | } |
||
| 5908 | } |
||
| 5909 | return result;
|
||
| 5910 | } |
||
| 5911 | |||
| 5912 | /**
|
||
| 5913 | * Gets the argument placeholder value for `func`.
|
||
| 5914 | *
|
||
| 5915 | * @private
|
||
| 5916 | * @param {Function} func The function to inspect.
|
||
| 5917 | * @returns {*} Returns the placeholder value.
|
||
| 5918 | */
|
||
| 5919 | function getHolder(func) { |
||
| 5920 | var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func; |
||
| 5921 | return object.placeholder;
|
||
| 5922 | } |
||
| 5923 | |||
| 5924 | /**
|
||
| 5925 | * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
|
||
| 5926 | * this function returns the custom method, otherwise it returns `baseIteratee`.
|
||
| 5927 | * If arguments are provided, the chosen function is invoked with them and
|
||
| 5928 | * its result is returned.
|
||
| 5929 | *
|
||
| 5930 | * @private
|
||
| 5931 | * @param {*} [value] The value to convert to an iteratee.
|
||
| 5932 | * @param {number} [arity] The arity of the created iteratee.
|
||
| 5933 | * @returns {Function} Returns the chosen function or its result.
|
||
| 5934 | */
|
||
| 5935 | function getIteratee() { |
||
| 5936 | var result = lodash.iteratee || iteratee;
|
||
| 5937 | result = result === iteratee ? baseIteratee : result; |
||
| 5938 | return arguments.length ? result(arguments[0], arguments[1]) : result; |
||
| 5939 | } |
||
| 5940 | |||
| 5941 | /**
|
||
| 5942 | * Gets the data for `map`.
|
||
| 5943 | *
|
||
| 5944 | * @private
|
||
| 5945 | * @param {Object} map The map to query.
|
||
| 5946 | * @param {string} key The reference key.
|
||
| 5947 | * @returns {*} Returns the map data.
|
||
| 5948 | */
|
||
| 5949 | function getMapData(map, key) { |
||
| 5950 | var data = map.__data__;
|
||
| 5951 | return isKeyable(key)
|
||
| 5952 | ? data[typeof key == 'string' ? 'string' : 'hash'] |
||
| 5953 | : data.map; |
||
| 5954 | } |
||
| 5955 | |||
| 5956 | /**
|
||
| 5957 | * Gets the property names, values, and compare flags of `object`.
|
||
| 5958 | *
|
||
| 5959 | * @private
|
||
| 5960 | * @param {Object} object The object to query.
|
||
| 5961 | * @returns {Array} Returns the match data of `object`.
|
||
| 5962 | */
|
||
| 5963 | function getMatchData(object) { |
||
| 5964 | var result = keys(object),
|
||
| 5965 | length = result.length; |
||
| 5966 | |||
| 5967 | while (length--) {
|
||
| 5968 | var key = result[length],
|
||
| 5969 | value = object[key]; |
||
| 5970 | |||
| 5971 | result[length] = [key, value, isStrictComparable(value)]; |
||
| 5972 | } |
||
| 5973 | return result;
|
||
| 5974 | } |
||
| 5975 | |||
| 5976 | /**
|
||
| 5977 | * Gets the native function at `key` of `object`.
|
||
| 5978 | *
|
||
| 5979 | * @private
|
||
| 5980 | * @param {Object} object The object to query.
|
||
| 5981 | * @param {string} key The key of the method to get.
|
||
| 5982 | * @returns {*} Returns the function if it's native, else `undefined`.
|
||
| 5983 | */
|
||
| 5984 | function getNative(object, key) { |
||
| 5985 | var value = getValue(object, key);
|
||
| 5986 | return baseIsNative(value) ? value : undefined; |
||
| 5987 | } |
||
| 5988 | |||
| 5989 | /**
|
||
| 5990 | * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
||
| 5991 | *
|
||
| 5992 | * @private
|
||
| 5993 | * @param {*} value The value to query.
|
||
| 5994 | * @returns {string} Returns the raw `toStringTag`.
|
||
| 5995 | */
|
||
| 5996 | function getRawTag(value) { |
||
| 5997 | var isOwn = hasOwnProperty.call(value, symToStringTag),
|
||
| 5998 | tag = value[symToStringTag]; |
||
| 5999 | |||
| 6000 | try {
|
||
| 6001 | value[symToStringTag] = undefined;
|
||
| 6002 | var unmasked = true; |
||
| 6003 | } catch (e) {}
|
||
| 6004 | |||
| 6005 | var result = nativeObjectToString.call(value);
|
||
| 6006 | if (unmasked) {
|
||
| 6007 | if (isOwn) {
|
||
| 6008 | value[symToStringTag] = tag; |
||
| 6009 | } else {
|
||
| 6010 | delete value[symToStringTag];
|
||
| 6011 | } |
||
| 6012 | } |
||
| 6013 | return result;
|
||
| 6014 | } |
||
| 6015 | |||
| 6016 | /**
|
||
| 6017 | * Creates an array of the own enumerable symbols of `object`.
|
||
| 6018 | *
|
||
| 6019 | * @private
|
||
| 6020 | * @param {Object} object The object to query.
|
||
| 6021 | * @returns {Array} Returns the array of symbols.
|
||
| 6022 | */
|
||
| 6023 | var getSymbols = !nativeGetSymbols ? stubArray : function(object) { |
||
| 6024 | if (object == null) { |
||
| 6025 | return [];
|
||
| 6026 | } |
||
| 6027 | object = Object(object); |
||
| 6028 | return arrayFilter(nativeGetSymbols(object), function(symbol) { |
||
| 6029 | return propertyIsEnumerable.call(object, symbol);
|
||
| 6030 | }); |
||
| 6031 | }; |
||
| 6032 | |||
| 6033 | /**
|
||
| 6034 | * Creates an array of the own and inherited enumerable symbols of `object`.
|
||
| 6035 | *
|
||
| 6036 | * @private
|
||
| 6037 | * @param {Object} object The object to query.
|
||
| 6038 | * @returns {Array} Returns the array of symbols.
|
||
| 6039 | */
|
||
| 6040 | var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) { |
||
| 6041 | var result = [];
|
||
| 6042 | while (object) {
|
||
| 6043 | arrayPush(result, getSymbols(object)); |
||
| 6044 | object = getPrototype(object); |
||
| 6045 | } |
||
| 6046 | return result;
|
||
| 6047 | }; |
||
| 6048 | |||
| 6049 | /**
|
||
| 6050 | * Gets the `toStringTag` of `value`.
|
||
| 6051 | *
|
||
| 6052 | * @private
|
||
| 6053 | * @param {*} value The value to query.
|
||
| 6054 | * @returns {string} Returns the `toStringTag`.
|
||
| 6055 | */
|
||
| 6056 | var getTag = baseGetTag;
|
||
| 6057 | |||
| 6058 | // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
||
| 6059 | if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || |
||
| 6060 | (Map && getTag(new Map) != mapTag) ||
|
||
| 6061 | (Promise && getTag(Promise.resolve()) != promiseTag) || |
||
| 6062 | (Set && getTag(new Set) != setTag) ||
|
||
| 6063 | (WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
||
| 6064 | getTag = function(value) { |
||
| 6065 | var result = baseGetTag(value),
|
||
| 6066 | Ctor = result == objectTag ? value.constructor : undefined,
|
||
| 6067 | ctorString = Ctor ? toSource(Ctor) : '';
|
||
| 6068 | |||
| 6069 | if (ctorString) {
|
||
| 6070 | switch (ctorString) {
|
||
| 6071 | case dataViewCtorString: return dataViewTag; |
||
| 6072 | case mapCtorString: return mapTag; |
||
| 6073 | case promiseCtorString: return promiseTag; |
||
| 6074 | case setCtorString: return setTag; |
||
| 6075 | case weakMapCtorString: return weakMapTag; |
||
| 6076 | } |
||
| 6077 | } |
||
| 6078 | return result;
|
||
| 6079 | }; |
||
| 6080 | } |
||
| 6081 | |||
| 6082 | /**
|
||
| 6083 | * Gets the view, applying any `transforms` to the `start` and `end` positions.
|
||
| 6084 | *
|
||
| 6085 | * @private
|
||
| 6086 | * @param {number} start The start of the view.
|
||
| 6087 | * @param {number} end The end of the view.
|
||
| 6088 | * @param {Array} transforms The transformations to apply to the view.
|
||
| 6089 | * @returns {Object} Returns an object containing the `start` and `end`
|
||
| 6090 | * positions of the view.
|
||
| 6091 | */
|
||
| 6092 | function getView(start, end, transforms) { |
||
| 6093 | var index = -1, |
||
| 6094 | length = transforms.length; |
||
| 6095 | |||
| 6096 | while (++index < length) {
|
||
| 6097 | var data = transforms[index],
|
||
| 6098 | size = data.size; |
||
| 6099 | |||
| 6100 | switch (data.type) {
|
||
| 6101 | case 'drop': start += size; break; |
||
| 6102 | case 'dropRight': end -= size; break; |
||
| 6103 | case 'take': end = nativeMin(end, start + size); break; |
||
| 6104 | case 'takeRight': start = nativeMax(start, end - size); break; |
||
| 6105 | } |
||
| 6106 | } |
||
| 6107 | return { 'start': start, 'end': end }; |
||
| 6108 | } |
||
| 6109 | |||
| 6110 | /**
|
||
| 6111 | * Extracts wrapper details from the `source` body comment.
|
||
| 6112 | *
|
||
| 6113 | * @private
|
||
| 6114 | * @param {string} source The source to inspect.
|
||
| 6115 | * @returns {Array} Returns the wrapper details.
|
||
| 6116 | */
|
||
| 6117 | function getWrapDetails(source) { |
||
| 6118 | var match = source.match(reWrapDetails);
|
||
| 6119 | return match ? match[1].split(reSplitDetails) : []; |
||
| 6120 | } |
||
| 6121 | |||
| 6122 | /**
|
||
| 6123 | * Checks if `path` exists on `object`.
|
||
| 6124 | *
|
||
| 6125 | * @private
|
||
| 6126 | * @param {Object} object The object to query.
|
||
| 6127 | * @param {Array|string} path The path to check.
|
||
| 6128 | * @param {Function} hasFunc The function to check properties.
|
||
| 6129 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
||
| 6130 | */
|
||
| 6131 | function hasPath(object, path, hasFunc) { |
||
| 6132 | path = castPath(path, object); |
||
| 6133 | |||
| 6134 | var index = -1, |
||
| 6135 | length = path.length, |
||
| 6136 | result = false;
|
||
| 6137 | |||
| 6138 | while (++index < length) {
|
||
| 6139 | var key = toKey(path[index]);
|
||
| 6140 | if (!(result = object != null && hasFunc(object, key))) { |
||
| 6141 | break;
|
||
| 6142 | } |
||
| 6143 | object = object[key]; |
||
| 6144 | } |
||
| 6145 | if (result || ++index != length) {
|
||
| 6146 | return result;
|
||
| 6147 | } |
||
| 6148 | length = object == null ? 0 : object.length; |
||
| 6149 | return !!length && isLength(length) && isIndex(key, length) &&
|
||
| 6150 | (isArray(object) || isArguments(object)); |
||
| 6151 | } |
||
| 6152 | |||
| 6153 | /**
|
||
| 6154 | * Initializes an array clone.
|
||
| 6155 | *
|
||
| 6156 | * @private
|
||
| 6157 | * @param {Array} array The array to clone.
|
||
| 6158 | * @returns {Array} Returns the initialized clone.
|
||
| 6159 | */
|
||
| 6160 | function initCloneArray(array) { |
||
| 6161 | var length = array.length,
|
||
| 6162 | result = new array.constructor(length);
|
||
| 6163 | |||
| 6164 | // Add properties assigned by `RegExp#exec`.
|
||
| 6165 | if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { |
||
| 6166 | result.index = array.index; |
||
| 6167 | result.input = array.input; |
||
| 6168 | } |
||
| 6169 | return result;
|
||
| 6170 | } |
||
| 6171 | |||
| 6172 | /**
|
||
| 6173 | * Initializes an object clone.
|
||
| 6174 | *
|
||
| 6175 | * @private
|
||
| 6176 | * @param {Object} object The object to clone.
|
||
| 6177 | * @returns {Object} Returns the initialized clone.
|
||
| 6178 | */
|
||
| 6179 | function initCloneObject(object) { |
||
| 6180 | return (typeof object.constructor == 'function' && !isPrototype(object)) |
||
| 6181 | ? baseCreate(getPrototype(object)) |
||
| 6182 | : {};
|
||
| 6183 | } |
||
| 6184 | |||
| 6185 | /**
|
||
| 6186 | * Initializes an object clone based on its `toStringTag`.
|
||
| 6187 | *
|
||
| 6188 | * **Note:** This function only supports cloning values with tags of
|
||
| 6189 | * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
|
||
| 6190 | *
|
||
| 6191 | * @private
|
||
| 6192 | * @param {Object} object The object to clone.
|
||
| 6193 | * @param {string} tag The `toStringTag` of the object to clone.
|
||
| 6194 | * @param {boolean} [isDeep] Specify a deep clone.
|
||
| 6195 | * @returns {Object} Returns the initialized clone.
|
||
| 6196 | */
|
||
| 6197 | function initCloneByTag(object, tag, isDeep) { |
||
| 6198 | var Ctor = object.constructor;
|
||
| 6199 | switch (tag) {
|
||
| 6200 | case arrayBufferTag:
|
||
| 6201 | return cloneArrayBuffer(object);
|
||
| 6202 | |||
| 6203 | case boolTag:
|
||
| 6204 | case dateTag:
|
||
| 6205 | return new Ctor(+object); |
||
| 6206 | |||
| 6207 | case dataViewTag:
|
||
| 6208 | return cloneDataView(object, isDeep);
|
||
| 6209 | |||
| 6210 | case float32Tag: case float64Tag: |
||
| 6211 | case int8Tag: case int16Tag: case int32Tag: |
||
| 6212 | case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: |
||
| 6213 | return cloneTypedArray(object, isDeep);
|
||
| 6214 | |||
| 6215 | case mapTag:
|
||
| 6216 | return new Ctor; |
||
| 6217 | |||
| 6218 | case numberTag:
|
||
| 6219 | case stringTag:
|
||
| 6220 | return new Ctor(object); |
||
| 6221 | |||
| 6222 | case regexpTag:
|
||
| 6223 | return cloneRegExp(object);
|
||
| 6224 | |||
| 6225 | case setTag:
|
||
| 6226 | return new Ctor; |
||
| 6227 | |||
| 6228 | case symbolTag:
|
||
| 6229 | return cloneSymbol(object);
|
||
| 6230 | } |
||
| 6231 | } |
||
| 6232 | |||
| 6233 | /**
|
||
| 6234 | * Inserts wrapper `details` in a comment at the top of the `source` body.
|
||
| 6235 | *
|
||
| 6236 | * @private
|
||
| 6237 | * @param {string} source The source to modify.
|
||
| 6238 | * @returns {Array} details The details to insert.
|
||
| 6239 | * @returns {string} Returns the modified source.
|
||
| 6240 | */
|
||
| 6241 | function insertWrapDetails(source, details) { |
||
| 6242 | var length = details.length;
|
||
| 6243 | if (!length) {
|
||
| 6244 | return source;
|
||
| 6245 | } |
||
| 6246 | var lastIndex = length - 1; |
||
| 6247 | details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; |
||
| 6248 | details = details.join(length > 2 ? ', ' : ' '); |
||
| 6249 | return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); |
||
| 6250 | } |
||
| 6251 | |||
| 6252 | /**
|
||
| 6253 | * Checks if `value` is a flattenable `arguments` object or array.
|
||
| 6254 | *
|
||
| 6255 | * @private
|
||
| 6256 | * @param {*} value The value to check.
|
||
| 6257 | * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
|
||
| 6258 | */
|
||
| 6259 | function isFlattenable(value) { |
||
| 6260 | return isArray(value) || isArguments(value) ||
|
||
| 6261 | !!(spreadableSymbol && value && value[spreadableSymbol]); |
||
| 6262 | } |
||
| 6263 | |||
| 6264 | /**
|
||
| 6265 | * Checks if `value` is a valid array-like index.
|
||
| 6266 | *
|
||
| 6267 | * @private
|
||
| 6268 | * @param {*} value The value to check.
|
||
| 6269 | * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
||
| 6270 | * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
||
| 6271 | */
|
||
| 6272 | function isIndex(value, length) { |
||
| 6273 | var type = typeof value; |
||
| 6274 | length = length == null ? MAX_SAFE_INTEGER : length;
|
||
| 6275 | |||
| 6276 | return !!length &&
|
||
| 6277 | (type == 'number' ||
|
||
| 6278 | (type != 'symbol' && reIsUint.test(value))) &&
|
||
| 6279 | (value > -1 && value % 1 == 0 && value < length); |
||
| 6280 | } |
||
| 6281 | |||
| 6282 | /**
|
||
| 6283 | * Checks if the given arguments are from an iteratee call.
|
||
| 6284 | *
|
||
| 6285 | * @private
|
||
| 6286 | * @param {*} value The potential iteratee value argument.
|
||
| 6287 | * @param {*} index The potential iteratee index or key argument.
|
||
| 6288 | * @param {*} object The potential iteratee object argument.
|
||
| 6289 | * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
|
||
| 6290 | * else `false`.
|
||
| 6291 | */
|
||
| 6292 | function isIterateeCall(value, index, object) { |
||
| 6293 | if (!isObject(object)) {
|
||
| 6294 | return false; |
||
| 6295 | } |
||
| 6296 | var type = typeof index; |
||
| 6297 | if (type == 'number' |
||
| 6298 | ? (isArrayLike(object) && isIndex(index, object.length)) |
||
| 6299 | : (type == 'string' && index in object) |
||
| 6300 | ) {
|
||
| 6301 | return eq(object[index], value);
|
||
| 6302 | } |
||
| 6303 | return false; |
||
| 6304 | } |
||
| 6305 | |||
| 6306 | /**
|
||
| 6307 | * Checks if `value` is a property name and not a property path.
|
||
| 6308 | *
|
||
| 6309 | * @private
|
||
| 6310 | * @param {*} value The value to check.
|
||
| 6311 | * @param {Object} [object] The object to query keys on.
|
||
| 6312 | * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
||
| 6313 | */
|
||
| 6314 | function isKey(value, object) { |
||
| 6315 | if (isArray(value)) {
|
||
| 6316 | return false; |
||
| 6317 | } |
||
| 6318 | var type = typeof value; |
||
| 6319 | if (type == 'number' || type == 'symbol' || type == 'boolean' || |
||
| 6320 | value == null || isSymbol(value)) {
|
||
| 6321 | return true; |
||
| 6322 | } |
||
| 6323 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
||
| 6324 | (object != null && value in Object(object)); |
||
| 6325 | } |
||
| 6326 | |||
| 6327 | /**
|
||
| 6328 | * Checks if `value` is suitable for use as unique object key.
|
||
| 6329 | *
|
||
| 6330 | * @private
|
||
| 6331 | * @param {*} value The value to check.
|
||
| 6332 | * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
||
| 6333 | */
|
||
| 6334 | function isKeyable(value) { |
||
| 6335 | var type = typeof value; |
||
| 6336 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') |
||
| 6337 | ? (value !== '__proto__')
|
||
| 6338 | : (value === null);
|
||
| 6339 | } |
||
| 6340 | |||
| 6341 | /**
|
||
| 6342 | * Checks if `func` has a lazy counterpart.
|
||
| 6343 | *
|
||
| 6344 | * @private
|
||
| 6345 | * @param {Function} func The function to check.
|
||
| 6346 | * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
|
||
| 6347 | * else `false`.
|
||
| 6348 | */
|
||
| 6349 | function isLaziable(func) { |
||
| 6350 | var funcName = getFuncName(func),
|
||
| 6351 | other = lodash[funcName]; |
||
| 6352 | |||
| 6353 | if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) { |
||
| 6354 | return false; |
||
| 6355 | } |
||
| 6356 | if (func === other) {
|
||
| 6357 | return true; |
||
| 6358 | } |
||
| 6359 | var data = getData(other);
|
||
| 6360 | return !!data && func === data[0]; |
||
| 6361 | } |
||
| 6362 | |||
| 6363 | /**
|
||
| 6364 | * Checks if `func` has its source masked.
|
||
| 6365 | *
|
||
| 6366 | * @private
|
||
| 6367 | * @param {Function} func The function to check.
|
||
| 6368 | * @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
||
| 6369 | */
|
||
| 6370 | function isMasked(func) { |
||
| 6371 | return !!maskSrcKey && (maskSrcKey in func); |
||
| 6372 | } |
||
| 6373 | |||
| 6374 | /**
|
||
| 6375 | * Checks if `func` is capable of being masked.
|
||
| 6376 | *
|
||
| 6377 | * @private
|
||
| 6378 | * @param {*} value The value to check.
|
||
| 6379 | * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
|
||
| 6380 | */
|
||
| 6381 | var isMaskable = coreJsData ? isFunction : stubFalse;
|
||
| 6382 | |||
| 6383 | /**
|
||
| 6384 | * Checks if `value` is likely a prototype object.
|
||
| 6385 | *
|
||
| 6386 | * @private
|
||
| 6387 | * @param {*} value The value to check.
|
||
| 6388 | * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
||
| 6389 | */
|
||
| 6390 | function isPrototype(value) { |
||
| 6391 | var Ctor = value && value.constructor,
|
||
| 6392 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; |
||
| 6393 | |||
| 6394 | return value === proto;
|
||
| 6395 | } |
||
| 6396 | |||
| 6397 | /**
|
||
| 6398 | * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
||
| 6399 | *
|
||
| 6400 | * @private
|
||
| 6401 | * @param {*} value The value to check.
|
||
| 6402 | * @returns {boolean} Returns `true` if `value` if suitable for strict
|
||
| 6403 | * equality comparisons, else `false`.
|
||
| 6404 | */
|
||
| 6405 | function isStrictComparable(value) { |
||
| 6406 | return value === value && !isObject(value);
|
||
| 6407 | } |
||
| 6408 | |||
| 6409 | /**
|
||
| 6410 | * A specialized version of `matchesProperty` for source values suitable
|
||
| 6411 | * for strict equality comparisons, i.e. `===`.
|
||
| 6412 | *
|
||
| 6413 | * @private
|
||
| 6414 | * @param {string} key The key of the property to get.
|
||
| 6415 | * @param {*} srcValue The value to match.
|
||
| 6416 | * @returns {Function} Returns the new spec function.
|
||
| 6417 | */
|
||
| 6418 | function matchesStrictComparable(key, srcValue) { |
||
| 6419 | return function(object) { |
||
| 6420 | if (object == null) { |
||
| 6421 | return false; |
||
| 6422 | } |
||
| 6423 | return object[key] === srcValue &&
|
||
| 6424 | (srcValue !== undefined || (key in Object(object))); |
||
| 6425 | }; |
||
| 6426 | } |
||
| 6427 | |||
| 6428 | /**
|
||
| 6429 | * A specialized version of `_.memoize` which clears the memoized function's
|
||
| 6430 | * cache when it exceeds `MAX_MEMOIZE_SIZE`.
|
||
| 6431 | *
|
||
| 6432 | * @private
|
||
| 6433 | * @param {Function} func The function to have its output memoized.
|
||
| 6434 | * @returns {Function} Returns the new memoized function.
|
||
| 6435 | */
|
||
| 6436 | function memoizeCapped(func) { |
||
| 6437 | var result = memoize(func, function(key) { |
||
| 6438 | if (cache.size === MAX_MEMOIZE_SIZE) {
|
||
| 6439 | cache.clear(); |
||
| 6440 | } |
||
| 6441 | return key;
|
||
| 6442 | }); |
||
| 6443 | |||
| 6444 | var cache = result.cache;
|
||
| 6445 | return result;
|
||
| 6446 | } |
||
| 6447 | |||
| 6448 | /**
|
||
| 6449 | * Merges the function metadata of `source` into `data`.
|
||
| 6450 | *
|
||
| 6451 | * Merging metadata reduces the number of wrappers used to invoke a function.
|
||
| 6452 | * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
|
||
| 6453 | * may be applied regardless of execution order. Methods like `_.ary` and
|
||
| 6454 | * `_.rearg` modify function arguments, making the order in which they are
|
||
| 6455 | * executed important, preventing the merging of metadata. However, we make
|
||
| 6456 | * an exception for a safe combined case where curried functions have `_.ary`
|
||
| 6457 | * and or `_.rearg` applied.
|
||
| 6458 | *
|
||
| 6459 | * @private
|
||
| 6460 | * @param {Array} data The destination metadata.
|
||
| 6461 | * @param {Array} source The source metadata.
|
||
| 6462 | * @returns {Array} Returns `data`.
|
||
| 6463 | */
|
||
| 6464 | function mergeData(data, source) { |
||
| 6465 | var bitmask = data[1], |
||
| 6466 | srcBitmask = source[1],
|
||
| 6467 | newBitmask = bitmask | srcBitmask, |
||
| 6468 | isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG); |
||
| 6469 | |||
| 6470 | var isCombo =
|
||
| 6471 | ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) || |
||
| 6472 | ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) || |
||
| 6473 | ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG)); |
||
| 6474 | |||
| 6475 | // Exit early if metadata can't be merged.
|
||
| 6476 | if (!(isCommon || isCombo)) {
|
||
| 6477 | return data;
|
||
| 6478 | } |
||
| 6479 | // Use source `thisArg` if available.
|
||
| 6480 | if (srcBitmask & WRAP_BIND_FLAG) {
|
||
| 6481 | data[2] = source[2]; |
||
| 6482 | // Set when currying a bound function.
|
||
| 6483 | newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
|
||
| 6484 | } |
||
| 6485 | // Compose partial arguments.
|
||
| 6486 | var value = source[3]; |
||
| 6487 | if (value) {
|
||
| 6488 | var partials = data[3]; |
||
| 6489 | data[3] = partials ? composeArgs(partials, value, source[4]) : value; |
||
| 6490 | data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; |
||
| 6491 | } |
||
| 6492 | // Compose partial right arguments.
|
||
| 6493 | value = source[5];
|
||
| 6494 | if (value) {
|
||
| 6495 | partials = data[5];
|
||
| 6496 | data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; |
||
| 6497 | data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; |
||
| 6498 | } |
||
| 6499 | // Use source `argPos` if available.
|
||
| 6500 | value = source[7];
|
||
| 6501 | if (value) {
|
||
| 6502 | data[7] = value;
|
||
| 6503 | } |
||
| 6504 | // Use source `ary` if it's smaller.
|
||
| 6505 | if (srcBitmask & WRAP_ARY_FLAG) {
|
||
| 6506 | data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); |
||
| 6507 | } |
||
| 6508 | // Use source `arity` if one is not provided.
|
||
| 6509 | if (data[9] == null) { |
||
| 6510 | data[9] = source[9]; |
||
| 6511 | } |
||
| 6512 | // Use source `func` and merge bitmasks.
|
||
| 6513 | data[0] = source[0]; |
||
| 6514 | data[1] = newBitmask;
|
||
| 6515 | |||
| 6516 | return data;
|
||
| 6517 | } |
||
| 6518 | |||
| 6519 | /**
|
||
| 6520 | * This function is like
|
||
| 6521 | * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
||
| 6522 | * except that it includes inherited enumerable properties.
|
||
| 6523 | *
|
||
| 6524 | * @private
|
||
| 6525 | * @param {Object} object The object to query.
|
||
| 6526 | * @returns {Array} Returns the array of property names.
|
||
| 6527 | */
|
||
| 6528 | function nativeKeysIn(object) { |
||
| 6529 | var result = [];
|
||
| 6530 | if (object != null) { |
||
| 6531 | for (var key in Object(object)) { |
||
| 6532 | result.push(key); |
||
| 6533 | } |
||
| 6534 | } |
||
| 6535 | return result;
|
||
| 6536 | } |
||
| 6537 | |||
| 6538 | /**
|
||
| 6539 | * Converts `value` to a string using `Object.prototype.toString`.
|
||
| 6540 | *
|
||
| 6541 | * @private
|
||
| 6542 | * @param {*} value The value to convert.
|
||
| 6543 | * @returns {string} Returns the converted string.
|
||
| 6544 | */
|
||
| 6545 | function objectToString(value) { |
||
| 6546 | return nativeObjectToString.call(value);
|
||
| 6547 | } |
||
| 6548 | |||
| 6549 | /**
|
||
| 6550 | * A specialized version of `baseRest` which transforms the rest array.
|
||
| 6551 | *
|
||
| 6552 | * @private
|
||
| 6553 | * @param {Function} func The function to apply a rest parameter to.
|
||
| 6554 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
||
| 6555 | * @param {Function} transform The rest array transform.
|
||
| 6556 | * @returns {Function} Returns the new function.
|
||
| 6557 | */
|
||
| 6558 | function overRest(func, start, transform) { |
||
| 6559 | start = nativeMax(start === undefined ? (func.length - 1) : start, 0); |
||
| 6560 | return function() { |
||
| 6561 | var args = arguments, |
||
| 6562 | index = -1,
|
||
| 6563 | length = nativeMax(args.length - start, 0),
|
||
| 6564 | array = Array(length); |
||
| 6565 | |||
| 6566 | while (++index < length) {
|
||
| 6567 | array[index] = args[start + index]; |
||
| 6568 | } |
||
| 6569 | index = -1;
|
||
| 6570 | var otherArgs = Array(start + 1); |
||
| 6571 | while (++index < start) {
|
||
| 6572 | otherArgs[index] = args[index]; |
||
| 6573 | } |
||
| 6574 | otherArgs[start] = transform(array); |
||
| 6575 | return apply(func, this, otherArgs); |
||
| 6576 | }; |
||
| 6577 | } |
||
| 6578 | |||
| 6579 | /**
|
||
| 6580 | * Gets the parent value at `path` of `object`.
|
||
| 6581 | *
|
||
| 6582 | * @private
|
||
| 6583 | * @param {Object} object The object to query.
|
||
| 6584 | * @param {Array} path The path to get the parent value of.
|
||
| 6585 | * @returns {*} Returns the parent value.
|
||
| 6586 | */
|
||
| 6587 | function parent(object, path) { |
||
| 6588 | return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1)); |
||
| 6589 | } |
||
| 6590 | |||
| 6591 | /**
|
||
| 6592 | * Reorder `array` according to the specified indexes where the element at
|
||
| 6593 | * the first index is assigned as the first element, the element at
|
||
| 6594 | * the second index is assigned as the second element, and so on.
|
||
| 6595 | *
|
||
| 6596 | * @private
|
||
| 6597 | * @param {Array} array The array to reorder.
|
||
| 6598 | * @param {Array} indexes The arranged array indexes.
|
||
| 6599 | * @returns {Array} Returns `array`.
|
||
| 6600 | */
|
||
| 6601 | function reorder(array, indexes) { |
||
| 6602 | var arrLength = array.length,
|
||
| 6603 | length = nativeMin(indexes.length, arrLength), |
||
| 6604 | oldArray = copyArray(array); |
||
| 6605 | |||
| 6606 | while (length--) {
|
||
| 6607 | var index = indexes[length];
|
||
| 6608 | array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
|
||
| 6609 | } |
||
| 6610 | return array;
|
||
| 6611 | } |
||
| 6612 | |||
| 6613 | /**
|
||
| 6614 | * Sets metadata for `func`.
|
||
| 6615 | *
|
||
| 6616 | * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
|
||
| 6617 | * period of time, it will trip its breaker and transition to an identity
|
||
| 6618 | * function to avoid garbage collection pauses in V8. See
|
||
| 6619 | * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
|
||
| 6620 | * for more details.
|
||
| 6621 | *
|
||
| 6622 | * @private
|
||
| 6623 | * @param {Function} func The function to associate metadata with.
|
||
| 6624 | * @param {*} data The metadata.
|
||
| 6625 | * @returns {Function} Returns `func`.
|
||
| 6626 | */
|
||
| 6627 | var setData = shortOut(baseSetData);
|
||
| 6628 | |||
| 6629 | /**
|
||
| 6630 | * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
|
||
| 6631 | *
|
||
| 6632 | * @private
|
||
| 6633 | * @param {Function} func The function to delay.
|
||
| 6634 | * @param {number} wait The number of milliseconds to delay invocation.
|
||
| 6635 | * @returns {number|Object} Returns the timer id or timeout object.
|
||
| 6636 | */
|
||
| 6637 | var setTimeout = ctxSetTimeout || function(func, wait) { |
||
| 6638 | return root.setTimeout(func, wait);
|
||
| 6639 | }; |
||
| 6640 | |||
| 6641 | /**
|
||
| 6642 | * Sets the `toString` method of `func` to return `string`.
|
||
| 6643 | *
|
||
| 6644 | * @private
|
||
| 6645 | * @param {Function} func The function to modify.
|
||
| 6646 | * @param {Function} string The `toString` result.
|
||
| 6647 | * @returns {Function} Returns `func`.
|
||
| 6648 | */
|
||
| 6649 | var setToString = shortOut(baseSetToString);
|
||
| 6650 | |||
| 6651 | /**
|
||
| 6652 | * Sets the `toString` method of `wrapper` to mimic the source of `reference`
|
||
| 6653 | * with wrapper details in a comment at the top of the source body.
|
||
| 6654 | *
|
||
| 6655 | * @private
|
||
| 6656 | * @param {Function} wrapper The function to modify.
|
||
| 6657 | * @param {Function} reference The reference function.
|
||
| 6658 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||
| 6659 | * @returns {Function} Returns `wrapper`.
|
||
| 6660 | */
|
||
| 6661 | function setWrapToString(wrapper, reference, bitmask) { |
||
| 6662 | var source = (reference + ''); |
||
| 6663 | return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
|
||
| 6664 | } |
||
| 6665 | |||
| 6666 | /**
|
||
| 6667 | * Creates a function that'll short out and invoke `identity` instead
|
||
| 6668 | * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
|
||
| 6669 | * milliseconds.
|
||
| 6670 | *
|
||
| 6671 | * @private
|
||
| 6672 | * @param {Function} func The function to restrict.
|
||
| 6673 | * @returns {Function} Returns the new shortable function.
|
||
| 6674 | */
|
||
| 6675 | function shortOut(func) { |
||
| 6676 | var count = 0, |
||
| 6677 | lastCalled = 0;
|
||
| 6678 | |||
| 6679 | return function() { |
||
| 6680 | var stamp = nativeNow(),
|
||
| 6681 | remaining = HOT_SPAN - (stamp - lastCalled); |
||
| 6682 | |||
| 6683 | lastCalled = stamp; |
||
| 6684 | if (remaining > 0) { |
||
| 6685 | if (++count >= HOT_COUNT) {
|
||
| 6686 | return arguments[0]; |
||
| 6687 | } |
||
| 6688 | } else {
|
||
| 6689 | count = 0;
|
||
| 6690 | } |
||
| 6691 | return func.apply(undefined, arguments); |
||
| 6692 | }; |
||
| 6693 | } |
||
| 6694 | |||
| 6695 | /**
|
||
| 6696 | * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
|
||
| 6697 | *
|
||
| 6698 | * @private
|
||
| 6699 | * @param {Array} array The array to shuffle.
|
||
| 6700 | * @param {number} [size=array.length] The size of `array`.
|
||
| 6701 | * @returns {Array} Returns `array`.
|
||
| 6702 | */
|
||
| 6703 | function shuffleSelf(array, size) { |
||
| 6704 | var index = -1, |
||
| 6705 | length = array.length, |
||
| 6706 | lastIndex = length - 1;
|
||
| 6707 | |||
| 6708 | size = size === undefined ? length : size;
|
||
| 6709 | while (++index < size) {
|
||
| 6710 | var rand = baseRandom(index, lastIndex),
|
||
| 6711 | value = array[rand]; |
||
| 6712 | |||
| 6713 | array[rand] = array[index]; |
||
| 6714 | array[index] = value; |
||
| 6715 | } |
||
| 6716 | array.length = size; |
||
| 6717 | return array;
|
||
| 6718 | } |
||
| 6719 | |||
| 6720 | /**
|
||
| 6721 | * Converts `string` to a property path array.
|
||
| 6722 | *
|
||
| 6723 | * @private
|
||
| 6724 | * @param {string} string The string to convert.
|
||
| 6725 | * @returns {Array} Returns the property path array.
|
||
| 6726 | */
|
||
| 6727 | var stringToPath = memoizeCapped(function(string) { |
||
| 6728 | var result = [];
|
||
| 6729 | if (string.charCodeAt(0) === 46 /* . */) { |
||
| 6730 | result.push('');
|
||
| 6731 | } |
||
| 6732 | string.replace(rePropName, function(match, number, quote, subString) {
|
||
| 6733 | result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
|
||
| 6734 | }); |
||
| 6735 | return result;
|
||
| 6736 | }); |
||
| 6737 | |||
| 6738 | /**
|
||
| 6739 | * Converts `value` to a string key if it's not a string or symbol.
|
||
| 6740 | *
|
||
| 6741 | * @private
|
||
| 6742 | * @param {*} value The value to inspect.
|
||
| 6743 | * @returns {string|symbol} Returns the key.
|
||
| 6744 | */
|
||
| 6745 | function toKey(value) { |
||
| 6746 | if (typeof value == 'string' || isSymbol(value)) { |
||
| 6747 | return value;
|
||
| 6748 | } |
||
| 6749 | var result = (value + ''); |
||
| 6750 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; |
||
| 6751 | } |
||
| 6752 | |||
| 6753 | /**
|
||
| 6754 | * Converts `func` to its source code.
|
||
| 6755 | *
|
||
| 6756 | * @private
|
||
| 6757 | * @param {Function} func The function to convert.
|
||
| 6758 | * @returns {string} Returns the source code.
|
||
| 6759 | */
|
||
| 6760 | function toSource(func) { |
||
| 6761 | if (func != null) { |
||
| 6762 | try {
|
||
| 6763 | return funcToString.call(func);
|
||
| 6764 | } catch (e) {}
|
||
| 6765 | try {
|
||
| 6766 | return (func + ''); |
||
| 6767 | } catch (e) {}
|
||
| 6768 | } |
||
| 6769 | return ''; |
||
| 6770 | } |
||
| 6771 | |||
| 6772 | /**
|
||
| 6773 | * Updates wrapper `details` based on `bitmask` flags.
|
||
| 6774 | *
|
||
| 6775 | * @private
|
||
| 6776 | * @returns {Array} details The details to modify.
|
||
| 6777 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
||
| 6778 | * @returns {Array} Returns `details`.
|
||
| 6779 | */
|
||
| 6780 | function updateWrapDetails(details, bitmask) { |
||
| 6781 | arrayEach(wrapFlags, function(pair) {
|
||
| 6782 | var value = '_.' + pair[0]; |
||
| 6783 | if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { |
||
| 6784 | details.push(value); |
||
| 6785 | } |
||
| 6786 | }); |
||
| 6787 | return details.sort();
|
||
| 6788 | } |
||
| 6789 | |||
| 6790 | /**
|
||
| 6791 | * Creates a clone of `wrapper`.
|
||
| 6792 | *
|
||
| 6793 | * @private
|
||
| 6794 | * @param {Object} wrapper The wrapper to clone.
|
||
| 6795 | * @returns {Object} Returns the cloned wrapper.
|
||
| 6796 | */
|
||
| 6797 | function wrapperClone(wrapper) { |
||
| 6798 | if (wrapper instanceof LazyWrapper) { |
||
| 6799 | return wrapper.clone();
|
||
| 6800 | } |
||
| 6801 | var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); |
||
| 6802 | result.__actions__ = copyArray(wrapper.__actions__); |
||
| 6803 | result.__index__ = wrapper.__index__; |
||
| 6804 | result.__values__ = wrapper.__values__; |
||
| 6805 | return result;
|
||
| 6806 | } |
||
| 6807 | |||
| 6808 | /*------------------------------------------------------------------------*/
|
||
| 6809 | |||
| 6810 | /**
|
||
| 6811 | * Creates an array of elements split into groups the length of `size`.
|
||
| 6812 | * If `array` can't be split evenly, the final chunk will be the remaining
|
||
| 6813 | * elements.
|
||
| 6814 | *
|
||
| 6815 | * @static
|
||
| 6816 | * @memberOf _
|
||
| 6817 | * @since 3.0.0
|
||
| 6818 | * @category Array
|
||
| 6819 | * @param {Array} array The array to process.
|
||
| 6820 | * @param {number} [size=1] The length of each chunk
|
||
| 6821 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 6822 | * @returns {Array} Returns the new array of chunks.
|
||
| 6823 | * @example
|
||
| 6824 | *
|
||
| 6825 | * _.chunk(['a', 'b', 'c', 'd'], 2);
|
||
| 6826 | * // => [['a', 'b'], ['c', 'd']]
|
||
| 6827 | *
|
||
| 6828 | * _.chunk(['a', 'b', 'c', 'd'], 3);
|
||
| 6829 | * // => [['a', 'b', 'c'], ['d']]
|
||
| 6830 | */
|
||
| 6831 | function chunk(array, size, guard) { |
||
| 6832 | if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) { |
||
| 6833 | size = 1;
|
||
| 6834 | } else {
|
||
| 6835 | size = nativeMax(toInteger(size), 0);
|
||
| 6836 | } |
||
| 6837 | var length = array == null ? 0 : array.length; |
||
| 6838 | if (!length || size < 1) { |
||
| 6839 | return [];
|
||
| 6840 | } |
||
| 6841 | var index = 0, |
||
| 6842 | resIndex = 0,
|
||
| 6843 | result = Array(nativeCeil(length / size)); |
||
| 6844 | |||
| 6845 | while (index < length) {
|
||
| 6846 | result[resIndex++] = baseSlice(array, index, (index += size)); |
||
| 6847 | } |
||
| 6848 | return result;
|
||
| 6849 | } |
||
| 6850 | |||
| 6851 | /**
|
||
| 6852 | * Creates an array with all falsey values removed. The values `false`, `null`,
|
||
| 6853 | * `0`, `""`, `undefined`, and `NaN` are falsey.
|
||
| 6854 | *
|
||
| 6855 | * @static
|
||
| 6856 | * @memberOf _
|
||
| 6857 | * @since 0.1.0
|
||
| 6858 | * @category Array
|
||
| 6859 | * @param {Array} array The array to compact.
|
||
| 6860 | * @returns {Array} Returns the new array of filtered values.
|
||
| 6861 | * @example
|
||
| 6862 | *
|
||
| 6863 | * _.compact([0, 1, false, 2, '', 3]);
|
||
| 6864 | * // => [1, 2, 3]
|
||
| 6865 | */
|
||
| 6866 | function compact(array) { |
||
| 6867 | var index = -1, |
||
| 6868 | length = array == null ? 0 : array.length, |
||
| 6869 | resIndex = 0,
|
||
| 6870 | result = []; |
||
| 6871 | |||
| 6872 | while (++index < length) {
|
||
| 6873 | var value = array[index];
|
||
| 6874 | if (value) {
|
||
| 6875 | result[resIndex++] = value; |
||
| 6876 | } |
||
| 6877 | } |
||
| 6878 | return result;
|
||
| 6879 | } |
||
| 6880 | |||
| 6881 | /**
|
||
| 6882 | * Creates a new array concatenating `array` with any additional arrays
|
||
| 6883 | * and/or values.
|
||
| 6884 | *
|
||
| 6885 | * @static
|
||
| 6886 | * @memberOf _
|
||
| 6887 | * @since 4.0.0
|
||
| 6888 | * @category Array
|
||
| 6889 | * @param {Array} array The array to concatenate.
|
||
| 6890 | * @param {...*} [values] The values to concatenate.
|
||
| 6891 | * @returns {Array} Returns the new concatenated array.
|
||
| 6892 | * @example
|
||
| 6893 | *
|
||
| 6894 | * var array = [1];
|
||
| 6895 | * var other = _.concat(array, 2, [3], [[4]]);
|
||
| 6896 | *
|
||
| 6897 | * console.log(other);
|
||
| 6898 | * // => [1, 2, 3, [4]]
|
||
| 6899 | *
|
||
| 6900 | * console.log(array);
|
||
| 6901 | * // => [1]
|
||
| 6902 | */
|
||
| 6903 | function concat() { |
||
| 6904 | var length = arguments.length; |
||
| 6905 | if (!length) {
|
||
| 6906 | return [];
|
||
| 6907 | } |
||
| 6908 | var args = Array(length - 1), |
||
| 6909 | array = arguments[0], |
||
| 6910 | index = length; |
||
| 6911 | |||
| 6912 | while (index--) {
|
||
| 6913 | args[index - 1] = arguments[index]; |
||
| 6914 | } |
||
| 6915 | return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); |
||
| 6916 | } |
||
| 6917 | |||
| 6918 | /**
|
||
| 6919 | * Creates an array of `array` values not included in the other given arrays
|
||
| 6920 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 6921 | * for equality comparisons. The order and references of result values are
|
||
| 6922 | * determined by the first array.
|
||
| 6923 | *
|
||
| 6924 | * **Note:** Unlike `_.pullAll`, this method returns a new array.
|
||
| 6925 | *
|
||
| 6926 | * @static
|
||
| 6927 | * @memberOf _
|
||
| 6928 | * @since 0.1.0
|
||
| 6929 | * @category Array
|
||
| 6930 | * @param {Array} array The array to inspect.
|
||
| 6931 | * @param {...Array} [values] The values to exclude.
|
||
| 6932 | * @returns {Array} Returns the new array of filtered values.
|
||
| 6933 | * @see _.without, _.xor
|
||
| 6934 | * @example
|
||
| 6935 | *
|
||
| 6936 | * _.difference([2, 1], [2, 3]);
|
||
| 6937 | * // => [1]
|
||
| 6938 | */
|
||
| 6939 | var difference = baseRest(function(array, values) { |
||
| 6940 | return isArrayLikeObject(array)
|
||
| 6941 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) |
||
| 6942 | : []; |
||
| 6943 | }); |
||
| 6944 | |||
| 6945 | /**
|
||
| 6946 | * This method is like `_.difference` except that it accepts `iteratee` which
|
||
| 6947 | * is invoked for each element of `array` and `values` to generate the criterion
|
||
| 6948 | * by which they're compared. The order and references of result values are
|
||
| 6949 | * determined by the first array. The iteratee is invoked with one argument:
|
||
| 6950 | * (value).
|
||
| 6951 | *
|
||
| 6952 | * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
|
||
| 6953 | *
|
||
| 6954 | * @static
|
||
| 6955 | * @memberOf _
|
||
| 6956 | * @since 4.0.0
|
||
| 6957 | * @category Array
|
||
| 6958 | * @param {Array} array The array to inspect.
|
||
| 6959 | * @param {...Array} [values] The values to exclude.
|
||
| 6960 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 6961 | * @returns {Array} Returns the new array of filtered values.
|
||
| 6962 | * @example
|
||
| 6963 | *
|
||
| 6964 | * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
||
| 6965 | * // => [1.2]
|
||
| 6966 | *
|
||
| 6967 | * // The `_.property` iteratee shorthand.
|
||
| 6968 | * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
|
||
| 6969 | * // => [{ 'x': 2 }]
|
||
| 6970 | */
|
||
| 6971 | var differenceBy = baseRest(function(array, values) { |
||
| 6972 | var iteratee = last(values);
|
||
| 6973 | if (isArrayLikeObject(iteratee)) {
|
||
| 6974 | iteratee = undefined;
|
||
| 6975 | } |
||
| 6976 | return isArrayLikeObject(array)
|
||
| 6977 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) |
||
| 6978 | : []; |
||
| 6979 | }); |
||
| 6980 | |||
| 6981 | /**
|
||
| 6982 | * This method is like `_.difference` except that it accepts `comparator`
|
||
| 6983 | * which is invoked to compare elements of `array` to `values`. The order and
|
||
| 6984 | * references of result values are determined by the first array. The comparator
|
||
| 6985 | * is invoked with two arguments: (arrVal, othVal).
|
||
| 6986 | *
|
||
| 6987 | * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
|
||
| 6988 | *
|
||
| 6989 | * @static
|
||
| 6990 | * @memberOf _
|
||
| 6991 | * @since 4.0.0
|
||
| 6992 | * @category Array
|
||
| 6993 | * @param {Array} array The array to inspect.
|
||
| 6994 | * @param {...Array} [values] The values to exclude.
|
||
| 6995 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 6996 | * @returns {Array} Returns the new array of filtered values.
|
||
| 6997 | * @example
|
||
| 6998 | *
|
||
| 6999 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
||
| 7000 | *
|
||
| 7001 | * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
|
||
| 7002 | * // => [{ 'x': 2, 'y': 1 }]
|
||
| 7003 | */
|
||
| 7004 | var differenceWith = baseRest(function(array, values) { |
||
| 7005 | var comparator = last(values);
|
||
| 7006 | if (isArrayLikeObject(comparator)) {
|
||
| 7007 | comparator = undefined;
|
||
| 7008 | } |
||
| 7009 | return isArrayLikeObject(array)
|
||
| 7010 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator) |
||
| 7011 | : []; |
||
| 7012 | }); |
||
| 7013 | |||
| 7014 | /**
|
||
| 7015 | * Creates a slice of `array` with `n` elements dropped from the beginning.
|
||
| 7016 | *
|
||
| 7017 | * @static
|
||
| 7018 | * @memberOf _
|
||
| 7019 | * @since 0.5.0
|
||
| 7020 | * @category Array
|
||
| 7021 | * @param {Array} array The array to query.
|
||
| 7022 | * @param {number} [n=1] The number of elements to drop.
|
||
| 7023 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 7024 | * @returns {Array} Returns the slice of `array`.
|
||
| 7025 | * @example
|
||
| 7026 | *
|
||
| 7027 | * _.drop([1, 2, 3]);
|
||
| 7028 | * // => [2, 3]
|
||
| 7029 | *
|
||
| 7030 | * _.drop([1, 2, 3], 2);
|
||
| 7031 | * // => [3]
|
||
| 7032 | *
|
||
| 7033 | * _.drop([1, 2, 3], 5);
|
||
| 7034 | * // => []
|
||
| 7035 | *
|
||
| 7036 | * _.drop([1, 2, 3], 0);
|
||
| 7037 | * // => [1, 2, 3]
|
||
| 7038 | */
|
||
| 7039 | function drop(array, n, guard) { |
||
| 7040 | var length = array == null ? 0 : array.length; |
||
| 7041 | if (!length) {
|
||
| 7042 | return [];
|
||
| 7043 | } |
||
| 7044 | n = (guard || n === undefined) ? 1 : toInteger(n); |
||
| 7045 | return baseSlice(array, n < 0 ? 0 : n, length); |
||
| 7046 | } |
||
| 7047 | |||
| 7048 | /**
|
||
| 7049 | * Creates a slice of `array` with `n` elements dropped from the end.
|
||
| 7050 | *
|
||
| 7051 | * @static
|
||
| 7052 | * @memberOf _
|
||
| 7053 | * @since 3.0.0
|
||
| 7054 | * @category Array
|
||
| 7055 | * @param {Array} array The array to query.
|
||
| 7056 | * @param {number} [n=1] The number of elements to drop.
|
||
| 7057 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 7058 | * @returns {Array} Returns the slice of `array`.
|
||
| 7059 | * @example
|
||
| 7060 | *
|
||
| 7061 | * _.dropRight([1, 2, 3]);
|
||
| 7062 | * // => [1, 2]
|
||
| 7063 | *
|
||
| 7064 | * _.dropRight([1, 2, 3], 2);
|
||
| 7065 | * // => [1]
|
||
| 7066 | *
|
||
| 7067 | * _.dropRight([1, 2, 3], 5);
|
||
| 7068 | * // => []
|
||
| 7069 | *
|
||
| 7070 | * _.dropRight([1, 2, 3], 0);
|
||
| 7071 | * // => [1, 2, 3]
|
||
| 7072 | */
|
||
| 7073 | function dropRight(array, n, guard) { |
||
| 7074 | var length = array == null ? 0 : array.length; |
||
| 7075 | if (!length) {
|
||
| 7076 | return [];
|
||
| 7077 | } |
||
| 7078 | n = (guard || n === undefined) ? 1 : toInteger(n); |
||
| 7079 | n = length - n; |
||
| 7080 | return baseSlice(array, 0, n < 0 ? 0 : n); |
||
| 7081 | } |
||
| 7082 | |||
| 7083 | /**
|
||
| 7084 | * Creates a slice of `array` excluding elements dropped from the end.
|
||
| 7085 | * Elements are dropped until `predicate` returns falsey. The predicate is
|
||
| 7086 | * invoked with three arguments: (value, index, array).
|
||
| 7087 | *
|
||
| 7088 | * @static
|
||
| 7089 | * @memberOf _
|
||
| 7090 | * @since 3.0.0
|
||
| 7091 | * @category Array
|
||
| 7092 | * @param {Array} array The array to query.
|
||
| 7093 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 7094 | * @returns {Array} Returns the slice of `array`.
|
||
| 7095 | * @example
|
||
| 7096 | *
|
||
| 7097 | * var users = [
|
||
| 7098 | * { 'user': 'barney', 'active': true },
|
||
| 7099 | * { 'user': 'fred', 'active': false },
|
||
| 7100 | * { 'user': 'pebbles', 'active': false }
|
||
| 7101 | * ];
|
||
| 7102 | *
|
||
| 7103 | * _.dropRightWhile(users, function(o) { return !o.active; });
|
||
| 7104 | * // => objects for ['barney']
|
||
| 7105 | *
|
||
| 7106 | * // The `_.matches` iteratee shorthand.
|
||
| 7107 | * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
|
||
| 7108 | * // => objects for ['barney', 'fred']
|
||
| 7109 | *
|
||
| 7110 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 7111 | * _.dropRightWhile(users, ['active', false]);
|
||
| 7112 | * // => objects for ['barney']
|
||
| 7113 | *
|
||
| 7114 | * // The `_.property` iteratee shorthand.
|
||
| 7115 | * _.dropRightWhile(users, 'active');
|
||
| 7116 | * // => objects for ['barney', 'fred', 'pebbles']
|
||
| 7117 | */
|
||
| 7118 | function dropRightWhile(array, predicate) { |
||
| 7119 | return (array && array.length)
|
||
| 7120 | ? baseWhile(array, getIteratee(predicate, 3), true, true) |
||
| 7121 | : []; |
||
| 7122 | } |
||
| 7123 | |||
| 7124 | /**
|
||
| 7125 | * Creates a slice of `array` excluding elements dropped from the beginning.
|
||
| 7126 | * Elements are dropped until `predicate` returns falsey. The predicate is
|
||
| 7127 | * invoked with three arguments: (value, index, array).
|
||
| 7128 | *
|
||
| 7129 | * @static
|
||
| 7130 | * @memberOf _
|
||
| 7131 | * @since 3.0.0
|
||
| 7132 | * @category Array
|
||
| 7133 | * @param {Array} array The array to query.
|
||
| 7134 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 7135 | * @returns {Array} Returns the slice of `array`.
|
||
| 7136 | * @example
|
||
| 7137 | *
|
||
| 7138 | * var users = [
|
||
| 7139 | * { 'user': 'barney', 'active': false },
|
||
| 7140 | * { 'user': 'fred', 'active': false },
|
||
| 7141 | * { 'user': 'pebbles', 'active': true }
|
||
| 7142 | * ];
|
||
| 7143 | *
|
||
| 7144 | * _.dropWhile(users, function(o) { return !o.active; });
|
||
| 7145 | * // => objects for ['pebbles']
|
||
| 7146 | *
|
||
| 7147 | * // The `_.matches` iteratee shorthand.
|
||
| 7148 | * _.dropWhile(users, { 'user': 'barney', 'active': false });
|
||
| 7149 | * // => objects for ['fred', 'pebbles']
|
||
| 7150 | *
|
||
| 7151 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 7152 | * _.dropWhile(users, ['active', false]);
|
||
| 7153 | * // => objects for ['pebbles']
|
||
| 7154 | *
|
||
| 7155 | * // The `_.property` iteratee shorthand.
|
||
| 7156 | * _.dropWhile(users, 'active');
|
||
| 7157 | * // => objects for ['barney', 'fred', 'pebbles']
|
||
| 7158 | */
|
||
| 7159 | function dropWhile(array, predicate) { |
||
| 7160 | return (array && array.length)
|
||
| 7161 | ? baseWhile(array, getIteratee(predicate, 3), true) |
||
| 7162 | : []; |
||
| 7163 | } |
||
| 7164 | |||
| 7165 | /**
|
||
| 7166 | * Fills elements of `array` with `value` from `start` up to, but not
|
||
| 7167 | * including, `end`.
|
||
| 7168 | *
|
||
| 7169 | * **Note:** This method mutates `array`.
|
||
| 7170 | *
|
||
| 7171 | * @static
|
||
| 7172 | * @memberOf _
|
||
| 7173 | * @since 3.2.0
|
||
| 7174 | * @category Array
|
||
| 7175 | * @param {Array} array The array to fill.
|
||
| 7176 | * @param {*} value The value to fill `array` with.
|
||
| 7177 | * @param {number} [start=0] The start position.
|
||
| 7178 | * @param {number} [end=array.length] The end position.
|
||
| 7179 | * @returns {Array} Returns `array`.
|
||
| 7180 | * @example
|
||
| 7181 | *
|
||
| 7182 | * var array = [1, 2, 3];
|
||
| 7183 | *
|
||
| 7184 | * _.fill(array, 'a');
|
||
| 7185 | * console.log(array);
|
||
| 7186 | * // => ['a', 'a', 'a']
|
||
| 7187 | *
|
||
| 7188 | * _.fill(Array(3), 2);
|
||
| 7189 | * // => [2, 2, 2]
|
||
| 7190 | *
|
||
| 7191 | * _.fill([4, 6, 8, 10], '*', 1, 3);
|
||
| 7192 | * // => [4, '*', '*', 10]
|
||
| 7193 | */
|
||
| 7194 | function fill(array, value, start, end) { |
||
| 7195 | var length = array == null ? 0 : array.length; |
||
| 7196 | if (!length) {
|
||
| 7197 | return [];
|
||
| 7198 | } |
||
| 7199 | if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { |
||
| 7200 | start = 0;
|
||
| 7201 | end = length; |
||
| 7202 | } |
||
| 7203 | return baseFill(array, value, start, end);
|
||
| 7204 | } |
||
| 7205 | |||
| 7206 | /**
|
||
| 7207 | * This method is like `_.find` except that it returns the index of the first
|
||
| 7208 | * element `predicate` returns truthy for instead of the element itself.
|
||
| 7209 | *
|
||
| 7210 | * @static
|
||
| 7211 | * @memberOf _
|
||
| 7212 | * @since 1.1.0
|
||
| 7213 | * @category Array
|
||
| 7214 | * @param {Array} array The array to inspect.
|
||
| 7215 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 7216 | * @param {number} [fromIndex=0] The index to search from.
|
||
| 7217 | * @returns {number} Returns the index of the found element, else `-1`.
|
||
| 7218 | * @example
|
||
| 7219 | *
|
||
| 7220 | * var users = [
|
||
| 7221 | * { 'user': 'barney', 'active': false },
|
||
| 7222 | * { 'user': 'fred', 'active': false },
|
||
| 7223 | * { 'user': 'pebbles', 'active': true }
|
||
| 7224 | * ];
|
||
| 7225 | *
|
||
| 7226 | * _.findIndex(users, function(o) { return o.user == 'barney'; });
|
||
| 7227 | * // => 0
|
||
| 7228 | *
|
||
| 7229 | * // The `_.matches` iteratee shorthand.
|
||
| 7230 | * _.findIndex(users, { 'user': 'fred', 'active': false });
|
||
| 7231 | * // => 1
|
||
| 7232 | *
|
||
| 7233 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 7234 | * _.findIndex(users, ['active', false]);
|
||
| 7235 | * // => 0
|
||
| 7236 | *
|
||
| 7237 | * // The `_.property` iteratee shorthand.
|
||
| 7238 | * _.findIndex(users, 'active');
|
||
| 7239 | * // => 2
|
||
| 7240 | */
|
||
| 7241 | function findIndex(array, predicate, fromIndex) { |
||
| 7242 | var length = array == null ? 0 : array.length; |
||
| 7243 | if (!length) {
|
||
| 7244 | return -1; |
||
| 7245 | } |
||
| 7246 | var index = fromIndex == null ? 0 : toInteger(fromIndex); |
||
| 7247 | if (index < 0) { |
||
| 7248 | index = nativeMax(length + index, 0);
|
||
| 7249 | } |
||
| 7250 | return baseFindIndex(array, getIteratee(predicate, 3), index); |
||
| 7251 | } |
||
| 7252 | |||
| 7253 | /**
|
||
| 7254 | * This method is like `_.findIndex` except that it iterates over elements
|
||
| 7255 | * of `collection` from right to left.
|
||
| 7256 | *
|
||
| 7257 | * @static
|
||
| 7258 | * @memberOf _
|
||
| 7259 | * @since 2.0.0
|
||
| 7260 | * @category Array
|
||
| 7261 | * @param {Array} array The array to inspect.
|
||
| 7262 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 7263 | * @param {number} [fromIndex=array.length-1] The index to search from.
|
||
| 7264 | * @returns {number} Returns the index of the found element, else `-1`.
|
||
| 7265 | * @example
|
||
| 7266 | *
|
||
| 7267 | * var users = [
|
||
| 7268 | * { 'user': 'barney', 'active': true },
|
||
| 7269 | * { 'user': 'fred', 'active': false },
|
||
| 7270 | * { 'user': 'pebbles', 'active': false }
|
||
| 7271 | * ];
|
||
| 7272 | *
|
||
| 7273 | * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
|
||
| 7274 | * // => 2
|
||
| 7275 | *
|
||
| 7276 | * // The `_.matches` iteratee shorthand.
|
||
| 7277 | * _.findLastIndex(users, { 'user': 'barney', 'active': true });
|
||
| 7278 | * // => 0
|
||
| 7279 | *
|
||
| 7280 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 7281 | * _.findLastIndex(users, ['active', false]);
|
||
| 7282 | * // => 2
|
||
| 7283 | *
|
||
| 7284 | * // The `_.property` iteratee shorthand.
|
||
| 7285 | * _.findLastIndex(users, 'active');
|
||
| 7286 | * // => 0
|
||
| 7287 | */
|
||
| 7288 | function findLastIndex(array, predicate, fromIndex) { |
||
| 7289 | var length = array == null ? 0 : array.length; |
||
| 7290 | if (!length) {
|
||
| 7291 | return -1; |
||
| 7292 | } |
||
| 7293 | var index = length - 1; |
||
| 7294 | if (fromIndex !== undefined) { |
||
| 7295 | index = toInteger(fromIndex); |
||
| 7296 | index = fromIndex < 0
|
||
| 7297 | ? nativeMax(length + index, 0)
|
||
| 7298 | : nativeMin(index, length - 1);
|
||
| 7299 | } |
||
| 7300 | return baseFindIndex(array, getIteratee(predicate, 3), index, true); |
||
| 7301 | } |
||
| 7302 | |||
| 7303 | /**
|
||
| 7304 | * Flattens `array` a single level deep.
|
||
| 7305 | *
|
||
| 7306 | * @static
|
||
| 7307 | * @memberOf _
|
||
| 7308 | * @since 0.1.0
|
||
| 7309 | * @category Array
|
||
| 7310 | * @param {Array} array The array to flatten.
|
||
| 7311 | * @returns {Array} Returns the new flattened array.
|
||
| 7312 | * @example
|
||
| 7313 | *
|
||
| 7314 | * _.flatten([1, [2, [3, [4]], 5]]);
|
||
| 7315 | * // => [1, 2, [3, [4]], 5]
|
||
| 7316 | */
|
||
| 7317 | function flatten(array) { |
||
| 7318 | var length = array == null ? 0 : array.length; |
||
| 7319 | return length ? baseFlatten(array, 1) : []; |
||
| 7320 | } |
||
| 7321 | |||
| 7322 | /**
|
||
| 7323 | * Recursively flattens `array`.
|
||
| 7324 | *
|
||
| 7325 | * @static
|
||
| 7326 | * @memberOf _
|
||
| 7327 | * @since 3.0.0
|
||
| 7328 | * @category Array
|
||
| 7329 | * @param {Array} array The array to flatten.
|
||
| 7330 | * @returns {Array} Returns the new flattened array.
|
||
| 7331 | * @example
|
||
| 7332 | *
|
||
| 7333 | * _.flattenDeep([1, [2, [3, [4]], 5]]);
|
||
| 7334 | * // => [1, 2, 3, 4, 5]
|
||
| 7335 | */
|
||
| 7336 | function flattenDeep(array) { |
||
| 7337 | var length = array == null ? 0 : array.length; |
||
| 7338 | return length ? baseFlatten(array, INFINITY) : [];
|
||
| 7339 | } |
||
| 7340 | |||
| 7341 | /**
|
||
| 7342 | * Recursively flatten `array` up to `depth` times.
|
||
| 7343 | *
|
||
| 7344 | * @static
|
||
| 7345 | * @memberOf _
|
||
| 7346 | * @since 4.4.0
|
||
| 7347 | * @category Array
|
||
| 7348 | * @param {Array} array The array to flatten.
|
||
| 7349 | * @param {number} [depth=1] The maximum recursion depth.
|
||
| 7350 | * @returns {Array} Returns the new flattened array.
|
||
| 7351 | * @example
|
||
| 7352 | *
|
||
| 7353 | * var array = [1, [2, [3, [4]], 5]];
|
||
| 7354 | *
|
||
| 7355 | * _.flattenDepth(array, 1);
|
||
| 7356 | * // => [1, 2, [3, [4]], 5]
|
||
| 7357 | *
|
||
| 7358 | * _.flattenDepth(array, 2);
|
||
| 7359 | * // => [1, 2, 3, [4], 5]
|
||
| 7360 | */
|
||
| 7361 | function flattenDepth(array, depth) { |
||
| 7362 | var length = array == null ? 0 : array.length; |
||
| 7363 | if (!length) {
|
||
| 7364 | return [];
|
||
| 7365 | } |
||
| 7366 | depth = depth === undefined ? 1 : toInteger(depth); |
||
| 7367 | return baseFlatten(array, depth);
|
||
| 7368 | } |
||
| 7369 | |||
| 7370 | /**
|
||
| 7371 | * The inverse of `_.toPairs`; this method returns an object composed
|
||
| 7372 | * from key-value `pairs`.
|
||
| 7373 | *
|
||
| 7374 | * @static
|
||
| 7375 | * @memberOf _
|
||
| 7376 | * @since 4.0.0
|
||
| 7377 | * @category Array
|
||
| 7378 | * @param {Array} pairs The key-value pairs.
|
||
| 7379 | * @returns {Object} Returns the new object.
|
||
| 7380 | * @example
|
||
| 7381 | *
|
||
| 7382 | * _.fromPairs([['a', 1], ['b', 2]]);
|
||
| 7383 | * // => { 'a': 1, 'b': 2 }
|
||
| 7384 | */
|
||
| 7385 | function fromPairs(pairs) { |
||
| 7386 | var index = -1, |
||
| 7387 | length = pairs == null ? 0 : pairs.length, |
||
| 7388 | result = {};
|
||
| 7389 | |||
| 7390 | while (++index < length) {
|
||
| 7391 | var pair = pairs[index];
|
||
| 7392 | result[pair[0]] = pair[1]; |
||
| 7393 | } |
||
| 7394 | return result;
|
||
| 7395 | } |
||
| 7396 | |||
| 7397 | /**
|
||
| 7398 | * Gets the first element of `array`.
|
||
| 7399 | *
|
||
| 7400 | * @static
|
||
| 7401 | * @memberOf _
|
||
| 7402 | * @since 0.1.0
|
||
| 7403 | * @alias first
|
||
| 7404 | * @category Array
|
||
| 7405 | * @param {Array} array The array to query.
|
||
| 7406 | * @returns {*} Returns the first element of `array`.
|
||
| 7407 | * @example
|
||
| 7408 | *
|
||
| 7409 | * _.head([1, 2, 3]);
|
||
| 7410 | * // => 1
|
||
| 7411 | *
|
||
| 7412 | * _.head([]);
|
||
| 7413 | * // => undefined
|
||
| 7414 | */
|
||
| 7415 | function head(array) { |
||
| 7416 | return (array && array.length) ? array[0] : undefined; |
||
| 7417 | } |
||
| 7418 | |||
| 7419 | /**
|
||
| 7420 | * Gets the index at which the first occurrence of `value` is found in `array`
|
||
| 7421 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 7422 | * for equality comparisons. If `fromIndex` is negative, it's used as the
|
||
| 7423 | * offset from the end of `array`.
|
||
| 7424 | *
|
||
| 7425 | * @static
|
||
| 7426 | * @memberOf _
|
||
| 7427 | * @since 0.1.0
|
||
| 7428 | * @category Array
|
||
| 7429 | * @param {Array} array The array to inspect.
|
||
| 7430 | * @param {*} value The value to search for.
|
||
| 7431 | * @param {number} [fromIndex=0] The index to search from.
|
||
| 7432 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 7433 | * @example
|
||
| 7434 | *
|
||
| 7435 | * _.indexOf([1, 2, 1, 2], 2);
|
||
| 7436 | * // => 1
|
||
| 7437 | *
|
||
| 7438 | * // Search from the `fromIndex`.
|
||
| 7439 | * _.indexOf([1, 2, 1, 2], 2, 2);
|
||
| 7440 | * // => 3
|
||
| 7441 | */
|
||
| 7442 | function indexOf(array, value, fromIndex) { |
||
| 7443 | var length = array == null ? 0 : array.length; |
||
| 7444 | if (!length) {
|
||
| 7445 | return -1; |
||
| 7446 | } |
||
| 7447 | var index = fromIndex == null ? 0 : toInteger(fromIndex); |
||
| 7448 | if (index < 0) { |
||
| 7449 | index = nativeMax(length + index, 0);
|
||
| 7450 | } |
||
| 7451 | return baseIndexOf(array, value, index);
|
||
| 7452 | } |
||
| 7453 | |||
| 7454 | /**
|
||
| 7455 | * Gets all but the last element of `array`.
|
||
| 7456 | *
|
||
| 7457 | * @static
|
||
| 7458 | * @memberOf _
|
||
| 7459 | * @since 0.1.0
|
||
| 7460 | * @category Array
|
||
| 7461 | * @param {Array} array The array to query.
|
||
| 7462 | * @returns {Array} Returns the slice of `array`.
|
||
| 7463 | * @example
|
||
| 7464 | *
|
||
| 7465 | * _.initial([1, 2, 3]);
|
||
| 7466 | * // => [1, 2]
|
||
| 7467 | */
|
||
| 7468 | function initial(array) { |
||
| 7469 | var length = array == null ? 0 : array.length; |
||
| 7470 | return length ? baseSlice(array, 0, -1) : []; |
||
| 7471 | } |
||
| 7472 | |||
| 7473 | /**
|
||
| 7474 | * Creates an array of unique values that are included in all given arrays
|
||
| 7475 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 7476 | * for equality comparisons. The order and references of result values are
|
||
| 7477 | * determined by the first array.
|
||
| 7478 | *
|
||
| 7479 | * @static
|
||
| 7480 | * @memberOf _
|
||
| 7481 | * @since 0.1.0
|
||
| 7482 | * @category Array
|
||
| 7483 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 7484 | * @returns {Array} Returns the new array of intersecting values.
|
||
| 7485 | * @example
|
||
| 7486 | *
|
||
| 7487 | * _.intersection([2, 1], [2, 3]);
|
||
| 7488 | * // => [2]
|
||
| 7489 | */
|
||
| 7490 | var intersection = baseRest(function(arrays) { |
||
| 7491 | var mapped = arrayMap(arrays, castArrayLikeObject);
|
||
| 7492 | return (mapped.length && mapped[0] === arrays[0]) |
||
| 7493 | ? baseIntersection(mapped) |
||
| 7494 | : []; |
||
| 7495 | }); |
||
| 7496 | |||
| 7497 | /**
|
||
| 7498 | * This method is like `_.intersection` except that it accepts `iteratee`
|
||
| 7499 | * which is invoked for each element of each `arrays` to generate the criterion
|
||
| 7500 | * by which they're compared. The order and references of result values are
|
||
| 7501 | * determined by the first array. The iteratee is invoked with one argument:
|
||
| 7502 | * (value).
|
||
| 7503 | *
|
||
| 7504 | * @static
|
||
| 7505 | * @memberOf _
|
||
| 7506 | * @since 4.0.0
|
||
| 7507 | * @category Array
|
||
| 7508 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 7509 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 7510 | * @returns {Array} Returns the new array of intersecting values.
|
||
| 7511 | * @example
|
||
| 7512 | *
|
||
| 7513 | * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
||
| 7514 | * // => [2.1]
|
||
| 7515 | *
|
||
| 7516 | * // The `_.property` iteratee shorthand.
|
||
| 7517 | * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||
| 7518 | * // => [{ 'x': 1 }]
|
||
| 7519 | */
|
||
| 7520 | var intersectionBy = baseRest(function(arrays) { |
||
| 7521 | var iteratee = last(arrays),
|
||
| 7522 | mapped = arrayMap(arrays, castArrayLikeObject); |
||
| 7523 | |||
| 7524 | if (iteratee === last(mapped)) {
|
||
| 7525 | iteratee = undefined;
|
||
| 7526 | } else {
|
||
| 7527 | mapped.pop(); |
||
| 7528 | } |
||
| 7529 | return (mapped.length && mapped[0] === arrays[0]) |
||
| 7530 | ? baseIntersection(mapped, getIteratee(iteratee, 2))
|
||
| 7531 | : []; |
||
| 7532 | }); |
||
| 7533 | |||
| 7534 | /**
|
||
| 7535 | * This method is like `_.intersection` except that it accepts `comparator`
|
||
| 7536 | * which is invoked to compare elements of `arrays`. The order and references
|
||
| 7537 | * of result values are determined by the first array. The comparator is
|
||
| 7538 | * invoked with two arguments: (arrVal, othVal).
|
||
| 7539 | *
|
||
| 7540 | * @static
|
||
| 7541 | * @memberOf _
|
||
| 7542 | * @since 4.0.0
|
||
| 7543 | * @category Array
|
||
| 7544 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 7545 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 7546 | * @returns {Array} Returns the new array of intersecting values.
|
||
| 7547 | * @example
|
||
| 7548 | *
|
||
| 7549 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
||
| 7550 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
||
| 7551 | *
|
||
| 7552 | * _.intersectionWith(objects, others, _.isEqual);
|
||
| 7553 | * // => [{ 'x': 1, 'y': 2 }]
|
||
| 7554 | */
|
||
| 7555 | var intersectionWith = baseRest(function(arrays) { |
||
| 7556 | var comparator = last(arrays),
|
||
| 7557 | mapped = arrayMap(arrays, castArrayLikeObject); |
||
| 7558 | |||
| 7559 | comparator = typeof comparator == 'function' ? comparator : undefined; |
||
| 7560 | if (comparator) {
|
||
| 7561 | mapped.pop(); |
||
| 7562 | } |
||
| 7563 | return (mapped.length && mapped[0] === arrays[0]) |
||
| 7564 | ? baseIntersection(mapped, undefined, comparator)
|
||
| 7565 | : []; |
||
| 7566 | }); |
||
| 7567 | |||
| 7568 | /**
|
||
| 7569 | * Converts all elements in `array` into a string separated by `separator`.
|
||
| 7570 | *
|
||
| 7571 | * @static
|
||
| 7572 | * @memberOf _
|
||
| 7573 | * @since 4.0.0
|
||
| 7574 | * @category Array
|
||
| 7575 | * @param {Array} array The array to convert.
|
||
| 7576 | * @param {string} [separator=','] The element separator.
|
||
| 7577 | * @returns {string} Returns the joined string.
|
||
| 7578 | * @example
|
||
| 7579 | *
|
||
| 7580 | * _.join(['a', 'b', 'c'], '~');
|
||
| 7581 | * // => 'a~b~c'
|
||
| 7582 | */
|
||
| 7583 | function join(array, separator) { |
||
| 7584 | return array == null ? '' : nativeJoin.call(array, separator); |
||
| 7585 | } |
||
| 7586 | |||
| 7587 | /**
|
||
| 7588 | * Gets the last element of `array`.
|
||
| 7589 | *
|
||
| 7590 | * @static
|
||
| 7591 | * @memberOf _
|
||
| 7592 | * @since 0.1.0
|
||
| 7593 | * @category Array
|
||
| 7594 | * @param {Array} array The array to query.
|
||
| 7595 | * @returns {*} Returns the last element of `array`.
|
||
| 7596 | * @example
|
||
| 7597 | *
|
||
| 7598 | * _.last([1, 2, 3]);
|
||
| 7599 | * // => 3
|
||
| 7600 | */
|
||
| 7601 | function last(array) { |
||
| 7602 | var length = array == null ? 0 : array.length; |
||
| 7603 | return length ? array[length - 1] : undefined; |
||
| 7604 | } |
||
| 7605 | |||
| 7606 | /**
|
||
| 7607 | * This method is like `_.indexOf` except that it iterates over elements of
|
||
| 7608 | * `array` from right to left.
|
||
| 7609 | *
|
||
| 7610 | * @static
|
||
| 7611 | * @memberOf _
|
||
| 7612 | * @since 0.1.0
|
||
| 7613 | * @category Array
|
||
| 7614 | * @param {Array} array The array to inspect.
|
||
| 7615 | * @param {*} value The value to search for.
|
||
| 7616 | * @param {number} [fromIndex=array.length-1] The index to search from.
|
||
| 7617 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 7618 | * @example
|
||
| 7619 | *
|
||
| 7620 | * _.lastIndexOf([1, 2, 1, 2], 2);
|
||
| 7621 | * // => 3
|
||
| 7622 | *
|
||
| 7623 | * // Search from the `fromIndex`.
|
||
| 7624 | * _.lastIndexOf([1, 2, 1, 2], 2, 2);
|
||
| 7625 | * // => 1
|
||
| 7626 | */
|
||
| 7627 | function lastIndexOf(array, value, fromIndex) { |
||
| 7628 | var length = array == null ? 0 : array.length; |
||
| 7629 | if (!length) {
|
||
| 7630 | return -1; |
||
| 7631 | } |
||
| 7632 | var index = length;
|
||
| 7633 | if (fromIndex !== undefined) { |
||
| 7634 | index = toInteger(fromIndex); |
||
| 7635 | index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1); |
||
| 7636 | } |
||
| 7637 | return value === value
|
||
| 7638 | ? strictLastIndexOf(array, value, index) |
||
| 7639 | : baseFindIndex(array, baseIsNaN, index, true);
|
||
| 7640 | } |
||
| 7641 | |||
| 7642 | /**
|
||
| 7643 | * Gets the element at index `n` of `array`. If `n` is negative, the nth
|
||
| 7644 | * element from the end is returned.
|
||
| 7645 | *
|
||
| 7646 | * @static
|
||
| 7647 | * @memberOf _
|
||
| 7648 | * @since 4.11.0
|
||
| 7649 | * @category Array
|
||
| 7650 | * @param {Array} array The array to query.
|
||
| 7651 | * @param {number} [n=0] The index of the element to return.
|
||
| 7652 | * @returns {*} Returns the nth element of `array`.
|
||
| 7653 | * @example
|
||
| 7654 | *
|
||
| 7655 | * var array = ['a', 'b', 'c', 'd'];
|
||
| 7656 | *
|
||
| 7657 | * _.nth(array, 1);
|
||
| 7658 | * // => 'b'
|
||
| 7659 | *
|
||
| 7660 | * _.nth(array, -2);
|
||
| 7661 | * // => 'c';
|
||
| 7662 | */
|
||
| 7663 | function nth(array, n) { |
||
| 7664 | return (array && array.length) ? baseNth(array, toInteger(n)) : undefined; |
||
| 7665 | } |
||
| 7666 | |||
| 7667 | /**
|
||
| 7668 | * Removes all given values from `array` using
|
||
| 7669 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 7670 | * for equality comparisons.
|
||
| 7671 | *
|
||
| 7672 | * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
|
||
| 7673 | * to remove elements from an array by predicate.
|
||
| 7674 | *
|
||
| 7675 | * @static
|
||
| 7676 | * @memberOf _
|
||
| 7677 | * @since 2.0.0
|
||
| 7678 | * @category Array
|
||
| 7679 | * @param {Array} array The array to modify.
|
||
| 7680 | * @param {...*} [values] The values to remove.
|
||
| 7681 | * @returns {Array} Returns `array`.
|
||
| 7682 | * @example
|
||
| 7683 | *
|
||
| 7684 | * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
|
||
| 7685 | *
|
||
| 7686 | * _.pull(array, 'a', 'c');
|
||
| 7687 | * console.log(array);
|
||
| 7688 | * // => ['b', 'b']
|
||
| 7689 | */
|
||
| 7690 | var pull = baseRest(pullAll);
|
||
| 7691 | |||
| 7692 | /**
|
||
| 7693 | * This method is like `_.pull` except that it accepts an array of values to remove.
|
||
| 7694 | *
|
||
| 7695 | * **Note:** Unlike `_.difference`, this method mutates `array`.
|
||
| 7696 | *
|
||
| 7697 | * @static
|
||
| 7698 | * @memberOf _
|
||
| 7699 | * @since 4.0.0
|
||
| 7700 | * @category Array
|
||
| 7701 | * @param {Array} array The array to modify.
|
||
| 7702 | * @param {Array} values The values to remove.
|
||
| 7703 | * @returns {Array} Returns `array`.
|
||
| 7704 | * @example
|
||
| 7705 | *
|
||
| 7706 | * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
|
||
| 7707 | *
|
||
| 7708 | * _.pullAll(array, ['a', 'c']);
|
||
| 7709 | * console.log(array);
|
||
| 7710 | * // => ['b', 'b']
|
||
| 7711 | */
|
||
| 7712 | function pullAll(array, values) { |
||
| 7713 | return (array && array.length && values && values.length)
|
||
| 7714 | ? basePullAll(array, values) |
||
| 7715 | : array; |
||
| 7716 | } |
||
| 7717 | |||
| 7718 | /**
|
||
| 7719 | * This method is like `_.pullAll` except that it accepts `iteratee` which is
|
||
| 7720 | * invoked for each element of `array` and `values` to generate the criterion
|
||
| 7721 | * by which they're compared. The iteratee is invoked with one argument: (value).
|
||
| 7722 | *
|
||
| 7723 | * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
|
||
| 7724 | *
|
||
| 7725 | * @static
|
||
| 7726 | * @memberOf _
|
||
| 7727 | * @since 4.0.0
|
||
| 7728 | * @category Array
|
||
| 7729 | * @param {Array} array The array to modify.
|
||
| 7730 | * @param {Array} values The values to remove.
|
||
| 7731 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 7732 | * @returns {Array} Returns `array`.
|
||
| 7733 | * @example
|
||
| 7734 | *
|
||
| 7735 | * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
|
||
| 7736 | *
|
||
| 7737 | * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
|
||
| 7738 | * console.log(array);
|
||
| 7739 | * // => [{ 'x': 2 }]
|
||
| 7740 | */
|
||
| 7741 | function pullAllBy(array, values, iteratee) { |
||
| 7742 | return (array && array.length && values && values.length)
|
||
| 7743 | ? basePullAll(array, values, getIteratee(iteratee, 2))
|
||
| 7744 | : array; |
||
| 7745 | } |
||
| 7746 | |||
| 7747 | /**
|
||
| 7748 | * This method is like `_.pullAll` except that it accepts `comparator` which
|
||
| 7749 | * is invoked to compare elements of `array` to `values`. The comparator is
|
||
| 7750 | * invoked with two arguments: (arrVal, othVal).
|
||
| 7751 | *
|
||
| 7752 | * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
|
||
| 7753 | *
|
||
| 7754 | * @static
|
||
| 7755 | * @memberOf _
|
||
| 7756 | * @since 4.6.0
|
||
| 7757 | * @category Array
|
||
| 7758 | * @param {Array} array The array to modify.
|
||
| 7759 | * @param {Array} values The values to remove.
|
||
| 7760 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 7761 | * @returns {Array} Returns `array`.
|
||
| 7762 | * @example
|
||
| 7763 | *
|
||
| 7764 | * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
|
||
| 7765 | *
|
||
| 7766 | * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
|
||
| 7767 | * console.log(array);
|
||
| 7768 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
|
||
| 7769 | */
|
||
| 7770 | function pullAllWith(array, values, comparator) { |
||
| 7771 | return (array && array.length && values && values.length)
|
||
| 7772 | ? basePullAll(array, values, undefined, comparator)
|
||
| 7773 | : array; |
||
| 7774 | } |
||
| 7775 | |||
| 7776 | /**
|
||
| 7777 | * Removes elements from `array` corresponding to `indexes` and returns an
|
||
| 7778 | * array of removed elements.
|
||
| 7779 | *
|
||
| 7780 | * **Note:** Unlike `_.at`, this method mutates `array`.
|
||
| 7781 | *
|
||
| 7782 | * @static
|
||
| 7783 | * @memberOf _
|
||
| 7784 | * @since 3.0.0
|
||
| 7785 | * @category Array
|
||
| 7786 | * @param {Array} array The array to modify.
|
||
| 7787 | * @param {...(number|number[])} [indexes] The indexes of elements to remove.
|
||
| 7788 | * @returns {Array} Returns the new array of removed elements.
|
||
| 7789 | * @example
|
||
| 7790 | *
|
||
| 7791 | * var array = ['a', 'b', 'c', 'd'];
|
||
| 7792 | * var pulled = _.pullAt(array, [1, 3]);
|
||
| 7793 | *
|
||
| 7794 | * console.log(array);
|
||
| 7795 | * // => ['a', 'c']
|
||
| 7796 | *
|
||
| 7797 | * console.log(pulled);
|
||
| 7798 | * // => ['b', 'd']
|
||
| 7799 | */
|
||
| 7800 | var pullAt = flatRest(function(array, indexes) { |
||
| 7801 | var length = array == null ? 0 : array.length, |
||
| 7802 | result = baseAt(array, indexes); |
||
| 7803 | |||
| 7804 | basePullAt(array, arrayMap(indexes, function(index) {
|
||
| 7805 | return isIndex(index, length) ? +index : index;
|
||
| 7806 | }).sort(compareAscending)); |
||
| 7807 | |||
| 7808 | return result;
|
||
| 7809 | }); |
||
| 7810 | |||
| 7811 | /**
|
||
| 7812 | * Removes all elements from `array` that `predicate` returns truthy for
|
||
| 7813 | * and returns an array of the removed elements. The predicate is invoked
|
||
| 7814 | * with three arguments: (value, index, array).
|
||
| 7815 | *
|
||
| 7816 | * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
|
||
| 7817 | * to pull elements from an array by value.
|
||
| 7818 | *
|
||
| 7819 | * @static
|
||
| 7820 | * @memberOf _
|
||
| 7821 | * @since 2.0.0
|
||
| 7822 | * @category Array
|
||
| 7823 | * @param {Array} array The array to modify.
|
||
| 7824 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 7825 | * @returns {Array} Returns the new array of removed elements.
|
||
| 7826 | * @example
|
||
| 7827 | *
|
||
| 7828 | * var array = [1, 2, 3, 4];
|
||
| 7829 | * var evens = _.remove(array, function(n) {
|
||
| 7830 | * return n % 2 == 0;
|
||
| 7831 | * });
|
||
| 7832 | *
|
||
| 7833 | * console.log(array);
|
||
| 7834 | * // => [1, 3]
|
||
| 7835 | *
|
||
| 7836 | * console.log(evens);
|
||
| 7837 | * // => [2, 4]
|
||
| 7838 | */
|
||
| 7839 | function remove(array, predicate) { |
||
| 7840 | var result = [];
|
||
| 7841 | if (!(array && array.length)) {
|
||
| 7842 | return result;
|
||
| 7843 | } |
||
| 7844 | var index = -1, |
||
| 7845 | indexes = [], |
||
| 7846 | length = array.length; |
||
| 7847 | |||
| 7848 | predicate = getIteratee(predicate, 3);
|
||
| 7849 | while (++index < length) {
|
||
| 7850 | var value = array[index];
|
||
| 7851 | if (predicate(value, index, array)) {
|
||
| 7852 | result.push(value); |
||
| 7853 | indexes.push(index); |
||
| 7854 | } |
||
| 7855 | } |
||
| 7856 | basePullAt(array, indexes); |
||
| 7857 | return result;
|
||
| 7858 | } |
||
| 7859 | |||
| 7860 | /**
|
||
| 7861 | * Reverses `array` so that the first element becomes the last, the second
|
||
| 7862 | * element becomes the second to last, and so on.
|
||
| 7863 | *
|
||
| 7864 | * **Note:** This method mutates `array` and is based on
|
||
| 7865 | * [`Array#reverse`](https://mdn.io/Array/reverse).
|
||
| 7866 | *
|
||
| 7867 | * @static
|
||
| 7868 | * @memberOf _
|
||
| 7869 | * @since 4.0.0
|
||
| 7870 | * @category Array
|
||
| 7871 | * @param {Array} array The array to modify.
|
||
| 7872 | * @returns {Array} Returns `array`.
|
||
| 7873 | * @example
|
||
| 7874 | *
|
||
| 7875 | * var array = [1, 2, 3];
|
||
| 7876 | *
|
||
| 7877 | * _.reverse(array);
|
||
| 7878 | * // => [3, 2, 1]
|
||
| 7879 | *
|
||
| 7880 | * console.log(array);
|
||
| 7881 | * // => [3, 2, 1]
|
||
| 7882 | */
|
||
| 7883 | function reverse(array) { |
||
| 7884 | return array == null ? array : nativeReverse.call(array); |
||
| 7885 | } |
||
| 7886 | |||
| 7887 | /**
|
||
| 7888 | * Creates a slice of `array` from `start` up to, but not including, `end`.
|
||
| 7889 | *
|
||
| 7890 | * **Note:** This method is used instead of
|
||
| 7891 | * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
|
||
| 7892 | * returned.
|
||
| 7893 | *
|
||
| 7894 | * @static
|
||
| 7895 | * @memberOf _
|
||
| 7896 | * @since 3.0.0
|
||
| 7897 | * @category Array
|
||
| 7898 | * @param {Array} array The array to slice.
|
||
| 7899 | * @param {number} [start=0] The start position.
|
||
| 7900 | * @param {number} [end=array.length] The end position.
|
||
| 7901 | * @returns {Array} Returns the slice of `array`.
|
||
| 7902 | */
|
||
| 7903 | function slice(array, start, end) { |
||
| 7904 | var length = array == null ? 0 : array.length; |
||
| 7905 | if (!length) {
|
||
| 7906 | return [];
|
||
| 7907 | } |
||
| 7908 | if (end && typeof end != 'number' && isIterateeCall(array, start, end)) { |
||
| 7909 | start = 0;
|
||
| 7910 | end = length; |
||
| 7911 | } |
||
| 7912 | else {
|
||
| 7913 | start = start == null ? 0 : toInteger(start); |
||
| 7914 | end = end === undefined ? length : toInteger(end);
|
||
| 7915 | } |
||
| 7916 | return baseSlice(array, start, end);
|
||
| 7917 | } |
||
| 7918 | |||
| 7919 | /**
|
||
| 7920 | * Uses a binary search to determine the lowest index at which `value`
|
||
| 7921 | * should be inserted into `array` in order to maintain its sort order.
|
||
| 7922 | *
|
||
| 7923 | * @static
|
||
| 7924 | * @memberOf _
|
||
| 7925 | * @since 0.1.0
|
||
| 7926 | * @category Array
|
||
| 7927 | * @param {Array} array The sorted array to inspect.
|
||
| 7928 | * @param {*} value The value to evaluate.
|
||
| 7929 | * @returns {number} Returns the index at which `value` should be inserted
|
||
| 7930 | * into `array`.
|
||
| 7931 | * @example
|
||
| 7932 | *
|
||
| 7933 | * _.sortedIndex([30, 50], 40);
|
||
| 7934 | * // => 1
|
||
| 7935 | */
|
||
| 7936 | function sortedIndex(array, value) { |
||
| 7937 | return baseSortedIndex(array, value);
|
||
| 7938 | } |
||
| 7939 | |||
| 7940 | /**
|
||
| 7941 | * This method is like `_.sortedIndex` except that it accepts `iteratee`
|
||
| 7942 | * which is invoked for `value` and each element of `array` to compute their
|
||
| 7943 | * sort ranking. The iteratee is invoked with one argument: (value).
|
||
| 7944 | *
|
||
| 7945 | * @static
|
||
| 7946 | * @memberOf _
|
||
| 7947 | * @since 4.0.0
|
||
| 7948 | * @category Array
|
||
| 7949 | * @param {Array} array The sorted array to inspect.
|
||
| 7950 | * @param {*} value The value to evaluate.
|
||
| 7951 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 7952 | * @returns {number} Returns the index at which `value` should be inserted
|
||
| 7953 | * into `array`.
|
||
| 7954 | * @example
|
||
| 7955 | *
|
||
| 7956 | * var objects = [{ 'x': 4 }, { 'x': 5 }];
|
||
| 7957 | *
|
||
| 7958 | * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
|
||
| 7959 | * // => 0
|
||
| 7960 | *
|
||
| 7961 | * // The `_.property` iteratee shorthand.
|
||
| 7962 | * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
|
||
| 7963 | * // => 0
|
||
| 7964 | */
|
||
| 7965 | function sortedIndexBy(array, value, iteratee) { |
||
| 7966 | return baseSortedIndexBy(array, value, getIteratee(iteratee, 2)); |
||
| 7967 | } |
||
| 7968 | |||
| 7969 | /**
|
||
| 7970 | * This method is like `_.indexOf` except that it performs a binary
|
||
| 7971 | * search on a sorted `array`.
|
||
| 7972 | *
|
||
| 7973 | * @static
|
||
| 7974 | * @memberOf _
|
||
| 7975 | * @since 4.0.0
|
||
| 7976 | * @category Array
|
||
| 7977 | * @param {Array} array The array to inspect.
|
||
| 7978 | * @param {*} value The value to search for.
|
||
| 7979 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 7980 | * @example
|
||
| 7981 | *
|
||
| 7982 | * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
|
||
| 7983 | * // => 1
|
||
| 7984 | */
|
||
| 7985 | function sortedIndexOf(array, value) { |
||
| 7986 | var length = array == null ? 0 : array.length; |
||
| 7987 | if (length) {
|
||
| 7988 | var index = baseSortedIndex(array, value);
|
||
| 7989 | if (index < length && eq(array[index], value)) {
|
||
| 7990 | return index;
|
||
| 7991 | } |
||
| 7992 | } |
||
| 7993 | return -1; |
||
| 7994 | } |
||
| 7995 | |||
| 7996 | /**
|
||
| 7997 | * This method is like `_.sortedIndex` except that it returns the highest
|
||
| 7998 | * index at which `value` should be inserted into `array` in order to
|
||
| 7999 | * maintain its sort order.
|
||
| 8000 | *
|
||
| 8001 | * @static
|
||
| 8002 | * @memberOf _
|
||
| 8003 | * @since 3.0.0
|
||
| 8004 | * @category Array
|
||
| 8005 | * @param {Array} array The sorted array to inspect.
|
||
| 8006 | * @param {*} value The value to evaluate.
|
||
| 8007 | * @returns {number} Returns the index at which `value` should be inserted
|
||
| 8008 | * into `array`.
|
||
| 8009 | * @example
|
||
| 8010 | *
|
||
| 8011 | * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
|
||
| 8012 | * // => 4
|
||
| 8013 | */
|
||
| 8014 | function sortedLastIndex(array, value) { |
||
| 8015 | return baseSortedIndex(array, value, true); |
||
| 8016 | } |
||
| 8017 | |||
| 8018 | /**
|
||
| 8019 | * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
|
||
| 8020 | * which is invoked for `value` and each element of `array` to compute their
|
||
| 8021 | * sort ranking. The iteratee is invoked with one argument: (value).
|
||
| 8022 | *
|
||
| 8023 | * @static
|
||
| 8024 | * @memberOf _
|
||
| 8025 | * @since 4.0.0
|
||
| 8026 | * @category Array
|
||
| 8027 | * @param {Array} array The sorted array to inspect.
|
||
| 8028 | * @param {*} value The value to evaluate.
|
||
| 8029 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 8030 | * @returns {number} Returns the index at which `value` should be inserted
|
||
| 8031 | * into `array`.
|
||
| 8032 | * @example
|
||
| 8033 | *
|
||
| 8034 | * var objects = [{ 'x': 4 }, { 'x': 5 }];
|
||
| 8035 | *
|
||
| 8036 | * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
|
||
| 8037 | * // => 1
|
||
| 8038 | *
|
||
| 8039 | * // The `_.property` iteratee shorthand.
|
||
| 8040 | * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
|
||
| 8041 | * // => 1
|
||
| 8042 | */
|
||
| 8043 | function sortedLastIndexBy(array, value, iteratee) { |
||
| 8044 | return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true); |
||
| 8045 | } |
||
| 8046 | |||
| 8047 | /**
|
||
| 8048 | * This method is like `_.lastIndexOf` except that it performs a binary
|
||
| 8049 | * search on a sorted `array`.
|
||
| 8050 | *
|
||
| 8051 | * @static
|
||
| 8052 | * @memberOf _
|
||
| 8053 | * @since 4.0.0
|
||
| 8054 | * @category Array
|
||
| 8055 | * @param {Array} array The array to inspect.
|
||
| 8056 | * @param {*} value The value to search for.
|
||
| 8057 | * @returns {number} Returns the index of the matched value, else `-1`.
|
||
| 8058 | * @example
|
||
| 8059 | *
|
||
| 8060 | * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
|
||
| 8061 | * // => 3
|
||
| 8062 | */
|
||
| 8063 | function sortedLastIndexOf(array, value) { |
||
| 8064 | var length = array == null ? 0 : array.length; |
||
| 8065 | if (length) {
|
||
| 8066 | var index = baseSortedIndex(array, value, true) - 1; |
||
| 8067 | if (eq(array[index], value)) {
|
||
| 8068 | return index;
|
||
| 8069 | } |
||
| 8070 | } |
||
| 8071 | return -1; |
||
| 8072 | } |
||
| 8073 | |||
| 8074 | /**
|
||
| 8075 | * This method is like `_.uniq` except that it's designed and optimized
|
||
| 8076 | * for sorted arrays.
|
||
| 8077 | *
|
||
| 8078 | * @static
|
||
| 8079 | * @memberOf _
|
||
| 8080 | * @since 4.0.0
|
||
| 8081 | * @category Array
|
||
| 8082 | * @param {Array} array The array to inspect.
|
||
| 8083 | * @returns {Array} Returns the new duplicate free array.
|
||
| 8084 | * @example
|
||
| 8085 | *
|
||
| 8086 | * _.sortedUniq([1, 1, 2]);
|
||
| 8087 | * // => [1, 2]
|
||
| 8088 | */
|
||
| 8089 | function sortedUniq(array) { |
||
| 8090 | return (array && array.length)
|
||
| 8091 | ? baseSortedUniq(array) |
||
| 8092 | : []; |
||
| 8093 | } |
||
| 8094 | |||
| 8095 | /**
|
||
| 8096 | * This method is like `_.uniqBy` except that it's designed and optimized
|
||
| 8097 | * for sorted arrays.
|
||
| 8098 | *
|
||
| 8099 | * @static
|
||
| 8100 | * @memberOf _
|
||
| 8101 | * @since 4.0.0
|
||
| 8102 | * @category Array
|
||
| 8103 | * @param {Array} array The array to inspect.
|
||
| 8104 | * @param {Function} [iteratee] The iteratee invoked per element.
|
||
| 8105 | * @returns {Array} Returns the new duplicate free array.
|
||
| 8106 | * @example
|
||
| 8107 | *
|
||
| 8108 | * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
|
||
| 8109 | * // => [1.1, 2.3]
|
||
| 8110 | */
|
||
| 8111 | function sortedUniqBy(array, iteratee) { |
||
| 8112 | return (array && array.length)
|
||
| 8113 | ? baseSortedUniq(array, getIteratee(iteratee, 2))
|
||
| 8114 | : []; |
||
| 8115 | } |
||
| 8116 | |||
| 8117 | /**
|
||
| 8118 | * Gets all but the first element of `array`.
|
||
| 8119 | *
|
||
| 8120 | * @static
|
||
| 8121 | * @memberOf _
|
||
| 8122 | * @since 4.0.0
|
||
| 8123 | * @category Array
|
||
| 8124 | * @param {Array} array The array to query.
|
||
| 8125 | * @returns {Array} Returns the slice of `array`.
|
||
| 8126 | * @example
|
||
| 8127 | *
|
||
| 8128 | * _.tail([1, 2, 3]);
|
||
| 8129 | * // => [2, 3]
|
||
| 8130 | */
|
||
| 8131 | function tail(array) { |
||
| 8132 | var length = array == null ? 0 : array.length; |
||
| 8133 | return length ? baseSlice(array, 1, length) : []; |
||
| 8134 | } |
||
| 8135 | |||
| 8136 | /**
|
||
| 8137 | * Creates a slice of `array` with `n` elements taken from the beginning.
|
||
| 8138 | *
|
||
| 8139 | * @static
|
||
| 8140 | * @memberOf _
|
||
| 8141 | * @since 0.1.0
|
||
| 8142 | * @category Array
|
||
| 8143 | * @param {Array} array The array to query.
|
||
| 8144 | * @param {number} [n=1] The number of elements to take.
|
||
| 8145 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 8146 | * @returns {Array} Returns the slice of `array`.
|
||
| 8147 | * @example
|
||
| 8148 | *
|
||
| 8149 | * _.take([1, 2, 3]);
|
||
| 8150 | * // => [1]
|
||
| 8151 | *
|
||
| 8152 | * _.take([1, 2, 3], 2);
|
||
| 8153 | * // => [1, 2]
|
||
| 8154 | *
|
||
| 8155 | * _.take([1, 2, 3], 5);
|
||
| 8156 | * // => [1, 2, 3]
|
||
| 8157 | *
|
||
| 8158 | * _.take([1, 2, 3], 0);
|
||
| 8159 | * // => []
|
||
| 8160 | */
|
||
| 8161 | function take(array, n, guard) { |
||
| 8162 | if (!(array && array.length)) {
|
||
| 8163 | return [];
|
||
| 8164 | } |
||
| 8165 | n = (guard || n === undefined) ? 1 : toInteger(n); |
||
| 8166 | return baseSlice(array, 0, n < 0 ? 0 : n); |
||
| 8167 | } |
||
| 8168 | |||
| 8169 | /**
|
||
| 8170 | * Creates a slice of `array` with `n` elements taken from the end.
|
||
| 8171 | *
|
||
| 8172 | * @static
|
||
| 8173 | * @memberOf _
|
||
| 8174 | * @since 3.0.0
|
||
| 8175 | * @category Array
|
||
| 8176 | * @param {Array} array The array to query.
|
||
| 8177 | * @param {number} [n=1] The number of elements to take.
|
||
| 8178 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 8179 | * @returns {Array} Returns the slice of `array`.
|
||
| 8180 | * @example
|
||
| 8181 | *
|
||
| 8182 | * _.takeRight([1, 2, 3]);
|
||
| 8183 | * // => [3]
|
||
| 8184 | *
|
||
| 8185 | * _.takeRight([1, 2, 3], 2);
|
||
| 8186 | * // => [2, 3]
|
||
| 8187 | *
|
||
| 8188 | * _.takeRight([1, 2, 3], 5);
|
||
| 8189 | * // => [1, 2, 3]
|
||
| 8190 | *
|
||
| 8191 | * _.takeRight([1, 2, 3], 0);
|
||
| 8192 | * // => []
|
||
| 8193 | */
|
||
| 8194 | function takeRight(array, n, guard) { |
||
| 8195 | var length = array == null ? 0 : array.length; |
||
| 8196 | if (!length) {
|
||
| 8197 | return [];
|
||
| 8198 | } |
||
| 8199 | n = (guard || n === undefined) ? 1 : toInteger(n); |
||
| 8200 | n = length - n; |
||
| 8201 | return baseSlice(array, n < 0 ? 0 : n, length); |
||
| 8202 | } |
||
| 8203 | |||
| 8204 | /**
|
||
| 8205 | * Creates a slice of `array` with elements taken from the end. Elements are
|
||
| 8206 | * taken until `predicate` returns falsey. The predicate is invoked with
|
||
| 8207 | * three arguments: (value, index, array).
|
||
| 8208 | *
|
||
| 8209 | * @static
|
||
| 8210 | * @memberOf _
|
||
| 8211 | * @since 3.0.0
|
||
| 8212 | * @category Array
|
||
| 8213 | * @param {Array} array The array to query.
|
||
| 8214 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 8215 | * @returns {Array} Returns the slice of `array`.
|
||
| 8216 | * @example
|
||
| 8217 | *
|
||
| 8218 | * var users = [
|
||
| 8219 | * { 'user': 'barney', 'active': true },
|
||
| 8220 | * { 'user': 'fred', 'active': false },
|
||
| 8221 | * { 'user': 'pebbles', 'active': false }
|
||
| 8222 | * ];
|
||
| 8223 | *
|
||
| 8224 | * _.takeRightWhile(users, function(o) { return !o.active; });
|
||
| 8225 | * // => objects for ['fred', 'pebbles']
|
||
| 8226 | *
|
||
| 8227 | * // The `_.matches` iteratee shorthand.
|
||
| 8228 | * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
|
||
| 8229 | * // => objects for ['pebbles']
|
||
| 8230 | *
|
||
| 8231 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 8232 | * _.takeRightWhile(users, ['active', false]);
|
||
| 8233 | * // => objects for ['fred', 'pebbles']
|
||
| 8234 | *
|
||
| 8235 | * // The `_.property` iteratee shorthand.
|
||
| 8236 | * _.takeRightWhile(users, 'active');
|
||
| 8237 | * // => []
|
||
| 8238 | */
|
||
| 8239 | function takeRightWhile(array, predicate) { |
||
| 8240 | return (array && array.length)
|
||
| 8241 | ? baseWhile(array, getIteratee(predicate, 3), false, true) |
||
| 8242 | : []; |
||
| 8243 | } |
||
| 8244 | |||
| 8245 | /**
|
||
| 8246 | * Creates a slice of `array` with elements taken from the beginning. Elements
|
||
| 8247 | * are taken until `predicate` returns falsey. The predicate is invoked with
|
||
| 8248 | * three arguments: (value, index, array).
|
||
| 8249 | *
|
||
| 8250 | * @static
|
||
| 8251 | * @memberOf _
|
||
| 8252 | * @since 3.0.0
|
||
| 8253 | * @category Array
|
||
| 8254 | * @param {Array} array The array to query.
|
||
| 8255 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 8256 | * @returns {Array} Returns the slice of `array`.
|
||
| 8257 | * @example
|
||
| 8258 | *
|
||
| 8259 | * var users = [
|
||
| 8260 | * { 'user': 'barney', 'active': false },
|
||
| 8261 | * { 'user': 'fred', 'active': false },
|
||
| 8262 | * { 'user': 'pebbles', 'active': true }
|
||
| 8263 | * ];
|
||
| 8264 | *
|
||
| 8265 | * _.takeWhile(users, function(o) { return !o.active; });
|
||
| 8266 | * // => objects for ['barney', 'fred']
|
||
| 8267 | *
|
||
| 8268 | * // The `_.matches` iteratee shorthand.
|
||
| 8269 | * _.takeWhile(users, { 'user': 'barney', 'active': false });
|
||
| 8270 | * // => objects for ['barney']
|
||
| 8271 | *
|
||
| 8272 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 8273 | * _.takeWhile(users, ['active', false]);
|
||
| 8274 | * // => objects for ['barney', 'fred']
|
||
| 8275 | *
|
||
| 8276 | * // The `_.property` iteratee shorthand.
|
||
| 8277 | * _.takeWhile(users, 'active');
|
||
| 8278 | * // => []
|
||
| 8279 | */
|
||
| 8280 | function takeWhile(array, predicate) { |
||
| 8281 | return (array && array.length)
|
||
| 8282 | ? baseWhile(array, getIteratee(predicate, 3))
|
||
| 8283 | : []; |
||
| 8284 | } |
||
| 8285 | |||
| 8286 | /**
|
||
| 8287 | * Creates an array of unique values, in order, from all given arrays using
|
||
| 8288 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 8289 | * for equality comparisons.
|
||
| 8290 | *
|
||
| 8291 | * @static
|
||
| 8292 | * @memberOf _
|
||
| 8293 | * @since 0.1.0
|
||
| 8294 | * @category Array
|
||
| 8295 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 8296 | * @returns {Array} Returns the new array of combined values.
|
||
| 8297 | * @example
|
||
| 8298 | *
|
||
| 8299 | * _.union([2], [1, 2]);
|
||
| 8300 | * // => [2, 1]
|
||
| 8301 | */
|
||
| 8302 | var union = baseRest(function(arrays) { |
||
| 8303 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); |
||
| 8304 | }); |
||
| 8305 | |||
| 8306 | /**
|
||
| 8307 | * This method is like `_.union` except that it accepts `iteratee` which is
|
||
| 8308 | * invoked for each element of each `arrays` to generate the criterion by
|
||
| 8309 | * which uniqueness is computed. Result values are chosen from the first
|
||
| 8310 | * array in which the value occurs. The iteratee is invoked with one argument:
|
||
| 8311 | * (value).
|
||
| 8312 | *
|
||
| 8313 | * @static
|
||
| 8314 | * @memberOf _
|
||
| 8315 | * @since 4.0.0
|
||
| 8316 | * @category Array
|
||
| 8317 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 8318 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 8319 | * @returns {Array} Returns the new array of combined values.
|
||
| 8320 | * @example
|
||
| 8321 | *
|
||
| 8322 | * _.unionBy([2.1], [1.2, 2.3], Math.floor);
|
||
| 8323 | * // => [2.1, 1.2]
|
||
| 8324 | *
|
||
| 8325 | * // The `_.property` iteratee shorthand.
|
||
| 8326 | * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||
| 8327 | * // => [{ 'x': 1 }, { 'x': 2 }]
|
||
| 8328 | */
|
||
| 8329 | var unionBy = baseRest(function(arrays) { |
||
| 8330 | var iteratee = last(arrays);
|
||
| 8331 | if (isArrayLikeObject(iteratee)) {
|
||
| 8332 | iteratee = undefined;
|
||
| 8333 | } |
||
| 8334 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)); |
||
| 8335 | }); |
||
| 8336 | |||
| 8337 | /**
|
||
| 8338 | * This method is like `_.union` except that it accepts `comparator` which
|
||
| 8339 | * is invoked to compare elements of `arrays`. Result values are chosen from
|
||
| 8340 | * the first array in which the value occurs. The comparator is invoked
|
||
| 8341 | * with two arguments: (arrVal, othVal).
|
||
| 8342 | *
|
||
| 8343 | * @static
|
||
| 8344 | * @memberOf _
|
||
| 8345 | * @since 4.0.0
|
||
| 8346 | * @category Array
|
||
| 8347 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 8348 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 8349 | * @returns {Array} Returns the new array of combined values.
|
||
| 8350 | * @example
|
||
| 8351 | *
|
||
| 8352 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
||
| 8353 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
||
| 8354 | *
|
||
| 8355 | * _.unionWith(objects, others, _.isEqual);
|
||
| 8356 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
||
| 8357 | */
|
||
| 8358 | var unionWith = baseRest(function(arrays) { |
||
| 8359 | var comparator = last(arrays);
|
||
| 8360 | comparator = typeof comparator == 'function' ? comparator : undefined; |
||
| 8361 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator); |
||
| 8362 | }); |
||
| 8363 | |||
| 8364 | /**
|
||
| 8365 | * Creates a duplicate-free version of an array, using
|
||
| 8366 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 8367 | * for equality comparisons, in which only the first occurrence of each element
|
||
| 8368 | * is kept. The order of result values is determined by the order they occur
|
||
| 8369 | * in the array.
|
||
| 8370 | *
|
||
| 8371 | * @static
|
||
| 8372 | * @memberOf _
|
||
| 8373 | * @since 0.1.0
|
||
| 8374 | * @category Array
|
||
| 8375 | * @param {Array} array The array to inspect.
|
||
| 8376 | * @returns {Array} Returns the new duplicate free array.
|
||
| 8377 | * @example
|
||
| 8378 | *
|
||
| 8379 | * _.uniq([2, 1, 2]);
|
||
| 8380 | * // => [2, 1]
|
||
| 8381 | */
|
||
| 8382 | function uniq(array) { |
||
| 8383 | return (array && array.length) ? baseUniq(array) : [];
|
||
| 8384 | } |
||
| 8385 | |||
| 8386 | /**
|
||
| 8387 | * This method is like `_.uniq` except that it accepts `iteratee` which is
|
||
| 8388 | * invoked for each element in `array` to generate the criterion by which
|
||
| 8389 | * uniqueness is computed. The order of result values is determined by the
|
||
| 8390 | * order they occur in the array. The iteratee is invoked with one argument:
|
||
| 8391 | * (value).
|
||
| 8392 | *
|
||
| 8393 | * @static
|
||
| 8394 | * @memberOf _
|
||
| 8395 | * @since 4.0.0
|
||
| 8396 | * @category Array
|
||
| 8397 | * @param {Array} array The array to inspect.
|
||
| 8398 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 8399 | * @returns {Array} Returns the new duplicate free array.
|
||
| 8400 | * @example
|
||
| 8401 | *
|
||
| 8402 | * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
|
||
| 8403 | * // => [2.1, 1.2]
|
||
| 8404 | *
|
||
| 8405 | * // The `_.property` iteratee shorthand.
|
||
| 8406 | * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
||
| 8407 | * // => [{ 'x': 1 }, { 'x': 2 }]
|
||
| 8408 | */
|
||
| 8409 | function uniqBy(array, iteratee) { |
||
| 8410 | return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : []; |
||
| 8411 | } |
||
| 8412 | |||
| 8413 | /**
|
||
| 8414 | * This method is like `_.uniq` except that it accepts `comparator` which
|
||
| 8415 | * is invoked to compare elements of `array`. The order of result values is
|
||
| 8416 | * determined by the order they occur in the array.The comparator is invoked
|
||
| 8417 | * with two arguments: (arrVal, othVal).
|
||
| 8418 | *
|
||
| 8419 | * @static
|
||
| 8420 | * @memberOf _
|
||
| 8421 | * @since 4.0.0
|
||
| 8422 | * @category Array
|
||
| 8423 | * @param {Array} array The array to inspect.
|
||
| 8424 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 8425 | * @returns {Array} Returns the new duplicate free array.
|
||
| 8426 | * @example
|
||
| 8427 | *
|
||
| 8428 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
||
| 8429 | *
|
||
| 8430 | * _.uniqWith(objects, _.isEqual);
|
||
| 8431 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
|
||
| 8432 | */
|
||
| 8433 | function uniqWith(array, comparator) { |
||
| 8434 | comparator = typeof comparator == 'function' ? comparator : undefined; |
||
| 8435 | return (array && array.length) ? baseUniq(array, undefined, comparator) : []; |
||
| 8436 | } |
||
| 8437 | |||
| 8438 | /**
|
||
| 8439 | * This method is like `_.zip` except that it accepts an array of grouped
|
||
| 8440 | * elements and creates an array regrouping the elements to their pre-zip
|
||
| 8441 | * configuration.
|
||
| 8442 | *
|
||
| 8443 | * @static
|
||
| 8444 | * @memberOf _
|
||
| 8445 | * @since 1.2.0
|
||
| 8446 | * @category Array
|
||
| 8447 | * @param {Array} array The array of grouped elements to process.
|
||
| 8448 | * @returns {Array} Returns the new array of regrouped elements.
|
||
| 8449 | * @example
|
||
| 8450 | *
|
||
| 8451 | * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
|
||
| 8452 | * // => [['a', 1, true], ['b', 2, false]]
|
||
| 8453 | *
|
||
| 8454 | * _.unzip(zipped);
|
||
| 8455 | * // => [['a', 'b'], [1, 2], [true, false]]
|
||
| 8456 | */
|
||
| 8457 | function unzip(array) { |
||
| 8458 | if (!(array && array.length)) {
|
||
| 8459 | return [];
|
||
| 8460 | } |
||
| 8461 | var length = 0; |
||
| 8462 | array = arrayFilter(array, function(group) {
|
||
| 8463 | if (isArrayLikeObject(group)) {
|
||
| 8464 | length = nativeMax(group.length, length); |
||
| 8465 | return true; |
||
| 8466 | } |
||
| 8467 | }); |
||
| 8468 | return baseTimes(length, function(index) { |
||
| 8469 | return arrayMap(array, baseProperty(index));
|
||
| 8470 | }); |
||
| 8471 | } |
||
| 8472 | |||
| 8473 | /**
|
||
| 8474 | * This method is like `_.unzip` except that it accepts `iteratee` to specify
|
||
| 8475 | * how regrouped values should be combined. The iteratee is invoked with the
|
||
| 8476 | * elements of each group: (...group).
|
||
| 8477 | *
|
||
| 8478 | * @static
|
||
| 8479 | * @memberOf _
|
||
| 8480 | * @since 3.8.0
|
||
| 8481 | * @category Array
|
||
| 8482 | * @param {Array} array The array of grouped elements to process.
|
||
| 8483 | * @param {Function} [iteratee=_.identity] The function to combine
|
||
| 8484 | * regrouped values.
|
||
| 8485 | * @returns {Array} Returns the new array of regrouped elements.
|
||
| 8486 | * @example
|
||
| 8487 | *
|
||
| 8488 | * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
|
||
| 8489 | * // => [[1, 10, 100], [2, 20, 200]]
|
||
| 8490 | *
|
||
| 8491 | * _.unzipWith(zipped, _.add);
|
||
| 8492 | * // => [3, 30, 300]
|
||
| 8493 | */
|
||
| 8494 | function unzipWith(array, iteratee) { |
||
| 8495 | if (!(array && array.length)) {
|
||
| 8496 | return [];
|
||
| 8497 | } |
||
| 8498 | var result = unzip(array);
|
||
| 8499 | if (iteratee == null) { |
||
| 8500 | return result;
|
||
| 8501 | } |
||
| 8502 | return arrayMap(result, function(group) { |
||
| 8503 | return apply(iteratee, undefined, group); |
||
| 8504 | }); |
||
| 8505 | } |
||
| 8506 | |||
| 8507 | /**
|
||
| 8508 | * Creates an array excluding all given values using
|
||
| 8509 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 8510 | * for equality comparisons.
|
||
| 8511 | *
|
||
| 8512 | * **Note:** Unlike `_.pull`, this method returns a new array.
|
||
| 8513 | *
|
||
| 8514 | * @static
|
||
| 8515 | * @memberOf _
|
||
| 8516 | * @since 0.1.0
|
||
| 8517 | * @category Array
|
||
| 8518 | * @param {Array} array The array to inspect.
|
||
| 8519 | * @param {...*} [values] The values to exclude.
|
||
| 8520 | * @returns {Array} Returns the new array of filtered values.
|
||
| 8521 | * @see _.difference, _.xor
|
||
| 8522 | * @example
|
||
| 8523 | *
|
||
| 8524 | * _.without([2, 1, 2, 3], 1, 2);
|
||
| 8525 | * // => [3]
|
||
| 8526 | */
|
||
| 8527 | var without = baseRest(function(array, values) { |
||
| 8528 | return isArrayLikeObject(array)
|
||
| 8529 | ? baseDifference(array, values) |
||
| 8530 | : []; |
||
| 8531 | }); |
||
| 8532 | |||
| 8533 | /**
|
||
| 8534 | * Creates an array of unique values that is the
|
||
| 8535 | * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
|
||
| 8536 | * of the given arrays. The order of result values is determined by the order
|
||
| 8537 | * they occur in the arrays.
|
||
| 8538 | *
|
||
| 8539 | * @static
|
||
| 8540 | * @memberOf _
|
||
| 8541 | * @since 2.4.0
|
||
| 8542 | * @category Array
|
||
| 8543 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 8544 | * @returns {Array} Returns the new array of filtered values.
|
||
| 8545 | * @see _.difference, _.without
|
||
| 8546 | * @example
|
||
| 8547 | *
|
||
| 8548 | * _.xor([2, 1], [2, 3]);
|
||
| 8549 | * // => [1, 3]
|
||
| 8550 | */
|
||
| 8551 | var xor = baseRest(function(arrays) { |
||
| 8552 | return baseXor(arrayFilter(arrays, isArrayLikeObject));
|
||
| 8553 | }); |
||
| 8554 | |||
| 8555 | /**
|
||
| 8556 | * This method is like `_.xor` except that it accepts `iteratee` which is
|
||
| 8557 | * invoked for each element of each `arrays` to generate the criterion by
|
||
| 8558 | * which by which they're compared. The order of result values is determined
|
||
| 8559 | * by the order they occur in the arrays. The iteratee is invoked with one
|
||
| 8560 | * argument: (value).
|
||
| 8561 | *
|
||
| 8562 | * @static
|
||
| 8563 | * @memberOf _
|
||
| 8564 | * @since 4.0.0
|
||
| 8565 | * @category Array
|
||
| 8566 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 8567 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 8568 | * @returns {Array} Returns the new array of filtered values.
|
||
| 8569 | * @example
|
||
| 8570 | *
|
||
| 8571 | * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
||
| 8572 | * // => [1.2, 3.4]
|
||
| 8573 | *
|
||
| 8574 | * // The `_.property` iteratee shorthand.
|
||
| 8575 | * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||
| 8576 | * // => [{ 'x': 2 }]
|
||
| 8577 | */
|
||
| 8578 | var xorBy = baseRest(function(arrays) { |
||
| 8579 | var iteratee = last(arrays);
|
||
| 8580 | if (isArrayLikeObject(iteratee)) {
|
||
| 8581 | iteratee = undefined;
|
||
| 8582 | } |
||
| 8583 | return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2)); |
||
| 8584 | }); |
||
| 8585 | |||
| 8586 | /**
|
||
| 8587 | * This method is like `_.xor` except that it accepts `comparator` which is
|
||
| 8588 | * invoked to compare elements of `arrays`. The order of result values is
|
||
| 8589 | * determined by the order they occur in the arrays. The comparator is invoked
|
||
| 8590 | * with two arguments: (arrVal, othVal).
|
||
| 8591 | *
|
||
| 8592 | * @static
|
||
| 8593 | * @memberOf _
|
||
| 8594 | * @since 4.0.0
|
||
| 8595 | * @category Array
|
||
| 8596 | * @param {...Array} [arrays] The arrays to inspect.
|
||
| 8597 | * @param {Function} [comparator] The comparator invoked per element.
|
||
| 8598 | * @returns {Array} Returns the new array of filtered values.
|
||
| 8599 | * @example
|
||
| 8600 | *
|
||
| 8601 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
||
| 8602 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
||
| 8603 | *
|
||
| 8604 | * _.xorWith(objects, others, _.isEqual);
|
||
| 8605 | * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
||
| 8606 | */
|
||
| 8607 | var xorWith = baseRest(function(arrays) { |
||
| 8608 | var comparator = last(arrays);
|
||
| 8609 | comparator = typeof comparator == 'function' ? comparator : undefined; |
||
| 8610 | return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator); |
||
| 8611 | }); |
||
| 8612 | |||
| 8613 | /**
|
||
| 8614 | * Creates an array of grouped elements, the first of which contains the
|
||
| 8615 | * first elements of the given arrays, the second of which contains the
|
||
| 8616 | * second elements of the given arrays, and so on.
|
||
| 8617 | *
|
||
| 8618 | * @static
|
||
| 8619 | * @memberOf _
|
||
| 8620 | * @since 0.1.0
|
||
| 8621 | * @category Array
|
||
| 8622 | * @param {...Array} [arrays] The arrays to process.
|
||
| 8623 | * @returns {Array} Returns the new array of grouped elements.
|
||
| 8624 | * @example
|
||
| 8625 | *
|
||
| 8626 | * _.zip(['a', 'b'], [1, 2], [true, false]);
|
||
| 8627 | * // => [['a', 1, true], ['b', 2, false]]
|
||
| 8628 | */
|
||
| 8629 | var zip = baseRest(unzip);
|
||
| 8630 | |||
| 8631 | /**
|
||
| 8632 | * This method is like `_.fromPairs` except that it accepts two arrays,
|
||
| 8633 | * one of property identifiers and one of corresponding values.
|
||
| 8634 | *
|
||
| 8635 | * @static
|
||
| 8636 | * @memberOf _
|
||
| 8637 | * @since 0.4.0
|
||
| 8638 | * @category Array
|
||
| 8639 | * @param {Array} [props=[]] The property identifiers.
|
||
| 8640 | * @param {Array} [values=[]] The property values.
|
||
| 8641 | * @returns {Object} Returns the new object.
|
||
| 8642 | * @example
|
||
| 8643 | *
|
||
| 8644 | * _.zipObject(['a', 'b'], [1, 2]);
|
||
| 8645 | * // => { 'a': 1, 'b': 2 }
|
||
| 8646 | */
|
||
| 8647 | function zipObject(props, values) { |
||
| 8648 | return baseZipObject(props || [], values || [], assignValue);
|
||
| 8649 | } |
||
| 8650 | |||
| 8651 | /**
|
||
| 8652 | * This method is like `_.zipObject` except that it supports property paths.
|
||
| 8653 | *
|
||
| 8654 | * @static
|
||
| 8655 | * @memberOf _
|
||
| 8656 | * @since 4.1.0
|
||
| 8657 | * @category Array
|
||
| 8658 | * @param {Array} [props=[]] The property identifiers.
|
||
| 8659 | * @param {Array} [values=[]] The property values.
|
||
| 8660 | * @returns {Object} Returns the new object.
|
||
| 8661 | * @example
|
||
| 8662 | *
|
||
| 8663 | * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
|
||
| 8664 | * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
|
||
| 8665 | */
|
||
| 8666 | function zipObjectDeep(props, values) { |
||
| 8667 | return baseZipObject(props || [], values || [], baseSet);
|
||
| 8668 | } |
||
| 8669 | |||
| 8670 | /**
|
||
| 8671 | * This method is like `_.zip` except that it accepts `iteratee` to specify
|
||
| 8672 | * how grouped values should be combined. The iteratee is invoked with the
|
||
| 8673 | * elements of each group: (...group).
|
||
| 8674 | *
|
||
| 8675 | * @static
|
||
| 8676 | * @memberOf _
|
||
| 8677 | * @since 3.8.0
|
||
| 8678 | * @category Array
|
||
| 8679 | * @param {...Array} [arrays] The arrays to process.
|
||
| 8680 | * @param {Function} [iteratee=_.identity] The function to combine
|
||
| 8681 | * grouped values.
|
||
| 8682 | * @returns {Array} Returns the new array of grouped elements.
|
||
| 8683 | * @example
|
||
| 8684 | *
|
||
| 8685 | * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
|
||
| 8686 | * return a + b + c;
|
||
| 8687 | * });
|
||
| 8688 | * // => [111, 222]
|
||
| 8689 | */
|
||
| 8690 | var zipWith = baseRest(function(arrays) { |
||
| 8691 | var length = arrays.length,
|
||
| 8692 | iteratee = length > 1 ? arrays[length - 1] : undefined; |
||
| 8693 | |||
| 8694 | iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined; |
||
| 8695 | return unzipWith(arrays, iteratee);
|
||
| 8696 | }); |
||
| 8697 | |||
| 8698 | /*------------------------------------------------------------------------*/
|
||
| 8699 | |||
| 8700 | /**
|
||
| 8701 | * Creates a `lodash` wrapper instance that wraps `value` with explicit method
|
||
| 8702 | * chain sequences enabled. The result of such sequences must be unwrapped
|
||
| 8703 | * with `_#value`.
|
||
| 8704 | *
|
||
| 8705 | * @static
|
||
| 8706 | * @memberOf _
|
||
| 8707 | * @since 1.3.0
|
||
| 8708 | * @category Seq
|
||
| 8709 | * @param {*} value The value to wrap.
|
||
| 8710 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
||
| 8711 | * @example
|
||
| 8712 | *
|
||
| 8713 | * var users = [
|
||
| 8714 | * { 'user': 'barney', 'age': 36 },
|
||
| 8715 | * { 'user': 'fred', 'age': 40 },
|
||
| 8716 | * { 'user': 'pebbles', 'age': 1 }
|
||
| 8717 | * ];
|
||
| 8718 | *
|
||
| 8719 | * var youngest = _
|
||
| 8720 | * .chain(users)
|
||
| 8721 | * .sortBy('age')
|
||
| 8722 | * .map(function(o) {
|
||
| 8723 | * return o.user + ' is ' + o.age;
|
||
| 8724 | * })
|
||
| 8725 | * .head()
|
||
| 8726 | * .value();
|
||
| 8727 | * // => 'pebbles is 1'
|
||
| 8728 | */
|
||
| 8729 | function chain(value) { |
||
| 8730 | var result = lodash(value);
|
||
| 8731 | result.__chain__ = true;
|
||
| 8732 | return result;
|
||
| 8733 | } |
||
| 8734 | |||
| 8735 | /**
|
||
| 8736 | * This method invokes `interceptor` and returns `value`. The interceptor
|
||
| 8737 | * is invoked with one argument; (value). The purpose of this method is to
|
||
| 8738 | * "tap into" a method chain sequence in order to modify intermediate results.
|
||
| 8739 | *
|
||
| 8740 | * @static
|
||
| 8741 | * @memberOf _
|
||
| 8742 | * @since 0.1.0
|
||
| 8743 | * @category Seq
|
||
| 8744 | * @param {*} value The value to provide to `interceptor`.
|
||
| 8745 | * @param {Function} interceptor The function to invoke.
|
||
| 8746 | * @returns {*} Returns `value`.
|
||
| 8747 | * @example
|
||
| 8748 | *
|
||
| 8749 | * _([1, 2, 3])
|
||
| 8750 | * .tap(function(array) {
|
||
| 8751 | * // Mutate input array.
|
||
| 8752 | * array.pop();
|
||
| 8753 | * })
|
||
| 8754 | * .reverse()
|
||
| 8755 | * .value();
|
||
| 8756 | * // => [2, 1]
|
||
| 8757 | */
|
||
| 8758 | function tap(value, interceptor) { |
||
| 8759 | interceptor(value); |
||
| 8760 | return value;
|
||
| 8761 | } |
||
| 8762 | |||
| 8763 | /**
|
||
| 8764 | * This method is like `_.tap` except that it returns the result of `interceptor`.
|
||
| 8765 | * The purpose of this method is to "pass thru" values replacing intermediate
|
||
| 8766 | * results in a method chain sequence.
|
||
| 8767 | *
|
||
| 8768 | * @static
|
||
| 8769 | * @memberOf _
|
||
| 8770 | * @since 3.0.0
|
||
| 8771 | * @category Seq
|
||
| 8772 | * @param {*} value The value to provide to `interceptor`.
|
||
| 8773 | * @param {Function} interceptor The function to invoke.
|
||
| 8774 | * @returns {*} Returns the result of `interceptor`.
|
||
| 8775 | * @example
|
||
| 8776 | *
|
||
| 8777 | * _(' abc ')
|
||
| 8778 | * .chain()
|
||
| 8779 | * .trim()
|
||
| 8780 | * .thru(function(value) {
|
||
| 8781 | * return [value];
|
||
| 8782 | * })
|
||
| 8783 | * .value();
|
||
| 8784 | * // => ['abc']
|
||
| 8785 | */
|
||
| 8786 | function thru(value, interceptor) { |
||
| 8787 | return interceptor(value);
|
||
| 8788 | } |
||
| 8789 | |||
| 8790 | /**
|
||
| 8791 | * This method is the wrapper version of `_.at`.
|
||
| 8792 | *
|
||
| 8793 | * @name at
|
||
| 8794 | * @memberOf _
|
||
| 8795 | * @since 1.0.0
|
||
| 8796 | * @category Seq
|
||
| 8797 | * @param {...(string|string[])} [paths] The property paths to pick.
|
||
| 8798 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
||
| 8799 | * @example
|
||
| 8800 | *
|
||
| 8801 | * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
|
||
| 8802 | *
|
||
| 8803 | * _(object).at(['a[0].b.c', 'a[1]']).value();
|
||
| 8804 | * // => [3, 4]
|
||
| 8805 | */
|
||
| 8806 | var wrapperAt = flatRest(function(paths) { |
||
| 8807 | var length = paths.length,
|
||
| 8808 | start = length ? paths[0] : 0, |
||
| 8809 | value = this.__wrapped__,
|
||
| 8810 | interceptor = function(object) { return baseAt(object, paths); }; |
||
| 8811 | |||
| 8812 | if (length > 1 || this.__actions__.length || |
||
| 8813 | !(value instanceof LazyWrapper) || !isIndex(start)) {
|
||
| 8814 | return this.thru(interceptor); |
||
| 8815 | } |
||
| 8816 | value = value.slice(start, +start + (length ? 1 : 0)); |
||
| 8817 | value.__actions__.push({
|
||
| 8818 | 'func': thru,
|
||
| 8819 | 'args': [interceptor],
|
||
| 8820 | 'thisArg': undefined |
||
| 8821 | }); |
||
| 8822 | return new LodashWrapper(value, this.__chain__).thru(function(array) { |
||
| 8823 | if (length && !array.length) {
|
||
| 8824 | array.push(undefined);
|
||
| 8825 | } |
||
| 8826 | return array;
|
||
| 8827 | }); |
||
| 8828 | }); |
||
| 8829 | |||
| 8830 | /**
|
||
| 8831 | * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
|
||
| 8832 | *
|
||
| 8833 | * @name chain
|
||
| 8834 | * @memberOf _
|
||
| 8835 | * @since 0.1.0
|
||
| 8836 | * @category Seq
|
||
| 8837 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
||
| 8838 | * @example
|
||
| 8839 | *
|
||
| 8840 | * var users = [
|
||
| 8841 | * { 'user': 'barney', 'age': 36 },
|
||
| 8842 | * { 'user': 'fred', 'age': 40 }
|
||
| 8843 | * ];
|
||
| 8844 | *
|
||
| 8845 | * // A sequence without explicit chaining.
|
||
| 8846 | * _(users).head();
|
||
| 8847 | * // => { 'user': 'barney', 'age': 36 }
|
||
| 8848 | *
|
||
| 8849 | * // A sequence with explicit chaining.
|
||
| 8850 | * _(users)
|
||
| 8851 | * .chain()
|
||
| 8852 | * .head()
|
||
| 8853 | * .pick('user')
|
||
| 8854 | * .value();
|
||
| 8855 | * // => { 'user': 'barney' }
|
||
| 8856 | */
|
||
| 8857 | function wrapperChain() { |
||
| 8858 | return chain(this); |
||
| 8859 | } |
||
| 8860 | |||
| 8861 | /**
|
||
| 8862 | * Executes the chain sequence and returns the wrapped result.
|
||
| 8863 | *
|
||
| 8864 | * @name commit
|
||
| 8865 | * @memberOf _
|
||
| 8866 | * @since 3.2.0
|
||
| 8867 | * @category Seq
|
||
| 8868 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
||
| 8869 | * @example
|
||
| 8870 | *
|
||
| 8871 | * var array = [1, 2];
|
||
| 8872 | * var wrapped = _(array).push(3);
|
||
| 8873 | *
|
||
| 8874 | * console.log(array);
|
||
| 8875 | * // => [1, 2]
|
||
| 8876 | *
|
||
| 8877 | * wrapped = wrapped.commit();
|
||
| 8878 | * console.log(array);
|
||
| 8879 | * // => [1, 2, 3]
|
||
| 8880 | *
|
||
| 8881 | * wrapped.last();
|
||
| 8882 | * // => 3
|
||
| 8883 | *
|
||
| 8884 | * console.log(array);
|
||
| 8885 | * // => [1, 2, 3]
|
||
| 8886 | */
|
||
| 8887 | function wrapperCommit() { |
||
| 8888 | return new LodashWrapper(this.value(), this.__chain__); |
||
| 8889 | } |
||
| 8890 | |||
| 8891 | /**
|
||
| 8892 | * Gets the next value on a wrapped object following the
|
||
| 8893 | * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
|
||
| 8894 | *
|
||
| 8895 | * @name next
|
||
| 8896 | * @memberOf _
|
||
| 8897 | * @since 4.0.0
|
||
| 8898 | * @category Seq
|
||
| 8899 | * @returns {Object} Returns the next iterator value.
|
||
| 8900 | * @example
|
||
| 8901 | *
|
||
| 8902 | * var wrapped = _([1, 2]);
|
||
| 8903 | *
|
||
| 8904 | * wrapped.next();
|
||
| 8905 | * // => { 'done': false, 'value': 1 }
|
||
| 8906 | *
|
||
| 8907 | * wrapped.next();
|
||
| 8908 | * // => { 'done': false, 'value': 2 }
|
||
| 8909 | *
|
||
| 8910 | * wrapped.next();
|
||
| 8911 | * // => { 'done': true, 'value': undefined }
|
||
| 8912 | */
|
||
| 8913 | function wrapperNext() { |
||
| 8914 | if (this.__values__ === undefined) { |
||
| 8915 | this.__values__ = toArray(this.value()); |
||
| 8916 | } |
||
| 8917 | var done = this.__index__ >= this.__values__.length, |
||
| 8918 | value = done ? undefined : this.__values__[this.__index__++]; |
||
| 8919 | |||
| 8920 | return { 'done': done, 'value': value }; |
||
| 8921 | } |
||
| 8922 | |||
| 8923 | /**
|
||
| 8924 | * Enables the wrapper to be iterable.
|
||
| 8925 | *
|
||
| 8926 | * @name Symbol.iterator
|
||
| 8927 | * @memberOf _
|
||
| 8928 | * @since 4.0.0
|
||
| 8929 | * @category Seq
|
||
| 8930 | * @returns {Object} Returns the wrapper object.
|
||
| 8931 | * @example
|
||
| 8932 | *
|
||
| 8933 | * var wrapped = _([1, 2]);
|
||
| 8934 | *
|
||
| 8935 | * wrapped[Symbol.iterator]() === wrapped;
|
||
| 8936 | * // => true
|
||
| 8937 | *
|
||
| 8938 | * Array.from(wrapped);
|
||
| 8939 | * // => [1, 2]
|
||
| 8940 | */
|
||
| 8941 | function wrapperToIterator() { |
||
| 8942 | return this; |
||
| 8943 | } |
||
| 8944 | |||
| 8945 | /**
|
||
| 8946 | * Creates a clone of the chain sequence planting `value` as the wrapped value.
|
||
| 8947 | *
|
||
| 8948 | * @name plant
|
||
| 8949 | * @memberOf _
|
||
| 8950 | * @since 3.2.0
|
||
| 8951 | * @category Seq
|
||
| 8952 | * @param {*} value The value to plant.
|
||
| 8953 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
||
| 8954 | * @example
|
||
| 8955 | *
|
||
| 8956 | * function square(n) {
|
||
| 8957 | * return n * n;
|
||
| 8958 | * }
|
||
| 8959 | *
|
||
| 8960 | * var wrapped = _([1, 2]).map(square);
|
||
| 8961 | * var other = wrapped.plant([3, 4]);
|
||
| 8962 | *
|
||
| 8963 | * other.value();
|
||
| 8964 | * // => [9, 16]
|
||
| 8965 | *
|
||
| 8966 | * wrapped.value();
|
||
| 8967 | * // => [1, 4]
|
||
| 8968 | */
|
||
| 8969 | function wrapperPlant(value) { |
||
| 8970 | var result,
|
||
| 8971 | parent = this;
|
||
| 8972 | |||
| 8973 | while (parent instanceof baseLodash) { |
||
| 8974 | var clone = wrapperClone(parent);
|
||
| 8975 | clone.__index__ = 0;
|
||
| 8976 | clone.__values__ = undefined;
|
||
| 8977 | if (result) {
|
||
| 8978 | previous.__wrapped__ = clone; |
||
| 8979 | } else {
|
||
| 8980 | result = clone; |
||
| 8981 | } |
||
| 8982 | var previous = clone;
|
||
| 8983 | parent = parent.__wrapped__; |
||
| 8984 | } |
||
| 8985 | previous.__wrapped__ = value; |
||
| 8986 | return result;
|
||
| 8987 | } |
||
| 8988 | |||
| 8989 | /**
|
||
| 8990 | * This method is the wrapper version of `_.reverse`.
|
||
| 8991 | *
|
||
| 8992 | * **Note:** This method mutates the wrapped array.
|
||
| 8993 | *
|
||
| 8994 | * @name reverse
|
||
| 8995 | * @memberOf _
|
||
| 8996 | * @since 0.1.0
|
||
| 8997 | * @category Seq
|
||
| 8998 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
||
| 8999 | * @example
|
||
| 9000 | *
|
||
| 9001 | * var array = [1, 2, 3];
|
||
| 9002 | *
|
||
| 9003 | * _(array).reverse().value()
|
||
| 9004 | * // => [3, 2, 1]
|
||
| 9005 | *
|
||
| 9006 | * console.log(array);
|
||
| 9007 | * // => [3, 2, 1]
|
||
| 9008 | */
|
||
| 9009 | function wrapperReverse() { |
||
| 9010 | var value = this.__wrapped__; |
||
| 9011 | if (value instanceof LazyWrapper) { |
||
| 9012 | var wrapped = value;
|
||
| 9013 | if (this.__actions__.length) { |
||
| 9014 | wrapped = new LazyWrapper(this); |
||
| 9015 | } |
||
| 9016 | wrapped = wrapped.reverse(); |
||
| 9017 | wrapped.__actions__.push({
|
||
| 9018 | 'func': thru,
|
||
| 9019 | 'args': [reverse],
|
||
| 9020 | 'thisArg': undefined |
||
| 9021 | }); |
||
| 9022 | return new LodashWrapper(wrapped, this.__chain__); |
||
| 9023 | } |
||
| 9024 | return this.thru(reverse); |
||
| 9025 | } |
||
| 9026 | |||
| 9027 | /**
|
||
| 9028 | * Executes the chain sequence to resolve the unwrapped value.
|
||
| 9029 | *
|
||
| 9030 | * @name value
|
||
| 9031 | * @memberOf _
|
||
| 9032 | * @since 0.1.0
|
||
| 9033 | * @alias toJSON, valueOf
|
||
| 9034 | * @category Seq
|
||
| 9035 | * @returns {*} Returns the resolved unwrapped value.
|
||
| 9036 | * @example
|
||
| 9037 | *
|
||
| 9038 | * _([1, 2, 3]).value();
|
||
| 9039 | * // => [1, 2, 3]
|
||
| 9040 | */
|
||
| 9041 | function wrapperValue() { |
||
| 9042 | return baseWrapperValue(this.__wrapped__, this.__actions__); |
||
| 9043 | } |
||
| 9044 | |||
| 9045 | /*------------------------------------------------------------------------*/
|
||
| 9046 | |||
| 9047 | /**
|
||
| 9048 | * Creates an object composed of keys generated from the results of running
|
||
| 9049 | * each element of `collection` thru `iteratee`. The corresponding value of
|
||
| 9050 | * each key is the number of times the key was returned by `iteratee`. The
|
||
| 9051 | * iteratee is invoked with one argument: (value).
|
||
| 9052 | *
|
||
| 9053 | * @static
|
||
| 9054 | * @memberOf _
|
||
| 9055 | * @since 0.5.0
|
||
| 9056 | * @category Collection
|
||
| 9057 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9058 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
||
| 9059 | * @returns {Object} Returns the composed aggregate object.
|
||
| 9060 | * @example
|
||
| 9061 | *
|
||
| 9062 | * _.countBy([6.1, 4.2, 6.3], Math.floor);
|
||
| 9063 | * // => { '4': 1, '6': 2 }
|
||
| 9064 | *
|
||
| 9065 | * // The `_.property` iteratee shorthand.
|
||
| 9066 | * _.countBy(['one', 'two', 'three'], 'length');
|
||
| 9067 | * // => { '3': 2, '5': 1 }
|
||
| 9068 | */
|
||
| 9069 | var countBy = createAggregator(function(result, value, key) { |
||
| 9070 | if (hasOwnProperty.call(result, key)) {
|
||
| 9071 | ++result[key]; |
||
| 9072 | } else {
|
||
| 9073 | baseAssignValue(result, key, 1);
|
||
| 9074 | } |
||
| 9075 | }); |
||
| 9076 | |||
| 9077 | /**
|
||
| 9078 | * Checks if `predicate` returns truthy for **all** elements of `collection`.
|
||
| 9079 | * Iteration is stopped once `predicate` returns falsey. The predicate is
|
||
| 9080 | * invoked with three arguments: (value, index|key, collection).
|
||
| 9081 | *
|
||
| 9082 | * **Note:** This method returns `true` for
|
||
| 9083 | * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
|
||
| 9084 | * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
|
||
| 9085 | * elements of empty collections.
|
||
| 9086 | *
|
||
| 9087 | * @static
|
||
| 9088 | * @memberOf _
|
||
| 9089 | * @since 0.1.0
|
||
| 9090 | * @category Collection
|
||
| 9091 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9092 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 9093 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 9094 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
||
| 9095 | * else `false`.
|
||
| 9096 | * @example
|
||
| 9097 | *
|
||
| 9098 | * _.every([true, 1, null, 'yes'], Boolean);
|
||
| 9099 | * // => false
|
||
| 9100 | *
|
||
| 9101 | * var users = [
|
||
| 9102 | * { 'user': 'barney', 'age': 36, 'active': false },
|
||
| 9103 | * { 'user': 'fred', 'age': 40, 'active': false }
|
||
| 9104 | * ];
|
||
| 9105 | *
|
||
| 9106 | * // The `_.matches` iteratee shorthand.
|
||
| 9107 | * _.every(users, { 'user': 'barney', 'active': false });
|
||
| 9108 | * // => false
|
||
| 9109 | *
|
||
| 9110 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 9111 | * _.every(users, ['active', false]);
|
||
| 9112 | * // => true
|
||
| 9113 | *
|
||
| 9114 | * // The `_.property` iteratee shorthand.
|
||
| 9115 | * _.every(users, 'active');
|
||
| 9116 | * // => false
|
||
| 9117 | */
|
||
| 9118 | function every(collection, predicate, guard) { |
||
| 9119 | var func = isArray(collection) ? arrayEvery : baseEvery;
|
||
| 9120 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
||
| 9121 | predicate = undefined;
|
||
| 9122 | } |
||
| 9123 | return func(collection, getIteratee(predicate, 3)); |
||
| 9124 | } |
||
| 9125 | |||
| 9126 | /**
|
||
| 9127 | * Iterates over elements of `collection`, returning an array of all elements
|
||
| 9128 | * `predicate` returns truthy for. The predicate is invoked with three
|
||
| 9129 | * arguments: (value, index|key, collection).
|
||
| 9130 | *
|
||
| 9131 | * **Note:** Unlike `_.remove`, this method returns a new array.
|
||
| 9132 | *
|
||
| 9133 | * @static
|
||
| 9134 | * @memberOf _
|
||
| 9135 | * @since 0.1.0
|
||
| 9136 | * @category Collection
|
||
| 9137 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9138 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 9139 | * @returns {Array} Returns the new filtered array.
|
||
| 9140 | * @see _.reject
|
||
| 9141 | * @example
|
||
| 9142 | *
|
||
| 9143 | * var users = [
|
||
| 9144 | * { 'user': 'barney', 'age': 36, 'active': true },
|
||
| 9145 | * { 'user': 'fred', 'age': 40, 'active': false }
|
||
| 9146 | * ];
|
||
| 9147 | *
|
||
| 9148 | * _.filter(users, function(o) { return !o.active; });
|
||
| 9149 | * // => objects for ['fred']
|
||
| 9150 | *
|
||
| 9151 | * // The `_.matches` iteratee shorthand.
|
||
| 9152 | * _.filter(users, { 'age': 36, 'active': true });
|
||
| 9153 | * // => objects for ['barney']
|
||
| 9154 | *
|
||
| 9155 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 9156 | * _.filter(users, ['active', false]);
|
||
| 9157 | * // => objects for ['fred']
|
||
| 9158 | *
|
||
| 9159 | * // The `_.property` iteratee shorthand.
|
||
| 9160 | * _.filter(users, 'active');
|
||
| 9161 | * // => objects for ['barney']
|
||
| 9162 | */
|
||
| 9163 | function filter(collection, predicate) { |
||
| 9164 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
||
| 9165 | return func(collection, getIteratee(predicate, 3)); |
||
| 9166 | } |
||
| 9167 | |||
| 9168 | /**
|
||
| 9169 | * Iterates over elements of `collection`, returning the first element
|
||
| 9170 | * `predicate` returns truthy for. The predicate is invoked with three
|
||
| 9171 | * arguments: (value, index|key, collection).
|
||
| 9172 | *
|
||
| 9173 | * @static
|
||
| 9174 | * @memberOf _
|
||
| 9175 | * @since 0.1.0
|
||
| 9176 | * @category Collection
|
||
| 9177 | * @param {Array|Object} collection The collection to inspect.
|
||
| 9178 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 9179 | * @param {number} [fromIndex=0] The index to search from.
|
||
| 9180 | * @returns {*} Returns the matched element, else `undefined`.
|
||
| 9181 | * @example
|
||
| 9182 | *
|
||
| 9183 | * var users = [
|
||
| 9184 | * { 'user': 'barney', 'age': 36, 'active': true },
|
||
| 9185 | * { 'user': 'fred', 'age': 40, 'active': false },
|
||
| 9186 | * { 'user': 'pebbles', 'age': 1, 'active': true }
|
||
| 9187 | * ];
|
||
| 9188 | *
|
||
| 9189 | * _.find(users, function(o) { return o.age < 40; });
|
||
| 9190 | * // => object for 'barney'
|
||
| 9191 | *
|
||
| 9192 | * // The `_.matches` iteratee shorthand.
|
||
| 9193 | * _.find(users, { 'age': 1, 'active': true });
|
||
| 9194 | * // => object for 'pebbles'
|
||
| 9195 | *
|
||
| 9196 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 9197 | * _.find(users, ['active', false]);
|
||
| 9198 | * // => object for 'fred'
|
||
| 9199 | *
|
||
| 9200 | * // The `_.property` iteratee shorthand.
|
||
| 9201 | * _.find(users, 'active');
|
||
| 9202 | * // => object for 'barney'
|
||
| 9203 | */
|
||
| 9204 | var find = createFind(findIndex);
|
||
| 9205 | |||
| 9206 | /**
|
||
| 9207 | * This method is like `_.find` except that it iterates over elements of
|
||
| 9208 | * `collection` from right to left.
|
||
| 9209 | *
|
||
| 9210 | * @static
|
||
| 9211 | * @memberOf _
|
||
| 9212 | * @since 2.0.0
|
||
| 9213 | * @category Collection
|
||
| 9214 | * @param {Array|Object} collection The collection to inspect.
|
||
| 9215 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 9216 | * @param {number} [fromIndex=collection.length-1] The index to search from.
|
||
| 9217 | * @returns {*} Returns the matched element, else `undefined`.
|
||
| 9218 | * @example
|
||
| 9219 | *
|
||
| 9220 | * _.findLast([1, 2, 3, 4], function(n) {
|
||
| 9221 | * return n % 2 == 1;
|
||
| 9222 | * });
|
||
| 9223 | * // => 3
|
||
| 9224 | */
|
||
| 9225 | var findLast = createFind(findLastIndex);
|
||
| 9226 | |||
| 9227 | /**
|
||
| 9228 | * Creates a flattened array of values by running each element in `collection`
|
||
| 9229 | * thru `iteratee` and flattening the mapped results. The iteratee is invoked
|
||
| 9230 | * with three arguments: (value, index|key, collection).
|
||
| 9231 | *
|
||
| 9232 | * @static
|
||
| 9233 | * @memberOf _
|
||
| 9234 | * @since 4.0.0
|
||
| 9235 | * @category Collection
|
||
| 9236 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9237 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9238 | * @returns {Array} Returns the new flattened array.
|
||
| 9239 | * @example
|
||
| 9240 | *
|
||
| 9241 | * function duplicate(n) {
|
||
| 9242 | * return [n, n];
|
||
| 9243 | * }
|
||
| 9244 | *
|
||
| 9245 | * _.flatMap([1, 2], duplicate);
|
||
| 9246 | * // => [1, 1, 2, 2]
|
||
| 9247 | */
|
||
| 9248 | function flatMap(collection, iteratee) { |
||
| 9249 | return baseFlatten(map(collection, iteratee), 1); |
||
| 9250 | } |
||
| 9251 | |||
| 9252 | /**
|
||
| 9253 | * This method is like `_.flatMap` except that it recursively flattens the
|
||
| 9254 | * mapped results.
|
||
| 9255 | *
|
||
| 9256 | * @static
|
||
| 9257 | * @memberOf _
|
||
| 9258 | * @since 4.7.0
|
||
| 9259 | * @category Collection
|
||
| 9260 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9261 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9262 | * @returns {Array} Returns the new flattened array.
|
||
| 9263 | * @example
|
||
| 9264 | *
|
||
| 9265 | * function duplicate(n) {
|
||
| 9266 | * return [[[n, n]]];
|
||
| 9267 | * }
|
||
| 9268 | *
|
||
| 9269 | * _.flatMapDeep([1, 2], duplicate);
|
||
| 9270 | * // => [1, 1, 2, 2]
|
||
| 9271 | */
|
||
| 9272 | function flatMapDeep(collection, iteratee) { |
||
| 9273 | return baseFlatten(map(collection, iteratee), INFINITY);
|
||
| 9274 | } |
||
| 9275 | |||
| 9276 | /**
|
||
| 9277 | * This method is like `_.flatMap` except that it recursively flattens the
|
||
| 9278 | * mapped results up to `depth` times.
|
||
| 9279 | *
|
||
| 9280 | * @static
|
||
| 9281 | * @memberOf _
|
||
| 9282 | * @since 4.7.0
|
||
| 9283 | * @category Collection
|
||
| 9284 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9285 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9286 | * @param {number} [depth=1] The maximum recursion depth.
|
||
| 9287 | * @returns {Array} Returns the new flattened array.
|
||
| 9288 | * @example
|
||
| 9289 | *
|
||
| 9290 | * function duplicate(n) {
|
||
| 9291 | * return [[[n, n]]];
|
||
| 9292 | * }
|
||
| 9293 | *
|
||
| 9294 | * _.flatMapDepth([1, 2], duplicate, 2);
|
||
| 9295 | * // => [[1, 1], [2, 2]]
|
||
| 9296 | */
|
||
| 9297 | function flatMapDepth(collection, iteratee, depth) { |
||
| 9298 | depth = depth === undefined ? 1 : toInteger(depth); |
||
| 9299 | return baseFlatten(map(collection, iteratee), depth);
|
||
| 9300 | } |
||
| 9301 | |||
| 9302 | /**
|
||
| 9303 | * Iterates over elements of `collection` and invokes `iteratee` for each element.
|
||
| 9304 | * The iteratee is invoked with three arguments: (value, index|key, collection).
|
||
| 9305 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
||
| 9306 | *
|
||
| 9307 | * **Note:** As with other "Collections" methods, objects with a "length"
|
||
| 9308 | * property are iterated like arrays. To avoid this behavior use `_.forIn`
|
||
| 9309 | * or `_.forOwn` for object iteration.
|
||
| 9310 | *
|
||
| 9311 | * @static
|
||
| 9312 | * @memberOf _
|
||
| 9313 | * @since 0.1.0
|
||
| 9314 | * @alias each
|
||
| 9315 | * @category Collection
|
||
| 9316 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9317 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9318 | * @returns {Array|Object} Returns `collection`.
|
||
| 9319 | * @see _.forEachRight
|
||
| 9320 | * @example
|
||
| 9321 | *
|
||
| 9322 | * _.forEach([1, 2], function(value) {
|
||
| 9323 | * console.log(value);
|
||
| 9324 | * });
|
||
| 9325 | * // => Logs `1` then `2`.
|
||
| 9326 | *
|
||
| 9327 | * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
|
||
| 9328 | * console.log(key);
|
||
| 9329 | * });
|
||
| 9330 | * // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
||
| 9331 | */
|
||
| 9332 | function forEach(collection, iteratee) { |
||
| 9333 | var func = isArray(collection) ? arrayEach : baseEach;
|
||
| 9334 | return func(collection, getIteratee(iteratee, 3)); |
||
| 9335 | } |
||
| 9336 | |||
| 9337 | /**
|
||
| 9338 | * This method is like `_.forEach` except that it iterates over elements of
|
||
| 9339 | * `collection` from right to left.
|
||
| 9340 | *
|
||
| 9341 | * @static
|
||
| 9342 | * @memberOf _
|
||
| 9343 | * @since 2.0.0
|
||
| 9344 | * @alias eachRight
|
||
| 9345 | * @category Collection
|
||
| 9346 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9347 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9348 | * @returns {Array|Object} Returns `collection`.
|
||
| 9349 | * @see _.forEach
|
||
| 9350 | * @example
|
||
| 9351 | *
|
||
| 9352 | * _.forEachRight([1, 2], function(value) {
|
||
| 9353 | * console.log(value);
|
||
| 9354 | * });
|
||
| 9355 | * // => Logs `2` then `1`.
|
||
| 9356 | */
|
||
| 9357 | function forEachRight(collection, iteratee) { |
||
| 9358 | var func = isArray(collection) ? arrayEachRight : baseEachRight;
|
||
| 9359 | return func(collection, getIteratee(iteratee, 3)); |
||
| 9360 | } |
||
| 9361 | |||
| 9362 | /**
|
||
| 9363 | * Creates an object composed of keys generated from the results of running
|
||
| 9364 | * each element of `collection` thru `iteratee`. The order of grouped values
|
||
| 9365 | * is determined by the order they occur in `collection`. The corresponding
|
||
| 9366 | * value of each key is an array of elements responsible for generating the
|
||
| 9367 | * key. The iteratee is invoked with one argument: (value).
|
||
| 9368 | *
|
||
| 9369 | * @static
|
||
| 9370 | * @memberOf _
|
||
| 9371 | * @since 0.1.0
|
||
| 9372 | * @category Collection
|
||
| 9373 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9374 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
||
| 9375 | * @returns {Object} Returns the composed aggregate object.
|
||
| 9376 | * @example
|
||
| 9377 | *
|
||
| 9378 | * _.groupBy([6.1, 4.2, 6.3], Math.floor);
|
||
| 9379 | * // => { '4': [4.2], '6': [6.1, 6.3] }
|
||
| 9380 | *
|
||
| 9381 | * // The `_.property` iteratee shorthand.
|
||
| 9382 | * _.groupBy(['one', 'two', 'three'], 'length');
|
||
| 9383 | * // => { '3': ['one', 'two'], '5': ['three'] }
|
||
| 9384 | */
|
||
| 9385 | var groupBy = createAggregator(function(result, value, key) { |
||
| 9386 | if (hasOwnProperty.call(result, key)) {
|
||
| 9387 | result[key].push(value); |
||
| 9388 | } else {
|
||
| 9389 | baseAssignValue(result, key, [value]); |
||
| 9390 | } |
||
| 9391 | }); |
||
| 9392 | |||
| 9393 | /**
|
||
| 9394 | * Checks if `value` is in `collection`. If `collection` is a string, it's
|
||
| 9395 | * checked for a substring of `value`, otherwise
|
||
| 9396 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 9397 | * is used for equality comparisons. If `fromIndex` is negative, it's used as
|
||
| 9398 | * the offset from the end of `collection`.
|
||
| 9399 | *
|
||
| 9400 | * @static
|
||
| 9401 | * @memberOf _
|
||
| 9402 | * @since 0.1.0
|
||
| 9403 | * @category Collection
|
||
| 9404 | * @param {Array|Object|string} collection The collection to inspect.
|
||
| 9405 | * @param {*} value The value to search for.
|
||
| 9406 | * @param {number} [fromIndex=0] The index to search from.
|
||
| 9407 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
||
| 9408 | * @returns {boolean} Returns `true` if `value` is found, else `false`.
|
||
| 9409 | * @example
|
||
| 9410 | *
|
||
| 9411 | * _.includes([1, 2, 3], 1);
|
||
| 9412 | * // => true
|
||
| 9413 | *
|
||
| 9414 | * _.includes([1, 2, 3], 1, 2);
|
||
| 9415 | * // => false
|
||
| 9416 | *
|
||
| 9417 | * _.includes({ 'a': 1, 'b': 2 }, 1);
|
||
| 9418 | * // => true
|
||
| 9419 | *
|
||
| 9420 | * _.includes('abcd', 'bc');
|
||
| 9421 | * // => true
|
||
| 9422 | */
|
||
| 9423 | function includes(collection, value, fromIndex, guard) { |
||
| 9424 | collection = isArrayLike(collection) ? collection : values(collection); |
||
| 9425 | fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
|
||
| 9426 | |||
| 9427 | var length = collection.length;
|
||
| 9428 | if (fromIndex < 0) { |
||
| 9429 | fromIndex = nativeMax(length + fromIndex, 0);
|
||
| 9430 | } |
||
| 9431 | return isString(collection)
|
||
| 9432 | ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
|
||
| 9433 | : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
|
||
| 9434 | } |
||
| 9435 | |||
| 9436 | /**
|
||
| 9437 | * Invokes the method at `path` of each element in `collection`, returning
|
||
| 9438 | * an array of the results of each invoked method. Any additional arguments
|
||
| 9439 | * are provided to each invoked method. If `path` is a function, it's invoked
|
||
| 9440 | * for, and `this` bound to, each element in `collection`.
|
||
| 9441 | *
|
||
| 9442 | * @static
|
||
| 9443 | * @memberOf _
|
||
| 9444 | * @since 4.0.0
|
||
| 9445 | * @category Collection
|
||
| 9446 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9447 | * @param {Array|Function|string} path The path of the method to invoke or
|
||
| 9448 | * the function invoked per iteration.
|
||
| 9449 | * @param {...*} [args] The arguments to invoke each method with.
|
||
| 9450 | * @returns {Array} Returns the array of results.
|
||
| 9451 | * @example
|
||
| 9452 | *
|
||
| 9453 | * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
|
||
| 9454 | * // => [[1, 5, 7], [1, 2, 3]]
|
||
| 9455 | *
|
||
| 9456 | * _.invokeMap([123, 456], String.prototype.split, '');
|
||
| 9457 | * // => [['1', '2', '3'], ['4', '5', '6']]
|
||
| 9458 | */
|
||
| 9459 | var invokeMap = baseRest(function(collection, path, args) { |
||
| 9460 | var index = -1, |
||
| 9461 | isFunc = typeof path == 'function', |
||
| 9462 | result = isArrayLike(collection) ? Array(collection.length) : []; |
||
| 9463 | |||
| 9464 | baseEach(collection, function(value) {
|
||
| 9465 | result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args); |
||
| 9466 | }); |
||
| 9467 | return result;
|
||
| 9468 | }); |
||
| 9469 | |||
| 9470 | /**
|
||
| 9471 | * Creates an object composed of keys generated from the results of running
|
||
| 9472 | * each element of `collection` thru `iteratee`. The corresponding value of
|
||
| 9473 | * each key is the last element responsible for generating the key. The
|
||
| 9474 | * iteratee is invoked with one argument: (value).
|
||
| 9475 | *
|
||
| 9476 | * @static
|
||
| 9477 | * @memberOf _
|
||
| 9478 | * @since 4.0.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 | * var array = [
|
||
| 9486 | * { 'dir': 'left', 'code': 97 },
|
||
| 9487 | * { 'dir': 'right', 'code': 100 }
|
||
| 9488 | * ];
|
||
| 9489 | *
|
||
| 9490 | * _.keyBy(array, function(o) {
|
||
| 9491 | * return String.fromCharCode(o.code);
|
||
| 9492 | * });
|
||
| 9493 | * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
||
| 9494 | *
|
||
| 9495 | * _.keyBy(array, 'dir');
|
||
| 9496 | * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
||
| 9497 | */
|
||
| 9498 | var keyBy = createAggregator(function(result, value, key) { |
||
| 9499 | baseAssignValue(result, key, value); |
||
| 9500 | }); |
||
| 9501 | |||
| 9502 | /**
|
||
| 9503 | * Creates an array of values by running each element in `collection` thru
|
||
| 9504 | * `iteratee`. The iteratee is invoked with three arguments:
|
||
| 9505 | * (value, index|key, collection).
|
||
| 9506 | *
|
||
| 9507 | * Many lodash methods are guarded to work as iteratees for methods like
|
||
| 9508 | * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
||
| 9509 | *
|
||
| 9510 | * The guarded methods are:
|
||
| 9511 | * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
|
||
| 9512 | * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
|
||
| 9513 | * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
|
||
| 9514 | * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
|
||
| 9515 | *
|
||
| 9516 | * @static
|
||
| 9517 | * @memberOf _
|
||
| 9518 | * @since 0.1.0
|
||
| 9519 | * @category Collection
|
||
| 9520 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9521 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9522 | * @returns {Array} Returns the new mapped array.
|
||
| 9523 | * @example
|
||
| 9524 | *
|
||
| 9525 | * function square(n) {
|
||
| 9526 | * return n * n;
|
||
| 9527 | * }
|
||
| 9528 | *
|
||
| 9529 | * _.map([4, 8], square);
|
||
| 9530 | * // => [16, 64]
|
||
| 9531 | *
|
||
| 9532 | * _.map({ 'a': 4, 'b': 8 }, square);
|
||
| 9533 | * // => [16, 64] (iteration order is not guaranteed)
|
||
| 9534 | *
|
||
| 9535 | * var users = [
|
||
| 9536 | * { 'user': 'barney' },
|
||
| 9537 | * { 'user': 'fred' }
|
||
| 9538 | * ];
|
||
| 9539 | *
|
||
| 9540 | * // The `_.property` iteratee shorthand.
|
||
| 9541 | * _.map(users, 'user');
|
||
| 9542 | * // => ['barney', 'fred']
|
||
| 9543 | */
|
||
| 9544 | function map(collection, iteratee) { |
||
| 9545 | var func = isArray(collection) ? arrayMap : baseMap;
|
||
| 9546 | return func(collection, getIteratee(iteratee, 3)); |
||
| 9547 | } |
||
| 9548 | |||
| 9549 | /**
|
||
| 9550 | * This method is like `_.sortBy` except that it allows specifying the sort
|
||
| 9551 | * orders of the iteratees to sort by. If `orders` is unspecified, all values
|
||
| 9552 | * are sorted in ascending order. Otherwise, specify an order of "desc" for
|
||
| 9553 | * descending or "asc" for ascending sort order of corresponding values.
|
||
| 9554 | *
|
||
| 9555 | * @static
|
||
| 9556 | * @memberOf _
|
||
| 9557 | * @since 4.0.0
|
||
| 9558 | * @category Collection
|
||
| 9559 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9560 | * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
|
||
| 9561 | * The iteratees to sort by.
|
||
| 9562 | * @param {string[]} [orders] The sort orders of `iteratees`.
|
||
| 9563 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
||
| 9564 | * @returns {Array} Returns the new sorted array.
|
||
| 9565 | * @example
|
||
| 9566 | *
|
||
| 9567 | * var users = [
|
||
| 9568 | * { 'user': 'fred', 'age': 48 },
|
||
| 9569 | * { 'user': 'barney', 'age': 34 },
|
||
| 9570 | * { 'user': 'fred', 'age': 40 },
|
||
| 9571 | * { 'user': 'barney', 'age': 36 }
|
||
| 9572 | * ];
|
||
| 9573 | *
|
||
| 9574 | * // Sort by `user` in ascending order and by `age` in descending order.
|
||
| 9575 | * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
|
||
| 9576 | * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
||
| 9577 | */
|
||
| 9578 | function orderBy(collection, iteratees, orders, guard) { |
||
| 9579 | if (collection == null) { |
||
| 9580 | return [];
|
||
| 9581 | } |
||
| 9582 | if (!isArray(iteratees)) {
|
||
| 9583 | iteratees = iteratees == null ? [] : [iteratees];
|
||
| 9584 | } |
||
| 9585 | orders = guard ? undefined : orders;
|
||
| 9586 | if (!isArray(orders)) {
|
||
| 9587 | orders = orders == null ? [] : [orders];
|
||
| 9588 | } |
||
| 9589 | return baseOrderBy(collection, iteratees, orders);
|
||
| 9590 | } |
||
| 9591 | |||
| 9592 | /**
|
||
| 9593 | * Creates an array of elements split into two groups, the first of which
|
||
| 9594 | * contains elements `predicate` returns truthy for, the second of which
|
||
| 9595 | * contains elements `predicate` returns falsey for. The predicate is
|
||
| 9596 | * invoked with one argument: (value).
|
||
| 9597 | *
|
||
| 9598 | * @static
|
||
| 9599 | * @memberOf _
|
||
| 9600 | * @since 3.0.0
|
||
| 9601 | * @category Collection
|
||
| 9602 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9603 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 9604 | * @returns {Array} Returns the array of grouped elements.
|
||
| 9605 | * @example
|
||
| 9606 | *
|
||
| 9607 | * var users = [
|
||
| 9608 | * { 'user': 'barney', 'age': 36, 'active': false },
|
||
| 9609 | * { 'user': 'fred', 'age': 40, 'active': true },
|
||
| 9610 | * { 'user': 'pebbles', 'age': 1, 'active': false }
|
||
| 9611 | * ];
|
||
| 9612 | *
|
||
| 9613 | * _.partition(users, function(o) { return o.active; });
|
||
| 9614 | * // => objects for [['fred'], ['barney', 'pebbles']]
|
||
| 9615 | *
|
||
| 9616 | * // The `_.matches` iteratee shorthand.
|
||
| 9617 | * _.partition(users, { 'age': 1, 'active': false });
|
||
| 9618 | * // => objects for [['pebbles'], ['barney', 'fred']]
|
||
| 9619 | *
|
||
| 9620 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 9621 | * _.partition(users, ['active', false]);
|
||
| 9622 | * // => objects for [['barney', 'pebbles'], ['fred']]
|
||
| 9623 | *
|
||
| 9624 | * // The `_.property` iteratee shorthand.
|
||
| 9625 | * _.partition(users, 'active');
|
||
| 9626 | * // => objects for [['fred'], ['barney', 'pebbles']]
|
||
| 9627 | */
|
||
| 9628 | var partition = createAggregator(function(result, value, key) { |
||
| 9629 | result[key ? 0 : 1].push(value); |
||
| 9630 | }, function() { return [[], []]; }); |
||
| 9631 | |||
| 9632 | /**
|
||
| 9633 | * Reduces `collection` to a value which is the accumulated result of running
|
||
| 9634 | * each element in `collection` thru `iteratee`, where each successive
|
||
| 9635 | * invocation is supplied the return value of the previous. If `accumulator`
|
||
| 9636 | * is not given, the first element of `collection` is used as the initial
|
||
| 9637 | * value. The iteratee is invoked with four arguments:
|
||
| 9638 | * (accumulator, value, index|key, collection).
|
||
| 9639 | *
|
||
| 9640 | * Many lodash methods are guarded to work as iteratees for methods like
|
||
| 9641 | * `_.reduce`, `_.reduceRight`, and `_.transform`.
|
||
| 9642 | *
|
||
| 9643 | * The guarded methods are:
|
||
| 9644 | * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
|
||
| 9645 | * and `sortBy`
|
||
| 9646 | *
|
||
| 9647 | * @static
|
||
| 9648 | * @memberOf _
|
||
| 9649 | * @since 0.1.0
|
||
| 9650 | * @category Collection
|
||
| 9651 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9652 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9653 | * @param {*} [accumulator] The initial value.
|
||
| 9654 | * @returns {*} Returns the accumulated value.
|
||
| 9655 | * @see _.reduceRight
|
||
| 9656 | * @example
|
||
| 9657 | *
|
||
| 9658 | * _.reduce([1, 2], function(sum, n) {
|
||
| 9659 | * return sum + n;
|
||
| 9660 | * }, 0);
|
||
| 9661 | * // => 3
|
||
| 9662 | *
|
||
| 9663 | * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
||
| 9664 | * (result[value] || (result[value] = [])).push(key);
|
||
| 9665 | * return result;
|
||
| 9666 | * }, {});
|
||
| 9667 | * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
|
||
| 9668 | */
|
||
| 9669 | function reduce(collection, iteratee, accumulator) { |
||
| 9670 | var func = isArray(collection) ? arrayReduce : baseReduce,
|
||
| 9671 | initAccum = arguments.length < 3; |
||
| 9672 | |||
| 9673 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach); |
||
| 9674 | } |
||
| 9675 | |||
| 9676 | /**
|
||
| 9677 | * This method is like `_.reduce` except that it iterates over elements of
|
||
| 9678 | * `collection` from right to left.
|
||
| 9679 | *
|
||
| 9680 | * @static
|
||
| 9681 | * @memberOf _
|
||
| 9682 | * @since 0.1.0
|
||
| 9683 | * @category Collection
|
||
| 9684 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9685 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 9686 | * @param {*} [accumulator] The initial value.
|
||
| 9687 | * @returns {*} Returns the accumulated value.
|
||
| 9688 | * @see _.reduce
|
||
| 9689 | * @example
|
||
| 9690 | *
|
||
| 9691 | * var array = [[0, 1], [2, 3], [4, 5]];
|
||
| 9692 | *
|
||
| 9693 | * _.reduceRight(array, function(flattened, other) {
|
||
| 9694 | * return flattened.concat(other);
|
||
| 9695 | * }, []);
|
||
| 9696 | * // => [4, 5, 2, 3, 0, 1]
|
||
| 9697 | */
|
||
| 9698 | function reduceRight(collection, iteratee, accumulator) { |
||
| 9699 | var func = isArray(collection) ? arrayReduceRight : baseReduce,
|
||
| 9700 | initAccum = arguments.length < 3; |
||
| 9701 | |||
| 9702 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight); |
||
| 9703 | } |
||
| 9704 | |||
| 9705 | /**
|
||
| 9706 | * The opposite of `_.filter`; this method returns the elements of `collection`
|
||
| 9707 | * that `predicate` does **not** return truthy for.
|
||
| 9708 | *
|
||
| 9709 | * @static
|
||
| 9710 | * @memberOf _
|
||
| 9711 | * @since 0.1.0
|
||
| 9712 | * @category Collection
|
||
| 9713 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9714 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 9715 | * @returns {Array} Returns the new filtered array.
|
||
| 9716 | * @see _.filter
|
||
| 9717 | * @example
|
||
| 9718 | *
|
||
| 9719 | * var users = [
|
||
| 9720 | * { 'user': 'barney', 'age': 36, 'active': false },
|
||
| 9721 | * { 'user': 'fred', 'age': 40, 'active': true }
|
||
| 9722 | * ];
|
||
| 9723 | *
|
||
| 9724 | * _.reject(users, function(o) { return !o.active; });
|
||
| 9725 | * // => objects for ['fred']
|
||
| 9726 | *
|
||
| 9727 | * // The `_.matches` iteratee shorthand.
|
||
| 9728 | * _.reject(users, { 'age': 40, 'active': true });
|
||
| 9729 | * // => objects for ['barney']
|
||
| 9730 | *
|
||
| 9731 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 9732 | * _.reject(users, ['active', false]);
|
||
| 9733 | * // => objects for ['fred']
|
||
| 9734 | *
|
||
| 9735 | * // The `_.property` iteratee shorthand.
|
||
| 9736 | * _.reject(users, 'active');
|
||
| 9737 | * // => objects for ['barney']
|
||
| 9738 | */
|
||
| 9739 | function reject(collection, predicate) { |
||
| 9740 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
||
| 9741 | return func(collection, negate(getIteratee(predicate, 3))); |
||
| 9742 | } |
||
| 9743 | |||
| 9744 | /**
|
||
| 9745 | * Gets a random element from `collection`.
|
||
| 9746 | *
|
||
| 9747 | * @static
|
||
| 9748 | * @memberOf _
|
||
| 9749 | * @since 2.0.0
|
||
| 9750 | * @category Collection
|
||
| 9751 | * @param {Array|Object} collection The collection to sample.
|
||
| 9752 | * @returns {*} Returns the random element.
|
||
| 9753 | * @example
|
||
| 9754 | *
|
||
| 9755 | * _.sample([1, 2, 3, 4]);
|
||
| 9756 | * // => 2
|
||
| 9757 | */
|
||
| 9758 | function sample(collection) { |
||
| 9759 | var func = isArray(collection) ? arraySample : baseSample;
|
||
| 9760 | return func(collection);
|
||
| 9761 | } |
||
| 9762 | |||
| 9763 | /**
|
||
| 9764 | * Gets `n` random elements at unique keys from `collection` up to the
|
||
| 9765 | * size of `collection`.
|
||
| 9766 | *
|
||
| 9767 | * @static
|
||
| 9768 | * @memberOf _
|
||
| 9769 | * @since 4.0.0
|
||
| 9770 | * @category Collection
|
||
| 9771 | * @param {Array|Object} collection The collection to sample.
|
||
| 9772 | * @param {number} [n=1] The number of elements to sample.
|
||
| 9773 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 9774 | * @returns {Array} Returns the random elements.
|
||
| 9775 | * @example
|
||
| 9776 | *
|
||
| 9777 | * _.sampleSize([1, 2, 3], 2);
|
||
| 9778 | * // => [3, 1]
|
||
| 9779 | *
|
||
| 9780 | * _.sampleSize([1, 2, 3], 4);
|
||
| 9781 | * // => [2, 3, 1]
|
||
| 9782 | */
|
||
| 9783 | function sampleSize(collection, n, guard) { |
||
| 9784 | if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) { |
||
| 9785 | n = 1;
|
||
| 9786 | } else {
|
||
| 9787 | n = toInteger(n); |
||
| 9788 | } |
||
| 9789 | var func = isArray(collection) ? arraySampleSize : baseSampleSize;
|
||
| 9790 | return func(collection, n);
|
||
| 9791 | } |
||
| 9792 | |||
| 9793 | /**
|
||
| 9794 | * Creates an array of shuffled values, using a version of the
|
||
| 9795 | * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
||
| 9796 | *
|
||
| 9797 | * @static
|
||
| 9798 | * @memberOf _
|
||
| 9799 | * @since 0.1.0
|
||
| 9800 | * @category Collection
|
||
| 9801 | * @param {Array|Object} collection The collection to shuffle.
|
||
| 9802 | * @returns {Array} Returns the new shuffled array.
|
||
| 9803 | * @example
|
||
| 9804 | *
|
||
| 9805 | * _.shuffle([1, 2, 3, 4]);
|
||
| 9806 | * // => [4, 1, 3, 2]
|
||
| 9807 | */
|
||
| 9808 | function shuffle(collection) { |
||
| 9809 | var func = isArray(collection) ? arrayShuffle : baseShuffle;
|
||
| 9810 | return func(collection);
|
||
| 9811 | } |
||
| 9812 | |||
| 9813 | /**
|
||
| 9814 | * Gets the size of `collection` by returning its length for array-like
|
||
| 9815 | * values or the number of own enumerable string keyed properties for objects.
|
||
| 9816 | *
|
||
| 9817 | * @static
|
||
| 9818 | * @memberOf _
|
||
| 9819 | * @since 0.1.0
|
||
| 9820 | * @category Collection
|
||
| 9821 | * @param {Array|Object|string} collection The collection to inspect.
|
||
| 9822 | * @returns {number} Returns the collection size.
|
||
| 9823 | * @example
|
||
| 9824 | *
|
||
| 9825 | * _.size([1, 2, 3]);
|
||
| 9826 | * // => 3
|
||
| 9827 | *
|
||
| 9828 | * _.size({ 'a': 1, 'b': 2 });
|
||
| 9829 | * // => 2
|
||
| 9830 | *
|
||
| 9831 | * _.size('pebbles');
|
||
| 9832 | * // => 7
|
||
| 9833 | */
|
||
| 9834 | function size(collection) { |
||
| 9835 | if (collection == null) { |
||
| 9836 | return 0; |
||
| 9837 | } |
||
| 9838 | if (isArrayLike(collection)) {
|
||
| 9839 | return isString(collection) ? stringSize(collection) : collection.length;
|
||
| 9840 | } |
||
| 9841 | var tag = getTag(collection);
|
||
| 9842 | if (tag == mapTag || tag == setTag) {
|
||
| 9843 | return collection.size;
|
||
| 9844 | } |
||
| 9845 | return baseKeys(collection).length;
|
||
| 9846 | } |
||
| 9847 | |||
| 9848 | /**
|
||
| 9849 | * Checks if `predicate` returns truthy for **any** element of `collection`.
|
||
| 9850 | * Iteration is stopped once `predicate` returns truthy. The predicate is
|
||
| 9851 | * invoked with three arguments: (value, index|key, collection).
|
||
| 9852 | *
|
||
| 9853 | * @static
|
||
| 9854 | * @memberOf _
|
||
| 9855 | * @since 0.1.0
|
||
| 9856 | * @category Collection
|
||
| 9857 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9858 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 9859 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 9860 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
||
| 9861 | * else `false`.
|
||
| 9862 | * @example
|
||
| 9863 | *
|
||
| 9864 | * _.some([null, 0, 'yes', false], Boolean);
|
||
| 9865 | * // => true
|
||
| 9866 | *
|
||
| 9867 | * var users = [
|
||
| 9868 | * { 'user': 'barney', 'active': true },
|
||
| 9869 | * { 'user': 'fred', 'active': false }
|
||
| 9870 | * ];
|
||
| 9871 | *
|
||
| 9872 | * // The `_.matches` iteratee shorthand.
|
||
| 9873 | * _.some(users, { 'user': 'barney', 'active': false });
|
||
| 9874 | * // => false
|
||
| 9875 | *
|
||
| 9876 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 9877 | * _.some(users, ['active', false]);
|
||
| 9878 | * // => true
|
||
| 9879 | *
|
||
| 9880 | * // The `_.property` iteratee shorthand.
|
||
| 9881 | * _.some(users, 'active');
|
||
| 9882 | * // => true
|
||
| 9883 | */
|
||
| 9884 | function some(collection, predicate, guard) { |
||
| 9885 | var func = isArray(collection) ? arraySome : baseSome;
|
||
| 9886 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
||
| 9887 | predicate = undefined;
|
||
| 9888 | } |
||
| 9889 | return func(collection, getIteratee(predicate, 3)); |
||
| 9890 | } |
||
| 9891 | |||
| 9892 | /**
|
||
| 9893 | * Creates an array of elements, sorted in ascending order by the results of
|
||
| 9894 | * running each element in a collection thru each iteratee. This method
|
||
| 9895 | * performs a stable sort, that is, it preserves the original sort order of
|
||
| 9896 | * equal elements. The iteratees are invoked with one argument: (value).
|
||
| 9897 | *
|
||
| 9898 | * @static
|
||
| 9899 | * @memberOf _
|
||
| 9900 | * @since 0.1.0
|
||
| 9901 | * @category Collection
|
||
| 9902 | * @param {Array|Object} collection The collection to iterate over.
|
||
| 9903 | * @param {...(Function|Function[])} [iteratees=[_.identity]]
|
||
| 9904 | * The iteratees to sort by.
|
||
| 9905 | * @returns {Array} Returns the new sorted array.
|
||
| 9906 | * @example
|
||
| 9907 | *
|
||
| 9908 | * var users = [
|
||
| 9909 | * { 'user': 'fred', 'age': 48 },
|
||
| 9910 | * { 'user': 'barney', 'age': 36 },
|
||
| 9911 | * { 'user': 'fred', 'age': 40 },
|
||
| 9912 | * { 'user': 'barney', 'age': 34 }
|
||
| 9913 | * ];
|
||
| 9914 | *
|
||
| 9915 | * _.sortBy(users, [function(o) { return o.user; }]);
|
||
| 9916 | * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
||
| 9917 | *
|
||
| 9918 | * _.sortBy(users, ['user', 'age']);
|
||
| 9919 | * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
|
||
| 9920 | */
|
||
| 9921 | var sortBy = baseRest(function(collection, iteratees) { |
||
| 9922 | if (collection == null) { |
||
| 9923 | return [];
|
||
| 9924 | } |
||
| 9925 | var length = iteratees.length;
|
||
| 9926 | if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { |
||
| 9927 | iteratees = []; |
||
| 9928 | } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { |
||
| 9929 | iteratees = [iteratees[0]];
|
||
| 9930 | } |
||
| 9931 | return baseOrderBy(collection, baseFlatten(iteratees, 1), []); |
||
| 9932 | }); |
||
| 9933 | |||
| 9934 | /*------------------------------------------------------------------------*/
|
||
| 9935 | |||
| 9936 | /**
|
||
| 9937 | * Gets the timestamp of the number of milliseconds that have elapsed since
|
||
| 9938 | * the Unix epoch (1 January 1970 00:00:00 UTC).
|
||
| 9939 | *
|
||
| 9940 | * @static
|
||
| 9941 | * @memberOf _
|
||
| 9942 | * @since 2.4.0
|
||
| 9943 | * @category Date
|
||
| 9944 | * @returns {number} Returns the timestamp.
|
||
| 9945 | * @example
|
||
| 9946 | *
|
||
| 9947 | * _.defer(function(stamp) {
|
||
| 9948 | * console.log(_.now() - stamp);
|
||
| 9949 | * }, _.now());
|
||
| 9950 | * // => Logs the number of milliseconds it took for the deferred invocation.
|
||
| 9951 | */
|
||
| 9952 | var now = ctxNow || function() { |
||
| 9953 | return root.Date.now();
|
||
| 9954 | }; |
||
| 9955 | |||
| 9956 | /*------------------------------------------------------------------------*/
|
||
| 9957 | |||
| 9958 | /**
|
||
| 9959 | * The opposite of `_.before`; this method creates a function that invokes
|
||
| 9960 | * `func` once it's called `n` or more times.
|
||
| 9961 | *
|
||
| 9962 | * @static
|
||
| 9963 | * @memberOf _
|
||
| 9964 | * @since 0.1.0
|
||
| 9965 | * @category Function
|
||
| 9966 | * @param {number} n The number of calls before `func` is invoked.
|
||
| 9967 | * @param {Function} func The function to restrict.
|
||
| 9968 | * @returns {Function} Returns the new restricted function.
|
||
| 9969 | * @example
|
||
| 9970 | *
|
||
| 9971 | * var saves = ['profile', 'settings'];
|
||
| 9972 | *
|
||
| 9973 | * var done = _.after(saves.length, function() {
|
||
| 9974 | * console.log('done saving!');
|
||
| 9975 | * });
|
||
| 9976 | *
|
||
| 9977 | * _.forEach(saves, function(type) {
|
||
| 9978 | * asyncSave({ 'type': type, 'complete': done });
|
||
| 9979 | * });
|
||
| 9980 | * // => Logs 'done saving!' after the two async saves have completed.
|
||
| 9981 | */
|
||
| 9982 | function after(n, func) { |
||
| 9983 | if (typeof func != 'function') { |
||
| 9984 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 9985 | } |
||
| 9986 | n = toInteger(n); |
||
| 9987 | return function() { |
||
| 9988 | if (--n < 1) { |
||
| 9989 | return func.apply(this, arguments); |
||
| 9990 | } |
||
| 9991 | }; |
||
| 9992 | } |
||
| 9993 | |||
| 9994 | /**
|
||
| 9995 | * Creates a function that invokes `func`, with up to `n` arguments,
|
||
| 9996 | * ignoring any additional arguments.
|
||
| 9997 | *
|
||
| 9998 | * @static
|
||
| 9999 | * @memberOf _
|
||
| 10000 | * @since 3.0.0
|
||
| 10001 | * @category Function
|
||
| 10002 | * @param {Function} func The function to cap arguments for.
|
||
| 10003 | * @param {number} [n=func.length] The arity cap.
|
||
| 10004 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 10005 | * @returns {Function} Returns the new capped function.
|
||
| 10006 | * @example
|
||
| 10007 | *
|
||
| 10008 | * _.map(['6', '8', '10'], _.ary(parseInt, 1));
|
||
| 10009 | * // => [6, 8, 10]
|
||
| 10010 | */
|
||
| 10011 | function ary(func, n, guard) { |
||
| 10012 | n = guard ? undefined : n;
|
||
| 10013 | n = (func && n == null) ? func.length : n;
|
||
| 10014 | return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n); |
||
| 10015 | } |
||
| 10016 | |||
| 10017 | /**
|
||
| 10018 | * Creates a function that invokes `func`, with the `this` binding and arguments
|
||
| 10019 | * of the created function, while it's called less than `n` times. Subsequent
|
||
| 10020 | * calls to the created function return the result of the last `func` invocation.
|
||
| 10021 | *
|
||
| 10022 | * @static
|
||
| 10023 | * @memberOf _
|
||
| 10024 | * @since 3.0.0
|
||
| 10025 | * @category Function
|
||
| 10026 | * @param {number} n The number of calls at which `func` is no longer invoked.
|
||
| 10027 | * @param {Function} func The function to restrict.
|
||
| 10028 | * @returns {Function} Returns the new restricted function.
|
||
| 10029 | * @example
|
||
| 10030 | *
|
||
| 10031 | * jQuery(element).on('click', _.before(5, addContactToList));
|
||
| 10032 | * // => Allows adding up to 4 contacts to the list.
|
||
| 10033 | */
|
||
| 10034 | function before(n, func) { |
||
| 10035 | var result;
|
||
| 10036 | if (typeof func != 'function') { |
||
| 10037 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 10038 | } |
||
| 10039 | n = toInteger(n); |
||
| 10040 | return function() { |
||
| 10041 | if (--n > 0) { |
||
| 10042 | result = func.apply(this, arguments); |
||
| 10043 | } |
||
| 10044 | if (n <= 1) { |
||
| 10045 | func = undefined;
|
||
| 10046 | } |
||
| 10047 | return result;
|
||
| 10048 | }; |
||
| 10049 | } |
||
| 10050 | |||
| 10051 | /**
|
||
| 10052 | * Creates a function that invokes `func` with the `this` binding of `thisArg`
|
||
| 10053 | * and `partials` prepended to the arguments it receives.
|
||
| 10054 | *
|
||
| 10055 | * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
||
| 10056 | * may be used as a placeholder for partially applied arguments.
|
||
| 10057 | *
|
||
| 10058 | * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
|
||
| 10059 | * property of bound functions.
|
||
| 10060 | *
|
||
| 10061 | * @static
|
||
| 10062 | * @memberOf _
|
||
| 10063 | * @since 0.1.0
|
||
| 10064 | * @category Function
|
||
| 10065 | * @param {Function} func The function to bind.
|
||
| 10066 | * @param {*} thisArg The `this` binding of `func`.
|
||
| 10067 | * @param {...*} [partials] The arguments to be partially applied.
|
||
| 10068 | * @returns {Function} Returns the new bound function.
|
||
| 10069 | * @example
|
||
| 10070 | *
|
||
| 10071 | * function greet(greeting, punctuation) {
|
||
| 10072 | * return greeting + ' ' + this.user + punctuation;
|
||
| 10073 | * }
|
||
| 10074 | *
|
||
| 10075 | * var object = { 'user': 'fred' };
|
||
| 10076 | *
|
||
| 10077 | * var bound = _.bind(greet, object, 'hi');
|
||
| 10078 | * bound('!');
|
||
| 10079 | * // => 'hi fred!'
|
||
| 10080 | *
|
||
| 10081 | * // Bound with placeholders.
|
||
| 10082 | * var bound = _.bind(greet, object, _, '!');
|
||
| 10083 | * bound('hi');
|
||
| 10084 | * // => 'hi fred!'
|
||
| 10085 | */
|
||
| 10086 | var bind = baseRest(function(func, thisArg, partials) { |
||
| 10087 | var bitmask = WRAP_BIND_FLAG;
|
||
| 10088 | if (partials.length) {
|
||
| 10089 | var holders = replaceHolders(partials, getHolder(bind));
|
||
| 10090 | bitmask |= WRAP_PARTIAL_FLAG; |
||
| 10091 | } |
||
| 10092 | return createWrap(func, bitmask, thisArg, partials, holders);
|
||
| 10093 | }); |
||
| 10094 | |||
| 10095 | /**
|
||
| 10096 | * Creates a function that invokes the method at `object[key]` with `partials`
|
||
| 10097 | * prepended to the arguments it receives.
|
||
| 10098 | *
|
||
| 10099 | * This method differs from `_.bind` by allowing bound functions to reference
|
||
| 10100 | * methods that may be redefined or don't yet exist. See
|
||
| 10101 | * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
|
||
| 10102 | * for more details.
|
||
| 10103 | *
|
||
| 10104 | * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
||
| 10105 | * builds, may be used as a placeholder for partially applied arguments.
|
||
| 10106 | *
|
||
| 10107 | * @static
|
||
| 10108 | * @memberOf _
|
||
| 10109 | * @since 0.10.0
|
||
| 10110 | * @category Function
|
||
| 10111 | * @param {Object} object The object to invoke the method on.
|
||
| 10112 | * @param {string} key The key of the method.
|
||
| 10113 | * @param {...*} [partials] The arguments to be partially applied.
|
||
| 10114 | * @returns {Function} Returns the new bound function.
|
||
| 10115 | * @example
|
||
| 10116 | *
|
||
| 10117 | * var object = {
|
||
| 10118 | * 'user': 'fred',
|
||
| 10119 | * 'greet': function(greeting, punctuation) {
|
||
| 10120 | * return greeting + ' ' + this.user + punctuation;
|
||
| 10121 | * }
|
||
| 10122 | * };
|
||
| 10123 | *
|
||
| 10124 | * var bound = _.bindKey(object, 'greet', 'hi');
|
||
| 10125 | * bound('!');
|
||
| 10126 | * // => 'hi fred!'
|
||
| 10127 | *
|
||
| 10128 | * object.greet = function(greeting, punctuation) {
|
||
| 10129 | * return greeting + 'ya ' + this.user + punctuation;
|
||
| 10130 | * };
|
||
| 10131 | *
|
||
| 10132 | * bound('!');
|
||
| 10133 | * // => 'hiya fred!'
|
||
| 10134 | *
|
||
| 10135 | * // Bound with placeholders.
|
||
| 10136 | * var bound = _.bindKey(object, 'greet', _, '!');
|
||
| 10137 | * bound('hi');
|
||
| 10138 | * // => 'hiya fred!'
|
||
| 10139 | */
|
||
| 10140 | var bindKey = baseRest(function(object, key, partials) { |
||
| 10141 | var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
|
||
| 10142 | if (partials.length) {
|
||
| 10143 | var holders = replaceHolders(partials, getHolder(bindKey));
|
||
| 10144 | bitmask |= WRAP_PARTIAL_FLAG; |
||
| 10145 | } |
||
| 10146 | return createWrap(key, bitmask, object, partials, holders);
|
||
| 10147 | }); |
||
| 10148 | |||
| 10149 | /**
|
||
| 10150 | * Creates a function that accepts arguments of `func` and either invokes
|
||
| 10151 | * `func` returning its result, if at least `arity` number of arguments have
|
||
| 10152 | * been provided, or returns a function that accepts the remaining `func`
|
||
| 10153 | * arguments, and so on. The arity of `func` may be specified if `func.length`
|
||
| 10154 | * is not sufficient.
|
||
| 10155 | *
|
||
| 10156 | * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
||
| 10157 | * may be used as a placeholder for provided arguments.
|
||
| 10158 | *
|
||
| 10159 | * **Note:** This method doesn't set the "length" property of curried functions.
|
||
| 10160 | *
|
||
| 10161 | * @static
|
||
| 10162 | * @memberOf _
|
||
| 10163 | * @since 2.0.0
|
||
| 10164 | * @category Function
|
||
| 10165 | * @param {Function} func The function to curry.
|
||
| 10166 | * @param {number} [arity=func.length] The arity of `func`.
|
||
| 10167 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 10168 | * @returns {Function} Returns the new curried function.
|
||
| 10169 | * @example
|
||
| 10170 | *
|
||
| 10171 | * var abc = function(a, b, c) {
|
||
| 10172 | * return [a, b, c];
|
||
| 10173 | * };
|
||
| 10174 | *
|
||
| 10175 | * var curried = _.curry(abc);
|
||
| 10176 | *
|
||
| 10177 | * curried(1)(2)(3);
|
||
| 10178 | * // => [1, 2, 3]
|
||
| 10179 | *
|
||
| 10180 | * curried(1, 2)(3);
|
||
| 10181 | * // => [1, 2, 3]
|
||
| 10182 | *
|
||
| 10183 | * curried(1, 2, 3);
|
||
| 10184 | * // => [1, 2, 3]
|
||
| 10185 | *
|
||
| 10186 | * // Curried with placeholders.
|
||
| 10187 | * curried(1)(_, 3)(2);
|
||
| 10188 | * // => [1, 2, 3]
|
||
| 10189 | */
|
||
| 10190 | function curry(func, arity, guard) { |
||
| 10191 | arity = guard ? undefined : arity;
|
||
| 10192 | var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); |
||
| 10193 | result.placeholder = curry.placeholder; |
||
| 10194 | return result;
|
||
| 10195 | } |
||
| 10196 | |||
| 10197 | /**
|
||
| 10198 | * This method is like `_.curry` except that arguments are applied to `func`
|
||
| 10199 | * in the manner of `_.partialRight` instead of `_.partial`.
|
||
| 10200 | *
|
||
| 10201 | * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
||
| 10202 | * builds, may be used as a placeholder for provided arguments.
|
||
| 10203 | *
|
||
| 10204 | * **Note:** This method doesn't set the "length" property of curried functions.
|
||
| 10205 | *
|
||
| 10206 | * @static
|
||
| 10207 | * @memberOf _
|
||
| 10208 | * @since 3.0.0
|
||
| 10209 | * @category Function
|
||
| 10210 | * @param {Function} func The function to curry.
|
||
| 10211 | * @param {number} [arity=func.length] The arity of `func`.
|
||
| 10212 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 10213 | * @returns {Function} Returns the new curried function.
|
||
| 10214 | * @example
|
||
| 10215 | *
|
||
| 10216 | * var abc = function(a, b, c) {
|
||
| 10217 | * return [a, b, c];
|
||
| 10218 | * };
|
||
| 10219 | *
|
||
| 10220 | * var curried = _.curryRight(abc);
|
||
| 10221 | *
|
||
| 10222 | * curried(3)(2)(1);
|
||
| 10223 | * // => [1, 2, 3]
|
||
| 10224 | *
|
||
| 10225 | * curried(2, 3)(1);
|
||
| 10226 | * // => [1, 2, 3]
|
||
| 10227 | *
|
||
| 10228 | * curried(1, 2, 3);
|
||
| 10229 | * // => [1, 2, 3]
|
||
| 10230 | *
|
||
| 10231 | * // Curried with placeholders.
|
||
| 10232 | * curried(3)(1, _)(2);
|
||
| 10233 | * // => [1, 2, 3]
|
||
| 10234 | */
|
||
| 10235 | function curryRight(func, arity, guard) { |
||
| 10236 | arity = guard ? undefined : arity;
|
||
| 10237 | var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); |
||
| 10238 | result.placeholder = curryRight.placeholder; |
||
| 10239 | return result;
|
||
| 10240 | } |
||
| 10241 | |||
| 10242 | /**
|
||
| 10243 | * Creates a debounced function that delays invoking `func` until after `wait`
|
||
| 10244 | * milliseconds have elapsed since the last time the debounced function was
|
||
| 10245 | * invoked. The debounced function comes with a `cancel` method to cancel
|
||
| 10246 | * delayed `func` invocations and a `flush` method to immediately invoke them.
|
||
| 10247 | * Provide `options` to indicate whether `func` should be invoked on the
|
||
| 10248 | * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
|
||
| 10249 | * with the last arguments provided to the debounced function. Subsequent
|
||
| 10250 | * calls to the debounced function return the result of the last `func`
|
||
| 10251 | * invocation.
|
||
| 10252 | *
|
||
| 10253 | * **Note:** If `leading` and `trailing` options are `true`, `func` is
|
||
| 10254 | * invoked on the trailing edge of the timeout only if the debounced function
|
||
| 10255 | * is invoked more than once during the `wait` timeout.
|
||
| 10256 | *
|
||
| 10257 | * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
||
| 10258 | * until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
||
| 10259 | *
|
||
| 10260 | * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
||
| 10261 | * for details over the differences between `_.debounce` and `_.throttle`.
|
||
| 10262 | *
|
||
| 10263 | * @static
|
||
| 10264 | * @memberOf _
|
||
| 10265 | * @since 0.1.0
|
||
| 10266 | * @category Function
|
||
| 10267 | * @param {Function} func The function to debounce.
|
||
| 10268 | * @param {number} [wait=0] The number of milliseconds to delay.
|
||
| 10269 | * @param {Object} [options={}] The options object.
|
||
| 10270 | * @param {boolean} [options.leading=false]
|
||
| 10271 | * Specify invoking on the leading edge of the timeout.
|
||
| 10272 | * @param {number} [options.maxWait]
|
||
| 10273 | * The maximum time `func` is allowed to be delayed before it's invoked.
|
||
| 10274 | * @param {boolean} [options.trailing=true]
|
||
| 10275 | * Specify invoking on the trailing edge of the timeout.
|
||
| 10276 | * @returns {Function} Returns the new debounced function.
|
||
| 10277 | * @example
|
||
| 10278 | *
|
||
| 10279 | * // Avoid costly calculations while the window size is in flux.
|
||
| 10280 | * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
|
||
| 10281 | *
|
||
| 10282 | * // Invoke `sendMail` when clicked, debouncing subsequent calls.
|
||
| 10283 | * jQuery(element).on('click', _.debounce(sendMail, 300, {
|
||
| 10284 | * 'leading': true,
|
||
| 10285 | * 'trailing': false
|
||
| 10286 | * }));
|
||
| 10287 | *
|
||
| 10288 | * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
|
||
| 10289 | * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
|
||
| 10290 | * var source = new EventSource('/stream');
|
||
| 10291 | * jQuery(source).on('message', debounced);
|
||
| 10292 | *
|
||
| 10293 | * // Cancel the trailing debounced invocation.
|
||
| 10294 | * jQuery(window).on('popstate', debounced.cancel);
|
||
| 10295 | */
|
||
| 10296 | function debounce(func, wait, options) { |
||
| 10297 | var lastArgs,
|
||
| 10298 | lastThis, |
||
| 10299 | maxWait, |
||
| 10300 | result, |
||
| 10301 | timerId, |
||
| 10302 | lastCallTime, |
||
| 10303 | lastInvokeTime = 0,
|
||
| 10304 | leading = false,
|
||
| 10305 | maxing = false,
|
||
| 10306 | trailing = true;
|
||
| 10307 | |||
| 10308 | if (typeof func != 'function') { |
||
| 10309 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 10310 | } |
||
| 10311 | wait = toNumber(wait) || 0;
|
||
| 10312 | if (isObject(options)) {
|
||
| 10313 | leading = !!options.leading; |
||
| 10314 | maxing = 'maxWait' in options; |
||
| 10315 | maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
||
| 10316 | trailing = 'trailing' in options ? !!options.trailing : trailing; |
||
| 10317 | } |
||
| 10318 | |||
| 10319 | function invokeFunc(time) { |
||
| 10320 | var args = lastArgs,
|
||
| 10321 | thisArg = lastThis; |
||
| 10322 | |||
| 10323 | lastArgs = lastThis = undefined;
|
||
| 10324 | lastInvokeTime = time; |
||
| 10325 | result = func.apply(thisArg, args); |
||
| 10326 | return result;
|
||
| 10327 | } |
||
| 10328 | |||
| 10329 | function leadingEdge(time) { |
||
| 10330 | // Reset any `maxWait` timer.
|
||
| 10331 | lastInvokeTime = time; |
||
| 10332 | // Start the timer for the trailing edge.
|
||
| 10333 | timerId = setTimeout(timerExpired, wait); |
||
| 10334 | // Invoke the leading edge.
|
||
| 10335 | return leading ? invokeFunc(time) : result;
|
||
| 10336 | } |
||
| 10337 | |||
| 10338 | function remainingWait(time) { |
||
| 10339 | var timeSinceLastCall = time - lastCallTime,
|
||
| 10340 | timeSinceLastInvoke = time - lastInvokeTime, |
||
| 10341 | timeWaiting = wait - timeSinceLastCall; |
||
| 10342 | |||
| 10343 | return maxing
|
||
| 10344 | ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) |
||
| 10345 | : timeWaiting; |
||
| 10346 | } |
||
| 10347 | |||
| 10348 | function shouldInvoke(time) { |
||
| 10349 | var timeSinceLastCall = time - lastCallTime,
|
||
| 10350 | timeSinceLastInvoke = time - lastInvokeTime; |
||
| 10351 | |||
| 10352 | // Either this is the first call, activity has stopped and we're at the
|
||
| 10353 | // trailing edge, the system time has gone backwards and we're treating
|
||
| 10354 | // it as the trailing edge, or we've hit the `maxWait` limit.
|
||
| 10355 | return (lastCallTime === undefined || (timeSinceLastCall >= wait) || |
||
| 10356 | (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
|
||
| 10357 | } |
||
| 10358 | |||
| 10359 | function timerExpired() { |
||
| 10360 | var time = now();
|
||
| 10361 | if (shouldInvoke(time)) {
|
||
| 10362 | return trailingEdge(time);
|
||
| 10363 | } |
||
| 10364 | // Restart the timer.
|
||
| 10365 | timerId = setTimeout(timerExpired, remainingWait(time)); |
||
| 10366 | } |
||
| 10367 | |||
| 10368 | function trailingEdge(time) { |
||
| 10369 | timerId = undefined;
|
||
| 10370 | |||
| 10371 | // Only invoke if we have `lastArgs` which means `func` has been
|
||
| 10372 | // debounced at least once.
|
||
| 10373 | if (trailing && lastArgs) {
|
||
| 10374 | return invokeFunc(time);
|
||
| 10375 | } |
||
| 10376 | lastArgs = lastThis = undefined;
|
||
| 10377 | return result;
|
||
| 10378 | } |
||
| 10379 | |||
| 10380 | function cancel() { |
||
| 10381 | if (timerId !== undefined) { |
||
| 10382 | clearTimeout(timerId); |
||
| 10383 | } |
||
| 10384 | lastInvokeTime = 0;
|
||
| 10385 | lastArgs = lastCallTime = lastThis = timerId = undefined;
|
||
| 10386 | } |
||
| 10387 | |||
| 10388 | function flush() { |
||
| 10389 | return timerId === undefined ? result : trailingEdge(now()); |
||
| 10390 | } |
||
| 10391 | |||
| 10392 | function debounced() { |
||
| 10393 | var time = now(),
|
||
| 10394 | isInvoking = shouldInvoke(time); |
||
| 10395 | |||
| 10396 | lastArgs = arguments;
|
||
| 10397 | lastThis = this;
|
||
| 10398 | lastCallTime = time; |
||
| 10399 | |||
| 10400 | if (isInvoking) {
|
||
| 10401 | if (timerId === undefined) { |
||
| 10402 | return leadingEdge(lastCallTime);
|
||
| 10403 | } |
||
| 10404 | if (maxing) {
|
||
| 10405 | // Handle invocations in a tight loop.
|
||
| 10406 | timerId = setTimeout(timerExpired, wait); |
||
| 10407 | return invokeFunc(lastCallTime);
|
||
| 10408 | } |
||
| 10409 | } |
||
| 10410 | if (timerId === undefined) { |
||
| 10411 | timerId = setTimeout(timerExpired, wait); |
||
| 10412 | } |
||
| 10413 | return result;
|
||
| 10414 | } |
||
| 10415 | debounced.cancel = cancel; |
||
| 10416 | debounced.flush = flush; |
||
| 10417 | return debounced;
|
||
| 10418 | } |
||
| 10419 | |||
| 10420 | /**
|
||
| 10421 | * Defers invoking the `func` until the current call stack has cleared. Any
|
||
| 10422 | * additional arguments are provided to `func` when it's invoked.
|
||
| 10423 | *
|
||
| 10424 | * @static
|
||
| 10425 | * @memberOf _
|
||
| 10426 | * @since 0.1.0
|
||
| 10427 | * @category Function
|
||
| 10428 | * @param {Function} func The function to defer.
|
||
| 10429 | * @param {...*} [args] The arguments to invoke `func` with.
|
||
| 10430 | * @returns {number} Returns the timer id.
|
||
| 10431 | * @example
|
||
| 10432 | *
|
||
| 10433 | * _.defer(function(text) {
|
||
| 10434 | * console.log(text);
|
||
| 10435 | * }, 'deferred');
|
||
| 10436 | * // => Logs 'deferred' after one millisecond.
|
||
| 10437 | */
|
||
| 10438 | var defer = baseRest(function(func, args) { |
||
| 10439 | return baseDelay(func, 1, args); |
||
| 10440 | }); |
||
| 10441 | |||
| 10442 | /**
|
||
| 10443 | * Invokes `func` after `wait` milliseconds. Any additional arguments are
|
||
| 10444 | * provided to `func` when it's invoked.
|
||
| 10445 | *
|
||
| 10446 | * @static
|
||
| 10447 | * @memberOf _
|
||
| 10448 | * @since 0.1.0
|
||
| 10449 | * @category Function
|
||
| 10450 | * @param {Function} func The function to delay.
|
||
| 10451 | * @param {number} wait The number of milliseconds to delay invocation.
|
||
| 10452 | * @param {...*} [args] The arguments to invoke `func` with.
|
||
| 10453 | * @returns {number} Returns the timer id.
|
||
| 10454 | * @example
|
||
| 10455 | *
|
||
| 10456 | * _.delay(function(text) {
|
||
| 10457 | * console.log(text);
|
||
| 10458 | * }, 1000, 'later');
|
||
| 10459 | * // => Logs 'later' after one second.
|
||
| 10460 | */
|
||
| 10461 | var delay = baseRest(function(func, wait, args) { |
||
| 10462 | return baseDelay(func, toNumber(wait) || 0, args); |
||
| 10463 | }); |
||
| 10464 | |||
| 10465 | /**
|
||
| 10466 | * Creates a function that invokes `func` with arguments reversed.
|
||
| 10467 | *
|
||
| 10468 | * @static
|
||
| 10469 | * @memberOf _
|
||
| 10470 | * @since 4.0.0
|
||
| 10471 | * @category Function
|
||
| 10472 | * @param {Function} func The function to flip arguments for.
|
||
| 10473 | * @returns {Function} Returns the new flipped function.
|
||
| 10474 | * @example
|
||
| 10475 | *
|
||
| 10476 | * var flipped = _.flip(function() {
|
||
| 10477 | * return _.toArray(arguments);
|
||
| 10478 | * });
|
||
| 10479 | *
|
||
| 10480 | * flipped('a', 'b', 'c', 'd');
|
||
| 10481 | * // => ['d', 'c', 'b', 'a']
|
||
| 10482 | */
|
||
| 10483 | function flip(func) { |
||
| 10484 | return createWrap(func, WRAP_FLIP_FLAG);
|
||
| 10485 | } |
||
| 10486 | |||
| 10487 | /**
|
||
| 10488 | * Creates a function that memoizes the result of `func`. If `resolver` is
|
||
| 10489 | * provided, it determines the cache key for storing the result based on the
|
||
| 10490 | * arguments provided to the memoized function. By default, the first argument
|
||
| 10491 | * provided to the memoized function is used as the map cache key. The `func`
|
||
| 10492 | * is invoked with the `this` binding of the memoized function.
|
||
| 10493 | *
|
||
| 10494 | * **Note:** The cache is exposed as the `cache` property on the memoized
|
||
| 10495 | * function. Its creation may be customized by replacing the `_.memoize.Cache`
|
||
| 10496 | * constructor with one whose instances implement the
|
||
| 10497 | * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
|
||
| 10498 | * method interface of `clear`, `delete`, `get`, `has`, and `set`.
|
||
| 10499 | *
|
||
| 10500 | * @static
|
||
| 10501 | * @memberOf _
|
||
| 10502 | * @since 0.1.0
|
||
| 10503 | * @category Function
|
||
| 10504 | * @param {Function} func The function to have its output memoized.
|
||
| 10505 | * @param {Function} [resolver] The function to resolve the cache key.
|
||
| 10506 | * @returns {Function} Returns the new memoized function.
|
||
| 10507 | * @example
|
||
| 10508 | *
|
||
| 10509 | * var object = { 'a': 1, 'b': 2 };
|
||
| 10510 | * var other = { 'c': 3, 'd': 4 };
|
||
| 10511 | *
|
||
| 10512 | * var values = _.memoize(_.values);
|
||
| 10513 | * values(object);
|
||
| 10514 | * // => [1, 2]
|
||
| 10515 | *
|
||
| 10516 | * values(other);
|
||
| 10517 | * // => [3, 4]
|
||
| 10518 | *
|
||
| 10519 | * object.a = 2;
|
||
| 10520 | * values(object);
|
||
| 10521 | * // => [1, 2]
|
||
| 10522 | *
|
||
| 10523 | * // Modify the result cache.
|
||
| 10524 | * values.cache.set(object, ['a', 'b']);
|
||
| 10525 | * values(object);
|
||
| 10526 | * // => ['a', 'b']
|
||
| 10527 | *
|
||
| 10528 | * // Replace `_.memoize.Cache`.
|
||
| 10529 | * _.memoize.Cache = WeakMap;
|
||
| 10530 | */
|
||
| 10531 | function memoize(func, resolver) { |
||
| 10532 | if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { |
||
| 10533 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 10534 | } |
||
| 10535 | var memoized = function() { |
||
| 10536 | var args = arguments, |
||
| 10537 | key = resolver ? resolver.apply(this, args) : args[0], |
||
| 10538 | cache = memoized.cache; |
||
| 10539 | |||
| 10540 | if (cache.has(key)) {
|
||
| 10541 | return cache.get(key);
|
||
| 10542 | } |
||
| 10543 | var result = func.apply(this, args); |
||
| 10544 | memoized.cache = cache.set(key, result) || cache; |
||
| 10545 | return result;
|
||
| 10546 | }; |
||
| 10547 | memoized.cache = new (memoize.Cache || MapCache);
|
||
| 10548 | return memoized;
|
||
| 10549 | } |
||
| 10550 | |||
| 10551 | // Expose `MapCache`.
|
||
| 10552 | memoize.Cache = MapCache; |
||
| 10553 | |||
| 10554 | /**
|
||
| 10555 | * Creates a function that negates the result of the predicate `func`. The
|
||
| 10556 | * `func` predicate is invoked with the `this` binding and arguments of the
|
||
| 10557 | * created function.
|
||
| 10558 | *
|
||
| 10559 | * @static
|
||
| 10560 | * @memberOf _
|
||
| 10561 | * @since 3.0.0
|
||
| 10562 | * @category Function
|
||
| 10563 | * @param {Function} predicate The predicate to negate.
|
||
| 10564 | * @returns {Function} Returns the new negated function.
|
||
| 10565 | * @example
|
||
| 10566 | *
|
||
| 10567 | * function isEven(n) {
|
||
| 10568 | * return n % 2 == 0;
|
||
| 10569 | * }
|
||
| 10570 | *
|
||
| 10571 | * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
|
||
| 10572 | * // => [1, 3, 5]
|
||
| 10573 | */
|
||
| 10574 | function negate(predicate) { |
||
| 10575 | if (typeof predicate != 'function') { |
||
| 10576 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 10577 | } |
||
| 10578 | return function() { |
||
| 10579 | var args = arguments; |
||
| 10580 | switch (args.length) {
|
||
| 10581 | case 0: return !predicate.call(this); |
||
| 10582 | case 1: return !predicate.call(this, args[0]); |
||
| 10583 | case 2: return !predicate.call(this, args[0], args[1]); |
||
| 10584 | case 3: return !predicate.call(this, args[0], args[1], args[2]); |
||
| 10585 | } |
||
| 10586 | return !predicate.apply(this, args); |
||
| 10587 | }; |
||
| 10588 | } |
||
| 10589 | |||
| 10590 | /**
|
||
| 10591 | * Creates a function that is restricted to invoking `func` once. Repeat calls
|
||
| 10592 | * to the function return the value of the first invocation. The `func` is
|
||
| 10593 | * invoked with the `this` binding and arguments of the created function.
|
||
| 10594 | *
|
||
| 10595 | * @static
|
||
| 10596 | * @memberOf _
|
||
| 10597 | * @since 0.1.0
|
||
| 10598 | * @category Function
|
||
| 10599 | * @param {Function} func The function to restrict.
|
||
| 10600 | * @returns {Function} Returns the new restricted function.
|
||
| 10601 | * @example
|
||
| 10602 | *
|
||
| 10603 | * var initialize = _.once(createApplication);
|
||
| 10604 | * initialize();
|
||
| 10605 | * initialize();
|
||
| 10606 | * // => `createApplication` is invoked once
|
||
| 10607 | */
|
||
| 10608 | function once(func) { |
||
| 10609 | return before(2, func); |
||
| 10610 | } |
||
| 10611 | |||
| 10612 | /**
|
||
| 10613 | * Creates a function that invokes `func` with its arguments transformed.
|
||
| 10614 | *
|
||
| 10615 | * @static
|
||
| 10616 | * @since 4.0.0
|
||
| 10617 | * @memberOf _
|
||
| 10618 | * @category Function
|
||
| 10619 | * @param {Function} func The function to wrap.
|
||
| 10620 | * @param {...(Function|Function[])} [transforms=[_.identity]]
|
||
| 10621 | * The argument transforms.
|
||
| 10622 | * @returns {Function} Returns the new function.
|
||
| 10623 | * @example
|
||
| 10624 | *
|
||
| 10625 | * function doubled(n) {
|
||
| 10626 | * return n * 2;
|
||
| 10627 | * }
|
||
| 10628 | *
|
||
| 10629 | * function square(n) {
|
||
| 10630 | * return n * n;
|
||
| 10631 | * }
|
||
| 10632 | *
|
||
| 10633 | * var func = _.overArgs(function(x, y) {
|
||
| 10634 | * return [x, y];
|
||
| 10635 | * }, [square, doubled]);
|
||
| 10636 | *
|
||
| 10637 | * func(9, 3);
|
||
| 10638 | * // => [81, 6]
|
||
| 10639 | *
|
||
| 10640 | * func(10, 5);
|
||
| 10641 | * // => [100, 10]
|
||
| 10642 | */
|
||
| 10643 | var overArgs = castRest(function(func, transforms) { |
||
| 10644 | transforms = (transforms.length == 1 && isArray(transforms[0])) |
||
| 10645 | ? arrayMap(transforms[0], baseUnary(getIteratee()))
|
||
| 10646 | : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
|
||
| 10647 | |||
| 10648 | var funcsLength = transforms.length;
|
||
| 10649 | return baseRest(function(args) { |
||
| 10650 | var index = -1, |
||
| 10651 | length = nativeMin(args.length, funcsLength); |
||
| 10652 | |||
| 10653 | while (++index < length) {
|
||
| 10654 | args[index] = transforms[index].call(this, args[index]);
|
||
| 10655 | } |
||
| 10656 | return apply(func, this, args); |
||
| 10657 | }); |
||
| 10658 | }); |
||
| 10659 | |||
| 10660 | /**
|
||
| 10661 | * Creates a function that invokes `func` with `partials` prepended to the
|
||
| 10662 | * arguments it receives. This method is like `_.bind` except it does **not**
|
||
| 10663 | * alter the `this` binding.
|
||
| 10664 | *
|
||
| 10665 | * The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
||
| 10666 | * builds, may be used as a placeholder for partially applied arguments.
|
||
| 10667 | *
|
||
| 10668 | * **Note:** This method doesn't set the "length" property of partially
|
||
| 10669 | * applied functions.
|
||
| 10670 | *
|
||
| 10671 | * @static
|
||
| 10672 | * @memberOf _
|
||
| 10673 | * @since 0.2.0
|
||
| 10674 | * @category Function
|
||
| 10675 | * @param {Function} func The function to partially apply arguments to.
|
||
| 10676 | * @param {...*} [partials] The arguments to be partially applied.
|
||
| 10677 | * @returns {Function} Returns the new partially applied function.
|
||
| 10678 | * @example
|
||
| 10679 | *
|
||
| 10680 | * function greet(greeting, name) {
|
||
| 10681 | * return greeting + ' ' + name;
|
||
| 10682 | * }
|
||
| 10683 | *
|
||
| 10684 | * var sayHelloTo = _.partial(greet, 'hello');
|
||
| 10685 | * sayHelloTo('fred');
|
||
| 10686 | * // => 'hello fred'
|
||
| 10687 | *
|
||
| 10688 | * // Partially applied with placeholders.
|
||
| 10689 | * var greetFred = _.partial(greet, _, 'fred');
|
||
| 10690 | * greetFred('hi');
|
||
| 10691 | * // => 'hi fred'
|
||
| 10692 | */
|
||
| 10693 | var partial = baseRest(function(func, partials) { |
||
| 10694 | var holders = replaceHolders(partials, getHolder(partial));
|
||
| 10695 | return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders); |
||
| 10696 | }); |
||
| 10697 | |||
| 10698 | /**
|
||
| 10699 | * This method is like `_.partial` except that partially applied arguments
|
||
| 10700 | * are appended to the arguments it receives.
|
||
| 10701 | *
|
||
| 10702 | * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
||
| 10703 | * builds, may be used as a placeholder for partially applied arguments.
|
||
| 10704 | *
|
||
| 10705 | * **Note:** This method doesn't set the "length" property of partially
|
||
| 10706 | * applied functions.
|
||
| 10707 | *
|
||
| 10708 | * @static
|
||
| 10709 | * @memberOf _
|
||
| 10710 | * @since 1.0.0
|
||
| 10711 | * @category Function
|
||
| 10712 | * @param {Function} func The function to partially apply arguments to.
|
||
| 10713 | * @param {...*} [partials] The arguments to be partially applied.
|
||
| 10714 | * @returns {Function} Returns the new partially applied function.
|
||
| 10715 | * @example
|
||
| 10716 | *
|
||
| 10717 | * function greet(greeting, name) {
|
||
| 10718 | * return greeting + ' ' + name;
|
||
| 10719 | * }
|
||
| 10720 | *
|
||
| 10721 | * var greetFred = _.partialRight(greet, 'fred');
|
||
| 10722 | * greetFred('hi');
|
||
| 10723 | * // => 'hi fred'
|
||
| 10724 | *
|
||
| 10725 | * // Partially applied with placeholders.
|
||
| 10726 | * var sayHelloTo = _.partialRight(greet, 'hello', _);
|
||
| 10727 | * sayHelloTo('fred');
|
||
| 10728 | * // => 'hello fred'
|
||
| 10729 | */
|
||
| 10730 | var partialRight = baseRest(function(func, partials) { |
||
| 10731 | var holders = replaceHolders(partials, getHolder(partialRight));
|
||
| 10732 | return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders); |
||
| 10733 | }); |
||
| 10734 | |||
| 10735 | /**
|
||
| 10736 | * Creates a function that invokes `func` with arguments arranged according
|
||
| 10737 | * to the specified `indexes` where the argument value at the first index is
|
||
| 10738 | * provided as the first argument, the argument value at the second index is
|
||
| 10739 | * provided as the second argument, and so on.
|
||
| 10740 | *
|
||
| 10741 | * @static
|
||
| 10742 | * @memberOf _
|
||
| 10743 | * @since 3.0.0
|
||
| 10744 | * @category Function
|
||
| 10745 | * @param {Function} func The function to rearrange arguments for.
|
||
| 10746 | * @param {...(number|number[])} indexes The arranged argument indexes.
|
||
| 10747 | * @returns {Function} Returns the new function.
|
||
| 10748 | * @example
|
||
| 10749 | *
|
||
| 10750 | * var rearged = _.rearg(function(a, b, c) {
|
||
| 10751 | * return [a, b, c];
|
||
| 10752 | * }, [2, 0, 1]);
|
||
| 10753 | *
|
||
| 10754 | * rearged('b', 'c', 'a')
|
||
| 10755 | * // => ['a', 'b', 'c']
|
||
| 10756 | */
|
||
| 10757 | var rearg = flatRest(function(func, indexes) { |
||
| 10758 | return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes); |
||
| 10759 | }); |
||
| 10760 | |||
| 10761 | /**
|
||
| 10762 | * Creates a function that invokes `func` with the `this` binding of the
|
||
| 10763 | * created function and arguments from `start` and beyond provided as
|
||
| 10764 | * an array.
|
||
| 10765 | *
|
||
| 10766 | * **Note:** This method is based on the
|
||
| 10767 | * [rest parameter](https://mdn.io/rest_parameters).
|
||
| 10768 | *
|
||
| 10769 | * @static
|
||
| 10770 | * @memberOf _
|
||
| 10771 | * @since 4.0.0
|
||
| 10772 | * @category Function
|
||
| 10773 | * @param {Function} func The function to apply a rest parameter to.
|
||
| 10774 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
||
| 10775 | * @returns {Function} Returns the new function.
|
||
| 10776 | * @example
|
||
| 10777 | *
|
||
| 10778 | * var say = _.rest(function(what, names) {
|
||
| 10779 | * return what + ' ' + _.initial(names).join(', ') +
|
||
| 10780 | * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
||
| 10781 | * });
|
||
| 10782 | *
|
||
| 10783 | * say('hello', 'fred', 'barney', 'pebbles');
|
||
| 10784 | * // => 'hello fred, barney, & pebbles'
|
||
| 10785 | */
|
||
| 10786 | function rest(func, start) { |
||
| 10787 | if (typeof func != 'function') { |
||
| 10788 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 10789 | } |
||
| 10790 | start = start === undefined ? start : toInteger(start);
|
||
| 10791 | return baseRest(func, start);
|
||
| 10792 | } |
||
| 10793 | |||
| 10794 | /**
|
||
| 10795 | * Creates a function that invokes `func` with the `this` binding of the
|
||
| 10796 | * create function and an array of arguments much like
|
||
| 10797 | * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
|
||
| 10798 | *
|
||
| 10799 | * **Note:** This method is based on the
|
||
| 10800 | * [spread operator](https://mdn.io/spread_operator).
|
||
| 10801 | *
|
||
| 10802 | * @static
|
||
| 10803 | * @memberOf _
|
||
| 10804 | * @since 3.2.0
|
||
| 10805 | * @category Function
|
||
| 10806 | * @param {Function} func The function to spread arguments over.
|
||
| 10807 | * @param {number} [start=0] The start position of the spread.
|
||
| 10808 | * @returns {Function} Returns the new function.
|
||
| 10809 | * @example
|
||
| 10810 | *
|
||
| 10811 | * var say = _.spread(function(who, what) {
|
||
| 10812 | * return who + ' says ' + what;
|
||
| 10813 | * });
|
||
| 10814 | *
|
||
| 10815 | * say(['fred', 'hello']);
|
||
| 10816 | * // => 'fred says hello'
|
||
| 10817 | *
|
||
| 10818 | * var numbers = Promise.all([
|
||
| 10819 | * Promise.resolve(40),
|
||
| 10820 | * Promise.resolve(36)
|
||
| 10821 | * ]);
|
||
| 10822 | *
|
||
| 10823 | * numbers.then(_.spread(function(x, y) {
|
||
| 10824 | * return x + y;
|
||
| 10825 | * }));
|
||
| 10826 | * // => a Promise of 76
|
||
| 10827 | */
|
||
| 10828 | function spread(func, start) { |
||
| 10829 | if (typeof func != 'function') { |
||
| 10830 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 10831 | } |
||
| 10832 | start = start == null ? 0 : nativeMax(toInteger(start), 0); |
||
| 10833 | return baseRest(function(args) { |
||
| 10834 | var array = args[start],
|
||
| 10835 | otherArgs = castSlice(args, 0, start);
|
||
| 10836 | |||
| 10837 | if (array) {
|
||
| 10838 | arrayPush(otherArgs, array); |
||
| 10839 | } |
||
| 10840 | return apply(func, this, otherArgs); |
||
| 10841 | }); |
||
| 10842 | } |
||
| 10843 | |||
| 10844 | /**
|
||
| 10845 | * Creates a throttled function that only invokes `func` at most once per
|
||
| 10846 | * every `wait` milliseconds. The throttled function comes with a `cancel`
|
||
| 10847 | * method to cancel delayed `func` invocations and a `flush` method to
|
||
| 10848 | * immediately invoke them. Provide `options` to indicate whether `func`
|
||
| 10849 | * should be invoked on the leading and/or trailing edge of the `wait`
|
||
| 10850 | * timeout. The `func` is invoked with the last arguments provided to the
|
||
| 10851 | * throttled function. Subsequent calls to the throttled function return the
|
||
| 10852 | * result of the last `func` invocation.
|
||
| 10853 | *
|
||
| 10854 | * **Note:** If `leading` and `trailing` options are `true`, `func` is
|
||
| 10855 | * invoked on the trailing edge of the timeout only if the throttled function
|
||
| 10856 | * is invoked more than once during the `wait` timeout.
|
||
| 10857 | *
|
||
| 10858 | * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
||
| 10859 | * until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
||
| 10860 | *
|
||
| 10861 | * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
||
| 10862 | * for details over the differences between `_.throttle` and `_.debounce`.
|
||
| 10863 | *
|
||
| 10864 | * @static
|
||
| 10865 | * @memberOf _
|
||
| 10866 | * @since 0.1.0
|
||
| 10867 | * @category Function
|
||
| 10868 | * @param {Function} func The function to throttle.
|
||
| 10869 | * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
||
| 10870 | * @param {Object} [options={}] The options object.
|
||
| 10871 | * @param {boolean} [options.leading=true]
|
||
| 10872 | * Specify invoking on the leading edge of the timeout.
|
||
| 10873 | * @param {boolean} [options.trailing=true]
|
||
| 10874 | * Specify invoking on the trailing edge of the timeout.
|
||
| 10875 | * @returns {Function} Returns the new throttled function.
|
||
| 10876 | * @example
|
||
| 10877 | *
|
||
| 10878 | * // Avoid excessively updating the position while scrolling.
|
||
| 10879 | * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
||
| 10880 | *
|
||
| 10881 | * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
||
| 10882 | * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
||
| 10883 | * jQuery(element).on('click', throttled);
|
||
| 10884 | *
|
||
| 10885 | * // Cancel the trailing throttled invocation.
|
||
| 10886 | * jQuery(window).on('popstate', throttled.cancel);
|
||
| 10887 | */
|
||
| 10888 | function throttle(func, wait, options) { |
||
| 10889 | var leading = true, |
||
| 10890 | trailing = true;
|
||
| 10891 | |||
| 10892 | if (typeof func != 'function') { |
||
| 10893 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 10894 | } |
||
| 10895 | if (isObject(options)) {
|
||
| 10896 | leading = 'leading' in options ? !!options.leading : leading; |
||
| 10897 | trailing = 'trailing' in options ? !!options.trailing : trailing; |
||
| 10898 | } |
||
| 10899 | return debounce(func, wait, {
|
||
| 10900 | 'leading': leading,
|
||
| 10901 | 'maxWait': wait,
|
||
| 10902 | 'trailing': trailing
|
||
| 10903 | }); |
||
| 10904 | } |
||
| 10905 | |||
| 10906 | /**
|
||
| 10907 | * Creates a function that accepts up to one argument, ignoring any
|
||
| 10908 | * additional arguments.
|
||
| 10909 | *
|
||
| 10910 | * @static
|
||
| 10911 | * @memberOf _
|
||
| 10912 | * @since 4.0.0
|
||
| 10913 | * @category Function
|
||
| 10914 | * @param {Function} func The function to cap arguments for.
|
||
| 10915 | * @returns {Function} Returns the new capped function.
|
||
| 10916 | * @example
|
||
| 10917 | *
|
||
| 10918 | * _.map(['6', '8', '10'], _.unary(parseInt));
|
||
| 10919 | * // => [6, 8, 10]
|
||
| 10920 | */
|
||
| 10921 | function unary(func) { |
||
| 10922 | return ary(func, 1); |
||
| 10923 | } |
||
| 10924 | |||
| 10925 | /**
|
||
| 10926 | * Creates a function that provides `value` to `wrapper` as its first
|
||
| 10927 | * argument. Any additional arguments provided to the function are appended
|
||
| 10928 | * to those provided to the `wrapper`. The wrapper is invoked with the `this`
|
||
| 10929 | * binding of the created function.
|
||
| 10930 | *
|
||
| 10931 | * @static
|
||
| 10932 | * @memberOf _
|
||
| 10933 | * @since 0.1.0
|
||
| 10934 | * @category Function
|
||
| 10935 | * @param {*} value The value to wrap.
|
||
| 10936 | * @param {Function} [wrapper=identity] The wrapper function.
|
||
| 10937 | * @returns {Function} Returns the new function.
|
||
| 10938 | * @example
|
||
| 10939 | *
|
||
| 10940 | * var p = _.wrap(_.escape, function(func, text) {
|
||
| 10941 | * return '<p>' + func(text) + '</p>';
|
||
| 10942 | * });
|
||
| 10943 | *
|
||
| 10944 | * p('fred, barney, & pebbles');
|
||
| 10945 | * // => '<p>fred, barney, & pebbles</p>'
|
||
| 10946 | */
|
||
| 10947 | function wrap(value, wrapper) { |
||
| 10948 | return partial(castFunction(wrapper), value);
|
||
| 10949 | } |
||
| 10950 | |||
| 10951 | /*------------------------------------------------------------------------*/
|
||
| 10952 | |||
| 10953 | /**
|
||
| 10954 | * Casts `value` as an array if it's not one.
|
||
| 10955 | *
|
||
| 10956 | * @static
|
||
| 10957 | * @memberOf _
|
||
| 10958 | * @since 4.4.0
|
||
| 10959 | * @category Lang
|
||
| 10960 | * @param {*} value The value to inspect.
|
||
| 10961 | * @returns {Array} Returns the cast array.
|
||
| 10962 | * @example
|
||
| 10963 | *
|
||
| 10964 | * _.castArray(1);
|
||
| 10965 | * // => [1]
|
||
| 10966 | *
|
||
| 10967 | * _.castArray({ 'a': 1 });
|
||
| 10968 | * // => [{ 'a': 1 }]
|
||
| 10969 | *
|
||
| 10970 | * _.castArray('abc');
|
||
| 10971 | * // => ['abc']
|
||
| 10972 | *
|
||
| 10973 | * _.castArray(null);
|
||
| 10974 | * // => [null]
|
||
| 10975 | *
|
||
| 10976 | * _.castArray(undefined);
|
||
| 10977 | * // => [undefined]
|
||
| 10978 | *
|
||
| 10979 | * _.castArray();
|
||
| 10980 | * // => []
|
||
| 10981 | *
|
||
| 10982 | * var array = [1, 2, 3];
|
||
| 10983 | * console.log(_.castArray(array) === array);
|
||
| 10984 | * // => true
|
||
| 10985 | */
|
||
| 10986 | function castArray() { |
||
| 10987 | if (!arguments.length) { |
||
| 10988 | return [];
|
||
| 10989 | } |
||
| 10990 | var value = arguments[0]; |
||
| 10991 | return isArray(value) ? value : [value];
|
||
| 10992 | } |
||
| 10993 | |||
| 10994 | /**
|
||
| 10995 | * Creates a shallow clone of `value`.
|
||
| 10996 | *
|
||
| 10997 | * **Note:** This method is loosely based on the
|
||
| 10998 | * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
|
||
| 10999 | * and supports cloning arrays, array buffers, booleans, date objects, maps,
|
||
| 11000 | * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
|
||
| 11001 | * arrays. The own enumerable properties of `arguments` objects are cloned
|
||
| 11002 | * as plain objects. An empty object is returned for uncloneable values such
|
||
| 11003 | * as error objects, functions, DOM nodes, and WeakMaps.
|
||
| 11004 | *
|
||
| 11005 | * @static
|
||
| 11006 | * @memberOf _
|
||
| 11007 | * @since 0.1.0
|
||
| 11008 | * @category Lang
|
||
| 11009 | * @param {*} value The value to clone.
|
||
| 11010 | * @returns {*} Returns the cloned value.
|
||
| 11011 | * @see _.cloneDeep
|
||
| 11012 | * @example
|
||
| 11013 | *
|
||
| 11014 | * var objects = [{ 'a': 1 }, { 'b': 2 }];
|
||
| 11015 | *
|
||
| 11016 | * var shallow = _.clone(objects);
|
||
| 11017 | * console.log(shallow[0] === objects[0]);
|
||
| 11018 | * // => true
|
||
| 11019 | */
|
||
| 11020 | function clone(value) { |
||
| 11021 | return baseClone(value, CLONE_SYMBOLS_FLAG);
|
||
| 11022 | } |
||
| 11023 | |||
| 11024 | /**
|
||
| 11025 | * This method is like `_.clone` except that it accepts `customizer` which
|
||
| 11026 | * is invoked to produce the cloned value. If `customizer` returns `undefined`,
|
||
| 11027 | * cloning is handled by the method instead. The `customizer` is invoked with
|
||
| 11028 | * up to four arguments; (value [, index|key, object, stack]).
|
||
| 11029 | *
|
||
| 11030 | * @static
|
||
| 11031 | * @memberOf _
|
||
| 11032 | * @since 4.0.0
|
||
| 11033 | * @category Lang
|
||
| 11034 | * @param {*} value The value to clone.
|
||
| 11035 | * @param {Function} [customizer] The function to customize cloning.
|
||
| 11036 | * @returns {*} Returns the cloned value.
|
||
| 11037 | * @see _.cloneDeepWith
|
||
| 11038 | * @example
|
||
| 11039 | *
|
||
| 11040 | * function customizer(value) {
|
||
| 11041 | * if (_.isElement(value)) {
|
||
| 11042 | * return value.cloneNode(false);
|
||
| 11043 | * }
|
||
| 11044 | * }
|
||
| 11045 | *
|
||
| 11046 | * var el = _.cloneWith(document.body, customizer);
|
||
| 11047 | *
|
||
| 11048 | * console.log(el === document.body);
|
||
| 11049 | * // => false
|
||
| 11050 | * console.log(el.nodeName);
|
||
| 11051 | * // => 'BODY'
|
||
| 11052 | * console.log(el.childNodes.length);
|
||
| 11053 | * // => 0
|
||
| 11054 | */
|
||
| 11055 | function cloneWith(value, customizer) { |
||
| 11056 | customizer = typeof customizer == 'function' ? customizer : undefined; |
||
| 11057 | return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
|
||
| 11058 | } |
||
| 11059 | |||
| 11060 | /**
|
||
| 11061 | * This method is like `_.clone` except that it recursively clones `value`.
|
||
| 11062 | *
|
||
| 11063 | * @static
|
||
| 11064 | * @memberOf _
|
||
| 11065 | * @since 1.0.0
|
||
| 11066 | * @category Lang
|
||
| 11067 | * @param {*} value The value to recursively clone.
|
||
| 11068 | * @returns {*} Returns the deep cloned value.
|
||
| 11069 | * @see _.clone
|
||
| 11070 | * @example
|
||
| 11071 | *
|
||
| 11072 | * var objects = [{ 'a': 1 }, { 'b': 2 }];
|
||
| 11073 | *
|
||
| 11074 | * var deep = _.cloneDeep(objects);
|
||
| 11075 | * console.log(deep[0] === objects[0]);
|
||
| 11076 | * // => false
|
||
| 11077 | */
|
||
| 11078 | function cloneDeep(value) { |
||
| 11079 | return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
|
||
| 11080 | } |
||
| 11081 | |||
| 11082 | /**
|
||
| 11083 | * This method is like `_.cloneWith` except that it recursively clones `value`.
|
||
| 11084 | *
|
||
| 11085 | * @static
|
||
| 11086 | * @memberOf _
|
||
| 11087 | * @since 4.0.0
|
||
| 11088 | * @category Lang
|
||
| 11089 | * @param {*} value The value to recursively clone.
|
||
| 11090 | * @param {Function} [customizer] The function to customize cloning.
|
||
| 11091 | * @returns {*} Returns the deep cloned value.
|
||
| 11092 | * @see _.cloneWith
|
||
| 11093 | * @example
|
||
| 11094 | *
|
||
| 11095 | * function customizer(value) {
|
||
| 11096 | * if (_.isElement(value)) {
|
||
| 11097 | * return value.cloneNode(true);
|
||
| 11098 | * }
|
||
| 11099 | * }
|
||
| 11100 | *
|
||
| 11101 | * var el = _.cloneDeepWith(document.body, customizer);
|
||
| 11102 | *
|
||
| 11103 | * console.log(el === document.body);
|
||
| 11104 | * // => false
|
||
| 11105 | * console.log(el.nodeName);
|
||
| 11106 | * // => 'BODY'
|
||
| 11107 | * console.log(el.childNodes.length);
|
||
| 11108 | * // => 20
|
||
| 11109 | */
|
||
| 11110 | function cloneDeepWith(value, customizer) { |
||
| 11111 | customizer = typeof customizer == 'function' ? customizer : undefined; |
||
| 11112 | return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
|
||
| 11113 | } |
||
| 11114 | |||
| 11115 | /**
|
||
| 11116 | * Checks if `object` conforms to `source` by invoking the predicate
|
||
| 11117 | * properties of `source` with the corresponding property values of `object`.
|
||
| 11118 | *
|
||
| 11119 | * **Note:** This method is equivalent to `_.conforms` when `source` is
|
||
| 11120 | * partially applied.
|
||
| 11121 | *
|
||
| 11122 | * @static
|
||
| 11123 | * @memberOf _
|
||
| 11124 | * @since 4.14.0
|
||
| 11125 | * @category Lang
|
||
| 11126 | * @param {Object} object The object to inspect.
|
||
| 11127 | * @param {Object} source The object of property predicates to conform to.
|
||
| 11128 | * @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
||
| 11129 | * @example
|
||
| 11130 | *
|
||
| 11131 | * var object = { 'a': 1, 'b': 2 };
|
||
| 11132 | *
|
||
| 11133 | * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
|
||
| 11134 | * // => true
|
||
| 11135 | *
|
||
| 11136 | * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
|
||
| 11137 | * // => false
|
||
| 11138 | */
|
||
| 11139 | function conformsTo(object, source) { |
||
| 11140 | return source == null || baseConformsTo(object, source, keys(source)); |
||
| 11141 | } |
||
| 11142 | |||
| 11143 | /**
|
||
| 11144 | * Performs a
|
||
| 11145 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
||
| 11146 | * comparison between two values to determine if they are equivalent.
|
||
| 11147 | *
|
||
| 11148 | * @static
|
||
| 11149 | * @memberOf _
|
||
| 11150 | * @since 4.0.0
|
||
| 11151 | * @category Lang
|
||
| 11152 | * @param {*} value The value to compare.
|
||
| 11153 | * @param {*} other The other value to compare.
|
||
| 11154 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
||
| 11155 | * @example
|
||
| 11156 | *
|
||
| 11157 | * var object = { 'a': 1 };
|
||
| 11158 | * var other = { 'a': 1 };
|
||
| 11159 | *
|
||
| 11160 | * _.eq(object, object);
|
||
| 11161 | * // => true
|
||
| 11162 | *
|
||
| 11163 | * _.eq(object, other);
|
||
| 11164 | * // => false
|
||
| 11165 | *
|
||
| 11166 | * _.eq('a', 'a');
|
||
| 11167 | * // => true
|
||
| 11168 | *
|
||
| 11169 | * _.eq('a', Object('a'));
|
||
| 11170 | * // => false
|
||
| 11171 | *
|
||
| 11172 | * _.eq(NaN, NaN);
|
||
| 11173 | * // => true
|
||
| 11174 | */
|
||
| 11175 | function eq(value, other) { |
||
| 11176 | return value === other || (value !== value && other !== other);
|
||
| 11177 | } |
||
| 11178 | |||
| 11179 | /**
|
||
| 11180 | * Checks if `value` is greater than `other`.
|
||
| 11181 | *
|
||
| 11182 | * @static
|
||
| 11183 | * @memberOf _
|
||
| 11184 | * @since 3.9.0
|
||
| 11185 | * @category Lang
|
||
| 11186 | * @param {*} value The value to compare.
|
||
| 11187 | * @param {*} other The other value to compare.
|
||
| 11188 | * @returns {boolean} Returns `true` if `value` is greater than `other`,
|
||
| 11189 | * else `false`.
|
||
| 11190 | * @see _.lt
|
||
| 11191 | * @example
|
||
| 11192 | *
|
||
| 11193 | * _.gt(3, 1);
|
||
| 11194 | * // => true
|
||
| 11195 | *
|
||
| 11196 | * _.gt(3, 3);
|
||
| 11197 | * // => false
|
||
| 11198 | *
|
||
| 11199 | * _.gt(1, 3);
|
||
| 11200 | * // => false
|
||
| 11201 | */
|
||
| 11202 | var gt = createRelationalOperation(baseGt);
|
||
| 11203 | |||
| 11204 | /**
|
||
| 11205 | * Checks if `value` is greater than or equal to `other`.
|
||
| 11206 | *
|
||
| 11207 | * @static
|
||
| 11208 | * @memberOf _
|
||
| 11209 | * @since 3.9.0
|
||
| 11210 | * @category Lang
|
||
| 11211 | * @param {*} value The value to compare.
|
||
| 11212 | * @param {*} other The other value to compare.
|
||
| 11213 | * @returns {boolean} Returns `true` if `value` is greater than or equal to
|
||
| 11214 | * `other`, else `false`.
|
||
| 11215 | * @see _.lte
|
||
| 11216 | * @example
|
||
| 11217 | *
|
||
| 11218 | * _.gte(3, 1);
|
||
| 11219 | * // => true
|
||
| 11220 | *
|
||
| 11221 | * _.gte(3, 3);
|
||
| 11222 | * // => true
|
||
| 11223 | *
|
||
| 11224 | * _.gte(1, 3);
|
||
| 11225 | * // => false
|
||
| 11226 | */
|
||
| 11227 | var gte = createRelationalOperation(function(value, other) { |
||
| 11228 | return value >= other;
|
||
| 11229 | }); |
||
| 11230 | |||
| 11231 | /**
|
||
| 11232 | * Checks if `value` is likely an `arguments` object.
|
||
| 11233 | *
|
||
| 11234 | * @static
|
||
| 11235 | * @memberOf _
|
||
| 11236 | * @since 0.1.0
|
||
| 11237 | * @category Lang
|
||
| 11238 | * @param {*} value The value to check.
|
||
| 11239 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
||
| 11240 | * else `false`.
|
||
| 11241 | * @example
|
||
| 11242 | *
|
||
| 11243 | * _.isArguments(function() { return arguments; }());
|
||
| 11244 | * // => true
|
||
| 11245 | *
|
||
| 11246 | * _.isArguments([1, 2, 3]);
|
||
| 11247 | * // => false
|
||
| 11248 | */
|
||
| 11249 | var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { |
||
| 11250 | return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && |
||
| 11251 | !propertyIsEnumerable.call(value, 'callee');
|
||
| 11252 | }; |
||
| 11253 | |||
| 11254 | /**
|
||
| 11255 | * Checks if `value` is classified as an `Array` object.
|
||
| 11256 | *
|
||
| 11257 | * @static
|
||
| 11258 | * @memberOf _
|
||
| 11259 | * @since 0.1.0
|
||
| 11260 | * @category Lang
|
||
| 11261 | * @param {*} value The value to check.
|
||
| 11262 | * @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
||
| 11263 | * @example
|
||
| 11264 | *
|
||
| 11265 | * _.isArray([1, 2, 3]);
|
||
| 11266 | * // => true
|
||
| 11267 | *
|
||
| 11268 | * _.isArray(document.body.children);
|
||
| 11269 | * // => false
|
||
| 11270 | *
|
||
| 11271 | * _.isArray('abc');
|
||
| 11272 | * // => false
|
||
| 11273 | *
|
||
| 11274 | * _.isArray(_.noop);
|
||
| 11275 | * // => false
|
||
| 11276 | */
|
||
| 11277 | var isArray = Array.isArray;
|
||
| 11278 | |||
| 11279 | /**
|
||
| 11280 | * Checks if `value` is classified as an `ArrayBuffer` object.
|
||
| 11281 | *
|
||
| 11282 | * @static
|
||
| 11283 | * @memberOf _
|
||
| 11284 | * @since 4.3.0
|
||
| 11285 | * @category Lang
|
||
| 11286 | * @param {*} value The value to check.
|
||
| 11287 | * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
|
||
| 11288 | * @example
|
||
| 11289 | *
|
||
| 11290 | * _.isArrayBuffer(new ArrayBuffer(2));
|
||
| 11291 | * // => true
|
||
| 11292 | *
|
||
| 11293 | * _.isArrayBuffer(new Array(2));
|
||
| 11294 | * // => false
|
||
| 11295 | */
|
||
| 11296 | var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
|
||
| 11297 | |||
| 11298 | /**
|
||
| 11299 | * Checks if `value` is array-like. A value is considered array-like if it's
|
||
| 11300 | * not a function and has a `value.length` that's an integer greater than or
|
||
| 11301 | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
||
| 11302 | *
|
||
| 11303 | * @static
|
||
| 11304 | * @memberOf _
|
||
| 11305 | * @since 4.0.0
|
||
| 11306 | * @category Lang
|
||
| 11307 | * @param {*} value The value to check.
|
||
| 11308 | * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
||
| 11309 | * @example
|
||
| 11310 | *
|
||
| 11311 | * _.isArrayLike([1, 2, 3]);
|
||
| 11312 | * // => true
|
||
| 11313 | *
|
||
| 11314 | * _.isArrayLike(document.body.children);
|
||
| 11315 | * // => true
|
||
| 11316 | *
|
||
| 11317 | * _.isArrayLike('abc');
|
||
| 11318 | * // => true
|
||
| 11319 | *
|
||
| 11320 | * _.isArrayLike(_.noop);
|
||
| 11321 | * // => false
|
||
| 11322 | */
|
||
| 11323 | function isArrayLike(value) { |
||
| 11324 | return value != null && isLength(value.length) && !isFunction(value); |
||
| 11325 | } |
||
| 11326 | |||
| 11327 | /**
|
||
| 11328 | * This method is like `_.isArrayLike` except that it also checks if `value`
|
||
| 11329 | * is an object.
|
||
| 11330 | *
|
||
| 11331 | * @static
|
||
| 11332 | * @memberOf _
|
||
| 11333 | * @since 4.0.0
|
||
| 11334 | * @category Lang
|
||
| 11335 | * @param {*} value The value to check.
|
||
| 11336 | * @returns {boolean} Returns `true` if `value` is an array-like object,
|
||
| 11337 | * else `false`.
|
||
| 11338 | * @example
|
||
| 11339 | *
|
||
| 11340 | * _.isArrayLikeObject([1, 2, 3]);
|
||
| 11341 | * // => true
|
||
| 11342 | *
|
||
| 11343 | * _.isArrayLikeObject(document.body.children);
|
||
| 11344 | * // => true
|
||
| 11345 | *
|
||
| 11346 | * _.isArrayLikeObject('abc');
|
||
| 11347 | * // => false
|
||
| 11348 | *
|
||
| 11349 | * _.isArrayLikeObject(_.noop);
|
||
| 11350 | * // => false
|
||
| 11351 | */
|
||
| 11352 | function isArrayLikeObject(value) { |
||
| 11353 | return isObjectLike(value) && isArrayLike(value);
|
||
| 11354 | } |
||
| 11355 | |||
| 11356 | /**
|
||
| 11357 | * Checks if `value` is classified as a boolean primitive or object.
|
||
| 11358 | *
|
||
| 11359 | * @static
|
||
| 11360 | * @memberOf _
|
||
| 11361 | * @since 0.1.0
|
||
| 11362 | * @category Lang
|
||
| 11363 | * @param {*} value The value to check.
|
||
| 11364 | * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
|
||
| 11365 | * @example
|
||
| 11366 | *
|
||
| 11367 | * _.isBoolean(false);
|
||
| 11368 | * // => true
|
||
| 11369 | *
|
||
| 11370 | * _.isBoolean(null);
|
||
| 11371 | * // => false
|
||
| 11372 | */
|
||
| 11373 | function isBoolean(value) { |
||
| 11374 | return value === true || value === false || |
||
| 11375 | (isObjectLike(value) && baseGetTag(value) == boolTag); |
||
| 11376 | } |
||
| 11377 | |||
| 11378 | /**
|
||
| 11379 | * Checks if `value` is a buffer.
|
||
| 11380 | *
|
||
| 11381 | * @static
|
||
| 11382 | * @memberOf _
|
||
| 11383 | * @since 4.3.0
|
||
| 11384 | * @category Lang
|
||
| 11385 | * @param {*} value The value to check.
|
||
| 11386 | * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
||
| 11387 | * @example
|
||
| 11388 | *
|
||
| 11389 | * _.isBuffer(new Buffer(2));
|
||
| 11390 | * // => true
|
||
| 11391 | *
|
||
| 11392 | * _.isBuffer(new Uint8Array(2));
|
||
| 11393 | * // => false
|
||
| 11394 | */
|
||
| 11395 | var isBuffer = nativeIsBuffer || stubFalse;
|
||
| 11396 | |||
| 11397 | /**
|
||
| 11398 | * Checks if `value` is classified as a `Date` object.
|
||
| 11399 | *
|
||
| 11400 | * @static
|
||
| 11401 | * @memberOf _
|
||
| 11402 | * @since 0.1.0
|
||
| 11403 | * @category Lang
|
||
| 11404 | * @param {*} value The value to check.
|
||
| 11405 | * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
||
| 11406 | * @example
|
||
| 11407 | *
|
||
| 11408 | * _.isDate(new Date);
|
||
| 11409 | * // => true
|
||
| 11410 | *
|
||
| 11411 | * _.isDate('Mon April 23 2012');
|
||
| 11412 | * // => false
|
||
| 11413 | */
|
||
| 11414 | var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
|
||
| 11415 | |||
| 11416 | /**
|
||
| 11417 | * Checks if `value` is likely a DOM element.
|
||
| 11418 | *
|
||
| 11419 | * @static
|
||
| 11420 | * @memberOf _
|
||
| 11421 | * @since 0.1.0
|
||
| 11422 | * @category Lang
|
||
| 11423 | * @param {*} value The value to check.
|
||
| 11424 | * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
|
||
| 11425 | * @example
|
||
| 11426 | *
|
||
| 11427 | * _.isElement(document.body);
|
||
| 11428 | * // => true
|
||
| 11429 | *
|
||
| 11430 | * _.isElement('<body>');
|
||
| 11431 | * // => false
|
||
| 11432 | */
|
||
| 11433 | function isElement(value) { |
||
| 11434 | return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); |
||
| 11435 | } |
||
| 11436 | |||
| 11437 | /**
|
||
| 11438 | * Checks if `value` is an empty object, collection, map, or set.
|
||
| 11439 | *
|
||
| 11440 | * Objects are considered empty if they have no own enumerable string keyed
|
||
| 11441 | * properties.
|
||
| 11442 | *
|
||
| 11443 | * Array-like values such as `arguments` objects, arrays, buffers, strings, or
|
||
| 11444 | * jQuery-like collections are considered empty if they have a `length` of `0`.
|
||
| 11445 | * Similarly, maps and sets are considered empty if they have a `size` of `0`.
|
||
| 11446 | *
|
||
| 11447 | * @static
|
||
| 11448 | * @memberOf _
|
||
| 11449 | * @since 0.1.0
|
||
| 11450 | * @category Lang
|
||
| 11451 | * @param {*} value The value to check.
|
||
| 11452 | * @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
||
| 11453 | * @example
|
||
| 11454 | *
|
||
| 11455 | * _.isEmpty(null);
|
||
| 11456 | * // => true
|
||
| 11457 | *
|
||
| 11458 | * _.isEmpty(true);
|
||
| 11459 | * // => true
|
||
| 11460 | *
|
||
| 11461 | * _.isEmpty(1);
|
||
| 11462 | * // => true
|
||
| 11463 | *
|
||
| 11464 | * _.isEmpty([1, 2, 3]);
|
||
| 11465 | * // => false
|
||
| 11466 | *
|
||
| 11467 | * _.isEmpty({ 'a': 1 });
|
||
| 11468 | * // => false
|
||
| 11469 | */
|
||
| 11470 | function isEmpty(value) { |
||
| 11471 | if (value == null) { |
||
| 11472 | return true; |
||
| 11473 | } |
||
| 11474 | if (isArrayLike(value) &&
|
||
| 11475 | (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || |
||
| 11476 | isBuffer(value) || isTypedArray(value) || isArguments(value))) {
|
||
| 11477 | return !value.length;
|
||
| 11478 | } |
||
| 11479 | var tag = getTag(value);
|
||
| 11480 | if (tag == mapTag || tag == setTag) {
|
||
| 11481 | return !value.size;
|
||
| 11482 | } |
||
| 11483 | if (isPrototype(value)) {
|
||
| 11484 | return !baseKeys(value).length;
|
||
| 11485 | } |
||
| 11486 | for (var key in value) { |
||
| 11487 | if (hasOwnProperty.call(value, key)) {
|
||
| 11488 | return false; |
||
| 11489 | } |
||
| 11490 | } |
||
| 11491 | return true; |
||
| 11492 | } |
||
| 11493 | |||
| 11494 | /**
|
||
| 11495 | * Performs a deep comparison between two values to determine if they are
|
||
| 11496 | * equivalent.
|
||
| 11497 | *
|
||
| 11498 | * **Note:** This method supports comparing arrays, array buffers, booleans,
|
||
| 11499 | * date objects, error objects, maps, numbers, `Object` objects, regexes,
|
||
| 11500 | * sets, strings, symbols, and typed arrays. `Object` objects are compared
|
||
| 11501 | * by their own, not inherited, enumerable properties. Functions and DOM
|
||
| 11502 | * nodes are compared by strict equality, i.e. `===`.
|
||
| 11503 | *
|
||
| 11504 | * @static
|
||
| 11505 | * @memberOf _
|
||
| 11506 | * @since 0.1.0
|
||
| 11507 | * @category Lang
|
||
| 11508 | * @param {*} value The value to compare.
|
||
| 11509 | * @param {*} other The other value to compare.
|
||
| 11510 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
||
| 11511 | * @example
|
||
| 11512 | *
|
||
| 11513 | * var object = { 'a': 1 };
|
||
| 11514 | * var other = { 'a': 1 };
|
||
| 11515 | *
|
||
| 11516 | * _.isEqual(object, other);
|
||
| 11517 | * // => true
|
||
| 11518 | *
|
||
| 11519 | * object === other;
|
||
| 11520 | * // => false
|
||
| 11521 | */
|
||
| 11522 | function isEqual(value, other) { |
||
| 11523 | return baseIsEqual(value, other);
|
||
| 11524 | } |
||
| 11525 | |||
| 11526 | /**
|
||
| 11527 | * This method is like `_.isEqual` except that it accepts `customizer` which
|
||
| 11528 | * is invoked to compare values. If `customizer` returns `undefined`, comparisons
|
||
| 11529 | * are handled by the method instead. The `customizer` is invoked with up to
|
||
| 11530 | * six arguments: (objValue, othValue [, index|key, object, other, stack]).
|
||
| 11531 | *
|
||
| 11532 | * @static
|
||
| 11533 | * @memberOf _
|
||
| 11534 | * @since 4.0.0
|
||
| 11535 | * @category Lang
|
||
| 11536 | * @param {*} value The value to compare.
|
||
| 11537 | * @param {*} other The other value to compare.
|
||
| 11538 | * @param {Function} [customizer] The function to customize comparisons.
|
||
| 11539 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
||
| 11540 | * @example
|
||
| 11541 | *
|
||
| 11542 | * function isGreeting(value) {
|
||
| 11543 | * return /^h(?:i|ello)$/.test(value);
|
||
| 11544 | * }
|
||
| 11545 | *
|
||
| 11546 | * function customizer(objValue, othValue) {
|
||
| 11547 | * if (isGreeting(objValue) && isGreeting(othValue)) {
|
||
| 11548 | * return true;
|
||
| 11549 | * }
|
||
| 11550 | * }
|
||
| 11551 | *
|
||
| 11552 | * var array = ['hello', 'goodbye'];
|
||
| 11553 | * var other = ['hi', 'goodbye'];
|
||
| 11554 | *
|
||
| 11555 | * _.isEqualWith(array, other, customizer);
|
||
| 11556 | * // => true
|
||
| 11557 | */
|
||
| 11558 | function isEqualWith(value, other, customizer) { |
||
| 11559 | customizer = typeof customizer == 'function' ? customizer : undefined; |
||
| 11560 | var result = customizer ? customizer(value, other) : undefined; |
||
| 11561 | return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result; |
||
| 11562 | } |
||
| 11563 | |||
| 11564 | /**
|
||
| 11565 | * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
|
||
| 11566 | * `SyntaxError`, `TypeError`, or `URIError` object.
|
||
| 11567 | *
|
||
| 11568 | * @static
|
||
| 11569 | * @memberOf _
|
||
| 11570 | * @since 3.0.0
|
||
| 11571 | * @category Lang
|
||
| 11572 | * @param {*} value The value to check.
|
||
| 11573 | * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
|
||
| 11574 | * @example
|
||
| 11575 | *
|
||
| 11576 | * _.isError(new Error);
|
||
| 11577 | * // => true
|
||
| 11578 | *
|
||
| 11579 | * _.isError(Error);
|
||
| 11580 | * // => false
|
||
| 11581 | */
|
||
| 11582 | function isError(value) { |
||
| 11583 | if (!isObjectLike(value)) {
|
||
| 11584 | return false; |
||
| 11585 | } |
||
| 11586 | var tag = baseGetTag(value);
|
||
| 11587 | return tag == errorTag || tag == domExcTag ||
|
||
| 11588 | (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); |
||
| 11589 | } |
||
| 11590 | |||
| 11591 | /**
|
||
| 11592 | * Checks if `value` is a finite primitive number.
|
||
| 11593 | *
|
||
| 11594 | * **Note:** This method is based on
|
||
| 11595 | * [`Number.isFinite`](https://mdn.io/Number/isFinite).
|
||
| 11596 | *
|
||
| 11597 | * @static
|
||
| 11598 | * @memberOf _
|
||
| 11599 | * @since 0.1.0
|
||
| 11600 | * @category Lang
|
||
| 11601 | * @param {*} value The value to check.
|
||
| 11602 | * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
|
||
| 11603 | * @example
|
||
| 11604 | *
|
||
| 11605 | * _.isFinite(3);
|
||
| 11606 | * // => true
|
||
| 11607 | *
|
||
| 11608 | * _.isFinite(Number.MIN_VALUE);
|
||
| 11609 | * // => true
|
||
| 11610 | *
|
||
| 11611 | * _.isFinite(Infinity);
|
||
| 11612 | * // => false
|
||
| 11613 | *
|
||
| 11614 | * _.isFinite('3');
|
||
| 11615 | * // => false
|
||
| 11616 | */
|
||
| 11617 | function isFinite(value) { |
||
| 11618 | return typeof value == 'number' && nativeIsFinite(value); |
||
| 11619 | } |
||
| 11620 | |||
| 11621 | /**
|
||
| 11622 | * Checks if `value` is classified as a `Function` object.
|
||
| 11623 | *
|
||
| 11624 | * @static
|
||
| 11625 | * @memberOf _
|
||
| 11626 | * @since 0.1.0
|
||
| 11627 | * @category Lang
|
||
| 11628 | * @param {*} value The value to check.
|
||
| 11629 | * @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
||
| 11630 | * @example
|
||
| 11631 | *
|
||
| 11632 | * _.isFunction(_);
|
||
| 11633 | * // => true
|
||
| 11634 | *
|
||
| 11635 | * _.isFunction(/abc/);
|
||
| 11636 | * // => false
|
||
| 11637 | */
|
||
| 11638 | function isFunction(value) { |
||
| 11639 | if (!isObject(value)) {
|
||
| 11640 | return false; |
||
| 11641 | } |
||
| 11642 | // The use of `Object#toString` avoids issues with the `typeof` operator
|
||
| 11643 | // in Safari 9 which returns 'object' for typed arrays and other constructors.
|
||
| 11644 | var tag = baseGetTag(value);
|
||
| 11645 | return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
||
| 11646 | } |
||
| 11647 | |||
| 11648 | /**
|
||
| 11649 | * Checks if `value` is an integer.
|
||
| 11650 | *
|
||
| 11651 | * **Note:** This method is based on
|
||
| 11652 | * [`Number.isInteger`](https://mdn.io/Number/isInteger).
|
||
| 11653 | *
|
||
| 11654 | * @static
|
||
| 11655 | * @memberOf _
|
||
| 11656 | * @since 4.0.0
|
||
| 11657 | * @category Lang
|
||
| 11658 | * @param {*} value The value to check.
|
||
| 11659 | * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
|
||
| 11660 | * @example
|
||
| 11661 | *
|
||
| 11662 | * _.isInteger(3);
|
||
| 11663 | * // => true
|
||
| 11664 | *
|
||
| 11665 | * _.isInteger(Number.MIN_VALUE);
|
||
| 11666 | * // => false
|
||
| 11667 | *
|
||
| 11668 | * _.isInteger(Infinity);
|
||
| 11669 | * // => false
|
||
| 11670 | *
|
||
| 11671 | * _.isInteger('3');
|
||
| 11672 | * // => false
|
||
| 11673 | */
|
||
| 11674 | function isInteger(value) { |
||
| 11675 | return typeof value == 'number' && value == toInteger(value); |
||
| 11676 | } |
||
| 11677 | |||
| 11678 | /**
|
||
| 11679 | * Checks if `value` is a valid array-like length.
|
||
| 11680 | *
|
||
| 11681 | * **Note:** This method is loosely based on
|
||
| 11682 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
||
| 11683 | *
|
||
| 11684 | * @static
|
||
| 11685 | * @memberOf _
|
||
| 11686 | * @since 4.0.0
|
||
| 11687 | * @category Lang
|
||
| 11688 | * @param {*} value The value to check.
|
||
| 11689 | * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
||
| 11690 | * @example
|
||
| 11691 | *
|
||
| 11692 | * _.isLength(3);
|
||
| 11693 | * // => true
|
||
| 11694 | *
|
||
| 11695 | * _.isLength(Number.MIN_VALUE);
|
||
| 11696 | * // => false
|
||
| 11697 | *
|
||
| 11698 | * _.isLength(Infinity);
|
||
| 11699 | * // => false
|
||
| 11700 | *
|
||
| 11701 | * _.isLength('3');
|
||
| 11702 | * // => false
|
||
| 11703 | */
|
||
| 11704 | function isLength(value) { |
||
| 11705 | return typeof value == 'number' && |
||
| 11706 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; |
||
| 11707 | } |
||
| 11708 | |||
| 11709 | /**
|
||
| 11710 | * Checks if `value` is the
|
||
| 11711 | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
||
| 11712 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
||
| 11713 | *
|
||
| 11714 | * @static
|
||
| 11715 | * @memberOf _
|
||
| 11716 | * @since 0.1.0
|
||
| 11717 | * @category Lang
|
||
| 11718 | * @param {*} value The value to check.
|
||
| 11719 | * @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
||
| 11720 | * @example
|
||
| 11721 | *
|
||
| 11722 | * _.isObject({});
|
||
| 11723 | * // => true
|
||
| 11724 | *
|
||
| 11725 | * _.isObject([1, 2, 3]);
|
||
| 11726 | * // => true
|
||
| 11727 | *
|
||
| 11728 | * _.isObject(_.noop);
|
||
| 11729 | * // => true
|
||
| 11730 | *
|
||
| 11731 | * _.isObject(null);
|
||
| 11732 | * // => false
|
||
| 11733 | */
|
||
| 11734 | function isObject(value) { |
||
| 11735 | var type = typeof value; |
||
| 11736 | return value != null && (type == 'object' || type == 'function'); |
||
| 11737 | } |
||
| 11738 | |||
| 11739 | /**
|
||
| 11740 | * Checks if `value` is object-like. A value is object-like if it's not `null`
|
||
| 11741 | * and has a `typeof` result of "object".
|
||
| 11742 | *
|
||
| 11743 | * @static
|
||
| 11744 | * @memberOf _
|
||
| 11745 | * @since 4.0.0
|
||
| 11746 | * @category Lang
|
||
| 11747 | * @param {*} value The value to check.
|
||
| 11748 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
||
| 11749 | * @example
|
||
| 11750 | *
|
||
| 11751 | * _.isObjectLike({});
|
||
| 11752 | * // => true
|
||
| 11753 | *
|
||
| 11754 | * _.isObjectLike([1, 2, 3]);
|
||
| 11755 | * // => true
|
||
| 11756 | *
|
||
| 11757 | * _.isObjectLike(_.noop);
|
||
| 11758 | * // => false
|
||
| 11759 | *
|
||
| 11760 | * _.isObjectLike(null);
|
||
| 11761 | * // => false
|
||
| 11762 | */
|
||
| 11763 | function isObjectLike(value) { |
||
| 11764 | return value != null && typeof value == 'object'; |
||
| 11765 | } |
||
| 11766 | |||
| 11767 | /**
|
||
| 11768 | * Checks if `value` is classified as a `Map` object.
|
||
| 11769 | *
|
||
| 11770 | * @static
|
||
| 11771 | * @memberOf _
|
||
| 11772 | * @since 4.3.0
|
||
| 11773 | * @category Lang
|
||
| 11774 | * @param {*} value The value to check.
|
||
| 11775 | * @returns {boolean} Returns `true` if `value` is a map, else `false`.
|
||
| 11776 | * @example
|
||
| 11777 | *
|
||
| 11778 | * _.isMap(new Map);
|
||
| 11779 | * // => true
|
||
| 11780 | *
|
||
| 11781 | * _.isMap(new WeakMap);
|
||
| 11782 | * // => false
|
||
| 11783 | */
|
||
| 11784 | var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
|
||
| 11785 | |||
| 11786 | /**
|
||
| 11787 | * Performs a partial deep comparison between `object` and `source` to
|
||
| 11788 | * determine if `object` contains equivalent property values.
|
||
| 11789 | *
|
||
| 11790 | * **Note:** This method is equivalent to `_.matches` when `source` is
|
||
| 11791 | * partially applied.
|
||
| 11792 | *
|
||
| 11793 | * Partial comparisons will match empty array and empty object `source`
|
||
| 11794 | * values against any array or object value, respectively. See `_.isEqual`
|
||
| 11795 | * for a list of supported value comparisons.
|
||
| 11796 | *
|
||
| 11797 | * @static
|
||
| 11798 | * @memberOf _
|
||
| 11799 | * @since 3.0.0
|
||
| 11800 | * @category Lang
|
||
| 11801 | * @param {Object} object The object to inspect.
|
||
| 11802 | * @param {Object} source The object of property values to match.
|
||
| 11803 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
||
| 11804 | * @example
|
||
| 11805 | *
|
||
| 11806 | * var object = { 'a': 1, 'b': 2 };
|
||
| 11807 | *
|
||
| 11808 | * _.isMatch(object, { 'b': 2 });
|
||
| 11809 | * // => true
|
||
| 11810 | *
|
||
| 11811 | * _.isMatch(object, { 'b': 1 });
|
||
| 11812 | * // => false
|
||
| 11813 | */
|
||
| 11814 | function isMatch(object, source) { |
||
| 11815 | return object === source || baseIsMatch(object, source, getMatchData(source));
|
||
| 11816 | } |
||
| 11817 | |||
| 11818 | /**
|
||
| 11819 | * This method is like `_.isMatch` except that it accepts `customizer` which
|
||
| 11820 | * is invoked to compare values. If `customizer` returns `undefined`, comparisons
|
||
| 11821 | * are handled by the method instead. The `customizer` is invoked with five
|
||
| 11822 | * arguments: (objValue, srcValue, index|key, object, source).
|
||
| 11823 | *
|
||
| 11824 | * @static
|
||
| 11825 | * @memberOf _
|
||
| 11826 | * @since 4.0.0
|
||
| 11827 | * @category Lang
|
||
| 11828 | * @param {Object} object The object to inspect.
|
||
| 11829 | * @param {Object} source The object of property values to match.
|
||
| 11830 | * @param {Function} [customizer] The function to customize comparisons.
|
||
| 11831 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
||
| 11832 | * @example
|
||
| 11833 | *
|
||
| 11834 | * function isGreeting(value) {
|
||
| 11835 | * return /^h(?:i|ello)$/.test(value);
|
||
| 11836 | * }
|
||
| 11837 | *
|
||
| 11838 | * function customizer(objValue, srcValue) {
|
||
| 11839 | * if (isGreeting(objValue) && isGreeting(srcValue)) {
|
||
| 11840 | * return true;
|
||
| 11841 | * }
|
||
| 11842 | * }
|
||
| 11843 | *
|
||
| 11844 | * var object = { 'greeting': 'hello' };
|
||
| 11845 | * var source = { 'greeting': 'hi' };
|
||
| 11846 | *
|
||
| 11847 | * _.isMatchWith(object, source, customizer);
|
||
| 11848 | * // => true
|
||
| 11849 | */
|
||
| 11850 | function isMatchWith(object, source, customizer) { |
||
| 11851 | customizer = typeof customizer == 'function' ? customizer : undefined; |
||
| 11852 | return baseIsMatch(object, source, getMatchData(source), customizer);
|
||
| 11853 | } |
||
| 11854 | |||
| 11855 | /**
|
||
| 11856 | * Checks if `value` is `NaN`.
|
||
| 11857 | *
|
||
| 11858 | * **Note:** This method is based on
|
||
| 11859 | * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
|
||
| 11860 | * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
|
||
| 11861 | * `undefined` and other non-number values.
|
||
| 11862 | *
|
||
| 11863 | * @static
|
||
| 11864 | * @memberOf _
|
||
| 11865 | * @since 0.1.0
|
||
| 11866 | * @category Lang
|
||
| 11867 | * @param {*} value The value to check.
|
||
| 11868 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
||
| 11869 | * @example
|
||
| 11870 | *
|
||
| 11871 | * _.isNaN(NaN);
|
||
| 11872 | * // => true
|
||
| 11873 | *
|
||
| 11874 | * _.isNaN(new Number(NaN));
|
||
| 11875 | * // => true
|
||
| 11876 | *
|
||
| 11877 | * isNaN(undefined);
|
||
| 11878 | * // => true
|
||
| 11879 | *
|
||
| 11880 | * _.isNaN(undefined);
|
||
| 11881 | * // => false
|
||
| 11882 | */
|
||
| 11883 | function isNaN(value) { |
||
| 11884 | // An `NaN` primitive is the only value that is not equal to itself.
|
||
| 11885 | // Perform the `toStringTag` check first to avoid errors with some
|
||
| 11886 | // ActiveX objects in IE.
|
||
| 11887 | return isNumber(value) && value != +value;
|
||
| 11888 | } |
||
| 11889 | |||
| 11890 | /**
|
||
| 11891 | * Checks if `value` is a pristine native function.
|
||
| 11892 | *
|
||
| 11893 | * **Note:** This method can't reliably detect native functions in the presence
|
||
| 11894 | * of the core-js package because core-js circumvents this kind of detection.
|
||
| 11895 | * Despite multiple requests, the core-js maintainer has made it clear: any
|
||
| 11896 | * attempt to fix the detection will be obstructed. As a result, we're left
|
||
| 11897 | * with little choice but to throw an error. Unfortunately, this also affects
|
||
| 11898 | * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
|
||
| 11899 | * which rely on core-js.
|
||
| 11900 | *
|
||
| 11901 | * @static
|
||
| 11902 | * @memberOf _
|
||
| 11903 | * @since 3.0.0
|
||
| 11904 | * @category Lang
|
||
| 11905 | * @param {*} value The value to check.
|
||
| 11906 | * @returns {boolean} Returns `true` if `value` is a native function,
|
||
| 11907 | * else `false`.
|
||
| 11908 | * @example
|
||
| 11909 | *
|
||
| 11910 | * _.isNative(Array.prototype.push);
|
||
| 11911 | * // => true
|
||
| 11912 | *
|
||
| 11913 | * _.isNative(_);
|
||
| 11914 | * // => false
|
||
| 11915 | */
|
||
| 11916 | function isNative(value) { |
||
| 11917 | if (isMaskable(value)) {
|
||
| 11918 | throw new Error(CORE_ERROR_TEXT); |
||
| 11919 | } |
||
| 11920 | return baseIsNative(value);
|
||
| 11921 | } |
||
| 11922 | |||
| 11923 | /**
|
||
| 11924 | * Checks if `value` is `null`.
|
||
| 11925 | *
|
||
| 11926 | * @static
|
||
| 11927 | * @memberOf _
|
||
| 11928 | * @since 0.1.0
|
||
| 11929 | * @category Lang
|
||
| 11930 | * @param {*} value The value to check.
|
||
| 11931 | * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
|
||
| 11932 | * @example
|
||
| 11933 | *
|
||
| 11934 | * _.isNull(null);
|
||
| 11935 | * // => true
|
||
| 11936 | *
|
||
| 11937 | * _.isNull(void 0);
|
||
| 11938 | * // => false
|
||
| 11939 | */
|
||
| 11940 | function isNull(value) { |
||
| 11941 | return value === null; |
||
| 11942 | } |
||
| 11943 | |||
| 11944 | /**
|
||
| 11945 | * Checks if `value` is `null` or `undefined`.
|
||
| 11946 | *
|
||
| 11947 | * @static
|
||
| 11948 | * @memberOf _
|
||
| 11949 | * @since 4.0.0
|
||
| 11950 | * @category Lang
|
||
| 11951 | * @param {*} value The value to check.
|
||
| 11952 | * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
|
||
| 11953 | * @example
|
||
| 11954 | *
|
||
| 11955 | * _.isNil(null);
|
||
| 11956 | * // => true
|
||
| 11957 | *
|
||
| 11958 | * _.isNil(void 0);
|
||
| 11959 | * // => true
|
||
| 11960 | *
|
||
| 11961 | * _.isNil(NaN);
|
||
| 11962 | * // => false
|
||
| 11963 | */
|
||
| 11964 | function isNil(value) { |
||
| 11965 | return value == null; |
||
| 11966 | } |
||
| 11967 | |||
| 11968 | /**
|
||
| 11969 | * Checks if `value` is classified as a `Number` primitive or object.
|
||
| 11970 | *
|
||
| 11971 | * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
|
||
| 11972 | * classified as numbers, use the `_.isFinite` method.
|
||
| 11973 | *
|
||
| 11974 | * @static
|
||
| 11975 | * @memberOf _
|
||
| 11976 | * @since 0.1.0
|
||
| 11977 | * @category Lang
|
||
| 11978 | * @param {*} value The value to check.
|
||
| 11979 | * @returns {boolean} Returns `true` if `value` is a number, else `false`.
|
||
| 11980 | * @example
|
||
| 11981 | *
|
||
| 11982 | * _.isNumber(3);
|
||
| 11983 | * // => true
|
||
| 11984 | *
|
||
| 11985 | * _.isNumber(Number.MIN_VALUE);
|
||
| 11986 | * // => true
|
||
| 11987 | *
|
||
| 11988 | * _.isNumber(Infinity);
|
||
| 11989 | * // => true
|
||
| 11990 | *
|
||
| 11991 | * _.isNumber('3');
|
||
| 11992 | * // => false
|
||
| 11993 | */
|
||
| 11994 | function isNumber(value) { |
||
| 11995 | return typeof value == 'number' || |
||
| 11996 | (isObjectLike(value) && baseGetTag(value) == numberTag); |
||
| 11997 | } |
||
| 11998 | |||
| 11999 | /**
|
||
| 12000 | * Checks if `value` is a plain object, that is, an object created by the
|
||
| 12001 | * `Object` constructor or one with a `[[Prototype]]` of `null`.
|
||
| 12002 | *
|
||
| 12003 | * @static
|
||
| 12004 | * @memberOf _
|
||
| 12005 | * @since 0.8.0
|
||
| 12006 | * @category Lang
|
||
| 12007 | * @param {*} value The value to check.
|
||
| 12008 | * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
||
| 12009 | * @example
|
||
| 12010 | *
|
||
| 12011 | * function Foo() {
|
||
| 12012 | * this.a = 1;
|
||
| 12013 | * }
|
||
| 12014 | *
|
||
| 12015 | * _.isPlainObject(new Foo);
|
||
| 12016 | * // => false
|
||
| 12017 | *
|
||
| 12018 | * _.isPlainObject([1, 2, 3]);
|
||
| 12019 | * // => false
|
||
| 12020 | *
|
||
| 12021 | * _.isPlainObject({ 'x': 0, 'y': 0 });
|
||
| 12022 | * // => true
|
||
| 12023 | *
|
||
| 12024 | * _.isPlainObject(Object.create(null));
|
||
| 12025 | * // => true
|
||
| 12026 | */
|
||
| 12027 | function isPlainObject(value) { |
||
| 12028 | if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
|
||
| 12029 | return false; |
||
| 12030 | } |
||
| 12031 | var proto = getPrototype(value);
|
||
| 12032 | if (proto === null) { |
||
| 12033 | return true; |
||
| 12034 | } |
||
| 12035 | var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; |
||
| 12036 | return typeof Ctor == 'function' && Ctor instanceof Ctor && |
||
| 12037 | funcToString.call(Ctor) == objectCtorString; |
||
| 12038 | } |
||
| 12039 | |||
| 12040 | /**
|
||
| 12041 | * Checks if `value` is classified as a `RegExp` object.
|
||
| 12042 | *
|
||
| 12043 | * @static
|
||
| 12044 | * @memberOf _
|
||
| 12045 | * @since 0.1.0
|
||
| 12046 | * @category Lang
|
||
| 12047 | * @param {*} value The value to check.
|
||
| 12048 | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
|
||
| 12049 | * @example
|
||
| 12050 | *
|
||
| 12051 | * _.isRegExp(/abc/);
|
||
| 12052 | * // => true
|
||
| 12053 | *
|
||
| 12054 | * _.isRegExp('/abc/');
|
||
| 12055 | * // => false
|
||
| 12056 | */
|
||
| 12057 | var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
|
||
| 12058 | |||
| 12059 | /**
|
||
| 12060 | * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
|
||
| 12061 | * double precision number which isn't the result of a rounded unsafe integer.
|
||
| 12062 | *
|
||
| 12063 | * **Note:** This method is based on
|
||
| 12064 | * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
|
||
| 12065 | *
|
||
| 12066 | * @static
|
||
| 12067 | * @memberOf _
|
||
| 12068 | * @since 4.0.0
|
||
| 12069 | * @category Lang
|
||
| 12070 | * @param {*} value The value to check.
|
||
| 12071 | * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
|
||
| 12072 | * @example
|
||
| 12073 | *
|
||
| 12074 | * _.isSafeInteger(3);
|
||
| 12075 | * // => true
|
||
| 12076 | *
|
||
| 12077 | * _.isSafeInteger(Number.MIN_VALUE);
|
||
| 12078 | * // => false
|
||
| 12079 | *
|
||
| 12080 | * _.isSafeInteger(Infinity);
|
||
| 12081 | * // => false
|
||
| 12082 | *
|
||
| 12083 | * _.isSafeInteger('3');
|
||
| 12084 | * // => false
|
||
| 12085 | */
|
||
| 12086 | function isSafeInteger(value) { |
||
| 12087 | return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
||
| 12088 | } |
||
| 12089 | |||
| 12090 | /**
|
||
| 12091 | * Checks if `value` is classified as a `Set` object.
|
||
| 12092 | *
|
||
| 12093 | * @static
|
||
| 12094 | * @memberOf _
|
||
| 12095 | * @since 4.3.0
|
||
| 12096 | * @category Lang
|
||
| 12097 | * @param {*} value The value to check.
|
||
| 12098 | * @returns {boolean} Returns `true` if `value` is a set, else `false`.
|
||
| 12099 | * @example
|
||
| 12100 | *
|
||
| 12101 | * _.isSet(new Set);
|
||
| 12102 | * // => true
|
||
| 12103 | *
|
||
| 12104 | * _.isSet(new WeakSet);
|
||
| 12105 | * // => false
|
||
| 12106 | */
|
||
| 12107 | var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
||
| 12108 | |||
| 12109 | /**
|
||
| 12110 | * Checks if `value` is classified as a `String` primitive or object.
|
||
| 12111 | *
|
||
| 12112 | * @static
|
||
| 12113 | * @since 0.1.0
|
||
| 12114 | * @memberOf _
|
||
| 12115 | * @category Lang
|
||
| 12116 | * @param {*} value The value to check.
|
||
| 12117 | * @returns {boolean} Returns `true` if `value` is a string, else `false`.
|
||
| 12118 | * @example
|
||
| 12119 | *
|
||
| 12120 | * _.isString('abc');
|
||
| 12121 | * // => true
|
||
| 12122 | *
|
||
| 12123 | * _.isString(1);
|
||
| 12124 | * // => false
|
||
| 12125 | */
|
||
| 12126 | function isString(value) { |
||
| 12127 | return typeof value == 'string' || |
||
| 12128 | (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); |
||
| 12129 | } |
||
| 12130 | |||
| 12131 | /**
|
||
| 12132 | * Checks if `value` is classified as a `Symbol` primitive or object.
|
||
| 12133 | *
|
||
| 12134 | * @static
|
||
| 12135 | * @memberOf _
|
||
| 12136 | * @since 4.0.0
|
||
| 12137 | * @category Lang
|
||
| 12138 | * @param {*} value The value to check.
|
||
| 12139 | * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
||
| 12140 | * @example
|
||
| 12141 | *
|
||
| 12142 | * _.isSymbol(Symbol.iterator);
|
||
| 12143 | * // => true
|
||
| 12144 | *
|
||
| 12145 | * _.isSymbol('abc');
|
||
| 12146 | * // => false
|
||
| 12147 | */
|
||
| 12148 | function isSymbol(value) { |
||
| 12149 | return typeof value == 'symbol' || |
||
| 12150 | (isObjectLike(value) && baseGetTag(value) == symbolTag); |
||
| 12151 | } |
||
| 12152 | |||
| 12153 | /**
|
||
| 12154 | * Checks if `value` is classified as a typed array.
|
||
| 12155 | *
|
||
| 12156 | * @static
|
||
| 12157 | * @memberOf _
|
||
| 12158 | * @since 3.0.0
|
||
| 12159 | * @category Lang
|
||
| 12160 | * @param {*} value The value to check.
|
||
| 12161 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
||
| 12162 | * @example
|
||
| 12163 | *
|
||
| 12164 | * _.isTypedArray(new Uint8Array);
|
||
| 12165 | * // => true
|
||
| 12166 | *
|
||
| 12167 | * _.isTypedArray([]);
|
||
| 12168 | * // => false
|
||
| 12169 | */
|
||
| 12170 | var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
|
||
| 12171 | |||
| 12172 | /**
|
||
| 12173 | * Checks if `value` is `undefined`.
|
||
| 12174 | *
|
||
| 12175 | * @static
|
||
| 12176 | * @since 0.1.0
|
||
| 12177 | * @memberOf _
|
||
| 12178 | * @category Lang
|
||
| 12179 | * @param {*} value The value to check.
|
||
| 12180 | * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
|
||
| 12181 | * @example
|
||
| 12182 | *
|
||
| 12183 | * _.isUndefined(void 0);
|
||
| 12184 | * // => true
|
||
| 12185 | *
|
||
| 12186 | * _.isUndefined(null);
|
||
| 12187 | * // => false
|
||
| 12188 | */
|
||
| 12189 | function isUndefined(value) { |
||
| 12190 | return value === undefined; |
||
| 12191 | } |
||
| 12192 | |||
| 12193 | /**
|
||
| 12194 | * Checks if `value` is classified as a `WeakMap` object.
|
||
| 12195 | *
|
||
| 12196 | * @static
|
||
| 12197 | * @memberOf _
|
||
| 12198 | * @since 4.3.0
|
||
| 12199 | * @category Lang
|
||
| 12200 | * @param {*} value The value to check.
|
||
| 12201 | * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
|
||
| 12202 | * @example
|
||
| 12203 | *
|
||
| 12204 | * _.isWeakMap(new WeakMap);
|
||
| 12205 | * // => true
|
||
| 12206 | *
|
||
| 12207 | * _.isWeakMap(new Map);
|
||
| 12208 | * // => false
|
||
| 12209 | */
|
||
| 12210 | function isWeakMap(value) { |
||
| 12211 | return isObjectLike(value) && getTag(value) == weakMapTag;
|
||
| 12212 | } |
||
| 12213 | |||
| 12214 | /**
|
||
| 12215 | * Checks if `value` is classified as a `WeakSet` object.
|
||
| 12216 | *
|
||
| 12217 | * @static
|
||
| 12218 | * @memberOf _
|
||
| 12219 | * @since 4.3.0
|
||
| 12220 | * @category Lang
|
||
| 12221 | * @param {*} value The value to check.
|
||
| 12222 | * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
|
||
| 12223 | * @example
|
||
| 12224 | *
|
||
| 12225 | * _.isWeakSet(new WeakSet);
|
||
| 12226 | * // => true
|
||
| 12227 | *
|
||
| 12228 | * _.isWeakSet(new Set);
|
||
| 12229 | * // => false
|
||
| 12230 | */
|
||
| 12231 | function isWeakSet(value) { |
||
| 12232 | return isObjectLike(value) && baseGetTag(value) == weakSetTag;
|
||
| 12233 | } |
||
| 12234 | |||
| 12235 | /**
|
||
| 12236 | * Checks if `value` is less than `other`.
|
||
| 12237 | *
|
||
| 12238 | * @static
|
||
| 12239 | * @memberOf _
|
||
| 12240 | * @since 3.9.0
|
||
| 12241 | * @category Lang
|
||
| 12242 | * @param {*} value The value to compare.
|
||
| 12243 | * @param {*} other The other value to compare.
|
||
| 12244 | * @returns {boolean} Returns `true` if `value` is less than `other`,
|
||
| 12245 | * else `false`.
|
||
| 12246 | * @see _.gt
|
||
| 12247 | * @example
|
||
| 12248 | *
|
||
| 12249 | * _.lt(1, 3);
|
||
| 12250 | * // => true
|
||
| 12251 | *
|
||
| 12252 | * _.lt(3, 3);
|
||
| 12253 | * // => false
|
||
| 12254 | *
|
||
| 12255 | * _.lt(3, 1);
|
||
| 12256 | * // => false
|
||
| 12257 | */
|
||
| 12258 | var lt = createRelationalOperation(baseLt);
|
||
| 12259 | |||
| 12260 | /**
|
||
| 12261 | * Checks if `value` is less than or equal to `other`.
|
||
| 12262 | *
|
||
| 12263 | * @static
|
||
| 12264 | * @memberOf _
|
||
| 12265 | * @since 3.9.0
|
||
| 12266 | * @category Lang
|
||
| 12267 | * @param {*} value The value to compare.
|
||
| 12268 | * @param {*} other The other value to compare.
|
||
| 12269 | * @returns {boolean} Returns `true` if `value` is less than or equal to
|
||
| 12270 | * `other`, else `false`.
|
||
| 12271 | * @see _.gte
|
||
| 12272 | * @example
|
||
| 12273 | *
|
||
| 12274 | * _.lte(1, 3);
|
||
| 12275 | * // => true
|
||
| 12276 | *
|
||
| 12277 | * _.lte(3, 3);
|
||
| 12278 | * // => true
|
||
| 12279 | *
|
||
| 12280 | * _.lte(3, 1);
|
||
| 12281 | * // => false
|
||
| 12282 | */
|
||
| 12283 | var lte = createRelationalOperation(function(value, other) { |
||
| 12284 | return value <= other;
|
||
| 12285 | }); |
||
| 12286 | |||
| 12287 | /**
|
||
| 12288 | * Converts `value` to an array.
|
||
| 12289 | *
|
||
| 12290 | * @static
|
||
| 12291 | * @since 0.1.0
|
||
| 12292 | * @memberOf _
|
||
| 12293 | * @category Lang
|
||
| 12294 | * @param {*} value The value to convert.
|
||
| 12295 | * @returns {Array} Returns the converted array.
|
||
| 12296 | * @example
|
||
| 12297 | *
|
||
| 12298 | * _.toArray({ 'a': 1, 'b': 2 });
|
||
| 12299 | * // => [1, 2]
|
||
| 12300 | *
|
||
| 12301 | * _.toArray('abc');
|
||
| 12302 | * // => ['a', 'b', 'c']
|
||
| 12303 | *
|
||
| 12304 | * _.toArray(1);
|
||
| 12305 | * // => []
|
||
| 12306 | *
|
||
| 12307 | * _.toArray(null);
|
||
| 12308 | * // => []
|
||
| 12309 | */
|
||
| 12310 | function toArray(value) { |
||
| 12311 | if (!value) {
|
||
| 12312 | return [];
|
||
| 12313 | } |
||
| 12314 | if (isArrayLike(value)) {
|
||
| 12315 | return isString(value) ? stringToArray(value) : copyArray(value);
|
||
| 12316 | } |
||
| 12317 | if (symIterator && value[symIterator]) {
|
||
| 12318 | return iteratorToArray(value[symIterator]());
|
||
| 12319 | } |
||
| 12320 | var tag = getTag(value),
|
||
| 12321 | func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); |
||
| 12322 | |||
| 12323 | return func(value);
|
||
| 12324 | } |
||
| 12325 | |||
| 12326 | /**
|
||
| 12327 | * Converts `value` to a finite number.
|
||
| 12328 | *
|
||
| 12329 | * @static
|
||
| 12330 | * @memberOf _
|
||
| 12331 | * @since 4.12.0
|
||
| 12332 | * @category Lang
|
||
| 12333 | * @param {*} value The value to convert.
|
||
| 12334 | * @returns {number} Returns the converted number.
|
||
| 12335 | * @example
|
||
| 12336 | *
|
||
| 12337 | * _.toFinite(3.2);
|
||
| 12338 | * // => 3.2
|
||
| 12339 | *
|
||
| 12340 | * _.toFinite(Number.MIN_VALUE);
|
||
| 12341 | * // => 5e-324
|
||
| 12342 | *
|
||
| 12343 | * _.toFinite(Infinity);
|
||
| 12344 | * // => 1.7976931348623157e+308
|
||
| 12345 | *
|
||
| 12346 | * _.toFinite('3.2');
|
||
| 12347 | * // => 3.2
|
||
| 12348 | */
|
||
| 12349 | function toFinite(value) { |
||
| 12350 | if (!value) {
|
||
| 12351 | return value === 0 ? value : 0; |
||
| 12352 | } |
||
| 12353 | value = toNumber(value); |
||
| 12354 | if (value === INFINITY || value === -INFINITY) {
|
||
| 12355 | var sign = (value < 0 ? -1 : 1); |
||
| 12356 | return sign * MAX_INTEGER;
|
||
| 12357 | } |
||
| 12358 | return value === value ? value : 0; |
||
| 12359 | } |
||
| 12360 | |||
| 12361 | /**
|
||
| 12362 | * Converts `value` to an integer.
|
||
| 12363 | *
|
||
| 12364 | * **Note:** This method is loosely based on
|
||
| 12365 | * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
|
||
| 12366 | *
|
||
| 12367 | * @static
|
||
| 12368 | * @memberOf _
|
||
| 12369 | * @since 4.0.0
|
||
| 12370 | * @category Lang
|
||
| 12371 | * @param {*} value The value to convert.
|
||
| 12372 | * @returns {number} Returns the converted integer.
|
||
| 12373 | * @example
|
||
| 12374 | *
|
||
| 12375 | * _.toInteger(3.2);
|
||
| 12376 | * // => 3
|
||
| 12377 | *
|
||
| 12378 | * _.toInteger(Number.MIN_VALUE);
|
||
| 12379 | * // => 0
|
||
| 12380 | *
|
||
| 12381 | * _.toInteger(Infinity);
|
||
| 12382 | * // => 1.7976931348623157e+308
|
||
| 12383 | *
|
||
| 12384 | * _.toInteger('3.2');
|
||
| 12385 | * // => 3
|
||
| 12386 | */
|
||
| 12387 | function toInteger(value) { |
||
| 12388 | var result = toFinite(value),
|
||
| 12389 | remainder = result % 1;
|
||
| 12390 | |||
| 12391 | return result === result ? (remainder ? result - remainder : result) : 0; |
||
| 12392 | } |
||
| 12393 | |||
| 12394 | /**
|
||
| 12395 | * Converts `value` to an integer suitable for use as the length of an
|
||
| 12396 | * array-like object.
|
||
| 12397 | *
|
||
| 12398 | * **Note:** This method is based on
|
||
| 12399 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
||
| 12400 | *
|
||
| 12401 | * @static
|
||
| 12402 | * @memberOf _
|
||
| 12403 | * @since 4.0.0
|
||
| 12404 | * @category Lang
|
||
| 12405 | * @param {*} value The value to convert.
|
||
| 12406 | * @returns {number} Returns the converted integer.
|
||
| 12407 | * @example
|
||
| 12408 | *
|
||
| 12409 | * _.toLength(3.2);
|
||
| 12410 | * // => 3
|
||
| 12411 | *
|
||
| 12412 | * _.toLength(Number.MIN_VALUE);
|
||
| 12413 | * // => 0
|
||
| 12414 | *
|
||
| 12415 | * _.toLength(Infinity);
|
||
| 12416 | * // => 4294967295
|
||
| 12417 | *
|
||
| 12418 | * _.toLength('3.2');
|
||
| 12419 | * // => 3
|
||
| 12420 | */
|
||
| 12421 | function toLength(value) { |
||
| 12422 | return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0; |
||
| 12423 | } |
||
| 12424 | |||
| 12425 | /**
|
||
| 12426 | * Converts `value` to a number.
|
||
| 12427 | *
|
||
| 12428 | * @static
|
||
| 12429 | * @memberOf _
|
||
| 12430 | * @since 4.0.0
|
||
| 12431 | * @category Lang
|
||
| 12432 | * @param {*} value The value to process.
|
||
| 12433 | * @returns {number} Returns the number.
|
||
| 12434 | * @example
|
||
| 12435 | *
|
||
| 12436 | * _.toNumber(3.2);
|
||
| 12437 | * // => 3.2
|
||
| 12438 | *
|
||
| 12439 | * _.toNumber(Number.MIN_VALUE);
|
||
| 12440 | * // => 5e-324
|
||
| 12441 | *
|
||
| 12442 | * _.toNumber(Infinity);
|
||
| 12443 | * // => Infinity
|
||
| 12444 | *
|
||
| 12445 | * _.toNumber('3.2');
|
||
| 12446 | * // => 3.2
|
||
| 12447 | */
|
||
| 12448 | function toNumber(value) { |
||
| 12449 | if (typeof value == 'number') { |
||
| 12450 | return value;
|
||
| 12451 | } |
||
| 12452 | if (isSymbol(value)) {
|
||
| 12453 | return NAN;
|
||
| 12454 | } |
||
| 12455 | if (isObject(value)) {
|
||
| 12456 | var other = typeof value.valueOf == 'function' ? value.valueOf() : value; |
||
| 12457 | value = isObject(other) ? (other + '') : other;
|
||
| 12458 | } |
||
| 12459 | if (typeof value != 'string') { |
||
| 12460 | return value === 0 ? value : +value; |
||
| 12461 | } |
||
| 12462 | value = value.replace(reTrim, '');
|
||
| 12463 | var isBinary = reIsBinary.test(value);
|
||
| 12464 | return (isBinary || reIsOctal.test(value))
|
||
| 12465 | ? freeParseInt(value.slice(2), isBinary ? 2 : 8) |
||
| 12466 | : (reIsBadHex.test(value) ? NAN : +value); |
||
| 12467 | } |
||
| 12468 | |||
| 12469 | /**
|
||
| 12470 | * Converts `value` to a plain object flattening inherited enumerable string
|
||
| 12471 | * keyed properties of `value` to own properties of the plain object.
|
||
| 12472 | *
|
||
| 12473 | * @static
|
||
| 12474 | * @memberOf _
|
||
| 12475 | * @since 3.0.0
|
||
| 12476 | * @category Lang
|
||
| 12477 | * @param {*} value The value to convert.
|
||
| 12478 | * @returns {Object} Returns the converted plain object.
|
||
| 12479 | * @example
|
||
| 12480 | *
|
||
| 12481 | * function Foo() {
|
||
| 12482 | * this.b = 2;
|
||
| 12483 | * }
|
||
| 12484 | *
|
||
| 12485 | * Foo.prototype.c = 3;
|
||
| 12486 | *
|
||
| 12487 | * _.assign({ 'a': 1 }, new Foo);
|
||
| 12488 | * // => { 'a': 1, 'b': 2 }
|
||
| 12489 | *
|
||
| 12490 | * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
|
||
| 12491 | * // => { 'a': 1, 'b': 2, 'c': 3 }
|
||
| 12492 | */
|
||
| 12493 | function toPlainObject(value) { |
||
| 12494 | return copyObject(value, keysIn(value));
|
||
| 12495 | } |
||
| 12496 | |||
| 12497 | /**
|
||
| 12498 | * Converts `value` to a safe integer. A safe integer can be compared and
|
||
| 12499 | * represented correctly.
|
||
| 12500 | *
|
||
| 12501 | * @static
|
||
| 12502 | * @memberOf _
|
||
| 12503 | * @since 4.0.0
|
||
| 12504 | * @category Lang
|
||
| 12505 | * @param {*} value The value to convert.
|
||
| 12506 | * @returns {number} Returns the converted integer.
|
||
| 12507 | * @example
|
||
| 12508 | *
|
||
| 12509 | * _.toSafeInteger(3.2);
|
||
| 12510 | * // => 3
|
||
| 12511 | *
|
||
| 12512 | * _.toSafeInteger(Number.MIN_VALUE);
|
||
| 12513 | * // => 0
|
||
| 12514 | *
|
||
| 12515 | * _.toSafeInteger(Infinity);
|
||
| 12516 | * // => 9007199254740991
|
||
| 12517 | *
|
||
| 12518 | * _.toSafeInteger('3.2');
|
||
| 12519 | * // => 3
|
||
| 12520 | */
|
||
| 12521 | function toSafeInteger(value) { |
||
| 12522 | return value
|
||
| 12523 | ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) |
||
| 12524 | : (value === 0 ? value : 0); |
||
| 12525 | } |
||
| 12526 | |||
| 12527 | /**
|
||
| 12528 | * Converts `value` to a string. An empty string is returned for `null`
|
||
| 12529 | * and `undefined` values. The sign of `-0` is preserved.
|
||
| 12530 | *
|
||
| 12531 | * @static
|
||
| 12532 | * @memberOf _
|
||
| 12533 | * @since 4.0.0
|
||
| 12534 | * @category Lang
|
||
| 12535 | * @param {*} value The value to convert.
|
||
| 12536 | * @returns {string} Returns the converted string.
|
||
| 12537 | * @example
|
||
| 12538 | *
|
||
| 12539 | * _.toString(null);
|
||
| 12540 | * // => ''
|
||
| 12541 | *
|
||
| 12542 | * _.toString(-0);
|
||
| 12543 | * // => '-0'
|
||
| 12544 | *
|
||
| 12545 | * _.toString([1, 2, 3]);
|
||
| 12546 | * // => '1,2,3'
|
||
| 12547 | */
|
||
| 12548 | function toString(value) { |
||
| 12549 | return value == null ? '' : baseToString(value); |
||
| 12550 | } |
||
| 12551 | |||
| 12552 | /*------------------------------------------------------------------------*/
|
||
| 12553 | |||
| 12554 | /**
|
||
| 12555 | * Assigns own enumerable string keyed properties of source objects to the
|
||
| 12556 | * destination object. Source objects are applied from left to right.
|
||
| 12557 | * Subsequent sources overwrite property assignments of previous sources.
|
||
| 12558 | *
|
||
| 12559 | * **Note:** This method mutates `object` and is loosely based on
|
||
| 12560 | * [`Object.assign`](https://mdn.io/Object/assign).
|
||
| 12561 | *
|
||
| 12562 | * @static
|
||
| 12563 | * @memberOf _
|
||
| 12564 | * @since 0.10.0
|
||
| 12565 | * @category Object
|
||
| 12566 | * @param {Object} object The destination object.
|
||
| 12567 | * @param {...Object} [sources] The source objects.
|
||
| 12568 | * @returns {Object} Returns `object`.
|
||
| 12569 | * @see _.assignIn
|
||
| 12570 | * @example
|
||
| 12571 | *
|
||
| 12572 | * function Foo() {
|
||
| 12573 | * this.a = 1;
|
||
| 12574 | * }
|
||
| 12575 | *
|
||
| 12576 | * function Bar() {
|
||
| 12577 | * this.c = 3;
|
||
| 12578 | * }
|
||
| 12579 | *
|
||
| 12580 | * Foo.prototype.b = 2;
|
||
| 12581 | * Bar.prototype.d = 4;
|
||
| 12582 | *
|
||
| 12583 | * _.assign({ 'a': 0 }, new Foo, new Bar);
|
||
| 12584 | * // => { 'a': 1, 'c': 3 }
|
||
| 12585 | */
|
||
| 12586 | var assign = createAssigner(function(object, source) { |
||
| 12587 | if (isPrototype(source) || isArrayLike(source)) {
|
||
| 12588 | copyObject(source, keys(source), object); |
||
| 12589 | return;
|
||
| 12590 | } |
||
| 12591 | for (var key in source) { |
||
| 12592 | if (hasOwnProperty.call(source, key)) {
|
||
| 12593 | assignValue(object, key, source[key]); |
||
| 12594 | } |
||
| 12595 | } |
||
| 12596 | }); |
||
| 12597 | |||
| 12598 | /**
|
||
| 12599 | * This method is like `_.assign` except that it iterates over own and
|
||
| 12600 | * inherited source properties.
|
||
| 12601 | *
|
||
| 12602 | * **Note:** This method mutates `object`.
|
||
| 12603 | *
|
||
| 12604 | * @static
|
||
| 12605 | * @memberOf _
|
||
| 12606 | * @since 4.0.0
|
||
| 12607 | * @alias extend
|
||
| 12608 | * @category Object
|
||
| 12609 | * @param {Object} object The destination object.
|
||
| 12610 | * @param {...Object} [sources] The source objects.
|
||
| 12611 | * @returns {Object} Returns `object`.
|
||
| 12612 | * @see _.assign
|
||
| 12613 | * @example
|
||
| 12614 | *
|
||
| 12615 | * function Foo() {
|
||
| 12616 | * this.a = 1;
|
||
| 12617 | * }
|
||
| 12618 | *
|
||
| 12619 | * function Bar() {
|
||
| 12620 | * this.c = 3;
|
||
| 12621 | * }
|
||
| 12622 | *
|
||
| 12623 | * Foo.prototype.b = 2;
|
||
| 12624 | * Bar.prototype.d = 4;
|
||
| 12625 | *
|
||
| 12626 | * _.assignIn({ 'a': 0 }, new Foo, new Bar);
|
||
| 12627 | * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
||
| 12628 | */
|
||
| 12629 | var assignIn = createAssigner(function(object, source) { |
||
| 12630 | copyObject(source, keysIn(source), object); |
||
| 12631 | }); |
||
| 12632 | |||
| 12633 | /**
|
||
| 12634 | * This method is like `_.assignIn` except that it accepts `customizer`
|
||
| 12635 | * which is invoked to produce the assigned values. If `customizer` returns
|
||
| 12636 | * `undefined`, assignment is handled by the method instead. The `customizer`
|
||
| 12637 | * is invoked with five arguments: (objValue, srcValue, key, object, source).
|
||
| 12638 | *
|
||
| 12639 | * **Note:** This method mutates `object`.
|
||
| 12640 | *
|
||
| 12641 | * @static
|
||
| 12642 | * @memberOf _
|
||
| 12643 | * @since 4.0.0
|
||
| 12644 | * @alias extendWith
|
||
| 12645 | * @category Object
|
||
| 12646 | * @param {Object} object The destination object.
|
||
| 12647 | * @param {...Object} sources The source objects.
|
||
| 12648 | * @param {Function} [customizer] The function to customize assigned values.
|
||
| 12649 | * @returns {Object} Returns `object`.
|
||
| 12650 | * @see _.assignWith
|
||
| 12651 | * @example
|
||
| 12652 | *
|
||
| 12653 | * function customizer(objValue, srcValue) {
|
||
| 12654 | * return _.isUndefined(objValue) ? srcValue : objValue;
|
||
| 12655 | * }
|
||
| 12656 | *
|
||
| 12657 | * var defaults = _.partialRight(_.assignInWith, customizer);
|
||
| 12658 | *
|
||
| 12659 | * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
||
| 12660 | * // => { 'a': 1, 'b': 2 }
|
||
| 12661 | */
|
||
| 12662 | var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { |
||
| 12663 | copyObject(source, keysIn(source), object, customizer); |
||
| 12664 | }); |
||
| 12665 | |||
| 12666 | /**
|
||
| 12667 | * This method is like `_.assign` except that it accepts `customizer`
|
||
| 12668 | * which is invoked to produce the assigned values. If `customizer` returns
|
||
| 12669 | * `undefined`, assignment is handled by the method instead. The `customizer`
|
||
| 12670 | * is invoked with five arguments: (objValue, srcValue, key, object, source).
|
||
| 12671 | *
|
||
| 12672 | * **Note:** This method mutates `object`.
|
||
| 12673 | *
|
||
| 12674 | * @static
|
||
| 12675 | * @memberOf _
|
||
| 12676 | * @since 4.0.0
|
||
| 12677 | * @category Object
|
||
| 12678 | * @param {Object} object The destination object.
|
||
| 12679 | * @param {...Object} sources The source objects.
|
||
| 12680 | * @param {Function} [customizer] The function to customize assigned values.
|
||
| 12681 | * @returns {Object} Returns `object`.
|
||
| 12682 | * @see _.assignInWith
|
||
| 12683 | * @example
|
||
| 12684 | *
|
||
| 12685 | * function customizer(objValue, srcValue) {
|
||
| 12686 | * return _.isUndefined(objValue) ? srcValue : objValue;
|
||
| 12687 | * }
|
||
| 12688 | *
|
||
| 12689 | * var defaults = _.partialRight(_.assignWith, customizer);
|
||
| 12690 | *
|
||
| 12691 | * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
||
| 12692 | * // => { 'a': 1, 'b': 2 }
|
||
| 12693 | */
|
||
| 12694 | var assignWith = createAssigner(function(object, source, srcIndex, customizer) { |
||
| 12695 | copyObject(source, keys(source), object, customizer); |
||
| 12696 | }); |
||
| 12697 | |||
| 12698 | /**
|
||
| 12699 | * Creates an array of values corresponding to `paths` of `object`.
|
||
| 12700 | *
|
||
| 12701 | * @static
|
||
| 12702 | * @memberOf _
|
||
| 12703 | * @since 1.0.0
|
||
| 12704 | * @category Object
|
||
| 12705 | * @param {Object} object The object to iterate over.
|
||
| 12706 | * @param {...(string|string[])} [paths] The property paths to pick.
|
||
| 12707 | * @returns {Array} Returns the picked values.
|
||
| 12708 | * @example
|
||
| 12709 | *
|
||
| 12710 | * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
|
||
| 12711 | *
|
||
| 12712 | * _.at(object, ['a[0].b.c', 'a[1]']);
|
||
| 12713 | * // => [3, 4]
|
||
| 12714 | */
|
||
| 12715 | var at = flatRest(baseAt);
|
||
| 12716 | |||
| 12717 | /**
|
||
| 12718 | * Creates an object that inherits from the `prototype` object. If a
|
||
| 12719 | * `properties` object is given, its own enumerable string keyed properties
|
||
| 12720 | * are assigned to the created object.
|
||
| 12721 | *
|
||
| 12722 | * @static
|
||
| 12723 | * @memberOf _
|
||
| 12724 | * @since 2.3.0
|
||
| 12725 | * @category Object
|
||
| 12726 | * @param {Object} prototype The object to inherit from.
|
||
| 12727 | * @param {Object} [properties] The properties to assign to the object.
|
||
| 12728 | * @returns {Object} Returns the new object.
|
||
| 12729 | * @example
|
||
| 12730 | *
|
||
| 12731 | * function Shape() {
|
||
| 12732 | * this.x = 0;
|
||
| 12733 | * this.y = 0;
|
||
| 12734 | * }
|
||
| 12735 | *
|
||
| 12736 | * function Circle() {
|
||
| 12737 | * Shape.call(this);
|
||
| 12738 | * }
|
||
| 12739 | *
|
||
| 12740 | * Circle.prototype = _.create(Shape.prototype, {
|
||
| 12741 | * 'constructor': Circle
|
||
| 12742 | * });
|
||
| 12743 | *
|
||
| 12744 | * var circle = new Circle;
|
||
| 12745 | * circle instanceof Circle;
|
||
| 12746 | * // => true
|
||
| 12747 | *
|
||
| 12748 | * circle instanceof Shape;
|
||
| 12749 | * // => true
|
||
| 12750 | */
|
||
| 12751 | function create(prototype, properties) { |
||
| 12752 | var result = baseCreate(prototype);
|
||
| 12753 | return properties == null ? result : baseAssign(result, properties); |
||
| 12754 | } |
||
| 12755 | |||
| 12756 | /**
|
||
| 12757 | * Assigns own and inherited enumerable string keyed properties of source
|
||
| 12758 | * objects to the destination object for all destination properties that
|
||
| 12759 | * resolve to `undefined`. Source objects are applied from left to right.
|
||
| 12760 | * Once a property is set, additional values of the same property are ignored.
|
||
| 12761 | *
|
||
| 12762 | * **Note:** This method mutates `object`.
|
||
| 12763 | *
|
||
| 12764 | * @static
|
||
| 12765 | * @since 0.1.0
|
||
| 12766 | * @memberOf _
|
||
| 12767 | * @category Object
|
||
| 12768 | * @param {Object} object The destination object.
|
||
| 12769 | * @param {...Object} [sources] The source objects.
|
||
| 12770 | * @returns {Object} Returns `object`.
|
||
| 12771 | * @see _.defaultsDeep
|
||
| 12772 | * @example
|
||
| 12773 | *
|
||
| 12774 | * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
||
| 12775 | * // => { 'a': 1, 'b': 2 }
|
||
| 12776 | */
|
||
| 12777 | var defaults = baseRest(function(object, sources) { |
||
| 12778 | object = Object(object); |
||
| 12779 | |||
| 12780 | var index = -1; |
||
| 12781 | var length = sources.length;
|
||
| 12782 | var guard = length > 2 ? sources[2] : undefined; |
||
| 12783 | |||
| 12784 | if (guard && isIterateeCall(sources[0], sources[1], guard)) { |
||
| 12785 | length = 1;
|
||
| 12786 | } |
||
| 12787 | |||
| 12788 | while (++index < length) {
|
||
| 12789 | var source = sources[index];
|
||
| 12790 | var props = keysIn(source);
|
||
| 12791 | var propsIndex = -1; |
||
| 12792 | var propsLength = props.length;
|
||
| 12793 | |||
| 12794 | while (++propsIndex < propsLength) {
|
||
| 12795 | var key = props[propsIndex];
|
||
| 12796 | var value = object[key];
|
||
| 12797 | |||
| 12798 | if (value === undefined || |
||
| 12799 | (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
||
| 12800 | object[key] = source[key]; |
||
| 12801 | } |
||
| 12802 | } |
||
| 12803 | } |
||
| 12804 | |||
| 12805 | return object;
|
||
| 12806 | }); |
||
| 12807 | |||
| 12808 | /**
|
||
| 12809 | * This method is like `_.defaults` except that it recursively assigns
|
||
| 12810 | * default properties.
|
||
| 12811 | *
|
||
| 12812 | * **Note:** This method mutates `object`.
|
||
| 12813 | *
|
||
| 12814 | * @static
|
||
| 12815 | * @memberOf _
|
||
| 12816 | * @since 3.10.0
|
||
| 12817 | * @category Object
|
||
| 12818 | * @param {Object} object The destination object.
|
||
| 12819 | * @param {...Object} [sources] The source objects.
|
||
| 12820 | * @returns {Object} Returns `object`.
|
||
| 12821 | * @see _.defaults
|
||
| 12822 | * @example
|
||
| 12823 | *
|
||
| 12824 | * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
|
||
| 12825 | * // => { 'a': { 'b': 2, 'c': 3 } }
|
||
| 12826 | */
|
||
| 12827 | var defaultsDeep = baseRest(function(args) { |
||
| 12828 | args.push(undefined, customDefaultsMerge);
|
||
| 12829 | return apply(mergeWith, undefined, args); |
||
| 12830 | }); |
||
| 12831 | |||
| 12832 | /**
|
||
| 12833 | * This method is like `_.find` except that it returns the key of the first
|
||
| 12834 | * element `predicate` returns truthy for instead of the element itself.
|
||
| 12835 | *
|
||
| 12836 | * @static
|
||
| 12837 | * @memberOf _
|
||
| 12838 | * @since 1.1.0
|
||
| 12839 | * @category Object
|
||
| 12840 | * @param {Object} object The object to inspect.
|
||
| 12841 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 12842 | * @returns {string|undefined} Returns the key of the matched element,
|
||
| 12843 | * else `undefined`.
|
||
| 12844 | * @example
|
||
| 12845 | *
|
||
| 12846 | * var users = {
|
||
| 12847 | * 'barney': { 'age': 36, 'active': true },
|
||
| 12848 | * 'fred': { 'age': 40, 'active': false },
|
||
| 12849 | * 'pebbles': { 'age': 1, 'active': true }
|
||
| 12850 | * };
|
||
| 12851 | *
|
||
| 12852 | * _.findKey(users, function(o) { return o.age < 40; });
|
||
| 12853 | * // => 'barney' (iteration order is not guaranteed)
|
||
| 12854 | *
|
||
| 12855 | * // The `_.matches` iteratee shorthand.
|
||
| 12856 | * _.findKey(users, { 'age': 1, 'active': true });
|
||
| 12857 | * // => 'pebbles'
|
||
| 12858 | *
|
||
| 12859 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 12860 | * _.findKey(users, ['active', false]);
|
||
| 12861 | * // => 'fred'
|
||
| 12862 | *
|
||
| 12863 | * // The `_.property` iteratee shorthand.
|
||
| 12864 | * _.findKey(users, 'active');
|
||
| 12865 | * // => 'barney'
|
||
| 12866 | */
|
||
| 12867 | function findKey(object, predicate) { |
||
| 12868 | return baseFindKey(object, getIteratee(predicate, 3), baseForOwn); |
||
| 12869 | } |
||
| 12870 | |||
| 12871 | /**
|
||
| 12872 | * This method is like `_.findKey` except that it iterates over elements of
|
||
| 12873 | * a collection in the opposite order.
|
||
| 12874 | *
|
||
| 12875 | * @static
|
||
| 12876 | * @memberOf _
|
||
| 12877 | * @since 2.0.0
|
||
| 12878 | * @category Object
|
||
| 12879 | * @param {Object} object The object to inspect.
|
||
| 12880 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||
| 12881 | * @returns {string|undefined} Returns the key of the matched element,
|
||
| 12882 | * else `undefined`.
|
||
| 12883 | * @example
|
||
| 12884 | *
|
||
| 12885 | * var users = {
|
||
| 12886 | * 'barney': { 'age': 36, 'active': true },
|
||
| 12887 | * 'fred': { 'age': 40, 'active': false },
|
||
| 12888 | * 'pebbles': { 'age': 1, 'active': true }
|
||
| 12889 | * };
|
||
| 12890 | *
|
||
| 12891 | * _.findLastKey(users, function(o) { return o.age < 40; });
|
||
| 12892 | * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
|
||
| 12893 | *
|
||
| 12894 | * // The `_.matches` iteratee shorthand.
|
||
| 12895 | * _.findLastKey(users, { 'age': 36, 'active': true });
|
||
| 12896 | * // => 'barney'
|
||
| 12897 | *
|
||
| 12898 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 12899 | * _.findLastKey(users, ['active', false]);
|
||
| 12900 | * // => 'fred'
|
||
| 12901 | *
|
||
| 12902 | * // The `_.property` iteratee shorthand.
|
||
| 12903 | * _.findLastKey(users, 'active');
|
||
| 12904 | * // => 'pebbles'
|
||
| 12905 | */
|
||
| 12906 | function findLastKey(object, predicate) { |
||
| 12907 | return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight); |
||
| 12908 | } |
||
| 12909 | |||
| 12910 | /**
|
||
| 12911 | * Iterates over own and inherited enumerable string keyed properties of an
|
||
| 12912 | * object and invokes `iteratee` for each property. The iteratee is invoked
|
||
| 12913 | * with three arguments: (value, key, object). Iteratee functions may exit
|
||
| 12914 | * iteration early by explicitly returning `false`.
|
||
| 12915 | *
|
||
| 12916 | * @static
|
||
| 12917 | * @memberOf _
|
||
| 12918 | * @since 0.3.0
|
||
| 12919 | * @category Object
|
||
| 12920 | * @param {Object} object The object to iterate over.
|
||
| 12921 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 12922 | * @returns {Object} Returns `object`.
|
||
| 12923 | * @see _.forInRight
|
||
| 12924 | * @example
|
||
| 12925 | *
|
||
| 12926 | * function Foo() {
|
||
| 12927 | * this.a = 1;
|
||
| 12928 | * this.b = 2;
|
||
| 12929 | * }
|
||
| 12930 | *
|
||
| 12931 | * Foo.prototype.c = 3;
|
||
| 12932 | *
|
||
| 12933 | * _.forIn(new Foo, function(value, key) {
|
||
| 12934 | * console.log(key);
|
||
| 12935 | * });
|
||
| 12936 | * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
|
||
| 12937 | */
|
||
| 12938 | function forIn(object, iteratee) { |
||
| 12939 | return object == null |
||
| 12940 | ? object |
||
| 12941 | : baseFor(object, getIteratee(iteratee, 3), keysIn);
|
||
| 12942 | } |
||
| 12943 | |||
| 12944 | /**
|
||
| 12945 | * This method is like `_.forIn` except that it iterates over properties of
|
||
| 12946 | * `object` in the opposite order.
|
||
| 12947 | *
|
||
| 12948 | * @static
|
||
| 12949 | * @memberOf _
|
||
| 12950 | * @since 2.0.0
|
||
| 12951 | * @category Object
|
||
| 12952 | * @param {Object} object The object to iterate over.
|
||
| 12953 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 12954 | * @returns {Object} Returns `object`.
|
||
| 12955 | * @see _.forIn
|
||
| 12956 | * @example
|
||
| 12957 | *
|
||
| 12958 | * function Foo() {
|
||
| 12959 | * this.a = 1;
|
||
| 12960 | * this.b = 2;
|
||
| 12961 | * }
|
||
| 12962 | *
|
||
| 12963 | * Foo.prototype.c = 3;
|
||
| 12964 | *
|
||
| 12965 | * _.forInRight(new Foo, function(value, key) {
|
||
| 12966 | * console.log(key);
|
||
| 12967 | * });
|
||
| 12968 | * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
|
||
| 12969 | */
|
||
| 12970 | function forInRight(object, iteratee) { |
||
| 12971 | return object == null |
||
| 12972 | ? object |
||
| 12973 | : baseForRight(object, getIteratee(iteratee, 3), keysIn);
|
||
| 12974 | } |
||
| 12975 | |||
| 12976 | /**
|
||
| 12977 | * Iterates over own enumerable string keyed properties of an object and
|
||
| 12978 | * invokes `iteratee` for each property. The iteratee is invoked with three
|
||
| 12979 | * arguments: (value, key, object). Iteratee functions may exit iteration
|
||
| 12980 | * early by explicitly returning `false`.
|
||
| 12981 | *
|
||
| 12982 | * @static
|
||
| 12983 | * @memberOf _
|
||
| 12984 | * @since 0.3.0
|
||
| 12985 | * @category Object
|
||
| 12986 | * @param {Object} object The object to iterate over.
|
||
| 12987 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 12988 | * @returns {Object} Returns `object`.
|
||
| 12989 | * @see _.forOwnRight
|
||
| 12990 | * @example
|
||
| 12991 | *
|
||
| 12992 | * function Foo() {
|
||
| 12993 | * this.a = 1;
|
||
| 12994 | * this.b = 2;
|
||
| 12995 | * }
|
||
| 12996 | *
|
||
| 12997 | * Foo.prototype.c = 3;
|
||
| 12998 | *
|
||
| 12999 | * _.forOwn(new Foo, function(value, key) {
|
||
| 13000 | * console.log(key);
|
||
| 13001 | * });
|
||
| 13002 | * // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
||
| 13003 | */
|
||
| 13004 | function forOwn(object, iteratee) { |
||
| 13005 | return object && baseForOwn(object, getIteratee(iteratee, 3)); |
||
| 13006 | } |
||
| 13007 | |||
| 13008 | /**
|
||
| 13009 | * This method is like `_.forOwn` except that it iterates over properties of
|
||
| 13010 | * `object` in the opposite order.
|
||
| 13011 | *
|
||
| 13012 | * @static
|
||
| 13013 | * @memberOf _
|
||
| 13014 | * @since 2.0.0
|
||
| 13015 | * @category Object
|
||
| 13016 | * @param {Object} object The object to iterate over.
|
||
| 13017 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 13018 | * @returns {Object} Returns `object`.
|
||
| 13019 | * @see _.forOwn
|
||
| 13020 | * @example
|
||
| 13021 | *
|
||
| 13022 | * function Foo() {
|
||
| 13023 | * this.a = 1;
|
||
| 13024 | * this.b = 2;
|
||
| 13025 | * }
|
||
| 13026 | *
|
||
| 13027 | * Foo.prototype.c = 3;
|
||
| 13028 | *
|
||
| 13029 | * _.forOwnRight(new Foo, function(value, key) {
|
||
| 13030 | * console.log(key);
|
||
| 13031 | * });
|
||
| 13032 | * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
|
||
| 13033 | */
|
||
| 13034 | function forOwnRight(object, iteratee) { |
||
| 13035 | return object && baseForOwnRight(object, getIteratee(iteratee, 3)); |
||
| 13036 | } |
||
| 13037 | |||
| 13038 | /**
|
||
| 13039 | * Creates an array of function property names from own enumerable properties
|
||
| 13040 | * of `object`.
|
||
| 13041 | *
|
||
| 13042 | * @static
|
||
| 13043 | * @since 0.1.0
|
||
| 13044 | * @memberOf _
|
||
| 13045 | * @category Object
|
||
| 13046 | * @param {Object} object The object to inspect.
|
||
| 13047 | * @returns {Array} Returns the function names.
|
||
| 13048 | * @see _.functionsIn
|
||
| 13049 | * @example
|
||
| 13050 | *
|
||
| 13051 | * function Foo() {
|
||
| 13052 | * this.a = _.constant('a');
|
||
| 13053 | * this.b = _.constant('b');
|
||
| 13054 | * }
|
||
| 13055 | *
|
||
| 13056 | * Foo.prototype.c = _.constant('c');
|
||
| 13057 | *
|
||
| 13058 | * _.functions(new Foo);
|
||
| 13059 | * // => ['a', 'b']
|
||
| 13060 | */
|
||
| 13061 | function functions(object) { |
||
| 13062 | return object == null ? [] : baseFunctions(object, keys(object)); |
||
| 13063 | } |
||
| 13064 | |||
| 13065 | /**
|
||
| 13066 | * Creates an array of function property names from own and inherited
|
||
| 13067 | * enumerable properties of `object`.
|
||
| 13068 | *
|
||
| 13069 | * @static
|
||
| 13070 | * @memberOf _
|
||
| 13071 | * @since 4.0.0
|
||
| 13072 | * @category Object
|
||
| 13073 | * @param {Object} object The object to inspect.
|
||
| 13074 | * @returns {Array} Returns the function names.
|
||
| 13075 | * @see _.functions
|
||
| 13076 | * @example
|
||
| 13077 | *
|
||
| 13078 | * function Foo() {
|
||
| 13079 | * this.a = _.constant('a');
|
||
| 13080 | * this.b = _.constant('b');
|
||
| 13081 | * }
|
||
| 13082 | *
|
||
| 13083 | * Foo.prototype.c = _.constant('c');
|
||
| 13084 | *
|
||
| 13085 | * _.functionsIn(new Foo);
|
||
| 13086 | * // => ['a', 'b', 'c']
|
||
| 13087 | */
|
||
| 13088 | function functionsIn(object) { |
||
| 13089 | return object == null ? [] : baseFunctions(object, keysIn(object)); |
||
| 13090 | } |
||
| 13091 | |||
| 13092 | /**
|
||
| 13093 | * Gets the value at `path` of `object`. If the resolved value is
|
||
| 13094 | * `undefined`, the `defaultValue` is returned in its place.
|
||
| 13095 | *
|
||
| 13096 | * @static
|
||
| 13097 | * @memberOf _
|
||
| 13098 | * @since 3.7.0
|
||
| 13099 | * @category Object
|
||
| 13100 | * @param {Object} object The object to query.
|
||
| 13101 | * @param {Array|string} path The path of the property to get.
|
||
| 13102 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
||
| 13103 | * @returns {*} Returns the resolved value.
|
||
| 13104 | * @example
|
||
| 13105 | *
|
||
| 13106 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
||
| 13107 | *
|
||
| 13108 | * _.get(object, 'a[0].b.c');
|
||
| 13109 | * // => 3
|
||
| 13110 | *
|
||
| 13111 | * _.get(object, ['a', '0', 'b', 'c']);
|
||
| 13112 | * // => 3
|
||
| 13113 | *
|
||
| 13114 | * _.get(object, 'a.b.c', 'default');
|
||
| 13115 | * // => 'default'
|
||
| 13116 | */
|
||
| 13117 | function get(object, path, defaultValue) { |
||
| 13118 | var result = object == null ? undefined : baseGet(object, path); |
||
| 13119 | return result === undefined ? defaultValue : result; |
||
| 13120 | } |
||
| 13121 | |||
| 13122 | /**
|
||
| 13123 | * Checks if `path` is a direct property of `object`.
|
||
| 13124 | *
|
||
| 13125 | * @static
|
||
| 13126 | * @since 0.1.0
|
||
| 13127 | * @memberOf _
|
||
| 13128 | * @category Object
|
||
| 13129 | * @param {Object} object The object to query.
|
||
| 13130 | * @param {Array|string} path The path to check.
|
||
| 13131 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
||
| 13132 | * @example
|
||
| 13133 | *
|
||
| 13134 | * var object = { 'a': { 'b': 2 } };
|
||
| 13135 | * var other = _.create({ 'a': _.create({ 'b': 2 }) });
|
||
| 13136 | *
|
||
| 13137 | * _.has(object, 'a');
|
||
| 13138 | * // => true
|
||
| 13139 | *
|
||
| 13140 | * _.has(object, 'a.b');
|
||
| 13141 | * // => true
|
||
| 13142 | *
|
||
| 13143 | * _.has(object, ['a', 'b']);
|
||
| 13144 | * // => true
|
||
| 13145 | *
|
||
| 13146 | * _.has(other, 'a');
|
||
| 13147 | * // => false
|
||
| 13148 | */
|
||
| 13149 | function has(object, path) { |
||
| 13150 | return object != null && hasPath(object, path, baseHas); |
||
| 13151 | } |
||
| 13152 | |||
| 13153 | /**
|
||
| 13154 | * Checks if `path` is a direct or inherited property of `object`.
|
||
| 13155 | *
|
||
| 13156 | * @static
|
||
| 13157 | * @memberOf _
|
||
| 13158 | * @since 4.0.0
|
||
| 13159 | * @category Object
|
||
| 13160 | * @param {Object} object The object to query.
|
||
| 13161 | * @param {Array|string} path The path to check.
|
||
| 13162 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
||
| 13163 | * @example
|
||
| 13164 | *
|
||
| 13165 | * var object = _.create({ 'a': _.create({ 'b': 2 }) });
|
||
| 13166 | *
|
||
| 13167 | * _.hasIn(object, 'a');
|
||
| 13168 | * // => true
|
||
| 13169 | *
|
||
| 13170 | * _.hasIn(object, 'a.b');
|
||
| 13171 | * // => true
|
||
| 13172 | *
|
||
| 13173 | * _.hasIn(object, ['a', 'b']);
|
||
| 13174 | * // => true
|
||
| 13175 | *
|
||
| 13176 | * _.hasIn(object, 'b');
|
||
| 13177 | * // => false
|
||
| 13178 | */
|
||
| 13179 | function hasIn(object, path) { |
||
| 13180 | return object != null && hasPath(object, path, baseHasIn); |
||
| 13181 | } |
||
| 13182 | |||
| 13183 | /**
|
||
| 13184 | * Creates an object composed of the inverted keys and values of `object`.
|
||
| 13185 | * If `object` contains duplicate values, subsequent values overwrite
|
||
| 13186 | * property assignments of previous values.
|
||
| 13187 | *
|
||
| 13188 | * @static
|
||
| 13189 | * @memberOf _
|
||
| 13190 | * @since 0.7.0
|
||
| 13191 | * @category Object
|
||
| 13192 | * @param {Object} object The object to invert.
|
||
| 13193 | * @returns {Object} Returns the new inverted object.
|
||
| 13194 | * @example
|
||
| 13195 | *
|
||
| 13196 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
||
| 13197 | *
|
||
| 13198 | * _.invert(object);
|
||
| 13199 | * // => { '1': 'c', '2': 'b' }
|
||
| 13200 | */
|
||
| 13201 | var invert = createInverter(function(result, value, key) { |
||
| 13202 | if (value != null && |
||
| 13203 | typeof value.toString != 'function') { |
||
| 13204 | value = nativeObjectToString.call(value); |
||
| 13205 | } |
||
| 13206 | |||
| 13207 | result[value] = key; |
||
| 13208 | }, constant(identity)); |
||
| 13209 | |||
| 13210 | /**
|
||
| 13211 | * This method is like `_.invert` except that the inverted object is generated
|
||
| 13212 | * from the results of running each element of `object` thru `iteratee`. The
|
||
| 13213 | * corresponding inverted value of each inverted key is an array of keys
|
||
| 13214 | * responsible for generating the inverted value. The iteratee is invoked
|
||
| 13215 | * with one argument: (value).
|
||
| 13216 | *
|
||
| 13217 | * @static
|
||
| 13218 | * @memberOf _
|
||
| 13219 | * @since 4.1.0
|
||
| 13220 | * @category Object
|
||
| 13221 | * @param {Object} object The object to invert.
|
||
| 13222 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 13223 | * @returns {Object} Returns the new inverted object.
|
||
| 13224 | * @example
|
||
| 13225 | *
|
||
| 13226 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
||
| 13227 | *
|
||
| 13228 | * _.invertBy(object);
|
||
| 13229 | * // => { '1': ['a', 'c'], '2': ['b'] }
|
||
| 13230 | *
|
||
| 13231 | * _.invertBy(object, function(value) {
|
||
| 13232 | * return 'group' + value;
|
||
| 13233 | * });
|
||
| 13234 | * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
||
| 13235 | */
|
||
| 13236 | var invertBy = createInverter(function(result, value, key) { |
||
| 13237 | if (value != null && |
||
| 13238 | typeof value.toString != 'function') { |
||
| 13239 | value = nativeObjectToString.call(value); |
||
| 13240 | } |
||
| 13241 | |||
| 13242 | if (hasOwnProperty.call(result, value)) {
|
||
| 13243 | result[value].push(key); |
||
| 13244 | } else {
|
||
| 13245 | result[value] = [key]; |
||
| 13246 | } |
||
| 13247 | }, getIteratee); |
||
| 13248 | |||
| 13249 | /**
|
||
| 13250 | * Invokes the method at `path` of `object`.
|
||
| 13251 | *
|
||
| 13252 | * @static
|
||
| 13253 | * @memberOf _
|
||
| 13254 | * @since 4.0.0
|
||
| 13255 | * @category Object
|
||
| 13256 | * @param {Object} object The object to query.
|
||
| 13257 | * @param {Array|string} path The path of the method to invoke.
|
||
| 13258 | * @param {...*} [args] The arguments to invoke the method with.
|
||
| 13259 | * @returns {*} Returns the result of the invoked method.
|
||
| 13260 | * @example
|
||
| 13261 | *
|
||
| 13262 | * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
|
||
| 13263 | *
|
||
| 13264 | * _.invoke(object, 'a[0].b.c.slice', 1, 3);
|
||
| 13265 | * // => [2, 3]
|
||
| 13266 | */
|
||
| 13267 | var invoke = baseRest(baseInvoke);
|
||
| 13268 | |||
| 13269 | /**
|
||
| 13270 | * Creates an array of the own enumerable property names of `object`.
|
||
| 13271 | *
|
||
| 13272 | * **Note:** Non-object values are coerced to objects. See the
|
||
| 13273 | * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
||
| 13274 | * for more details.
|
||
| 13275 | *
|
||
| 13276 | * @static
|
||
| 13277 | * @since 0.1.0
|
||
| 13278 | * @memberOf _
|
||
| 13279 | * @category Object
|
||
| 13280 | * @param {Object} object The object to query.
|
||
| 13281 | * @returns {Array} Returns the array of property names.
|
||
| 13282 | * @example
|
||
| 13283 | *
|
||
| 13284 | * function Foo() {
|
||
| 13285 | * this.a = 1;
|
||
| 13286 | * this.b = 2;
|
||
| 13287 | * }
|
||
| 13288 | *
|
||
| 13289 | * Foo.prototype.c = 3;
|
||
| 13290 | *
|
||
| 13291 | * _.keys(new Foo);
|
||
| 13292 | * // => ['a', 'b'] (iteration order is not guaranteed)
|
||
| 13293 | *
|
||
| 13294 | * _.keys('hi');
|
||
| 13295 | * // => ['0', '1']
|
||
| 13296 | */
|
||
| 13297 | function keys(object) { |
||
| 13298 | return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
||
| 13299 | } |
||
| 13300 | |||
| 13301 | /**
|
||
| 13302 | * Creates an array of the own and inherited enumerable property names of `object`.
|
||
| 13303 | *
|
||
| 13304 | * **Note:** Non-object values are coerced to objects.
|
||
| 13305 | *
|
||
| 13306 | * @static
|
||
| 13307 | * @memberOf _
|
||
| 13308 | * @since 3.0.0
|
||
| 13309 | * @category Object
|
||
| 13310 | * @param {Object} object The object to query.
|
||
| 13311 | * @returns {Array} Returns the array of property names.
|
||
| 13312 | * @example
|
||
| 13313 | *
|
||
| 13314 | * function Foo() {
|
||
| 13315 | * this.a = 1;
|
||
| 13316 | * this.b = 2;
|
||
| 13317 | * }
|
||
| 13318 | *
|
||
| 13319 | * Foo.prototype.c = 3;
|
||
| 13320 | *
|
||
| 13321 | * _.keysIn(new Foo);
|
||
| 13322 | * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
||
| 13323 | */
|
||
| 13324 | function keysIn(object) { |
||
| 13325 | return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); |
||
| 13326 | } |
||
| 13327 | |||
| 13328 | /**
|
||
| 13329 | * The opposite of `_.mapValues`; this method creates an object with the
|
||
| 13330 | * same values as `object` and keys generated by running each own enumerable
|
||
| 13331 | * string keyed property of `object` thru `iteratee`. The iteratee is invoked
|
||
| 13332 | * with three arguments: (value, key, object).
|
||
| 13333 | *
|
||
| 13334 | * @static
|
||
| 13335 | * @memberOf _
|
||
| 13336 | * @since 3.8.0
|
||
| 13337 | * @category Object
|
||
| 13338 | * @param {Object} object The object to iterate over.
|
||
| 13339 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 13340 | * @returns {Object} Returns the new mapped object.
|
||
| 13341 | * @see _.mapValues
|
||
| 13342 | * @example
|
||
| 13343 | *
|
||
| 13344 | * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
|
||
| 13345 | * return key + value;
|
||
| 13346 | * });
|
||
| 13347 | * // => { 'a1': 1, 'b2': 2 }
|
||
| 13348 | */
|
||
| 13349 | function mapKeys(object, iteratee) { |
||
| 13350 | var result = {};
|
||
| 13351 | iteratee = getIteratee(iteratee, 3);
|
||
| 13352 | |||
| 13353 | baseForOwn(object, function(value, key, object) {
|
||
| 13354 | baseAssignValue(result, iteratee(value, key, object), value); |
||
| 13355 | }); |
||
| 13356 | return result;
|
||
| 13357 | } |
||
| 13358 | |||
| 13359 | /**
|
||
| 13360 | * Creates an object with the same keys as `object` and values generated
|
||
| 13361 | * by running each own enumerable string keyed property of `object` thru
|
||
| 13362 | * `iteratee`. The iteratee is invoked with three arguments:
|
||
| 13363 | * (value, key, object).
|
||
| 13364 | *
|
||
| 13365 | * @static
|
||
| 13366 | * @memberOf _
|
||
| 13367 | * @since 2.4.0
|
||
| 13368 | * @category Object
|
||
| 13369 | * @param {Object} object The object to iterate over.
|
||
| 13370 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 13371 | * @returns {Object} Returns the new mapped object.
|
||
| 13372 | * @see _.mapKeys
|
||
| 13373 | * @example
|
||
| 13374 | *
|
||
| 13375 | * var users = {
|
||
| 13376 | * 'fred': { 'user': 'fred', 'age': 40 },
|
||
| 13377 | * 'pebbles': { 'user': 'pebbles', 'age': 1 }
|
||
| 13378 | * };
|
||
| 13379 | *
|
||
| 13380 | * _.mapValues(users, function(o) { return o.age; });
|
||
| 13381 | * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
||
| 13382 | *
|
||
| 13383 | * // The `_.property` iteratee shorthand.
|
||
| 13384 | * _.mapValues(users, 'age');
|
||
| 13385 | * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
||
| 13386 | */
|
||
| 13387 | function mapValues(object, iteratee) { |
||
| 13388 | var result = {};
|
||
| 13389 | iteratee = getIteratee(iteratee, 3);
|
||
| 13390 | |||
| 13391 | baseForOwn(object, function(value, key, object) {
|
||
| 13392 | baseAssignValue(result, key, iteratee(value, key, object)); |
||
| 13393 | }); |
||
| 13394 | return result;
|
||
| 13395 | } |
||
| 13396 | |||
| 13397 | /**
|
||
| 13398 | * This method is like `_.assign` except that it recursively merges own and
|
||
| 13399 | * inherited enumerable string keyed properties of source objects into the
|
||
| 13400 | * destination object. Source properties that resolve to `undefined` are
|
||
| 13401 | * skipped if a destination value exists. Array and plain object properties
|
||
| 13402 | * are merged recursively. Other objects and value types are overridden by
|
||
| 13403 | * assignment. Source objects are applied from left to right. Subsequent
|
||
| 13404 | * sources overwrite property assignments of previous sources.
|
||
| 13405 | *
|
||
| 13406 | * **Note:** This method mutates `object`.
|
||
| 13407 | *
|
||
| 13408 | * @static
|
||
| 13409 | * @memberOf _
|
||
| 13410 | * @since 0.5.0
|
||
| 13411 | * @category Object
|
||
| 13412 | * @param {Object} object The destination object.
|
||
| 13413 | * @param {...Object} [sources] The source objects.
|
||
| 13414 | * @returns {Object} Returns `object`.
|
||
| 13415 | * @example
|
||
| 13416 | *
|
||
| 13417 | * var object = {
|
||
| 13418 | * 'a': [{ 'b': 2 }, { 'd': 4 }]
|
||
| 13419 | * };
|
||
| 13420 | *
|
||
| 13421 | * var other = {
|
||
| 13422 | * 'a': [{ 'c': 3 }, { 'e': 5 }]
|
||
| 13423 | * };
|
||
| 13424 | *
|
||
| 13425 | * _.merge(object, other);
|
||
| 13426 | * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
|
||
| 13427 | */
|
||
| 13428 | var merge = createAssigner(function(object, source, srcIndex) { |
||
| 13429 | baseMerge(object, source, srcIndex); |
||
| 13430 | }); |
||
| 13431 | |||
| 13432 | /**
|
||
| 13433 | * This method is like `_.merge` except that it accepts `customizer` which
|
||
| 13434 | * is invoked to produce the merged values of the destination and source
|
||
| 13435 | * properties. If `customizer` returns `undefined`, merging is handled by the
|
||
| 13436 | * method instead. The `customizer` is invoked with six arguments:
|
||
| 13437 | * (objValue, srcValue, key, object, source, stack).
|
||
| 13438 | *
|
||
| 13439 | * **Note:** This method mutates `object`.
|
||
| 13440 | *
|
||
| 13441 | * @static
|
||
| 13442 | * @memberOf _
|
||
| 13443 | * @since 4.0.0
|
||
| 13444 | * @category Object
|
||
| 13445 | * @param {Object} object The destination object.
|
||
| 13446 | * @param {...Object} sources The source objects.
|
||
| 13447 | * @param {Function} customizer The function to customize assigned values.
|
||
| 13448 | * @returns {Object} Returns `object`.
|
||
| 13449 | * @example
|
||
| 13450 | *
|
||
| 13451 | * function customizer(objValue, srcValue) {
|
||
| 13452 | * if (_.isArray(objValue)) {
|
||
| 13453 | * return objValue.concat(srcValue);
|
||
| 13454 | * }
|
||
| 13455 | * }
|
||
| 13456 | *
|
||
| 13457 | * var object = { 'a': [1], 'b': [2] };
|
||
| 13458 | * var other = { 'a': [3], 'b': [4] };
|
||
| 13459 | *
|
||
| 13460 | * _.mergeWith(object, other, customizer);
|
||
| 13461 | * // => { 'a': [1, 3], 'b': [2, 4] }
|
||
| 13462 | */
|
||
| 13463 | var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { |
||
| 13464 | baseMerge(object, source, srcIndex, customizer); |
||
| 13465 | }); |
||
| 13466 | |||
| 13467 | /**
|
||
| 13468 | * The opposite of `_.pick`; this method creates an object composed of the
|
||
| 13469 | * own and inherited enumerable property paths of `object` that are not omitted.
|
||
| 13470 | *
|
||
| 13471 | * **Note:** This method is considerably slower than `_.pick`.
|
||
| 13472 | *
|
||
| 13473 | * @static
|
||
| 13474 | * @since 0.1.0
|
||
| 13475 | * @memberOf _
|
||
| 13476 | * @category Object
|
||
| 13477 | * @param {Object} object The source object.
|
||
| 13478 | * @param {...(string|string[])} [paths] The property paths to omit.
|
||
| 13479 | * @returns {Object} Returns the new object.
|
||
| 13480 | * @example
|
||
| 13481 | *
|
||
| 13482 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
||
| 13483 | *
|
||
| 13484 | * _.omit(object, ['a', 'c']);
|
||
| 13485 | * // => { 'b': '2' }
|
||
| 13486 | */
|
||
| 13487 | var omit = flatRest(function(object, paths) { |
||
| 13488 | var result = {};
|
||
| 13489 | if (object == null) { |
||
| 13490 | return result;
|
||
| 13491 | } |
||
| 13492 | var isDeep = false; |
||
| 13493 | paths = arrayMap(paths, function(path) {
|
||
| 13494 | path = castPath(path, object); |
||
| 13495 | isDeep || (isDeep = path.length > 1);
|
||
| 13496 | return path;
|
||
| 13497 | }); |
||
| 13498 | copyObject(object, getAllKeysIn(object), result); |
||
| 13499 | if (isDeep) {
|
||
| 13500 | result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone); |
||
| 13501 | } |
||
| 13502 | var length = paths.length;
|
||
| 13503 | while (length--) {
|
||
| 13504 | baseUnset(result, paths[length]); |
||
| 13505 | } |
||
| 13506 | return result;
|
||
| 13507 | }); |
||
| 13508 | |||
| 13509 | /**
|
||
| 13510 | * The opposite of `_.pickBy`; this method creates an object composed of
|
||
| 13511 | * the own and inherited enumerable string keyed properties of `object` that
|
||
| 13512 | * `predicate` doesn't return truthy for. The predicate is invoked with two
|
||
| 13513 | * arguments: (value, key).
|
||
| 13514 | *
|
||
| 13515 | * @static
|
||
| 13516 | * @memberOf _
|
||
| 13517 | * @since 4.0.0
|
||
| 13518 | * @category Object
|
||
| 13519 | * @param {Object} object The source object.
|
||
| 13520 | * @param {Function} [predicate=_.identity] The function invoked per property.
|
||
| 13521 | * @returns {Object} Returns the new object.
|
||
| 13522 | * @example
|
||
| 13523 | *
|
||
| 13524 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
||
| 13525 | *
|
||
| 13526 | * _.omitBy(object, _.isNumber);
|
||
| 13527 | * // => { 'b': '2' }
|
||
| 13528 | */
|
||
| 13529 | function omitBy(object, predicate) { |
||
| 13530 | return pickBy(object, negate(getIteratee(predicate)));
|
||
| 13531 | } |
||
| 13532 | |||
| 13533 | /**
|
||
| 13534 | * Creates an object composed of the picked `object` properties.
|
||
| 13535 | *
|
||
| 13536 | * @static
|
||
| 13537 | * @since 0.1.0
|
||
| 13538 | * @memberOf _
|
||
| 13539 | * @category Object
|
||
| 13540 | * @param {Object} object The source object.
|
||
| 13541 | * @param {...(string|string[])} [paths] The property paths to pick.
|
||
| 13542 | * @returns {Object} Returns the new object.
|
||
| 13543 | * @example
|
||
| 13544 | *
|
||
| 13545 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
||
| 13546 | *
|
||
| 13547 | * _.pick(object, ['a', 'c']);
|
||
| 13548 | * // => { 'a': 1, 'c': 3 }
|
||
| 13549 | */
|
||
| 13550 | var pick = flatRest(function(object, paths) { |
||
| 13551 | return object == null ? {} : basePick(object, paths); |
||
| 13552 | }); |
||
| 13553 | |||
| 13554 | /**
|
||
| 13555 | * Creates an object composed of the `object` properties `predicate` returns
|
||
| 13556 | * truthy for. The predicate is invoked with two arguments: (value, key).
|
||
| 13557 | *
|
||
| 13558 | * @static
|
||
| 13559 | * @memberOf _
|
||
| 13560 | * @since 4.0.0
|
||
| 13561 | * @category Object
|
||
| 13562 | * @param {Object} object The source object.
|
||
| 13563 | * @param {Function} [predicate=_.identity] The function invoked per property.
|
||
| 13564 | * @returns {Object} Returns the new object.
|
||
| 13565 | * @example
|
||
| 13566 | *
|
||
| 13567 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
||
| 13568 | *
|
||
| 13569 | * _.pickBy(object, _.isNumber);
|
||
| 13570 | * // => { 'a': 1, 'c': 3 }
|
||
| 13571 | */
|
||
| 13572 | function pickBy(object, predicate) { |
||
| 13573 | if (object == null) { |
||
| 13574 | return {};
|
||
| 13575 | } |
||
| 13576 | var props = arrayMap(getAllKeysIn(object), function(prop) { |
||
| 13577 | return [prop];
|
||
| 13578 | }); |
||
| 13579 | predicate = getIteratee(predicate); |
||
| 13580 | return basePickBy(object, props, function(value, path) { |
||
| 13581 | return predicate(value, path[0]); |
||
| 13582 | }); |
||
| 13583 | } |
||
| 13584 | |||
| 13585 | /**
|
||
| 13586 | * This method is like `_.get` except that if the resolved value is a
|
||
| 13587 | * function it's invoked with the `this` binding of its parent object and
|
||
| 13588 | * its result is returned.
|
||
| 13589 | *
|
||
| 13590 | * @static
|
||
| 13591 | * @since 0.1.0
|
||
| 13592 | * @memberOf _
|
||
| 13593 | * @category Object
|
||
| 13594 | * @param {Object} object The object to query.
|
||
| 13595 | * @param {Array|string} path The path of the property to resolve.
|
||
| 13596 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
||
| 13597 | * @returns {*} Returns the resolved value.
|
||
| 13598 | * @example
|
||
| 13599 | *
|
||
| 13600 | * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
|
||
| 13601 | *
|
||
| 13602 | * _.result(object, 'a[0].b.c1');
|
||
| 13603 | * // => 3
|
||
| 13604 | *
|
||
| 13605 | * _.result(object, 'a[0].b.c2');
|
||
| 13606 | * // => 4
|
||
| 13607 | *
|
||
| 13608 | * _.result(object, 'a[0].b.c3', 'default');
|
||
| 13609 | * // => 'default'
|
||
| 13610 | *
|
||
| 13611 | * _.result(object, 'a[0].b.c3', _.constant('default'));
|
||
| 13612 | * // => 'default'
|
||
| 13613 | */
|
||
| 13614 | function result(object, path, defaultValue) { |
||
| 13615 | path = castPath(path, object); |
||
| 13616 | |||
| 13617 | var index = -1, |
||
| 13618 | length = path.length; |
||
| 13619 | |||
| 13620 | // Ensure the loop is entered when path is empty.
|
||
| 13621 | if (!length) {
|
||
| 13622 | length = 1;
|
||
| 13623 | object = undefined;
|
||
| 13624 | } |
||
| 13625 | while (++index < length) {
|
||
| 13626 | var value = object == null ? undefined : object[toKey(path[index])]; |
||
| 13627 | if (value === undefined) { |
||
| 13628 | index = length; |
||
| 13629 | value = defaultValue; |
||
| 13630 | } |
||
| 13631 | object = isFunction(value) ? value.call(object) : value; |
||
| 13632 | } |
||
| 13633 | return object;
|
||
| 13634 | } |
||
| 13635 | |||
| 13636 | /**
|
||
| 13637 | * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
|
||
| 13638 | * it's created. Arrays are created for missing index properties while objects
|
||
| 13639 | * are created for all other missing properties. Use `_.setWith` to customize
|
||
| 13640 | * `path` creation.
|
||
| 13641 | *
|
||
| 13642 | * **Note:** This method mutates `object`.
|
||
| 13643 | *
|
||
| 13644 | * @static
|
||
| 13645 | * @memberOf _
|
||
| 13646 | * @since 3.7.0
|
||
| 13647 | * @category Object
|
||
| 13648 | * @param {Object} object The object to modify.
|
||
| 13649 | * @param {Array|string} path The path of the property to set.
|
||
| 13650 | * @param {*} value The value to set.
|
||
| 13651 | * @returns {Object} Returns `object`.
|
||
| 13652 | * @example
|
||
| 13653 | *
|
||
| 13654 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
||
| 13655 | *
|
||
| 13656 | * _.set(object, 'a[0].b.c', 4);
|
||
| 13657 | * console.log(object.a[0].b.c);
|
||
| 13658 | * // => 4
|
||
| 13659 | *
|
||
| 13660 | * _.set(object, ['x', '0', 'y', 'z'], 5);
|
||
| 13661 | * console.log(object.x[0].y.z);
|
||
| 13662 | * // => 5
|
||
| 13663 | */
|
||
| 13664 | function set(object, path, value) { |
||
| 13665 | return object == null ? object : baseSet(object, path, value); |
||
| 13666 | } |
||
| 13667 | |||
| 13668 | /**
|
||
| 13669 | * This method is like `_.set` except that it accepts `customizer` which is
|
||
| 13670 | * invoked to produce the objects of `path`. If `customizer` returns `undefined`
|
||
| 13671 | * path creation is handled by the method instead. The `customizer` is invoked
|
||
| 13672 | * with three arguments: (nsValue, key, nsObject).
|
||
| 13673 | *
|
||
| 13674 | * **Note:** This method mutates `object`.
|
||
| 13675 | *
|
||
| 13676 | * @static
|
||
| 13677 | * @memberOf _
|
||
| 13678 | * @since 4.0.0
|
||
| 13679 | * @category Object
|
||
| 13680 | * @param {Object} object The object to modify.
|
||
| 13681 | * @param {Array|string} path The path of the property to set.
|
||
| 13682 | * @param {*} value The value to set.
|
||
| 13683 | * @param {Function} [customizer] The function to customize assigned values.
|
||
| 13684 | * @returns {Object} Returns `object`.
|
||
| 13685 | * @example
|
||
| 13686 | *
|
||
| 13687 | * var object = {};
|
||
| 13688 | *
|
||
| 13689 | * _.setWith(object, '[0][1]', 'a', Object);
|
||
| 13690 | * // => { '0': { '1': 'a' } }
|
||
| 13691 | */
|
||
| 13692 | function setWith(object, path, value, customizer) { |
||
| 13693 | customizer = typeof customizer == 'function' ? customizer : undefined; |
||
| 13694 | return object == null ? object : baseSet(object, path, value, customizer); |
||
| 13695 | } |
||
| 13696 | |||
| 13697 | /**
|
||
| 13698 | * Creates an array of own enumerable string keyed-value pairs for `object`
|
||
| 13699 | * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
|
||
| 13700 | * entries are returned.
|
||
| 13701 | *
|
||
| 13702 | * @static
|
||
| 13703 | * @memberOf _
|
||
| 13704 | * @since 4.0.0
|
||
| 13705 | * @alias entries
|
||
| 13706 | * @category Object
|
||
| 13707 | * @param {Object} object The object to query.
|
||
| 13708 | * @returns {Array} Returns the key-value pairs.
|
||
| 13709 | * @example
|
||
| 13710 | *
|
||
| 13711 | * function Foo() {
|
||
| 13712 | * this.a = 1;
|
||
| 13713 | * this.b = 2;
|
||
| 13714 | * }
|
||
| 13715 | *
|
||
| 13716 | * Foo.prototype.c = 3;
|
||
| 13717 | *
|
||
| 13718 | * _.toPairs(new Foo);
|
||
| 13719 | * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
|
||
| 13720 | */
|
||
| 13721 | var toPairs = createToPairs(keys);
|
||
| 13722 | |||
| 13723 | /**
|
||
| 13724 | * Creates an array of own and inherited enumerable string keyed-value pairs
|
||
| 13725 | * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
|
||
| 13726 | * or set, its entries are returned.
|
||
| 13727 | *
|
||
| 13728 | * @static
|
||
| 13729 | * @memberOf _
|
||
| 13730 | * @since 4.0.0
|
||
| 13731 | * @alias entriesIn
|
||
| 13732 | * @category Object
|
||
| 13733 | * @param {Object} object The object to query.
|
||
| 13734 | * @returns {Array} Returns the key-value pairs.
|
||
| 13735 | * @example
|
||
| 13736 | *
|
||
| 13737 | * function Foo() {
|
||
| 13738 | * this.a = 1;
|
||
| 13739 | * this.b = 2;
|
||
| 13740 | * }
|
||
| 13741 | *
|
||
| 13742 | * Foo.prototype.c = 3;
|
||
| 13743 | *
|
||
| 13744 | * _.toPairsIn(new Foo);
|
||
| 13745 | * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
|
||
| 13746 | */
|
||
| 13747 | var toPairsIn = createToPairs(keysIn);
|
||
| 13748 | |||
| 13749 | /**
|
||
| 13750 | * An alternative to `_.reduce`; this method transforms `object` to a new
|
||
| 13751 | * `accumulator` object which is the result of running each of its own
|
||
| 13752 | * enumerable string keyed properties thru `iteratee`, with each invocation
|
||
| 13753 | * potentially mutating the `accumulator` object. If `accumulator` is not
|
||
| 13754 | * provided, a new object with the same `[[Prototype]]` will be used. The
|
||
| 13755 | * iteratee is invoked with four arguments: (accumulator, value, key, object).
|
||
| 13756 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
||
| 13757 | *
|
||
| 13758 | * @static
|
||
| 13759 | * @memberOf _
|
||
| 13760 | * @since 1.3.0
|
||
| 13761 | * @category Object
|
||
| 13762 | * @param {Object} object The object to iterate over.
|
||
| 13763 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 13764 | * @param {*} [accumulator] The custom accumulator value.
|
||
| 13765 | * @returns {*} Returns the accumulated value.
|
||
| 13766 | * @example
|
||
| 13767 | *
|
||
| 13768 | * _.transform([2, 3, 4], function(result, n) {
|
||
| 13769 | * result.push(n *= n);
|
||
| 13770 | * return n % 2 == 0;
|
||
| 13771 | * }, []);
|
||
| 13772 | * // => [4, 9]
|
||
| 13773 | *
|
||
| 13774 | * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
||
| 13775 | * (result[value] || (result[value] = [])).push(key);
|
||
| 13776 | * }, {});
|
||
| 13777 | * // => { '1': ['a', 'c'], '2': ['b'] }
|
||
| 13778 | */
|
||
| 13779 | function transform(object, iteratee, accumulator) { |
||
| 13780 | var isArr = isArray(object),
|
||
| 13781 | isArrLike = isArr || isBuffer(object) || isTypedArray(object); |
||
| 13782 | |||
| 13783 | iteratee = getIteratee(iteratee, 4);
|
||
| 13784 | if (accumulator == null) { |
||
| 13785 | var Ctor = object && object.constructor;
|
||
| 13786 | if (isArrLike) {
|
||
| 13787 | accumulator = isArr ? new Ctor : [];
|
||
| 13788 | } |
||
| 13789 | else if (isObject(object)) { |
||
| 13790 | accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
|
||
| 13791 | } |
||
| 13792 | else {
|
||
| 13793 | accumulator = {};
|
||
| 13794 | } |
||
| 13795 | } |
||
| 13796 | (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
|
||
| 13797 | return iteratee(accumulator, value, index, object);
|
||
| 13798 | }); |
||
| 13799 | return accumulator;
|
||
| 13800 | } |
||
| 13801 | |||
| 13802 | /**
|
||
| 13803 | * Removes the property at `path` of `object`.
|
||
| 13804 | *
|
||
| 13805 | * **Note:** This method mutates `object`.
|
||
| 13806 | *
|
||
| 13807 | * @static
|
||
| 13808 | * @memberOf _
|
||
| 13809 | * @since 4.0.0
|
||
| 13810 | * @category Object
|
||
| 13811 | * @param {Object} object The object to modify.
|
||
| 13812 | * @param {Array|string} path The path of the property to unset.
|
||
| 13813 | * @returns {boolean} Returns `true` if the property is deleted, else `false`.
|
||
| 13814 | * @example
|
||
| 13815 | *
|
||
| 13816 | * var object = { 'a': [{ 'b': { 'c': 7 } }] };
|
||
| 13817 | * _.unset(object, 'a[0].b.c');
|
||
| 13818 | * // => true
|
||
| 13819 | *
|
||
| 13820 | * console.log(object);
|
||
| 13821 | * // => { 'a': [{ 'b': {} }] };
|
||
| 13822 | *
|
||
| 13823 | * _.unset(object, ['a', '0', 'b', 'c']);
|
||
| 13824 | * // => true
|
||
| 13825 | *
|
||
| 13826 | * console.log(object);
|
||
| 13827 | * // => { 'a': [{ 'b': {} }] };
|
||
| 13828 | */
|
||
| 13829 | function unset(object, path) { |
||
| 13830 | return object == null ? true : baseUnset(object, path); |
||
| 13831 | } |
||
| 13832 | |||
| 13833 | /**
|
||
| 13834 | * This method is like `_.set` except that accepts `updater` to produce the
|
||
| 13835 | * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
|
||
| 13836 | * is invoked with one argument: (value).
|
||
| 13837 | *
|
||
| 13838 | * **Note:** This method mutates `object`.
|
||
| 13839 | *
|
||
| 13840 | * @static
|
||
| 13841 | * @memberOf _
|
||
| 13842 | * @since 4.6.0
|
||
| 13843 | * @category Object
|
||
| 13844 | * @param {Object} object The object to modify.
|
||
| 13845 | * @param {Array|string} path The path of the property to set.
|
||
| 13846 | * @param {Function} updater The function to produce the updated value.
|
||
| 13847 | * @returns {Object} Returns `object`.
|
||
| 13848 | * @example
|
||
| 13849 | *
|
||
| 13850 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
||
| 13851 | *
|
||
| 13852 | * _.update(object, 'a[0].b.c', function(n) { return n * n; });
|
||
| 13853 | * console.log(object.a[0].b.c);
|
||
| 13854 | * // => 9
|
||
| 13855 | *
|
||
| 13856 | * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
|
||
| 13857 | * console.log(object.x[0].y.z);
|
||
| 13858 | * // => 0
|
||
| 13859 | */
|
||
| 13860 | function update(object, path, updater) { |
||
| 13861 | return object == null ? object : baseUpdate(object, path, castFunction(updater)); |
||
| 13862 | } |
||
| 13863 | |||
| 13864 | /**
|
||
| 13865 | * This method is like `_.update` except that it accepts `customizer` which is
|
||
| 13866 | * invoked to produce the objects of `path`. If `customizer` returns `undefined`
|
||
| 13867 | * path creation is handled by the method instead. The `customizer` is invoked
|
||
| 13868 | * with three arguments: (nsValue, key, nsObject).
|
||
| 13869 | *
|
||
| 13870 | * **Note:** This method mutates `object`.
|
||
| 13871 | *
|
||
| 13872 | * @static
|
||
| 13873 | * @memberOf _
|
||
| 13874 | * @since 4.6.0
|
||
| 13875 | * @category Object
|
||
| 13876 | * @param {Object} object The object to modify.
|
||
| 13877 | * @param {Array|string} path The path of the property to set.
|
||
| 13878 | * @param {Function} updater The function to produce the updated value.
|
||
| 13879 | * @param {Function} [customizer] The function to customize assigned values.
|
||
| 13880 | * @returns {Object} Returns `object`.
|
||
| 13881 | * @example
|
||
| 13882 | *
|
||
| 13883 | * var object = {};
|
||
| 13884 | *
|
||
| 13885 | * _.updateWith(object, '[0][1]', _.constant('a'), Object);
|
||
| 13886 | * // => { '0': { '1': 'a' } }
|
||
| 13887 | */
|
||
| 13888 | function updateWith(object, path, updater, customizer) { |
||
| 13889 | customizer = typeof customizer == 'function' ? customizer : undefined; |
||
| 13890 | return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer); |
||
| 13891 | } |
||
| 13892 | |||
| 13893 | /**
|
||
| 13894 | * Creates an array of the own enumerable string keyed property values of `object`.
|
||
| 13895 | *
|
||
| 13896 | * **Note:** Non-object values are coerced to objects.
|
||
| 13897 | *
|
||
| 13898 | * @static
|
||
| 13899 | * @since 0.1.0
|
||
| 13900 | * @memberOf _
|
||
| 13901 | * @category Object
|
||
| 13902 | * @param {Object} object The object to query.
|
||
| 13903 | * @returns {Array} Returns the array of property values.
|
||
| 13904 | * @example
|
||
| 13905 | *
|
||
| 13906 | * function Foo() {
|
||
| 13907 | * this.a = 1;
|
||
| 13908 | * this.b = 2;
|
||
| 13909 | * }
|
||
| 13910 | *
|
||
| 13911 | * Foo.prototype.c = 3;
|
||
| 13912 | *
|
||
| 13913 | * _.values(new Foo);
|
||
| 13914 | * // => [1, 2] (iteration order is not guaranteed)
|
||
| 13915 | *
|
||
| 13916 | * _.values('hi');
|
||
| 13917 | * // => ['h', 'i']
|
||
| 13918 | */
|
||
| 13919 | function values(object) { |
||
| 13920 | return object == null ? [] : baseValues(object, keys(object)); |
||
| 13921 | } |
||
| 13922 | |||
| 13923 | /**
|
||
| 13924 | * Creates an array of the own and inherited enumerable string keyed property
|
||
| 13925 | * values of `object`.
|
||
| 13926 | *
|
||
| 13927 | * **Note:** Non-object values are coerced to objects.
|
||
| 13928 | *
|
||
| 13929 | * @static
|
||
| 13930 | * @memberOf _
|
||
| 13931 | * @since 3.0.0
|
||
| 13932 | * @category Object
|
||
| 13933 | * @param {Object} object The object to query.
|
||
| 13934 | * @returns {Array} Returns the array of property values.
|
||
| 13935 | * @example
|
||
| 13936 | *
|
||
| 13937 | * function Foo() {
|
||
| 13938 | * this.a = 1;
|
||
| 13939 | * this.b = 2;
|
||
| 13940 | * }
|
||
| 13941 | *
|
||
| 13942 | * Foo.prototype.c = 3;
|
||
| 13943 | *
|
||
| 13944 | * _.valuesIn(new Foo);
|
||
| 13945 | * // => [1, 2, 3] (iteration order is not guaranteed)
|
||
| 13946 | */
|
||
| 13947 | function valuesIn(object) { |
||
| 13948 | return object == null ? [] : baseValues(object, keysIn(object)); |
||
| 13949 | } |
||
| 13950 | |||
| 13951 | /*------------------------------------------------------------------------*/
|
||
| 13952 | |||
| 13953 | /**
|
||
| 13954 | * Clamps `number` within the inclusive `lower` and `upper` bounds.
|
||
| 13955 | *
|
||
| 13956 | * @static
|
||
| 13957 | * @memberOf _
|
||
| 13958 | * @since 4.0.0
|
||
| 13959 | * @category Number
|
||
| 13960 | * @param {number} number The number to clamp.
|
||
| 13961 | * @param {number} [lower] The lower bound.
|
||
| 13962 | * @param {number} upper The upper bound.
|
||
| 13963 | * @returns {number} Returns the clamped number.
|
||
| 13964 | * @example
|
||
| 13965 | *
|
||
| 13966 | * _.clamp(-10, -5, 5);
|
||
| 13967 | * // => -5
|
||
| 13968 | *
|
||
| 13969 | * _.clamp(10, -5, 5);
|
||
| 13970 | * // => 5
|
||
| 13971 | */
|
||
| 13972 | function clamp(number, lower, upper) { |
||
| 13973 | if (upper === undefined) { |
||
| 13974 | upper = lower; |
||
| 13975 | lower = undefined;
|
||
| 13976 | } |
||
| 13977 | if (upper !== undefined) { |
||
| 13978 | upper = toNumber(upper); |
||
| 13979 | upper = upper === upper ? upper : 0;
|
||
| 13980 | } |
||
| 13981 | if (lower !== undefined) { |
||
| 13982 | lower = toNumber(lower); |
||
| 13983 | lower = lower === lower ? lower : 0;
|
||
| 13984 | } |
||
| 13985 | return baseClamp(toNumber(number), lower, upper);
|
||
| 13986 | } |
||
| 13987 | |||
| 13988 | /**
|
||
| 13989 | * Checks if `n` is between `start` and up to, but not including, `end`. If
|
||
| 13990 | * `end` is not specified, it's set to `start` with `start` then set to `0`.
|
||
| 13991 | * If `start` is greater than `end` the params are swapped to support
|
||
| 13992 | * negative ranges.
|
||
| 13993 | *
|
||
| 13994 | * @static
|
||
| 13995 | * @memberOf _
|
||
| 13996 | * @since 3.3.0
|
||
| 13997 | * @category Number
|
||
| 13998 | * @param {number} number The number to check.
|
||
| 13999 | * @param {number} [start=0] The start of the range.
|
||
| 14000 | * @param {number} end The end of the range.
|
||
| 14001 | * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
|
||
| 14002 | * @see _.range, _.rangeRight
|
||
| 14003 | * @example
|
||
| 14004 | *
|
||
| 14005 | * _.inRange(3, 2, 4);
|
||
| 14006 | * // => true
|
||
| 14007 | *
|
||
| 14008 | * _.inRange(4, 8);
|
||
| 14009 | * // => true
|
||
| 14010 | *
|
||
| 14011 | * _.inRange(4, 2);
|
||
| 14012 | * // => false
|
||
| 14013 | *
|
||
| 14014 | * _.inRange(2, 2);
|
||
| 14015 | * // => false
|
||
| 14016 | *
|
||
| 14017 | * _.inRange(1.2, 2);
|
||
| 14018 | * // => true
|
||
| 14019 | *
|
||
| 14020 | * _.inRange(5.2, 4);
|
||
| 14021 | * // => false
|
||
| 14022 | *
|
||
| 14023 | * _.inRange(-3, -2, -6);
|
||
| 14024 | * // => true
|
||
| 14025 | */
|
||
| 14026 | function inRange(number, start, end) { |
||
| 14027 | start = toFinite(start); |
||
| 14028 | if (end === undefined) { |
||
| 14029 | end = start; |
||
| 14030 | start = 0;
|
||
| 14031 | } else {
|
||
| 14032 | end = toFinite(end); |
||
| 14033 | } |
||
| 14034 | number = toNumber(number); |
||
| 14035 | return baseInRange(number, start, end);
|
||
| 14036 | } |
||
| 14037 | |||
| 14038 | /**
|
||
| 14039 | * Produces a random number between the inclusive `lower` and `upper` bounds.
|
||
| 14040 | * If only one argument is provided a number between `0` and the given number
|
||
| 14041 | * is returned. If `floating` is `true`, or either `lower` or `upper` are
|
||
| 14042 | * floats, a floating-point number is returned instead of an integer.
|
||
| 14043 | *
|
||
| 14044 | * **Note:** JavaScript follows the IEEE-754 standard for resolving
|
||
| 14045 | * floating-point values which can produce unexpected results.
|
||
| 14046 | *
|
||
| 14047 | * @static
|
||
| 14048 | * @memberOf _
|
||
| 14049 | * @since 0.7.0
|
||
| 14050 | * @category Number
|
||
| 14051 | * @param {number} [lower=0] The lower bound.
|
||
| 14052 | * @param {number} [upper=1] The upper bound.
|
||
| 14053 | * @param {boolean} [floating] Specify returning a floating-point number.
|
||
| 14054 | * @returns {number} Returns the random number.
|
||
| 14055 | * @example
|
||
| 14056 | *
|
||
| 14057 | * _.random(0, 5);
|
||
| 14058 | * // => an integer between 0 and 5
|
||
| 14059 | *
|
||
| 14060 | * _.random(5);
|
||
| 14061 | * // => also an integer between 0 and 5
|
||
| 14062 | *
|
||
| 14063 | * _.random(5, true);
|
||
| 14064 | * // => a floating-point number between 0 and 5
|
||
| 14065 | *
|
||
| 14066 | * _.random(1.2, 5.2);
|
||
| 14067 | * // => a floating-point number between 1.2 and 5.2
|
||
| 14068 | */
|
||
| 14069 | function random(lower, upper, floating) { |
||
| 14070 | if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) { |
||
| 14071 | upper = floating = undefined;
|
||
| 14072 | } |
||
| 14073 | if (floating === undefined) { |
||
| 14074 | if (typeof upper == 'boolean') { |
||
| 14075 | floating = upper; |
||
| 14076 | upper = undefined;
|
||
| 14077 | } |
||
| 14078 | else if (typeof lower == 'boolean') { |
||
| 14079 | floating = lower; |
||
| 14080 | lower = undefined;
|
||
| 14081 | } |
||
| 14082 | } |
||
| 14083 | if (lower === undefined && upper === undefined) { |
||
| 14084 | lower = 0;
|
||
| 14085 | upper = 1;
|
||
| 14086 | } |
||
| 14087 | else {
|
||
| 14088 | lower = toFinite(lower); |
||
| 14089 | if (upper === undefined) { |
||
| 14090 | upper = lower; |
||
| 14091 | lower = 0;
|
||
| 14092 | } else {
|
||
| 14093 | upper = toFinite(upper); |
||
| 14094 | } |
||
| 14095 | } |
||
| 14096 | if (lower > upper) {
|
||
| 14097 | var temp = lower;
|
||
| 14098 | lower = upper; |
||
| 14099 | upper = temp; |
||
| 14100 | } |
||
| 14101 | if (floating || lower % 1 || upper % 1) { |
||
| 14102 | var rand = nativeRandom();
|
||
| 14103 | return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper); |
||
| 14104 | } |
||
| 14105 | return baseRandom(lower, upper);
|
||
| 14106 | } |
||
| 14107 | |||
| 14108 | /*------------------------------------------------------------------------*/
|
||
| 14109 | |||
| 14110 | /**
|
||
| 14111 | * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
|
||
| 14112 | *
|
||
| 14113 | * @static
|
||
| 14114 | * @memberOf _
|
||
| 14115 | * @since 3.0.0
|
||
| 14116 | * @category String
|
||
| 14117 | * @param {string} [string=''] The string to convert.
|
||
| 14118 | * @returns {string} Returns the camel cased string.
|
||
| 14119 | * @example
|
||
| 14120 | *
|
||
| 14121 | * _.camelCase('Foo Bar');
|
||
| 14122 | * // => 'fooBar'
|
||
| 14123 | *
|
||
| 14124 | * _.camelCase('--foo-bar--');
|
||
| 14125 | * // => 'fooBar'
|
||
| 14126 | *
|
||
| 14127 | * _.camelCase('__FOO_BAR__');
|
||
| 14128 | * // => 'fooBar'
|
||
| 14129 | */
|
||
| 14130 | var camelCase = createCompounder(function(result, word, index) { |
||
| 14131 | word = word.toLowerCase(); |
||
| 14132 | return result + (index ? capitalize(word) : word);
|
||
| 14133 | }); |
||
| 14134 | |||
| 14135 | /**
|
||
| 14136 | * Converts the first character of `string` to upper case and the remaining
|
||
| 14137 | * to lower case.
|
||
| 14138 | *
|
||
| 14139 | * @static
|
||
| 14140 | * @memberOf _
|
||
| 14141 | * @since 3.0.0
|
||
| 14142 | * @category String
|
||
| 14143 | * @param {string} [string=''] The string to capitalize.
|
||
| 14144 | * @returns {string} Returns the capitalized string.
|
||
| 14145 | * @example
|
||
| 14146 | *
|
||
| 14147 | * _.capitalize('FRED');
|
||
| 14148 | * // => 'Fred'
|
||
| 14149 | */
|
||
| 14150 | function capitalize(string) { |
||
| 14151 | return upperFirst(toString(string).toLowerCase());
|
||
| 14152 | } |
||
| 14153 | |||
| 14154 | /**
|
||
| 14155 | * Deburrs `string` by converting
|
||
| 14156 | * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
||
| 14157 | * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
|
||
| 14158 | * letters to basic Latin letters and removing
|
||
| 14159 | * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
||
| 14160 | *
|
||
| 14161 | * @static
|
||
| 14162 | * @memberOf _
|
||
| 14163 | * @since 3.0.0
|
||
| 14164 | * @category String
|
||
| 14165 | * @param {string} [string=''] The string to deburr.
|
||
| 14166 | * @returns {string} Returns the deburred string.
|
||
| 14167 | * @example
|
||
| 14168 | *
|
||
| 14169 | * _.deburr('déjà vu');
|
||
| 14170 | * // => 'deja vu'
|
||
| 14171 | */
|
||
| 14172 | function deburr(string) { |
||
| 14173 | string = toString(string); |
||
| 14174 | return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); |
||
| 14175 | } |
||
| 14176 | |||
| 14177 | /**
|
||
| 14178 | * Checks if `string` ends with the given target string.
|
||
| 14179 | *
|
||
| 14180 | * @static
|
||
| 14181 | * @memberOf _
|
||
| 14182 | * @since 3.0.0
|
||
| 14183 | * @category String
|
||
| 14184 | * @param {string} [string=''] The string to inspect.
|
||
| 14185 | * @param {string} [target] The string to search for.
|
||
| 14186 | * @param {number} [position=string.length] The position to search up to.
|
||
| 14187 | * @returns {boolean} Returns `true` if `string` ends with `target`,
|
||
| 14188 | * else `false`.
|
||
| 14189 | * @example
|
||
| 14190 | *
|
||
| 14191 | * _.endsWith('abc', 'c');
|
||
| 14192 | * // => true
|
||
| 14193 | *
|
||
| 14194 | * _.endsWith('abc', 'b');
|
||
| 14195 | * // => false
|
||
| 14196 | *
|
||
| 14197 | * _.endsWith('abc', 'b', 2);
|
||
| 14198 | * // => true
|
||
| 14199 | */
|
||
| 14200 | function endsWith(string, target, position) { |
||
| 14201 | string = toString(string); |
||
| 14202 | target = baseToString(target); |
||
| 14203 | |||
| 14204 | var length = string.length;
|
||
| 14205 | position = position === undefined
|
||
| 14206 | ? length |
||
| 14207 | : baseClamp(toInteger(position), 0, length);
|
||
| 14208 | |||
| 14209 | var end = position;
|
||
| 14210 | position -= target.length; |
||
| 14211 | return position >= 0 && string.slice(position, end) == target; |
||
| 14212 | } |
||
| 14213 | |||
| 14214 | /**
|
||
| 14215 | * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
|
||
| 14216 | * corresponding HTML entities.
|
||
| 14217 | *
|
||
| 14218 | * **Note:** No other characters are escaped. To escape additional
|
||
| 14219 | * characters use a third-party library like [_he_](https://mths.be/he).
|
||
| 14220 | *
|
||
| 14221 | * Though the ">" character is escaped for symmetry, characters like
|
||
| 14222 | * ">" and "/" don't need escaping in HTML and have no special meaning
|
||
| 14223 | * unless they're part of a tag or unquoted attribute value. See
|
||
| 14224 | * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
|
||
| 14225 | * (under "semi-related fun fact") for more details.
|
||
| 14226 | *
|
||
| 14227 | * When working with HTML you should always
|
||
| 14228 | * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
|
||
| 14229 | * XSS vectors.
|
||
| 14230 | *
|
||
| 14231 | * @static
|
||
| 14232 | * @since 0.1.0
|
||
| 14233 | * @memberOf _
|
||
| 14234 | * @category String
|
||
| 14235 | * @param {string} [string=''] The string to escape.
|
||
| 14236 | * @returns {string} Returns the escaped string.
|
||
| 14237 | * @example
|
||
| 14238 | *
|
||
| 14239 | * _.escape('fred, barney, & pebbles');
|
||
| 14240 | * // => 'fred, barney, & pebbles'
|
||
| 14241 | */
|
||
| 14242 | function escape(string) { |
||
| 14243 | string = toString(string); |
||
| 14244 | return (string && reHasUnescapedHtml.test(string))
|
||
| 14245 | ? string.replace(reUnescapedHtml, escapeHtmlChar) |
||
| 14246 | : string; |
||
| 14247 | } |
||
| 14248 | |||
| 14249 | /**
|
||
| 14250 | * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
|
||
| 14251 | * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
|
||
| 14252 | *
|
||
| 14253 | * @static
|
||
| 14254 | * @memberOf _
|
||
| 14255 | * @since 3.0.0
|
||
| 14256 | * @category String
|
||
| 14257 | * @param {string} [string=''] The string to escape.
|
||
| 14258 | * @returns {string} Returns the escaped string.
|
||
| 14259 | * @example
|
||
| 14260 | *
|
||
| 14261 | * _.escapeRegExp('[lodash](https://lodash.com/)');
|
||
| 14262 | * // => '\[lodash\]\(https://lodash\.com/\)'
|
||
| 14263 | */
|
||
| 14264 | function escapeRegExp(string) { |
||
| 14265 | string = toString(string); |
||
| 14266 | return (string && reHasRegExpChar.test(string))
|
||
| 14267 | ? string.replace(reRegExpChar, '\\$&')
|
||
| 14268 | : string; |
||
| 14269 | } |
||
| 14270 | |||
| 14271 | /**
|
||
| 14272 | * Converts `string` to
|
||
| 14273 | * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
|
||
| 14274 | *
|
||
| 14275 | * @static
|
||
| 14276 | * @memberOf _
|
||
| 14277 | * @since 3.0.0
|
||
| 14278 | * @category String
|
||
| 14279 | * @param {string} [string=''] The string to convert.
|
||
| 14280 | * @returns {string} Returns the kebab cased string.
|
||
| 14281 | * @example
|
||
| 14282 | *
|
||
| 14283 | * _.kebabCase('Foo Bar');
|
||
| 14284 | * // => 'foo-bar'
|
||
| 14285 | *
|
||
| 14286 | * _.kebabCase('fooBar');
|
||
| 14287 | * // => 'foo-bar'
|
||
| 14288 | *
|
||
| 14289 | * _.kebabCase('__FOO_BAR__');
|
||
| 14290 | * // => 'foo-bar'
|
||
| 14291 | */
|
||
| 14292 | var kebabCase = createCompounder(function(result, word, index) { |
||
| 14293 | return result + (index ? '-' : '') + word.toLowerCase(); |
||
| 14294 | }); |
||
| 14295 | |||
| 14296 | /**
|
||
| 14297 | * Converts `string`, as space separated words, to lower case.
|
||
| 14298 | *
|
||
| 14299 | * @static
|
||
| 14300 | * @memberOf _
|
||
| 14301 | * @since 4.0.0
|
||
| 14302 | * @category String
|
||
| 14303 | * @param {string} [string=''] The string to convert.
|
||
| 14304 | * @returns {string} Returns the lower cased string.
|
||
| 14305 | * @example
|
||
| 14306 | *
|
||
| 14307 | * _.lowerCase('--Foo-Bar--');
|
||
| 14308 | * // => 'foo bar'
|
||
| 14309 | *
|
||
| 14310 | * _.lowerCase('fooBar');
|
||
| 14311 | * // => 'foo bar'
|
||
| 14312 | *
|
||
| 14313 | * _.lowerCase('__FOO_BAR__');
|
||
| 14314 | * // => 'foo bar'
|
||
| 14315 | */
|
||
| 14316 | var lowerCase = createCompounder(function(result, word, index) { |
||
| 14317 | return result + (index ? ' ' : '') + word.toLowerCase(); |
||
| 14318 | }); |
||
| 14319 | |||
| 14320 | /**
|
||
| 14321 | * Converts the first character of `string` to lower case.
|
||
| 14322 | *
|
||
| 14323 | * @static
|
||
| 14324 | * @memberOf _
|
||
| 14325 | * @since 4.0.0
|
||
| 14326 | * @category String
|
||
| 14327 | * @param {string} [string=''] The string to convert.
|
||
| 14328 | * @returns {string} Returns the converted string.
|
||
| 14329 | * @example
|
||
| 14330 | *
|
||
| 14331 | * _.lowerFirst('Fred');
|
||
| 14332 | * // => 'fred'
|
||
| 14333 | *
|
||
| 14334 | * _.lowerFirst('FRED');
|
||
| 14335 | * // => 'fRED'
|
||
| 14336 | */
|
||
| 14337 | var lowerFirst = createCaseFirst('toLowerCase'); |
||
| 14338 | |||
| 14339 | /**
|
||
| 14340 | * Pads `string` on the left and right sides if it's shorter than `length`.
|
||
| 14341 | * Padding characters are truncated if they can't be evenly divided by `length`.
|
||
| 14342 | *
|
||
| 14343 | * @static
|
||
| 14344 | * @memberOf _
|
||
| 14345 | * @since 3.0.0
|
||
| 14346 | * @category String
|
||
| 14347 | * @param {string} [string=''] The string to pad.
|
||
| 14348 | * @param {number} [length=0] The padding length.
|
||
| 14349 | * @param {string} [chars=' '] The string used as padding.
|
||
| 14350 | * @returns {string} Returns the padded string.
|
||
| 14351 | * @example
|
||
| 14352 | *
|
||
| 14353 | * _.pad('abc', 8);
|
||
| 14354 | * // => ' abc '
|
||
| 14355 | *
|
||
| 14356 | * _.pad('abc', 8, '_-');
|
||
| 14357 | * // => '_-abc_-_'
|
||
| 14358 | *
|
||
| 14359 | * _.pad('abc', 3);
|
||
| 14360 | * // => 'abc'
|
||
| 14361 | */
|
||
| 14362 | function pad(string, length, chars) { |
||
| 14363 | string = toString(string); |
||
| 14364 | length = toInteger(length); |
||
| 14365 | |||
| 14366 | var strLength = length ? stringSize(string) : 0; |
||
| 14367 | if (!length || strLength >= length) {
|
||
| 14368 | return string;
|
||
| 14369 | } |
||
| 14370 | var mid = (length - strLength) / 2; |
||
| 14371 | return (
|
||
| 14372 | createPadding(nativeFloor(mid), chars) + |
||
| 14373 | string + |
||
| 14374 | createPadding(nativeCeil(mid), chars) |
||
| 14375 | ); |
||
| 14376 | } |
||
| 14377 | |||
| 14378 | /**
|
||
| 14379 | * Pads `string` on the right side if it's shorter than `length`. Padding
|
||
| 14380 | * characters are truncated if they exceed `length`.
|
||
| 14381 | *
|
||
| 14382 | * @static
|
||
| 14383 | * @memberOf _
|
||
| 14384 | * @since 4.0.0
|
||
| 14385 | * @category String
|
||
| 14386 | * @param {string} [string=''] The string to pad.
|
||
| 14387 | * @param {number} [length=0] The padding length.
|
||
| 14388 | * @param {string} [chars=' '] The string used as padding.
|
||
| 14389 | * @returns {string} Returns the padded string.
|
||
| 14390 | * @example
|
||
| 14391 | *
|
||
| 14392 | * _.padEnd('abc', 6);
|
||
| 14393 | * // => 'abc '
|
||
| 14394 | *
|
||
| 14395 | * _.padEnd('abc', 6, '_-');
|
||
| 14396 | * // => 'abc_-_'
|
||
| 14397 | *
|
||
| 14398 | * _.padEnd('abc', 3);
|
||
| 14399 | * // => 'abc'
|
||
| 14400 | */
|
||
| 14401 | function padEnd(string, length, chars) { |
||
| 14402 | string = toString(string); |
||
| 14403 | length = toInteger(length); |
||
| 14404 | |||
| 14405 | var strLength = length ? stringSize(string) : 0; |
||
| 14406 | return (length && strLength < length)
|
||
| 14407 | ? (string + createPadding(length - strLength, chars)) |
||
| 14408 | : string; |
||
| 14409 | } |
||
| 14410 | |||
| 14411 | /**
|
||
| 14412 | * Pads `string` on the left side if it's shorter than `length`. Padding
|
||
| 14413 | * characters are truncated if they exceed `length`.
|
||
| 14414 | *
|
||
| 14415 | * @static
|
||
| 14416 | * @memberOf _
|
||
| 14417 | * @since 4.0.0
|
||
| 14418 | * @category String
|
||
| 14419 | * @param {string} [string=''] The string to pad.
|
||
| 14420 | * @param {number} [length=0] The padding length.
|
||
| 14421 | * @param {string} [chars=' '] The string used as padding.
|
||
| 14422 | * @returns {string} Returns the padded string.
|
||
| 14423 | * @example
|
||
| 14424 | *
|
||
| 14425 | * _.padStart('abc', 6);
|
||
| 14426 | * // => ' abc'
|
||
| 14427 | *
|
||
| 14428 | * _.padStart('abc', 6, '_-');
|
||
| 14429 | * // => '_-_abc'
|
||
| 14430 | *
|
||
| 14431 | * _.padStart('abc', 3);
|
||
| 14432 | * // => 'abc'
|
||
| 14433 | */
|
||
| 14434 | function padStart(string, length, chars) { |
||
| 14435 | string = toString(string); |
||
| 14436 | length = toInteger(length); |
||
| 14437 | |||
| 14438 | var strLength = length ? stringSize(string) : 0; |
||
| 14439 | return (length && strLength < length)
|
||
| 14440 | ? (createPadding(length - strLength, chars) + string) |
||
| 14441 | : string; |
||
| 14442 | } |
||
| 14443 | |||
| 14444 | /**
|
||
| 14445 | * Converts `string` to an integer of the specified radix. If `radix` is
|
||
| 14446 | * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
|
||
| 14447 | * hexadecimal, in which case a `radix` of `16` is used.
|
||
| 14448 | *
|
||
| 14449 | * **Note:** This method aligns with the
|
||
| 14450 | * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
|
||
| 14451 | *
|
||
| 14452 | * @static
|
||
| 14453 | * @memberOf _
|
||
| 14454 | * @since 1.1.0
|
||
| 14455 | * @category String
|
||
| 14456 | * @param {string} string The string to convert.
|
||
| 14457 | * @param {number} [radix=10] The radix to interpret `value` by.
|
||
| 14458 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 14459 | * @returns {number} Returns the converted integer.
|
||
| 14460 | * @example
|
||
| 14461 | *
|
||
| 14462 | * _.parseInt('08');
|
||
| 14463 | * // => 8
|
||
| 14464 | *
|
||
| 14465 | * _.map(['6', '08', '10'], _.parseInt);
|
||
| 14466 | * // => [6, 8, 10]
|
||
| 14467 | */
|
||
| 14468 | function parseInt(string, radix, guard) { |
||
| 14469 | if (guard || radix == null) { |
||
| 14470 | radix = 0;
|
||
| 14471 | } else if (radix) { |
||
| 14472 | radix = +radix; |
||
| 14473 | } |
||
| 14474 | return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0); |
||
| 14475 | } |
||
| 14476 | |||
| 14477 | /**
|
||
| 14478 | * Repeats the given string `n` times.
|
||
| 14479 | *
|
||
| 14480 | * @static
|
||
| 14481 | * @memberOf _
|
||
| 14482 | * @since 3.0.0
|
||
| 14483 | * @category String
|
||
| 14484 | * @param {string} [string=''] The string to repeat.
|
||
| 14485 | * @param {number} [n=1] The number of times to repeat the string.
|
||
| 14486 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 14487 | * @returns {string} Returns the repeated string.
|
||
| 14488 | * @example
|
||
| 14489 | *
|
||
| 14490 | * _.repeat('*', 3);
|
||
| 14491 | * // => '***'
|
||
| 14492 | *
|
||
| 14493 | * _.repeat('abc', 2);
|
||
| 14494 | * // => 'abcabc'
|
||
| 14495 | *
|
||
| 14496 | * _.repeat('abc', 0);
|
||
| 14497 | * // => ''
|
||
| 14498 | */
|
||
| 14499 | function repeat(string, n, guard) { |
||
| 14500 | if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) { |
||
| 14501 | n = 1;
|
||
| 14502 | } else {
|
||
| 14503 | n = toInteger(n); |
||
| 14504 | } |
||
| 14505 | return baseRepeat(toString(string), n);
|
||
| 14506 | } |
||
| 14507 | |||
| 14508 | /**
|
||
| 14509 | * Replaces matches for `pattern` in `string` with `replacement`.
|
||
| 14510 | *
|
||
| 14511 | * **Note:** This method is based on
|
||
| 14512 | * [`String#replace`](https://mdn.io/String/replace).
|
||
| 14513 | *
|
||
| 14514 | * @static
|
||
| 14515 | * @memberOf _
|
||
| 14516 | * @since 4.0.0
|
||
| 14517 | * @category String
|
||
| 14518 | * @param {string} [string=''] The string to modify.
|
||
| 14519 | * @param {RegExp|string} pattern The pattern to replace.
|
||
| 14520 | * @param {Function|string} replacement The match replacement.
|
||
| 14521 | * @returns {string} Returns the modified string.
|
||
| 14522 | * @example
|
||
| 14523 | *
|
||
| 14524 | * _.replace('Hi Fred', 'Fred', 'Barney');
|
||
| 14525 | * // => 'Hi Barney'
|
||
| 14526 | */
|
||
| 14527 | function replace() { |
||
| 14528 | var args = arguments, |
||
| 14529 | string = toString(args[0]);
|
||
| 14530 | |||
| 14531 | return args.length < 3 ? string : string.replace(args[1], args[2]); |
||
| 14532 | } |
||
| 14533 | |||
| 14534 | /**
|
||
| 14535 | * Converts `string` to
|
||
| 14536 | * [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
||
| 14537 | *
|
||
| 14538 | * @static
|
||
| 14539 | * @memberOf _
|
||
| 14540 | * @since 3.0.0
|
||
| 14541 | * @category String
|
||
| 14542 | * @param {string} [string=''] The string to convert.
|
||
| 14543 | * @returns {string} Returns the snake cased string.
|
||
| 14544 | * @example
|
||
| 14545 | *
|
||
| 14546 | * _.snakeCase('Foo Bar');
|
||
| 14547 | * // => 'foo_bar'
|
||
| 14548 | *
|
||
| 14549 | * _.snakeCase('fooBar');
|
||
| 14550 | * // => 'foo_bar'
|
||
| 14551 | *
|
||
| 14552 | * _.snakeCase('--FOO-BAR--');
|
||
| 14553 | * // => 'foo_bar'
|
||
| 14554 | */
|
||
| 14555 | var snakeCase = createCompounder(function(result, word, index) { |
||
| 14556 | return result + (index ? '_' : '') + word.toLowerCase(); |
||
| 14557 | }); |
||
| 14558 | |||
| 14559 | /**
|
||
| 14560 | * Splits `string` by `separator`.
|
||
| 14561 | *
|
||
| 14562 | * **Note:** This method is based on
|
||
| 14563 | * [`String#split`](https://mdn.io/String/split).
|
||
| 14564 | *
|
||
| 14565 | * @static
|
||
| 14566 | * @memberOf _
|
||
| 14567 | * @since 4.0.0
|
||
| 14568 | * @category String
|
||
| 14569 | * @param {string} [string=''] The string to split.
|
||
| 14570 | * @param {RegExp|string} separator The separator pattern to split by.
|
||
| 14571 | * @param {number} [limit] The length to truncate results to.
|
||
| 14572 | * @returns {Array} Returns the string segments.
|
||
| 14573 | * @example
|
||
| 14574 | *
|
||
| 14575 | * _.split('a-b-c', '-', 2);
|
||
| 14576 | * // => ['a', 'b']
|
||
| 14577 | */
|
||
| 14578 | function split(string, separator, limit) { |
||
| 14579 | if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { |
||
| 14580 | separator = limit = undefined;
|
||
| 14581 | } |
||
| 14582 | limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0; |
||
| 14583 | if (!limit) {
|
||
| 14584 | return [];
|
||
| 14585 | } |
||
| 14586 | string = toString(string); |
||
| 14587 | if (string && (
|
||
| 14588 | typeof separator == 'string' || |
||
| 14589 | (separator != null && !isRegExp(separator))
|
||
| 14590 | )) {
|
||
| 14591 | separator = baseToString(separator); |
||
| 14592 | if (!separator && hasUnicode(string)) {
|
||
| 14593 | return castSlice(stringToArray(string), 0, limit); |
||
| 14594 | } |
||
| 14595 | } |
||
| 14596 | return string.split(separator, limit);
|
||
| 14597 | } |
||
| 14598 | |||
| 14599 | /**
|
||
| 14600 | * Converts `string` to
|
||
| 14601 | * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
|
||
| 14602 | *
|
||
| 14603 | * @static
|
||
| 14604 | * @memberOf _
|
||
| 14605 | * @since 3.1.0
|
||
| 14606 | * @category String
|
||
| 14607 | * @param {string} [string=''] The string to convert.
|
||
| 14608 | * @returns {string} Returns the start cased string.
|
||
| 14609 | * @example
|
||
| 14610 | *
|
||
| 14611 | * _.startCase('--foo-bar--');
|
||
| 14612 | * // => 'Foo Bar'
|
||
| 14613 | *
|
||
| 14614 | * _.startCase('fooBar');
|
||
| 14615 | * // => 'Foo Bar'
|
||
| 14616 | *
|
||
| 14617 | * _.startCase('__FOO_BAR__');
|
||
| 14618 | * // => 'FOO BAR'
|
||
| 14619 | */
|
||
| 14620 | var startCase = createCompounder(function(result, word, index) { |
||
| 14621 | return result + (index ? ' ' : '') + upperFirst(word); |
||
| 14622 | }); |
||
| 14623 | |||
| 14624 | /**
|
||
| 14625 | * Checks if `string` starts with the given target string.
|
||
| 14626 | *
|
||
| 14627 | * @static
|
||
| 14628 | * @memberOf _
|
||
| 14629 | * @since 3.0.0
|
||
| 14630 | * @category String
|
||
| 14631 | * @param {string} [string=''] The string to inspect.
|
||
| 14632 | * @param {string} [target] The string to search for.
|
||
| 14633 | * @param {number} [position=0] The position to search from.
|
||
| 14634 | * @returns {boolean} Returns `true` if `string` starts with `target`,
|
||
| 14635 | * else `false`.
|
||
| 14636 | * @example
|
||
| 14637 | *
|
||
| 14638 | * _.startsWith('abc', 'a');
|
||
| 14639 | * // => true
|
||
| 14640 | *
|
||
| 14641 | * _.startsWith('abc', 'b');
|
||
| 14642 | * // => false
|
||
| 14643 | *
|
||
| 14644 | * _.startsWith('abc', 'b', 1);
|
||
| 14645 | * // => true
|
||
| 14646 | */
|
||
| 14647 | function startsWith(string, target, position) { |
||
| 14648 | string = toString(string); |
||
| 14649 | position = position == null
|
||
| 14650 | ? 0
|
||
| 14651 | : baseClamp(toInteger(position), 0, string.length);
|
||
| 14652 | |||
| 14653 | target = baseToString(target); |
||
| 14654 | return string.slice(position, position + target.length) == target;
|
||
| 14655 | } |
||
| 14656 | |||
| 14657 | /**
|
||
| 14658 | * Creates a compiled template function that can interpolate data properties
|
||
| 14659 | * in "interpolate" delimiters, HTML-escape interpolated data properties in
|
||
| 14660 | * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
|
||
| 14661 | * properties may be accessed as free variables in the template. If a setting
|
||
| 14662 | * object is given, it takes precedence over `_.templateSettings` values.
|
||
| 14663 | *
|
||
| 14664 | * **Note:** In the development build `_.template` utilizes
|
||
| 14665 | * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
|
||
| 14666 | * for easier debugging.
|
||
| 14667 | *
|
||
| 14668 | * For more information on precompiling templates see
|
||
| 14669 | * [lodash's custom builds documentation](https://lodash.com/custom-builds).
|
||
| 14670 | *
|
||
| 14671 | * For more information on Chrome extension sandboxes see
|
||
| 14672 | * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
|
||
| 14673 | *
|
||
| 14674 | * @static
|
||
| 14675 | * @since 0.1.0
|
||
| 14676 | * @memberOf _
|
||
| 14677 | * @category String
|
||
| 14678 | * @param {string} [string=''] The template string.
|
||
| 14679 | * @param {Object} [options={}] The options object.
|
||
| 14680 | * @param {RegExp} [options.escape=_.templateSettings.escape]
|
||
| 14681 | * The HTML "escape" delimiter.
|
||
| 14682 | * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
|
||
| 14683 | * The "evaluate" delimiter.
|
||
| 14684 | * @param {Object} [options.imports=_.templateSettings.imports]
|
||
| 14685 | * An object to import into the template as free variables.
|
||
| 14686 | * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
|
||
| 14687 | * The "interpolate" delimiter.
|
||
| 14688 | * @param {string} [options.sourceURL='lodash.templateSources[n]']
|
||
| 14689 | * The sourceURL of the compiled template.
|
||
| 14690 | * @param {string} [options.variable='obj']
|
||
| 14691 | * The data object variable name.
|
||
| 14692 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 14693 | * @returns {Function} Returns the compiled template function.
|
||
| 14694 | * @example
|
||
| 14695 | *
|
||
| 14696 | * // Use the "interpolate" delimiter to create a compiled template.
|
||
| 14697 | * var compiled = _.template('hello <%= user %>!');
|
||
| 14698 | * compiled({ 'user': 'fred' });
|
||
| 14699 | * // => 'hello fred!'
|
||
| 14700 | *
|
||
| 14701 | * // Use the HTML "escape" delimiter to escape data property values.
|
||
| 14702 | * var compiled = _.template('<b><%- value %></b>');
|
||
| 14703 | * compiled({ 'value': '<script>' });
|
||
| 14704 | * // => '<b><script></b>'
|
||
| 14705 | *
|
||
| 14706 | * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
|
||
| 14707 | * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
||
| 14708 | * compiled({ 'users': ['fred', 'barney'] });
|
||
| 14709 | * // => '<li>fred</li><li>barney</li>'
|
||
| 14710 | *
|
||
| 14711 | * // Use the internal `print` function in "evaluate" delimiters.
|
||
| 14712 | * var compiled = _.template('<% print("hello " + user); %>!');
|
||
| 14713 | * compiled({ 'user': 'barney' });
|
||
| 14714 | * // => 'hello barney!'
|
||
| 14715 | *
|
||
| 14716 | * // Use the ES template literal delimiter as an "interpolate" delimiter.
|
||
| 14717 | * // Disable support by replacing the "interpolate" delimiter.
|
||
| 14718 | * var compiled = _.template('hello ${ user }!');
|
||
| 14719 | * compiled({ 'user': 'pebbles' });
|
||
| 14720 | * // => 'hello pebbles!'
|
||
| 14721 | *
|
||
| 14722 | * // Use backslashes to treat delimiters as plain text.
|
||
| 14723 | * var compiled = _.template('<%= "\\<%- value %\\>" %>');
|
||
| 14724 | * compiled({ 'value': 'ignored' });
|
||
| 14725 | * // => '<%- value %>'
|
||
| 14726 | *
|
||
| 14727 | * // Use the `imports` option to import `jQuery` as `jq`.
|
||
| 14728 | * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
|
||
| 14729 | * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
|
||
| 14730 | * compiled({ 'users': ['fred', 'barney'] });
|
||
| 14731 | * // => '<li>fred</li><li>barney</li>'
|
||
| 14732 | *
|
||
| 14733 | * // Use the `sourceURL` option to specify a custom sourceURL for the template.
|
||
| 14734 | * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
|
||
| 14735 | * compiled(data);
|
||
| 14736 | * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
|
||
| 14737 | *
|
||
| 14738 | * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
|
||
| 14739 | * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
|
||
| 14740 | * compiled.source;
|
||
| 14741 | * // => function(data) {
|
||
| 14742 | * // var __t, __p = '';
|
||
| 14743 | * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
|
||
| 14744 | * // return __p;
|
||
| 14745 | * // }
|
||
| 14746 | *
|
||
| 14747 | * // Use custom template delimiters.
|
||
| 14748 | * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
||
| 14749 | * var compiled = _.template('hello {{ user }}!');
|
||
| 14750 | * compiled({ 'user': 'mustache' });
|
||
| 14751 | * // => 'hello mustache!'
|
||
| 14752 | *
|
||
| 14753 | * // Use the `source` property to inline compiled templates for meaningful
|
||
| 14754 | * // line numbers in error messages and stack traces.
|
||
| 14755 | * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
|
||
| 14756 | * var JST = {\
|
||
| 14757 | * "main": ' + _.template(mainText).source + '\
|
||
| 14758 | * };\
|
||
| 14759 | * ');
|
||
| 14760 | */
|
||
| 14761 | function template(string, options, guard) { |
||
| 14762 | // Based on John Resig's `tmpl` implementation
|
||
| 14763 | // (http://ejohn.org/blog/javascript-micro-templating/)
|
||
| 14764 | // and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
||
| 14765 | var settings = lodash.templateSettings;
|
||
| 14766 | |||
| 14767 | if (guard && isIterateeCall(string, options, guard)) {
|
||
| 14768 | options = undefined;
|
||
| 14769 | } |
||
| 14770 | string = toString(string); |
||
| 14771 | options = assignInWith({}, options, settings, customDefaultsAssignIn);
|
||
| 14772 | |||
| 14773 | var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
|
||
| 14774 | importsKeys = keys(imports), |
||
| 14775 | importsValues = baseValues(imports, importsKeys); |
||
| 14776 | |||
| 14777 | var isEscaping,
|
||
| 14778 | isEvaluating, |
||
| 14779 | index = 0,
|
||
| 14780 | interpolate = options.interpolate || reNoMatch, |
||
| 14781 | source = "__p += '";
|
||
| 14782 | |||
| 14783 | // Compile the regexp to match each delimiter.
|
||
| 14784 | var reDelimiters = RegExp(
|
||
| 14785 | (options.escape || reNoMatch).source + '|' +
|
||
| 14786 | interpolate.source + '|' +
|
||
| 14787 | (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
|
||
| 14788 | (options.evaluate || reNoMatch).source + '|$'
|
||
| 14789 | , 'g');
|
||
| 14790 | |||
| 14791 | // Use a sourceURL for easier debugging.
|
||
| 14792 | var sourceURL = '//# sourceURL=' + |
||
| 14793 | ('sourceURL' in options |
||
| 14794 | ? options.sourceURL |
||
| 14795 | : ('lodash.templateSources[' + (++templateCounter) + ']') |
||
| 14796 | ) + '\n';
|
||
| 14797 | |||
| 14798 | string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
|
||
| 14799 | interpolateValue || (interpolateValue = esTemplateValue); |
||
| 14800 | |||
| 14801 | // Escape characters that can't be included in string literals.
|
||
| 14802 | source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar); |
||
| 14803 | |||
| 14804 | // Replace delimiters with snippets.
|
||
| 14805 | if (escapeValue) {
|
||
| 14806 | isEscaping = true;
|
||
| 14807 | source += "' +\n__e(" + escapeValue + ") +\n'"; |
||
| 14808 | } |
||
| 14809 | if (evaluateValue) {
|
||
| 14810 | isEvaluating = true;
|
||
| 14811 | source += "';\n" + evaluateValue + ";\n__p += '"; |
||
| 14812 | } |
||
| 14813 | if (interpolateValue) {
|
||
| 14814 | source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'"; |
||
| 14815 | } |
||
| 14816 | index = offset + match.length; |
||
| 14817 | |||
| 14818 | // The JS engine embedded in Adobe products needs `match` returned in
|
||
| 14819 | // order to produce the correct `offset` value.
|
||
| 14820 | return match;
|
||
| 14821 | }); |
||
| 14822 | |||
| 14823 | source += "';\n";
|
||
| 14824 | |||
| 14825 | // If `variable` is not specified wrap a with-statement around the generated
|
||
| 14826 | // code to add the data object to the top of the scope chain.
|
||
| 14827 | var variable = options.variable;
|
||
| 14828 | if (!variable) {
|
||
| 14829 | source = 'with (obj) {\n' + source + '\n}\n'; |
||
| 14830 | } |
||
| 14831 | // Cleanup code by stripping empty strings.
|
||
| 14832 | source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
||
| 14833 | .replace(reEmptyStringMiddle, '$1')
|
||
| 14834 | .replace(reEmptyStringTrailing, '$1;');
|
||
| 14835 | |||
| 14836 | // Frame code as the function body.
|
||
| 14837 | source = 'function(' + (variable || 'obj') + ') {\n' + |
||
| 14838 | (variable |
||
| 14839 | ? ''
|
||
| 14840 | : 'obj || (obj = {});\n'
|
||
| 14841 | ) + |
||
| 14842 | "var __t, __p = ''" +
|
||
| 14843 | (isEscaping |
||
| 14844 | ? ', __e = _.escape'
|
||
| 14845 | : ''
|
||
| 14846 | ) + |
||
| 14847 | (isEvaluating |
||
| 14848 | ? ', __j = Array.prototype.join;\n' +
|
||
| 14849 | "function print() { __p += __j.call(arguments, '') }\n"
|
||
| 14850 | : ';\n'
|
||
| 14851 | ) + |
||
| 14852 | source + |
||
| 14853 | 'return __p\n}';
|
||
| 14854 | |||
| 14855 | var result = attempt(function() { |
||
| 14856 | return Function(importsKeys, sourceURL + 'return ' + source) |
||
| 14857 | .apply(undefined, importsValues);
|
||
| 14858 | }); |
||
| 14859 | |||
| 14860 | // Provide the compiled function's source by its `toString` method or
|
||
| 14861 | // the `source` property as a convenience for inlining compiled templates.
|
||
| 14862 | result.source = source; |
||
| 14863 | if (isError(result)) {
|
||
| 14864 | throw result;
|
||
| 14865 | } |
||
| 14866 | return result;
|
||
| 14867 | } |
||
| 14868 | |||
| 14869 | /**
|
||
| 14870 | * Converts `string`, as a whole, to lower case just like
|
||
| 14871 | * [String#toLowerCase](https://mdn.io/toLowerCase).
|
||
| 14872 | *
|
||
| 14873 | * @static
|
||
| 14874 | * @memberOf _
|
||
| 14875 | * @since 4.0.0
|
||
| 14876 | * @category String
|
||
| 14877 | * @param {string} [string=''] The string to convert.
|
||
| 14878 | * @returns {string} Returns the lower cased string.
|
||
| 14879 | * @example
|
||
| 14880 | *
|
||
| 14881 | * _.toLower('--Foo-Bar--');
|
||
| 14882 | * // => '--foo-bar--'
|
||
| 14883 | *
|
||
| 14884 | * _.toLower('fooBar');
|
||
| 14885 | * // => 'foobar'
|
||
| 14886 | *
|
||
| 14887 | * _.toLower('__FOO_BAR__');
|
||
| 14888 | * // => '__foo_bar__'
|
||
| 14889 | */
|
||
| 14890 | function toLower(value) { |
||
| 14891 | return toString(value).toLowerCase();
|
||
| 14892 | } |
||
| 14893 | |||
| 14894 | /**
|
||
| 14895 | * Converts `string`, as a whole, to upper case just like
|
||
| 14896 | * [String#toUpperCase](https://mdn.io/toUpperCase).
|
||
| 14897 | *
|
||
| 14898 | * @static
|
||
| 14899 | * @memberOf _
|
||
| 14900 | * @since 4.0.0
|
||
| 14901 | * @category String
|
||
| 14902 | * @param {string} [string=''] The string to convert.
|
||
| 14903 | * @returns {string} Returns the upper cased string.
|
||
| 14904 | * @example
|
||
| 14905 | *
|
||
| 14906 | * _.toUpper('--foo-bar--');
|
||
| 14907 | * // => '--FOO-BAR--'
|
||
| 14908 | *
|
||
| 14909 | * _.toUpper('fooBar');
|
||
| 14910 | * // => 'FOOBAR'
|
||
| 14911 | *
|
||
| 14912 | * _.toUpper('__foo_bar__');
|
||
| 14913 | * // => '__FOO_BAR__'
|
||
| 14914 | */
|
||
| 14915 | function toUpper(value) { |
||
| 14916 | return toString(value).toUpperCase();
|
||
| 14917 | } |
||
| 14918 | |||
| 14919 | /**
|
||
| 14920 | * Removes leading and trailing whitespace or specified characters from `string`.
|
||
| 14921 | *
|
||
| 14922 | * @static
|
||
| 14923 | * @memberOf _
|
||
| 14924 | * @since 3.0.0
|
||
| 14925 | * @category String
|
||
| 14926 | * @param {string} [string=''] The string to trim.
|
||
| 14927 | * @param {string} [chars=whitespace] The characters to trim.
|
||
| 14928 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 14929 | * @returns {string} Returns the trimmed string.
|
||
| 14930 | * @example
|
||
| 14931 | *
|
||
| 14932 | * _.trim(' abc ');
|
||
| 14933 | * // => 'abc'
|
||
| 14934 | *
|
||
| 14935 | * _.trim('-_-abc-_-', '_-');
|
||
| 14936 | * // => 'abc'
|
||
| 14937 | *
|
||
| 14938 | * _.map([' foo ', ' bar '], _.trim);
|
||
| 14939 | * // => ['foo', 'bar']
|
||
| 14940 | */
|
||
| 14941 | function trim(string, chars, guard) { |
||
| 14942 | string = toString(string); |
||
| 14943 | if (string && (guard || chars === undefined)) { |
||
| 14944 | return string.replace(reTrim, ''); |
||
| 14945 | } |
||
| 14946 | if (!string || !(chars = baseToString(chars))) {
|
||
| 14947 | return string;
|
||
| 14948 | } |
||
| 14949 | var strSymbols = stringToArray(string),
|
||
| 14950 | chrSymbols = stringToArray(chars), |
||
| 14951 | start = charsStartIndex(strSymbols, chrSymbols), |
||
| 14952 | end = charsEndIndex(strSymbols, chrSymbols) + 1;
|
||
| 14953 | |||
| 14954 | return castSlice(strSymbols, start, end).join(''); |
||
| 14955 | } |
||
| 14956 | |||
| 14957 | /**
|
||
| 14958 | * Removes trailing whitespace or specified characters from `string`.
|
||
| 14959 | *
|
||
| 14960 | * @static
|
||
| 14961 | * @memberOf _
|
||
| 14962 | * @since 4.0.0
|
||
| 14963 | * @category String
|
||
| 14964 | * @param {string} [string=''] The string to trim.
|
||
| 14965 | * @param {string} [chars=whitespace] The characters to trim.
|
||
| 14966 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 14967 | * @returns {string} Returns the trimmed string.
|
||
| 14968 | * @example
|
||
| 14969 | *
|
||
| 14970 | * _.trimEnd(' abc ');
|
||
| 14971 | * // => ' abc'
|
||
| 14972 | *
|
||
| 14973 | * _.trimEnd('-_-abc-_-', '_-');
|
||
| 14974 | * // => '-_-abc'
|
||
| 14975 | */
|
||
| 14976 | function trimEnd(string, chars, guard) { |
||
| 14977 | string = toString(string); |
||
| 14978 | if (string && (guard || chars === undefined)) { |
||
| 14979 | return string.replace(reTrimEnd, ''); |
||
| 14980 | } |
||
| 14981 | if (!string || !(chars = baseToString(chars))) {
|
||
| 14982 | return string;
|
||
| 14983 | } |
||
| 14984 | var strSymbols = stringToArray(string),
|
||
| 14985 | end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
|
||
| 14986 | |||
| 14987 | return castSlice(strSymbols, 0, end).join(''); |
||
| 14988 | } |
||
| 14989 | |||
| 14990 | /**
|
||
| 14991 | * Removes leading whitespace or specified characters from `string`.
|
||
| 14992 | *
|
||
| 14993 | * @static
|
||
| 14994 | * @memberOf _
|
||
| 14995 | * @since 4.0.0
|
||
| 14996 | * @category String
|
||
| 14997 | * @param {string} [string=''] The string to trim.
|
||
| 14998 | * @param {string} [chars=whitespace] The characters to trim.
|
||
| 14999 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 15000 | * @returns {string} Returns the trimmed string.
|
||
| 15001 | * @example
|
||
| 15002 | *
|
||
| 15003 | * _.trimStart(' abc ');
|
||
| 15004 | * // => 'abc '
|
||
| 15005 | *
|
||
| 15006 | * _.trimStart('-_-abc-_-', '_-');
|
||
| 15007 | * // => 'abc-_-'
|
||
| 15008 | */
|
||
| 15009 | function trimStart(string, chars, guard) { |
||
| 15010 | string = toString(string); |
||
| 15011 | if (string && (guard || chars === undefined)) { |
||
| 15012 | return string.replace(reTrimStart, ''); |
||
| 15013 | } |
||
| 15014 | if (!string || !(chars = baseToString(chars))) {
|
||
| 15015 | return string;
|
||
| 15016 | } |
||
| 15017 | var strSymbols = stringToArray(string),
|
||
| 15018 | start = charsStartIndex(strSymbols, stringToArray(chars)); |
||
| 15019 | |||
| 15020 | return castSlice(strSymbols, start).join(''); |
||
| 15021 | } |
||
| 15022 | |||
| 15023 | /**
|
||
| 15024 | * Truncates `string` if it's longer than the given maximum string length.
|
||
| 15025 | * The last characters of the truncated string are replaced with the omission
|
||
| 15026 | * string which defaults to "...".
|
||
| 15027 | *
|
||
| 15028 | * @static
|
||
| 15029 | * @memberOf _
|
||
| 15030 | * @since 4.0.0
|
||
| 15031 | * @category String
|
||
| 15032 | * @param {string} [string=''] The string to truncate.
|
||
| 15033 | * @param {Object} [options={}] The options object.
|
||
| 15034 | * @param {number} [options.length=30] The maximum string length.
|
||
| 15035 | * @param {string} [options.omission='...'] The string to indicate text is omitted.
|
||
| 15036 | * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
|
||
| 15037 | * @returns {string} Returns the truncated string.
|
||
| 15038 | * @example
|
||
| 15039 | *
|
||
| 15040 | * _.truncate('hi-diddly-ho there, neighborino');
|
||
| 15041 | * // => 'hi-diddly-ho there, neighbo...'
|
||
| 15042 | *
|
||
| 15043 | * _.truncate('hi-diddly-ho there, neighborino', {
|
||
| 15044 | * 'length': 24,
|
||
| 15045 | * 'separator': ' '
|
||
| 15046 | * });
|
||
| 15047 | * // => 'hi-diddly-ho there,...'
|
||
| 15048 | *
|
||
| 15049 | * _.truncate('hi-diddly-ho there, neighborino', {
|
||
| 15050 | * 'length': 24,
|
||
| 15051 | * 'separator': /,? +/
|
||
| 15052 | * });
|
||
| 15053 | * // => 'hi-diddly-ho there...'
|
||
| 15054 | *
|
||
| 15055 | * _.truncate('hi-diddly-ho there, neighborino', {
|
||
| 15056 | * 'omission': ' [...]'
|
||
| 15057 | * });
|
||
| 15058 | * // => 'hi-diddly-ho there, neig [...]'
|
||
| 15059 | */
|
||
| 15060 | function truncate(string, options) { |
||
| 15061 | var length = DEFAULT_TRUNC_LENGTH,
|
||
| 15062 | omission = DEFAULT_TRUNC_OMISSION; |
||
| 15063 | |||
| 15064 | if (isObject(options)) {
|
||
| 15065 | var separator = 'separator' in options ? options.separator : separator; |
||
| 15066 | length = 'length' in options ? toInteger(options.length) : length; |
||
| 15067 | omission = 'omission' in options ? baseToString(options.omission) : omission; |
||
| 15068 | } |
||
| 15069 | string = toString(string); |
||
| 15070 | |||
| 15071 | var strLength = string.length;
|
||
| 15072 | if (hasUnicode(string)) {
|
||
| 15073 | var strSymbols = stringToArray(string);
|
||
| 15074 | strLength = strSymbols.length; |
||
| 15075 | } |
||
| 15076 | if (length >= strLength) {
|
||
| 15077 | return string;
|
||
| 15078 | } |
||
| 15079 | var end = length - stringSize(omission);
|
||
| 15080 | if (end < 1) { |
||
| 15081 | return omission;
|
||
| 15082 | } |
||
| 15083 | var result = strSymbols
|
||
| 15084 | ? castSlice(strSymbols, 0, end).join('') |
||
| 15085 | : string.slice(0, end);
|
||
| 15086 | |||
| 15087 | if (separator === undefined) { |
||
| 15088 | return result + omission;
|
||
| 15089 | } |
||
| 15090 | if (strSymbols) {
|
||
| 15091 | end += (result.length - end); |
||
| 15092 | } |
||
| 15093 | if (isRegExp(separator)) {
|
||
| 15094 | if (string.slice(end).search(separator)) {
|
||
| 15095 | var match,
|
||
| 15096 | substring = result; |
||
| 15097 | |||
| 15098 | if (!separator.global) {
|
||
| 15099 | separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
|
||
| 15100 | } |
||
| 15101 | separator.lastIndex = 0;
|
||
| 15102 | while ((match = separator.exec(substring))) {
|
||
| 15103 | var newEnd = match.index;
|
||
| 15104 | } |
||
| 15105 | result = result.slice(0, newEnd === undefined ? end : newEnd); |
||
| 15106 | } |
||
| 15107 | } else if (string.indexOf(baseToString(separator), end) != end) { |
||
| 15108 | var index = result.lastIndexOf(separator);
|
||
| 15109 | if (index > -1) { |
||
| 15110 | result = result.slice(0, index);
|
||
| 15111 | } |
||
| 15112 | } |
||
| 15113 | return result + omission;
|
||
| 15114 | } |
||
| 15115 | |||
| 15116 | /**
|
||
| 15117 | * The inverse of `_.escape`; this method converts the HTML entities
|
||
| 15118 | * `&`, `<`, `>`, `"`, and `'` in `string` to
|
||
| 15119 | * their corresponding characters.
|
||
| 15120 | *
|
||
| 15121 | * **Note:** No other HTML entities are unescaped. To unescape additional
|
||
| 15122 | * HTML entities use a third-party library like [_he_](https://mths.be/he).
|
||
| 15123 | *
|
||
| 15124 | * @static
|
||
| 15125 | * @memberOf _
|
||
| 15126 | * @since 0.6.0
|
||
| 15127 | * @category String
|
||
| 15128 | * @param {string} [string=''] The string to unescape.
|
||
| 15129 | * @returns {string} Returns the unescaped string.
|
||
| 15130 | * @example
|
||
| 15131 | *
|
||
| 15132 | * _.unescape('fred, barney, & pebbles');
|
||
| 15133 | * // => 'fred, barney, & pebbles'
|
||
| 15134 | */
|
||
| 15135 | function unescape(string) { |
||
| 15136 | string = toString(string); |
||
| 15137 | return (string && reHasEscapedHtml.test(string))
|
||
| 15138 | ? string.replace(reEscapedHtml, unescapeHtmlChar) |
||
| 15139 | : string; |
||
| 15140 | } |
||
| 15141 | |||
| 15142 | /**
|
||
| 15143 | * Converts `string`, as space separated words, to upper case.
|
||
| 15144 | *
|
||
| 15145 | * @static
|
||
| 15146 | * @memberOf _
|
||
| 15147 | * @since 4.0.0
|
||
| 15148 | * @category String
|
||
| 15149 | * @param {string} [string=''] The string to convert.
|
||
| 15150 | * @returns {string} Returns the upper cased string.
|
||
| 15151 | * @example
|
||
| 15152 | *
|
||
| 15153 | * _.upperCase('--foo-bar');
|
||
| 15154 | * // => 'FOO BAR'
|
||
| 15155 | *
|
||
| 15156 | * _.upperCase('fooBar');
|
||
| 15157 | * // => 'FOO BAR'
|
||
| 15158 | *
|
||
| 15159 | * _.upperCase('__foo_bar__');
|
||
| 15160 | * // => 'FOO BAR'
|
||
| 15161 | */
|
||
| 15162 | var upperCase = createCompounder(function(result, word, index) { |
||
| 15163 | return result + (index ? ' ' : '') + word.toUpperCase(); |
||
| 15164 | }); |
||
| 15165 | |||
| 15166 | /**
|
||
| 15167 | * Converts the first character of `string` to upper case.
|
||
| 15168 | *
|
||
| 15169 | * @static
|
||
| 15170 | * @memberOf _
|
||
| 15171 | * @since 4.0.0
|
||
| 15172 | * @category String
|
||
| 15173 | * @param {string} [string=''] The string to convert.
|
||
| 15174 | * @returns {string} Returns the converted string.
|
||
| 15175 | * @example
|
||
| 15176 | *
|
||
| 15177 | * _.upperFirst('fred');
|
||
| 15178 | * // => 'Fred'
|
||
| 15179 | *
|
||
| 15180 | * _.upperFirst('FRED');
|
||
| 15181 | * // => 'FRED'
|
||
| 15182 | */
|
||
| 15183 | var upperFirst = createCaseFirst('toUpperCase'); |
||
| 15184 | |||
| 15185 | /**
|
||
| 15186 | * Splits `string` into an array of its words.
|
||
| 15187 | *
|
||
| 15188 | * @static
|
||
| 15189 | * @memberOf _
|
||
| 15190 | * @since 3.0.0
|
||
| 15191 | * @category String
|
||
| 15192 | * @param {string} [string=''] The string to inspect.
|
||
| 15193 | * @param {RegExp|string} [pattern] The pattern to match words.
|
||
| 15194 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||
| 15195 | * @returns {Array} Returns the words of `string`.
|
||
| 15196 | * @example
|
||
| 15197 | *
|
||
| 15198 | * _.words('fred, barney, & pebbles');
|
||
| 15199 | * // => ['fred', 'barney', 'pebbles']
|
||
| 15200 | *
|
||
| 15201 | * _.words('fred, barney, & pebbles', /[^, ]+/g);
|
||
| 15202 | * // => ['fred', 'barney', '&', 'pebbles']
|
||
| 15203 | */
|
||
| 15204 | function words(string, pattern, guard) { |
||
| 15205 | string = toString(string); |
||
| 15206 | pattern = guard ? undefined : pattern;
|
||
| 15207 | |||
| 15208 | if (pattern === undefined) { |
||
| 15209 | return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
|
||
| 15210 | } |
||
| 15211 | return string.match(pattern) || [];
|
||
| 15212 | } |
||
| 15213 | |||
| 15214 | /*------------------------------------------------------------------------*/
|
||
| 15215 | |||
| 15216 | /**
|
||
| 15217 | * Attempts to invoke `func`, returning either the result or the caught error
|
||
| 15218 | * object. Any additional arguments are provided to `func` when it's invoked.
|
||
| 15219 | *
|
||
| 15220 | * @static
|
||
| 15221 | * @memberOf _
|
||
| 15222 | * @since 3.0.0
|
||
| 15223 | * @category Util
|
||
| 15224 | * @param {Function} func The function to attempt.
|
||
| 15225 | * @param {...*} [args] The arguments to invoke `func` with.
|
||
| 15226 | * @returns {*} Returns the `func` result or error object.
|
||
| 15227 | * @example
|
||
| 15228 | *
|
||
| 15229 | * // Avoid throwing errors for invalid selectors.
|
||
| 15230 | * var elements = _.attempt(function(selector) {
|
||
| 15231 | * return document.querySelectorAll(selector);
|
||
| 15232 | * }, '>_>');
|
||
| 15233 | *
|
||
| 15234 | * if (_.isError(elements)) {
|
||
| 15235 | * elements = [];
|
||
| 15236 | * }
|
||
| 15237 | */
|
||
| 15238 | var attempt = baseRest(function(func, args) { |
||
| 15239 | try {
|
||
| 15240 | return apply(func, undefined, args); |
||
| 15241 | } catch (e) {
|
||
| 15242 | return isError(e) ? e : new Error(e); |
||
| 15243 | } |
||
| 15244 | }); |
||
| 15245 | |||
| 15246 | /**
|
||
| 15247 | * Binds methods of an object to the object itself, overwriting the existing
|
||
| 15248 | * method.
|
||
| 15249 | *
|
||
| 15250 | * **Note:** This method doesn't set the "length" property of bound functions.
|
||
| 15251 | *
|
||
| 15252 | * @static
|
||
| 15253 | * @since 0.1.0
|
||
| 15254 | * @memberOf _
|
||
| 15255 | * @category Util
|
||
| 15256 | * @param {Object} object The object to bind and assign the bound methods to.
|
||
| 15257 | * @param {...(string|string[])} methodNames The object method names to bind.
|
||
| 15258 | * @returns {Object} Returns `object`.
|
||
| 15259 | * @example
|
||
| 15260 | *
|
||
| 15261 | * var view = {
|
||
| 15262 | * 'label': 'docs',
|
||
| 15263 | * 'click': function() {
|
||
| 15264 | * console.log('clicked ' + this.label);
|
||
| 15265 | * }
|
||
| 15266 | * };
|
||
| 15267 | *
|
||
| 15268 | * _.bindAll(view, ['click']);
|
||
| 15269 | * jQuery(element).on('click', view.click);
|
||
| 15270 | * // => Logs 'clicked docs' when clicked.
|
||
| 15271 | */
|
||
| 15272 | var bindAll = flatRest(function(object, methodNames) { |
||
| 15273 | arrayEach(methodNames, function(key) {
|
||
| 15274 | key = toKey(key); |
||
| 15275 | baseAssignValue(object, key, bind(object[key], object)); |
||
| 15276 | }); |
||
| 15277 | return object;
|
||
| 15278 | }); |
||
| 15279 | |||
| 15280 | /**
|
||
| 15281 | * Creates a function that iterates over `pairs` and invokes the corresponding
|
||
| 15282 | * function of the first predicate to return truthy. The predicate-function
|
||
| 15283 | * pairs are invoked with the `this` binding and arguments of the created
|
||
| 15284 | * function.
|
||
| 15285 | *
|
||
| 15286 | * @static
|
||
| 15287 | * @memberOf _
|
||
| 15288 | * @since 4.0.0
|
||
| 15289 | * @category Util
|
||
| 15290 | * @param {Array} pairs The predicate-function pairs.
|
||
| 15291 | * @returns {Function} Returns the new composite function.
|
||
| 15292 | * @example
|
||
| 15293 | *
|
||
| 15294 | * var func = _.cond([
|
||
| 15295 | * [_.matches({ 'a': 1 }), _.constant('matches A')],
|
||
| 15296 | * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
|
||
| 15297 | * [_.stubTrue, _.constant('no match')]
|
||
| 15298 | * ]);
|
||
| 15299 | *
|
||
| 15300 | * func({ 'a': 1, 'b': 2 });
|
||
| 15301 | * // => 'matches A'
|
||
| 15302 | *
|
||
| 15303 | * func({ 'a': 0, 'b': 1 });
|
||
| 15304 | * // => 'matches B'
|
||
| 15305 | *
|
||
| 15306 | * func({ 'a': '1', 'b': '2' });
|
||
| 15307 | * // => 'no match'
|
||
| 15308 | */
|
||
| 15309 | function cond(pairs) { |
||
| 15310 | var length = pairs == null ? 0 : pairs.length, |
||
| 15311 | toIteratee = getIteratee(); |
||
| 15312 | |||
| 15313 | pairs = !length ? [] : arrayMap(pairs, function(pair) {
|
||
| 15314 | if (typeof pair[1] != 'function') { |
||
| 15315 | throw new TypeError(FUNC_ERROR_TEXT); |
||
| 15316 | } |
||
| 15317 | return [toIteratee(pair[0]), pair[1]]; |
||
| 15318 | }); |
||
| 15319 | |||
| 15320 | return baseRest(function(args) { |
||
| 15321 | var index = -1; |
||
| 15322 | while (++index < length) {
|
||
| 15323 | var pair = pairs[index];
|
||
| 15324 | if (apply(pair[0], this, args)) { |
||
| 15325 | return apply(pair[1], this, args); |
||
| 15326 | } |
||
| 15327 | } |
||
| 15328 | }); |
||
| 15329 | } |
||
| 15330 | |||
| 15331 | /**
|
||
| 15332 | * Creates a function that invokes the predicate properties of `source` with
|
||
| 15333 | * the corresponding property values of a given object, returning `true` if
|
||
| 15334 | * all predicates return truthy, else `false`.
|
||
| 15335 | *
|
||
| 15336 | * **Note:** The created function is equivalent to `_.conformsTo` with
|
||
| 15337 | * `source` partially applied.
|
||
| 15338 | *
|
||
| 15339 | * @static
|
||
| 15340 | * @memberOf _
|
||
| 15341 | * @since 4.0.0
|
||
| 15342 | * @category Util
|
||
| 15343 | * @param {Object} source The object of property predicates to conform to.
|
||
| 15344 | * @returns {Function} Returns the new spec function.
|
||
| 15345 | * @example
|
||
| 15346 | *
|
||
| 15347 | * var objects = [
|
||
| 15348 | * { 'a': 2, 'b': 1 },
|
||
| 15349 | * { 'a': 1, 'b': 2 }
|
||
| 15350 | * ];
|
||
| 15351 | *
|
||
| 15352 | * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
|
||
| 15353 | * // => [{ 'a': 1, 'b': 2 }]
|
||
| 15354 | */
|
||
| 15355 | function conforms(source) { |
||
| 15356 | return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
|
||
| 15357 | } |
||
| 15358 | |||
| 15359 | /**
|
||
| 15360 | * Creates a function that returns `value`.
|
||
| 15361 | *
|
||
| 15362 | * @static
|
||
| 15363 | * @memberOf _
|
||
| 15364 | * @since 2.4.0
|
||
| 15365 | * @category Util
|
||
| 15366 | * @param {*} value The value to return from the new function.
|
||
| 15367 | * @returns {Function} Returns the new constant function.
|
||
| 15368 | * @example
|
||
| 15369 | *
|
||
| 15370 | * var objects = _.times(2, _.constant({ 'a': 1 }));
|
||
| 15371 | *
|
||
| 15372 | * console.log(objects);
|
||
| 15373 | * // => [{ 'a': 1 }, { 'a': 1 }]
|
||
| 15374 | *
|
||
| 15375 | * console.log(objects[0] === objects[1]);
|
||
| 15376 | * // => true
|
||
| 15377 | */
|
||
| 15378 | function constant(value) { |
||
| 15379 | return function() { |
||
| 15380 | return value;
|
||
| 15381 | }; |
||
| 15382 | } |
||
| 15383 | |||
| 15384 | /**
|
||
| 15385 | * Checks `value` to determine whether a default value should be returned in
|
||
| 15386 | * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
|
||
| 15387 | * or `undefined`.
|
||
| 15388 | *
|
||
| 15389 | * @static
|
||
| 15390 | * @memberOf _
|
||
| 15391 | * @since 4.14.0
|
||
| 15392 | * @category Util
|
||
| 15393 | * @param {*} value The value to check.
|
||
| 15394 | * @param {*} defaultValue The default value.
|
||
| 15395 | * @returns {*} Returns the resolved value.
|
||
| 15396 | * @example
|
||
| 15397 | *
|
||
| 15398 | * _.defaultTo(1, 10);
|
||
| 15399 | * // => 1
|
||
| 15400 | *
|
||
| 15401 | * _.defaultTo(undefined, 10);
|
||
| 15402 | * // => 10
|
||
| 15403 | */
|
||
| 15404 | function defaultTo(value, defaultValue) { |
||
| 15405 | return (value == null || value !== value) ? defaultValue : value; |
||
| 15406 | } |
||
| 15407 | |||
| 15408 | /**
|
||
| 15409 | * Creates a function that returns the result of invoking the given functions
|
||
| 15410 | * with the `this` binding of the created function, where each successive
|
||
| 15411 | * invocation is supplied the return value of the previous.
|
||
| 15412 | *
|
||
| 15413 | * @static
|
||
| 15414 | * @memberOf _
|
||
| 15415 | * @since 3.0.0
|
||
| 15416 | * @category Util
|
||
| 15417 | * @param {...(Function|Function[])} [funcs] The functions to invoke.
|
||
| 15418 | * @returns {Function} Returns the new composite function.
|
||
| 15419 | * @see _.flowRight
|
||
| 15420 | * @example
|
||
| 15421 | *
|
||
| 15422 | * function square(n) {
|
||
| 15423 | * return n * n;
|
||
| 15424 | * }
|
||
| 15425 | *
|
||
| 15426 | * var addSquare = _.flow([_.add, square]);
|
||
| 15427 | * addSquare(1, 2);
|
||
| 15428 | * // => 9
|
||
| 15429 | */
|
||
| 15430 | var flow = createFlow();
|
||
| 15431 | |||
| 15432 | /**
|
||
| 15433 | * This method is like `_.flow` except that it creates a function that
|
||
| 15434 | * invokes the given functions from right to left.
|
||
| 15435 | *
|
||
| 15436 | * @static
|
||
| 15437 | * @since 3.0.0
|
||
| 15438 | * @memberOf _
|
||
| 15439 | * @category Util
|
||
| 15440 | * @param {...(Function|Function[])} [funcs] The functions to invoke.
|
||
| 15441 | * @returns {Function} Returns the new composite function.
|
||
| 15442 | * @see _.flow
|
||
| 15443 | * @example
|
||
| 15444 | *
|
||
| 15445 | * function square(n) {
|
||
| 15446 | * return n * n;
|
||
| 15447 | * }
|
||
| 15448 | *
|
||
| 15449 | * var addSquare = _.flowRight([square, _.add]);
|
||
| 15450 | * addSquare(1, 2);
|
||
| 15451 | * // => 9
|
||
| 15452 | */
|
||
| 15453 | var flowRight = createFlow(true); |
||
| 15454 | |||
| 15455 | /**
|
||
| 15456 | * This method returns the first argument it receives.
|
||
| 15457 | *
|
||
| 15458 | * @static
|
||
| 15459 | * @since 0.1.0
|
||
| 15460 | * @memberOf _
|
||
| 15461 | * @category Util
|
||
| 15462 | * @param {*} value Any value.
|
||
| 15463 | * @returns {*} Returns `value`.
|
||
| 15464 | * @example
|
||
| 15465 | *
|
||
| 15466 | * var object = { 'a': 1 };
|
||
| 15467 | *
|
||
| 15468 | * console.log(_.identity(object) === object);
|
||
| 15469 | * // => true
|
||
| 15470 | */
|
||
| 15471 | function identity(value) { |
||
| 15472 | return value;
|
||
| 15473 | } |
||
| 15474 | |||
| 15475 | /**
|
||
| 15476 | * Creates a function that invokes `func` with the arguments of the created
|
||
| 15477 | * function. If `func` is a property name, the created function returns the
|
||
| 15478 | * property value for a given element. If `func` is an array or object, the
|
||
| 15479 | * created function returns `true` for elements that contain the equivalent
|
||
| 15480 | * source properties, otherwise it returns `false`.
|
||
| 15481 | *
|
||
| 15482 | * @static
|
||
| 15483 | * @since 4.0.0
|
||
| 15484 | * @memberOf _
|
||
| 15485 | * @category Util
|
||
| 15486 | * @param {*} [func=_.identity] The value to convert to a callback.
|
||
| 15487 | * @returns {Function} Returns the callback.
|
||
| 15488 | * @example
|
||
| 15489 | *
|
||
| 15490 | * var users = [
|
||
| 15491 | * { 'user': 'barney', 'age': 36, 'active': true },
|
||
| 15492 | * { 'user': 'fred', 'age': 40, 'active': false }
|
||
| 15493 | * ];
|
||
| 15494 | *
|
||
| 15495 | * // The `_.matches` iteratee shorthand.
|
||
| 15496 | * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
|
||
| 15497 | * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
|
||
| 15498 | *
|
||
| 15499 | * // The `_.matchesProperty` iteratee shorthand.
|
||
| 15500 | * _.filter(users, _.iteratee(['user', 'fred']));
|
||
| 15501 | * // => [{ 'user': 'fred', 'age': 40 }]
|
||
| 15502 | *
|
||
| 15503 | * // The `_.property` iteratee shorthand.
|
||
| 15504 | * _.map(users, _.iteratee('user'));
|
||
| 15505 | * // => ['barney', 'fred']
|
||
| 15506 | *
|
||
| 15507 | * // Create custom iteratee shorthands.
|
||
| 15508 | * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
|
||
| 15509 | * return !_.isRegExp(func) ? iteratee(func) : function(string) {
|
||
| 15510 | * return func.test(string);
|
||
| 15511 | * };
|
||
| 15512 | * });
|
||
| 15513 | *
|
||
| 15514 | * _.filter(['abc', 'def'], /ef/);
|
||
| 15515 | * // => ['def']
|
||
| 15516 | */
|
||
| 15517 | function iteratee(func) { |
||
| 15518 | return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG)); |
||
| 15519 | } |
||
| 15520 | |||
| 15521 | /**
|
||
| 15522 | * Creates a function that performs a partial deep comparison between a given
|
||
| 15523 | * object and `source`, returning `true` if the given object has equivalent
|
||
| 15524 | * property values, else `false`.
|
||
| 15525 | *
|
||
| 15526 | * **Note:** The created function is equivalent to `_.isMatch` with `source`
|
||
| 15527 | * partially applied.
|
||
| 15528 | *
|
||
| 15529 | * Partial comparisons will match empty array and empty object `source`
|
||
| 15530 | * values against any array or object value, respectively. See `_.isEqual`
|
||
| 15531 | * for a list of supported value comparisons.
|
||
| 15532 | *
|
||
| 15533 | * @static
|
||
| 15534 | * @memberOf _
|
||
| 15535 | * @since 3.0.0
|
||
| 15536 | * @category Util
|
||
| 15537 | * @param {Object} source The object of property values to match.
|
||
| 15538 | * @returns {Function} Returns the new spec function.
|
||
| 15539 | * @example
|
||
| 15540 | *
|
||
| 15541 | * var objects = [
|
||
| 15542 | * { 'a': 1, 'b': 2, 'c': 3 },
|
||
| 15543 | * { 'a': 4, 'b': 5, 'c': 6 }
|
||
| 15544 | * ];
|
||
| 15545 | *
|
||
| 15546 | * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
|
||
| 15547 | * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
|
||
| 15548 | */
|
||
| 15549 | function matches(source) { |
||
| 15550 | return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
|
||
| 15551 | } |
||
| 15552 | |||
| 15553 | /**
|
||
| 15554 | * Creates a function that performs a partial deep comparison between the
|
||
| 15555 | * value at `path` of a given object to `srcValue`, returning `true` if the
|
||
| 15556 | * object value is equivalent, else `false`.
|
||
| 15557 | *
|
||
| 15558 | * **Note:** Partial comparisons will match empty array and empty object
|
||
| 15559 | * `srcValue` values against any array or object value, respectively. See
|
||
| 15560 | * `_.isEqual` for a list of supported value comparisons.
|
||
| 15561 | *
|
||
| 15562 | * @static
|
||
| 15563 | * @memberOf _
|
||
| 15564 | * @since 3.2.0
|
||
| 15565 | * @category Util
|
||
| 15566 | * @param {Array|string} path The path of the property to get.
|
||
| 15567 | * @param {*} srcValue The value to match.
|
||
| 15568 | * @returns {Function} Returns the new spec function.
|
||
| 15569 | * @example
|
||
| 15570 | *
|
||
| 15571 | * var objects = [
|
||
| 15572 | * { 'a': 1, 'b': 2, 'c': 3 },
|
||
| 15573 | * { 'a': 4, 'b': 5, 'c': 6 }
|
||
| 15574 | * ];
|
||
| 15575 | *
|
||
| 15576 | * _.find(objects, _.matchesProperty('a', 4));
|
||
| 15577 | * // => { 'a': 4, 'b': 5, 'c': 6 }
|
||
| 15578 | */
|
||
| 15579 | function matchesProperty(path, srcValue) { |
||
| 15580 | return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
|
||
| 15581 | } |
||
| 15582 | |||
| 15583 | /**
|
||
| 15584 | * Creates a function that invokes the method at `path` of a given object.
|
||
| 15585 | * Any additional arguments are provided to the invoked method.
|
||
| 15586 | *
|
||
| 15587 | * @static
|
||
| 15588 | * @memberOf _
|
||
| 15589 | * @since 3.7.0
|
||
| 15590 | * @category Util
|
||
| 15591 | * @param {Array|string} path The path of the method to invoke.
|
||
| 15592 | * @param {...*} [args] The arguments to invoke the method with.
|
||
| 15593 | * @returns {Function} Returns the new invoker function.
|
||
| 15594 | * @example
|
||
| 15595 | *
|
||
| 15596 | * var objects = [
|
||
| 15597 | * { 'a': { 'b': _.constant(2) } },
|
||
| 15598 | * { 'a': { 'b': _.constant(1) } }
|
||
| 15599 | * ];
|
||
| 15600 | *
|
||
| 15601 | * _.map(objects, _.method('a.b'));
|
||
| 15602 | * // => [2, 1]
|
||
| 15603 | *
|
||
| 15604 | * _.map(objects, _.method(['a', 'b']));
|
||
| 15605 | * // => [2, 1]
|
||
| 15606 | */
|
||
| 15607 | var method = baseRest(function(path, args) { |
||
| 15608 | return function(object) { |
||
| 15609 | return baseInvoke(object, path, args);
|
||
| 15610 | }; |
||
| 15611 | }); |
||
| 15612 | |||
| 15613 | /**
|
||
| 15614 | * The opposite of `_.method`; this method creates a function that invokes
|
||
| 15615 | * the method at a given path of `object`. Any additional arguments are
|
||
| 15616 | * provided to the invoked method.
|
||
| 15617 | *
|
||
| 15618 | * @static
|
||
| 15619 | * @memberOf _
|
||
| 15620 | * @since 3.7.0
|
||
| 15621 | * @category Util
|
||
| 15622 | * @param {Object} object The object to query.
|
||
| 15623 | * @param {...*} [args] The arguments to invoke the method with.
|
||
| 15624 | * @returns {Function} Returns the new invoker function.
|
||
| 15625 | * @example
|
||
| 15626 | *
|
||
| 15627 | * var array = _.times(3, _.constant),
|
||
| 15628 | * object = { 'a': array, 'b': array, 'c': array };
|
||
| 15629 | *
|
||
| 15630 | * _.map(['a[2]', 'c[0]'], _.methodOf(object));
|
||
| 15631 | * // => [2, 0]
|
||
| 15632 | *
|
||
| 15633 | * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
|
||
| 15634 | * // => [2, 0]
|
||
| 15635 | */
|
||
| 15636 | var methodOf = baseRest(function(object, args) { |
||
| 15637 | return function(path) { |
||
| 15638 | return baseInvoke(object, path, args);
|
||
| 15639 | }; |
||
| 15640 | }); |
||
| 15641 | |||
| 15642 | /**
|
||
| 15643 | * Adds all own enumerable string keyed function properties of a source
|
||
| 15644 | * object to the destination object. If `object` is a function, then methods
|
||
| 15645 | * are added to its prototype as well.
|
||
| 15646 | *
|
||
| 15647 | * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
|
||
| 15648 | * avoid conflicts caused by modifying the original.
|
||
| 15649 | *
|
||
| 15650 | * @static
|
||
| 15651 | * @since 0.1.0
|
||
| 15652 | * @memberOf _
|
||
| 15653 | * @category Util
|
||
| 15654 | * @param {Function|Object} [object=lodash] The destination object.
|
||
| 15655 | * @param {Object} source The object of functions to add.
|
||
| 15656 | * @param {Object} [options={}] The options object.
|
||
| 15657 | * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
|
||
| 15658 | * @returns {Function|Object} Returns `object`.
|
||
| 15659 | * @example
|
||
| 15660 | *
|
||
| 15661 | * function vowels(string) {
|
||
| 15662 | * return _.filter(string, function(v) {
|
||
| 15663 | * return /[aeiou]/i.test(v);
|
||
| 15664 | * });
|
||
| 15665 | * }
|
||
| 15666 | *
|
||
| 15667 | * _.mixin({ 'vowels': vowels });
|
||
| 15668 | * _.vowels('fred');
|
||
| 15669 | * // => ['e']
|
||
| 15670 | *
|
||
| 15671 | * _('fred').vowels().value();
|
||
| 15672 | * // => ['e']
|
||
| 15673 | *
|
||
| 15674 | * _.mixin({ 'vowels': vowels }, { 'chain': false });
|
||
| 15675 | * _('fred').vowels();
|
||
| 15676 | * // => ['e']
|
||
| 15677 | */
|
||
| 15678 | function mixin(object, source, options) { |
||
| 15679 | var props = keys(source),
|
||
| 15680 | methodNames = baseFunctions(source, props); |
||
| 15681 | |||
| 15682 | if (options == null && |
||
| 15683 | !(isObject(source) && (methodNames.length || !props.length))) {
|
||
| 15684 | options = source; |
||
| 15685 | source = object; |
||
| 15686 | object = this;
|
||
| 15687 | methodNames = baseFunctions(source, keys(source)); |
||
| 15688 | } |
||
| 15689 | var chain = !(isObject(options) && 'chain' in options) || !!options.chain, |
||
| 15690 | isFunc = isFunction(object); |
||
| 15691 | |||
| 15692 | arrayEach(methodNames, function(methodName) {
|
||
| 15693 | var func = source[methodName];
|
||
| 15694 | object[methodName] = func; |
||
| 15695 | if (isFunc) {
|
||
| 15696 | object.prototype[methodName] = function() {
|
||
| 15697 | var chainAll = this.__chain__; |
||
| 15698 | if (chain || chainAll) {
|
||
| 15699 | var result = object(this.__wrapped__), |
||
| 15700 | actions = result.__actions__ = copyArray(this.__actions__);
|
||
| 15701 | |||
| 15702 | actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
||
| 15703 | result.__chain__ = chainAll; |
||
| 15704 | return result;
|
||
| 15705 | } |
||
| 15706 | return func.apply(object, arrayPush([this.value()], arguments)); |
||
| 15707 | }; |
||
| 15708 | } |
||
| 15709 | }); |
||
| 15710 | |||
| 15711 | return object;
|
||
| 15712 | } |
||
| 15713 | |||
| 15714 | /**
|
||
| 15715 | * Reverts the `_` variable to its previous value and returns a reference to
|
||
| 15716 | * the `lodash` function.
|
||
| 15717 | *
|
||
| 15718 | * @static
|
||
| 15719 | * @since 0.1.0
|
||
| 15720 | * @memberOf _
|
||
| 15721 | * @category Util
|
||
| 15722 | * @returns {Function} Returns the `lodash` function.
|
||
| 15723 | * @example
|
||
| 15724 | *
|
||
| 15725 | * var lodash = _.noConflict();
|
||
| 15726 | */
|
||
| 15727 | function noConflict() { |
||
| 15728 | if (root._ === this) { |
||
| 15729 | root._ = oldDash; |
||
| 15730 | } |
||
| 15731 | return this; |
||
| 15732 | } |
||
| 15733 | |||
| 15734 | /**
|
||
| 15735 | * This method returns `undefined`.
|
||
| 15736 | *
|
||
| 15737 | * @static
|
||
| 15738 | * @memberOf _
|
||
| 15739 | * @since 2.3.0
|
||
| 15740 | * @category Util
|
||
| 15741 | * @example
|
||
| 15742 | *
|
||
| 15743 | * _.times(2, _.noop);
|
||
| 15744 | * // => [undefined, undefined]
|
||
| 15745 | */
|
||
| 15746 | function noop() { |
||
| 15747 | // No operation performed.
|
||
| 15748 | } |
||
| 15749 | |||
| 15750 | /**
|
||
| 15751 | * Creates a function that gets the argument at index `n`. If `n` is negative,
|
||
| 15752 | * the nth argument from the end is returned.
|
||
| 15753 | *
|
||
| 15754 | * @static
|
||
| 15755 | * @memberOf _
|
||
| 15756 | * @since 4.0.0
|
||
| 15757 | * @category Util
|
||
| 15758 | * @param {number} [n=0] The index of the argument to return.
|
||
| 15759 | * @returns {Function} Returns the new pass-thru function.
|
||
| 15760 | * @example
|
||
| 15761 | *
|
||
| 15762 | * var func = _.nthArg(1);
|
||
| 15763 | * func('a', 'b', 'c', 'd');
|
||
| 15764 | * // => 'b'
|
||
| 15765 | *
|
||
| 15766 | * var func = _.nthArg(-2);
|
||
| 15767 | * func('a', 'b', 'c', 'd');
|
||
| 15768 | * // => 'c'
|
||
| 15769 | */
|
||
| 15770 | function nthArg(n) { |
||
| 15771 | n = toInteger(n); |
||
| 15772 | return baseRest(function(args) { |
||
| 15773 | return baseNth(args, n);
|
||
| 15774 | }); |
||
| 15775 | } |
||
| 15776 | |||
| 15777 | /**
|
||
| 15778 | * Creates a function that invokes `iteratees` with the arguments it receives
|
||
| 15779 | * and returns their results.
|
||
| 15780 | *
|
||
| 15781 | * @static
|
||
| 15782 | * @memberOf _
|
||
| 15783 | * @since 4.0.0
|
||
| 15784 | * @category Util
|
||
| 15785 | * @param {...(Function|Function[])} [iteratees=[_.identity]]
|
||
| 15786 | * The iteratees to invoke.
|
||
| 15787 | * @returns {Function} Returns the new function.
|
||
| 15788 | * @example
|
||
| 15789 | *
|
||
| 15790 | * var func = _.over([Math.max, Math.min]);
|
||
| 15791 | *
|
||
| 15792 | * func(1, 2, 3, 4);
|
||
| 15793 | * // => [4, 1]
|
||
| 15794 | */
|
||
| 15795 | var over = createOver(arrayMap);
|
||
| 15796 | |||
| 15797 | /**
|
||
| 15798 | * Creates a function that checks if **all** of the `predicates` return
|
||
| 15799 | * truthy when invoked with the arguments it receives.
|
||
| 15800 | *
|
||
| 15801 | * @static
|
||
| 15802 | * @memberOf _
|
||
| 15803 | * @since 4.0.0
|
||
| 15804 | * @category Util
|
||
| 15805 | * @param {...(Function|Function[])} [predicates=[_.identity]]
|
||
| 15806 | * The predicates to check.
|
||
| 15807 | * @returns {Function} Returns the new function.
|
||
| 15808 | * @example
|
||
| 15809 | *
|
||
| 15810 | * var func = _.overEvery([Boolean, isFinite]);
|
||
| 15811 | *
|
||
| 15812 | * func('1');
|
||
| 15813 | * // => true
|
||
| 15814 | *
|
||
| 15815 | * func(null);
|
||
| 15816 | * // => false
|
||
| 15817 | *
|
||
| 15818 | * func(NaN);
|
||
| 15819 | * // => false
|
||
| 15820 | */
|
||
| 15821 | var overEvery = createOver(arrayEvery);
|
||
| 15822 | |||
| 15823 | /**
|
||
| 15824 | * Creates a function that checks if **any** of the `predicates` return
|
||
| 15825 | * truthy when invoked with the arguments it receives.
|
||
| 15826 | *
|
||
| 15827 | * @static
|
||
| 15828 | * @memberOf _
|
||
| 15829 | * @since 4.0.0
|
||
| 15830 | * @category Util
|
||
| 15831 | * @param {...(Function|Function[])} [predicates=[_.identity]]
|
||
| 15832 | * The predicates to check.
|
||
| 15833 | * @returns {Function} Returns the new function.
|
||
| 15834 | * @example
|
||
| 15835 | *
|
||
| 15836 | * var func = _.overSome([Boolean, isFinite]);
|
||
| 15837 | *
|
||
| 15838 | * func('1');
|
||
| 15839 | * // => true
|
||
| 15840 | *
|
||
| 15841 | * func(null);
|
||
| 15842 | * // => true
|
||
| 15843 | *
|
||
| 15844 | * func(NaN);
|
||
| 15845 | * // => false
|
||
| 15846 | */
|
||
| 15847 | var overSome = createOver(arraySome);
|
||
| 15848 | |||
| 15849 | /**
|
||
| 15850 | * Creates a function that returns the value at `path` of a given object.
|
||
| 15851 | *
|
||
| 15852 | * @static
|
||
| 15853 | * @memberOf _
|
||
| 15854 | * @since 2.4.0
|
||
| 15855 | * @category Util
|
||
| 15856 | * @param {Array|string} path The path of the property to get.
|
||
| 15857 | * @returns {Function} Returns the new accessor function.
|
||
| 15858 | * @example
|
||
| 15859 | *
|
||
| 15860 | * var objects = [
|
||
| 15861 | * { 'a': { 'b': 2 } },
|
||
| 15862 | * { 'a': { 'b': 1 } }
|
||
| 15863 | * ];
|
||
| 15864 | *
|
||
| 15865 | * _.map(objects, _.property('a.b'));
|
||
| 15866 | * // => [2, 1]
|
||
| 15867 | *
|
||
| 15868 | * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
|
||
| 15869 | * // => [1, 2]
|
||
| 15870 | */
|
||
| 15871 | function property(path) { |
||
| 15872 | return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
|
||
| 15873 | } |
||
| 15874 | |||
| 15875 | /**
|
||
| 15876 | * The opposite of `_.property`; this method creates a function that returns
|
||
| 15877 | * the value at a given path of `object`.
|
||
| 15878 | *
|
||
| 15879 | * @static
|
||
| 15880 | * @memberOf _
|
||
| 15881 | * @since 3.0.0
|
||
| 15882 | * @category Util
|
||
| 15883 | * @param {Object} object The object to query.
|
||
| 15884 | * @returns {Function} Returns the new accessor function.
|
||
| 15885 | * @example
|
||
| 15886 | *
|
||
| 15887 | * var array = [0, 1, 2],
|
||
| 15888 | * object = { 'a': array, 'b': array, 'c': array };
|
||
| 15889 | *
|
||
| 15890 | * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
|
||
| 15891 | * // => [2, 0]
|
||
| 15892 | *
|
||
| 15893 | * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
|
||
| 15894 | * // => [2, 0]
|
||
| 15895 | */
|
||
| 15896 | function propertyOf(object) { |
||
| 15897 | return function(path) { |
||
| 15898 | return object == null ? undefined : baseGet(object, path); |
||
| 15899 | }; |
||
| 15900 | } |
||
| 15901 | |||
| 15902 | /**
|
||
| 15903 | * Creates an array of numbers (positive and/or negative) progressing from
|
||
| 15904 | * `start` up to, but not including, `end`. A step of `-1` is used if a negative
|
||
| 15905 | * `start` is specified without an `end` or `step`. If `end` is not specified,
|
||
| 15906 | * it's set to `start` with `start` then set to `0`.
|
||
| 15907 | *
|
||
| 15908 | * **Note:** JavaScript follows the IEEE-754 standard for resolving
|
||
| 15909 | * floating-point values which can produce unexpected results.
|
||
| 15910 | *
|
||
| 15911 | * @static
|
||
| 15912 | * @since 0.1.0
|
||
| 15913 | * @memberOf _
|
||
| 15914 | * @category Util
|
||
| 15915 | * @param {number} [start=0] The start of the range.
|
||
| 15916 | * @param {number} end The end of the range.
|
||
| 15917 | * @param {number} [step=1] The value to increment or decrement by.
|
||
| 15918 | * @returns {Array} Returns the range of numbers.
|
||
| 15919 | * @see _.inRange, _.rangeRight
|
||
| 15920 | * @example
|
||
| 15921 | *
|
||
| 15922 | * _.range(4);
|
||
| 15923 | * // => [0, 1, 2, 3]
|
||
| 15924 | *
|
||
| 15925 | * _.range(-4);
|
||
| 15926 | * // => [0, -1, -2, -3]
|
||
| 15927 | *
|
||
| 15928 | * _.range(1, 5);
|
||
| 15929 | * // => [1, 2, 3, 4]
|
||
| 15930 | *
|
||
| 15931 | * _.range(0, 20, 5);
|
||
| 15932 | * // => [0, 5, 10, 15]
|
||
| 15933 | *
|
||
| 15934 | * _.range(0, -4, -1);
|
||
| 15935 | * // => [0, -1, -2, -3]
|
||
| 15936 | *
|
||
| 15937 | * _.range(1, 4, 0);
|
||
| 15938 | * // => [1, 1, 1]
|
||
| 15939 | *
|
||
| 15940 | * _.range(0);
|
||
| 15941 | * // => []
|
||
| 15942 | */
|
||
| 15943 | var range = createRange();
|
||
| 15944 | |||
| 15945 | /**
|
||
| 15946 | * This method is like `_.range` except that it populates values in
|
||
| 15947 | * descending order.
|
||
| 15948 | *
|
||
| 15949 | * @static
|
||
| 15950 | * @memberOf _
|
||
| 15951 | * @since 4.0.0
|
||
| 15952 | * @category Util
|
||
| 15953 | * @param {number} [start=0] The start of the range.
|
||
| 15954 | * @param {number} end The end of the range.
|
||
| 15955 | * @param {number} [step=1] The value to increment or decrement by.
|
||
| 15956 | * @returns {Array} Returns the range of numbers.
|
||
| 15957 | * @see _.inRange, _.range
|
||
| 15958 | * @example
|
||
| 15959 | *
|
||
| 15960 | * _.rangeRight(4);
|
||
| 15961 | * // => [3, 2, 1, 0]
|
||
| 15962 | *
|
||
| 15963 | * _.rangeRight(-4);
|
||
| 15964 | * // => [-3, -2, -1, 0]
|
||
| 15965 | *
|
||
| 15966 | * _.rangeRight(1, 5);
|
||
| 15967 | * // => [4, 3, 2, 1]
|
||
| 15968 | *
|
||
| 15969 | * _.rangeRight(0, 20, 5);
|
||
| 15970 | * // => [15, 10, 5, 0]
|
||
| 15971 | *
|
||
| 15972 | * _.rangeRight(0, -4, -1);
|
||
| 15973 | * // => [-3, -2, -1, 0]
|
||
| 15974 | *
|
||
| 15975 | * _.rangeRight(1, 4, 0);
|
||
| 15976 | * // => [1, 1, 1]
|
||
| 15977 | *
|
||
| 15978 | * _.rangeRight(0);
|
||
| 15979 | * // => []
|
||
| 15980 | */
|
||
| 15981 | var rangeRight = createRange(true); |
||
| 15982 | |||
| 15983 | /**
|
||
| 15984 | * This method returns a new empty array.
|
||
| 15985 | *
|
||
| 15986 | * @static
|
||
| 15987 | * @memberOf _
|
||
| 15988 | * @since 4.13.0
|
||
| 15989 | * @category Util
|
||
| 15990 | * @returns {Array} Returns the new empty array.
|
||
| 15991 | * @example
|
||
| 15992 | *
|
||
| 15993 | * var arrays = _.times(2, _.stubArray);
|
||
| 15994 | *
|
||
| 15995 | * console.log(arrays);
|
||
| 15996 | * // => [[], []]
|
||
| 15997 | *
|
||
| 15998 | * console.log(arrays[0] === arrays[1]);
|
||
| 15999 | * // => false
|
||
| 16000 | */
|
||
| 16001 | function stubArray() { |
||
| 16002 | return [];
|
||
| 16003 | } |
||
| 16004 | |||
| 16005 | /**
|
||
| 16006 | * This method returns `false`.
|
||
| 16007 | *
|
||
| 16008 | * @static
|
||
| 16009 | * @memberOf _
|
||
| 16010 | * @since 4.13.0
|
||
| 16011 | * @category Util
|
||
| 16012 | * @returns {boolean} Returns `false`.
|
||
| 16013 | * @example
|
||
| 16014 | *
|
||
| 16015 | * _.times(2, _.stubFalse);
|
||
| 16016 | * // => [false, false]
|
||
| 16017 | */
|
||
| 16018 | function stubFalse() { |
||
| 16019 | return false; |
||
| 16020 | } |
||
| 16021 | |||
| 16022 | /**
|
||
| 16023 | * This method returns a new empty object.
|
||
| 16024 | *
|
||
| 16025 | * @static
|
||
| 16026 | * @memberOf _
|
||
| 16027 | * @since 4.13.0
|
||
| 16028 | * @category Util
|
||
| 16029 | * @returns {Object} Returns the new empty object.
|
||
| 16030 | * @example
|
||
| 16031 | *
|
||
| 16032 | * var objects = _.times(2, _.stubObject);
|
||
| 16033 | *
|
||
| 16034 | * console.log(objects);
|
||
| 16035 | * // => [{}, {}]
|
||
| 16036 | *
|
||
| 16037 | * console.log(objects[0] === objects[1]);
|
||
| 16038 | * // => false
|
||
| 16039 | */
|
||
| 16040 | function stubObject() { |
||
| 16041 | return {};
|
||
| 16042 | } |
||
| 16043 | |||
| 16044 | /**
|
||
| 16045 | * This method returns an empty string.
|
||
| 16046 | *
|
||
| 16047 | * @static
|
||
| 16048 | * @memberOf _
|
||
| 16049 | * @since 4.13.0
|
||
| 16050 | * @category Util
|
||
| 16051 | * @returns {string} Returns the empty string.
|
||
| 16052 | * @example
|
||
| 16053 | *
|
||
| 16054 | * _.times(2, _.stubString);
|
||
| 16055 | * // => ['', '']
|
||
| 16056 | */
|
||
| 16057 | function stubString() { |
||
| 16058 | return ''; |
||
| 16059 | } |
||
| 16060 | |||
| 16061 | /**
|
||
| 16062 | * This method returns `true`.
|
||
| 16063 | *
|
||
| 16064 | * @static
|
||
| 16065 | * @memberOf _
|
||
| 16066 | * @since 4.13.0
|
||
| 16067 | * @category Util
|
||
| 16068 | * @returns {boolean} Returns `true`.
|
||
| 16069 | * @example
|
||
| 16070 | *
|
||
| 16071 | * _.times(2, _.stubTrue);
|
||
| 16072 | * // => [true, true]
|
||
| 16073 | */
|
||
| 16074 | function stubTrue() { |
||
| 16075 | return true; |
||
| 16076 | } |
||
| 16077 | |||
| 16078 | /**
|
||
| 16079 | * Invokes the iteratee `n` times, returning an array of the results of
|
||
| 16080 | * each invocation. The iteratee is invoked with one argument; (index).
|
||
| 16081 | *
|
||
| 16082 | * @static
|
||
| 16083 | * @since 0.1.0
|
||
| 16084 | * @memberOf _
|
||
| 16085 | * @category Util
|
||
| 16086 | * @param {number} n The number of times to invoke `iteratee`.
|
||
| 16087 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
||
| 16088 | * @returns {Array} Returns the array of results.
|
||
| 16089 | * @example
|
||
| 16090 | *
|
||
| 16091 | * _.times(3, String);
|
||
| 16092 | * // => ['0', '1', '2']
|
||
| 16093 | *
|
||
| 16094 | * _.times(4, _.constant(0));
|
||
| 16095 | * // => [0, 0, 0, 0]
|
||
| 16096 | */
|
||
| 16097 | function times(n, iteratee) { |
||
| 16098 | n = toInteger(n); |
||
| 16099 | if (n < 1 || n > MAX_SAFE_INTEGER) { |
||
| 16100 | return [];
|
||
| 16101 | } |
||
| 16102 | var index = MAX_ARRAY_LENGTH,
|
||
| 16103 | length = nativeMin(n, MAX_ARRAY_LENGTH); |
||
| 16104 | |||
| 16105 | iteratee = getIteratee(iteratee); |
||
| 16106 | n -= MAX_ARRAY_LENGTH; |
||
| 16107 | |||
| 16108 | var result = baseTimes(length, iteratee);
|
||
| 16109 | while (++index < n) {
|
||
| 16110 | iteratee(index); |
||
| 16111 | } |
||
| 16112 | return result;
|
||
| 16113 | } |
||
| 16114 | |||
| 16115 | /**
|
||
| 16116 | * Converts `value` to a property path array.
|
||
| 16117 | *
|
||
| 16118 | * @static
|
||
| 16119 | * @memberOf _
|
||
| 16120 | * @since 4.0.0
|
||
| 16121 | * @category Util
|
||
| 16122 | * @param {*} value The value to convert.
|
||
| 16123 | * @returns {Array} Returns the new property path array.
|
||
| 16124 | * @example
|
||
| 16125 | *
|
||
| 16126 | * _.toPath('a.b.c');
|
||
| 16127 | * // => ['a', 'b', 'c']
|
||
| 16128 | *
|
||
| 16129 | * _.toPath('a[0].b.c');
|
||
| 16130 | * // => ['a', '0', 'b', 'c']
|
||
| 16131 | */
|
||
| 16132 | function toPath(value) { |
||
| 16133 | if (isArray(value)) {
|
||
| 16134 | return arrayMap(value, toKey);
|
||
| 16135 | } |
||
| 16136 | return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
|
||
| 16137 | } |
||
| 16138 | |||
| 16139 | /**
|
||
| 16140 | * Generates a unique ID. If `prefix` is given, the ID is appended to it.
|
||
| 16141 | *
|
||
| 16142 | * @static
|
||
| 16143 | * @since 0.1.0
|
||
| 16144 | * @memberOf _
|
||
| 16145 | * @category Util
|
||
| 16146 | * @param {string} [prefix=''] The value to prefix the ID with.
|
||
| 16147 | * @returns {string} Returns the unique ID.
|
||
| 16148 | * @example
|
||
| 16149 | *
|
||
| 16150 | * _.uniqueId('contact_');
|
||
| 16151 | * // => 'contact_104'
|
||
| 16152 | *
|
||
| 16153 | * _.uniqueId();
|
||
| 16154 | * // => '105'
|
||
| 16155 | */
|
||
| 16156 | function uniqueId(prefix) { |
||
| 16157 | var id = ++idCounter;
|
||
| 16158 | return toString(prefix) + id;
|
||
| 16159 | } |
||
| 16160 | |||
| 16161 | /*------------------------------------------------------------------------*/
|
||
| 16162 | |||
| 16163 | /**
|
||
| 16164 | * Adds two numbers.
|
||
| 16165 | *
|
||
| 16166 | * @static
|
||
| 16167 | * @memberOf _
|
||
| 16168 | * @since 3.4.0
|
||
| 16169 | * @category Math
|
||
| 16170 | * @param {number} augend The first number in an addition.
|
||
| 16171 | * @param {number} addend The second number in an addition.
|
||
| 16172 | * @returns {number} Returns the total.
|
||
| 16173 | * @example
|
||
| 16174 | *
|
||
| 16175 | * _.add(6, 4);
|
||
| 16176 | * // => 10
|
||
| 16177 | */
|
||
| 16178 | var add = createMathOperation(function(augend, addend) { |
||
| 16179 | return augend + addend;
|
||
| 16180 | }, 0);
|
||
| 16181 | |||
| 16182 | /**
|
||
| 16183 | * Computes `number` rounded up to `precision`.
|
||
| 16184 | *
|
||
| 16185 | * @static
|
||
| 16186 | * @memberOf _
|
||
| 16187 | * @since 3.10.0
|
||
| 16188 | * @category Math
|
||
| 16189 | * @param {number} number The number to round up.
|
||
| 16190 | * @param {number} [precision=0] The precision to round up to.
|
||
| 16191 | * @returns {number} Returns the rounded up number.
|
||
| 16192 | * @example
|
||
| 16193 | *
|
||
| 16194 | * _.ceil(4.006);
|
||
| 16195 | * // => 5
|
||
| 16196 | *
|
||
| 16197 | * _.ceil(6.004, 2);
|
||
| 16198 | * // => 6.01
|
||
| 16199 | *
|
||
| 16200 | * _.ceil(6040, -2);
|
||
| 16201 | * // => 6100
|
||
| 16202 | */
|
||
| 16203 | var ceil = createRound('ceil'); |
||
| 16204 | |||
| 16205 | /**
|
||
| 16206 | * Divide two numbers.
|
||
| 16207 | *
|
||
| 16208 | * @static
|
||
| 16209 | * @memberOf _
|
||
| 16210 | * @since 4.7.0
|
||
| 16211 | * @category Math
|
||
| 16212 | * @param {number} dividend The first number in a division.
|
||
| 16213 | * @param {number} divisor The second number in a division.
|
||
| 16214 | * @returns {number} Returns the quotient.
|
||
| 16215 | * @example
|
||
| 16216 | *
|
||
| 16217 | * _.divide(6, 4);
|
||
| 16218 | * // => 1.5
|
||
| 16219 | */
|
||
| 16220 | var divide = createMathOperation(function(dividend, divisor) { |
||
| 16221 | return dividend / divisor;
|
||
| 16222 | }, 1);
|
||
| 16223 | |||
| 16224 | /**
|
||
| 16225 | * Computes `number` rounded down to `precision`.
|
||
| 16226 | *
|
||
| 16227 | * @static
|
||
| 16228 | * @memberOf _
|
||
| 16229 | * @since 3.10.0
|
||
| 16230 | * @category Math
|
||
| 16231 | * @param {number} number The number to round down.
|
||
| 16232 | * @param {number} [precision=0] The precision to round down to.
|
||
| 16233 | * @returns {number} Returns the rounded down number.
|
||
| 16234 | * @example
|
||
| 16235 | *
|
||
| 16236 | * _.floor(4.006);
|
||
| 16237 | * // => 4
|
||
| 16238 | *
|
||
| 16239 | * _.floor(0.046, 2);
|
||
| 16240 | * // => 0.04
|
||
| 16241 | *
|
||
| 16242 | * _.floor(4060, -2);
|
||
| 16243 | * // => 4000
|
||
| 16244 | */
|
||
| 16245 | var floor = createRound('floor'); |
||
| 16246 | |||
| 16247 | /**
|
||
| 16248 | * Computes the maximum value of `array`. If `array` is empty or falsey,
|
||
| 16249 | * `undefined` is returned.
|
||
| 16250 | *
|
||
| 16251 | * @static
|
||
| 16252 | * @since 0.1.0
|
||
| 16253 | * @memberOf _
|
||
| 16254 | * @category Math
|
||
| 16255 | * @param {Array} array The array to iterate over.
|
||
| 16256 | * @returns {*} Returns the maximum value.
|
||
| 16257 | * @example
|
||
| 16258 | *
|
||
| 16259 | * _.max([4, 2, 8, 6]);
|
||
| 16260 | * // => 8
|
||
| 16261 | *
|
||
| 16262 | * _.max([]);
|
||
| 16263 | * // => undefined
|
||
| 16264 | */
|
||
| 16265 | function max(array) { |
||
| 16266 | return (array && array.length)
|
||
| 16267 | ? baseExtremum(array, identity, baseGt) |
||
| 16268 | : undefined;
|
||
| 16269 | } |
||
| 16270 | |||
| 16271 | /**
|
||
| 16272 | * This method is like `_.max` except that it accepts `iteratee` which is
|
||
| 16273 | * invoked for each element in `array` to generate the criterion by which
|
||
| 16274 | * the value is ranked. The iteratee is invoked with one argument: (value).
|
||
| 16275 | *
|
||
| 16276 | * @static
|
||
| 16277 | * @memberOf _
|
||
| 16278 | * @since 4.0.0
|
||
| 16279 | * @category Math
|
||
| 16280 | * @param {Array} array The array to iterate over.
|
||
| 16281 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 16282 | * @returns {*} Returns the maximum value.
|
||
| 16283 | * @example
|
||
| 16284 | *
|
||
| 16285 | * var objects = [{ 'n': 1 }, { 'n': 2 }];
|
||
| 16286 | *
|
||
| 16287 | * _.maxBy(objects, function(o) { return o.n; });
|
||
| 16288 | * // => { 'n': 2 }
|
||
| 16289 | *
|
||
| 16290 | * // The `_.property` iteratee shorthand.
|
||
| 16291 | * _.maxBy(objects, 'n');
|
||
| 16292 | * // => { 'n': 2 }
|
||
| 16293 | */
|
||
| 16294 | function maxBy(array, iteratee) { |
||
| 16295 | return (array && array.length)
|
||
| 16296 | ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
|
||
| 16297 | : undefined;
|
||
| 16298 | } |
||
| 16299 | |||
| 16300 | /**
|
||
| 16301 | * Computes the mean of the values in `array`.
|
||
| 16302 | *
|
||
| 16303 | * @static
|
||
| 16304 | * @memberOf _
|
||
| 16305 | * @since 4.0.0
|
||
| 16306 | * @category Math
|
||
| 16307 | * @param {Array} array The array to iterate over.
|
||
| 16308 | * @returns {number} Returns the mean.
|
||
| 16309 | * @example
|
||
| 16310 | *
|
||
| 16311 | * _.mean([4, 2, 8, 6]);
|
||
| 16312 | * // => 5
|
||
| 16313 | */
|
||
| 16314 | function mean(array) { |
||
| 16315 | return baseMean(array, identity);
|
||
| 16316 | } |
||
| 16317 | |||
| 16318 | /**
|
||
| 16319 | * This method is like `_.mean` except that it accepts `iteratee` which is
|
||
| 16320 | * invoked for each element in `array` to generate the value to be averaged.
|
||
| 16321 | * The iteratee is invoked with one argument: (value).
|
||
| 16322 | *
|
||
| 16323 | * @static
|
||
| 16324 | * @memberOf _
|
||
| 16325 | * @since 4.7.0
|
||
| 16326 | * @category Math
|
||
| 16327 | * @param {Array} array The array to iterate over.
|
||
| 16328 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 16329 | * @returns {number} Returns the mean.
|
||
| 16330 | * @example
|
||
| 16331 | *
|
||
| 16332 | * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
|
||
| 16333 | *
|
||
| 16334 | * _.meanBy(objects, function(o) { return o.n; });
|
||
| 16335 | * // => 5
|
||
| 16336 | *
|
||
| 16337 | * // The `_.property` iteratee shorthand.
|
||
| 16338 | * _.meanBy(objects, 'n');
|
||
| 16339 | * // => 5
|
||
| 16340 | */
|
||
| 16341 | function meanBy(array, iteratee) { |
||
| 16342 | return baseMean(array, getIteratee(iteratee, 2)); |
||
| 16343 | } |
||
| 16344 | |||
| 16345 | /**
|
||
| 16346 | * Computes the minimum value of `array`. If `array` is empty or falsey,
|
||
| 16347 | * `undefined` is returned.
|
||
| 16348 | *
|
||
| 16349 | * @static
|
||
| 16350 | * @since 0.1.0
|
||
| 16351 | * @memberOf _
|
||
| 16352 | * @category Math
|
||
| 16353 | * @param {Array} array The array to iterate over.
|
||
| 16354 | * @returns {*} Returns the minimum value.
|
||
| 16355 | * @example
|
||
| 16356 | *
|
||
| 16357 | * _.min([4, 2, 8, 6]);
|
||
| 16358 | * // => 2
|
||
| 16359 | *
|
||
| 16360 | * _.min([]);
|
||
| 16361 | * // => undefined
|
||
| 16362 | */
|
||
| 16363 | function min(array) { |
||
| 16364 | return (array && array.length)
|
||
| 16365 | ? baseExtremum(array, identity, baseLt) |
||
| 16366 | : undefined;
|
||
| 16367 | } |
||
| 16368 | |||
| 16369 | /**
|
||
| 16370 | * This method is like `_.min` except that it accepts `iteratee` which is
|
||
| 16371 | * invoked for each element in `array` to generate the criterion by which
|
||
| 16372 | * the value is ranked. The iteratee is invoked with one argument: (value).
|
||
| 16373 | *
|
||
| 16374 | * @static
|
||
| 16375 | * @memberOf _
|
||
| 16376 | * @since 4.0.0
|
||
| 16377 | * @category Math
|
||
| 16378 | * @param {Array} array The array to iterate over.
|
||
| 16379 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
||
| 16380 | * @returns {*} Returns the minimum value.
|
||
| 16381 | * @example
|
||
| 16382 | *
|
||
| 16383 | * var objects = [{ 'n': 1 }, { 'n': 2 }];
|
||
| 16384 | *
|
||
| 16385 | * _.minBy(objects, function(o) { return o.n; });
|
||
| 16386 | * // => { 'n': 1 }
|
||
| 16387 | *
|
||
| 16388 | * // The `_.property` iteratee shorthand.
|
||
| 16389 | * _.minBy(objects, 'n');
|
||
| 16390 | * // => { 'n': 1 }
|
||
| 16391 | */
|
||
| 16392 | function minBy(array, iteratee) { |
||
| 16393 | return (array && array.length)
|
||
| 16394 | ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
|
||
| 16395 | : undefined;
|
||
| 16396 | } |
||
| 16397 | |||
| 16398 | /**
|
||
| 16399 | * Multiply two numbers.
|
||
| 16400 | *
|
||
| 16401 | * @static
|
||
| 16402 | * @memberOf _
|
||
| 16403 | * @since 4.7.0
|
||
| 16404 | * @category Math
|
||
| 16405 | * @param {number} multiplier The first number in a multiplication.
|
||
| 16406 | * @param {number} multiplicand The second number in a multiplication.
|
||
| 16407 | * @returns {number} Returns the product.
|
||
| 16408 | * @example
|
||
| 16409 | *
|
||
| 16410 | * _.multiply(6, 4);
|
||
| 16411 | * // => 24
|
||
| 16412 | */
|
||
| 16413 | var multiply = createMathOperation(function(multiplier, multiplicand) { |
||
| 16414 | return multiplier * multiplicand;
|
||
| 16415 | }, 1);
|
||
| 16416 | |||
| 16417 | /**
|
||
| 16418 | * Computes `number` rounded to `precision`.
|
||
| 16419 | *
|
||
| 16420 | * @static
|
||
| 16421 | * @memberOf _
|
||
| 16422 | * @since 3.10.0
|
||
| 16423 | * @category Math
|
||
| 16424 | * @param {number} number The number to round.
|
||
| 16425 | * @param {number} [precision=0] The precision to round to.
|
||
| 16426 | * @returns {number} Returns the rounded number.
|
||
| 16427 | * @example
|
||
| 16428 | *
|
||
| 16429 | * _.round(4.006);
|
||
| 16430 | * // => 4
|
||
| 16431 | *
|
||
| 16432 | * _.round(4.006, 2);
|
||
| 16433 | * // => 4.01
|
||
| 16434 | *
|
||
| 16435 | * _.round(4060, -2);
|
||
| 16436 | * // => 4100
|
||
| 16437 | */
|
||
| 16438 | var round = createRound('round'); |
||
| 16439 | |||
| 16440 | /**
|
||
| 16441 | * Subtract two numbers.
|
||
| 16442 | *
|
||
| 16443 | * @static
|
||
| 16444 | * @memberOf _
|
||
| 16445 | * @since 4.0.0
|
||
| 16446 | * @category Math
|
||
| 16447 | * @param {number} minuend The first number in a subtraction.
|
||
| 16448 | * @param {number} subtrahend The second number in a subtraction.
|
||
| 16449 | * @returns {number} Returns the difference.
|
||
| 16450 | * @example
|
||
| 16451 | *
|
||
| 16452 | * _.subtract(6, 4);
|
||
| 16453 | * // => 2
|
||
| 16454 | */
|
||
| 16455 | var subtract = createMathOperation(function(minuend, subtrahend) { |
||
| 16456 | return minuend - subtrahend;
|
||
| 16457 | }, 0);
|
||
| 16458 | |||
| 16459 | /**
|
||
| 16460 | * Computes the sum of the values in `array`.
|
||
| 16461 | *
|
||
| 16462 | * @static
|
||
| 16463 | * @memberOf _
|
||
| 16464 | * @since 3.4.0
|
||
| 16465 | * @category Math
|
||
| 16466 | * @param {Array} array The array to iterate over.
|
||
| 16467 | * @returns {number} Returns the sum.
|
||
| 16468 | * @example
|
||
| 16469 | *
|
||
| 16470 | * _.sum([4, 2, 8, 6]);
|
||
| 16471 | * // => 20
|
||
| 16472 | */
|
||
| 16473 | function sum(array) { |
||
| 16474 | return (array && array.length)
|
||
| 16475 | ? baseSum(array, identity) |
||
| 16476 | : 0;
|
||
| 16477 | } |
||
| 16478 | |||
| 16479 | /**
|
||
| 16480 | * This method is like `_.sum` except that it accepts `iteratee` which is
|
||
| 16481 | * invoked for each element in `array` to generate the value to be summed.
|
||
| 16482 | * The iteratee is invoked with one argument: (value).
|
||
| 16483 | *
|
||
| 16484 | * @static
|
||
| 16485 | * @memberOf _
|
||
| 16486 | * @since 4.0.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 sum.
|
||
| 16491 | * @example
|
||
| 16492 | *
|
||
| 16493 | * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
|
||
| 16494 | *
|
||
| 16495 | * _.sumBy(objects, function(o) { return o.n; });
|
||
| 16496 | * // => 20
|
||
| 16497 | *
|
||
| 16498 | * // The `_.property` iteratee shorthand.
|
||
| 16499 | * _.sumBy(objects, 'n');
|
||
| 16500 | * // => 20
|
||
| 16501 | */
|
||
| 16502 | function sumBy(array, iteratee) { |
||
| 16503 | return (array && array.length)
|
||
| 16504 | ? baseSum(array, getIteratee(iteratee, 2))
|
||
| 16505 | : 0;
|
||
| 16506 | } |
||
| 16507 | |||
| 16508 | /*------------------------------------------------------------------------*/
|
||
| 16509 | |||
| 16510 | // Add methods that return wrapped values in chain sequences.
|
||
| 16511 | lodash.after = after; |
||
| 16512 | lodash.ary = ary; |
||
| 16513 | lodash.assign = assign; |
||
| 16514 | lodash.assignIn = assignIn; |
||
| 16515 | lodash.assignInWith = assignInWith; |
||
| 16516 | lodash.assignWith = assignWith; |
||
| 16517 | lodash.at = at; |
||
| 16518 | lodash.before = before; |
||
| 16519 | lodash.bind = bind; |
||
| 16520 | lodash.bindAll = bindAll; |
||
| 16521 | lodash.bindKey = bindKey; |
||
| 16522 | lodash.castArray = castArray; |
||
| 16523 | lodash.chain = chain; |
||
| 16524 | lodash.chunk = chunk; |
||
| 16525 | lodash.compact = compact; |
||
| 16526 | lodash.concat = concat; |
||
| 16527 | lodash.cond = cond; |
||
| 16528 | lodash.conforms = conforms; |
||
| 16529 | lodash.constant = constant; |
||
| 16530 | lodash.countBy = countBy; |
||
| 16531 | lodash.create = create; |
||
| 16532 | lodash.curry = curry; |
||
| 16533 | lodash.curryRight = curryRight; |
||
| 16534 | lodash.debounce = debounce; |
||
| 16535 | lodash.defaults = defaults; |
||
| 16536 | lodash.defaultsDeep = defaultsDeep; |
||
| 16537 | lodash.defer = defer; |
||
| 16538 | lodash.delay = delay; |
||
| 16539 | lodash.difference = difference; |
||
| 16540 | lodash.differenceBy = differenceBy; |
||
| 16541 | lodash.differenceWith = differenceWith; |
||
| 16542 | lodash.drop = drop; |
||
| 16543 | lodash.dropRight = dropRight; |
||
| 16544 | lodash.dropRightWhile = dropRightWhile; |
||
| 16545 | lodash.dropWhile = dropWhile; |
||
| 16546 | lodash.fill = fill; |
||
| 16547 | lodash.filter = filter; |
||
| 16548 | lodash.flatMap = flatMap; |
||
| 16549 | lodash.flatMapDeep = flatMapDeep; |
||
| 16550 | lodash.flatMapDepth = flatMapDepth; |
||
| 16551 | lodash.flatten = flatten; |
||
| 16552 | lodash.flattenDeep = flattenDeep; |
||
| 16553 | lodash.flattenDepth = flattenDepth; |
||
| 16554 | lodash.flip = flip; |
||
| 16555 | lodash.flow = flow; |
||
| 16556 | lodash.flowRight = flowRight; |
||
| 16557 | lodash.fromPairs = fromPairs; |
||
| 16558 | lodash.functions = functions; |
||
| 16559 | lodash.functionsIn = functionsIn; |
||
| 16560 | lodash.groupBy = groupBy; |
||
| 16561 | lodash.initial = initial; |
||
| 16562 | lodash.intersection = intersection; |
||
| 16563 | lodash.intersectionBy = intersectionBy; |
||
| 16564 | lodash.intersectionWith = intersectionWith; |
||
| 16565 | lodash.invert = invert; |
||
| 16566 | lodash.invertBy = invertBy; |
||
| 16567 | lodash.invokeMap = invokeMap; |
||
| 16568 | lodash.iteratee = iteratee; |
||
| 16569 | lodash.keyBy = keyBy; |
||
| 16570 | lodash.keys = keys; |
||
| 16571 | lodash.keysIn = keysIn; |
||
| 16572 | lodash.map = map; |
||
| 16573 | lodash.mapKeys = mapKeys; |
||
| 16574 | lodash.mapValues = mapValues; |
||
| 16575 | lodash.matches = matches; |
||
| 16576 | lodash.matchesProperty = matchesProperty; |
||
| 16577 | lodash.memoize = memoize; |
||
| 16578 | lodash.merge = merge; |
||
| 16579 | lodash.mergeWith = mergeWith; |
||
| 16580 | lodash.method = method; |
||
| 16581 | lodash.methodOf = methodOf; |
||
| 16582 | lodash.mixin = mixin; |
||
| 16583 | lodash.negate = negate; |
||
| 16584 | lodash.nthArg = nthArg; |
||
| 16585 | lodash.omit = omit; |
||
| 16586 | lodash.omitBy = omitBy; |
||
| 16587 | lodash.once = once; |
||
| 16588 | lodash.orderBy = orderBy; |
||
| 16589 | lodash.over = over; |
||
| 16590 | lodash.overArgs = overArgs; |
||
| 16591 | lodash.overEvery = overEvery; |
||
| 16592 | lodash.overSome = overSome; |
||
| 16593 | lodash.partial = partial; |
||
| 16594 | lodash.partialRight = partialRight; |
||
| 16595 | lodash.partition = partition; |
||
| 16596 | lodash.pick = pick; |
||
| 16597 | lodash.pickBy = pickBy; |
||
| 16598 | lodash.property = property; |
||
| 16599 | lodash.propertyOf = propertyOf; |
||
| 16600 | lodash.pull = pull; |
||
| 16601 | lodash.pullAll = pullAll; |
||
| 16602 | lodash.pullAllBy = pullAllBy; |
||
| 16603 | lodash.pullAllWith = pullAllWith; |
||
| 16604 | lodash.pullAt = pullAt; |
||
| 16605 | lodash.range = range; |
||
| 16606 | lodash.rangeRight = rangeRight; |
||
| 16607 | lodash.rearg = rearg; |
||
| 16608 | lodash.reject = reject; |
||
| 16609 | lodash.remove = remove; |
||
| 16610 | lodash.rest = rest; |
||
| 16611 | lodash.reverse = reverse; |
||
| 16612 | lodash.sampleSize = sampleSize; |
||
| 16613 | lodash.set = set; |
||
| 16614 | lodash.setWith = setWith; |
||
| 16615 | lodash.shuffle = shuffle; |
||
| 16616 | lodash.slice = slice; |
||
| 16617 | lodash.sortBy = sortBy; |
||
| 16618 | lodash.sortedUniq = sortedUniq; |
||
| 16619 | lodash.sortedUniqBy = sortedUniqBy; |
||
| 16620 | lodash.split = split; |
||
| 16621 | lodash.spread = spread; |
||
| 16622 | lodash.tail = tail; |
||
| 16623 | lodash.take = take; |
||
| 16624 | lodash.takeRight = takeRight; |
||
| 16625 | lodash.takeRightWhile = takeRightWhile; |
||
| 16626 | lodash.takeWhile = takeWhile; |
||
| 16627 | lodash.tap = tap; |
||
| 16628 | lodash.throttle = throttle; |
||
| 16629 | lodash.thru = thru; |
||
| 16630 | lodash.toArray = toArray; |
||
| 16631 | lodash.toPairs = toPairs; |
||
| 16632 | lodash.toPairsIn = toPairsIn; |
||
| 16633 | lodash.toPath = toPath; |
||
| 16634 | lodash.toPlainObject = toPlainObject; |
||
| 16635 | lodash.transform = transform; |
||
| 16636 | lodash.unary = unary; |
||
| 16637 | lodash.union = union; |
||
| 16638 | lodash.unionBy = unionBy; |
||
| 16639 | lodash.unionWith = unionWith; |
||
| 16640 | lodash.uniq = uniq; |
||
| 16641 | lodash.uniqBy = uniqBy; |
||
| 16642 | lodash.uniqWith = uniqWith; |
||
| 16643 | lodash.unset = unset; |
||
| 16644 | lodash.unzip = unzip; |
||
| 16645 | lodash.unzipWith = unzipWith; |
||
| 16646 | lodash.update = update; |
||
| 16647 | lodash.updateWith = updateWith; |
||
| 16648 | lodash.values = values; |
||
| 16649 | lodash.valuesIn = valuesIn; |
||
| 16650 | lodash.without = without; |
||
| 16651 | lodash.words = words; |
||
| 16652 | lodash.wrap = wrap; |
||
| 16653 | lodash.xor = xor; |
||
| 16654 | lodash.xorBy = xorBy; |
||
| 16655 | lodash.xorWith = xorWith; |
||
| 16656 | lodash.zip = zip; |
||
| 16657 | lodash.zipObject = zipObject; |
||
| 16658 | lodash.zipObjectDeep = zipObjectDeep; |
||
| 16659 | lodash.zipWith = zipWith; |
||
| 16660 | |||
| 16661 | // Add aliases.
|
||
| 16662 | lodash.entries = toPairs; |
||
| 16663 | lodash.entriesIn = toPairsIn; |
||
| 16664 | lodash.extend = assignIn; |
||
| 16665 | lodash.extendWith = assignInWith; |
||
| 16666 | |||
| 16667 | // Add methods to `lodash.prototype`.
|
||
| 16668 | mixin(lodash, lodash); |
||
| 16669 | |||
| 16670 | /*------------------------------------------------------------------------*/
|
||
| 16671 | |||
| 16672 | // Add methods that return unwrapped values in chain sequences.
|
||
| 16673 | lodash.add = add; |
||
| 16674 | lodash.attempt = attempt; |
||
| 16675 | lodash.camelCase = camelCase; |
||
| 16676 | lodash.capitalize = capitalize; |
||
| 16677 | lodash.ceil = ceil; |
||
| 16678 | lodash.clamp = clamp; |
||
| 16679 | lodash.clone = clone; |
||
| 16680 | lodash.cloneDeep = cloneDeep; |
||
| 16681 | lodash.cloneDeepWith = cloneDeepWith; |
||
| 16682 | lodash.cloneWith = cloneWith; |
||
| 16683 | lodash.conformsTo = conformsTo; |
||
| 16684 | lodash.deburr = deburr; |
||
| 16685 | lodash.defaultTo = defaultTo; |
||
| 16686 | lodash.divide = divide; |
||
| 16687 | lodash.endsWith = endsWith; |
||
| 16688 | lodash.eq = eq; |
||
| 16689 | lodash.escape = escape; |
||
| 16690 | lodash.escapeRegExp = escapeRegExp; |
||
| 16691 | lodash.every = every; |
||
| 16692 | lodash.find = find; |
||
| 16693 | lodash.findIndex = findIndex; |
||
| 16694 | lodash.findKey = findKey; |
||
| 16695 | lodash.findLast = findLast; |
||
| 16696 | lodash.findLastIndex = findLastIndex; |
||
| 16697 | lodash.findLastKey = findLastKey; |
||
| 16698 | lodash.floor = floor; |
||
| 16699 | lodash.forEach = forEach; |
||
| 16700 | lodash.forEachRight = forEachRight; |
||
| 16701 | lodash.forIn = forIn; |
||
| 16702 | lodash.forInRight = forInRight; |
||
| 16703 | lodash.forOwn = forOwn; |
||
| 16704 | lodash.forOwnRight = forOwnRight; |
||
| 16705 | lodash.get = get; |
||
| 16706 | lodash.gt = gt; |
||
| 16707 | lodash.gte = gte; |
||
| 16708 | lodash.has = has; |
||
| 16709 | lodash.hasIn = hasIn; |
||
| 16710 | lodash.head = head; |
||
| 16711 | lodash.identity = identity; |
||
| 16712 | lodash.includes = includes; |
||
| 16713 | lodash.indexOf = indexOf; |
||
| 16714 | lodash.inRange = inRange; |
||
| 16715 | lodash.invoke = invoke; |
||
| 16716 | lodash.isArguments = isArguments; |
||
| 16717 | lodash.isArray = isArray; |
||
| 16718 | lodash.isArrayBuffer = isArrayBuffer; |
||
| 16719 | lodash.isArrayLike = isArrayLike; |
||
| 16720 | lodash.isArrayLikeObject = isArrayLikeObject; |
||
| 16721 | lodash.isBoolean = isBoolean; |
||
| 16722 | lodash.isBuffer = isBuffer; |
||
| 16723 | lodash.isDate = isDate; |
||
| 16724 | lodash.isElement = isElement; |
||
| 16725 | lodash.isEmpty = isEmpty; |
||
| 16726 | lodash.isEqual = isEqual; |
||
| 16727 | lodash.isEqualWith = isEqualWith; |
||
| 16728 | lodash.isError = isError; |
||
| 16729 | lodash.isFinite = isFinite; |
||
| 16730 | lodash.isFunction = isFunction; |
||
| 16731 | lodash.isInteger = isInteger; |
||
| 16732 | lodash.isLength = isLength; |
||
| 16733 | lodash.isMap = isMap; |
||
| 16734 | lodash.isMatch = isMatch; |
||
| 16735 | lodash.isMatchWith = isMatchWith; |
||
| 16736 | lodash.isNaN = isNaN; |
||
| 16737 | lodash.isNative = isNative; |
||
| 16738 | lodash.isNil = isNil; |
||
| 16739 | lodash.isNull = isNull; |
||
| 16740 | lodash.isNumber = isNumber; |
||
| 16741 | lodash.isObject = isObject; |
||
| 16742 | lodash.isObjectLike = isObjectLike; |
||
| 16743 | lodash.isPlainObject = isPlainObject; |
||
| 16744 | lodash.isRegExp = isRegExp; |
||
| 16745 | lodash.isSafeInteger = isSafeInteger; |
||
| 16746 | lodash.isSet = isSet; |
||
| 16747 | lodash.isString = isString; |
||
| 16748 | lodash.isSymbol = isSymbol; |
||
| 16749 | lodash.isTypedArray = isTypedArray; |
||
| 16750 | lodash.isUndefined = isUndefined; |
||
| 16751 | lodash.isWeakMap = isWeakMap; |
||
| 16752 | lodash.isWeakSet = isWeakSet; |
||
| 16753 | lodash.join = join; |
||
| 16754 | lodash.kebabCase = kebabCase; |
||
| 16755 | lodash.last = last; |
||
| 16756 | lodash.lastIndexOf = lastIndexOf; |
||
| 16757 | lodash.lowerCase = lowerCase; |
||
| 16758 | lodash.lowerFirst = lowerFirst; |
||
| 16759 | lodash.lt = lt; |
||
| 16760 | lodash.lte = lte; |
||
| 16761 | lodash.max = max; |
||
| 16762 | lodash.maxBy = maxBy; |
||
| 16763 | lodash.mean = mean; |
||
| 16764 | lodash.meanBy = meanBy; |
||
| 16765 | lodash.min = min; |
||
| 16766 | lodash.minBy = minBy; |
||
| 16767 | lodash.stubArray = stubArray; |
||
| 16768 | lodash.stubFalse = stubFalse; |
||
| 16769 | lodash.stubObject = stubObject; |
||
| 16770 | lodash.stubString = stubString; |
||
| 16771 | lodash.stubTrue = stubTrue; |
||
| 16772 | lodash.multiply = multiply; |
||
| 16773 | lodash.nth = nth; |
||
| 16774 | lodash.noConflict = noConflict; |
||
| 16775 | lodash.noop = noop; |
||
| 16776 | lodash.now = now; |
||
| 16777 | lodash.pad = pad; |
||
| 16778 | lodash.padEnd = padEnd; |
||
| 16779 | lodash.padStart = padStart; |
||
| 16780 | lodash.parseInt = parseInt; |
||
| 16781 | lodash.random = random; |
||
| 16782 | lodash.reduce = reduce; |
||
| 16783 | lodash.reduceRight = reduceRight; |
||
| 16784 | lodash.repeat = repeat; |
||
| 16785 | lodash.replace = replace; |
||
| 16786 | lodash.result = result; |
||
| 16787 | lodash.round = round; |
||
| 16788 | lodash.runInContext = runInContext; |
||
| 16789 | lodash.sample = sample; |
||
| 16790 | lodash.size = size; |
||
| 16791 | lodash.snakeCase = snakeCase; |
||
| 16792 | lodash.some = some; |
||
| 16793 | lodash.sortedIndex = sortedIndex; |
||
| 16794 | lodash.sortedIndexBy = sortedIndexBy; |
||
| 16795 | lodash.sortedIndexOf = sortedIndexOf; |
||
| 16796 | lodash.sortedLastIndex = sortedLastIndex; |
||
| 16797 | lodash.sortedLastIndexBy = sortedLastIndexBy; |
||
| 16798 | lodash.sortedLastIndexOf = sortedLastIndexOf; |
||
| 16799 | lodash.startCase = startCase; |
||
| 16800 | lodash.startsWith = startsWith; |
||
| 16801 | lodash.subtract = subtract; |
||
| 16802 | lodash.sum = sum; |
||
| 16803 | lodash.sumBy = sumBy; |
||
| 16804 | lodash.template = template; |
||
| 16805 | lodash.times = times; |
||
| 16806 | lodash.toFinite = toFinite; |
||
| 16807 | lodash.toInteger = toInteger; |
||
| 16808 | lodash.toLength = toLength; |
||
| 16809 | lodash.toLower = toLower; |
||
| 16810 | lodash.toNumber = toNumber; |
||
| 16811 | lodash.toSafeInteger = toSafeInteger; |
||
| 16812 | lodash.toString = toString; |
||
| 16813 | lodash.toUpper = toUpper; |
||
| 16814 | lodash.trim = trim; |
||
| 16815 | lodash.trimEnd = trimEnd; |
||
| 16816 | lodash.trimStart = trimStart; |
||
| 16817 | lodash.truncate = truncate; |
||
| 16818 | lodash.unescape = unescape; |
||
| 16819 | lodash.uniqueId = uniqueId; |
||
| 16820 | lodash.upperCase = upperCase; |
||
| 16821 | lodash.upperFirst = upperFirst; |
||
| 16822 | |||
| 16823 | // Add aliases.
|
||
| 16824 | lodash.each = forEach; |
||
| 16825 | lodash.eachRight = forEachRight; |
||
| 16826 | lodash.first = head; |
||
| 16827 | |||
| 16828 | mixin(lodash, (function() {
|
||
| 16829 | var source = {};
|
||
| 16830 | baseForOwn(lodash, function(func, methodName) {
|
||
| 16831 | if (!hasOwnProperty.call(lodash.prototype, methodName)) {
|
||
| 16832 | source[methodName] = func; |
||
| 16833 | } |
||
| 16834 | }); |
||
| 16835 | return source;
|
||
| 16836 | }()), { 'chain': false });
|
||
| 16837 | |||
| 16838 | /*------------------------------------------------------------------------*/
|
||
| 16839 | |||
| 16840 | /**
|
||
| 16841 | * The semantic version number.
|
||
| 16842 | *
|
||
| 16843 | * @static
|
||
| 16844 | * @memberOf _
|
||
| 16845 | * @type {string}
|
||
| 16846 | */
|
||
| 16847 | lodash.VERSION = VERSION; |
||
| 16848 | |||
| 16849 | // Assign default placeholders.
|
||
| 16850 | arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) { |
||
| 16851 | lodash[methodName].placeholder = lodash; |
||
| 16852 | }); |
||
| 16853 | |||
| 16854 | // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
|
||
| 16855 | arrayEach(['drop', 'take'], function(methodName, index) { |
||
| 16856 | LazyWrapper.prototype[methodName] = function(n) {
|
||
| 16857 | n = n === undefined ? 1 : nativeMax(toInteger(n), 0); |
||
| 16858 | |||
| 16859 | var result = (this.__filtered__ && !index) |
||
| 16860 | ? new LazyWrapper(this) |
||
| 16861 | : this.clone();
|
||
| 16862 | |||
| 16863 | if (result.__filtered__) {
|
||
| 16864 | result.__takeCount__ = nativeMin(n, result.__takeCount__); |
||
| 16865 | } else {
|
||
| 16866 | result.__views__.push({
|
||
| 16867 | 'size': nativeMin(n, MAX_ARRAY_LENGTH),
|
||
| 16868 | 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') |
||
| 16869 | }); |
||
| 16870 | } |
||
| 16871 | return result;
|
||
| 16872 | }; |
||
| 16873 | |||
| 16874 | LazyWrapper.prototype[methodName + 'Right'] = function(n) { |
||
| 16875 | return this.reverse()[methodName](n).reverse(); |
||
| 16876 | }; |
||
| 16877 | }); |
||
| 16878 | |||
| 16879 | // Add `LazyWrapper` methods that accept an `iteratee` value.
|
||
| 16880 | arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) { |
||
| 16881 | var type = index + 1, |
||
| 16882 | isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG; |
||
| 16883 | |||
| 16884 | LazyWrapper.prototype[methodName] = function(iteratee) {
|
||
| 16885 | var result = this.clone(); |
||
| 16886 | result.__iteratees__.push({
|
||
| 16887 | 'iteratee': getIteratee(iteratee, 3), |
||
| 16888 | 'type': type
|
||
| 16889 | }); |
||
| 16890 | result.__filtered__ = result.__filtered__ || isFilter; |
||
| 16891 | return result;
|
||
| 16892 | }; |
||
| 16893 | }); |
||
| 16894 | |||
| 16895 | // Add `LazyWrapper` methods for `_.head` and `_.last`.
|
||
| 16896 | arrayEach(['head', 'last'], function(methodName, index) { |
||
| 16897 | var takeName = 'take' + (index ? 'Right' : ''); |
||
| 16898 | |||
| 16899 | LazyWrapper.prototype[methodName] = function() {
|
||
| 16900 | return this[takeName](1).value()[0]; |
||
| 16901 | }; |
||
| 16902 | }); |
||
| 16903 | |||
| 16904 | // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
|
||
| 16905 | arrayEach(['initial', 'tail'], function(methodName, index) { |
||
| 16906 | var dropName = 'drop' + (index ? '' : 'Right'); |
||
| 16907 | |||
| 16908 | LazyWrapper.prototype[methodName] = function() {
|
||
| 16909 | return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1); |
||
| 16910 | }; |
||
| 16911 | }); |
||
| 16912 | |||
| 16913 | LazyWrapper.prototype.compact = function() { |
||
| 16914 | return this.filter(identity); |
||
| 16915 | }; |
||
| 16916 | |||
| 16917 | LazyWrapper.prototype.find = function(predicate) { |
||
| 16918 | return this.filter(predicate).head(); |
||
| 16919 | }; |
||
| 16920 | |||
| 16921 | LazyWrapper.prototype.findLast = function(predicate) { |
||
| 16922 | return this.reverse().find(predicate); |
||
| 16923 | }; |
||
| 16924 | |||
| 16925 | LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
|
||
| 16926 | if (typeof path == 'function') { |
||
| 16927 | return new LazyWrapper(this); |
||
| 16928 | } |
||
| 16929 | return this.map(function(value) { |
||
| 16930 | return baseInvoke(value, path, args);
|
||
| 16931 | }); |
||
| 16932 | }); |
||
| 16933 | |||
| 16934 | LazyWrapper.prototype.reject = function(predicate) { |
||
| 16935 | return this.filter(negate(getIteratee(predicate))); |
||
| 16936 | }; |
||
| 16937 | |||
| 16938 | LazyWrapper.prototype.slice = function(start, end) { |
||
| 16939 | start = toInteger(start); |
||
| 16940 | |||
| 16941 | var result = this; |
||
| 16942 | if (result.__filtered__ && (start > 0 || end < 0)) { |
||
| 16943 | return new LazyWrapper(result); |
||
| 16944 | } |
||
| 16945 | if (start < 0) { |
||
| 16946 | result = result.takeRight(-start); |
||
| 16947 | } else if (start) { |
||
| 16948 | result = result.drop(start); |
||
| 16949 | } |
||
| 16950 | if (end !== undefined) { |
||
| 16951 | end = toInteger(end); |
||
| 16952 | result = end < 0 ? result.dropRight(-end) : result.take(end - start);
|
||
| 16953 | } |
||
| 16954 | return result;
|
||
| 16955 | }; |
||
| 16956 | |||
| 16957 | LazyWrapper.prototype.takeRightWhile = function(predicate) { |
||
| 16958 | return this.reverse().takeWhile(predicate).reverse(); |
||
| 16959 | }; |
||
| 16960 | |||
| 16961 | LazyWrapper.prototype.toArray = function() { |
||
| 16962 | return this.take(MAX_ARRAY_LENGTH); |
||
| 16963 | }; |
||
| 16964 | |||
| 16965 | // Add `LazyWrapper` methods to `lodash.prototype`.
|
||
| 16966 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
||
| 16967 | var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName), |
||
| 16968 | isTaker = /^(?:head|last)$/.test(methodName),
|
||
| 16969 | lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName], |
||
| 16970 | retUnwrapped = isTaker || /^find/.test(methodName);
|
||
| 16971 | |||
| 16972 | if (!lodashFunc) {
|
||
| 16973 | return;
|
||
| 16974 | } |
||
| 16975 | lodash.prototype[methodName] = function() {
|
||
| 16976 | var value = this.__wrapped__, |
||
| 16977 | args = isTaker ? [1] : arguments, |
||
| 16978 | isLazy = value instanceof LazyWrapper,
|
||
| 16979 | iteratee = args[0],
|
||
| 16980 | useLazy = isLazy || isArray(value); |
||
| 16981 | |||
| 16982 | var interceptor = function(value) { |
||
| 16983 | var result = lodashFunc.apply(lodash, arrayPush([value], args));
|
||
| 16984 | return (isTaker && chainAll) ? result[0] : result; |
||
| 16985 | }; |
||
| 16986 | |||
| 16987 | if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) { |
||
| 16988 | // Avoid lazy use if the iteratee has a "length" value other than `1`.
|
||
| 16989 | isLazy = useLazy = false;
|
||
| 16990 | } |
||
| 16991 | var chainAll = this.__chain__, |
||
| 16992 | isHybrid = !!this.__actions__.length,
|
||
| 16993 | isUnwrapped = retUnwrapped && !chainAll, |
||
| 16994 | onlyLazy = isLazy && !isHybrid; |
||
| 16995 | |||
| 16996 | if (!retUnwrapped && useLazy) {
|
||
| 16997 | value = onlyLazy ? value : new LazyWrapper(this); |
||
| 16998 | var result = func.apply(value, args);
|
||
| 16999 | result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
|
||
| 17000 | return new LodashWrapper(result, chainAll); |
||
| 17001 | } |
||
| 17002 | if (isUnwrapped && onlyLazy) {
|
||
| 17003 | return func.apply(this, args); |
||
| 17004 | } |
||
| 17005 | result = this.thru(interceptor);
|
||
| 17006 | return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result; |
||
| 17007 | }; |
||
| 17008 | }); |
||
| 17009 | |||
| 17010 | // Add `Array` methods to `lodash.prototype`.
|
||
| 17011 | arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { |
||
| 17012 | var func = arrayProto[methodName],
|
||
| 17013 | chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', |
||
| 17014 | retUnwrapped = /^(?:pop|shift)$/.test(methodName);
|
||
| 17015 | |||
| 17016 | lodash.prototype[methodName] = function() {
|
||
| 17017 | var args = arguments; |
||
| 17018 | if (retUnwrapped && !this.__chain__) { |
||
| 17019 | var value = this.value(); |
||
| 17020 | return func.apply(isArray(value) ? value : [], args);
|
||
| 17021 | } |
||
| 17022 | return this[chainName](function(value) { |
||
| 17023 | return func.apply(isArray(value) ? value : [], args);
|
||
| 17024 | }); |
||
| 17025 | }; |
||
| 17026 | }); |
||
| 17027 | |||
| 17028 | // Map minified method names to their real names.
|
||
| 17029 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
||
| 17030 | var lodashFunc = lodash[methodName];
|
||
| 17031 | if (lodashFunc) {
|
||
| 17032 | var key = (lodashFunc.name + ''), |
||
| 17033 | names = realNames[key] || (realNames[key] = []); |
||
| 17034 | |||
| 17035 | names.push({ 'name': methodName, 'func': lodashFunc });
|
||
| 17036 | } |
||
| 17037 | }); |
||
| 17038 | |||
| 17039 | realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
|
||
| 17040 | 'name': 'wrapper', |
||
| 17041 | 'func': undefined |
||
| 17042 | }]; |
||
| 17043 | |||
| 17044 | // Add methods to `LazyWrapper`.
|
||
| 17045 | LazyWrapper.prototype.clone = lazyClone; |
||
| 17046 | LazyWrapper.prototype.reverse = lazyReverse; |
||
| 17047 | LazyWrapper.prototype.value = lazyValue; |
||
| 17048 | |||
| 17049 | // Add chain sequence methods to the `lodash` wrapper.
|
||
| 17050 | lodash.prototype.at = wrapperAt; |
||
| 17051 | lodash.prototype.chain = wrapperChain; |
||
| 17052 | lodash.prototype.commit = wrapperCommit; |
||
| 17053 | lodash.prototype.next = wrapperNext; |
||
| 17054 | lodash.prototype.plant = wrapperPlant; |
||
| 17055 | lodash.prototype.reverse = wrapperReverse; |
||
| 17056 | lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; |
||
| 17057 | |||
| 17058 | // Add lazy aliases.
|
||
| 17059 | lodash.prototype.first = lodash.prototype.head; |
||
| 17060 | |||
| 17061 | if (symIterator) {
|
||
| 17062 | lodash.prototype[symIterator] = wrapperToIterator; |
||
| 17063 | } |
||
| 17064 | return lodash;
|
||
| 17065 | }); |
||
| 17066 | |||
| 17067 | /*--------------------------------------------------------------------------*/
|
||
| 17068 | |||
| 17069 | // Export lodash.
|
||
| 17070 | var _ = runInContext();
|
||
| 17071 | |||
| 17072 | // Some AMD build optimizers, like r.js, check for condition patterns like:
|
||
| 17073 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { |
||
| 17074 | // Expose Lodash on the global object to prevent errors when Lodash is
|
||
| 17075 | // loaded by a script tag in the presence of an AMD loader.
|
||
| 17076 | // See http://requirejs.org/docs/errors.html#mismatch for more details.
|
||
| 17077 | // Use `_.noConflict` to remove Lodash from the global object.
|
||
| 17078 | root._ = _; |
||
| 17079 | |||
| 17080 | // Define as an anonymous module so, through path mapping, it can be
|
||
| 17081 | // referenced as the "underscore" module.
|
||
| 17082 | define(function() {
|
||
| 17083 | return _;
|
||
| 17084 | }); |
||
| 17085 | } |
||
| 17086 | // Check for `exports` after `define` in case a build optimizer adds it.
|
||
| 17087 | else if (freeModule) { |
||
| 17088 | // Export for Node.js.
|
||
| 17089 | (freeModule.exports = _)._ = _; |
||
| 17090 | // Export for CommonJS support.
|
||
| 17091 | freeExports._ = _; |
||
| 17092 | } |
||
| 17093 | else {
|
||
| 17094 | // Export to the global object.
|
||
| 17095 | root._ = _; |
||
| 17096 | } |
||
| 17097 | }.call(this)); |