1 | /**
|
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.10';
|
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 | // Use `util.types` for Node.js 10+.
|
440 | var types = freeModule && freeModule.require && freeModule.require('util').types;
|
441 |
|
442 | if (types) {
|
443 | return types;
|
444 | }
|
445 |
|
446 | // Legacy `process.binding('util')` for Node.js < 10.
|
447 | return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
448 | } catch (e) {}
|
449 | }());
|
450 |
|
451 | /* Node.js helper references. */
|
452 | var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
|
453 | nodeIsDate = nodeUtil && nodeUtil.isDate,
|
454 | nodeIsMap = nodeUtil && nodeUtil.isMap,
|
455 | nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
|
456 | nodeIsSet = nodeUtil && nodeUtil.isSet,
|
457 | nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
458 |
|
459 | /*--------------------------------------------------------------------------*/
|
460 |
|
461 | /**
|
462 | * A faster alternative to `Function#apply`, this function invokes `func`
|
463 | * with the `this` binding of `thisArg` and the arguments of `args`.
|
464 | *
|
465 | * @private
|
466 | * @param {Function} func The function to invoke.
|
467 | * @param {*} thisArg The `this` binding of `func`.
|
468 | * @param {Array} args The arguments to invoke `func` with.
|
469 | * @returns {*} Returns the result of `func`.
|
470 | */
|
471 | function apply(func, thisArg, args) {
|
472 | switch (args.length) {
|
473 | case 0: return func.call(thisArg);
|
474 | case 1: return func.call(thisArg, args[0]);
|
475 | case 2: return func.call(thisArg, args[0], args[1]);
|
476 | case 3: return func.call(thisArg, args[0], args[1], args[2]);
|
477 | }
|
478 | return func.apply(thisArg, args);
|
479 | }
|
480 |
|
481 | /**
|
482 | * A specialized version of `baseAggregator` for arrays.
|
483 | *
|
484 | * @private
|
485 | * @param {Array} [array] The array to iterate over.
|
486 | * @param {Function} setter The function to set `accumulator` values.
|
487 | * @param {Function} iteratee The iteratee to transform keys.
|
488 | * @param {Object} accumulator The initial aggregated object.
|
489 | * @returns {Function} Returns `accumulator`.
|
490 | */
|
491 | function arrayAggregator(array, setter, iteratee, accumulator) {
|
492 | var index = -1,
|
493 | length = array == null ? 0 : array.length;
|
494 |
|
495 | while (++index < length) {
|
496 | var value = array[index];
|
497 | setter(accumulator, value, iteratee(value), array);
|
498 | }
|
499 | return accumulator;
|
500 | }
|
501 |
|
502 | /**
|
503 | * A specialized version of `_.forEach` for arrays without support for
|
504 | * iteratee shorthands.
|
505 | *
|
506 | * @private
|
507 | * @param {Array} [array] The array to iterate over.
|
508 | * @param {Function} iteratee The function invoked per iteration.
|
509 | * @returns {Array} Returns `array`.
|
510 | */
|
511 | function arrayEach(array, iteratee) {
|
512 | var index = -1,
|
513 | length = array == null ? 0 : array.length;
|
514 |
|
515 | while (++index < length) {
|
516 | if (iteratee(array[index], index, array) === false) {
|
517 | break;
|
518 | }
|
519 | }
|
520 | return array;
|
521 | }
|
522 |
|
523 | /**
|
524 | * A specialized version of `_.forEachRight` for arrays without support for
|
525 | * iteratee shorthands.
|
526 | *
|
527 | * @private
|
528 | * @param {Array} [array] The array to iterate over.
|
529 | * @param {Function} iteratee The function invoked per iteration.
|
530 | * @returns {Array} Returns `array`.
|
531 | */
|
532 | function arrayEachRight(array, iteratee) {
|
533 | var length = array == null ? 0 : array.length;
|
534 |
|
535 | while (length--) {
|
536 | if (iteratee(array[length], length, array) === false) {
|
537 | break;
|
538 | }
|
539 | }
|
540 | return array;
|
541 | }
|
542 |
|
543 | /**
|
544 | * A specialized version of `_.every` for arrays without support for
|
545 | * iteratee shorthands.
|
546 | *
|
547 | * @private
|
548 | * @param {Array} [array] The array to iterate over.
|
549 | * @param {Function} predicate The function invoked per iteration.
|
550 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
551 | * else `false`.
|
552 | */
|
553 | function arrayEvery(array, predicate) {
|
554 | var index = -1,
|
555 | length = array == null ? 0 : array.length;
|
556 |
|
557 | while (++index < length) {
|
558 | if (!predicate(array[index], index, array)) {
|
559 | return false;
|
560 | }
|
561 | }
|
562 | return true;
|
563 | }
|
564 |
|
565 | /**
|
566 | * A specialized version of `_.filter` for arrays without support for
|
567 | * iteratee shorthands.
|
568 | *
|
569 | * @private
|
570 | * @param {Array} [array] The array to iterate over.
|
571 | * @param {Function} predicate The function invoked per iteration.
|
572 | * @returns {Array} Returns the new filtered array.
|
573 | */
|
574 | function arrayFilter(array, predicate) {
|
575 | var index = -1,
|
576 | length = array == null ? 0 : array.length,
|
577 | resIndex = 0,
|
578 | result = [];
|
579 |
|
580 | while (++index < length) {
|
581 | var value = array[index];
|
582 | if (predicate(value, index, array)) {
|
583 | result[resIndex++] = value;
|
584 | }
|
585 | }
|
586 | return result;
|
587 | }
|
588 |
|
589 | /**
|
590 | * A specialized version of `_.includes` for arrays without support for
|
591 | * specifying an index to search from.
|
592 | *
|
593 | * @private
|
594 | * @param {Array} [array] The array to inspect.
|
595 | * @param {*} target The value to search for.
|
596 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
597 | */
|
598 | function arrayIncludes(array, value) {
|
599 | var length = array == null ? 0 : array.length;
|
600 | return !!length && baseIndexOf(array, value, 0) > -1;
|
601 | }
|
602 |
|
603 | /**
|
604 | * This function is like `arrayIncludes` except that it accepts a comparator.
|
605 | *
|
606 | * @private
|
607 | * @param {Array} [array] The array to inspect.
|
608 | * @param {*} target The value to search for.
|
609 | * @param {Function} comparator The comparator invoked per element.
|
610 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
611 | */
|
612 | function arrayIncludesWith(array, value, comparator) {
|
613 | var index = -1,
|
614 | length = array == null ? 0 : array.length;
|
615 |
|
616 | while (++index < length) {
|
617 | if (comparator(value, array[index])) {
|
618 | return true;
|
619 | }
|
620 | }
|
621 | return false;
|
622 | }
|
623 |
|
624 | /**
|
625 | * A specialized version of `_.map` for arrays without support for iteratee
|
626 | * shorthands.
|
627 | *
|
628 | * @private
|
629 | * @param {Array} [array] The array to iterate over.
|
630 | * @param {Function} iteratee The function invoked per iteration.
|
631 | * @returns {Array} Returns the new mapped array.
|
632 | */
|
633 | function arrayMap(array, iteratee) {
|
634 | var index = -1,
|
635 | length = array == null ? 0 : array.length,
|
636 | result = Array(length);
|
637 |
|
638 | while (++index < length) {
|
639 | result[index] = iteratee(array[index], index, array);
|
640 | }
|
641 | return result;
|
642 | }
|
643 |
|
644 | /**
|
645 | * Appends the elements of `values` to `array`.
|
646 | *
|
647 | * @private
|
648 | * @param {Array} array The array to modify.
|
649 | * @param {Array} values The values to append.
|
650 | * @returns {Array} Returns `array`.
|
651 | */
|
652 | function arrayPush(array, values) {
|
653 | var index = -1,
|
654 | length = values.length,
|
655 | offset = array.length;
|
656 |
|
657 | while (++index < length) {
|
658 | array[offset + index] = values[index];
|
659 | }
|
660 | return array;
|
661 | }
|
662 |
|
663 | /**
|
664 | * A specialized version of `_.reduce` for arrays without support for
|
665 | * iteratee shorthands.
|
666 | *
|
667 | * @private
|
668 | * @param {Array} [array] The array to iterate over.
|
669 | * @param {Function} iteratee The function invoked per iteration.
|
670 | * @param {*} [accumulator] The initial value.
|
671 | * @param {boolean} [initAccum] Specify using the first element of `array` as
|
672 | * the initial value.
|
673 | * @returns {*} Returns the accumulated value.
|
674 | */
|
675 | function arrayReduce(array, iteratee, accumulator, initAccum) {
|
676 | var index = -1,
|
677 | length = array == null ? 0 : array.length;
|
678 |
|
679 | if (initAccum && length) {
|
680 | accumulator = array[++index];
|
681 | }
|
682 | while (++index < length) {
|
683 | accumulator = iteratee(accumulator, array[index], index, array);
|
684 | }
|
685 | return accumulator;
|
686 | }
|
687 |
|
688 | /**
|
689 | * A specialized version of `_.reduceRight` for arrays without support for
|
690 | * iteratee shorthands.
|
691 | *
|
692 | * @private
|
693 | * @param {Array} [array] The array to iterate over.
|
694 | * @param {Function} iteratee The function invoked per iteration.
|
695 | * @param {*} [accumulator] The initial value.
|
696 | * @param {boolean} [initAccum] Specify using the last element of `array` as
|
697 | * the initial value.
|
698 | * @returns {*} Returns the accumulated value.
|
699 | */
|
700 | function arrayReduceRight(array, iteratee, accumulator, initAccum) {
|
701 | var length = array == null ? 0 : array.length;
|
702 | if (initAccum && length) {
|
703 | accumulator = array[--length];
|
704 | }
|
705 | while (length--) {
|
706 | accumulator = iteratee(accumulator, array[length], length, array);
|
707 | }
|
708 | return accumulator;
|
709 | }
|
710 |
|
711 | /**
|
712 | * A specialized version of `_.some` for arrays without support for iteratee
|
713 | * shorthands.
|
714 | *
|
715 | * @private
|
716 | * @param {Array} [array] The array to iterate over.
|
717 | * @param {Function} predicate The function invoked per iteration.
|
718 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
719 | * else `false`.
|
720 | */
|
721 | function arraySome(array, predicate) {
|
722 | var index = -1,
|
723 | length = array == null ? 0 : array.length;
|
724 |
|
725 | while (++index < length) {
|
726 | if (predicate(array[index], index, array)) {
|
727 | return true;
|
728 | }
|
729 | }
|
730 | return false;
|
731 | }
|
732 |
|
733 | /**
|
734 | * Gets the size of an ASCII `string`.
|
735 | *
|
736 | * @private
|
737 | * @param {string} string The string inspect.
|
738 | * @returns {number} Returns the string size.
|
739 | */
|
740 | var asciiSize = baseProperty('length');
|
741 |
|
742 | /**
|
743 | * Converts an ASCII `string` to an array.
|
744 | *
|
745 | * @private
|
746 | * @param {string} string The string to convert.
|
747 | * @returns {Array} Returns the converted array.
|
748 | */
|
749 | function asciiToArray(string) {
|
750 | return string.split('');
|
751 | }
|
752 |
|
753 | /**
|
754 | * Splits an ASCII `string` into an array of its words.
|
755 | *
|
756 | * @private
|
757 | * @param {string} The string to inspect.
|
758 | * @returns {Array} Returns the words of `string`.
|
759 | */
|
760 | function asciiWords(string) {
|
761 | return string.match(reAsciiWord) || [];
|
762 | }
|
763 |
|
764 | /**
|
765 | * The base implementation of methods like `_.findKey` and `_.findLastKey`,
|
766 | * without support for iteratee shorthands, which iterates over `collection`
|
767 | * using `eachFunc`.
|
768 | *
|
769 | * @private
|
770 | * @param {Array|Object} collection The collection to inspect.
|
771 | * @param {Function} predicate The function invoked per iteration.
|
772 | * @param {Function} eachFunc The function to iterate over `collection`.
|
773 | * @returns {*} Returns the found element or its key, else `undefined`.
|
774 | */
|
775 | function baseFindKey(collection, predicate, eachFunc) {
|
776 | var result;
|
777 | eachFunc(collection, function(value, key, collection) {
|
778 | if (predicate(value, key, collection)) {
|
779 | result = key;
|
780 | return false;
|
781 | }
|
782 | });
|
783 | return result;
|
784 | }
|
785 |
|
786 | /**
|
787 | * The base implementation of `_.findIndex` and `_.findLastIndex` without
|
788 | * support for iteratee shorthands.
|
789 | *
|
790 | * @private
|
791 | * @param {Array} array The array to inspect.
|
792 | * @param {Function} predicate The function invoked per iteration.
|
793 | * @param {number} fromIndex The index to search from.
|
794 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
795 | * @returns {number} Returns the index of the matched value, else `-1`.
|
796 | */
|
797 | function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
798 | var length = array.length,
|
799 | index = fromIndex + (fromRight ? 1 : -1);
|
800 |
|
801 | while ((fromRight ? index-- : ++index < length)) {
|
802 | if (predicate(array[index], index, array)) {
|
803 | return index;
|
804 | }
|
805 | }
|
806 | return -1;
|
807 | }
|
808 |
|
809 | /**
|
810 | * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
|
811 | *
|
812 | * @private
|
813 | * @param {Array} array The array to inspect.
|
814 | * @param {*} value The value to search for.
|
815 | * @param {number} fromIndex The index to search from.
|
816 | * @returns {number} Returns the index of the matched value, else `-1`.
|
817 | */
|
818 | function baseIndexOf(array, value, fromIndex) {
|
819 | return value === value
|
820 | ? strictIndexOf(array, value, fromIndex)
|
821 | : baseFindIndex(array, baseIsNaN, fromIndex);
|
822 | }
|
823 |
|
824 | /**
|
825 | * This function is like `baseIndexOf` except that it accepts a comparator.
|
826 | *
|
827 | * @private
|
828 | * @param {Array} array The array to inspect.
|
829 | * @param {*} value The value to search for.
|
830 | * @param {number} fromIndex The index to search from.
|
831 | * @param {Function} comparator The comparator invoked per element.
|
832 | * @returns {number} Returns the index of the matched value, else `-1`.
|
833 | */
|
834 | function baseIndexOfWith(array, value, fromIndex, comparator) {
|
835 | var index = fromIndex - 1,
|
836 | length = array.length;
|
837 |
|
838 | while (++index < length) {
|
839 | if (comparator(array[index], value)) {
|
840 | return index;
|
841 | }
|
842 | }
|
843 | return -1;
|
844 | }
|
845 |
|
846 | /**
|
847 | * The base implementation of `_.isNaN` without support for number objects.
|
848 | *
|
849 | * @private
|
850 | * @param {*} value The value to check.
|
851 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
852 | */
|
853 | function baseIsNaN(value) {
|
854 | return value !== value;
|
855 | }
|
856 |
|
857 | /**
|
858 | * The base implementation of `_.mean` and `_.meanBy` without support for
|
859 | * iteratee shorthands.
|
860 | *
|
861 | * @private
|
862 | * @param {Array} array The array to iterate over.
|
863 | * @param {Function} iteratee The function invoked per iteration.
|
864 | * @returns {number} Returns the mean.
|
865 | */
|
866 | function baseMean(array, iteratee) {
|
867 | var length = array == null ? 0 : array.length;
|
868 | return length ? (baseSum(array, iteratee) / length) : NAN;
|
869 | }
|
870 |
|
871 | /**
|
872 | * The base implementation of `_.property` without support for deep paths.
|
873 | *
|
874 | * @private
|
875 | * @param {string} key The key of the property to get.
|
876 | * @returns {Function} Returns the new accessor function.
|
877 | */
|
878 | function baseProperty(key) {
|
879 | return function(object) {
|
880 | return object == null ? undefined : object[key];
|
881 | };
|
882 | }
|
883 |
|
884 | /**
|
885 | * The base implementation of `_.propertyOf` without support for deep paths.
|
886 | *
|
887 | * @private
|
888 | * @param {Object} object The object to query.
|
889 | * @returns {Function} Returns the new accessor function.
|
890 | */
|
891 | function basePropertyOf(object) {
|
892 | return function(key) {
|
893 | return object == null ? undefined : object[key];
|
894 | };
|
895 | }
|
896 |
|
897 | /**
|
898 | * The base implementation of `_.reduce` and `_.reduceRight`, without support
|
899 | * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
|
900 | *
|
901 | * @private
|
902 | * @param {Array|Object} collection The collection to iterate over.
|
903 | * @param {Function} iteratee The function invoked per iteration.
|
904 | * @param {*} accumulator The initial value.
|
905 | * @param {boolean} initAccum Specify using the first or last element of
|
906 | * `collection` as the initial value.
|
907 | * @param {Function} eachFunc The function to iterate over `collection`.
|
908 | * @returns {*} Returns the accumulated value.
|
909 | */
|
910 | function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
|
911 | eachFunc(collection, function(value, index, collection) {
|
912 | accumulator = initAccum
|
913 | ? (initAccum = false, value)
|
914 | : iteratee(accumulator, value, index, collection);
|
915 | });
|
916 | return accumulator;
|
917 | }
|
918 |
|
919 | /**
|
920 | * The base implementation of `_.sortBy` which uses `comparer` to define the
|
921 | * sort order of `array` and replaces criteria objects with their corresponding
|
922 | * values.
|
923 | *
|
924 | * @private
|
925 | * @param {Array} array The array to sort.
|
926 | * @param {Function} comparer The function to define sort order.
|
927 | * @returns {Array} Returns `array`.
|
928 | */
|
929 | function baseSortBy(array, comparer) {
|
930 | var length = array.length;
|
931 |
|
932 | array.sort(comparer);
|
933 | while (length--) {
|
934 | array[length] = array[length].value;
|
935 | }
|
936 | return array;
|
937 | }
|
938 |
|
939 | /**
|
940 | * The base implementation of `_.sum` and `_.sumBy` without support for
|
941 | * iteratee shorthands.
|
942 | *
|
943 | * @private
|
944 | * @param {Array} array The array to iterate over.
|
945 | * @param {Function} iteratee The function invoked per iteration.
|
946 | * @returns {number} Returns the sum.
|
947 | */
|
948 | function baseSum(array, iteratee) {
|
949 | var result,
|
950 | index = -1,
|
951 | length = array.length;
|
952 |
|
953 | while (++index < length) {
|
954 | var current = iteratee(array[index]);
|
955 | if (current !== undefined) {
|
956 | result = result === undefined ? current : (result + current);
|
957 | }
|
958 | }
|
959 | return result;
|
960 | }
|
961 |
|
962 | /**
|
963 | * The base implementation of `_.times` without support for iteratee shorthands
|
964 | * or max array length checks.
|
965 | *
|
966 | * @private
|
967 | * @param {number} n The number of times to invoke `iteratee`.
|
968 | * @param {Function} iteratee The function invoked per iteration.
|
969 | * @returns {Array} Returns the array of results.
|
970 | */
|
971 | function baseTimes(n, iteratee) {
|
972 | var index = -1,
|
973 | result = Array(n);
|
974 |
|
975 | while (++index < n) {
|
976 | result[index] = iteratee(index);
|
977 | }
|
978 | return result;
|
979 | }
|
980 |
|
981 | /**
|
982 | * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
|
983 | * of key-value pairs for `object` corresponding to the property names of `props`.
|
984 | *
|
985 | * @private
|
986 | * @param {Object} object The object to query.
|
987 | * @param {Array} props The property names to get values for.
|
988 | * @returns {Object} Returns the key-value pairs.
|
989 | */
|
990 | function baseToPairs(object, props) {
|
991 | return arrayMap(props, function(key) {
|
992 | return [key, object[key]];
|
993 | });
|
994 | }
|
995 |
|
996 | /**
|
997 | * The base implementation of `_.unary` without support for storing metadata.
|
998 | *
|
999 | * @private
|
1000 | * @param {Function} func The function to cap arguments for.
|
1001 | * @returns {Function} Returns the new capped function.
|
1002 | */
|
1003 | function baseUnary(func) {
|
1004 | return function(value) {
|
1005 | return func(value);
|
1006 | };
|
1007 | }
|
1008 |
|
1009 | /**
|
1010 | * The base implementation of `_.values` and `_.valuesIn` which creates an
|
1011 | * array of `object` property values corresponding to the property names
|
1012 | * of `props`.
|
1013 | *
|
1014 | * @private
|
1015 | * @param {Object} object The object to query.
|
1016 | * @param {Array} props The property names to get values for.
|
1017 | * @returns {Object} Returns the array of property values.
|
1018 | */
|
1019 | function baseValues(object, props) {
|
1020 | return arrayMap(props, function(key) {
|
1021 | return object[key];
|
1022 | });
|
1023 | }
|
1024 |
|
1025 | /**
|
1026 | * Checks if a `cache` value for `key` exists.
|
1027 | *
|
1028 | * @private
|
1029 | * @param {Object} cache The cache to query.
|
1030 | * @param {string} key The key of the entry to check.
|
1031 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
1032 | */
|
1033 | function cacheHas(cache, key) {
|
1034 | return cache.has(key);
|
1035 | }
|
1036 |
|
1037 | /**
|
1038 | * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
|
1039 | * that is not found in the character symbols.
|
1040 | *
|
1041 | * @private
|
1042 | * @param {Array} strSymbols The string symbols to inspect.
|
1043 | * @param {Array} chrSymbols The character symbols to find.
|
1044 | * @returns {number} Returns the index of the first unmatched string symbol.
|
1045 | */
|
1046 | function charsStartIndex(strSymbols, chrSymbols) {
|
1047 | var index = -1,
|
1048 | length = strSymbols.length;
|
1049 |
|
1050 | while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
|
1051 | return index;
|
1052 | }
|
1053 |
|
1054 | /**
|
1055 | * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
|
1056 | * that is not found in the character symbols.
|
1057 | *
|
1058 | * @private
|
1059 | * @param {Array} strSymbols The string symbols to inspect.
|
1060 | * @param {Array} chrSymbols The character symbols to find.
|
1061 | * @returns {number} Returns the index of the last unmatched string symbol.
|
1062 | */
|
1063 | function charsEndIndex(strSymbols, chrSymbols) {
|
1064 | var index = strSymbols.length;
|
1065 |
|
1066 | while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
|
1067 | return index;
|
1068 | }
|
1069 |
|
1070 | /**
|
1071 | * Gets the number of `placeholder` occurrences in `array`.
|
1072 | *
|
1073 | * @private
|
1074 | * @param {Array} array The array to inspect.
|
1075 | * @param {*} placeholder The placeholder to search for.
|
1076 | * @returns {number} Returns the placeholder count.
|
1077 | */
|
1078 | function countHolders(array, placeholder) {
|
1079 | var length = array.length,
|
1080 | result = 0;
|
1081 |
|
1082 | while (length--) {
|
1083 | if (array[length] === placeholder) {
|
1084 | ++result;
|
1085 | }
|
1086 | }
|
1087 | return result;
|
1088 | }
|
1089 |
|
1090 | /**
|
1091 | * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
|
1092 | * letters to basic Latin letters.
|
1093 | *
|
1094 | * @private
|
1095 | * @param {string} letter The matched letter to deburr.
|
1096 | * @returns {string} Returns the deburred letter.
|
1097 | */
|
1098 | var deburrLetter = basePropertyOf(deburredLetters);
|
1099 |
|
1100 | /**
|
1101 | * Used by `_.escape` to convert characters to HTML entities.
|
1102 | *
|
1103 | * @private
|
1104 | * @param {string} chr The matched character to escape.
|
1105 | * @returns {string} Returns the escaped character.
|
1106 | */
|
1107 | var escapeHtmlChar = basePropertyOf(htmlEscapes);
|
1108 |
|
1109 | /**
|
1110 | * Used by `_.template` to escape characters for inclusion in compiled string literals.
|
1111 | *
|
1112 | * @private
|
1113 | * @param {string} chr The matched character to escape.
|
1114 | * @returns {string} Returns the escaped character.
|
1115 | */
|
1116 | function escapeStringChar(chr) {
|
1117 | return '\\' + stringEscapes[chr];
|
1118 | }
|
1119 |
|
1120 | /**
|
1121 | * Gets the value at `key` of `object`.
|
1122 | *
|
1123 | * @private
|
1124 | * @param {Object} [object] The object to query.
|
1125 | * @param {string} key The key of the property to get.
|
1126 | * @returns {*} Returns the property value.
|
1127 | */
|
1128 | function getValue(object, key) {
|
1129 | return object == null ? undefined : object[key];
|
1130 | }
|
1131 |
|
1132 | /**
|
1133 | * Checks if `string` contains Unicode symbols.
|
1134 | *
|
1135 | * @private
|
1136 | * @param {string} string The string to inspect.
|
1137 | * @returns {boolean} Returns `true` if a symbol is found, else `false`.
|
1138 | */
|
1139 | function hasUnicode(string) {
|
1140 | return reHasUnicode.test(string);
|
1141 | }
|
1142 |
|
1143 | /**
|
1144 | * Checks if `string` contains a word composed of Unicode symbols.
|
1145 | *
|
1146 | * @private
|
1147 | * @param {string} string The string to inspect.
|
1148 | * @returns {boolean} Returns `true` if a word is found, else `false`.
|
1149 | */
|
1150 | function hasUnicodeWord(string) {
|
1151 | return reHasUnicodeWord.test(string);
|
1152 | }
|
1153 |
|
1154 | /**
|
1155 | * Converts `iterator` to an array.
|
1156 | *
|
1157 | * @private
|
1158 | * @param {Object} iterator The iterator to convert.
|
1159 | * @returns {Array} Returns the converted array.
|
1160 | */
|
1161 | function iteratorToArray(iterator) {
|
1162 | var data,
|
1163 | result = [];
|
1164 |
|
1165 | while (!(data = iterator.next()).done) {
|
1166 | result.push(data.value);
|
1167 | }
|
1168 | return result;
|
1169 | }
|
1170 |
|
1171 | /**
|
1172 | * Converts `map` to its key-value pairs.
|
1173 | *
|
1174 | * @private
|
1175 | * @param {Object} map The map to convert.
|
1176 | * @returns {Array} Returns the key-value pairs.
|
1177 | */
|
1178 | function mapToArray(map) {
|
1179 | var index = -1,
|
1180 | result = Array(map.size);
|
1181 |
|
1182 | map.forEach(function(value, key) {
|
1183 | result[++index] = [key, value];
|
1184 | });
|
1185 | return result;
|
1186 | }
|
1187 |
|
1188 | /**
|
1189 | * Creates a unary function that invokes `func` with its argument transformed.
|
1190 | *
|
1191 | * @private
|
1192 | * @param {Function} func The function to wrap.
|
1193 | * @param {Function} transform The argument transform.
|
1194 | * @returns {Function} Returns the new function.
|
1195 | */
|
1196 | function overArg(func, transform) {
|
1197 | return function(arg) {
|
1198 | return func(transform(arg));
|
1199 | };
|
1200 | }
|
1201 |
|
1202 | /**
|
1203 | * Replaces all `placeholder` elements in `array` with an internal placeholder
|
1204 | * and returns an array of their indexes.
|
1205 | *
|
1206 | * @private
|
1207 | * @param {Array} array The array to modify.
|
1208 | * @param {*} placeholder The placeholder to replace.
|
1209 | * @returns {Array} Returns the new array of placeholder indexes.
|
1210 | */
|
1211 | function replaceHolders(array, placeholder) {
|
1212 | var index = -1,
|
1213 | length = array.length,
|
1214 | resIndex = 0,
|
1215 | result = [];
|
1216 |
|
1217 | while (++index < length) {
|
1218 | var value = array[index];
|
1219 | if (value === placeholder || value === PLACEHOLDER) {
|
1220 | array[index] = PLACEHOLDER;
|
1221 | result[resIndex++] = index;
|
1222 | }
|
1223 | }
|
1224 | return result;
|
1225 | }
|
1226 |
|
1227 | /**
|
1228 | * Gets the value at `key`, unless `key` is "__proto__".
|
1229 | *
|
1230 | * @private
|
1231 | * @param {Object} object The object to query.
|
1232 | * @param {string} key The key of the property to get.
|
1233 | * @returns {*} Returns the property value.
|
1234 | */
|
1235 | function safeGet(object, key) {
|
1236 | return key == '__proto__'
|
1237 | ? undefined
|
1238 | : object[key];
|
1239 | }
|
1240 |
|
1241 | /**
|
1242 | * Converts `set` to an array of its values.
|
1243 | *
|
1244 | * @private
|
1245 | * @param {Object} set The set to convert.
|
1246 | * @returns {Array} Returns the values.
|
1247 | */
|
1248 | function setToArray(set) {
|
1249 | var index = -1,
|
1250 | result = Array(set.size);
|
1251 |
|
1252 | set.forEach(function(value) {
|
1253 | result[++index] = value;
|
1254 | });
|
1255 | return result;
|
1256 | }
|
1257 |
|
1258 | /**
|
1259 | * Converts `set` to its value-value pairs.
|
1260 | *
|
1261 | * @private
|
1262 | * @param {Object} set The set to convert.
|
1263 | * @returns {Array} Returns the value-value pairs.
|
1264 | */
|
1265 | function setToPairs(set) {
|
1266 | var index = -1,
|
1267 | result = Array(set.size);
|
1268 |
|
1269 | set.forEach(function(value) {
|
1270 | result[++index] = [value, value];
|
1271 | });
|
1272 | return result;
|
1273 | }
|
1274 |
|
1275 | /**
|
1276 | * A specialized version of `_.indexOf` which performs strict equality
|
1277 | * comparisons of values, i.e. `===`.
|
1278 | *
|
1279 | * @private
|
1280 | * @param {Array} array The array to inspect.
|
1281 | * @param {*} value The value to search for.
|
1282 | * @param {number} fromIndex The index to search from.
|
1283 | * @returns {number} Returns the index of the matched value, else `-1`.
|
1284 | */
|
1285 | function strictIndexOf(array, value, fromIndex) {
|
1286 | var index = fromIndex - 1,
|
1287 | length = array.length;
|
1288 |
|
1289 | while (++index < length) {
|
1290 | if (array[index] === value) {
|
1291 | return index;
|
1292 | }
|
1293 | }
|
1294 | return -1;
|
1295 | }
|
1296 |
|
1297 | /**
|
1298 | * A specialized version of `_.lastIndexOf` which performs strict equality
|
1299 | * comparisons of values, i.e. `===`.
|
1300 | *
|
1301 | * @private
|
1302 | * @param {Array} array The array to inspect.
|
1303 | * @param {*} value The value to search for.
|
1304 | * @param {number} fromIndex The index to search from.
|
1305 | * @returns {number} Returns the index of the matched value, else `-1`.
|
1306 | */
|
1307 | function strictLastIndexOf(array, value, fromIndex) {
|
1308 | var index = fromIndex + 1;
|
1309 | while (index--) {
|
1310 | if (array[index] === value) {
|
1311 | return index;
|
1312 | }
|
1313 | }
|
1314 | return index;
|
1315 | }
|
1316 |
|
1317 | /**
|
1318 | * Gets the number of symbols in `string`.
|
1319 | *
|
1320 | * @private
|
1321 | * @param {string} string The string to inspect.
|
1322 | * @returns {number} Returns the string size.
|
1323 | */
|
1324 | function stringSize(string) {
|
1325 | return hasUnicode(string)
|
1326 | ? unicodeSize(string)
|
1327 | : asciiSize(string);
|
1328 | }
|
1329 |
|
1330 | /**
|
1331 | * Converts `string` to an array.
|
1332 | *
|
1333 | * @private
|
1334 | * @param {string} string The string to convert.
|
1335 | * @returns {Array} Returns the converted array.
|
1336 | */
|
1337 | function stringToArray(string) {
|
1338 | return hasUnicode(string)
|
1339 | ? unicodeToArray(string)
|
1340 | : asciiToArray(string);
|
1341 | }
|
1342 |
|
1343 | /**
|
1344 | * Used by `_.unescape` to convert HTML entities to characters.
|
1345 | *
|
1346 | * @private
|
1347 | * @param {string} chr The matched character to unescape.
|
1348 | * @returns {string} Returns the unescaped character.
|
1349 | */
|
1350 | var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
|
1351 |
|
1352 | /**
|
1353 | * Gets the size of a Unicode `string`.
|
1354 | *
|
1355 | * @private
|
1356 | * @param {string} string The string inspect.
|
1357 | * @returns {number} Returns the string size.
|
1358 | */
|
1359 | function unicodeSize(string) {
|
1360 | var result = reUnicode.lastIndex = 0;
|
1361 | while (reUnicode.test(string)) {
|
1362 | ++result;
|
1363 | }
|
1364 | return result;
|
1365 | }
|
1366 |
|
1367 | /**
|
1368 | * Converts a Unicode `string` to an array.
|
1369 | *
|
1370 | * @private
|
1371 | * @param {string} string The string to convert.
|
1372 | * @returns {Array} Returns the converted array.
|
1373 | */
|
1374 | function unicodeToArray(string) {
|
1375 | return string.match(reUnicode) || [];
|
1376 | }
|
1377 |
|
1378 | /**
|
1379 | * Splits a Unicode `string` into an array of its words.
|
1380 | *
|
1381 | * @private
|
1382 | * @param {string} The string to inspect.
|
1383 | * @returns {Array} Returns the words of `string`.
|
1384 | */
|
1385 | function unicodeWords(string) {
|
1386 | return string.match(reUnicodeWord) || [];
|
1387 | }
|
1388 |
|
1389 | /*--------------------------------------------------------------------------*/
|
1390 |
|
1391 | /**
|
1392 | * Create a new pristine `lodash` function using the `context` object.
|
1393 | *
|
1394 | * @static
|
1395 | * @memberOf _
|
1396 | * @since 1.1.0
|
1397 | * @category Util
|
1398 | * @param {Object} [context=root] The context object.
|
1399 | * @returns {Function} Returns a new `lodash` function.
|
1400 | * @example
|
1401 | *
|
1402 | * _.mixin({ 'foo': _.constant('foo') });
|
1403 | *
|
1404 | * var lodash = _.runInContext();
|
1405 | * lodash.mixin({ 'bar': lodash.constant('bar') });
|
1406 | *
|
1407 | * _.isFunction(_.foo);
|
1408 | * // => true
|
1409 | * _.isFunction(_.bar);
|
1410 | * // => false
|
1411 | *
|
1412 | * lodash.isFunction(lodash.foo);
|
1413 | * // => false
|
1414 | * lodash.isFunction(lodash.bar);
|
1415 | * // => true
|
1416 | *
|
1417 | * // Create a suped-up `defer` in Node.js.
|
1418 | * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
|
1419 | */
|
1420 | var runInContext = (function runInContext(context) {
|
1421 | context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
|
1422 |
|
1423 | /** Built-in constructor references. */
|
1424 | var Array = context.Array,
|
1425 | Date = context.Date,
|
1426 | Error = context.Error,
|
1427 | Function = context.Function,
|
1428 | Math = context.Math,
|
1429 | Object = context.Object,
|
1430 | RegExp = context.RegExp,
|
1431 | String = context.String,
|
1432 | TypeError = context.TypeError;
|
1433 |
|
1434 | /** Used for built-in method references. */
|
1435 | var arrayProto = Array.prototype,
|
1436 | funcProto = Function.prototype,
|
1437 | objectProto = Object.prototype;
|
1438 |
|
1439 | /** Used to detect overreaching core-js shims. */
|
1440 | var coreJsData = context['__core-js_shared__'];
|
1441 |
|
1442 | /** Used to resolve the decompiled source of functions. */
|
1443 | var funcToString = funcProto.toString;
|
1444 |
|
1445 | /** Used to check objects for own properties. */
|
1446 | var hasOwnProperty = objectProto.hasOwnProperty;
|
1447 |
|
1448 | /** Used to generate unique IDs. */
|
1449 | var idCounter = 0;
|
1450 |
|
1451 | /** Used to detect methods masquerading as native. */
|
1452 | var maskSrcKey = (function() {
|
1453 | var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
1454 | return uid ? ('Symbol(src)_1.' + uid) : '';
|
1455 | }());
|
1456 |
|
1457 | /**
|
1458 | * Used to resolve the
|
1459 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
1460 | * of values.
|
1461 | */
|
1462 | var nativeObjectToString = objectProto.toString;
|
1463 |
|
1464 | /** Used to infer the `Object` constructor. */
|
1465 | var objectCtorString = funcToString.call(Object);
|
1466 |
|
1467 | /** Used to restore the original `_` reference in `_.noConflict`. */
|
1468 | var oldDash = root._;
|
1469 |
|
1470 | /** Used to detect if a method is native. */
|
1471 | var reIsNative = RegExp('^' +
|
1472 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
1473 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
1474 | );
|
1475 |
|
1476 | /** Built-in value references. */
|
1477 | var Buffer = moduleExports ? context.Buffer : undefined,
|
1478 | Symbol = context.Symbol,
|
1479 | Uint8Array = context.Uint8Array,
|
1480 | allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
|
1481 | getPrototype = overArg(Object.getPrototypeOf, Object),
|
1482 | objectCreate = Object.create,
|
1483 | propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
1484 | splice = arrayProto.splice,
|
1485 | spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
|
1486 | symIterator = Symbol ? Symbol.iterator : undefined,
|
1487 | symToStringTag = Symbol ? Symbol.toStringTag : undefined;
|
1488 |
|
1489 | var defineProperty = (function() {
|
1490 | try {
|
1491 | var func = getNative(Object, 'defineProperty');
|
1492 | func({}, '', {});
|
1493 | return func;
|
1494 | } catch (e) {}
|
1495 | }());
|
1496 |
|
1497 | /** Mocked built-ins. */
|
1498 | var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
|
1499 | ctxNow = Date && Date.now !== root.Date.now && Date.now,
|
1500 | ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
|
1501 |
|
1502 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
1503 | var nativeCeil = Math.ceil,
|
1504 | nativeFloor = Math.floor,
|
1505 | nativeGetSymbols = Object.getOwnPropertySymbols,
|
1506 | nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
|
1507 | nativeIsFinite = context.isFinite,
|
1508 | nativeJoin = arrayProto.join,
|
1509 | nativeKeys = overArg(Object.keys, Object),
|
1510 | nativeMax = Math.max,
|
1511 | nativeMin = Math.min,
|
1512 | nativeNow = Date.now,
|
1513 | nativeParseInt = context.parseInt,
|
1514 | nativeRandom = Math.random,
|
1515 | nativeReverse = arrayProto.reverse;
|
1516 |
|
1517 | /* Built-in method references that are verified to be native. */
|
1518 | var DataView = getNative(context, 'DataView'),
|
1519 | Map = getNative(context, 'Map'),
|
1520 | Promise = getNative(context, 'Promise'),
|
1521 | Set = getNative(context, 'Set'),
|
1522 | WeakMap = getNative(context, 'WeakMap'),
|
1523 | nativeCreate = getNative(Object, 'create');
|
1524 |
|
1525 | /** Used to store function metadata. */
|
1526 | var metaMap = WeakMap && new WeakMap;
|
1527 |
|
1528 | /** Used to lookup unminified function names. */
|
1529 | var realNames = {};
|
1530 |
|
1531 | /** Used to detect maps, sets, and weakmaps. */
|
1532 | var dataViewCtorString = toSource(DataView),
|
1533 | mapCtorString = toSource(Map),
|
1534 | promiseCtorString = toSource(Promise),
|
1535 | setCtorString = toSource(Set),
|
1536 | weakMapCtorString = toSource(WeakMap);
|
1537 |
|
1538 | /** Used to convert symbols to primitives and strings. */
|
1539 | var symbolProto = Symbol ? Symbol.prototype : undefined,
|
1540 | symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
|
1541 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
1542 |
|
1543 | /*------------------------------------------------------------------------*/
|
1544 |
|
1545 | /**
|
1546 | * Creates a `lodash` object which wraps `value` to enable implicit method
|
1547 | * chain sequences. Methods that operate on and return arrays, collections,
|
1548 | * and functions can be chained together. Methods that retrieve a single value
|
1549 | * or may return a primitive value will automatically end the chain sequence
|
1550 | * and return the unwrapped value. Otherwise, the value must be unwrapped
|
1551 | * with `_#value`.
|
1552 | *
|
1553 | * Explicit chain sequences, which must be unwrapped with `_#value`, may be
|
1554 | * enabled using `_.chain`.
|
1555 | *
|
1556 | * The execution of chained methods is lazy, that is, it's deferred until
|
1557 | * `_#value` is implicitly or explicitly called.
|
1558 | *
|
1559 | * Lazy evaluation allows several methods to support shortcut fusion.
|
1560 | * Shortcut fusion is an optimization to merge iteratee calls; this avoids
|
1561 | * the creation of intermediate arrays and can greatly reduce the number of
|
1562 | * iteratee executions. Sections of a chain sequence qualify for shortcut
|
1563 | * fusion if the section is applied to an array and iteratees accept only
|
1564 | * one argument. The heuristic for whether a section qualifies for shortcut
|
1565 | * fusion is subject to change.
|
1566 | *
|
1567 | * Chaining is supported in custom builds as long as the `_#value` method is
|
1568 | * directly or indirectly included in the build.
|
1569 | *
|
1570 | * In addition to lodash methods, wrappers have `Array` and `String` methods.
|
1571 | *
|
1572 | * The wrapper `Array` methods are:
|
1573 | * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
|
1574 | *
|
1575 | * The wrapper `String` methods are:
|
1576 | * `replace` and `split`
|
1577 | *
|
1578 | * The wrapper methods that support shortcut fusion are:
|
1579 | * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
|
1580 | * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
|
1581 | * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
|
1582 | *
|
1583 | * The chainable wrapper methods are:
|
1584 | * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
|
1585 | * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
|
1586 | * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
|
1587 | * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
|
1588 | * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
|
1589 | * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
|
1590 | * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
|
1591 | * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
|
1592 | * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
|
1593 | * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
|
1594 | * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
|
1595 | * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
|
1596 | * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
|
1597 | * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
|
1598 | * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
|
1599 | * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
|
1600 | * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
|
1601 | * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
|
1602 | * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
|
1603 | * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
|
1604 | * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
|
1605 | * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
|
1606 | * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
|
1607 | * `zipObject`, `zipObjectDeep`, and `zipWith`
|
1608 | *
|
1609 | * The wrapper methods that are **not** chainable by default are:
|
1610 | * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
|
1611 | * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
|
1612 | * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
|
1613 | * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
|
1614 | * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
|
1615 | * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
|
1616 | * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
|
1617 | * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
|
1618 | * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
|
1619 | * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
|
1620 | * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
|
1621 | * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
|
1622 | * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
|
1623 | * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
|
1624 | * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
|
1625 | * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
|
1626 | * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
|
1627 | * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
|
1628 | * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
|
1629 | * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
|
1630 | * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
|
1631 | * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
|
1632 | * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
|
1633 | * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
|
1634 | * `upperFirst`, `value`, and `words`
|
1635 | *
|
1636 | * @name _
|
1637 | * @constructor
|
1638 | * @category Seq
|
1639 | * @param {*} value The value to wrap in a `lodash` instance.
|
1640 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
1641 | * @example
|
1642 | *
|
1643 | * function square(n) {
|
1644 | * return n * n;
|
1645 | * }
|
1646 | *
|
1647 | * var wrapped = _([1, 2, 3]);
|
1648 | *
|
1649 | * // Returns an unwrapped value.
|
1650 | * wrapped.reduce(_.add);
|
1651 | * // => 6
|
1652 | *
|
1653 | * // Returns a wrapped value.
|
1654 | * var squares = wrapped.map(square);
|
1655 | *
|
1656 | * _.isArray(squares);
|
1657 | * // => false
|
1658 | *
|
1659 | * _.isArray(squares.value());
|
1660 | * // => true
|
1661 | */
|
1662 | function lodash(value) {
|
1663 | if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
|
1664 | if (value instanceof LodashWrapper) {
|
1665 | return value;
|
1666 | }
|
1667 | if (hasOwnProperty.call(value, '__wrapped__')) {
|
1668 | return wrapperClone(value);
|
1669 | }
|
1670 | }
|
1671 | return new LodashWrapper(value);
|
1672 | }
|
1673 |
|
1674 | /**
|
1675 | * The base implementation of `_.create` without support for assigning
|
1676 | * properties to the created object.
|
1677 | *
|
1678 | * @private
|
1679 | * @param {Object} proto The object to inherit from.
|
1680 | * @returns {Object} Returns the new object.
|
1681 | */
|
1682 | var baseCreate = (function() {
|
1683 | function object() {}
|
1684 | return function(proto) {
|
1685 | if (!isObject(proto)) {
|
1686 | return {};
|
1687 | }
|
1688 | if (objectCreate) {
|
1689 | return objectCreate(proto);
|
1690 | }
|
1691 | object.prototype = proto;
|
1692 | var result = new object;
|
1693 | object.prototype = undefined;
|
1694 | return result;
|
1695 | };
|
1696 | }());
|
1697 |
|
1698 | /**
|
1699 | * The function whose prototype chain sequence wrappers inherit from.
|
1700 | *
|
1701 | * @private
|
1702 | */
|
1703 | function baseLodash() {
|
1704 | // No operation performed.
|
1705 | }
|
1706 |
|
1707 | /**
|
1708 | * The base constructor for creating `lodash` wrapper objects.
|
1709 | *
|
1710 | * @private
|
1711 | * @param {*} value The value to wrap.
|
1712 | * @param {boolean} [chainAll] Enable explicit method chain sequences.
|
1713 | */
|
1714 | function LodashWrapper(value, chainAll) {
|
1715 | this.__wrapped__ = value;
|
1716 | this.__actions__ = [];
|
1717 | this.__chain__ = !!chainAll;
|
1718 | this.__index__ = 0;
|
1719 | this.__values__ = undefined;
|
1720 | }
|
1721 |
|
1722 | /**
|
1723 | * By default, the template delimiters used by lodash are like those in
|
1724 | * embedded Ruby (ERB) as well as ES2015 template strings. Change the
|
1725 | * following template settings to use alternative delimiters.
|
1726 | *
|
1727 | * @static
|
1728 | * @memberOf _
|
1729 | * @type {Object}
|
1730 | */
|
1731 | lodash.templateSettings = {
|
1732 |
|
1733 | /**
|
1734 | * Used to detect `data` property values to be HTML-escaped.
|
1735 | *
|
1736 | * @memberOf _.templateSettings
|
1737 | * @type {RegExp}
|
1738 | */
|
1739 | 'escape': reEscape,
|
1740 |
|
1741 | /**
|
1742 | * Used to detect code to be evaluated.
|
1743 | *
|
1744 | * @memberOf _.templateSettings
|
1745 | * @type {RegExp}
|
1746 | */
|
1747 | 'evaluate': reEvaluate,
|
1748 |
|
1749 | /**
|
1750 | * Used to detect `data` property values to inject.
|
1751 | *
|
1752 | * @memberOf _.templateSettings
|
1753 | * @type {RegExp}
|
1754 | */
|
1755 | 'interpolate': reInterpolate,
|
1756 |
|
1757 | /**
|
1758 | * Used to reference the data object in the template text.
|
1759 | *
|
1760 | * @memberOf _.templateSettings
|
1761 | * @type {string}
|
1762 | */
|
1763 | 'variable': '',
|
1764 |
|
1765 | /**
|
1766 | * Used to import variables into the compiled template.
|
1767 | *
|
1768 | * @memberOf _.templateSettings
|
1769 | * @type {Object}
|
1770 | */
|
1771 | 'imports': {
|
1772 |
|
1773 | /**
|
1774 | * A reference to the `lodash` function.
|
1775 | *
|
1776 | * @memberOf _.templateSettings.imports
|
1777 | * @type {Function}
|
1778 | */
|
1779 | '_': lodash
|
1780 | }
|
1781 | };
|
1782 |
|
1783 | // Ensure wrappers are instances of `baseLodash`.
|
1784 | lodash.prototype = baseLodash.prototype;
|
1785 | lodash.prototype.constructor = lodash;
|
1786 |
|
1787 | LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
1788 | LodashWrapper.prototype.constructor = LodashWrapper;
|
1789 |
|
1790 | /*------------------------------------------------------------------------*/
|
1791 |
|
1792 | /**
|
1793 | * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
|
1794 | *
|
1795 | * @private
|
1796 | * @constructor
|
1797 | * @param {*} value The value to wrap.
|
1798 | */
|
1799 | function LazyWrapper(value) {
|
1800 | this.__wrapped__ = value;
|
1801 | this.__actions__ = [];
|
1802 | this.__dir__ = 1;
|
1803 | this.__filtered__ = false;
|
1804 | this.__iteratees__ = [];
|
1805 | this.__takeCount__ = MAX_ARRAY_LENGTH;
|
1806 | this.__views__ = [];
|
1807 | }
|
1808 |
|
1809 | /**
|
1810 | * Creates a clone of the lazy wrapper object.
|
1811 | *
|
1812 | * @private
|
1813 | * @name clone
|
1814 | * @memberOf LazyWrapper
|
1815 | * @returns {Object} Returns the cloned `LazyWrapper` object.
|
1816 | */
|
1817 | function lazyClone() {
|
1818 | var result = new LazyWrapper(this.__wrapped__);
|
1819 | result.__actions__ = copyArray(this.__actions__);
|
1820 | result.__dir__ = this.__dir__;
|
1821 | result.__filtered__ = this.__filtered__;
|
1822 | result.__iteratees__ = copyArray(this.__iteratees__);
|
1823 | result.__takeCount__ = this.__takeCount__;
|
1824 | result.__views__ = copyArray(this.__views__);
|
1825 | return result;
|
1826 | }
|
1827 |
|
1828 | /**
|
1829 | * Reverses the direction of lazy iteration.
|
1830 | *
|
1831 | * @private
|
1832 | * @name reverse
|
1833 | * @memberOf LazyWrapper
|
1834 | * @returns {Object} Returns the new reversed `LazyWrapper` object.
|
1835 | */
|
1836 | function lazyReverse() {
|
1837 | if (this.__filtered__) {
|
1838 | var result = new LazyWrapper(this);
|
1839 | result.__dir__ = -1;
|
1840 | result.__filtered__ = true;
|
1841 | } else {
|
1842 | result = this.clone();
|
1843 | result.__dir__ *= -1;
|
1844 | }
|
1845 | return result;
|
1846 | }
|
1847 |
|
1848 | /**
|
1849 | * Extracts the unwrapped value from its lazy wrapper.
|
1850 | *
|
1851 | * @private
|
1852 | * @name value
|
1853 | * @memberOf LazyWrapper
|
1854 | * @returns {*} Returns the unwrapped value.
|
1855 | */
|
1856 | function lazyValue() {
|
1857 | var array = this.__wrapped__.value(),
|
1858 | dir = this.__dir__,
|
1859 | isArr = isArray(array),
|
1860 | isRight = dir < 0,
|
1861 | arrLength = isArr ? array.length : 0,
|
1862 | view = getView(0, arrLength, this.__views__),
|
1863 | start = view.start,
|
1864 | end = view.end,
|
1865 | length = end - start,
|
1866 | index = isRight ? end : (start - 1),
|
1867 | iteratees = this.__iteratees__,
|
1868 | iterLength = iteratees.length,
|
1869 | resIndex = 0,
|
1870 | takeCount = nativeMin(length, this.__takeCount__);
|
1871 |
|
1872 | if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
|
1873 | return baseWrapperValue(array, this.__actions__);
|
1874 | }
|
1875 | var result = [];
|
1876 |
|
1877 | outer:
|
1878 | while (length-- && resIndex < takeCount) {
|
1879 | index += dir;
|
1880 |
|
1881 | var iterIndex = -1,
|
1882 | value = array[index];
|
1883 |
|
1884 | while (++iterIndex < iterLength) {
|
1885 | var data = iteratees[iterIndex],
|
1886 | iteratee = data.iteratee,
|
1887 | type = data.type,
|
1888 | computed = iteratee(value);
|
1889 |
|
1890 | if (type == LAZY_MAP_FLAG) {
|
1891 | value = computed;
|
1892 | } else if (!computed) {
|
1893 | if (type == LAZY_FILTER_FLAG) {
|
1894 | continue outer;
|
1895 | } else {
|
1896 | break outer;
|
1897 | }
|
1898 | }
|
1899 | }
|
1900 | result[resIndex++] = value;
|
1901 | }
|
1902 | return result;
|
1903 | }
|
1904 |
|
1905 | // Ensure `LazyWrapper` is an instance of `baseLodash`.
|
1906 | LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
1907 | LazyWrapper.prototype.constructor = LazyWrapper;
|
1908 |
|
1909 | /*------------------------------------------------------------------------*/
|
1910 |
|
1911 | /**
|
1912 | * Creates a hash object.
|
1913 | *
|
1914 | * @private
|
1915 | * @constructor
|
1916 | * @param {Array} [entries] The key-value pairs to cache.
|
1917 | */
|
1918 | function Hash(entries) {
|
1919 | var index = -1,
|
1920 | length = entries == null ? 0 : entries.length;
|
1921 |
|
1922 | this.clear();
|
1923 | while (++index < length) {
|
1924 | var entry = entries[index];
|
1925 | this.set(entry[0], entry[1]);
|
1926 | }
|
1927 | }
|
1928 |
|
1929 | /**
|
1930 | * Removes all key-value entries from the hash.
|
1931 | *
|
1932 | * @private
|
1933 | * @name clear
|
1934 | * @memberOf Hash
|
1935 | */
|
1936 | function hashClear() {
|
1937 | this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
1938 | this.size = 0;
|
1939 | }
|
1940 |
|
1941 | /**
|
1942 | * Removes `key` and its value from the hash.
|
1943 | *
|
1944 | * @private
|
1945 | * @name delete
|
1946 | * @memberOf Hash
|
1947 | * @param {Object} hash The hash to modify.
|
1948 | * @param {string} key The key of the value to remove.
|
1949 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
1950 | */
|
1951 | function hashDelete(key) {
|
1952 | var result = this.has(key) && delete this.__data__[key];
|
1953 | this.size -= result ? 1 : 0;
|
1954 | return result;
|
1955 | }
|
1956 |
|
1957 | /**
|
1958 | * Gets the hash value for `key`.
|
1959 | *
|
1960 | * @private
|
1961 | * @name get
|
1962 | * @memberOf Hash
|
1963 | * @param {string} key The key of the value to get.
|
1964 | * @returns {*} Returns the entry value.
|
1965 | */
|
1966 | function hashGet(key) {
|
1967 | var data = this.__data__;
|
1968 | if (nativeCreate) {
|
1969 | var result = data[key];
|
1970 | return result === HASH_UNDEFINED ? undefined : result;
|
1971 | }
|
1972 | return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
1973 | }
|
1974 |
|
1975 | /**
|
1976 | * Checks if a hash value for `key` exists.
|
1977 | *
|
1978 | * @private
|
1979 | * @name has
|
1980 | * @memberOf Hash
|
1981 | * @param {string} key The key of the entry to check.
|
1982 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
1983 | */
|
1984 | function hashHas(key) {
|
1985 | var data = this.__data__;
|
1986 | return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
|
1987 | }
|
1988 |
|
1989 | /**
|
1990 | * Sets the hash `key` to `value`.
|
1991 | *
|
1992 | * @private
|
1993 | * @name set
|
1994 | * @memberOf Hash
|
1995 | * @param {string} key The key of the value to set.
|
1996 | * @param {*} value The value to set.
|
1997 | * @returns {Object} Returns the hash instance.
|
1998 | */
|
1999 | function hashSet(key, value) {
|
2000 | var data = this.__data__;
|
2001 | this.size += this.has(key) ? 0 : 1;
|
2002 | data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
2003 | return this;
|
2004 | }
|
2005 |
|
2006 | // Add methods to `Hash`.
|
2007 | Hash.prototype.clear = hashClear;
|
2008 | Hash.prototype['delete'] = hashDelete;
|
2009 | Hash.prototype.get = hashGet;
|
2010 | Hash.prototype.has = hashHas;
|
2011 | Hash.prototype.set = hashSet;
|
2012 |
|
2013 | /*------------------------------------------------------------------------*/
|
2014 |
|
2015 | /**
|
2016 | * Creates an list cache object.
|
2017 | *
|
2018 | * @private
|
2019 | * @constructor
|
2020 | * @param {Array} [entries] The key-value pairs to cache.
|
2021 | */
|
2022 | function ListCache(entries) {
|
2023 | var index = -1,
|
2024 | length = entries == null ? 0 : entries.length;
|
2025 |
|
2026 | this.clear();
|
2027 | while (++index < length) {
|
2028 | var entry = entries[index];
|
2029 | this.set(entry[0], entry[1]);
|
2030 | }
|
2031 | }
|
2032 |
|
2033 | /**
|
2034 | * Removes all key-value entries from the list cache.
|
2035 | *
|
2036 | * @private
|
2037 | * @name clear
|
2038 | * @memberOf ListCache
|
2039 | */
|
2040 | function listCacheClear() {
|
2041 | this.__data__ = [];
|
2042 | this.size = 0;
|
2043 | }
|
2044 |
|
2045 | /**
|
2046 | * Removes `key` and its value from the list cache.
|
2047 | *
|
2048 | * @private
|
2049 | * @name delete
|
2050 | * @memberOf ListCache
|
2051 | * @param {string} key The key of the value to remove.
|
2052 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
2053 | */
|
2054 | function listCacheDelete(key) {
|
2055 | var data = this.__data__,
|
2056 | index = assocIndexOf(data, key);
|
2057 |
|
2058 | if (index < 0) {
|
2059 | return false;
|
2060 | }
|
2061 | var lastIndex = data.length - 1;
|
2062 | if (index == lastIndex) {
|
2063 | data.pop();
|
2064 | } else {
|
2065 | splice.call(data, index, 1);
|
2066 | }
|
2067 | --this.size;
|
2068 | return true;
|
2069 | }
|
2070 |
|
2071 | /**
|
2072 | * Gets the list cache value for `key`.
|
2073 | *
|
2074 | * @private
|
2075 | * @name get
|
2076 | * @memberOf ListCache
|
2077 | * @param {string} key The key of the value to get.
|
2078 | * @returns {*} Returns the entry value.
|
2079 | */
|
2080 | function listCacheGet(key) {
|
2081 | var data = this.__data__,
|
2082 | index = assocIndexOf(data, key);
|
2083 |
|
2084 | return index < 0 ? undefined : data[index][1];
|
2085 | }
|
2086 |
|
2087 | /**
|
2088 | * Checks if a list cache value for `key` exists.
|
2089 | *
|
2090 | * @private
|
2091 | * @name has
|
2092 | * @memberOf ListCache
|
2093 | * @param {string} key The key of the entry to check.
|
2094 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
2095 | */
|
2096 | function listCacheHas(key) {
|
2097 | return assocIndexOf(this.__data__, key) > -1;
|
2098 | }
|
2099 |
|
2100 | /**
|
2101 | * Sets the list cache `key` to `value`.
|
2102 | *
|
2103 | * @private
|
2104 | * @name set
|
2105 | * @memberOf ListCache
|
2106 | * @param {string} key The key of the value to set.
|
2107 | * @param {*} value The value to set.
|
2108 | * @returns {Object} Returns the list cache instance.
|
2109 | */
|
2110 | function listCacheSet(key, value) {
|
2111 | var data = this.__data__,
|
2112 | index = assocIndexOf(data, key);
|
2113 |
|
2114 | if (index < 0) {
|
2115 | ++this.size;
|
2116 | data.push([key, value]);
|
2117 | } else {
|
2118 | data[index][1] = value;
|
2119 | }
|
2120 | return this;
|
2121 | }
|
2122 |
|
2123 | // Add methods to `ListCache`.
|
2124 | ListCache.prototype.clear = listCacheClear;
|
2125 | ListCache.prototype['delete'] = listCacheDelete;
|
2126 | ListCache.prototype.get = listCacheGet;
|
2127 | ListCache.prototype.has = listCacheHas;
|
2128 | ListCache.prototype.set = listCacheSet;
|
2129 |
|
2130 | /*------------------------------------------------------------------------*/
|
2131 |
|
2132 | /**
|
2133 | * Creates a map cache object to store key-value pairs.
|
2134 | *
|
2135 | * @private
|
2136 | * @constructor
|
2137 | * @param {Array} [entries] The key-value pairs to cache.
|
2138 | */
|
2139 | function MapCache(entries) {
|
2140 | var index = -1,
|
2141 | length = entries == null ? 0 : entries.length;
|
2142 |
|
2143 | this.clear();
|
2144 | while (++index < length) {
|
2145 | var entry = entries[index];
|
2146 | this.set(entry[0], entry[1]);
|
2147 | }
|
2148 | }
|
2149 |
|
2150 | /**
|
2151 | * Removes all key-value entries from the map.
|
2152 | *
|
2153 | * @private
|
2154 | * @name clear
|
2155 | * @memberOf MapCache
|
2156 | */
|
2157 | function mapCacheClear() {
|
2158 | this.size = 0;
|
2159 | this.__data__ = {
|
2160 | 'hash': new Hash,
|
2161 | 'map': new (Map || ListCache),
|
2162 | 'string': new Hash
|
2163 | };
|
2164 | }
|
2165 |
|
2166 | /**
|
2167 | * Removes `key` and its value from the map.
|
2168 | *
|
2169 | * @private
|
2170 | * @name delete
|
2171 | * @memberOf MapCache
|
2172 | * @param {string} key The key of the value to remove.
|
2173 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
2174 | */
|
2175 | function mapCacheDelete(key) {
|
2176 | var result = getMapData(this, key)['delete'](key);
|
2177 | this.size -= result ? 1 : 0;
|
2178 | return result;
|
2179 | }
|
2180 |
|
2181 | /**
|
2182 | * Gets the map value for `key`.
|
2183 | *
|
2184 | * @private
|
2185 | * @name get
|
2186 | * @memberOf MapCache
|
2187 | * @param {string} key The key of the value to get.
|
2188 | * @returns {*} Returns the entry value.
|
2189 | */
|
2190 | function mapCacheGet(key) {
|
2191 | return getMapData(this, key).get(key);
|
2192 | }
|
2193 |
|
2194 | /**
|
2195 | * Checks if a map value for `key` exists.
|
2196 | *
|
2197 | * @private
|
2198 | * @name has
|
2199 | * @memberOf MapCache
|
2200 | * @param {string} key The key of the entry to check.
|
2201 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
2202 | */
|
2203 | function mapCacheHas(key) {
|
2204 | return getMapData(this, key).has(key);
|
2205 | }
|
2206 |
|
2207 | /**
|
2208 | * Sets the map `key` to `value`.
|
2209 | *
|
2210 | * @private
|
2211 | * @name set
|
2212 | * @memberOf MapCache
|
2213 | * @param {string} key The key of the value to set.
|
2214 | * @param {*} value The value to set.
|
2215 | * @returns {Object} Returns the map cache instance.
|
2216 | */
|
2217 | function mapCacheSet(key, value) {
|
2218 | var data = getMapData(this, key),
|
2219 | size = data.size;
|
2220 |
|
2221 | data.set(key, value);
|
2222 | this.size += data.size == size ? 0 : 1;
|
2223 | return this;
|
2224 | }
|
2225 |
|
2226 | // Add methods to `MapCache`.
|
2227 | MapCache.prototype.clear = mapCacheClear;
|
2228 | MapCache.prototype['delete'] = mapCacheDelete;
|
2229 | MapCache.prototype.get = mapCacheGet;
|
2230 | MapCache.prototype.has = mapCacheHas;
|
2231 | MapCache.prototype.set = mapCacheSet;
|
2232 |
|
2233 | /*------------------------------------------------------------------------*/
|
2234 |
|
2235 | /**
|
2236 | *
|
2237 | * Creates an array cache object to store unique values.
|
2238 | *
|
2239 | * @private
|
2240 | * @constructor
|
2241 | * @param {Array} [values] The values to cache.
|
2242 | */
|
2243 | function SetCache(values) {
|
2244 | var index = -1,
|
2245 | length = values == null ? 0 : values.length;
|
2246 |
|
2247 | this.__data__ = new MapCache;
|
2248 | while (++index < length) {
|
2249 | this.add(values[index]);
|
2250 | }
|
2251 | }
|
2252 |
|
2253 | /**
|
2254 | * Adds `value` to the array cache.
|
2255 | *
|
2256 | * @private
|
2257 | * @name add
|
2258 | * @memberOf SetCache
|
2259 | * @alias push
|
2260 | * @param {*} value The value to cache.
|
2261 | * @returns {Object} Returns the cache instance.
|
2262 | */
|
2263 | function setCacheAdd(value) {
|
2264 | this.__data__.set(value, HASH_UNDEFINED);
|
2265 | return this;
|
2266 | }
|
2267 |
|
2268 | /**
|
2269 | * Checks if `value` is in the array cache.
|
2270 | *
|
2271 | * @private
|
2272 | * @name has
|
2273 | * @memberOf SetCache
|
2274 | * @param {*} value The value to search for.
|
2275 | * @returns {number} Returns `true` if `value` is found, else `false`.
|
2276 | */
|
2277 | function setCacheHas(value) {
|
2278 | return this.__data__.has(value);
|
2279 | }
|
2280 |
|
2281 | // Add methods to `SetCache`.
|
2282 | SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
2283 | SetCache.prototype.has = setCacheHas;
|
2284 |
|
2285 | /*------------------------------------------------------------------------*/
|
2286 |
|
2287 | /**
|
2288 | * Creates a stack cache object to store key-value pairs.
|
2289 | *
|
2290 | * @private
|
2291 | * @constructor
|
2292 | * @param {Array} [entries] The key-value pairs to cache.
|
2293 | */
|
2294 | function Stack(entries) {
|
2295 | var data = this.__data__ = new ListCache(entries);
|
2296 | this.size = data.size;
|
2297 | }
|
2298 |
|
2299 | /**
|
2300 | * Removes all key-value entries from the stack.
|
2301 | *
|
2302 | * @private
|
2303 | * @name clear
|
2304 | * @memberOf Stack
|
2305 | */
|
2306 | function stackClear() {
|
2307 | this.__data__ = new ListCache;
|
2308 | this.size = 0;
|
2309 | }
|
2310 |
|
2311 | /**
|
2312 | * Removes `key` and its value from the stack.
|
2313 | *
|
2314 | * @private
|
2315 | * @name delete
|
2316 | * @memberOf Stack
|
2317 | * @param {string} key The key of the value to remove.
|
2318 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
2319 | */
|
2320 | function stackDelete(key) {
|
2321 | var data = this.__data__,
|
2322 | result = data['delete'](key);
|
2323 |
|
2324 | this.size = data.size;
|
2325 | return result;
|
2326 | }
|
2327 |
|
2328 | /**
|
2329 | * Gets the stack value for `key`.
|
2330 | *
|
2331 | * @private
|
2332 | * @name get
|
2333 | * @memberOf Stack
|
2334 | * @param {string} key The key of the value to get.
|
2335 | * @returns {*} Returns the entry value.
|
2336 | */
|
2337 | function stackGet(key) {
|
2338 | return this.__data__.get(key);
|
2339 | }
|
2340 |
|
2341 | /**
|
2342 | * Checks if a stack value for `key` exists.
|
2343 | *
|
2344 | * @private
|
2345 | * @name has
|
2346 | * @memberOf Stack
|
2347 | * @param {string} key The key of the entry to check.
|
2348 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
2349 | */
|
2350 | function stackHas(key) {
|
2351 | return this.__data__.has(key);
|
2352 | }
|
2353 |
|
2354 | /**
|
2355 | * Sets the stack `key` to `value`.
|
2356 | *
|
2357 | * @private
|
2358 | * @name set
|
2359 | * @memberOf Stack
|
2360 | * @param {string} key The key of the value to set.
|
2361 | * @param {*} value The value to set.
|
2362 | * @returns {Object} Returns the stack cache instance.
|
2363 | */
|
2364 | function stackSet(key, value) {
|
2365 | var data = this.__data__;
|
2366 | if (data instanceof ListCache) {
|
2367 | var pairs = data.__data__;
|
2368 | if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
2369 | pairs.push([key, value]);
|
2370 | this.size = ++data.size;
|
2371 | return this;
|
2372 | }
|
2373 | data = this.__data__ = new MapCache(pairs);
|
2374 | }
|
2375 | data.set(key, value);
|
2376 | this.size = data.size;
|
2377 | return this;
|
2378 | }
|
2379 |
|
2380 | // Add methods to `Stack`.
|
2381 | Stack.prototype.clear = stackClear;
|
2382 | Stack.prototype['delete'] = stackDelete;
|
2383 | Stack.prototype.get = stackGet;
|
2384 | Stack.prototype.has = stackHas;
|
2385 | Stack.prototype.set = stackSet;
|
2386 |
|
2387 | /*------------------------------------------------------------------------*/
|
2388 |
|
2389 | /**
|
2390 | * Creates an array of the enumerable property names of the array-like `value`.
|
2391 | *
|
2392 | * @private
|
2393 | * @param {*} value The value to query.
|
2394 | * @param {boolean} inherited Specify returning inherited property names.
|
2395 | * @returns {Array} Returns the array of property names.
|
2396 | */
|
2397 | function arrayLikeKeys(value, inherited) {
|
2398 | var isArr = isArray(value),
|
2399 | isArg = !isArr && isArguments(value),
|
2400 | isBuff = !isArr && !isArg && isBuffer(value),
|
2401 | isType = !isArr && !isArg && !isBuff && isTypedArray(value),
|
2402 | skipIndexes = isArr || isArg || isBuff || isType,
|
2403 | result = skipIndexes ? baseTimes(value.length, String) : [],
|
2404 | length = result.length;
|
2405 |
|
2406 | for (var key in value) {
|
2407 | if ((inherited || hasOwnProperty.call(value, key)) &&
|
2408 | !(skipIndexes && (
|
2409 | // Safari 9 has enumerable `arguments.length` in strict mode.
|
2410 | key == 'length' ||
|
2411 | // Node.js 0.10 has enumerable non-index properties on buffers.
|
2412 | (isBuff && (key == 'offset' || key == 'parent')) ||
|
2413 | // PhantomJS 2 has enumerable non-index properties on typed arrays.
|
2414 | (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
|
2415 | // Skip index properties.
|
2416 | isIndex(key, length)
|
2417 | ))) {
|
2418 | result.push(key);
|
2419 | }
|
2420 | }
|
2421 | return result;
|
2422 | }
|
2423 |
|
2424 | /**
|
2425 | * A specialized version of `_.sample` for arrays.
|
2426 | *
|
2427 | * @private
|
2428 | * @param {Array} array The array to sample.
|
2429 | * @returns {*} Returns the random element.
|
2430 | */
|
2431 | function arraySample(array) {
|
2432 | var length = array.length;
|
2433 | return length ? array[baseRandom(0, length - 1)] : undefined;
|
2434 | }
|
2435 |
|
2436 | /**
|
2437 | * A specialized version of `_.sampleSize` for arrays.
|
2438 | *
|
2439 | * @private
|
2440 | * @param {Array} array The array to sample.
|
2441 | * @param {number} n The number of elements to sample.
|
2442 | * @returns {Array} Returns the random elements.
|
2443 | */
|
2444 | function arraySampleSize(array, n) {
|
2445 | return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
|
2446 | }
|
2447 |
|
2448 | /**
|
2449 | * A specialized version of `_.shuffle` for arrays.
|
2450 | *
|
2451 | * @private
|
2452 | * @param {Array} array The array to shuffle.
|
2453 | * @returns {Array} Returns the new shuffled array.
|
2454 | */
|
2455 | function arrayShuffle(array) {
|
2456 | return shuffleSelf(copyArray(array));
|
2457 | }
|
2458 |
|
2459 | /**
|
2460 | * This function is like `assignValue` except that it doesn't assign
|
2461 | * `undefined` values.
|
2462 | *
|
2463 | * @private
|
2464 | * @param {Object} object The object to modify.
|
2465 | * @param {string} key The key of the property to assign.
|
2466 | * @param {*} value The value to assign.
|
2467 | */
|
2468 | function assignMergeValue(object, key, value) {
|
2469 | if ((value !== undefined && !eq(object[key], value)) ||
|
2470 | (value === undefined && !(key in object))) {
|
2471 | baseAssignValue(object, key, value);
|
2472 | }
|
2473 | }
|
2474 |
|
2475 | /**
|
2476 | * Assigns `value` to `key` of `object` if the existing value is not equivalent
|
2477 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
2478 | * for equality comparisons.
|
2479 | *
|
2480 | * @private
|
2481 | * @param {Object} object The object to modify.
|
2482 | * @param {string} key The key of the property to assign.
|
2483 | * @param {*} value The value to assign.
|
2484 | */
|
2485 | function assignValue(object, key, value) {
|
2486 | var objValue = object[key];
|
2487 | if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
2488 | (value === undefined && !(key in object))) {
|
2489 | baseAssignValue(object, key, value);
|
2490 | }
|
2491 | }
|
2492 |
|
2493 | /**
|
2494 | * Gets the index at which the `key` is found in `array` of key-value pairs.
|
2495 | *
|
2496 | * @private
|
2497 | * @param {Array} array The array to inspect.
|
2498 | * @param {*} key The key to search for.
|
2499 | * @returns {number} Returns the index of the matched value, else `-1`.
|
2500 | */
|
2501 | function assocIndexOf(array, key) {
|
2502 | var length = array.length;
|
2503 | while (length--) {
|
2504 | if (eq(array[length][0], key)) {
|
2505 | return length;
|
2506 | }
|
2507 | }
|
2508 | return -1;
|
2509 | }
|
2510 |
|
2511 | /**
|
2512 | * Aggregates elements of `collection` on `accumulator` with keys transformed
|
2513 | * by `iteratee` and values set by `setter`.
|
2514 | *
|
2515 | * @private
|
2516 | * @param {Array|Object} collection The collection to iterate over.
|
2517 | * @param {Function} setter The function to set `accumulator` values.
|
2518 | * @param {Function} iteratee The iteratee to transform keys.
|
2519 | * @param {Object} accumulator The initial aggregated object.
|
2520 | * @returns {Function} Returns `accumulator`.
|
2521 | */
|
2522 | function baseAggregator(collection, setter, iteratee, accumulator) {
|
2523 | baseEach(collection, function(value, key, collection) {
|
2524 | setter(accumulator, value, iteratee(value), collection);
|
2525 | });
|
2526 | return accumulator;
|
2527 | }
|
2528 |
|
2529 | /**
|
2530 | * The base implementation of `_.assign` without support for multiple sources
|
2531 | * or `customizer` functions.
|
2532 | *
|
2533 | * @private
|
2534 | * @param {Object} object The destination object.
|
2535 | * @param {Object} source The source object.
|
2536 | * @returns {Object} Returns `object`.
|
2537 | */
|
2538 | function baseAssign(object, source) {
|
2539 | return object && copyObject(source, keys(source), object);
|
2540 | }
|
2541 |
|
2542 | /**
|
2543 | * The base implementation of `_.assignIn` without support for multiple sources
|
2544 | * or `customizer` functions.
|
2545 | *
|
2546 | * @private
|
2547 | * @param {Object} object The destination object.
|
2548 | * @param {Object} source The source object.
|
2549 | * @returns {Object} Returns `object`.
|
2550 | */
|
2551 | function baseAssignIn(object, source) {
|
2552 | return object && copyObject(source, keysIn(source), object);
|
2553 | }
|
2554 |
|
2555 | /**
|
2556 | * The base implementation of `assignValue` and `assignMergeValue` without
|
2557 | * value checks.
|
2558 | *
|
2559 | * @private
|
2560 | * @param {Object} object The object to modify.
|
2561 | * @param {string} key The key of the property to assign.
|
2562 | * @param {*} value The value to assign.
|
2563 | */
|
2564 | function baseAssignValue(object, key, value) {
|
2565 | if (key == '__proto__' && defineProperty) {
|
2566 | defineProperty(object, key, {
|
2567 | 'configurable': true,
|
2568 | 'enumerable': true,
|
2569 | 'value': value,
|
2570 | 'writable': true
|
2571 | });
|
2572 | } else {
|
2573 | object[key] = value;
|
2574 | }
|
2575 | }
|
2576 |
|
2577 | /**
|
2578 | * The base implementation of `_.at` without support for individual paths.
|
2579 | *
|
2580 | * @private
|
2581 | * @param {Object} object The object to iterate over.
|
2582 | * @param {string[]} paths The property paths to pick.
|
2583 | * @returns {Array} Returns the picked elements.
|
2584 | */
|
2585 | function baseAt(object, paths) {
|
2586 | var index = -1,
|
2587 | length = paths.length,
|
2588 | result = Array(length),
|
2589 | skip = object == null;
|
2590 |
|
2591 | while (++index < length) {
|
2592 | result[index] = skip ? undefined : get(object, paths[index]);
|
2593 | }
|
2594 | return result;
|
2595 | }
|
2596 |
|
2597 | /**
|
2598 | * The base implementation of `_.clamp` which doesn't coerce arguments.
|
2599 | *
|
2600 | * @private
|
2601 | * @param {number} number The number to clamp.
|
2602 | * @param {number} [lower] The lower bound.
|
2603 | * @param {number} upper The upper bound.
|
2604 | * @returns {number} Returns the clamped number.
|
2605 | */
|
2606 | function baseClamp(number, lower, upper) {
|
2607 | if (number === number) {
|
2608 | if (upper !== undefined) {
|
2609 | number = number <= upper ? number : upper;
|
2610 | }
|
2611 | if (lower !== undefined) {
|
2612 | number = number >= lower ? number : lower;
|
2613 | }
|
2614 | }
|
2615 | return number;
|
2616 | }
|
2617 |
|
2618 | /**
|
2619 | * The base implementation of `_.clone` and `_.cloneDeep` which tracks
|
2620 | * traversed objects.
|
2621 | *
|
2622 | * @private
|
2623 | * @param {*} value The value to clone.
|
2624 | * @param {boolean} bitmask The bitmask flags.
|
2625 | * 1 - Deep clone
|
2626 | * 2 - Flatten inherited properties
|
2627 | * 4 - Clone symbols
|
2628 | * @param {Function} [customizer] The function to customize cloning.
|
2629 | * @param {string} [key] The key of `value`.
|
2630 | * @param {Object} [object] The parent object of `value`.
|
2631 | * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
2632 | * @returns {*} Returns the cloned value.
|
2633 | */
|
2634 | function baseClone(value, bitmask, customizer, key, object, stack) {
|
2635 | var result,
|
2636 | isDeep = bitmask & CLONE_DEEP_FLAG,
|
2637 | isFlat = bitmask & CLONE_FLAT_FLAG,
|
2638 | isFull = bitmask & CLONE_SYMBOLS_FLAG;
|
2639 |
|
2640 | if (customizer) {
|
2641 | result = object ? customizer(value, key, object, stack) : customizer(value);
|
2642 | }
|
2643 | if (result !== undefined) {
|
2644 | return result;
|
2645 | }
|
2646 | if (!isObject(value)) {
|
2647 | return value;
|
2648 | }
|
2649 | var isArr = isArray(value);
|
2650 | if (isArr) {
|
2651 | result = initCloneArray(value);
|
2652 | if (!isDeep) {
|
2653 | return copyArray(value, result);
|
2654 | }
|
2655 | } else {
|
2656 | var tag = getTag(value),
|
2657 | isFunc = tag == funcTag || tag == genTag;
|
2658 |
|
2659 | if (isBuffer(value)) {
|
2660 | return cloneBuffer(value, isDeep);
|
2661 | }
|
2662 | if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
2663 | result = (isFlat || isFunc) ? {} : initCloneObject(value);
|
2664 | if (!isDeep) {
|
2665 | return isFlat
|
2666 | ? copySymbolsIn(value, baseAssignIn(result, value))
|
2667 | : copySymbols(value, baseAssign(result, value));
|
2668 | }
|
2669 | } else {
|
2670 | if (!cloneableTags[tag]) {
|
2671 | return object ? value : {};
|
2672 | }
|
2673 | result = initCloneByTag(value, tag, isDeep);
|
2674 | }
|
2675 | }
|
2676 | // Check for circular references and return its corresponding clone.
|
2677 | stack || (stack = new Stack);
|
2678 | var stacked = stack.get(value);
|
2679 | if (stacked) {
|
2680 | return stacked;
|
2681 | }
|
2682 | stack.set(value, result);
|
2683 |
|
2684 | if (isSet(value)) {
|
2685 | value.forEach(function(subValue) {
|
2686 | result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
|
2687 | });
|
2688 |
|
2689 | return result;
|
2690 | }
|
2691 |
|
2692 | if (isMap(value)) {
|
2693 | value.forEach(function(subValue, key) {
|
2694 | result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
|
2695 | });
|
2696 |
|
2697 | return result;
|
2698 | }
|
2699 |
|
2700 | var keysFunc = isFull
|
2701 | ? (isFlat ? getAllKeysIn : getAllKeys)
|
2702 | : (isFlat ? keysIn : keys);
|
2703 |
|
2704 | var props = isArr ? undefined : keysFunc(value);
|
2705 | arrayEach(props || value, function(subValue, key) {
|
2706 | if (props) {
|
2707 | key = subValue;
|
2708 | subValue = value[key];
|
2709 | }
|
2710 | // Recursively populate clone (susceptible to call stack limits).
|
2711 | assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
|
2712 | });
|
2713 | return result;
|
2714 | }
|
2715 |
|
2716 | /**
|
2717 | * The base implementation of `_.conforms` which doesn't clone `source`.
|
2718 | *
|
2719 | * @private
|
2720 | * @param {Object} source The object of property predicates to conform to.
|
2721 | * @returns {Function} Returns the new spec function.
|
2722 | */
|
2723 | function baseConforms(source) {
|
2724 | var props = keys(source);
|
2725 | return function(object) {
|
2726 | return baseConformsTo(object, source, props);
|
2727 | };
|
2728 | }
|
2729 |
|
2730 | /**
|
2731 | * The base implementation of `_.conformsTo` which accepts `props` to check.
|
2732 | *
|
2733 | * @private
|
2734 | * @param {Object} object The object to inspect.
|
2735 | * @param {Object} source The object of property predicates to conform to.
|
2736 | * @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
2737 | */
|
2738 | function baseConformsTo(object, source, props) {
|
2739 | var length = props.length;
|
2740 | if (object == null) {
|
2741 | return !length;
|
2742 | }
|
2743 | object = Object(object);
|
2744 | while (length--) {
|
2745 | var key = props[length],
|
2746 | predicate = source[key],
|
2747 | value = object[key];
|
2748 |
|
2749 | if ((value === undefined && !(key in object)) || !predicate(value)) {
|
2750 | return false;
|
2751 | }
|
2752 | }
|
2753 | return true;
|
2754 | }
|
2755 |
|
2756 | /**
|
2757 | * The base implementation of `_.delay` and `_.defer` which accepts `args`
|
2758 | * to provide to `func`.
|
2759 | *
|
2760 | * @private
|
2761 | * @param {Function} func The function to delay.
|
2762 | * @param {number} wait The number of milliseconds to delay invocation.
|
2763 | * @param {Array} args The arguments to provide to `func`.
|
2764 | * @returns {number|Object} Returns the timer id or timeout object.
|
2765 | */
|
2766 | function baseDelay(func, wait, args) {
|
2767 | if (typeof func != 'function') {
|
2768 | throw new TypeError(FUNC_ERROR_TEXT);
|
2769 | }
|
2770 | return setTimeout(function() { func.apply(undefined, args); }, wait);
|
2771 | }
|
2772 |
|
2773 | /**
|
2774 | * The base implementation of methods like `_.difference` without support
|
2775 | * for excluding multiple arrays or iteratee shorthands.
|
2776 | *
|
2777 | * @private
|
2778 | * @param {Array} array The array to inspect.
|
2779 | * @param {Array} values The values to exclude.
|
2780 | * @param {Function} [iteratee] The iteratee invoked per element.
|
2781 | * @param {Function} [comparator] The comparator invoked per element.
|
2782 | * @returns {Array} Returns the new array of filtered values.
|
2783 | */
|
2784 | function baseDifference(array, values, iteratee, comparator) {
|
2785 | var index = -1,
|
2786 | includes = arrayIncludes,
|
2787 | isCommon = true,
|
2788 | length = array.length,
|
2789 | result = [],
|
2790 | valuesLength = values.length;
|
2791 |
|
2792 | if (!length) {
|
2793 | return result;
|
2794 | }
|
2795 | if (iteratee) {
|
2796 | values = arrayMap(values, baseUnary(iteratee));
|
2797 | }
|
2798 | if (comparator) {
|
2799 | includes = arrayIncludesWith;
|
2800 | isCommon = false;
|
2801 | }
|
2802 | else if (values.length >= LARGE_ARRAY_SIZE) {
|
2803 | includes = cacheHas;
|
2804 | isCommon = false;
|
2805 | values = new SetCache(values);
|
2806 | }
|
2807 | outer:
|
2808 | while (++index < length) {
|
2809 | var value = array[index],
|
2810 | computed = iteratee == null ? value : iteratee(value);
|
2811 |
|
2812 | value = (comparator || value !== 0) ? value : 0;
|
2813 | if (isCommon && computed === computed) {
|
2814 | var valuesIndex = valuesLength;
|
2815 | while (valuesIndex--) {
|
2816 | if (values[valuesIndex] === computed) {
|
2817 | continue outer;
|
2818 | }
|
2819 | }
|
2820 | result.push(value);
|
2821 | }
|
2822 | else if (!includes(values, computed, comparator)) {
|
2823 | result.push(value);
|
2824 | }
|
2825 | }
|
2826 | return result;
|
2827 | }
|
2828 |
|
2829 | /**
|
2830 | * The base implementation of `_.forEach` without support for iteratee shorthands.
|
2831 | *
|
2832 | * @private
|
2833 | * @param {Array|Object} collection The collection to iterate over.
|
2834 | * @param {Function} iteratee The function invoked per iteration.
|
2835 | * @returns {Array|Object} Returns `collection`.
|
2836 | */
|
2837 | var baseEach = createBaseEach(baseForOwn);
|
2838 |
|
2839 | /**
|
2840 | * The base implementation of `_.forEachRight` without support for iteratee shorthands.
|
2841 | *
|
2842 | * @private
|
2843 | * @param {Array|Object} collection The collection to iterate over.
|
2844 | * @param {Function} iteratee The function invoked per iteration.
|
2845 | * @returns {Array|Object} Returns `collection`.
|
2846 | */
|
2847 | var baseEachRight = createBaseEach(baseForOwnRight, true);
|
2848 |
|
2849 | /**
|
2850 | * The base implementation of `_.every` without support for iteratee shorthands.
|
2851 | *
|
2852 | * @private
|
2853 | * @param {Array|Object} collection The collection to iterate over.
|
2854 | * @param {Function} predicate The function invoked per iteration.
|
2855 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
2856 | * else `false`
|
2857 | */
|
2858 | function baseEvery(collection, predicate) {
|
2859 | var result = true;
|
2860 | baseEach(collection, function(value, index, collection) {
|
2861 | result = !!predicate(value, index, collection);
|
2862 | return result;
|
2863 | });
|
2864 | return result;
|
2865 | }
|
2866 |
|
2867 | /**
|
2868 | * The base implementation of methods like `_.max` and `_.min` which accepts a
|
2869 | * `comparator` to determine the extremum value.
|
2870 | *
|
2871 | * @private
|
2872 | * @param {Array} array The array to iterate over.
|
2873 | * @param {Function} iteratee The iteratee invoked per iteration.
|
2874 | * @param {Function} comparator The comparator used to compare values.
|
2875 | * @returns {*} Returns the extremum value.
|
2876 | */
|
2877 | function baseExtremum(array, iteratee, comparator) {
|
2878 | var index = -1,
|
2879 | length = array.length;
|
2880 |
|
2881 | while (++index < length) {
|
2882 | var value = array[index],
|
2883 | current = iteratee(value);
|
2884 |
|
2885 | if (current != null && (computed === undefined
|
2886 | ? (current === current && !isSymbol(current))
|
2887 | : comparator(current, computed)
|
2888 | )) {
|
2889 | var computed = current,
|
2890 | result = value;
|
2891 | }
|
2892 | }
|
2893 | return result;
|
2894 | }
|
2895 |
|
2896 | /**
|
2897 | * The base implementation of `_.fill` without an iteratee call guard.
|
2898 | *
|
2899 | * @private
|
2900 | * @param {Array} array The array to fill.
|
2901 | * @param {*} value The value to fill `array` with.
|
2902 | * @param {number} [start=0] The start position.
|
2903 | * @param {number} [end=array.length] The end position.
|
2904 | * @returns {Array} Returns `array`.
|
2905 | */
|
2906 | function baseFill(array, value, start, end) {
|
2907 | var length = array.length;
|
2908 |
|
2909 | start = toInteger(start);
|
2910 | if (start < 0) {
|
2911 | start = -start > length ? 0 : (length + start);
|
2912 | }
|
2913 | end = (end === undefined || end > length) ? length : toInteger(end);
|
2914 | if (end < 0) {
|
2915 | end += length;
|
2916 | }
|
2917 | end = start > end ? 0 : toLength(end);
|
2918 | while (start < end) {
|
2919 | array[start++] = value;
|
2920 | }
|
2921 | return array;
|
2922 | }
|
2923 |
|
2924 | /**
|
2925 | * The base implementation of `_.filter` without support for iteratee shorthands.
|
2926 | *
|
2927 | * @private
|
2928 | * @param {Array|Object} collection The collection to iterate over.
|
2929 | * @param {Function} predicate The function invoked per iteration.
|
2930 | * @returns {Array} Returns the new filtered array.
|
2931 | */
|
2932 | function baseFilter(collection, predicate) {
|
2933 | var result = [];
|
2934 | baseEach(collection, function(value, index, collection) {
|
2935 | if (predicate(value, index, collection)) {
|
2936 | result.push(value);
|
2937 | }
|
2938 | });
|
2939 | return result;
|
2940 | }
|
2941 |
|
2942 | /**
|
2943 | * The base implementation of `_.flatten` with support for restricting flattening.
|
2944 | *
|
2945 | * @private
|
2946 | * @param {Array} array The array to flatten.
|
2947 | * @param {number} depth The maximum recursion depth.
|
2948 | * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
|
2949 | * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
|
2950 | * @param {Array} [result=[]] The initial result value.
|
2951 | * @returns {Array} Returns the new flattened array.
|
2952 | */
|
2953 | function baseFlatten(array, depth, predicate, isStrict, result) {
|
2954 | var index = -1,
|
2955 | length = array.length;
|
2956 |
|
2957 | predicate || (predicate = isFlattenable);
|
2958 | result || (result = []);
|
2959 |
|
2960 | while (++index < length) {
|
2961 | var value = array[index];
|
2962 | if (depth > 0 && predicate(value)) {
|
2963 | if (depth > 1) {
|
2964 | // Recursively flatten arrays (susceptible to call stack limits).
|
2965 | baseFlatten(value, depth - 1, predicate, isStrict, result);
|
2966 | } else {
|
2967 | arrayPush(result, value);
|
2968 | }
|
2969 | } else if (!isStrict) {
|
2970 | result[result.length] = value;
|
2971 | }
|
2972 | }
|
2973 | return result;
|
2974 | }
|
2975 |
|
2976 | /**
|
2977 | * The base implementation of `baseForOwn` which iterates over `object`
|
2978 | * properties returned by `keysFunc` and invokes `iteratee` for each property.
|
2979 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
2980 | *
|
2981 | * @private
|
2982 | * @param {Object} object The object to iterate over.
|
2983 | * @param {Function} iteratee The function invoked per iteration.
|
2984 | * @param {Function} keysFunc The function to get the keys of `object`.
|
2985 | * @returns {Object} Returns `object`.
|
2986 | */
|
2987 | var baseFor = createBaseFor();
|
2988 |
|
2989 | /**
|
2990 | * This function is like `baseFor` except that it iterates over properties
|
2991 | * in the opposite order.
|
2992 | *
|
2993 | * @private
|
2994 | * @param {Object} object The object to iterate over.
|
2995 | * @param {Function} iteratee The function invoked per iteration.
|
2996 | * @param {Function} keysFunc The function to get the keys of `object`.
|
2997 | * @returns {Object} Returns `object`.
|
2998 | */
|
2999 | var baseForRight = createBaseFor(true);
|
3000 |
|
3001 | /**
|
3002 | * The base implementation of `_.forOwn` without support for iteratee shorthands.
|
3003 | *
|
3004 | * @private
|
3005 | * @param {Object} object The object to iterate over.
|
3006 | * @param {Function} iteratee The function invoked per iteration.
|
3007 | * @returns {Object} Returns `object`.
|
3008 | */
|
3009 | function baseForOwn(object, iteratee) {
|
3010 | return object && baseFor(object, iteratee, keys);
|
3011 | }
|
3012 |
|
3013 | /**
|
3014 | * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
|
3015 | *
|
3016 | * @private
|
3017 | * @param {Object} object The object to iterate over.
|
3018 | * @param {Function} iteratee The function invoked per iteration.
|
3019 | * @returns {Object} Returns `object`.
|
3020 | */
|
3021 | function baseForOwnRight(object, iteratee) {
|
3022 | return object && baseForRight(object, iteratee, keys);
|
3023 | }
|
3024 |
|
3025 | /**
|
3026 | * The base implementation of `_.functions` which creates an array of
|
3027 | * `object` function property names filtered from `props`.
|
3028 | *
|
3029 | * @private
|
3030 | * @param {Object} object The object to inspect.
|
3031 | * @param {Array} props The property names to filter.
|
3032 | * @returns {Array} Returns the function names.
|
3033 | */
|
3034 | function baseFunctions(object, props) {
|
3035 | return arrayFilter(props, function(key) {
|
3036 | return isFunction(object[key]);
|
3037 | });
|
3038 | }
|
3039 |
|
3040 | /**
|
3041 | * The base implementation of `_.get` without support for default values.
|
3042 | *
|
3043 | * @private
|
3044 | * @param {Object} object The object to query.
|
3045 | * @param {Array|string} path The path of the property to get.
|
3046 | * @returns {*} Returns the resolved value.
|
3047 | */
|
3048 | function baseGet(object, path) {
|
3049 | path = castPath(path, object);
|
3050 |
|
3051 | var index = 0,
|
3052 | length = path.length;
|
3053 |
|
3054 | while (object != null && index < length) {
|
3055 | object = object[toKey(path[index++])];
|
3056 | }
|
3057 | return (index && index == length) ? object : undefined;
|
3058 | }
|
3059 |
|
3060 | /**
|
3061 | * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
3062 | * `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
3063 | * symbols of `object`.
|
3064 | *
|
3065 | * @private
|
3066 | * @param {Object} object The object to query.
|
3067 | * @param {Function} keysFunc The function to get the keys of `object`.
|
3068 | * @param {Function} symbolsFunc The function to get the symbols of `object`.
|
3069 | * @returns {Array} Returns the array of property names and symbols.
|
3070 | */
|
3071 | function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
3072 | var result = keysFunc(object);
|
3073 | return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
3074 | }
|
3075 |
|
3076 | /**
|
3077 | * The base implementation of `getTag` without fallbacks for buggy environments.
|
3078 | *
|
3079 | * @private
|
3080 | * @param {*} value The value to query.
|
3081 | * @returns {string} Returns the `toStringTag`.
|
3082 | */
|
3083 | function baseGetTag(value) {
|
3084 | if (value == null) {
|
3085 | return value === undefined ? undefinedTag : nullTag;
|
3086 | }
|
3087 | return (symToStringTag && symToStringTag in Object(value))
|
3088 | ? getRawTag(value)
|
3089 | : objectToString(value);
|
3090 | }
|
3091 |
|
3092 | /**
|
3093 | * The base implementation of `_.gt` which doesn't coerce arguments.
|
3094 | *
|
3095 | * @private
|
3096 | * @param {*} value The value to compare.
|
3097 | * @param {*} other The other value to compare.
|
3098 | * @returns {boolean} Returns `true` if `value` is greater than `other`,
|
3099 | * else `false`.
|
3100 | */
|
3101 | function baseGt(value, other) {
|
3102 | return value > other;
|
3103 | }
|
3104 |
|
3105 | /**
|
3106 | * The base implementation of `_.has` without support for deep paths.
|
3107 | *
|
3108 | * @private
|
3109 | * @param {Object} [object] The object to query.
|
3110 | * @param {Array|string} key The key to check.
|
3111 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
3112 | */
|
3113 | function baseHas(object, key) {
|
3114 | return object != null && hasOwnProperty.call(object, key);
|
3115 | }
|
3116 |
|
3117 | /**
|
3118 | * The base implementation of `_.hasIn` without support for deep paths.
|
3119 | *
|
3120 | * @private
|
3121 | * @param {Object} [object] The object to query.
|
3122 | * @param {Array|string} key The key to check.
|
3123 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
3124 | */
|
3125 | function baseHasIn(object, key) {
|
3126 | return object != null && key in Object(object);
|
3127 | }
|
3128 |
|
3129 | /**
|
3130 | * The base implementation of `_.inRange` which doesn't coerce arguments.
|
3131 | *
|
3132 | * @private
|
3133 | * @param {number} number The number to check.
|
3134 | * @param {number} start The start of the range.
|
3135 | * @param {number} end The end of the range.
|
3136 | * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
|
3137 | */
|
3138 | function baseInRange(number, start, end) {
|
3139 | return number >= nativeMin(start, end) && number < nativeMax(start, end);
|
3140 | }
|
3141 |
|
3142 | /**
|
3143 | * The base implementation of methods like `_.intersection`, without support
|
3144 | * for iteratee shorthands, that accepts an array of arrays to inspect.
|
3145 | *
|
3146 | * @private
|
3147 | * @param {Array} arrays The arrays to inspect.
|
3148 | * @param {Function} [iteratee] The iteratee invoked per element.
|
3149 | * @param {Function} [comparator] The comparator invoked per element.
|
3150 | * @returns {Array} Returns the new array of shared values.
|
3151 | */
|
3152 | function baseIntersection(arrays, iteratee, comparator) {
|
3153 | var includes = comparator ? arrayIncludesWith : arrayIncludes,
|
3154 | length = arrays[0].length,
|
3155 | othLength = arrays.length,
|
3156 | othIndex = othLength,
|
3157 | caches = Array(othLength),
|
3158 | maxLength = Infinity,
|
3159 | result = [];
|
3160 |
|
3161 | while (othIndex--) {
|
3162 | var array = arrays[othIndex];
|
3163 | if (othIndex && iteratee) {
|
3164 | array = arrayMap(array, baseUnary(iteratee));
|
3165 | }
|
3166 | maxLength = nativeMin(array.length, maxLength);
|
3167 | caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
|
3168 | ? new SetCache(othIndex && array)
|
3169 | : undefined;
|
3170 | }
|
3171 | array = arrays[0];
|
3172 |
|
3173 | var index = -1,
|
3174 | seen = caches[0];
|
3175 |
|
3176 | outer:
|
3177 | while (++index < length && result.length < maxLength) {
|
3178 | var value = array[index],
|
3179 | computed = iteratee ? iteratee(value) : value;
|
3180 |
|
3181 | value = (comparator || value !== 0) ? value : 0;
|
3182 | if (!(seen
|
3183 | ? cacheHas(seen, computed)
|
3184 | : includes(result, computed, comparator)
|
3185 | )) {
|
3186 | othIndex = othLength;
|
3187 | while (--othIndex) {
|
3188 | var cache = caches[othIndex];
|
3189 | if (!(cache
|
3190 | ? cacheHas(cache, computed)
|
3191 | : includes(arrays[othIndex], computed, comparator))
|
3192 | ) {
|
3193 | continue outer;
|
3194 | }
|
3195 | }
|
3196 | if (seen) {
|
3197 | seen.push(computed);
|
3198 | }
|
3199 | result.push(value);
|
3200 | }
|
3201 | }
|
3202 | return result;
|
3203 | }
|
3204 |
|
3205 | /**
|
3206 | * The base implementation of `_.invert` and `_.invertBy` which inverts
|
3207 | * `object` with values transformed by `iteratee` and set by `setter`.
|
3208 | *
|
3209 | * @private
|
3210 | * @param {Object} object The object to iterate over.
|
3211 | * @param {Function} setter The function to set `accumulator` values.
|
3212 | * @param {Function} iteratee The iteratee to transform values.
|
3213 | * @param {Object} accumulator The initial inverted object.
|
3214 | * @returns {Function} Returns `accumulator`.
|
3215 | */
|
3216 | function baseInverter(object, setter, iteratee, accumulator) {
|
3217 | baseForOwn(object, function(value, key, object) {
|
3218 | setter(accumulator, iteratee(value), key, object);
|
3219 | });
|
3220 | return accumulator;
|
3221 | }
|
3222 |
|
3223 | /**
|
3224 | * The base implementation of `_.invoke` without support for individual
|
3225 | * method arguments.
|
3226 | *
|
3227 | * @private
|
3228 | * @param {Object} object The object to query.
|
3229 | * @param {Array|string} path The path of the method to invoke.
|
3230 | * @param {Array} args The arguments to invoke the method with.
|
3231 | * @returns {*} Returns the result of the invoked method.
|
3232 | */
|
3233 | function baseInvoke(object, path, args) {
|
3234 | path = castPath(path, object);
|
3235 | object = parent(object, path);
|
3236 | var func = object == null ? object : object[toKey(last(path))];
|
3237 | return func == null ? undefined : apply(func, object, args);
|
3238 | }
|
3239 |
|
3240 | /**
|
3241 | * The base implementation of `_.isArguments`.
|
3242 | *
|
3243 | * @private
|
3244 | * @param {*} value The value to check.
|
3245 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
3246 | */
|
3247 | function baseIsArguments(value) {
|
3248 | return isObjectLike(value) && baseGetTag(value) == argsTag;
|
3249 | }
|
3250 |
|
3251 | /**
|
3252 | * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
|
3253 | *
|
3254 | * @private
|
3255 | * @param {*} value The value to check.
|
3256 | * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
|
3257 | */
|
3258 | function baseIsArrayBuffer(value) {
|
3259 | return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
|
3260 | }
|
3261 |
|
3262 | /**
|
3263 | * The base implementation of `_.isDate` without Node.js optimizations.
|
3264 | *
|
3265 | * @private
|
3266 | * @param {*} value The value to check.
|
3267 | * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
3268 | */
|
3269 | function baseIsDate(value) {
|
3270 | return isObjectLike(value) && baseGetTag(value) == dateTag;
|
3271 | }
|
3272 |
|
3273 | /**
|
3274 | * The base implementation of `_.isEqual` which supports partial comparisons
|
3275 | * and tracks traversed objects.
|
3276 | *
|
3277 | * @private
|
3278 | * @param {*} value The value to compare.
|
3279 | * @param {*} other The other value to compare.
|
3280 | * @param {boolean} bitmask The bitmask flags.
|
3281 | * 1 - Unordered comparison
|
3282 | * 2 - Partial comparison
|
3283 | * @param {Function} [customizer] The function to customize comparisons.
|
3284 | * @param {Object} [stack] Tracks traversed `value` and `other` objects.
|
3285 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
3286 | */
|
3287 | function baseIsEqual(value, other, bitmask, customizer, stack) {
|
3288 | if (value === other) {
|
3289 | return true;
|
3290 | }
|
3291 | if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
|
3292 | return value !== value && other !== other;
|
3293 | }
|
3294 | return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
3295 | }
|
3296 |
|
3297 | /**
|
3298 | * A specialized version of `baseIsEqual` for arrays and objects which performs
|
3299 | * deep comparisons and tracks traversed objects enabling objects with circular
|
3300 | * references to be compared.
|
3301 | *
|
3302 | * @private
|
3303 | * @param {Object} object The object to compare.
|
3304 | * @param {Object} other The other object to compare.
|
3305 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
3306 | * @param {Function} customizer The function to customize comparisons.
|
3307 | * @param {Function} equalFunc The function to determine equivalents of values.
|
3308 | * @param {Object} [stack] Tracks traversed `object` and `other` objects.
|
3309 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
3310 | */
|
3311 | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
3312 | var objIsArr = isArray(object),
|
3313 | othIsArr = isArray(other),
|
3314 | objTag = objIsArr ? arrayTag : getTag(object),
|
3315 | othTag = othIsArr ? arrayTag : getTag(other);
|
3316 |
|
3317 | objTag = objTag == argsTag ? objectTag : objTag;
|
3318 | othTag = othTag == argsTag ? objectTag : othTag;
|
3319 |
|
3320 | var objIsObj = objTag == objectTag,
|
3321 | othIsObj = othTag == objectTag,
|
3322 | isSameTag = objTag == othTag;
|
3323 |
|
3324 | if (isSameTag && isBuffer(object)) {
|
3325 | if (!isBuffer(other)) {
|
3326 | return false;
|
3327 | }
|
3328 | objIsArr = true;
|
3329 | objIsObj = false;
|
3330 | }
|
3331 | if (isSameTag && !objIsObj) {
|
3332 | stack || (stack = new Stack);
|
3333 | return (objIsArr || isTypedArray(object))
|
3334 | ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
|
3335 | : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
|
3336 | }
|
3337 | if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
|
3338 | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
3339 | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
3340 |
|
3341 | if (objIsWrapped || othIsWrapped) {
|
3342 | var objUnwrapped = objIsWrapped ? object.value() : object,
|
3343 | othUnwrapped = othIsWrapped ? other.value() : other;
|
3344 |
|
3345 | stack || (stack = new Stack);
|
3346 | return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
|
3347 | }
|
3348 | }
|
3349 | if (!isSameTag) {
|
3350 | return false;
|
3351 | }
|
3352 | stack || (stack = new Stack);
|
3353 | return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
|
3354 | }
|
3355 |
|
3356 | /**
|
3357 | * The base implementation of `_.isMap` without Node.js optimizations.
|
3358 | *
|
3359 | * @private
|
3360 | * @param {*} value The value to check.
|
3361 | * @returns {boolean} Returns `true` if `value` is a map, else `false`.
|
3362 | */
|
3363 | function baseIsMap(value) {
|
3364 | return isObjectLike(value) && getTag(value) == mapTag;
|
3365 | }
|
3366 |
|
3367 | /**
|
3368 | * The base implementation of `_.isMatch` without support for iteratee shorthands.
|
3369 | *
|
3370 | * @private
|
3371 | * @param {Object} object The object to inspect.
|
3372 | * @param {Object} source The object of property values to match.
|
3373 | * @param {Array} matchData The property names, values, and compare flags to match.
|
3374 | * @param {Function} [customizer] The function to customize comparisons.
|
3375 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
3376 | */
|
3377 | function baseIsMatch(object, source, matchData, customizer) {
|
3378 | var index = matchData.length,
|
3379 | length = index,
|
3380 | noCustomizer = !customizer;
|
3381 |
|
3382 | if (object == null) {
|
3383 | return !length;
|
3384 | }
|
3385 | object = Object(object);
|
3386 | while (index--) {
|
3387 | var data = matchData[index];
|
3388 | if ((noCustomizer && data[2])
|
3389 | ? data[1] !== object[data[0]]
|
3390 | : !(data[0] in object)
|
3391 | ) {
|
3392 | return false;
|
3393 | }
|
3394 | }
|
3395 | while (++index < length) {
|
3396 | data = matchData[index];
|
3397 | var key = data[0],
|
3398 | objValue = object[key],
|
3399 | srcValue = data[1];
|
3400 |
|
3401 | if (noCustomizer && data[2]) {
|
3402 | if (objValue === undefined && !(key in object)) {
|
3403 | return false;
|
3404 | }
|
3405 | } else {
|
3406 | var stack = new Stack;
|
3407 | if (customizer) {
|
3408 | var result = customizer(objValue, srcValue, key, object, source, stack);
|
3409 | }
|
3410 | if (!(result === undefined
|
3411 | ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
|
3412 | : result
|
3413 | )) {
|
3414 | return false;
|
3415 | }
|
3416 | }
|
3417 | }
|
3418 | return true;
|
3419 | }
|
3420 |
|
3421 | /**
|
3422 | * The base implementation of `_.isNative` without bad shim checks.
|
3423 | *
|
3424 | * @private
|
3425 | * @param {*} value The value to check.
|
3426 | * @returns {boolean} Returns `true` if `value` is a native function,
|
3427 | * else `false`.
|
3428 | */
|
3429 | function baseIsNative(value) {
|
3430 | if (!isObject(value) || isMasked(value)) {
|
3431 | return false;
|
3432 | }
|
3433 | var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
3434 | return pattern.test(toSource(value));
|
3435 | }
|
3436 |
|
3437 | /**
|
3438 | * The base implementation of `_.isRegExp` without Node.js optimizations.
|
3439 | *
|
3440 | * @private
|
3441 | * @param {*} value The value to check.
|
3442 | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
|
3443 | */
|
3444 | function baseIsRegExp(value) {
|
3445 | return isObjectLike(value) && baseGetTag(value) == regexpTag;
|
3446 | }
|
3447 |
|
3448 | /**
|
3449 | * The base implementation of `_.isSet` without Node.js optimizations.
|
3450 | *
|
3451 | * @private
|
3452 | * @param {*} value The value to check.
|
3453 | * @returns {boolean} Returns `true` if `value` is a set, else `false`.
|
3454 | */
|
3455 | function baseIsSet(value) {
|
3456 | return isObjectLike(value) && getTag(value) == setTag;
|
3457 | }
|
3458 |
|
3459 | /**
|
3460 | * The base implementation of `_.isTypedArray` without Node.js optimizations.
|
3461 | *
|
3462 | * @private
|
3463 | * @param {*} value The value to check.
|
3464 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
3465 | */
|
3466 | function baseIsTypedArray(value) {
|
3467 | return isObjectLike(value) &&
|
3468 | isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
|
3469 | }
|
3470 |
|
3471 | /**
|
3472 | * The base implementation of `_.iteratee`.
|
3473 | *
|
3474 | * @private
|
3475 | * @param {*} [value=_.identity] The value to convert to an iteratee.
|
3476 | * @returns {Function} Returns the iteratee.
|
3477 | */
|
3478 | function baseIteratee(value) {
|
3479 | // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
|
3480 | // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
|
3481 | if (typeof value == 'function') {
|
3482 | return value;
|
3483 | }
|
3484 | if (value == null) {
|
3485 | return identity;
|
3486 | }
|
3487 | if (typeof value == 'object') {
|
3488 | return isArray(value)
|
3489 | ? baseMatchesProperty(value[0], value[1])
|
3490 | : baseMatches(value);
|
3491 | }
|
3492 | return property(value);
|
3493 | }
|
3494 |
|
3495 | /**
|
3496 | * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
3497 | *
|
3498 | * @private
|
3499 | * @param {Object} object The object to query.
|
3500 | * @returns {Array} Returns the array of property names.
|
3501 | */
|
3502 | function baseKeys(object) {
|
3503 | if (!isPrototype(object)) {
|
3504 | return nativeKeys(object);
|
3505 | }
|
3506 | var result = [];
|
3507 | for (var key in Object(object)) {
|
3508 | if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
3509 | result.push(key);
|
3510 | }
|
3511 | }
|
3512 | return result;
|
3513 | }
|
3514 |
|
3515 | /**
|
3516 | * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
|
3517 | *
|
3518 | * @private
|
3519 | * @param {Object} object The object to query.
|
3520 | * @returns {Array} Returns the array of property names.
|
3521 | */
|
3522 | function baseKeysIn(object) {
|
3523 | if (!isObject(object)) {
|
3524 | return nativeKeysIn(object);
|
3525 | }
|
3526 | var isProto = isPrototype(object),
|
3527 | result = [];
|
3528 |
|
3529 | for (var key in object) {
|
3530 | if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
3531 | result.push(key);
|
3532 | }
|
3533 | }
|
3534 | return result;
|
3535 | }
|
3536 |
|
3537 | /**
|
3538 | * The base implementation of `_.lt` which doesn't coerce arguments.
|
3539 | *
|
3540 | * @private
|
3541 | * @param {*} value The value to compare.
|
3542 | * @param {*} other The other value to compare.
|
3543 | * @returns {boolean} Returns `true` if `value` is less than `other`,
|
3544 | * else `false`.
|
3545 | */
|
3546 | function baseLt(value, other) {
|
3547 | return value < other;
|
3548 | }
|
3549 |
|
3550 | /**
|
3551 | * The base implementation of `_.map` without support for iteratee shorthands.
|
3552 | *
|
3553 | * @private
|
3554 | * @param {Array|Object} collection The collection to iterate over.
|
3555 | * @param {Function} iteratee The function invoked per iteration.
|
3556 | * @returns {Array} Returns the new mapped array.
|
3557 | */
|
3558 | function baseMap(collection, iteratee) {
|
3559 | var index = -1,
|
3560 | result = isArrayLike(collection) ? Array(collection.length) : [];
|
3561 |
|
3562 | baseEach(collection, function(value, key, collection) {
|
3563 | result[++index] = iteratee(value, key, collection);
|
3564 | });
|
3565 | return result;
|
3566 | }
|
3567 |
|
3568 | /**
|
3569 | * The base implementation of `_.matches` which doesn't clone `source`.
|
3570 | *
|
3571 | * @private
|
3572 | * @param {Object} source The object of property values to match.
|
3573 | * @returns {Function} Returns the new spec function.
|
3574 | */
|
3575 | function baseMatches(source) {
|
3576 | var matchData = getMatchData(source);
|
3577 | if (matchData.length == 1 && matchData[0][2]) {
|
3578 | return matchesStrictComparable(matchData[0][0], matchData[0][1]);
|
3579 | }
|
3580 | return function(object) {
|
3581 | return object === source || baseIsMatch(object, source, matchData);
|
3582 | };
|
3583 | }
|
3584 |
|
3585 | /**
|
3586 | * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
|
3587 | *
|
3588 | * @private
|
3589 | * @param {string} path The path of the property to get.
|
3590 | * @param {*} srcValue The value to match.
|
3591 | * @returns {Function} Returns the new spec function.
|
3592 | */
|
3593 | function baseMatchesProperty(path, srcValue) {
|
3594 | if (isKey(path) && isStrictComparable(srcValue)) {
|
3595 | return matchesStrictComparable(toKey(path), srcValue);
|
3596 | }
|
3597 | return function(object) {
|
3598 | var objValue = get(object, path);
|
3599 | return (objValue === undefined && objValue === srcValue)
|
3600 | ? hasIn(object, path)
|
3601 | : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
|
3602 | };
|
3603 | }
|
3604 |
|
3605 | /**
|
3606 | * The base implementation of `_.merge` without support for multiple sources.
|
3607 | *
|
3608 | * @private
|
3609 | * @param {Object} object The destination object.
|
3610 | * @param {Object} source The source object.
|
3611 | * @param {number} srcIndex The index of `source`.
|
3612 | * @param {Function} [customizer] The function to customize merged values.
|
3613 | * @param {Object} [stack] Tracks traversed source values and their merged
|
3614 | * counterparts.
|
3615 | */
|
3616 | function baseMerge(object, source, srcIndex, customizer, stack) {
|
3617 | if (object === source) {
|
3618 | return;
|
3619 | }
|
3620 | baseFor(source, function(srcValue, key) {
|
3621 | if (isObject(srcValue)) {
|
3622 | stack || (stack = new Stack);
|
3623 | baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
3624 | }
|
3625 | else {
|
3626 | var newValue = customizer
|
3627 | ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
|
3628 | : undefined;
|
3629 |
|
3630 | if (newValue === undefined) {
|
3631 | newValue = srcValue;
|
3632 | }
|
3633 | assignMergeValue(object, key, newValue);
|
3634 | }
|
3635 | }, keysIn);
|
3636 | }
|
3637 |
|
3638 | /**
|
3639 | * A specialized version of `baseMerge` for arrays and objects which performs
|
3640 | * deep merges and tracks traversed objects enabling objects with circular
|
3641 | * references to be merged.
|
3642 | *
|
3643 | * @private
|
3644 | * @param {Object} object The destination object.
|
3645 | * @param {Object} source The source object.
|
3646 | * @param {string} key The key of the value to merge.
|
3647 | * @param {number} srcIndex The index of `source`.
|
3648 | * @param {Function} mergeFunc The function to merge values.
|
3649 | * @param {Function} [customizer] The function to customize assigned values.
|
3650 | * @param {Object} [stack] Tracks traversed source values and their merged
|
3651 | * counterparts.
|
3652 | */
|
3653 | function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
|
3654 | var objValue = safeGet(object, key),
|
3655 | srcValue = safeGet(source, key),
|
3656 | stacked = stack.get(srcValue);
|
3657 |
|
3658 | if (stacked) {
|
3659 | assignMergeValue(object, key, stacked);
|
3660 | return;
|
3661 | }
|
3662 | var newValue = customizer
|
3663 | ? customizer(objValue, srcValue, (key + ''), object, source, stack)
|
3664 | : undefined;
|
3665 |
|
3666 | var isCommon = newValue === undefined;
|
3667 |
|
3668 | if (isCommon) {
|
3669 | var isArr = isArray(srcValue),
|
3670 | isBuff = !isArr && isBuffer(srcValue),
|
3671 | isTyped = !isArr && !isBuff && isTypedArray(srcValue);
|
3672 |
|
3673 | newValue = srcValue;
|
3674 | if (isArr || isBuff || isTyped) {
|
3675 | if (isArray(objValue)) {
|
3676 | newValue = objValue;
|
3677 | }
|
3678 | else if (isArrayLikeObject(objValue)) {
|
3679 | newValue = copyArray(objValue);
|
3680 | }
|
3681 | else if (isBuff) {
|
3682 | isCommon = false;
|
3683 | newValue = cloneBuffer(srcValue, true);
|
3684 | }
|
3685 | else if (isTyped) {
|
3686 | isCommon = false;
|
3687 | newValue = cloneTypedArray(srcValue, true);
|
3688 | }
|
3689 | else {
|
3690 | newValue = [];
|
3691 | }
|
3692 | }
|
3693 | else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
3694 | newValue = objValue;
|
3695 | if (isArguments(objValue)) {
|
3696 | newValue = toPlainObject(objValue);
|
3697 | }
|
3698 | else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
|
3699 | newValue = initCloneObject(srcValue);
|
3700 | }
|
3701 | }
|
3702 | else {
|
3703 | isCommon = false;
|
3704 | }
|
3705 | }
|
3706 | if (isCommon) {
|
3707 | // Recursively merge objects and arrays (susceptible to call stack limits).
|
3708 | stack.set(srcValue, newValue);
|
3709 | mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
|
3710 | stack['delete'](srcValue);
|
3711 | }
|
3712 | assignMergeValue(object, key, newValue);
|
3713 | }
|
3714 |
|
3715 | /**
|
3716 | * The base implementation of `_.nth` which doesn't coerce arguments.
|
3717 | *
|
3718 | * @private
|
3719 | * @param {Array} array The array to query.
|
3720 | * @param {number} n The index of the element to return.
|
3721 | * @returns {*} Returns the nth element of `array`.
|
3722 | */
|
3723 | function baseNth(array, n) {
|
3724 | var length = array.length;
|
3725 | if (!length) {
|
3726 | return;
|
3727 | }
|
3728 | n += n < 0 ? length : 0;
|
3729 | return isIndex(n, length) ? array[n] : undefined;
|
3730 | }
|
3731 |
|
3732 | /**
|
3733 | * The base implementation of `_.orderBy` without param guards.
|
3734 | *
|
3735 | * @private
|
3736 | * @param {Array|Object} collection The collection to iterate over.
|
3737 | * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
3738 | * @param {string[]} orders The sort orders of `iteratees`.
|
3739 | * @returns {Array} Returns the new sorted array.
|
3740 | */
|
3741 | function baseOrderBy(collection, iteratees, orders) {
|
3742 | var index = -1;
|
3743 | iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
|
3744 |
|
3745 | var result = baseMap(collection, function(value, key, collection) {
|
3746 | var criteria = arrayMap(iteratees, function(iteratee) {
|
3747 | return iteratee(value);
|
3748 | });
|
3749 | return { 'criteria': criteria, 'index': ++index, 'value': value };
|
3750 | });
|
3751 |
|
3752 | return baseSortBy(result, function(object, other) {
|
3753 | return compareMultiple(object, other, orders);
|
3754 | });
|
3755 | }
|
3756 |
|
3757 | /**
|
3758 | * The base implementation of `_.pick` without support for individual
|
3759 | * property identifiers.
|
3760 | *
|
3761 | * @private
|
3762 | * @param {Object} object The source object.
|
3763 | * @param {string[]} paths The property paths to pick.
|
3764 | * @returns {Object} Returns the new object.
|
3765 | */
|
3766 | function basePick(object, paths) {
|
3767 | return basePickBy(object, paths, function(value, path) {
|
3768 | return hasIn(object, path);
|
3769 | });
|
3770 | }
|
3771 |
|
3772 | /**
|
3773 | * The base implementation of `_.pickBy` without support for iteratee shorthands.
|
3774 | *
|
3775 | * @private
|
3776 | * @param {Object} object The source object.
|
3777 | * @param {string[]} paths The property paths to pick.
|
3778 | * @param {Function} predicate The function invoked per property.
|
3779 | * @returns {Object} Returns the new object.
|
3780 | */
|
3781 | function basePickBy(object, paths, predicate) {
|
3782 | var index = -1,
|
3783 | length = paths.length,
|
3784 | result = {};
|
3785 |
|
3786 | while (++index < length) {
|
3787 | var path = paths[index],
|
3788 | value = baseGet(object, path);
|
3789 |
|
3790 | if (predicate(value, path)) {
|
3791 | baseSet(result, castPath(path, object), value);
|
3792 | }
|
3793 | }
|
3794 | return result;
|
3795 | }
|
3796 |
|
3797 | /**
|
3798 | * A specialized version of `baseProperty` which supports deep paths.
|
3799 | *
|
3800 | * @private
|
3801 | * @param {Array|string} path The path of the property to get.
|
3802 | * @returns {Function} Returns the new accessor function.
|
3803 | */
|
3804 | function basePropertyDeep(path) {
|
3805 | return function(object) {
|
3806 | return baseGet(object, path);
|
3807 | };
|
3808 | }
|
3809 |
|
3810 | /**
|
3811 | * The base implementation of `_.pullAllBy` without support for iteratee
|
3812 | * shorthands.
|
3813 | *
|
3814 | * @private
|
3815 | * @param {Array} array The array to modify.
|
3816 | * @param {Array} values The values to remove.
|
3817 | * @param {Function} [iteratee] The iteratee invoked per element.
|
3818 | * @param {Function} [comparator] The comparator invoked per element.
|
3819 | * @returns {Array} Returns `array`.
|
3820 | */
|
3821 | function basePullAll(array, values, iteratee, comparator) {
|
3822 | var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
|
3823 | index = -1,
|
3824 | length = values.length,
|
3825 | seen = array;
|
3826 |
|
3827 | if (array === values) {
|
3828 | values = copyArray(values);
|
3829 | }
|
3830 | if (iteratee) {
|
3831 | seen = arrayMap(array, baseUnary(iteratee));
|
3832 | }
|
3833 | while (++index < length) {
|
3834 | var fromIndex = 0,
|
3835 | value = values[index],
|
3836 | computed = iteratee ? iteratee(value) : value;
|
3837 |
|
3838 | while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
|
3839 | if (seen !== array) {
|
3840 | splice.call(seen, fromIndex, 1);
|
3841 | }
|
3842 | splice.call(array, fromIndex, 1);
|
3843 | }
|
3844 | }
|
3845 | return array;
|
3846 | }
|
3847 |
|
3848 | /**
|
3849 | * The base implementation of `_.pullAt` without support for individual
|
3850 | * indexes or capturing the removed elements.
|
3851 | *
|
3852 | * @private
|
3853 | * @param {Array} array The array to modify.
|
3854 | * @param {number[]} indexes The indexes of elements to remove.
|
3855 | * @returns {Array} Returns `array`.
|
3856 | */
|
3857 | function basePullAt(array, indexes) {
|
3858 | var length = array ? indexes.length : 0,
|
3859 | lastIndex = length - 1;
|
3860 |
|
3861 | while (length--) {
|
3862 | var index = indexes[length];
|
3863 | if (length == lastIndex || index !== previous) {
|
3864 | var previous = index;
|
3865 | if (isIndex(index)) {
|
3866 | splice.call(array, index, 1);
|
3867 | } else {
|
3868 | baseUnset(array, index);
|
3869 | }
|
3870 | }
|
3871 | }
|
3872 | return array;
|
3873 | }
|
3874 |
|
3875 | /**
|
3876 | * The base implementation of `_.random` without support for returning
|
3877 | * floating-point numbers.
|
3878 | *
|
3879 | * @private
|
3880 | * @param {number} lower The lower bound.
|
3881 | * @param {number} upper The upper bound.
|
3882 | * @returns {number} Returns the random number.
|
3883 | */
|
3884 | function baseRandom(lower, upper) {
|
3885 | return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
|
3886 | }
|
3887 |
|
3888 | /**
|
3889 | * The base implementation of `_.range` and `_.rangeRight` which doesn't
|
3890 | * coerce arguments.
|
3891 | *
|
3892 | * @private
|
3893 | * @param {number} start The start of the range.
|
3894 | * @param {number} end The end of the range.
|
3895 | * @param {number} step The value to increment or decrement by.
|
3896 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
3897 | * @returns {Array} Returns the range of numbers.
|
3898 | */
|
3899 | function baseRange(start, end, step, fromRight) {
|
3900 | var index = -1,
|
3901 | length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
|
3902 | result = Array(length);
|
3903 |
|
3904 | while (length--) {
|
3905 | result[fromRight ? length : ++index] = start;
|
3906 | start += step;
|
3907 | }
|
3908 | return result;
|
3909 | }
|
3910 |
|
3911 | /**
|
3912 | * The base implementation of `_.repeat` which doesn't coerce arguments.
|
3913 | *
|
3914 | * @private
|
3915 | * @param {string} string The string to repeat.
|
3916 | * @param {number} n The number of times to repeat the string.
|
3917 | * @returns {string} Returns the repeated string.
|
3918 | */
|
3919 | function baseRepeat(string, n) {
|
3920 | var result = '';
|
3921 | if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
|
3922 | return result;
|
3923 | }
|
3924 | // Leverage the exponentiation by squaring algorithm for a faster repeat.
|
3925 | // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
|
3926 | do {
|
3927 | if (n % 2) {
|
3928 | result += string;
|
3929 | }
|
3930 | n = nativeFloor(n / 2);
|
3931 | if (n) {
|
3932 | string += string;
|
3933 | }
|
3934 | } while (n);
|
3935 |
|
3936 | return result;
|
3937 | }
|
3938 |
|
3939 | /**
|
3940 | * The base implementation of `_.rest` which doesn't validate or coerce arguments.
|
3941 | *
|
3942 | * @private
|
3943 | * @param {Function} func The function to apply a rest parameter to.
|
3944 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
3945 | * @returns {Function} Returns the new function.
|
3946 | */
|
3947 | function baseRest(func, start) {
|
3948 | return setToString(overRest(func, start, identity), func + '');
|
3949 | }
|
3950 |
|
3951 | /**
|
3952 | * The base implementation of `_.sample`.
|
3953 | *
|
3954 | * @private
|
3955 | * @param {Array|Object} collection The collection to sample.
|
3956 | * @returns {*} Returns the random element.
|
3957 | */
|
3958 | function baseSample(collection) {
|
3959 | return arraySample(values(collection));
|
3960 | }
|
3961 |
|
3962 | /**
|
3963 | * The base implementation of `_.sampleSize` without param guards.
|
3964 | *
|
3965 | * @private
|
3966 | * @param {Array|Object} collection The collection to sample.
|
3967 | * @param {number} n The number of elements to sample.
|
3968 | * @returns {Array} Returns the random elements.
|
3969 | */
|
3970 | function baseSampleSize(collection, n) {
|
3971 | var array = values(collection);
|
3972 | return shuffleSelf(array, baseClamp(n, 0, array.length));
|
3973 | }
|
3974 |
|
3975 | /**
|
3976 | * The base implementation of `_.set`.
|
3977 | *
|
3978 | * @private
|
3979 | * @param {Object} object The object to modify.
|
3980 | * @param {Array|string} path The path of the property to set.
|
3981 | * @param {*} value The value to set.
|
3982 | * @param {Function} [customizer] The function to customize path creation.
|
3983 | * @returns {Object} Returns `object`.
|
3984 | */
|
3985 | function baseSet(object, path, value, customizer) {
|
3986 | if (!isObject(object)) {
|
3987 | return object;
|
3988 | }
|
3989 | path = castPath(path, object);
|
3990 |
|
3991 | var index = -1,
|
3992 | length = path.length,
|
3993 | lastIndex = length - 1,
|
3994 | nested = object;
|
3995 |
|
3996 | while (nested != null && ++index < length) {
|
3997 | var key = toKey(path[index]),
|
3998 | newValue = value;
|
3999 |
|
4000 | if (index != lastIndex) {
|
4001 | var objValue = nested[key];
|
4002 | newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
4003 | if (newValue === undefined) {
|
4004 | newValue = isObject(objValue)
|
4005 | ? objValue
|
4006 | : (isIndex(path[index + 1]) ? [] : {});
|
4007 | }
|
4008 | }
|
4009 | assignValue(nested, key, newValue);
|
4010 | nested = nested[key];
|
4011 | }
|
4012 | return object;
|
4013 | }
|
4014 |
|
4015 | /**
|
4016 | * The base implementation of `setData` without support for hot loop shorting.
|
4017 | *
|
4018 | * @private
|
4019 | * @param {Function} func The function to associate metadata with.
|
4020 | * @param {*} data The metadata.
|
4021 | * @returns {Function} Returns `func`.
|
4022 | */
|
4023 | var baseSetData = !metaMap ? identity : function(func, data) {
|
4024 | metaMap.set(func, data);
|
4025 | return func;
|
4026 | };
|
4027 |
|
4028 | /**
|
4029 | * The base implementation of `setToString` without support for hot loop shorting.
|
4030 | *
|
4031 | * @private
|
4032 | * @param {Function} func The function to modify.
|
4033 | * @param {Function} string The `toString` result.
|
4034 | * @returns {Function} Returns `func`.
|
4035 | */
|
4036 | var baseSetToString = !defineProperty ? identity : function(func, string) {
|
4037 | return defineProperty(func, 'toString', {
|
4038 | 'configurable': true,
|
4039 | 'enumerable': false,
|
4040 | 'value': constant(string),
|
4041 | 'writable': true
|
4042 | });
|
4043 | };
|
4044 |
|
4045 | /**
|
4046 | * The base implementation of `_.shuffle`.
|
4047 | *
|
4048 | * @private
|
4049 | * @param {Array|Object} collection The collection to shuffle.
|
4050 | * @returns {Array} Returns the new shuffled array.
|
4051 | */
|
4052 | function baseShuffle(collection) {
|
4053 | return shuffleSelf(values(collection));
|
4054 | }
|
4055 |
|
4056 | /**
|
4057 | * The base implementation of `_.slice` without an iteratee call guard.
|
4058 | *
|
4059 | * @private
|
4060 | * @param {Array} array The array to slice.
|
4061 | * @param {number} [start=0] The start position.
|
4062 | * @param {number} [end=array.length] The end position.
|
4063 | * @returns {Array} Returns the slice of `array`.
|
4064 | */
|
4065 | function baseSlice(array, start, end) {
|
4066 | var index = -1,
|
4067 | length = array.length;
|
4068 |
|
4069 | if (start < 0) {
|
4070 | start = -start > length ? 0 : (length + start);
|
4071 | }
|
4072 | end = end > length ? length : end;
|
4073 | if (end < 0) {
|
4074 | end += length;
|
4075 | }
|
4076 | length = start > end ? 0 : ((end - start) >>> 0);
|
4077 | start >>>= 0;
|
4078 |
|
4079 | var result = Array(length);
|
4080 | while (++index < length) {
|
4081 | result[index] = array[index + start];
|
4082 | }
|
4083 | return result;
|
4084 | }
|
4085 |
|
4086 | /**
|
4087 | * The base implementation of `_.some` without support for iteratee shorthands.
|
4088 | *
|
4089 | * @private
|
4090 | * @param {Array|Object} collection The collection to iterate over.
|
4091 | * @param {Function} predicate The function invoked per iteration.
|
4092 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
4093 | * else `false`.
|
4094 | */
|
4095 | function baseSome(collection, predicate) {
|
4096 | var result;
|
4097 |
|
4098 | baseEach(collection, function(value, index, collection) {
|
4099 | result = predicate(value, index, collection);
|
4100 | return !result;
|
4101 | });
|
4102 | return !!result;
|
4103 | }
|
4104 |
|
4105 | /**
|
4106 | * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
|
4107 | * performs a binary search of `array` to determine the index at which `value`
|
4108 | * should be inserted into `array` in order to maintain its sort order.
|
4109 | *
|
4110 | * @private
|
4111 | * @param {Array} array The sorted array to inspect.
|
4112 | * @param {*} value The value to evaluate.
|
4113 | * @param {boolean} [retHighest] Specify returning the highest qualified index.
|
4114 | * @returns {number} Returns the index at which `value` should be inserted
|
4115 | * into `array`.
|
4116 | */
|
4117 | function baseSortedIndex(array, value, retHighest) {
|
4118 | var low = 0,
|
4119 | high = array == null ? low : array.length;
|
4120 |
|
4121 | if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
|
4122 | while (low < high) {
|
4123 | var mid = (low + high) >>> 1,
|
4124 | computed = array[mid];
|
4125 |
|
4126 | if (computed !== null && !isSymbol(computed) &&
|
4127 | (retHighest ? (computed <= value) : (computed < value))) {
|
4128 | low = mid + 1;
|
4129 | } else {
|
4130 | high = mid;
|
4131 | }
|
4132 | }
|
4133 | return high;
|
4134 | }
|
4135 | return baseSortedIndexBy(array, value, identity, retHighest);
|
4136 | }
|
4137 |
|
4138 | /**
|
4139 | * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
|
4140 | * which invokes `iteratee` for `value` and each element of `array` to compute
|
4141 | * their sort ranking. The iteratee is invoked with one argument; (value).
|
4142 | *
|
4143 | * @private
|
4144 | * @param {Array} array The sorted array to inspect.
|
4145 | * @param {*} value The value to evaluate.
|
4146 | * @param {Function} iteratee The iteratee invoked per element.
|
4147 | * @param {boolean} [retHighest] Specify returning the highest qualified index.
|
4148 | * @returns {number} Returns the index at which `value` should be inserted
|
4149 | * into `array`.
|
4150 | */
|
4151 | function baseSortedIndexBy(array, value, iteratee, retHighest) {
|
4152 | value = iteratee(value);
|
4153 |
|
4154 | var low = 0,
|
4155 | high = array == null ? 0 : array.length,
|
4156 | valIsNaN = value !== value,
|
4157 | valIsNull = value === null,
|
4158 | valIsSymbol = isSymbol(value),
|
4159 | valIsUndefined = value === undefined;
|
4160 |
|
4161 | while (low < high) {
|
4162 | var mid = nativeFloor((low + high) / 2),
|
4163 | computed = iteratee(array[mid]),
|
4164 | othIsDefined = computed !== undefined,
|
4165 | othIsNull = computed === null,
|
4166 | othIsReflexive = computed === computed,
|
4167 | othIsSymbol = isSymbol(computed);
|
4168 |
|
4169 | if (valIsNaN) {
|
4170 | var setLow = retHighest || othIsReflexive;
|
4171 | } else if (valIsUndefined) {
|
4172 | setLow = othIsReflexive && (retHighest || othIsDefined);
|
4173 | } else if (valIsNull) {
|
4174 | setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
|
4175 | } else if (valIsSymbol) {
|
4176 | setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
|
4177 | } else if (othIsNull || othIsSymbol) {
|
4178 | setLow = false;
|
4179 | } else {
|
4180 | setLow = retHighest ? (computed <= value) : (computed < value);
|
4181 | }
|
4182 | if (setLow) {
|
4183 | low = mid + 1;
|
4184 | } else {
|
4185 | high = mid;
|
4186 | }
|
4187 | }
|
4188 | return nativeMin(high, MAX_ARRAY_INDEX);
|
4189 | }
|
4190 |
|
4191 | /**
|
4192 | * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
|
4193 | * support for iteratee shorthands.
|
4194 | *
|
4195 | * @private
|
4196 | * @param {Array} array The array to inspect.
|
4197 | * @param {Function} [iteratee] The iteratee invoked per element.
|
4198 | * @returns {Array} Returns the new duplicate free array.
|
4199 | */
|
4200 | function baseSortedUniq(array, iteratee) {
|
4201 | var index = -1,
|
4202 | length = array.length,
|
4203 | resIndex = 0,
|
4204 | result = [];
|
4205 |
|
4206 | while (++index < length) {
|
4207 | var value = array[index],
|
4208 | computed = iteratee ? iteratee(value) : value;
|
4209 |
|
4210 | if (!index || !eq(computed, seen)) {
|
4211 | var seen = computed;
|
4212 | result[resIndex++] = value === 0 ? 0 : value;
|
4213 | }
|
4214 | }
|
4215 | return result;
|
4216 | }
|
4217 |
|
4218 | /**
|
4219 | * The base implementation of `_.toNumber` which doesn't ensure correct
|
4220 | * conversions of binary, hexadecimal, or octal string values.
|
4221 | *
|
4222 | * @private
|
4223 | * @param {*} value The value to process.
|
4224 | * @returns {number} Returns the number.
|
4225 | */
|
4226 | function baseToNumber(value) {
|
4227 | if (typeof value == 'number') {
|
4228 | return value;
|
4229 | }
|
4230 | if (isSymbol(value)) {
|
4231 | return NAN;
|
4232 | }
|
4233 | return +value;
|
4234 | }
|
4235 |
|
4236 | /**
|
4237 | * The base implementation of `_.toString` which doesn't convert nullish
|
4238 | * values to empty strings.
|
4239 | *
|
4240 | * @private
|
4241 | * @param {*} value The value to process.
|
4242 | * @returns {string} Returns the string.
|
4243 | */
|
4244 | function baseToString(value) {
|
4245 | // Exit early for strings to avoid a performance hit in some environments.
|
4246 | if (typeof value == 'string') {
|
4247 | return value;
|
4248 | }
|
4249 | if (isArray(value)) {
|
4250 | // Recursively convert values (susceptible to call stack limits).
|
4251 | return arrayMap(value, baseToString) + '';
|
4252 | }
|
4253 | if (isSymbol(value)) {
|
4254 | return symbolToString ? symbolToString.call(value) : '';
|
4255 | }
|
4256 | var result = (value + '');
|
4257 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
4258 | }
|
4259 |
|
4260 | /**
|
4261 | * The base implementation of `_.uniqBy` without support for iteratee shorthands.
|
4262 | *
|
4263 | * @private
|
4264 | * @param {Array} array The array to inspect.
|
4265 | * @param {Function} [iteratee] The iteratee invoked per element.
|
4266 | * @param {Function} [comparator] The comparator invoked per element.
|
4267 | * @returns {Array} Returns the new duplicate free array.
|
4268 | */
|
4269 | function baseUniq(array, iteratee, comparator) {
|
4270 | var index = -1,
|
4271 | includes = arrayIncludes,
|
4272 | length = array.length,
|
4273 | isCommon = true,
|
4274 | result = [],
|
4275 | seen = result;
|
4276 |
|
4277 | if (comparator) {
|
4278 | isCommon = false;
|
4279 | includes = arrayIncludesWith;
|
4280 | }
|
4281 | else if (length >= LARGE_ARRAY_SIZE) {
|
4282 | var set = iteratee ? null : createSet(array);
|
4283 | if (set) {
|
4284 | return setToArray(set);
|
4285 | }
|
4286 | isCommon = false;
|
4287 | includes = cacheHas;
|
4288 | seen = new SetCache;
|
4289 | }
|
4290 | else {
|
4291 | seen = iteratee ? [] : result;
|
4292 | }
|
4293 | outer:
|
4294 | while (++index < length) {
|
4295 | var value = array[index],
|
4296 | computed = iteratee ? iteratee(value) : value;
|
4297 |
|
4298 | value = (comparator || value !== 0) ? value : 0;
|
4299 | if (isCommon && computed === computed) {
|
4300 | var seenIndex = seen.length;
|
4301 | while (seenIndex--) {
|
4302 | if (seen[seenIndex] === computed) {
|
4303 | continue outer;
|
4304 | }
|
4305 | }
|
4306 | if (iteratee) {
|
4307 | seen.push(computed);
|
4308 | }
|
4309 | result.push(value);
|
4310 | }
|
4311 | else if (!includes(seen, computed, comparator)) {
|
4312 | if (seen !== result) {
|
4313 | seen.push(computed);
|
4314 | }
|
4315 | result.push(value);
|
4316 | }
|
4317 | }
|
4318 | return result;
|
4319 | }
|
4320 |
|
4321 | /**
|
4322 | * The base implementation of `_.unset`.
|
4323 | *
|
4324 | * @private
|
4325 | * @param {Object} object The object to modify.
|
4326 | * @param {Array|string} path The property path to unset.
|
4327 | * @returns {boolean} Returns `true` if the property is deleted, else `false`.
|
4328 | */
|
4329 | function baseUnset(object, path) {
|
4330 | path = castPath(path, object);
|
4331 | object = parent(object, path);
|
4332 | return object == null || delete object[toKey(last(path))];
|
4333 | }
|
4334 |
|
4335 | /**
|
4336 | * The base implementation of `_.update`.
|
4337 | *
|
4338 | * @private
|
4339 | * @param {Object} object The object to modify.
|
4340 | * @param {Array|string} path The path of the property to update.
|
4341 | * @param {Function} updater The function to produce the updated value.
|
4342 | * @param {Function} [customizer] The function to customize path creation.
|
4343 | * @returns {Object} Returns `object`.
|
4344 | */
|
4345 | function baseUpdate(object, path, updater, customizer) {
|
4346 | return baseSet(object, path, updater(baseGet(object, path)), customizer);
|
4347 | }
|
4348 |
|
4349 | /**
|
4350 | * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
|
4351 | * without support for iteratee shorthands.
|
4352 | *
|
4353 | * @private
|
4354 | * @param {Array} array The array to query.
|
4355 | * @param {Function} predicate The function invoked per iteration.
|
4356 | * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
|
4357 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
4358 | * @returns {Array} Returns the slice of `array`.
|
4359 | */
|
4360 | function baseWhile(array, predicate, isDrop, fromRight) {
|
4361 | var length = array.length,
|
4362 | index = fromRight ? length : -1;
|
4363 |
|
4364 | while ((fromRight ? index-- : ++index < length) &&
|
4365 | predicate(array[index], index, array)) {}
|
4366 |
|
4367 | return isDrop
|
4368 | ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
|
4369 | : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
|
4370 | }
|
4371 |
|
4372 | /**
|
4373 | * The base implementation of `wrapperValue` which returns the result of
|
4374 | * performing a sequence of actions on the unwrapped `value`, where each
|
4375 | * successive action is supplied the return value of the previous.
|
4376 | *
|
4377 | * @private
|
4378 | * @param {*} value The unwrapped value.
|
4379 | * @param {Array} actions Actions to perform to resolve the unwrapped value.
|
4380 | * @returns {*} Returns the resolved value.
|
4381 | */
|
4382 | function baseWrapperValue(value, actions) {
|
4383 | var result = value;
|
4384 | if (result instanceof LazyWrapper) {
|
4385 | result = result.value();
|
4386 | }
|
4387 | return arrayReduce(actions, function(result, action) {
|
4388 | return action.func.apply(action.thisArg, arrayPush([result], action.args));
|
4389 | }, result);
|
4390 | }
|
4391 |
|
4392 | /**
|
4393 | * The base implementation of methods like `_.xor`, without support for
|
4394 | * iteratee shorthands, that accepts an array of arrays to inspect.
|
4395 | *
|
4396 | * @private
|
4397 | * @param {Array} arrays The arrays to inspect.
|
4398 | * @param {Function} [iteratee] The iteratee invoked per element.
|
4399 | * @param {Function} [comparator] The comparator invoked per element.
|
4400 | * @returns {Array} Returns the new array of values.
|
4401 | */
|
4402 | function baseXor(arrays, iteratee, comparator) {
|
4403 | var length = arrays.length;
|
4404 | if (length < 2) {
|
4405 | return length ? baseUniq(arrays[0]) : [];
|
4406 | }
|
4407 | var index = -1,
|
4408 | result = Array(length);
|
4409 |
|
4410 | while (++index < length) {
|
4411 | var array = arrays[index],
|
4412 | othIndex = -1;
|
4413 |
|
4414 | while (++othIndex < length) {
|
4415 | if (othIndex != index) {
|
4416 | result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
|
4417 | }
|
4418 | }
|
4419 | }
|
4420 | return baseUniq(baseFlatten(result, 1), iteratee, comparator);
|
4421 | }
|
4422 |
|
4423 | /**
|
4424 | * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
|
4425 | *
|
4426 | * @private
|
4427 | * @param {Array} props The property identifiers.
|
4428 | * @param {Array} values The property values.
|
4429 | * @param {Function} assignFunc The function to assign values.
|
4430 | * @returns {Object} Returns the new object.
|
4431 | */
|
4432 | function baseZipObject(props, values, assignFunc) {
|
4433 | var index = -1,
|
4434 | length = props.length,
|
4435 | valsLength = values.length,
|
4436 | result = {};
|
4437 |
|
4438 | while (++index < length) {
|
4439 | var value = index < valsLength ? values[index] : undefined;
|
4440 | assignFunc(result, props[index], value);
|
4441 | }
|
4442 | return result;
|
4443 | }
|
4444 |
|
4445 | /**
|
4446 | * Casts `value` to an empty array if it's not an array like object.
|
4447 | *
|
4448 | * @private
|
4449 | * @param {*} value The value to inspect.
|
4450 | * @returns {Array|Object} Returns the cast array-like object.
|
4451 | */
|
4452 | function castArrayLikeObject(value) {
|
4453 | return isArrayLikeObject(value) ? value : [];
|
4454 | }
|
4455 |
|
4456 | /**
|
4457 | * Casts `value` to `identity` if it's not a function.
|
4458 | *
|
4459 | * @private
|
4460 | * @param {*} value The value to inspect.
|
4461 | * @returns {Function} Returns cast function.
|
4462 | */
|
4463 | function castFunction(value) {
|
4464 | return typeof value == 'function' ? value : identity;
|
4465 | }
|
4466 |
|
4467 | /**
|
4468 | * Casts `value` to a path array if it's not one.
|
4469 | *
|
4470 | * @private
|
4471 | * @param {*} value The value to inspect.
|
4472 | * @param {Object} [object] The object to query keys on.
|
4473 | * @returns {Array} Returns the cast property path array.
|
4474 | */
|
4475 | function castPath(value, object) {
|
4476 | if (isArray(value)) {
|
4477 | return value;
|
4478 | }
|
4479 | return isKey(value, object) ? [value] : stringToPath(toString(value));
|
4480 | }
|
4481 |
|
4482 | /**
|
4483 | * A `baseRest` alias which can be replaced with `identity` by module
|
4484 | * replacement plugins.
|
4485 | *
|
4486 | * @private
|
4487 | * @type {Function}
|
4488 | * @param {Function} func The function to apply a rest parameter to.
|
4489 | * @returns {Function} Returns the new function.
|
4490 | */
|
4491 | var castRest = baseRest;
|
4492 |
|
4493 | /**
|
4494 | * Casts `array` to a slice if it's needed.
|
4495 | *
|
4496 | * @private
|
4497 | * @param {Array} array The array to inspect.
|
4498 | * @param {number} start The start position.
|
4499 | * @param {number} [end=array.length] The end position.
|
4500 | * @returns {Array} Returns the cast slice.
|
4501 | */
|
4502 | function castSlice(array, start, end) {
|
4503 | var length = array.length;
|
4504 | end = end === undefined ? length : end;
|
4505 | return (!start && end >= length) ? array : baseSlice(array, start, end);
|
4506 | }
|
4507 |
|
4508 | /**
|
4509 | * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
|
4510 | *
|
4511 | * @private
|
4512 | * @param {number|Object} id The timer id or timeout object of the timer to clear.
|
4513 | */
|
4514 | var clearTimeout = ctxClearTimeout || function(id) {
|
4515 | return root.clearTimeout(id);
|
4516 | };
|
4517 |
|
4518 | /**
|
4519 | * Creates a clone of `buffer`.
|
4520 | *
|
4521 | * @private
|
4522 | * @param {Buffer} buffer The buffer to clone.
|
4523 | * @param {boolean} [isDeep] Specify a deep clone.
|
4524 | * @returns {Buffer} Returns the cloned buffer.
|
4525 | */
|
4526 | function cloneBuffer(buffer, isDeep) {
|
4527 | if (isDeep) {
|
4528 | return buffer.slice();
|
4529 | }
|
4530 | var length = buffer.length,
|
4531 | result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
|
4532 |
|
4533 | buffer.copy(result);
|
4534 | return result;
|
4535 | }
|
4536 |
|
4537 | /**
|
4538 | * Creates a clone of `arrayBuffer`.
|
4539 | *
|
4540 | * @private
|
4541 | * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
|
4542 | * @returns {ArrayBuffer} Returns the cloned array buffer.
|
4543 | */
|
4544 | function cloneArrayBuffer(arrayBuffer) {
|
4545 | var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
4546 | new Uint8Array(result).set(new Uint8Array(arrayBuffer));
|
4547 | return result;
|
4548 | }
|
4549 |
|
4550 | /**
|
4551 | * Creates a clone of `dataView`.
|
4552 | *
|
4553 | * @private
|
4554 | * @param {Object} dataView The data view to clone.
|
4555 | * @param {boolean} [isDeep] Specify a deep clone.
|
4556 | * @returns {Object} Returns the cloned data view.
|
4557 | */
|
4558 | function cloneDataView(dataView, isDeep) {
|
4559 | var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
|
4560 | return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
|
4561 | }
|
4562 |
|
4563 | /**
|
4564 | * Creates a clone of `regexp`.
|
4565 | *
|
4566 | * @private
|
4567 | * @param {Object} regexp The regexp to clone.
|
4568 | * @returns {Object} Returns the cloned regexp.
|
4569 | */
|
4570 | function cloneRegExp(regexp) {
|
4571 | var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
|
4572 | result.lastIndex = regexp.lastIndex;
|
4573 | return result;
|
4574 | }
|
4575 |
|
4576 | /**
|
4577 | * Creates a clone of the `symbol` object.
|
4578 | *
|
4579 | * @private
|
4580 | * @param {Object} symbol The symbol object to clone.
|
4581 | * @returns {Object} Returns the cloned symbol object.
|
4582 | */
|
4583 | function cloneSymbol(symbol) {
|
4584 | return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
|
4585 | }
|
4586 |
|
4587 | /**
|
4588 | * Creates a clone of `typedArray`.
|
4589 | *
|
4590 | * @private
|
4591 | * @param {Object} typedArray The typed array to clone.
|
4592 | * @param {boolean} [isDeep] Specify a deep clone.
|
4593 | * @returns {Object} Returns the cloned typed array.
|
4594 | */
|
4595 | function cloneTypedArray(typedArray, isDeep) {
|
4596 | var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
|
4597 | return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
|
4598 | }
|
4599 |
|
4600 | /**
|
4601 | * Compares values to sort them in ascending order.
|
4602 | *
|
4603 | * @private
|
4604 | * @param {*} value The value to compare.
|
4605 | * @param {*} other The other value to compare.
|
4606 | * @returns {number} Returns the sort order indicator for `value`.
|
4607 | */
|
4608 | function compareAscending(value, other) {
|
4609 | if (value !== other) {
|
4610 | var valIsDefined = value !== undefined,
|
4611 | valIsNull = value === null,
|
4612 | valIsReflexive = value === value,
|
4613 | valIsSymbol = isSymbol(value);
|
4614 |
|
4615 | var othIsDefined = other !== undefined,
|
4616 | othIsNull = other === null,
|
4617 | othIsReflexive = other === other,
|
4618 | othIsSymbol = isSymbol(other);
|
4619 |
|
4620 | if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
|
4621 | (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
|
4622 | (valIsNull && othIsDefined && othIsReflexive) ||
|
4623 | (!valIsDefined && othIsReflexive) ||
|
4624 | !valIsReflexive) {
|
4625 | return 1;
|
4626 | }
|
4627 | if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
|
4628 | (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
|
4629 | (othIsNull && valIsDefined && valIsReflexive) ||
|
4630 | (!othIsDefined && valIsReflexive) ||
|
4631 | !othIsReflexive) {
|
4632 | return -1;
|
4633 | }
|
4634 | }
|
4635 | return 0;
|
4636 | }
|
4637 |
|
4638 | /**
|
4639 | * Used by `_.orderBy` to compare multiple properties of a value to another
|
4640 | * and stable sort them.
|
4641 | *
|
4642 | * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
|
4643 | * specify an order of "desc" for descending or "asc" for ascending sort order
|
4644 | * of corresponding values.
|
4645 | *
|
4646 | * @private
|
4647 | * @param {Object} object The object to compare.
|
4648 | * @param {Object} other The other object to compare.
|
4649 | * @param {boolean[]|string[]} orders The order to sort by for each property.
|
4650 | * @returns {number} Returns the sort order indicator for `object`.
|
4651 | */
|
4652 | function compareMultiple(object, other, orders) {
|
4653 | var index = -1,
|
4654 | objCriteria = object.criteria,
|
4655 | othCriteria = other.criteria,
|
4656 | length = objCriteria.length,
|
4657 | ordersLength = orders.length;
|
4658 |
|
4659 | while (++index < length) {
|
4660 | var result = compareAscending(objCriteria[index], othCriteria[index]);
|
4661 | if (result) {
|
4662 | if (index >= ordersLength) {
|
4663 | return result;
|
4664 | }
|
4665 | var order = orders[index];
|
4666 | return result * (order == 'desc' ? -1 : 1);
|
4667 | }
|
4668 | }
|
4669 | // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
4670 | // that causes it, under certain circumstances, to provide the same value for
|
4671 | // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
|
4672 | // for more details.
|
4673 | //
|
4674 | // This also ensures a stable sort in V8 and other engines.
|
4675 | // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
|
4676 | return object.index - other.index;
|
4677 | }
|
4678 |
|
4679 | /**
|
4680 | * Creates an array that is the composition of partially applied arguments,
|
4681 | * placeholders, and provided arguments into a single array of arguments.
|
4682 | *
|
4683 | * @private
|
4684 | * @param {Array} args The provided arguments.
|
4685 | * @param {Array} partials The arguments to prepend to those provided.
|
4686 | * @param {Array} holders The `partials` placeholder indexes.
|
4687 | * @params {boolean} [isCurried] Specify composing for a curried function.
|
4688 | * @returns {Array} Returns the new array of composed arguments.
|
4689 | */
|
4690 | function composeArgs(args, partials, holders, isCurried) {
|
4691 | var argsIndex = -1,
|
4692 | argsLength = args.length,
|
4693 | holdersLength = holders.length,
|
4694 | leftIndex = -1,
|
4695 | leftLength = partials.length,
|
4696 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
4697 | result = Array(leftLength + rangeLength),
|
4698 | isUncurried = !isCurried;
|
4699 |
|
4700 | while (++leftIndex < leftLength) {
|
4701 | result[leftIndex] = partials[leftIndex];
|
4702 | }
|
4703 | while (++argsIndex < holdersLength) {
|
4704 | if (isUncurried || argsIndex < argsLength) {
|
4705 | result[holders[argsIndex]] = args[argsIndex];
|
4706 | }
|
4707 | }
|
4708 | while (rangeLength--) {
|
4709 | result[leftIndex++] = args[argsIndex++];
|
4710 | }
|
4711 | return result;
|
4712 | }
|
4713 |
|
4714 | /**
|
4715 | * This function is like `composeArgs` except that the arguments composition
|
4716 | * is tailored for `_.partialRight`.
|
4717 | *
|
4718 | * @private
|
4719 | * @param {Array} args The provided arguments.
|
4720 | * @param {Array} partials The arguments to append to those provided.
|
4721 | * @param {Array} holders The `partials` placeholder indexes.
|
4722 | * @params {boolean} [isCurried] Specify composing for a curried function.
|
4723 | * @returns {Array} Returns the new array of composed arguments.
|
4724 | */
|
4725 | function composeArgsRight(args, partials, holders, isCurried) {
|
4726 | var argsIndex = -1,
|
4727 | argsLength = args.length,
|
4728 | holdersIndex = -1,
|
4729 | holdersLength = holders.length,
|
4730 | rightIndex = -1,
|
4731 | rightLength = partials.length,
|
4732 | rangeLength = nativeMax(argsLength - holdersLength, 0),
|
4733 | result = Array(rangeLength + rightLength),
|
4734 | isUncurried = !isCurried;
|
4735 |
|
4736 | while (++argsIndex < rangeLength) {
|
4737 | result[argsIndex] = args[argsIndex];
|
4738 | }
|
4739 | var offset = argsIndex;
|
4740 | while (++rightIndex < rightLength) {
|
4741 | result[offset + rightIndex] = partials[rightIndex];
|
4742 | }
|
4743 | while (++holdersIndex < holdersLength) {
|
4744 | if (isUncurried || argsIndex < argsLength) {
|
4745 | result[offset + holders[holdersIndex]] = args[argsIndex++];
|
4746 | }
|
4747 | }
|
4748 | return result;
|
4749 | }
|
4750 |
|
4751 | /**
|
4752 | * Copies the values of `source` to `array`.
|
4753 | *
|
4754 | * @private
|
4755 | * @param {Array} source The array to copy values from.
|
4756 | * @param {Array} [array=[]] The array to copy values to.
|
4757 | * @returns {Array} Returns `array`.
|
4758 | */
|
4759 | function copyArray(source, array) {
|
4760 | var index = -1,
|
4761 | length = source.length;
|
4762 |
|
4763 | array || (array = Array(length));
|
4764 | while (++index < length) {
|
4765 | array[index] = source[index];
|
4766 | }
|
4767 | return array;
|
4768 | }
|
4769 |
|
4770 | /**
|
4771 | * Copies properties of `source` to `object`.
|
4772 | *
|
4773 | * @private
|
4774 | * @param {Object} source The object to copy properties from.
|
4775 | * @param {Array} props The property identifiers to copy.
|
4776 | * @param {Object} [object={}] The object to copy properties to.
|
4777 | * @param {Function} [customizer] The function to customize copied values.
|
4778 | * @returns {Object} Returns `object`.
|
4779 | */
|
4780 | function copyObject(source, props, object, customizer) {
|
4781 | var isNew = !object;
|
4782 | object || (object = {});
|
4783 |
|
4784 | var index = -1,
|
4785 | length = props.length;
|
4786 |
|
4787 | while (++index < length) {
|
4788 | var key = props[index];
|
4789 |
|
4790 | var newValue = customizer
|
4791 | ? customizer(object[key], source[key], key, object, source)
|
4792 | : undefined;
|
4793 |
|
4794 | if (newValue === undefined) {
|
4795 | newValue = source[key];
|
4796 | }
|
4797 | if (isNew) {
|
4798 | baseAssignValue(object, key, newValue);
|
4799 | } else {
|
4800 | assignValue(object, key, newValue);
|
4801 | }
|
4802 | }
|
4803 | return object;
|
4804 | }
|
4805 |
|
4806 | /**
|
4807 | * Copies own symbols of `source` to `object`.
|
4808 | *
|
4809 | * @private
|
4810 | * @param {Object} source The object to copy symbols from.
|
4811 | * @param {Object} [object={}] The object to copy symbols to.
|
4812 | * @returns {Object} Returns `object`.
|
4813 | */
|
4814 | function copySymbols(source, object) {
|
4815 | return copyObject(source, getSymbols(source), object);
|
4816 | }
|
4817 |
|
4818 | /**
|
4819 | * Copies own and inherited symbols of `source` to `object`.
|
4820 | *
|
4821 | * @private
|
4822 | * @param {Object} source The object to copy symbols from.
|
4823 | * @param {Object} [object={}] The object to copy symbols to.
|
4824 | * @returns {Object} Returns `object`.
|
4825 | */
|
4826 | function copySymbolsIn(source, object) {
|
4827 | return copyObject(source, getSymbolsIn(source), object);
|
4828 | }
|
4829 |
|
4830 | /**
|
4831 | * Creates a function like `_.groupBy`.
|
4832 | *
|
4833 | * @private
|
4834 | * @param {Function} setter The function to set accumulator values.
|
4835 | * @param {Function} [initializer] The accumulator object initializer.
|
4836 | * @returns {Function} Returns the new aggregator function.
|
4837 | */
|
4838 | function createAggregator(setter, initializer) {
|
4839 | return function(collection, iteratee) {
|
4840 | var func = isArray(collection) ? arrayAggregator : baseAggregator,
|
4841 | accumulator = initializer ? initializer() : {};
|
4842 |
|
4843 | return func(collection, setter, getIteratee(iteratee, 2), accumulator);
|
4844 | };
|
4845 | }
|
4846 |
|
4847 | /**
|
4848 | * Creates a function like `_.assign`.
|
4849 | *
|
4850 | * @private
|
4851 | * @param {Function} assigner The function to assign values.
|
4852 | * @returns {Function} Returns the new assigner function.
|
4853 | */
|
4854 | function createAssigner(assigner) {
|
4855 | return baseRest(function(object, sources) {
|
4856 | var index = -1,
|
4857 | length = sources.length,
|
4858 | customizer = length > 1 ? sources[length - 1] : undefined,
|
4859 | guard = length > 2 ? sources[2] : undefined;
|
4860 |
|
4861 | customizer = (assigner.length > 3 && typeof customizer == 'function')
|
4862 | ? (length--, customizer)
|
4863 | : undefined;
|
4864 |
|
4865 | if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
4866 | customizer = length < 3 ? undefined : customizer;
|
4867 | length = 1;
|
4868 | }
|
4869 | object = Object(object);
|
4870 | while (++index < length) {
|
4871 | var source = sources[index];
|
4872 | if (source) {
|
4873 | assigner(object, source, index, customizer);
|
4874 | }
|
4875 | }
|
4876 | return object;
|
4877 | });
|
4878 | }
|
4879 |
|
4880 | /**
|
4881 | * Creates a `baseEach` or `baseEachRight` function.
|
4882 | *
|
4883 | * @private
|
4884 | * @param {Function} eachFunc The function to iterate over a collection.
|
4885 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
4886 | * @returns {Function} Returns the new base function.
|
4887 | */
|
4888 | function createBaseEach(eachFunc, fromRight) {
|
4889 | return function(collection, iteratee) {
|
4890 | if (collection == null) {
|
4891 | return collection;
|
4892 | }
|
4893 | if (!isArrayLike(collection)) {
|
4894 | return eachFunc(collection, iteratee);
|
4895 | }
|
4896 | var length = collection.length,
|
4897 | index = fromRight ? length : -1,
|
4898 | iterable = Object(collection);
|
4899 |
|
4900 | while ((fromRight ? index-- : ++index < length)) {
|
4901 | if (iteratee(iterable[index], index, iterable) === false) {
|
4902 | break;
|
4903 | }
|
4904 | }
|
4905 | return collection;
|
4906 | };
|
4907 | }
|
4908 |
|
4909 | /**
|
4910 | * Creates a base function for methods like `_.forIn` and `_.forOwn`.
|
4911 | *
|
4912 | * @private
|
4913 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
4914 | * @returns {Function} Returns the new base function.
|
4915 | */
|
4916 | function createBaseFor(fromRight) {
|
4917 | return function(object, iteratee, keysFunc) {
|
4918 | var index = -1,
|
4919 | iterable = Object(object),
|
4920 | props = keysFunc(object),
|
4921 | length = props.length;
|
4922 |
|
4923 | while (length--) {
|
4924 | var key = props[fromRight ? length : ++index];
|
4925 | if (iteratee(iterable[key], key, iterable) === false) {
|
4926 | break;
|
4927 | }
|
4928 | }
|
4929 | return object;
|
4930 | };
|
4931 | }
|
4932 |
|
4933 | /**
|
4934 | * Creates a function that wraps `func` to invoke it with the optional `this`
|
4935 | * binding of `thisArg`.
|
4936 | *
|
4937 | * @private
|
4938 | * @param {Function} func The function to wrap.
|
4939 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
4940 | * @param {*} [thisArg] The `this` binding of `func`.
|
4941 | * @returns {Function} Returns the new wrapped function.
|
4942 | */
|
4943 | function createBind(func, bitmask, thisArg) {
|
4944 | var isBind = bitmask & WRAP_BIND_FLAG,
|
4945 | Ctor = createCtor(func);
|
4946 |
|
4947 | function wrapper() {
|
4948 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
4949 | return fn.apply(isBind ? thisArg : this, arguments);
|
4950 | }
|
4951 | return wrapper;
|
4952 | }
|
4953 |
|
4954 | /**
|
4955 | * Creates a function like `_.lowerFirst`.
|
4956 | *
|
4957 | * @private
|
4958 | * @param {string} methodName The name of the `String` case method to use.
|
4959 | * @returns {Function} Returns the new case function.
|
4960 | */
|
4961 | function createCaseFirst(methodName) {
|
4962 | return function(string) {
|
4963 | string = toString(string);
|
4964 |
|
4965 | var strSymbols = hasUnicode(string)
|
4966 | ? stringToArray(string)
|
4967 | : undefined;
|
4968 |
|
4969 | var chr = strSymbols
|
4970 | ? strSymbols[0]
|
4971 | : string.charAt(0);
|
4972 |
|
4973 | var trailing = strSymbols
|
4974 | ? castSlice(strSymbols, 1).join('')
|
4975 | : string.slice(1);
|
4976 |
|
4977 | return chr[methodName]() + trailing;
|
4978 | };
|
4979 | }
|
4980 |
|
4981 | /**
|
4982 | * Creates a function like `_.camelCase`.
|
4983 | *
|
4984 | * @private
|
4985 | * @param {Function} callback The function to combine each word.
|
4986 | * @returns {Function} Returns the new compounder function.
|
4987 | */
|
4988 | function createCompounder(callback) {
|
4989 | return function(string) {
|
4990 | return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
|
4991 | };
|
4992 | }
|
4993 |
|
4994 | /**
|
4995 | * Creates a function that produces an instance of `Ctor` regardless of
|
4996 | * whether it was invoked as part of a `new` expression or by `call` or `apply`.
|
4997 | *
|
4998 | * @private
|
4999 | * @param {Function} Ctor The constructor to wrap.
|
5000 | * @returns {Function} Returns the new wrapped function.
|
5001 | */
|
5002 | function createCtor(Ctor) {
|
5003 | return function() {
|
5004 | // Use a `switch` statement to work with class constructors. See
|
5005 | // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
5006 | // for more details.
|
5007 | var args = arguments;
|
5008 | switch (args.length) {
|
5009 | case 0: return new Ctor;
|
5010 | case 1: return new Ctor(args[0]);
|
5011 | case 2: return new Ctor(args[0], args[1]);
|
5012 | case 3: return new Ctor(args[0], args[1], args[2]);
|
5013 | case 4: return new Ctor(args[0], args[1], args[2], args[3]);
|
5014 | case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
|
5015 | case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
|
5016 | case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
5017 | }
|
5018 | var thisBinding = baseCreate(Ctor.prototype),
|
5019 | result = Ctor.apply(thisBinding, args);
|
5020 |
|
5021 | // Mimic the constructor's `return` behavior.
|
5022 | // See https://es5.github.io/#x13.2.2 for more details.
|
5023 | return isObject(result) ? result : thisBinding;
|
5024 | };
|
5025 | }
|
5026 |
|
5027 | /**
|
5028 | * Creates a function that wraps `func` to enable currying.
|
5029 | *
|
5030 | * @private
|
5031 | * @param {Function} func The function to wrap.
|
5032 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
5033 | * @param {number} arity The arity of `func`.
|
5034 | * @returns {Function} Returns the new wrapped function.
|
5035 | */
|
5036 | function createCurry(func, bitmask, arity) {
|
5037 | var Ctor = createCtor(func);
|
5038 |
|
5039 | function wrapper() {
|
5040 | var length = arguments.length,
|
5041 | args = Array(length),
|
5042 | index = length,
|
5043 | placeholder = getHolder(wrapper);
|
5044 |
|
5045 | while (index--) {
|
5046 | args[index] = arguments[index];
|
5047 | }
|
5048 | var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
|
5049 | ? []
|
5050 | : replaceHolders(args, placeholder);
|
5051 |
|
5052 | length -= holders.length;
|
5053 | if (length < arity) {
|
5054 | return createRecurry(
|
5055 | func, bitmask, createHybrid, wrapper.placeholder, undefined,
|
5056 | args, holders, undefined, undefined, arity - length);
|
5057 | }
|
5058 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
5059 | return apply(fn, this, args);
|
5060 | }
|
5061 | return wrapper;
|
5062 | }
|
5063 |
|
5064 | /**
|
5065 | * Creates a `_.find` or `_.findLast` function.
|
5066 | *
|
5067 | * @private
|
5068 | * @param {Function} findIndexFunc The function to find the collection index.
|
5069 | * @returns {Function} Returns the new find function.
|
5070 | */
|
5071 | function createFind(findIndexFunc) {
|
5072 | return function(collection, predicate, fromIndex) {
|
5073 | var iterable = Object(collection);
|
5074 | if (!isArrayLike(collection)) {
|
5075 | var iteratee = getIteratee(predicate, 3);
|
5076 | collection = keys(collection);
|
5077 | predicate = function(key) { return iteratee(iterable[key], key, iterable); };
|
5078 | }
|
5079 | var index = findIndexFunc(collection, predicate, fromIndex);
|
5080 | return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
|
5081 | };
|
5082 | }
|
5083 |
|
5084 | /**
|
5085 | * Creates a `_.flow` or `_.flowRight` function.
|
5086 | *
|
5087 | * @private
|
5088 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
5089 | * @returns {Function} Returns the new flow function.
|
5090 | */
|
5091 | function createFlow(fromRight) {
|
5092 | return flatRest(function(funcs) {
|
5093 | var length = funcs.length,
|
5094 | index = length,
|
5095 | prereq = LodashWrapper.prototype.thru;
|
5096 |
|
5097 | if (fromRight) {
|
5098 | funcs.reverse();
|
5099 | }
|
5100 | while (index--) {
|
5101 | var func = funcs[index];
|
5102 | if (typeof func != 'function') {
|
5103 | throw new TypeError(FUNC_ERROR_TEXT);
|
5104 | }
|
5105 | if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
|
5106 | var wrapper = new LodashWrapper([], true);
|
5107 | }
|
5108 | }
|
5109 | index = wrapper ? index : length;
|
5110 | while (++index < length) {
|
5111 | func = funcs[index];
|
5112 |
|
5113 | var funcName = getFuncName(func),
|
5114 | data = funcName == 'wrapper' ? getData(func) : undefined;
|
5115 |
|
5116 | if (data && isLaziable(data[0]) &&
|
5117 | data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
|
5118 | !data[4].length && data[9] == 1
|
5119 | ) {
|
5120 | wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
|
5121 | } else {
|
5122 | wrapper = (func.length == 1 && isLaziable(func))
|
5123 | ? wrapper[funcName]()
|
5124 | : wrapper.thru(func);
|
5125 | }
|
5126 | }
|
5127 | return function() {
|
5128 | var args = arguments,
|
5129 | value = args[0];
|
5130 |
|
5131 | if (wrapper && args.length == 1 && isArray(value)) {
|
5132 | return wrapper.plant(value).value();
|
5133 | }
|
5134 | var index = 0,
|
5135 | result = length ? funcs[index].apply(this, args) : value;
|
5136 |
|
5137 | while (++index < length) {
|
5138 | result = funcs[index].call(this, result);
|
5139 | }
|
5140 | return result;
|
5141 | };
|
5142 | });
|
5143 | }
|
5144 |
|
5145 | /**
|
5146 | * Creates a function that wraps `func` to invoke it with optional `this`
|
5147 | * binding of `thisArg`, partial application, and currying.
|
5148 | *
|
5149 | * @private
|
5150 | * @param {Function|string} func The function or method name to wrap.
|
5151 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
5152 | * @param {*} [thisArg] The `this` binding of `func`.
|
5153 | * @param {Array} [partials] The arguments to prepend to those provided to
|
5154 | * the new function.
|
5155 | * @param {Array} [holders] The `partials` placeholder indexes.
|
5156 | * @param {Array} [partialsRight] The arguments to append to those provided
|
5157 | * to the new function.
|
5158 | * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
|
5159 | * @param {Array} [argPos] The argument positions of the new function.
|
5160 | * @param {number} [ary] The arity cap of `func`.
|
5161 | * @param {number} [arity] The arity of `func`.
|
5162 | * @returns {Function} Returns the new wrapped function.
|
5163 | */
|
5164 | function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
|
5165 | var isAry = bitmask & WRAP_ARY_FLAG,
|
5166 | isBind = bitmask & WRAP_BIND_FLAG,
|
5167 | isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
|
5168 | isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
|
5169 | isFlip = bitmask & WRAP_FLIP_FLAG,
|
5170 | Ctor = isBindKey ? undefined : createCtor(func);
|
5171 |
|
5172 | function wrapper() {
|
5173 | var length = arguments.length,
|
5174 | args = Array(length),
|
5175 | index = length;
|
5176 |
|
5177 | while (index--) {
|
5178 | args[index] = arguments[index];
|
5179 | }
|
5180 | if (isCurried) {
|
5181 | var placeholder = getHolder(wrapper),
|
5182 | holdersCount = countHolders(args, placeholder);
|
5183 | }
|
5184 | if (partials) {
|
5185 | args = composeArgs(args, partials, holders, isCurried);
|
5186 | }
|
5187 | if (partialsRight) {
|
5188 | args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
|
5189 | }
|
5190 | length -= holdersCount;
|
5191 | if (isCurried && length < arity) {
|
5192 | var newHolders = replaceHolders(args, placeholder);
|
5193 | return createRecurry(
|
5194 | func, bitmask, createHybrid, wrapper.placeholder, thisArg,
|
5195 | args, newHolders, argPos, ary, arity - length
|
5196 | );
|
5197 | }
|
5198 | var thisBinding = isBind ? thisArg : this,
|
5199 | fn = isBindKey ? thisBinding[func] : func;
|
5200 |
|
5201 | length = args.length;
|
5202 | if (argPos) {
|
5203 | args = reorder(args, argPos);
|
5204 | } else if (isFlip && length > 1) {
|
5205 | args.reverse();
|
5206 | }
|
5207 | if (isAry && ary < length) {
|
5208 | args.length = ary;
|
5209 | }
|
5210 | if (this && this !== root && this instanceof wrapper) {
|
5211 | fn = Ctor || createCtor(fn);
|
5212 | }
|
5213 | return fn.apply(thisBinding, args);
|
5214 | }
|
5215 | return wrapper;
|
5216 | }
|
5217 |
|
5218 | /**
|
5219 | * Creates a function like `_.invertBy`.
|
5220 | *
|
5221 | * @private
|
5222 | * @param {Function} setter The function to set accumulator values.
|
5223 | * @param {Function} toIteratee The function to resolve iteratees.
|
5224 | * @returns {Function} Returns the new inverter function.
|
5225 | */
|
5226 | function createInverter(setter, toIteratee) {
|
5227 | return function(object, iteratee) {
|
5228 | return baseInverter(object, setter, toIteratee(iteratee), {});
|
5229 | };
|
5230 | }
|
5231 |
|
5232 | /**
|
5233 | * Creates a function that performs a mathematical operation on two values.
|
5234 | *
|
5235 | * @private
|
5236 | * @param {Function} operator The function to perform the operation.
|
5237 | * @param {number} [defaultValue] The value used for `undefined` arguments.
|
5238 | * @returns {Function} Returns the new mathematical operation function.
|
5239 | */
|
5240 | function createMathOperation(operator, defaultValue) {
|
5241 | return function(value, other) {
|
5242 | var result;
|
5243 | if (value === undefined && other === undefined) {
|
5244 | return defaultValue;
|
5245 | }
|
5246 | if (value !== undefined) {
|
5247 | result = value;
|
5248 | }
|
5249 | if (other !== undefined) {
|
5250 | if (result === undefined) {
|
5251 | return other;
|
5252 | }
|
5253 | if (typeof value == 'string' || typeof other == 'string') {
|
5254 | value = baseToString(value);
|
5255 | other = baseToString(other);
|
5256 | } else {
|
5257 | value = baseToNumber(value);
|
5258 | other = baseToNumber(other);
|
5259 | }
|
5260 | result = operator(value, other);
|
5261 | }
|
5262 | return result;
|
5263 | };
|
5264 | }
|
5265 |
|
5266 | /**
|
5267 | * Creates a function like `_.over`.
|
5268 | *
|
5269 | * @private
|
5270 | * @param {Function} arrayFunc The function to iterate over iteratees.
|
5271 | * @returns {Function} Returns the new over function.
|
5272 | */
|
5273 | function createOver(arrayFunc) {
|
5274 | return flatRest(function(iteratees) {
|
5275 | iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
|
5276 | return baseRest(function(args) {
|
5277 | var thisArg = this;
|
5278 | return arrayFunc(iteratees, function(iteratee) {
|
5279 | return apply(iteratee, thisArg, args);
|
5280 | });
|
5281 | });
|
5282 | });
|
5283 | }
|
5284 |
|
5285 | /**
|
5286 | * Creates the padding for `string` based on `length`. The `chars` string
|
5287 | * is truncated if the number of characters exceeds `length`.
|
5288 | *
|
5289 | * @private
|
5290 | * @param {number} length The padding length.
|
5291 | * @param {string} [chars=' '] The string used as padding.
|
5292 | * @returns {string} Returns the padding for `string`.
|
5293 | */
|
5294 | function createPadding(length, chars) {
|
5295 | chars = chars === undefined ? ' ' : baseToString(chars);
|
5296 |
|
5297 | var charsLength = chars.length;
|
5298 | if (charsLength < 2) {
|
5299 | return charsLength ? baseRepeat(chars, length) : chars;
|
5300 | }
|
5301 | var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
|
5302 | return hasUnicode(chars)
|
5303 | ? castSlice(stringToArray(result), 0, length).join('')
|
5304 | : result.slice(0, length);
|
5305 | }
|
5306 |
|
5307 | /**
|
5308 | * Creates a function that wraps `func` to invoke it with the `this` binding
|
5309 | * of `thisArg` and `partials` prepended to the arguments it receives.
|
5310 | *
|
5311 | * @private
|
5312 | * @param {Function} func The function to wrap.
|
5313 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
5314 | * @param {*} thisArg The `this` binding of `func`.
|
5315 | * @param {Array} partials The arguments to prepend to those provided to
|
5316 | * the new function.
|
5317 | * @returns {Function} Returns the new wrapped function.
|
5318 | */
|
5319 | function createPartial(func, bitmask, thisArg, partials) {
|
5320 | var isBind = bitmask & WRAP_BIND_FLAG,
|
5321 | Ctor = createCtor(func);
|
5322 |
|
5323 | function wrapper() {
|
5324 | var argsIndex = -1,
|
5325 | argsLength = arguments.length,
|
5326 | leftIndex = -1,
|
5327 | leftLength = partials.length,
|
5328 | args = Array(leftLength + argsLength),
|
5329 | fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
5330 |
|
5331 | while (++leftIndex < leftLength) {
|
5332 | args[leftIndex] = partials[leftIndex];
|
5333 | }
|
5334 | while (argsLength--) {
|
5335 | args[leftIndex++] = arguments[++argsIndex];
|
5336 | }
|
5337 | return apply(fn, isBind ? thisArg : this, args);
|
5338 | }
|
5339 | return wrapper;
|
5340 | }
|
5341 |
|
5342 | /**
|
5343 | * Creates a `_.range` or `_.rangeRight` function.
|
5344 | *
|
5345 | * @private
|
5346 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
5347 | * @returns {Function} Returns the new range function.
|
5348 | */
|
5349 | function createRange(fromRight) {
|
5350 | return function(start, end, step) {
|
5351 | if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
|
5352 | end = step = undefined;
|
5353 | }
|
5354 | // Ensure the sign of `-0` is preserved.
|
5355 | start = toFinite(start);
|
5356 | if (end === undefined) {
|
5357 | end = start;
|
5358 | start = 0;
|
5359 | } else {
|
5360 | end = toFinite(end);
|
5361 | }
|
5362 | step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
|
5363 | return baseRange(start, end, step, fromRight);
|
5364 | };
|
5365 | }
|
5366 |
|
5367 | /**
|
5368 | * Creates a function that performs a relational operation on two values.
|
5369 | *
|
5370 | * @private
|
5371 | * @param {Function} operator The function to perform the operation.
|
5372 | * @returns {Function} Returns the new relational operation function.
|
5373 | */
|
5374 | function createRelationalOperation(operator) {
|
5375 | return function(value, other) {
|
5376 | if (!(typeof value == 'string' && typeof other == 'string')) {
|
5377 | value = toNumber(value);
|
5378 | other = toNumber(other);
|
5379 | }
|
5380 | return operator(value, other);
|
5381 | };
|
5382 | }
|
5383 |
|
5384 | /**
|
5385 | * Creates a function that wraps `func` to continue currying.
|
5386 | *
|
5387 | * @private
|
5388 | * @param {Function} func The function to wrap.
|
5389 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
5390 | * @param {Function} wrapFunc The function to create the `func` wrapper.
|
5391 | * @param {*} placeholder The placeholder value.
|
5392 | * @param {*} [thisArg] The `this` binding of `func`.
|
5393 | * @param {Array} [partials] The arguments to prepend to those provided to
|
5394 | * the new function.
|
5395 | * @param {Array} [holders] The `partials` placeholder indexes.
|
5396 | * @param {Array} [argPos] The argument positions of the new function.
|
5397 | * @param {number} [ary] The arity cap of `func`.
|
5398 | * @param {number} [arity] The arity of `func`.
|
5399 | * @returns {Function} Returns the new wrapped function.
|
5400 | */
|
5401 | function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
|
5402 | var isCurry = bitmask & WRAP_CURRY_FLAG,
|
5403 | newHolders = isCurry ? holders : undefined,
|
5404 | newHoldersRight = isCurry ? undefined : holders,
|
5405 | newPartials = isCurry ? partials : undefined,
|
5406 | newPartialsRight = isCurry ? undefined : partials;
|
5407 |
|
5408 | bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
|
5409 | bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
|
5410 |
|
5411 | if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
|
5412 | bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
|
5413 | }
|
5414 | var newData = [
|
5415 | func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
|
5416 | newHoldersRight, argPos, ary, arity
|
5417 | ];
|
5418 |
|
5419 | var result = wrapFunc.apply(undefined, newData);
|
5420 | if (isLaziable(func)) {
|
5421 | setData(result, newData);
|
5422 | }
|
5423 | result.placeholder = placeholder;
|
5424 | return setWrapToString(result, func, bitmask);
|
5425 | }
|
5426 |
|
5427 | /**
|
5428 | * Creates a function like `_.round`.
|
5429 | *
|
5430 | * @private
|
5431 | * @param {string} methodName The name of the `Math` method to use when rounding.
|
5432 | * @returns {Function} Returns the new round function.
|
5433 | */
|
5434 | function createRound(methodName) {
|
5435 | var func = Math[methodName];
|
5436 | return function(number, precision) {
|
5437 | number = toNumber(number);
|
5438 | precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
|
5439 | if (precision) {
|
5440 | // Shift with exponential notation to avoid floating-point issues.
|
5441 | // See [MDN](https://mdn.io/round#Examples) for more details.
|
5442 | var pair = (toString(number) + 'e').split('e'),
|
5443 | value = func(pair[0] + 'e' + (+pair[1] + precision));
|
5444 |
|
5445 | pair = (toString(value) + 'e').split('e');
|
5446 | return +(pair[0] + 'e' + (+pair[1] - precision));
|
5447 | }
|
5448 | return func(number);
|
5449 | };
|
5450 | }
|
5451 |
|
5452 | /**
|
5453 | * Creates a set object of `values`.
|
5454 | *
|
5455 | * @private
|
5456 | * @param {Array} values The values to add to the set.
|
5457 | * @returns {Object} Returns the new set.
|
5458 | */
|
5459 | var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
|
5460 | return new Set(values);
|
5461 | };
|
5462 |
|
5463 | /**
|
5464 | * Creates a `_.toPairs` or `_.toPairsIn` function.
|
5465 | *
|
5466 | * @private
|
5467 | * @param {Function} keysFunc The function to get the keys of a given object.
|
5468 | * @returns {Function} Returns the new pairs function.
|
5469 | */
|
5470 | function createToPairs(keysFunc) {
|
5471 | return function(object) {
|
5472 | var tag = getTag(object);
|
5473 | if (tag == mapTag) {
|
5474 | return mapToArray(object);
|
5475 | }
|
5476 | if (tag == setTag) {
|
5477 | return setToPairs(object);
|
5478 | }
|
5479 | return baseToPairs(object, keysFunc(object));
|
5480 | };
|
5481 | }
|
5482 |
|
5483 | /**
|
5484 | * Creates a function that either curries or invokes `func` with optional
|
5485 | * `this` binding and partially applied arguments.
|
5486 | *
|
5487 | * @private
|
5488 | * @param {Function|string} func The function or method name to wrap.
|
5489 | * @param {number} bitmask The bitmask flags.
|
5490 | * 1 - `_.bind`
|
5491 | * 2 - `_.bindKey`
|
5492 | * 4 - `_.curry` or `_.curryRight` of a bound function
|
5493 | * 8 - `_.curry`
|
5494 | * 16 - `_.curryRight`
|
5495 | * 32 - `_.partial`
|
5496 | * 64 - `_.partialRight`
|
5497 | * 128 - `_.rearg`
|
5498 | * 256 - `_.ary`
|
5499 | * 512 - `_.flip`
|
5500 | * @param {*} [thisArg] The `this` binding of `func`.
|
5501 | * @param {Array} [partials] The arguments to be partially applied.
|
5502 | * @param {Array} [holders] The `partials` placeholder indexes.
|
5503 | * @param {Array} [argPos] The argument positions of the new function.
|
5504 | * @param {number} [ary] The arity cap of `func`.
|
5505 | * @param {number} [arity] The arity of `func`.
|
5506 | * @returns {Function} Returns the new wrapped function.
|
5507 | */
|
5508 | function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
|
5509 | var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
|
5510 | if (!isBindKey && typeof func != 'function') {
|
5511 | throw new TypeError(FUNC_ERROR_TEXT);
|
5512 | }
|
5513 | var length = partials ? partials.length : 0;
|
5514 | if (!length) {
|
5515 | bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
|
5516 | partials = holders = undefined;
|
5517 | }
|
5518 | ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
|
5519 | arity = arity === undefined ? arity : toInteger(arity);
|
5520 | length -= holders ? holders.length : 0;
|
5521 |
|
5522 | if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
|
5523 | var partialsRight = partials,
|
5524 | holdersRight = holders;
|
5525 |
|
5526 | partials = holders = undefined;
|
5527 | }
|
5528 | var data = isBindKey ? undefined : getData(func);
|
5529 |
|
5530 | var newData = [
|
5531 | func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
|
5532 | argPos, ary, arity
|
5533 | ];
|
5534 |
|
5535 | if (data) {
|
5536 | mergeData(newData, data);
|
5537 | }
|
5538 | func = newData[0];
|
5539 | bitmask = newData[1];
|
5540 | thisArg = newData[2];
|
5541 | partials = newData[3];
|
5542 | holders = newData[4];
|
5543 | arity = newData[9] = newData[9] === undefined
|
5544 | ? (isBindKey ? 0 : func.length)
|
5545 | : nativeMax(newData[9] - length, 0);
|
5546 |
|
5547 | if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
|
5548 | bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
|
5549 | }
|
5550 | if (!bitmask || bitmask == WRAP_BIND_FLAG) {
|
5551 | var result = createBind(func, bitmask, thisArg);
|
5552 | } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
|
5553 | result = createCurry(func, bitmask, arity);
|
5554 | } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
|
5555 | result = createPartial(func, bitmask, thisArg, partials);
|
5556 | } else {
|
5557 | result = createHybrid.apply(undefined, newData);
|
5558 | }
|
5559 | var setter = data ? baseSetData : setData;
|
5560 | return setWrapToString(setter(result, newData), func, bitmask);
|
5561 | }
|
5562 |
|
5563 | /**
|
5564 | * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
|
5565 | * of source objects to the destination object for all destination properties
|
5566 | * that resolve to `undefined`.
|
5567 | *
|
5568 | * @private
|
5569 | * @param {*} objValue The destination value.
|
5570 | * @param {*} srcValue The source value.
|
5571 | * @param {string} key The key of the property to assign.
|
5572 | * @param {Object} object The parent object of `objValue`.
|
5573 | * @returns {*} Returns the value to assign.
|
5574 | */
|
5575 | function customDefaultsAssignIn(objValue, srcValue, key, object) {
|
5576 | if (objValue === undefined ||
|
5577 | (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
5578 | return srcValue;
|
5579 | }
|
5580 | return objValue;
|
5581 | }
|
5582 |
|
5583 | /**
|
5584 | * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
|
5585 | * objects into destination objects that are passed thru.
|
5586 | *
|
5587 | * @private
|
5588 | * @param {*} objValue The destination value.
|
5589 | * @param {*} srcValue The source value.
|
5590 | * @param {string} key The key of the property to merge.
|
5591 | * @param {Object} object The parent object of `objValue`.
|
5592 | * @param {Object} source The parent object of `srcValue`.
|
5593 | * @param {Object} [stack] Tracks traversed source values and their merged
|
5594 | * counterparts.
|
5595 | * @returns {*} Returns the value to assign.
|
5596 | */
|
5597 | function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
|
5598 | if (isObject(objValue) && isObject(srcValue)) {
|
5599 | // Recursively merge objects and arrays (susceptible to call stack limits).
|
5600 | stack.set(srcValue, objValue);
|
5601 | baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
|
5602 | stack['delete'](srcValue);
|
5603 | }
|
5604 | return objValue;
|
5605 | }
|
5606 |
|
5607 | /**
|
5608 | * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
|
5609 | * objects.
|
5610 | *
|
5611 | * @private
|
5612 | * @param {*} value The value to inspect.
|
5613 | * @param {string} key The key of the property to inspect.
|
5614 | * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
|
5615 | */
|
5616 | function customOmitClone(value) {
|
5617 | return isPlainObject(value) ? undefined : value;
|
5618 | }
|
5619 |
|
5620 | /**
|
5621 | * A specialized version of `baseIsEqualDeep` for arrays with support for
|
5622 | * partial deep comparisons.
|
5623 | *
|
5624 | * @private
|
5625 | * @param {Array} array The array to compare.
|
5626 | * @param {Array} other The other array to compare.
|
5627 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
5628 | * @param {Function} customizer The function to customize comparisons.
|
5629 | * @param {Function} equalFunc The function to determine equivalents of values.
|
5630 | * @param {Object} stack Tracks traversed `array` and `other` objects.
|
5631 | * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
|
5632 | */
|
5633 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
|
5634 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
5635 | arrLength = array.length,
|
5636 | othLength = other.length;
|
5637 |
|
5638 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
5639 | return false;
|
5640 | }
|
5641 | // Assume cyclic values are equal.
|
5642 | var stacked = stack.get(array);
|
5643 | if (stacked && stack.get(other)) {
|
5644 | return stacked == other;
|
5645 | }
|
5646 | var index = -1,
|
5647 | result = true,
|
5648 | seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
|
5649 |
|
5650 | stack.set(array, other);
|
5651 | stack.set(other, array);
|
5652 |
|
5653 | // Ignore non-index properties.
|
5654 | while (++index < arrLength) {
|
5655 | var arrValue = array[index],
|
5656 | othValue = other[index];
|
5657 |
|
5658 | if (customizer) {
|
5659 | var compared = isPartial
|
5660 | ? customizer(othValue, arrValue, index, other, array, stack)
|
5661 | : customizer(arrValue, othValue, index, array, other, stack);
|
5662 | }
|
5663 | if (compared !== undefined) {
|
5664 | if (compared) {
|
5665 | continue;
|
5666 | }
|
5667 | result = false;
|
5668 | break;
|
5669 | }
|
5670 | // Recursively compare arrays (susceptible to call stack limits).
|
5671 | if (seen) {
|
5672 | if (!arraySome(other, function(othValue, othIndex) {
|
5673 | if (!cacheHas(seen, othIndex) &&
|
5674 | (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
5675 | return seen.push(othIndex);
|
5676 | }
|
5677 | })) {
|
5678 | result = false;
|
5679 | break;
|
5680 | }
|
5681 | } else if (!(
|
5682 | arrValue === othValue ||
|
5683 | equalFunc(arrValue, othValue, bitmask, customizer, stack)
|
5684 | )) {
|
5685 | result = false;
|
5686 | break;
|
5687 | }
|
5688 | }
|
5689 | stack['delete'](array);
|
5690 | stack['delete'](other);
|
5691 | return result;
|
5692 | }
|
5693 |
|
5694 | /**
|
5695 | * A specialized version of `baseIsEqualDeep` for comparing objects of
|
5696 | * the same `toStringTag`.
|
5697 | *
|
5698 | * **Note:** This function only supports comparing values with tags of
|
5699 | * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
5700 | *
|
5701 | * @private
|
5702 | * @param {Object} object The object to compare.
|
5703 | * @param {Object} other The other object to compare.
|
5704 | * @param {string} tag The `toStringTag` of the objects to compare.
|
5705 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
5706 | * @param {Function} customizer The function to customize comparisons.
|
5707 | * @param {Function} equalFunc The function to determine equivalents of values.
|
5708 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
5709 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
5710 | */
|
5711 | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
|
5712 | switch (tag) {
|
5713 | case dataViewTag:
|
5714 | if ((object.byteLength != other.byteLength) ||
|
5715 | (object.byteOffset != other.byteOffset)) {
|
5716 | return false;
|
5717 | }
|
5718 | object = object.buffer;
|
5719 | other = other.buffer;
|
5720 |
|
5721 | case arrayBufferTag:
|
5722 | if ((object.byteLength != other.byteLength) ||
|
5723 | !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
|
5724 | return false;
|
5725 | }
|
5726 | return true;
|
5727 |
|
5728 | case boolTag:
|
5729 | case dateTag:
|
5730 | case numberTag:
|
5731 | // Coerce booleans to `1` or `0` and dates to milliseconds.
|
5732 | // Invalid dates are coerced to `NaN`.
|
5733 | return eq(+object, +other);
|
5734 |
|
5735 | case errorTag:
|
5736 | return object.name == other.name && object.message == other.message;
|
5737 |
|
5738 | case regexpTag:
|
5739 | case stringTag:
|
5740 | // Coerce regexes to strings and treat strings, primitives and objects,
|
5741 | // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
|
5742 | // for more details.
|
5743 | return object == (other + '');
|
5744 |
|
5745 | case mapTag:
|
5746 | var convert = mapToArray;
|
5747 |
|
5748 | case setTag:
|
5749 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
|
5750 | convert || (convert = setToArray);
|
5751 |
|
5752 | if (object.size != other.size && !isPartial) {
|
5753 | return false;
|
5754 | }
|
5755 | // Assume cyclic values are equal.
|
5756 | var stacked = stack.get(object);
|
5757 | if (stacked) {
|
5758 | return stacked == other;
|
5759 | }
|
5760 | bitmask |= COMPARE_UNORDERED_FLAG;
|
5761 |
|
5762 | // Recursively compare objects (susceptible to call stack limits).
|
5763 | stack.set(object, other);
|
5764 | var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
|
5765 | stack['delete'](object);
|
5766 | return result;
|
5767 |
|
5768 | case symbolTag:
|
5769 | if (symbolValueOf) {
|
5770 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
5771 | }
|
5772 | }
|
5773 | return false;
|
5774 | }
|
5775 |
|
5776 | /**
|
5777 | * A specialized version of `baseIsEqualDeep` for objects with support for
|
5778 | * partial deep comparisons.
|
5779 | *
|
5780 | * @private
|
5781 | * @param {Object} object The object to compare.
|
5782 | * @param {Object} other The other object to compare.
|
5783 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
5784 | * @param {Function} customizer The function to customize comparisons.
|
5785 | * @param {Function} equalFunc The function to determine equivalents of values.
|
5786 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
5787 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
5788 | */
|
5789 | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
|
5790 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
5791 | objProps = getAllKeys(object),
|
5792 | objLength = objProps.length,
|
5793 | othProps = getAllKeys(other),
|
5794 | othLength = othProps.length;
|
5795 |
|
5796 | if (objLength != othLength && !isPartial) {
|
5797 | return false;
|
5798 | }
|
5799 | var index = objLength;
|
5800 | while (index--) {
|
5801 | var key = objProps[index];
|
5802 | if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
|
5803 | return false;
|
5804 | }
|
5805 | }
|
5806 | // Assume cyclic values are equal.
|
5807 | var stacked = stack.get(object);
|
5808 | if (stacked && stack.get(other)) {
|
5809 | return stacked == other;
|
5810 | }
|
5811 | var result = true;
|
5812 | stack.set(object, other);
|
5813 | stack.set(other, object);
|
5814 |
|
5815 | var skipCtor = isPartial;
|
5816 | while (++index < objLength) {
|
5817 | key = objProps[index];
|
5818 | var objValue = object[key],
|
5819 | othValue = other[key];
|
5820 |
|
5821 | if (customizer) {
|
5822 | var compared = isPartial
|
5823 | ? customizer(othValue, objValue, key, other, object, stack)
|
5824 | : customizer(objValue, othValue, key, object, other, stack);
|
5825 | }
|
5826 | // Recursively compare objects (susceptible to call stack limits).
|
5827 | if (!(compared === undefined
|
5828 | ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
|
5829 | : compared
|
5830 | )) {
|
5831 | result = false;
|
5832 | break;
|
5833 | }
|
5834 | skipCtor || (skipCtor = key == 'constructor');
|
5835 | }
|
5836 | if (result && !skipCtor) {
|
5837 | var objCtor = object.constructor,
|
5838 | othCtor = other.constructor;
|
5839 |
|
5840 | // Non `Object` object instances with different constructors are not equal.
|
5841 | if (objCtor != othCtor &&
|
5842 | ('constructor' in object && 'constructor' in other) &&
|
5843 | !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
5844 | typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
5845 | result = false;
|
5846 | }
|
5847 | }
|
5848 | stack['delete'](object);
|
5849 | stack['delete'](other);
|
5850 | return result;
|
5851 | }
|
5852 |
|
5853 | /**
|
5854 | * A specialized version of `baseRest` which flattens the rest array.
|
5855 | *
|
5856 | * @private
|
5857 | * @param {Function} func The function to apply a rest parameter to.
|
5858 | * @returns {Function} Returns the new function.
|
5859 | */
|
5860 | function flatRest(func) {
|
5861 | return setToString(overRest(func, undefined, flatten), func + '');
|
5862 | }
|
5863 |
|
5864 | /**
|
5865 | * Creates an array of own enumerable property names and symbols of `object`.
|
5866 | *
|
5867 | * @private
|
5868 | * @param {Object} object The object to query.
|
5869 | * @returns {Array} Returns the array of property names and symbols.
|
5870 | */
|
5871 | function getAllKeys(object) {
|
5872 | return baseGetAllKeys(object, keys, getSymbols);
|
5873 | }
|
5874 |
|
5875 | /**
|
5876 | * Creates an array of own and inherited enumerable property names and
|
5877 | * symbols of `object`.
|
5878 | *
|
5879 | * @private
|
5880 | * @param {Object} object The object to query.
|
5881 | * @returns {Array} Returns the array of property names and symbols.
|
5882 | */
|
5883 | function getAllKeysIn(object) {
|
5884 | return baseGetAllKeys(object, keysIn, getSymbolsIn);
|
5885 | }
|
5886 |
|
5887 | /**
|
5888 | * Gets metadata for `func`.
|
5889 | *
|
5890 | * @private
|
5891 | * @param {Function} func The function to query.
|
5892 | * @returns {*} Returns the metadata for `func`.
|
5893 | */
|
5894 | var getData = !metaMap ? noop : function(func) {
|
5895 | return metaMap.get(func);
|
5896 | };
|
5897 |
|
5898 | /**
|
5899 | * Gets the name of `func`.
|
5900 | *
|
5901 | * @private
|
5902 | * @param {Function} func The function to query.
|
5903 | * @returns {string} Returns the function name.
|
5904 | */
|
5905 | function getFuncName(func) {
|
5906 | var result = (func.name + ''),
|
5907 | array = realNames[result],
|
5908 | length = hasOwnProperty.call(realNames, result) ? array.length : 0;
|
5909 |
|
5910 | while (length--) {
|
5911 | var data = array[length],
|
5912 | otherFunc = data.func;
|
5913 | if (otherFunc == null || otherFunc == func) {
|
5914 | return data.name;
|
5915 | }
|
5916 | }
|
5917 | return result;
|
5918 | }
|
5919 |
|
5920 | /**
|
5921 | * Gets the argument placeholder value for `func`.
|
5922 | *
|
5923 | * @private
|
5924 | * @param {Function} func The function to inspect.
|
5925 | * @returns {*} Returns the placeholder value.
|
5926 | */
|
5927 | function getHolder(func) {
|
5928 | var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
|
5929 | return object.placeholder;
|
5930 | }
|
5931 |
|
5932 | /**
|
5933 | * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
|
5934 | * this function returns the custom method, otherwise it returns `baseIteratee`.
|
5935 | * If arguments are provided, the chosen function is invoked with them and
|
5936 | * its result is returned.
|
5937 | *
|
5938 | * @private
|
5939 | * @param {*} [value] The value to convert to an iteratee.
|
5940 | * @param {number} [arity] The arity of the created iteratee.
|
5941 | * @returns {Function} Returns the chosen function or its result.
|
5942 | */
|
5943 | function getIteratee() {
|
5944 | var result = lodash.iteratee || iteratee;
|
5945 | result = result === iteratee ? baseIteratee : result;
|
5946 | return arguments.length ? result(arguments[0], arguments[1]) : result;
|
5947 | }
|
5948 |
|
5949 | /**
|
5950 | * Gets the data for `map`.
|
5951 | *
|
5952 | * @private
|
5953 | * @param {Object} map The map to query.
|
5954 | * @param {string} key The reference key.
|
5955 | * @returns {*} Returns the map data.
|
5956 | */
|
5957 | function getMapData(map, key) {
|
5958 | var data = map.__data__;
|
5959 | return isKeyable(key)
|
5960 | ? data[typeof key == 'string' ? 'string' : 'hash']
|
5961 | : data.map;
|
5962 | }
|
5963 |
|
5964 | /**
|
5965 | * Gets the property names, values, and compare flags of `object`.
|
5966 | *
|
5967 | * @private
|
5968 | * @param {Object} object The object to query.
|
5969 | * @returns {Array} Returns the match data of `object`.
|
5970 | */
|
5971 | function getMatchData(object) {
|
5972 | var result = keys(object),
|
5973 | length = result.length;
|
5974 |
|
5975 | while (length--) {
|
5976 | var key = result[length],
|
5977 | value = object[key];
|
5978 |
|
5979 | result[length] = [key, value, isStrictComparable(value)];
|
5980 | }
|
5981 | return result;
|
5982 | }
|
5983 |
|
5984 | /**
|
5985 | * Gets the native function at `key` of `object`.
|
5986 | *
|
5987 | * @private
|
5988 | * @param {Object} object The object to query.
|
5989 | * @param {string} key The key of the method to get.
|
5990 | * @returns {*} Returns the function if it's native, else `undefined`.
|
5991 | */
|
5992 | function getNative(object, key) {
|
5993 | var value = getValue(object, key);
|
5994 | return baseIsNative(value) ? value : undefined;
|
5995 | }
|
5996 |
|
5997 | /**
|
5998 | * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
5999 | *
|
6000 | * @private
|
6001 | * @param {*} value The value to query.
|
6002 | * @returns {string} Returns the raw `toStringTag`.
|
6003 | */
|
6004 | function getRawTag(value) {
|
6005 | var isOwn = hasOwnProperty.call(value, symToStringTag),
|
6006 | tag = value[symToStringTag];
|
6007 |
|
6008 | try {
|
6009 | value[symToStringTag] = undefined;
|
6010 | var unmasked = true;
|
6011 | } catch (e) {}
|
6012 |
|
6013 | var result = nativeObjectToString.call(value);
|
6014 | if (unmasked) {
|
6015 | if (isOwn) {
|
6016 | value[symToStringTag] = tag;
|
6017 | } else {
|
6018 | delete value[symToStringTag];
|
6019 | }
|
6020 | }
|
6021 | return result;
|
6022 | }
|
6023 |
|
6024 | /**
|
6025 | * Creates an array of the own enumerable symbols of `object`.
|
6026 | *
|
6027 | * @private
|
6028 | * @param {Object} object The object to query.
|
6029 | * @returns {Array} Returns the array of symbols.
|
6030 | */
|
6031 | var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
|
6032 | if (object == null) {
|
6033 | return [];
|
6034 | }
|
6035 | object = Object(object);
|
6036 | return arrayFilter(nativeGetSymbols(object), function(symbol) {
|
6037 | return propertyIsEnumerable.call(object, symbol);
|
6038 | });
|
6039 | };
|
6040 |
|
6041 | /**
|
6042 | * Creates an array of the own and inherited enumerable symbols of `object`.
|
6043 | *
|
6044 | * @private
|
6045 | * @param {Object} object The object to query.
|
6046 | * @returns {Array} Returns the array of symbols.
|
6047 | */
|
6048 | var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
|
6049 | var result = [];
|
6050 | while (object) {
|
6051 | arrayPush(result, getSymbols(object));
|
6052 | object = getPrototype(object);
|
6053 | }
|
6054 | return result;
|
6055 | };
|
6056 |
|
6057 | /**
|
6058 | * Gets the `toStringTag` of `value`.
|
6059 | *
|
6060 | * @private
|
6061 | * @param {*} value The value to query.
|
6062 | * @returns {string} Returns the `toStringTag`.
|
6063 | */
|
6064 | var getTag = baseGetTag;
|
6065 |
|
6066 | // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
6067 | if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
6068 | (Map && getTag(new Map) != mapTag) ||
|
6069 | (Promise && getTag(Promise.resolve()) != promiseTag) ||
|
6070 | (Set && getTag(new Set) != setTag) ||
|
6071 | (WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
6072 | getTag = function(value) {
|
6073 | var result = baseGetTag(value),
|
6074 | Ctor = result == objectTag ? value.constructor : undefined,
|
6075 | ctorString = Ctor ? toSource(Ctor) : '';
|
6076 |
|
6077 | if (ctorString) {
|
6078 | switch (ctorString) {
|
6079 | case dataViewCtorString: return dataViewTag;
|
6080 | case mapCtorString: return mapTag;
|
6081 | case promiseCtorString: return promiseTag;
|
6082 | case setCtorString: return setTag;
|
6083 | case weakMapCtorString: return weakMapTag;
|
6084 | }
|
6085 | }
|
6086 | return result;
|
6087 | };
|
6088 | }
|
6089 |
|
6090 | /**
|
6091 | * Gets the view, applying any `transforms` to the `start` and `end` positions.
|
6092 | *
|
6093 | * @private
|
6094 | * @param {number} start The start of the view.
|
6095 | * @param {number} end The end of the view.
|
6096 | * @param {Array} transforms The transformations to apply to the view.
|
6097 | * @returns {Object} Returns an object containing the `start` and `end`
|
6098 | * positions of the view.
|
6099 | */
|
6100 | function getView(start, end, transforms) {
|
6101 | var index = -1,
|
6102 | length = transforms.length;
|
6103 |
|
6104 | while (++index < length) {
|
6105 | var data = transforms[index],
|
6106 | size = data.size;
|
6107 |
|
6108 | switch (data.type) {
|
6109 | case 'drop': start += size; break;
|
6110 | case 'dropRight': end -= size; break;
|
6111 | case 'take': end = nativeMin(end, start + size); break;
|
6112 | case 'takeRight': start = nativeMax(start, end - size); break;
|
6113 | }
|
6114 | }
|
6115 | return { 'start': start, 'end': end };
|
6116 | }
|
6117 |
|
6118 | /**
|
6119 | * Extracts wrapper details from the `source` body comment.
|
6120 | *
|
6121 | * @private
|
6122 | * @param {string} source The source to inspect.
|
6123 | * @returns {Array} Returns the wrapper details.
|
6124 | */
|
6125 | function getWrapDetails(source) {
|
6126 | var match = source.match(reWrapDetails);
|
6127 | return match ? match[1].split(reSplitDetails) : [];
|
6128 | }
|
6129 |
|
6130 | /**
|
6131 | * Checks if `path` exists on `object`.
|
6132 | *
|
6133 | * @private
|
6134 | * @param {Object} object The object to query.
|
6135 | * @param {Array|string} path The path to check.
|
6136 | * @param {Function} hasFunc The function to check properties.
|
6137 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
6138 | */
|
6139 | function hasPath(object, path, hasFunc) {
|
6140 | path = castPath(path, object);
|
6141 |
|
6142 | var index = -1,
|
6143 | length = path.length,
|
6144 | result = false;
|
6145 |
|
6146 | while (++index < length) {
|
6147 | var key = toKey(path[index]);
|
6148 | if (!(result = object != null && hasFunc(object, key))) {
|
6149 | break;
|
6150 | }
|
6151 | object = object[key];
|
6152 | }
|
6153 | if (result || ++index != length) {
|
6154 | return result;
|
6155 | }
|
6156 | length = object == null ? 0 : object.length;
|
6157 | return !!length && isLength(length) && isIndex(key, length) &&
|
6158 | (isArray(object) || isArguments(object));
|
6159 | }
|
6160 |
|
6161 | /**
|
6162 | * Initializes an array clone.
|
6163 | *
|
6164 | * @private
|
6165 | * @param {Array} array The array to clone.
|
6166 | * @returns {Array} Returns the initialized clone.
|
6167 | */
|
6168 | function initCloneArray(array) {
|
6169 | var length = array.length,
|
6170 | result = new array.constructor(length);
|
6171 |
|
6172 | // Add properties assigned by `RegExp#exec`.
|
6173 | if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
|
6174 | result.index = array.index;
|
6175 | result.input = array.input;
|
6176 | }
|
6177 | return result;
|
6178 | }
|
6179 |
|
6180 | /**
|
6181 | * Initializes an object clone.
|
6182 | *
|
6183 | * @private
|
6184 | * @param {Object} object The object to clone.
|
6185 | * @returns {Object} Returns the initialized clone.
|
6186 | */
|
6187 | function initCloneObject(object) {
|
6188 | return (typeof object.constructor == 'function' && !isPrototype(object))
|
6189 | ? baseCreate(getPrototype(object))
|
6190 | : {};
|
6191 | }
|
6192 |
|
6193 | /**
|
6194 | * Initializes an object clone based on its `toStringTag`.
|
6195 | *
|
6196 | * **Note:** This function only supports cloning values with tags of
|
6197 | * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
|
6198 | *
|
6199 | * @private
|
6200 | * @param {Object} object The object to clone.
|
6201 | * @param {string} tag The `toStringTag` of the object to clone.
|
6202 | * @param {boolean} [isDeep] Specify a deep clone.
|
6203 | * @returns {Object} Returns the initialized clone.
|
6204 | */
|
6205 | function initCloneByTag(object, tag, isDeep) {
|
6206 | var Ctor = object.constructor;
|
6207 | switch (tag) {
|
6208 | case arrayBufferTag:
|
6209 | return cloneArrayBuffer(object);
|
6210 |
|
6211 | case boolTag:
|
6212 | case dateTag:
|
6213 | return new Ctor(+object);
|
6214 |
|
6215 | case dataViewTag:
|
6216 | return cloneDataView(object, isDeep);
|
6217 |
|
6218 | case float32Tag: case float64Tag:
|
6219 | case int8Tag: case int16Tag: case int32Tag:
|
6220 | case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
|
6221 | return cloneTypedArray(object, isDeep);
|
6222 |
|
6223 | case mapTag:
|
6224 | return new Ctor;
|
6225 |
|
6226 | case numberTag:
|
6227 | case stringTag:
|
6228 | return new Ctor(object);
|
6229 |
|
6230 | case regexpTag:
|
6231 | return cloneRegExp(object);
|
6232 |
|
6233 | case setTag:
|
6234 | return new Ctor;
|
6235 |
|
6236 | case symbolTag:
|
6237 | return cloneSymbol(object);
|
6238 | }
|
6239 | }
|
6240 |
|
6241 | /**
|
6242 | * Inserts wrapper `details` in a comment at the top of the `source` body.
|
6243 | *
|
6244 | * @private
|
6245 | * @param {string} source The source to modify.
|
6246 | * @returns {Array} details The details to insert.
|
6247 | * @returns {string} Returns the modified source.
|
6248 | */
|
6249 | function insertWrapDetails(source, details) {
|
6250 | var length = details.length;
|
6251 | if (!length) {
|
6252 | return source;
|
6253 | }
|
6254 | var lastIndex = length - 1;
|
6255 | details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
|
6256 | details = details.join(length > 2 ? ', ' : ' ');
|
6257 | return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
|
6258 | }
|
6259 |
|
6260 | /**
|
6261 | * Checks if `value` is a flattenable `arguments` object or array.
|
6262 | *
|
6263 | * @private
|
6264 | * @param {*} value The value to check.
|
6265 | * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
|
6266 | */
|
6267 | function isFlattenable(value) {
|
6268 | return isArray(value) || isArguments(value) ||
|
6269 | !!(spreadableSymbol && value && value[spreadableSymbol]);
|
6270 | }
|
6271 |
|
6272 | /**
|
6273 | * Checks if `value` is a valid array-like index.
|
6274 | *
|
6275 | * @private
|
6276 | * @param {*} value The value to check.
|
6277 | * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
6278 | * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
6279 | */
|
6280 | function isIndex(value, length) {
|
6281 | var type = typeof value;
|
6282 | length = length == null ? MAX_SAFE_INTEGER : length;
|
6283 |
|
6284 | return !!length &&
|
6285 | (type == 'number' ||
|
6286 | (type != 'symbol' && reIsUint.test(value))) &&
|
6287 | (value > -1 && value % 1 == 0 && value < length);
|
6288 | }
|
6289 |
|
6290 | /**
|
6291 | * Checks if the given arguments are from an iteratee call.
|
6292 | *
|
6293 | * @private
|
6294 | * @param {*} value The potential iteratee value argument.
|
6295 | * @param {*} index The potential iteratee index or key argument.
|
6296 | * @param {*} object The potential iteratee object argument.
|
6297 | * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
|
6298 | * else `false`.
|
6299 | */
|
6300 | function isIterateeCall(value, index, object) {
|
6301 | if (!isObject(object)) {
|
6302 | return false;
|
6303 | }
|
6304 | var type = typeof index;
|
6305 | if (type == 'number'
|
6306 | ? (isArrayLike(object) && isIndex(index, object.length))
|
6307 | : (type == 'string' && index in object)
|
6308 | ) {
|
6309 | return eq(object[index], value);
|
6310 | }
|
6311 | return false;
|
6312 | }
|
6313 |
|
6314 | /**
|
6315 | * Checks if `value` is a property name and not a property path.
|
6316 | *
|
6317 | * @private
|
6318 | * @param {*} value The value to check.
|
6319 | * @param {Object} [object] The object to query keys on.
|
6320 | * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
6321 | */
|
6322 | function isKey(value, object) {
|
6323 | if (isArray(value)) {
|
6324 | return false;
|
6325 | }
|
6326 | var type = typeof value;
|
6327 | if (type == 'number' || type == 'symbol' || type == 'boolean' ||
|
6328 | value == null || isSymbol(value)) {
|
6329 | return true;
|
6330 | }
|
6331 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
6332 | (object != null && value in Object(object));
|
6333 | }
|
6334 |
|
6335 | /**
|
6336 | * Checks if `value` is suitable for use as unique object key.
|
6337 | *
|
6338 | * @private
|
6339 | * @param {*} value The value to check.
|
6340 | * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
6341 | */
|
6342 | function isKeyable(value) {
|
6343 | var type = typeof value;
|
6344 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
6345 | ? (value !== '__proto__')
|
6346 | : (value === null);
|
6347 | }
|
6348 |
|
6349 | /**
|
6350 | * Checks if `func` has a lazy counterpart.
|
6351 | *
|
6352 | * @private
|
6353 | * @param {Function} func The function to check.
|
6354 | * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
|
6355 | * else `false`.
|
6356 | */
|
6357 | function isLaziable(func) {
|
6358 | var funcName = getFuncName(func),
|
6359 | other = lodash[funcName];
|
6360 |
|
6361 | if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
|
6362 | return false;
|
6363 | }
|
6364 | if (func === other) {
|
6365 | return true;
|
6366 | }
|
6367 | var data = getData(other);
|
6368 | return !!data && func === data[0];
|
6369 | }
|
6370 |
|
6371 | /**
|
6372 | * Checks if `func` has its source masked.
|
6373 | *
|
6374 | * @private
|
6375 | * @param {Function} func The function to check.
|
6376 | * @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
6377 | */
|
6378 | function isMasked(func) {
|
6379 | return !!maskSrcKey && (maskSrcKey in func);
|
6380 | }
|
6381 |
|
6382 | /**
|
6383 | * Checks if `func` is capable of being masked.
|
6384 | *
|
6385 | * @private
|
6386 | * @param {*} value The value to check.
|
6387 | * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
|
6388 | */
|
6389 | var isMaskable = coreJsData ? isFunction : stubFalse;
|
6390 |
|
6391 | /**
|
6392 | * Checks if `value` is likely a prototype object.
|
6393 | *
|
6394 | * @private
|
6395 | * @param {*} value The value to check.
|
6396 | * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
6397 | */
|
6398 | function isPrototype(value) {
|
6399 | var Ctor = value && value.constructor,
|
6400 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
6401 |
|
6402 | return value === proto;
|
6403 | }
|
6404 |
|
6405 | /**
|
6406 | * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
6407 | *
|
6408 | * @private
|
6409 | * @param {*} value The value to check.
|
6410 | * @returns {boolean} Returns `true` if `value` if suitable for strict
|
6411 | * equality comparisons, else `false`.
|
6412 | */
|
6413 | function isStrictComparable(value) {
|
6414 | return value === value && !isObject(value);
|
6415 | }
|
6416 |
|
6417 | /**
|
6418 | * A specialized version of `matchesProperty` for source values suitable
|
6419 | * for strict equality comparisons, i.e. `===`.
|
6420 | *
|
6421 | * @private
|
6422 | * @param {string} key The key of the property to get.
|
6423 | * @param {*} srcValue The value to match.
|
6424 | * @returns {Function} Returns the new spec function.
|
6425 | */
|
6426 | function matchesStrictComparable(key, srcValue) {
|
6427 | return function(object) {
|
6428 | if (object == null) {
|
6429 | return false;
|
6430 | }
|
6431 | return object[key] === srcValue &&
|
6432 | (srcValue !== undefined || (key in Object(object)));
|
6433 | };
|
6434 | }
|
6435 |
|
6436 | /**
|
6437 | * A specialized version of `_.memoize` which clears the memoized function's
|
6438 | * cache when it exceeds `MAX_MEMOIZE_SIZE`.
|
6439 | *
|
6440 | * @private
|
6441 | * @param {Function} func The function to have its output memoized.
|
6442 | * @returns {Function} Returns the new memoized function.
|
6443 | */
|
6444 | function memoizeCapped(func) {
|
6445 | var result = memoize(func, function(key) {
|
6446 | if (cache.size === MAX_MEMOIZE_SIZE) {
|
6447 | cache.clear();
|
6448 | }
|
6449 | return key;
|
6450 | });
|
6451 |
|
6452 | var cache = result.cache;
|
6453 | return result;
|
6454 | }
|
6455 |
|
6456 | /**
|
6457 | * Merges the function metadata of `source` into `data`.
|
6458 | *
|
6459 | * Merging metadata reduces the number of wrappers used to invoke a function.
|
6460 | * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
|
6461 | * may be applied regardless of execution order. Methods like `_.ary` and
|
6462 | * `_.rearg` modify function arguments, making the order in which they are
|
6463 | * executed important, preventing the merging of metadata. However, we make
|
6464 | * an exception for a safe combined case where curried functions have `_.ary`
|
6465 | * and or `_.rearg` applied.
|
6466 | *
|
6467 | * @private
|
6468 | * @param {Array} data The destination metadata.
|
6469 | * @param {Array} source The source metadata.
|
6470 | * @returns {Array} Returns `data`.
|
6471 | */
|
6472 | function mergeData(data, source) {
|
6473 | var bitmask = data[1],
|
6474 | srcBitmask = source[1],
|
6475 | newBitmask = bitmask | srcBitmask,
|
6476 | isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
|
6477 |
|
6478 | var isCombo =
|
6479 | ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
|
6480 | ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
|
6481 | ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
|
6482 |
|
6483 | // Exit early if metadata can't be merged.
|
6484 | if (!(isCommon || isCombo)) {
|
6485 | return data;
|
6486 | }
|
6487 | // Use source `thisArg` if available.
|
6488 | if (srcBitmask & WRAP_BIND_FLAG) {
|
6489 | data[2] = source[2];
|
6490 | // Set when currying a bound function.
|
6491 | newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
|
6492 | }
|
6493 | // Compose partial arguments.
|
6494 | var value = source[3];
|
6495 | if (value) {
|
6496 | var partials = data[3];
|
6497 | data[3] = partials ? composeArgs(partials, value, source[4]) : value;
|
6498 | data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
|
6499 | }
|
6500 | // Compose partial right arguments.
|
6501 | value = source[5];
|
6502 | if (value) {
|
6503 | partials = data[5];
|
6504 | data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
|
6505 | data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
|
6506 | }
|
6507 | // Use source `argPos` if available.
|
6508 | value = source[7];
|
6509 | if (value) {
|
6510 | data[7] = value;
|
6511 | }
|
6512 | // Use source `ary` if it's smaller.
|
6513 | if (srcBitmask & WRAP_ARY_FLAG) {
|
6514 | data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
|
6515 | }
|
6516 | // Use source `arity` if one is not provided.
|
6517 | if (data[9] == null) {
|
6518 | data[9] = source[9];
|
6519 | }
|
6520 | // Use source `func` and merge bitmasks.
|
6521 | data[0] = source[0];
|
6522 | data[1] = newBitmask;
|
6523 |
|
6524 | return data;
|
6525 | }
|
6526 |
|
6527 | /**
|
6528 | * This function is like
|
6529 | * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
6530 | * except that it includes inherited enumerable properties.
|
6531 | *
|
6532 | * @private
|
6533 | * @param {Object} object The object to query.
|
6534 | * @returns {Array} Returns the array of property names.
|
6535 | */
|
6536 | function nativeKeysIn(object) {
|
6537 | var result = [];
|
6538 | if (object != null) {
|
6539 | for (var key in Object(object)) {
|
6540 | result.push(key);
|
6541 | }
|
6542 | }
|
6543 | return result;
|
6544 | }
|
6545 |
|
6546 | /**
|
6547 | * Converts `value` to a string using `Object.prototype.toString`.
|
6548 | *
|
6549 | * @private
|
6550 | * @param {*} value The value to convert.
|
6551 | * @returns {string} Returns the converted string.
|
6552 | */
|
6553 | function objectToString(value) {
|
6554 | return nativeObjectToString.call(value);
|
6555 | }
|
6556 |
|
6557 | /**
|
6558 | * A specialized version of `baseRest` which transforms the rest array.
|
6559 | *
|
6560 | * @private
|
6561 | * @param {Function} func The function to apply a rest parameter to.
|
6562 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
6563 | * @param {Function} transform The rest array transform.
|
6564 | * @returns {Function} Returns the new function.
|
6565 | */
|
6566 | function overRest(func, start, transform) {
|
6567 | start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
6568 | return function() {
|
6569 | var args = arguments,
|
6570 | index = -1,
|
6571 | length = nativeMax(args.length - start, 0),
|
6572 | array = Array(length);
|
6573 |
|
6574 | while (++index < length) {
|
6575 | array[index] = args[start + index];
|
6576 | }
|
6577 | index = -1;
|
6578 | var otherArgs = Array(start + 1);
|
6579 | while (++index < start) {
|
6580 | otherArgs[index] = args[index];
|
6581 | }
|
6582 | otherArgs[start] = transform(array);
|
6583 | return apply(func, this, otherArgs);
|
6584 | };
|
6585 | }
|
6586 |
|
6587 | /**
|
6588 | * Gets the parent value at `path` of `object`.
|
6589 | *
|
6590 | * @private
|
6591 | * @param {Object} object The object to query.
|
6592 | * @param {Array} path The path to get the parent value of.
|
6593 | * @returns {*} Returns the parent value.
|
6594 | */
|
6595 | function parent(object, path) {
|
6596 | return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
|
6597 | }
|
6598 |
|
6599 | /**
|
6600 | * Reorder `array` according to the specified indexes where the element at
|
6601 | * the first index is assigned as the first element, the element at
|
6602 | * the second index is assigned as the second element, and so on.
|
6603 | *
|
6604 | * @private
|
6605 | * @param {Array} array The array to reorder.
|
6606 | * @param {Array} indexes The arranged array indexes.
|
6607 | * @returns {Array} Returns `array`.
|
6608 | */
|
6609 | function reorder(array, indexes) {
|
6610 | var arrLength = array.length,
|
6611 | length = nativeMin(indexes.length, arrLength),
|
6612 | oldArray = copyArray(array);
|
6613 |
|
6614 | while (length--) {
|
6615 | var index = indexes[length];
|
6616 | array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
|
6617 | }
|
6618 | return array;
|
6619 | }
|
6620 |
|
6621 | /**
|
6622 | * Sets metadata for `func`.
|
6623 | *
|
6624 | * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
|
6625 | * period of time, it will trip its breaker and transition to an identity
|
6626 | * function to avoid garbage collection pauses in V8. See
|
6627 | * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
|
6628 | * for more details.
|
6629 | *
|
6630 | * @private
|
6631 | * @param {Function} func The function to associate metadata with.
|
6632 | * @param {*} data The metadata.
|
6633 | * @returns {Function} Returns `func`.
|
6634 | */
|
6635 | var setData = shortOut(baseSetData);
|
6636 |
|
6637 | /**
|
6638 | * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
|
6639 | *
|
6640 | * @private
|
6641 | * @param {Function} func The function to delay.
|
6642 | * @param {number} wait The number of milliseconds to delay invocation.
|
6643 | * @returns {number|Object} Returns the timer id or timeout object.
|
6644 | */
|
6645 | var setTimeout = ctxSetTimeout || function(func, wait) {
|
6646 | return root.setTimeout(func, wait);
|
6647 | };
|
6648 |
|
6649 | /**
|
6650 | * Sets the `toString` method of `func` to return `string`.
|
6651 | *
|
6652 | * @private
|
6653 | * @param {Function} func The function to modify.
|
6654 | * @param {Function} string The `toString` result.
|
6655 | * @returns {Function} Returns `func`.
|
6656 | */
|
6657 | var setToString = shortOut(baseSetToString);
|
6658 |
|
6659 | /**
|
6660 | * Sets the `toString` method of `wrapper` to mimic the source of `reference`
|
6661 | * with wrapper details in a comment at the top of the source body.
|
6662 | *
|
6663 | * @private
|
6664 | * @param {Function} wrapper The function to modify.
|
6665 | * @param {Function} reference The reference function.
|
6666 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
6667 | * @returns {Function} Returns `wrapper`.
|
6668 | */
|
6669 | function setWrapToString(wrapper, reference, bitmask) {
|
6670 | var source = (reference + '');
|
6671 | return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
|
6672 | }
|
6673 |
|
6674 | /**
|
6675 | * Creates a function that'll short out and invoke `identity` instead
|
6676 | * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
|
6677 | * milliseconds.
|
6678 | *
|
6679 | * @private
|
6680 | * @param {Function} func The function to restrict.
|
6681 | * @returns {Function} Returns the new shortable function.
|
6682 | */
|
6683 | function shortOut(func) {
|
6684 | var count = 0,
|
6685 | lastCalled = 0;
|
6686 |
|
6687 | return function() {
|
6688 | var stamp = nativeNow(),
|
6689 | remaining = HOT_SPAN - (stamp - lastCalled);
|
6690 |
|
6691 | lastCalled = stamp;
|
6692 | if (remaining > 0) {
|
6693 | if (++count >= HOT_COUNT) {
|
6694 | return arguments[0];
|
6695 | }
|
6696 | } else {
|
6697 | count = 0;
|
6698 | }
|
6699 | return func.apply(undefined, arguments);
|
6700 | };
|
6701 | }
|
6702 |
|
6703 | /**
|
6704 | * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
|
6705 | *
|
6706 | * @private
|
6707 | * @param {Array} array The array to shuffle.
|
6708 | * @param {number} [size=array.length] The size of `array`.
|
6709 | * @returns {Array} Returns `array`.
|
6710 | */
|
6711 | function shuffleSelf(array, size) {
|
6712 | var index = -1,
|
6713 | length = array.length,
|
6714 | lastIndex = length - 1;
|
6715 |
|
6716 | size = size === undefined ? length : size;
|
6717 | while (++index < size) {
|
6718 | var rand = baseRandom(index, lastIndex),
|
6719 | value = array[rand];
|
6720 |
|
6721 | array[rand] = array[index];
|
6722 | array[index] = value;
|
6723 | }
|
6724 | array.length = size;
|
6725 | return array;
|
6726 | }
|
6727 |
|
6728 | /**
|
6729 | * Converts `string` to a property path array.
|
6730 | *
|
6731 | * @private
|
6732 | * @param {string} string The string to convert.
|
6733 | * @returns {Array} Returns the property path array.
|
6734 | */
|
6735 | var stringToPath = memoizeCapped(function(string) {
|
6736 | var result = [];
|
6737 | if (string.charCodeAt(0) === 46 /* . */) {
|
6738 | result.push('');
|
6739 | }
|
6740 | string.replace(rePropName, function(match, number, quote, subString) {
|
6741 | result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
|
6742 | });
|
6743 | return result;
|
6744 | });
|
6745 |
|
6746 | /**
|
6747 | * Converts `value` to a string key if it's not a string or symbol.
|
6748 | *
|
6749 | * @private
|
6750 | * @param {*} value The value to inspect.
|
6751 | * @returns {string|symbol} Returns the key.
|
6752 | */
|
6753 | function toKey(value) {
|
6754 | if (typeof value == 'string' || isSymbol(value)) {
|
6755 | return value;
|
6756 | }
|
6757 | var result = (value + '');
|
6758 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
6759 | }
|
6760 |
|
6761 | /**
|
6762 | * Converts `func` to its source code.
|
6763 | *
|
6764 | * @private
|
6765 | * @param {Function} func The function to convert.
|
6766 | * @returns {string} Returns the source code.
|
6767 | */
|
6768 | function toSource(func) {
|
6769 | if (func != null) {
|
6770 | try {
|
6771 | return funcToString.call(func);
|
6772 | } catch (e) {}
|
6773 | try {
|
6774 | return (func + '');
|
6775 | } catch (e) {}
|
6776 | }
|
6777 | return '';
|
6778 | }
|
6779 |
|
6780 | /**
|
6781 | * Updates wrapper `details` based on `bitmask` flags.
|
6782 | *
|
6783 | * @private
|
6784 | * @returns {Array} details The details to modify.
|
6785 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
6786 | * @returns {Array} Returns `details`.
|
6787 | */
|
6788 | function updateWrapDetails(details, bitmask) {
|
6789 | arrayEach(wrapFlags, function(pair) {
|
6790 | var value = '_.' + pair[0];
|
6791 | if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
|
6792 | details.push(value);
|
6793 | }
|
6794 | });
|
6795 | return details.sort();
|
6796 | }
|
6797 |
|
6798 | /**
|
6799 | * Creates a clone of `wrapper`.
|
6800 | *
|
6801 | * @private
|
6802 | * @param {Object} wrapper The wrapper to clone.
|
6803 | * @returns {Object} Returns the cloned wrapper.
|
6804 | */
|
6805 | function wrapperClone(wrapper) {
|
6806 | if (wrapper instanceof LazyWrapper) {
|
6807 | return wrapper.clone();
|
6808 | }
|
6809 | var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
|
6810 | result.__actions__ = copyArray(wrapper.__actions__);
|
6811 | result.__index__ = wrapper.__index__;
|
6812 | result.__values__ = wrapper.__values__;
|
6813 | return result;
|
6814 | }
|
6815 |
|
6816 | /*------------------------------------------------------------------------*/
|
6817 |
|
6818 | /**
|
6819 | * Creates an array of elements split into groups the length of `size`.
|
6820 | * If `array` can't be split evenly, the final chunk will be the remaining
|
6821 | * elements.
|
6822 | *
|
6823 | * @static
|
6824 | * @memberOf _
|
6825 | * @since 3.0.0
|
6826 | * @category Array
|
6827 | * @param {Array} array The array to process.
|
6828 | * @param {number} [size=1] The length of each chunk
|
6829 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
6830 | * @returns {Array} Returns the new array of chunks.
|
6831 | * @example
|
6832 | *
|
6833 | * _.chunk(['a', 'b', 'c', 'd'], 2);
|
6834 | * // => [['a', 'b'], ['c', 'd']]
|
6835 | *
|
6836 | * _.chunk(['a', 'b', 'c', 'd'], 3);
|
6837 | * // => [['a', 'b', 'c'], ['d']]
|
6838 | */
|
6839 | function chunk(array, size, guard) {
|
6840 | if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
|
6841 | size = 1;
|
6842 | } else {
|
6843 | size = nativeMax(toInteger(size), 0);
|
6844 | }
|
6845 | var length = array == null ? 0 : array.length;
|
6846 | if (!length || size < 1) {
|
6847 | return [];
|
6848 | }
|
6849 | var index = 0,
|
6850 | resIndex = 0,
|
6851 | result = Array(nativeCeil(length / size));
|
6852 |
|
6853 | while (index < length) {
|
6854 | result[resIndex++] = baseSlice(array, index, (index += size));
|
6855 | }
|
6856 | return result;
|
6857 | }
|
6858 |
|
6859 | /**
|
6860 | * Creates an array with all falsey values removed. The values `false`, `null`,
|
6861 | * `0`, `""`, `undefined`, and `NaN` are falsey.
|
6862 | *
|
6863 | * @static
|
6864 | * @memberOf _
|
6865 | * @since 0.1.0
|
6866 | * @category Array
|
6867 | * @param {Array} array The array to compact.
|
6868 | * @returns {Array} Returns the new array of filtered values.
|
6869 | * @example
|
6870 | *
|
6871 | * _.compact([0, 1, false, 2, '', 3]);
|
6872 | * // => [1, 2, 3]
|
6873 | */
|
6874 | function compact(array) {
|
6875 | var index = -1,
|
6876 | length = array == null ? 0 : array.length,
|
6877 | resIndex = 0,
|
6878 | result = [];
|
6879 |
|
6880 | while (++index < length) {
|
6881 | var value = array[index];
|
6882 | if (value) {
|
6883 | result[resIndex++] = value;
|
6884 | }
|
6885 | }
|
6886 | return result;
|
6887 | }
|
6888 |
|
6889 | /**
|
6890 | * Creates a new array concatenating `array` with any additional arrays
|
6891 | * and/or values.
|
6892 | *
|
6893 | * @static
|
6894 | * @memberOf _
|
6895 | * @since 4.0.0
|
6896 | * @category Array
|
6897 | * @param {Array} array The array to concatenate.
|
6898 | * @param {...*} [values] The values to concatenate.
|
6899 | * @returns {Array} Returns the new concatenated array.
|
6900 | * @example
|
6901 | *
|
6902 | * var array = [1];
|
6903 | * var other = _.concat(array, 2, [3], [[4]]);
|
6904 | *
|
6905 | * console.log(other);
|
6906 | * // => [1, 2, 3, [4]]
|
6907 | *
|
6908 | * console.log(array);
|
6909 | * // => [1]
|
6910 | */
|
6911 | function concat() {
|
6912 | var length = arguments.length;
|
6913 | if (!length) {
|
6914 | return [];
|
6915 | }
|
6916 | var args = Array(length - 1),
|
6917 | array = arguments[0],
|
6918 | index = length;
|
6919 |
|
6920 | while (index--) {
|
6921 | args[index - 1] = arguments[index];
|
6922 | }
|
6923 | return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
|
6924 | }
|
6925 |
|
6926 | /**
|
6927 | * Creates an array of `array` values not included in the other given arrays
|
6928 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
6929 | * for equality comparisons. The order and references of result values are
|
6930 | * determined by the first array.
|
6931 | *
|
6932 | * **Note:** Unlike `_.pullAll`, this method returns a new array.
|
6933 | *
|
6934 | * @static
|
6935 | * @memberOf _
|
6936 | * @since 0.1.0
|
6937 | * @category Array
|
6938 | * @param {Array} array The array to inspect.
|
6939 | * @param {...Array} [values] The values to exclude.
|
6940 | * @returns {Array} Returns the new array of filtered values.
|
6941 | * @see _.without, _.xor
|
6942 | * @example
|
6943 | *
|
6944 | * _.difference([2, 1], [2, 3]);
|
6945 | * // => [1]
|
6946 | */
|
6947 | var difference = baseRest(function(array, values) {
|
6948 | return isArrayLikeObject(array)
|
6949 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
|
6950 | : [];
|
6951 | });
|
6952 |
|
6953 | /**
|
6954 | * This method is like `_.difference` except that it accepts `iteratee` which
|
6955 | * is invoked for each element of `array` and `values` to generate the criterion
|
6956 | * by which they're compared. The order and references of result values are
|
6957 | * determined by the first array. The iteratee is invoked with one argument:
|
6958 | * (value).
|
6959 | *
|
6960 | * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
|
6961 | *
|
6962 | * @static
|
6963 | * @memberOf _
|
6964 | * @since 4.0.0
|
6965 | * @category Array
|
6966 | * @param {Array} array The array to inspect.
|
6967 | * @param {...Array} [values] The values to exclude.
|
6968 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
6969 | * @returns {Array} Returns the new array of filtered values.
|
6970 | * @example
|
6971 | *
|
6972 | * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
6973 | * // => [1.2]
|
6974 | *
|
6975 | * // The `_.property` iteratee shorthand.
|
6976 | * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
|
6977 | * // => [{ 'x': 2 }]
|
6978 | */
|
6979 | var differenceBy = baseRest(function(array, values) {
|
6980 | var iteratee = last(values);
|
6981 | if (isArrayLikeObject(iteratee)) {
|
6982 | iteratee = undefined;
|
6983 | }
|
6984 | return isArrayLikeObject(array)
|
6985 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
|
6986 | : [];
|
6987 | });
|
6988 |
|
6989 | /**
|
6990 | * This method is like `_.difference` except that it accepts `comparator`
|
6991 | * which is invoked to compare elements of `array` to `values`. The order and
|
6992 | * references of result values are determined by the first array. The comparator
|
6993 | * is invoked with two arguments: (arrVal, othVal).
|
6994 | *
|
6995 | * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
|
6996 | *
|
6997 | * @static
|
6998 | * @memberOf _
|
6999 | * @since 4.0.0
|
7000 | * @category Array
|
7001 | * @param {Array} array The array to inspect.
|
7002 | * @param {...Array} [values] The values to exclude.
|
7003 | * @param {Function} [comparator] The comparator invoked per element.
|
7004 | * @returns {Array} Returns the new array of filtered values.
|
7005 | * @example
|
7006 | *
|
7007 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
7008 | *
|
7009 | * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
|
7010 | * // => [{ 'x': 2, 'y': 1 }]
|
7011 | */
|
7012 | var differenceWith = baseRest(function(array, values) {
|
7013 | var comparator = last(values);
|
7014 | if (isArrayLikeObject(comparator)) {
|
7015 | comparator = undefined;
|
7016 | }
|
7017 | return isArrayLikeObject(array)
|
7018 | ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
|
7019 | : [];
|
7020 | });
|
7021 |
|
7022 | /**
|
7023 | * Creates a slice of `array` with `n` elements dropped from the beginning.
|
7024 | *
|
7025 | * @static
|
7026 | * @memberOf _
|
7027 | * @since 0.5.0
|
7028 | * @category Array
|
7029 | * @param {Array} array The array to query.
|
7030 | * @param {number} [n=1] The number of elements to drop.
|
7031 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
7032 | * @returns {Array} Returns the slice of `array`.
|
7033 | * @example
|
7034 | *
|
7035 | * _.drop([1, 2, 3]);
|
7036 | * // => [2, 3]
|
7037 | *
|
7038 | * _.drop([1, 2, 3], 2);
|
7039 | * // => [3]
|
7040 | *
|
7041 | * _.drop([1, 2, 3], 5);
|
7042 | * // => []
|
7043 | *
|
7044 | * _.drop([1, 2, 3], 0);
|
7045 | * // => [1, 2, 3]
|
7046 | */
|
7047 | function drop(array, n, guard) {
|
7048 | var length = array == null ? 0 : array.length;
|
7049 | if (!length) {
|
7050 | return [];
|
7051 | }
|
7052 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
7053 | return baseSlice(array, n < 0 ? 0 : n, length);
|
7054 | }
|
7055 |
|
7056 | /**
|
7057 | * Creates a slice of `array` with `n` elements dropped from the end.
|
7058 | *
|
7059 | * @static
|
7060 | * @memberOf _
|
7061 | * @since 3.0.0
|
7062 | * @category Array
|
7063 | * @param {Array} array The array to query.
|
7064 | * @param {number} [n=1] The number of elements to drop.
|
7065 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
7066 | * @returns {Array} Returns the slice of `array`.
|
7067 | * @example
|
7068 | *
|
7069 | * _.dropRight([1, 2, 3]);
|
7070 | * // => [1, 2]
|
7071 | *
|
7072 | * _.dropRight([1, 2, 3], 2);
|
7073 | * // => [1]
|
7074 | *
|
7075 | * _.dropRight([1, 2, 3], 5);
|
7076 | * // => []
|
7077 | *
|
7078 | * _.dropRight([1, 2, 3], 0);
|
7079 | * // => [1, 2, 3]
|
7080 | */
|
7081 | function dropRight(array, n, guard) {
|
7082 | var length = array == null ? 0 : array.length;
|
7083 | if (!length) {
|
7084 | return [];
|
7085 | }
|
7086 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
7087 | n = length - n;
|
7088 | return baseSlice(array, 0, n < 0 ? 0 : n);
|
7089 | }
|
7090 |
|
7091 | /**
|
7092 | * Creates a slice of `array` excluding elements dropped from the end.
|
7093 | * Elements are dropped until `predicate` returns falsey. The predicate is
|
7094 | * invoked with three arguments: (value, index, array).
|
7095 | *
|
7096 | * @static
|
7097 | * @memberOf _
|
7098 | * @since 3.0.0
|
7099 | * @category Array
|
7100 | * @param {Array} array The array to query.
|
7101 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
7102 | * @returns {Array} Returns the slice of `array`.
|
7103 | * @example
|
7104 | *
|
7105 | * var users = [
|
7106 | * { 'user': 'barney', 'active': true },
|
7107 | * { 'user': 'fred', 'active': false },
|
7108 | * { 'user': 'pebbles', 'active': false }
|
7109 | * ];
|
7110 | *
|
7111 | * _.dropRightWhile(users, function(o) { return !o.active; });
|
7112 | * // => objects for ['barney']
|
7113 | *
|
7114 | * // The `_.matches` iteratee shorthand.
|
7115 | * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
|
7116 | * // => objects for ['barney', 'fred']
|
7117 | *
|
7118 | * // The `_.matchesProperty` iteratee shorthand.
|
7119 | * _.dropRightWhile(users, ['active', false]);
|
7120 | * // => objects for ['barney']
|
7121 | *
|
7122 | * // The `_.property` iteratee shorthand.
|
7123 | * _.dropRightWhile(users, 'active');
|
7124 | * // => objects for ['barney', 'fred', 'pebbles']
|
7125 | */
|
7126 | function dropRightWhile(array, predicate) {
|
7127 | return (array && array.length)
|
7128 | ? baseWhile(array, getIteratee(predicate, 3), true, true)
|
7129 | : [];
|
7130 | }
|
7131 |
|
7132 | /**
|
7133 | * Creates a slice of `array` excluding elements dropped from the beginning.
|
7134 | * Elements are dropped until `predicate` returns falsey. The predicate is
|
7135 | * invoked with three arguments: (value, index, array).
|
7136 | *
|
7137 | * @static
|
7138 | * @memberOf _
|
7139 | * @since 3.0.0
|
7140 | * @category Array
|
7141 | * @param {Array} array The array to query.
|
7142 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
7143 | * @returns {Array} Returns the slice of `array`.
|
7144 | * @example
|
7145 | *
|
7146 | * var users = [
|
7147 | * { 'user': 'barney', 'active': false },
|
7148 | * { 'user': 'fred', 'active': false },
|
7149 | * { 'user': 'pebbles', 'active': true }
|
7150 | * ];
|
7151 | *
|
7152 | * _.dropWhile(users, function(o) { return !o.active; });
|
7153 | * // => objects for ['pebbles']
|
7154 | *
|
7155 | * // The `_.matches` iteratee shorthand.
|
7156 | * _.dropWhile(users, { 'user': 'barney', 'active': false });
|
7157 | * // => objects for ['fred', 'pebbles']
|
7158 | *
|
7159 | * // The `_.matchesProperty` iteratee shorthand.
|
7160 | * _.dropWhile(users, ['active', false]);
|
7161 | * // => objects for ['pebbles']
|
7162 | *
|
7163 | * // The `_.property` iteratee shorthand.
|
7164 | * _.dropWhile(users, 'active');
|
7165 | * // => objects for ['barney', 'fred', 'pebbles']
|
7166 | */
|
7167 | function dropWhile(array, predicate) {
|
7168 | return (array && array.length)
|
7169 | ? baseWhile(array, getIteratee(predicate, 3), true)
|
7170 | : [];
|
7171 | }
|
7172 |
|
7173 | /**
|
7174 | * Fills elements of `array` with `value` from `start` up to, but not
|
7175 | * including, `end`.
|
7176 | *
|
7177 | * **Note:** This method mutates `array`.
|
7178 | *
|
7179 | * @static
|
7180 | * @memberOf _
|
7181 | * @since 3.2.0
|
7182 | * @category Array
|
7183 | * @param {Array} array The array to fill.
|
7184 | * @param {*} value The value to fill `array` with.
|
7185 | * @param {number} [start=0] The start position.
|
7186 | * @param {number} [end=array.length] The end position.
|
7187 | * @returns {Array} Returns `array`.
|
7188 | * @example
|
7189 | *
|
7190 | * var array = [1, 2, 3];
|
7191 | *
|
7192 | * _.fill(array, 'a');
|
7193 | * console.log(array);
|
7194 | * // => ['a', 'a', 'a']
|
7195 | *
|
7196 | * _.fill(Array(3), 2);
|
7197 | * // => [2, 2, 2]
|
7198 | *
|
7199 | * _.fill([4, 6, 8, 10], '*', 1, 3);
|
7200 | * // => [4, '*', '*', 10]
|
7201 | */
|
7202 | function fill(array, value, start, end) {
|
7203 | var length = array == null ? 0 : array.length;
|
7204 | if (!length) {
|
7205 | return [];
|
7206 | }
|
7207 | if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
|
7208 | start = 0;
|
7209 | end = length;
|
7210 | }
|
7211 | return baseFill(array, value, start, end);
|
7212 | }
|
7213 |
|
7214 | /**
|
7215 | * This method is like `_.find` except that it returns the index of the first
|
7216 | * element `predicate` returns truthy for instead of the element itself.
|
7217 | *
|
7218 | * @static
|
7219 | * @memberOf _
|
7220 | * @since 1.1.0
|
7221 | * @category Array
|
7222 | * @param {Array} array The array to inspect.
|
7223 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
7224 | * @param {number} [fromIndex=0] The index to search from.
|
7225 | * @returns {number} Returns the index of the found element, else `-1`.
|
7226 | * @example
|
7227 | *
|
7228 | * var users = [
|
7229 | * { 'user': 'barney', 'active': false },
|
7230 | * { 'user': 'fred', 'active': false },
|
7231 | * { 'user': 'pebbles', 'active': true }
|
7232 | * ];
|
7233 | *
|
7234 | * _.findIndex(users, function(o) { return o.user == 'barney'; });
|
7235 | * // => 0
|
7236 | *
|
7237 | * // The `_.matches` iteratee shorthand.
|
7238 | * _.findIndex(users, { 'user': 'fred', 'active': false });
|
7239 | * // => 1
|
7240 | *
|
7241 | * // The `_.matchesProperty` iteratee shorthand.
|
7242 | * _.findIndex(users, ['active', false]);
|
7243 | * // => 0
|
7244 | *
|
7245 | * // The `_.property` iteratee shorthand.
|
7246 | * _.findIndex(users, 'active');
|
7247 | * // => 2
|
7248 | */
|
7249 | function findIndex(array, predicate, fromIndex) {
|
7250 | var length = array == null ? 0 : array.length;
|
7251 | if (!length) {
|
7252 | return -1;
|
7253 | }
|
7254 | var index = fromIndex == null ? 0 : toInteger(fromIndex);
|
7255 | if (index < 0) {
|
7256 | index = nativeMax(length + index, 0);
|
7257 | }
|
7258 | return baseFindIndex(array, getIteratee(predicate, 3), index);
|
7259 | }
|
7260 |
|
7261 | /**
|
7262 | * This method is like `_.findIndex` except that it iterates over elements
|
7263 | * of `collection` from right to left.
|
7264 | *
|
7265 | * @static
|
7266 | * @memberOf _
|
7267 | * @since 2.0.0
|
7268 | * @category Array
|
7269 | * @param {Array} array The array to inspect.
|
7270 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
7271 | * @param {number} [fromIndex=array.length-1] The index to search from.
|
7272 | * @returns {number} Returns the index of the found element, else `-1`.
|
7273 | * @example
|
7274 | *
|
7275 | * var users = [
|
7276 | * { 'user': 'barney', 'active': true },
|
7277 | * { 'user': 'fred', 'active': false },
|
7278 | * { 'user': 'pebbles', 'active': false }
|
7279 | * ];
|
7280 | *
|
7281 | * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
|
7282 | * // => 2
|
7283 | *
|
7284 | * // The `_.matches` iteratee shorthand.
|
7285 | * _.findLastIndex(users, { 'user': 'barney', 'active': true });
|
7286 | * // => 0
|
7287 | *
|
7288 | * // The `_.matchesProperty` iteratee shorthand.
|
7289 | * _.findLastIndex(users, ['active', false]);
|
7290 | * // => 2
|
7291 | *
|
7292 | * // The `_.property` iteratee shorthand.
|
7293 | * _.findLastIndex(users, 'active');
|
7294 | * // => 0
|
7295 | */
|
7296 | function findLastIndex(array, predicate, fromIndex) {
|
7297 | var length = array == null ? 0 : array.length;
|
7298 | if (!length) {
|
7299 | return -1;
|
7300 | }
|
7301 | var index = length - 1;
|
7302 | if (fromIndex !== undefined) {
|
7303 | index = toInteger(fromIndex);
|
7304 | index = fromIndex < 0
|
7305 | ? nativeMax(length + index, 0)
|
7306 | : nativeMin(index, length - 1);
|
7307 | }
|
7308 | return baseFindIndex(array, getIteratee(predicate, 3), index, true);
|
7309 | }
|
7310 |
|
7311 | /**
|
7312 | * Flattens `array` a single level deep.
|
7313 | *
|
7314 | * @static
|
7315 | * @memberOf _
|
7316 | * @since 0.1.0
|
7317 | * @category Array
|
7318 | * @param {Array} array The array to flatten.
|
7319 | * @returns {Array} Returns the new flattened array.
|
7320 | * @example
|
7321 | *
|
7322 | * _.flatten([1, [2, [3, [4]], 5]]);
|
7323 | * // => [1, 2, [3, [4]], 5]
|
7324 | */
|
7325 | function flatten(array) {
|
7326 | var length = array == null ? 0 : array.length;
|
7327 | return length ? baseFlatten(array, 1) : [];
|
7328 | }
|
7329 |
|
7330 | /**
|
7331 | * Recursively flattens `array`.
|
7332 | *
|
7333 | * @static
|
7334 | * @memberOf _
|
7335 | * @since 3.0.0
|
7336 | * @category Array
|
7337 | * @param {Array} array The array to flatten.
|
7338 | * @returns {Array} Returns the new flattened array.
|
7339 | * @example
|
7340 | *
|
7341 | * _.flattenDeep([1, [2, [3, [4]], 5]]);
|
7342 | * // => [1, 2, 3, 4, 5]
|
7343 | */
|
7344 | function flattenDeep(array) {
|
7345 | var length = array == null ? 0 : array.length;
|
7346 | return length ? baseFlatten(array, INFINITY) : [];
|
7347 | }
|
7348 |
|
7349 | /**
|
7350 | * Recursively flatten `array` up to `depth` times.
|
7351 | *
|
7352 | * @static
|
7353 | * @memberOf _
|
7354 | * @since 4.4.0
|
7355 | * @category Array
|
7356 | * @param {Array} array The array to flatten.
|
7357 | * @param {number} [depth=1] The maximum recursion depth.
|
7358 | * @returns {Array} Returns the new flattened array.
|
7359 | * @example
|
7360 | *
|
7361 | * var array = [1, [2, [3, [4]], 5]];
|
7362 | *
|
7363 | * _.flattenDepth(array, 1);
|
7364 | * // => [1, 2, [3, [4]], 5]
|
7365 | *
|
7366 | * _.flattenDepth(array, 2);
|
7367 | * // => [1, 2, 3, [4], 5]
|
7368 | */
|
7369 | function flattenDepth(array, depth) {
|
7370 | var length = array == null ? 0 : array.length;
|
7371 | if (!length) {
|
7372 | return [];
|
7373 | }
|
7374 | depth = depth === undefined ? 1 : toInteger(depth);
|
7375 | return baseFlatten(array, depth);
|
7376 | }
|
7377 |
|
7378 | /**
|
7379 | * The inverse of `_.toPairs`; this method returns an object composed
|
7380 | * from key-value `pairs`.
|
7381 | *
|
7382 | * @static
|
7383 | * @memberOf _
|
7384 | * @since 4.0.0
|
7385 | * @category Array
|
7386 | * @param {Array} pairs The key-value pairs.
|
7387 | * @returns {Object} Returns the new object.
|
7388 | * @example
|
7389 | *
|
7390 | * _.fromPairs([['a', 1], ['b', 2]]);
|
7391 | * // => { 'a': 1, 'b': 2 }
|
7392 | */
|
7393 | function fromPairs(pairs) {
|
7394 | var index = -1,
|
7395 | length = pairs == null ? 0 : pairs.length,
|
7396 | result = {};
|
7397 |
|
7398 | while (++index < length) {
|
7399 | var pair = pairs[index];
|
7400 | result[pair[0]] = pair[1];
|
7401 | }
|
7402 | return result;
|
7403 | }
|
7404 |
|
7405 | /**
|
7406 | * Gets the first element of `array`.
|
7407 | *
|
7408 | * @static
|
7409 | * @memberOf _
|
7410 | * @since 0.1.0
|
7411 | * @alias first
|
7412 | * @category Array
|
7413 | * @param {Array} array The array to query.
|
7414 | * @returns {*} Returns the first element of `array`.
|
7415 | * @example
|
7416 | *
|
7417 | * _.head([1, 2, 3]);
|
7418 | * // => 1
|
7419 | *
|
7420 | * _.head([]);
|
7421 | * // => undefined
|
7422 | */
|
7423 | function head(array) {
|
7424 | return (array && array.length) ? array[0] : undefined;
|
7425 | }
|
7426 |
|
7427 | /**
|
7428 | * Gets the index at which the first occurrence of `value` is found in `array`
|
7429 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
7430 | * for equality comparisons. If `fromIndex` is negative, it's used as the
|
7431 | * offset from the end of `array`.
|
7432 | *
|
7433 | * @static
|
7434 | * @memberOf _
|
7435 | * @since 0.1.0
|
7436 | * @category Array
|
7437 | * @param {Array} array The array to inspect.
|
7438 | * @param {*} value The value to search for.
|
7439 | * @param {number} [fromIndex=0] The index to search from.
|
7440 | * @returns {number} Returns the index of the matched value, else `-1`.
|
7441 | * @example
|
7442 | *
|
7443 | * _.indexOf([1, 2, 1, 2], 2);
|
7444 | * // => 1
|
7445 | *
|
7446 | * // Search from the `fromIndex`.
|
7447 | * _.indexOf([1, 2, 1, 2], 2, 2);
|
7448 | * // => 3
|
7449 | */
|
7450 | function indexOf(array, value, fromIndex) {
|
7451 | var length = array == null ? 0 : array.length;
|
7452 | if (!length) {
|
7453 | return -1;
|
7454 | }
|
7455 | var index = fromIndex == null ? 0 : toInteger(fromIndex);
|
7456 | if (index < 0) {
|
7457 | index = nativeMax(length + index, 0);
|
7458 | }
|
7459 | return baseIndexOf(array, value, index);
|
7460 | }
|
7461 |
|
7462 | /**
|
7463 | * Gets all but the last element of `array`.
|
7464 | *
|
7465 | * @static
|
7466 | * @memberOf _
|
7467 | * @since 0.1.0
|
7468 | * @category Array
|
7469 | * @param {Array} array The array to query.
|
7470 | * @returns {Array} Returns the slice of `array`.
|
7471 | * @example
|
7472 | *
|
7473 | * _.initial([1, 2, 3]);
|
7474 | * // => [1, 2]
|
7475 | */
|
7476 | function initial(array) {
|
7477 | var length = array == null ? 0 : array.length;
|
7478 | return length ? baseSlice(array, 0, -1) : [];
|
7479 | }
|
7480 |
|
7481 | /**
|
7482 | * Creates an array of unique values that are included in all given arrays
|
7483 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
7484 | * for equality comparisons. The order and references of result values are
|
7485 | * determined by the first array.
|
7486 | *
|
7487 | * @static
|
7488 | * @memberOf _
|
7489 | * @since 0.1.0
|
7490 | * @category Array
|
7491 | * @param {...Array} [arrays] The arrays to inspect.
|
7492 | * @returns {Array} Returns the new array of intersecting values.
|
7493 | * @example
|
7494 | *
|
7495 | * _.intersection([2, 1], [2, 3]);
|
7496 | * // => [2]
|
7497 | */
|
7498 | var intersection = baseRest(function(arrays) {
|
7499 | var mapped = arrayMap(arrays, castArrayLikeObject);
|
7500 | return (mapped.length && mapped[0] === arrays[0])
|
7501 | ? baseIntersection(mapped)
|
7502 | : [];
|
7503 | });
|
7504 |
|
7505 | /**
|
7506 | * This method is like `_.intersection` except that it accepts `iteratee`
|
7507 | * which is invoked for each element of each `arrays` to generate the criterion
|
7508 | * by which they're compared. The order and references of result values are
|
7509 | * determined by the first array. The iteratee is invoked with one argument:
|
7510 | * (value).
|
7511 | *
|
7512 | * @static
|
7513 | * @memberOf _
|
7514 | * @since 4.0.0
|
7515 | * @category Array
|
7516 | * @param {...Array} [arrays] The arrays to inspect.
|
7517 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
7518 | * @returns {Array} Returns the new array of intersecting values.
|
7519 | * @example
|
7520 | *
|
7521 | * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
7522 | * // => [2.1]
|
7523 | *
|
7524 | * // The `_.property` iteratee shorthand.
|
7525 | * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
7526 | * // => [{ 'x': 1 }]
|
7527 | */
|
7528 | var intersectionBy = baseRest(function(arrays) {
|
7529 | var iteratee = last(arrays),
|
7530 | mapped = arrayMap(arrays, castArrayLikeObject);
|
7531 |
|
7532 | if (iteratee === last(mapped)) {
|
7533 | iteratee = undefined;
|
7534 | } else {
|
7535 | mapped.pop();
|
7536 | }
|
7537 | return (mapped.length && mapped[0] === arrays[0])
|
7538 | ? baseIntersection(mapped, getIteratee(iteratee, 2))
|
7539 | : [];
|
7540 | });
|
7541 |
|
7542 | /**
|
7543 | * This method is like `_.intersection` except that it accepts `comparator`
|
7544 | * which is invoked to compare elements of `arrays`. The order and references
|
7545 | * of result values are determined by the first array. The comparator is
|
7546 | * invoked with two arguments: (arrVal, othVal).
|
7547 | *
|
7548 | * @static
|
7549 | * @memberOf _
|
7550 | * @since 4.0.0
|
7551 | * @category Array
|
7552 | * @param {...Array} [arrays] The arrays to inspect.
|
7553 | * @param {Function} [comparator] The comparator invoked per element.
|
7554 | * @returns {Array} Returns the new array of intersecting values.
|
7555 | * @example
|
7556 | *
|
7557 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
7558 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
7559 | *
|
7560 | * _.intersectionWith(objects, others, _.isEqual);
|
7561 | * // => [{ 'x': 1, 'y': 2 }]
|
7562 | */
|
7563 | var intersectionWith = baseRest(function(arrays) {
|
7564 | var comparator = last(arrays),
|
7565 | mapped = arrayMap(arrays, castArrayLikeObject);
|
7566 |
|
7567 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
7568 | if (comparator) {
|
7569 | mapped.pop();
|
7570 | }
|
7571 | return (mapped.length && mapped[0] === arrays[0])
|
7572 | ? baseIntersection(mapped, undefined, comparator)
|
7573 | : [];
|
7574 | });
|
7575 |
|
7576 | /**
|
7577 | * Converts all elements in `array` into a string separated by `separator`.
|
7578 | *
|
7579 | * @static
|
7580 | * @memberOf _
|
7581 | * @since 4.0.0
|
7582 | * @category Array
|
7583 | * @param {Array} array The array to convert.
|
7584 | * @param {string} [separator=','] The element separator.
|
7585 | * @returns {string} Returns the joined string.
|
7586 | * @example
|
7587 | *
|
7588 | * _.join(['a', 'b', 'c'], '~');
|
7589 | * // => 'a~b~c'
|
7590 | */
|
7591 | function join(array, separator) {
|
7592 | return array == null ? '' : nativeJoin.call(array, separator);
|
7593 | }
|
7594 |
|
7595 | /**
|
7596 | * Gets the last element of `array`.
|
7597 | *
|
7598 | * @static
|
7599 | * @memberOf _
|
7600 | * @since 0.1.0
|
7601 | * @category Array
|
7602 | * @param {Array} array The array to query.
|
7603 | * @returns {*} Returns the last element of `array`.
|
7604 | * @example
|
7605 | *
|
7606 | * _.last([1, 2, 3]);
|
7607 | * // => 3
|
7608 | */
|
7609 | function last(array) {
|
7610 | var length = array == null ? 0 : array.length;
|
7611 | return length ? array[length - 1] : undefined;
|
7612 | }
|
7613 |
|
7614 | /**
|
7615 | * This method is like `_.indexOf` except that it iterates over elements of
|
7616 | * `array` from right to left.
|
7617 | *
|
7618 | * @static
|
7619 | * @memberOf _
|
7620 | * @since 0.1.0
|
7621 | * @category Array
|
7622 | * @param {Array} array The array to inspect.
|
7623 | * @param {*} value The value to search for.
|
7624 | * @param {number} [fromIndex=array.length-1] The index to search from.
|
7625 | * @returns {number} Returns the index of the matched value, else `-1`.
|
7626 | * @example
|
7627 | *
|
7628 | * _.lastIndexOf([1, 2, 1, 2], 2);
|
7629 | * // => 3
|
7630 | *
|
7631 | * // Search from the `fromIndex`.
|
7632 | * _.lastIndexOf([1, 2, 1, 2], 2, 2);
|
7633 | * // => 1
|
7634 | */
|
7635 | function lastIndexOf(array, value, fromIndex) {
|
7636 | var length = array == null ? 0 : array.length;
|
7637 | if (!length) {
|
7638 | return -1;
|
7639 | }
|
7640 | var index = length;
|
7641 | if (fromIndex !== undefined) {
|
7642 | index = toInteger(fromIndex);
|
7643 | index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
|
7644 | }
|
7645 | return value === value
|
7646 | ? strictLastIndexOf(array, value, index)
|
7647 | : baseFindIndex(array, baseIsNaN, index, true);
|
7648 | }
|
7649 |
|
7650 | /**
|
7651 | * Gets the element at index `n` of `array`. If `n` is negative, the nth
|
7652 | * element from the end is returned.
|
7653 | *
|
7654 | * @static
|
7655 | * @memberOf _
|
7656 | * @since 4.11.0
|
7657 | * @category Array
|
7658 | * @param {Array} array The array to query.
|
7659 | * @param {number} [n=0] The index of the element to return.
|
7660 | * @returns {*} Returns the nth element of `array`.
|
7661 | * @example
|
7662 | *
|
7663 | * var array = ['a', 'b', 'c', 'd'];
|
7664 | *
|
7665 | * _.nth(array, 1);
|
7666 | * // => 'b'
|
7667 | *
|
7668 | * _.nth(array, -2);
|
7669 | * // => 'c';
|
7670 | */
|
7671 | function nth(array, n) {
|
7672 | return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
|
7673 | }
|
7674 |
|
7675 | /**
|
7676 | * Removes all given values from `array` using
|
7677 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
7678 | * for equality comparisons.
|
7679 | *
|
7680 | * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
|
7681 | * to remove elements from an array by predicate.
|
7682 | *
|
7683 | * @static
|
7684 | * @memberOf _
|
7685 | * @since 2.0.0
|
7686 | * @category Array
|
7687 | * @param {Array} array The array to modify.
|
7688 | * @param {...*} [values] The values to remove.
|
7689 | * @returns {Array} Returns `array`.
|
7690 | * @example
|
7691 | *
|
7692 | * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
|
7693 | *
|
7694 | * _.pull(array, 'a', 'c');
|
7695 | * console.log(array);
|
7696 | * // => ['b', 'b']
|
7697 | */
|
7698 | var pull = baseRest(pullAll);
|
7699 |
|
7700 | /**
|
7701 | * This method is like `_.pull` except that it accepts an array of values to remove.
|
7702 | *
|
7703 | * **Note:** Unlike `_.difference`, this method mutates `array`.
|
7704 | *
|
7705 | * @static
|
7706 | * @memberOf _
|
7707 | * @since 4.0.0
|
7708 | * @category Array
|
7709 | * @param {Array} array The array to modify.
|
7710 | * @param {Array} values The values to remove.
|
7711 | * @returns {Array} Returns `array`.
|
7712 | * @example
|
7713 | *
|
7714 | * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
|
7715 | *
|
7716 | * _.pullAll(array, ['a', 'c']);
|
7717 | * console.log(array);
|
7718 | * // => ['b', 'b']
|
7719 | */
|
7720 | function pullAll(array, values) {
|
7721 | return (array && array.length && values && values.length)
|
7722 | ? basePullAll(array, values)
|
7723 | : array;
|
7724 | }
|
7725 |
|
7726 | /**
|
7727 | * This method is like `_.pullAll` except that it accepts `iteratee` which is
|
7728 | * invoked for each element of `array` and `values` to generate the criterion
|
7729 | * by which they're compared. The iteratee is invoked with one argument: (value).
|
7730 | *
|
7731 | * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
|
7732 | *
|
7733 | * @static
|
7734 | * @memberOf _
|
7735 | * @since 4.0.0
|
7736 | * @category Array
|
7737 | * @param {Array} array The array to modify.
|
7738 | * @param {Array} values The values to remove.
|
7739 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
7740 | * @returns {Array} Returns `array`.
|
7741 | * @example
|
7742 | *
|
7743 | * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
|
7744 | *
|
7745 | * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
|
7746 | * console.log(array);
|
7747 | * // => [{ 'x': 2 }]
|
7748 | */
|
7749 | function pullAllBy(array, values, iteratee) {
|
7750 | return (array && array.length && values && values.length)
|
7751 | ? basePullAll(array, values, getIteratee(iteratee, 2))
|
7752 | : array;
|
7753 | }
|
7754 |
|
7755 | /**
|
7756 | * This method is like `_.pullAll` except that it accepts `comparator` which
|
7757 | * is invoked to compare elements of `array` to `values`. The comparator is
|
7758 | * invoked with two arguments: (arrVal, othVal).
|
7759 | *
|
7760 | * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
|
7761 | *
|
7762 | * @static
|
7763 | * @memberOf _
|
7764 | * @since 4.6.0
|
7765 | * @category Array
|
7766 | * @param {Array} array The array to modify.
|
7767 | * @param {Array} values The values to remove.
|
7768 | * @param {Function} [comparator] The comparator invoked per element.
|
7769 | * @returns {Array} Returns `array`.
|
7770 | * @example
|
7771 | *
|
7772 | * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
|
7773 | *
|
7774 | * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
|
7775 | * console.log(array);
|
7776 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
|
7777 | */
|
7778 | function pullAllWith(array, values, comparator) {
|
7779 | return (array && array.length && values && values.length)
|
7780 | ? basePullAll(array, values, undefined, comparator)
|
7781 | : array;
|
7782 | }
|
7783 |
|
7784 | /**
|
7785 | * Removes elements from `array` corresponding to `indexes` and returns an
|
7786 | * array of removed elements.
|
7787 | *
|
7788 | * **Note:** Unlike `_.at`, this method mutates `array`.
|
7789 | *
|
7790 | * @static
|
7791 | * @memberOf _
|
7792 | * @since 3.0.0
|
7793 | * @category Array
|
7794 | * @param {Array} array The array to modify.
|
7795 | * @param {...(number|number[])} [indexes] The indexes of elements to remove.
|
7796 | * @returns {Array} Returns the new array of removed elements.
|
7797 | * @example
|
7798 | *
|
7799 | * var array = ['a', 'b', 'c', 'd'];
|
7800 | * var pulled = _.pullAt(array, [1, 3]);
|
7801 | *
|
7802 | * console.log(array);
|
7803 | * // => ['a', 'c']
|
7804 | *
|
7805 | * console.log(pulled);
|
7806 | * // => ['b', 'd']
|
7807 | */
|
7808 | var pullAt = flatRest(function(array, indexes) {
|
7809 | var length = array == null ? 0 : array.length,
|
7810 | result = baseAt(array, indexes);
|
7811 |
|
7812 | basePullAt(array, arrayMap(indexes, function(index) {
|
7813 | return isIndex(index, length) ? +index : index;
|
7814 | }).sort(compareAscending));
|
7815 |
|
7816 | return result;
|
7817 | });
|
7818 |
|
7819 | /**
|
7820 | * Removes all elements from `array` that `predicate` returns truthy for
|
7821 | * and returns an array of the removed elements. The predicate is invoked
|
7822 | * with three arguments: (value, index, array).
|
7823 | *
|
7824 | * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
|
7825 | * to pull elements from an array by value.
|
7826 | *
|
7827 | * @static
|
7828 | * @memberOf _
|
7829 | * @since 2.0.0
|
7830 | * @category Array
|
7831 | * @param {Array} array The array to modify.
|
7832 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
7833 | * @returns {Array} Returns the new array of removed elements.
|
7834 | * @example
|
7835 | *
|
7836 | * var array = [1, 2, 3, 4];
|
7837 | * var evens = _.remove(array, function(n) {
|
7838 | * return n % 2 == 0;
|
7839 | * });
|
7840 | *
|
7841 | * console.log(array);
|
7842 | * // => [1, 3]
|
7843 | *
|
7844 | * console.log(evens);
|
7845 | * // => [2, 4]
|
7846 | */
|
7847 | function remove(array, predicate) {
|
7848 | var result = [];
|
7849 | if (!(array && array.length)) {
|
7850 | return result;
|
7851 | }
|
7852 | var index = -1,
|
7853 | indexes = [],
|
7854 | length = array.length;
|
7855 |
|
7856 | predicate = getIteratee(predicate, 3);
|
7857 | while (++index < length) {
|
7858 | var value = array[index];
|
7859 | if (predicate(value, index, array)) {
|
7860 | result.push(value);
|
7861 | indexes.push(index);
|
7862 | }
|
7863 | }
|
7864 | basePullAt(array, indexes);
|
7865 | return result;
|
7866 | }
|
7867 |
|
7868 | /**
|
7869 | * Reverses `array` so that the first element becomes the last, the second
|
7870 | * element becomes the second to last, and so on.
|
7871 | *
|
7872 | * **Note:** This method mutates `array` and is based on
|
7873 | * [`Array#reverse`](https://mdn.io/Array/reverse).
|
7874 | *
|
7875 | * @static
|
7876 | * @memberOf _
|
7877 | * @since 4.0.0
|
7878 | * @category Array
|
7879 | * @param {Array} array The array to modify.
|
7880 | * @returns {Array} Returns `array`.
|
7881 | * @example
|
7882 | *
|
7883 | * var array = [1, 2, 3];
|
7884 | *
|
7885 | * _.reverse(array);
|
7886 | * // => [3, 2, 1]
|
7887 | *
|
7888 | * console.log(array);
|
7889 | * // => [3, 2, 1]
|
7890 | */
|
7891 | function reverse(array) {
|
7892 | return array == null ? array : nativeReverse.call(array);
|
7893 | }
|
7894 |
|
7895 | /**
|
7896 | * Creates a slice of `array` from `start` up to, but not including, `end`.
|
7897 | *
|
7898 | * **Note:** This method is used instead of
|
7899 | * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
|
7900 | * returned.
|
7901 | *
|
7902 | * @static
|
7903 | * @memberOf _
|
7904 | * @since 3.0.0
|
7905 | * @category Array
|
7906 | * @param {Array} array The array to slice.
|
7907 | * @param {number} [start=0] The start position.
|
7908 | * @param {number} [end=array.length] The end position.
|
7909 | * @returns {Array} Returns the slice of `array`.
|
7910 | */
|
7911 | function slice(array, start, end) {
|
7912 | var length = array == null ? 0 : array.length;
|
7913 | if (!length) {
|
7914 | return [];
|
7915 | }
|
7916 | if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
|
7917 | start = 0;
|
7918 | end = length;
|
7919 | }
|
7920 | else {
|
7921 | start = start == null ? 0 : toInteger(start);
|
7922 | end = end === undefined ? length : toInteger(end);
|
7923 | }
|
7924 | return baseSlice(array, start, end);
|
7925 | }
|
7926 |
|
7927 | /**
|
7928 | * Uses a binary search to determine the lowest index at which `value`
|
7929 | * should be inserted into `array` in order to maintain its sort order.
|
7930 | *
|
7931 | * @static
|
7932 | * @memberOf _
|
7933 | * @since 0.1.0
|
7934 | * @category Array
|
7935 | * @param {Array} array The sorted array to inspect.
|
7936 | * @param {*} value The value to evaluate.
|
7937 | * @returns {number} Returns the index at which `value` should be inserted
|
7938 | * into `array`.
|
7939 | * @example
|
7940 | *
|
7941 | * _.sortedIndex([30, 50], 40);
|
7942 | * // => 1
|
7943 | */
|
7944 | function sortedIndex(array, value) {
|
7945 | return baseSortedIndex(array, value);
|
7946 | }
|
7947 |
|
7948 | /**
|
7949 | * This method is like `_.sortedIndex` except that it accepts `iteratee`
|
7950 | * which is invoked for `value` and each element of `array` to compute their
|
7951 | * sort ranking. The iteratee is invoked with one argument: (value).
|
7952 | *
|
7953 | * @static
|
7954 | * @memberOf _
|
7955 | * @since 4.0.0
|
7956 | * @category Array
|
7957 | * @param {Array} array The sorted array to inspect.
|
7958 | * @param {*} value The value to evaluate.
|
7959 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
7960 | * @returns {number} Returns the index at which `value` should be inserted
|
7961 | * into `array`.
|
7962 | * @example
|
7963 | *
|
7964 | * var objects = [{ 'x': 4 }, { 'x': 5 }];
|
7965 | *
|
7966 | * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
|
7967 | * // => 0
|
7968 | *
|
7969 | * // The `_.property` iteratee shorthand.
|
7970 | * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
|
7971 | * // => 0
|
7972 | */
|
7973 | function sortedIndexBy(array, value, iteratee) {
|
7974 | return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
|
7975 | }
|
7976 |
|
7977 | /**
|
7978 | * This method is like `_.indexOf` except that it performs a binary
|
7979 | * search on a sorted `array`.
|
7980 | *
|
7981 | * @static
|
7982 | * @memberOf _
|
7983 | * @since 4.0.0
|
7984 | * @category Array
|
7985 | * @param {Array} array The array to inspect.
|
7986 | * @param {*} value The value to search for.
|
7987 | * @returns {number} Returns the index of the matched value, else `-1`.
|
7988 | * @example
|
7989 | *
|
7990 | * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
|
7991 | * // => 1
|
7992 | */
|
7993 | function sortedIndexOf(array, value) {
|
7994 | var length = array == null ? 0 : array.length;
|
7995 | if (length) {
|
7996 | var index = baseSortedIndex(array, value);
|
7997 | if (index < length && eq(array[index], value)) {
|
7998 | return index;
|
7999 | }
|
8000 | }
|
8001 | return -1;
|
8002 | }
|
8003 |
|
8004 | /**
|
8005 | * This method is like `_.sortedIndex` except that it returns the highest
|
8006 | * index at which `value` should be inserted into `array` in order to
|
8007 | * maintain its sort order.
|
8008 | *
|
8009 | * @static
|
8010 | * @memberOf _
|
8011 | * @since 3.0.0
|
8012 | * @category Array
|
8013 | * @param {Array} array The sorted array to inspect.
|
8014 | * @param {*} value The value to evaluate.
|
8015 | * @returns {number} Returns the index at which `value` should be inserted
|
8016 | * into `array`.
|
8017 | * @example
|
8018 | *
|
8019 | * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
|
8020 | * // => 4
|
8021 | */
|
8022 | function sortedLastIndex(array, value) {
|
8023 | return baseSortedIndex(array, value, true);
|
8024 | }
|
8025 |
|
8026 | /**
|
8027 | * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
|
8028 | * which is invoked for `value` and each element of `array` to compute their
|
8029 | * sort ranking. The iteratee is invoked with one argument: (value).
|
8030 | *
|
8031 | * @static
|
8032 | * @memberOf _
|
8033 | * @since 4.0.0
|
8034 | * @category Array
|
8035 | * @param {Array} array The sorted array to inspect.
|
8036 | * @param {*} value The value to evaluate.
|
8037 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
8038 | * @returns {number} Returns the index at which `value` should be inserted
|
8039 | * into `array`.
|
8040 | * @example
|
8041 | *
|
8042 | * var objects = [{ 'x': 4 }, { 'x': 5 }];
|
8043 | *
|
8044 | * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
|
8045 | * // => 1
|
8046 | *
|
8047 | * // The `_.property` iteratee shorthand.
|
8048 | * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
|
8049 | * // => 1
|
8050 | */
|
8051 | function sortedLastIndexBy(array, value, iteratee) {
|
8052 | return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
|
8053 | }
|
8054 |
|
8055 | /**
|
8056 | * This method is like `_.lastIndexOf` except that it performs a binary
|
8057 | * search on a sorted `array`.
|
8058 | *
|
8059 | * @static
|
8060 | * @memberOf _
|
8061 | * @since 4.0.0
|
8062 | * @category Array
|
8063 | * @param {Array} array The array to inspect.
|
8064 | * @param {*} value The value to search for.
|
8065 | * @returns {number} Returns the index of the matched value, else `-1`.
|
8066 | * @example
|
8067 | *
|
8068 | * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
|
8069 | * // => 3
|
8070 | */
|
8071 | function sortedLastIndexOf(array, value) {
|
8072 | var length = array == null ? 0 : array.length;
|
8073 | if (length) {
|
8074 | var index = baseSortedIndex(array, value, true) - 1;
|
8075 | if (eq(array[index], value)) {
|
8076 | return index;
|
8077 | }
|
8078 | }
|
8079 | return -1;
|
8080 | }
|
8081 |
|
8082 | /**
|
8083 | * This method is like `_.uniq` except that it's designed and optimized
|
8084 | * for sorted arrays.
|
8085 | *
|
8086 | * @static
|
8087 | * @memberOf _
|
8088 | * @since 4.0.0
|
8089 | * @category Array
|
8090 | * @param {Array} array The array to inspect.
|
8091 | * @returns {Array} Returns the new duplicate free array.
|
8092 | * @example
|
8093 | *
|
8094 | * _.sortedUniq([1, 1, 2]);
|
8095 | * // => [1, 2]
|
8096 | */
|
8097 | function sortedUniq(array) {
|
8098 | return (array && array.length)
|
8099 | ? baseSortedUniq(array)
|
8100 | : [];
|
8101 | }
|
8102 |
|
8103 | /**
|
8104 | * This method is like `_.uniqBy` except that it's designed and optimized
|
8105 | * for sorted arrays.
|
8106 | *
|
8107 | * @static
|
8108 | * @memberOf _
|
8109 | * @since 4.0.0
|
8110 | * @category Array
|
8111 | * @param {Array} array The array to inspect.
|
8112 | * @param {Function} [iteratee] The iteratee invoked per element.
|
8113 | * @returns {Array} Returns the new duplicate free array.
|
8114 | * @example
|
8115 | *
|
8116 | * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
|
8117 | * // => [1.1, 2.3]
|
8118 | */
|
8119 | function sortedUniqBy(array, iteratee) {
|
8120 | return (array && array.length)
|
8121 | ? baseSortedUniq(array, getIteratee(iteratee, 2))
|
8122 | : [];
|
8123 | }
|
8124 |
|
8125 | /**
|
8126 | * Gets all but the first element of `array`.
|
8127 | *
|
8128 | * @static
|
8129 | * @memberOf _
|
8130 | * @since 4.0.0
|
8131 | * @category Array
|
8132 | * @param {Array} array The array to query.
|
8133 | * @returns {Array} Returns the slice of `array`.
|
8134 | * @example
|
8135 | *
|
8136 | * _.tail([1, 2, 3]);
|
8137 | * // => [2, 3]
|
8138 | */
|
8139 | function tail(array) {
|
8140 | var length = array == null ? 0 : array.length;
|
8141 | return length ? baseSlice(array, 1, length) : [];
|
8142 | }
|
8143 |
|
8144 | /**
|
8145 | * Creates a slice of `array` with `n` elements taken from the beginning.
|
8146 | *
|
8147 | * @static
|
8148 | * @memberOf _
|
8149 | * @since 0.1.0
|
8150 | * @category Array
|
8151 | * @param {Array} array The array to query.
|
8152 | * @param {number} [n=1] The number of elements to take.
|
8153 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
8154 | * @returns {Array} Returns the slice of `array`.
|
8155 | * @example
|
8156 | *
|
8157 | * _.take([1, 2, 3]);
|
8158 | * // => [1]
|
8159 | *
|
8160 | * _.take([1, 2, 3], 2);
|
8161 | * // => [1, 2]
|
8162 | *
|
8163 | * _.take([1, 2, 3], 5);
|
8164 | * // => [1, 2, 3]
|
8165 | *
|
8166 | * _.take([1, 2, 3], 0);
|
8167 | * // => []
|
8168 | */
|
8169 | function take(array, n, guard) {
|
8170 | if (!(array && array.length)) {
|
8171 | return [];
|
8172 | }
|
8173 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
8174 | return baseSlice(array, 0, n < 0 ? 0 : n);
|
8175 | }
|
8176 |
|
8177 | /**
|
8178 | * Creates a slice of `array` with `n` elements taken from the end.
|
8179 | *
|
8180 | * @static
|
8181 | * @memberOf _
|
8182 | * @since 3.0.0
|
8183 | * @category Array
|
8184 | * @param {Array} array The array to query.
|
8185 | * @param {number} [n=1] The number of elements to take.
|
8186 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
8187 | * @returns {Array} Returns the slice of `array`.
|
8188 | * @example
|
8189 | *
|
8190 | * _.takeRight([1, 2, 3]);
|
8191 | * // => [3]
|
8192 | *
|
8193 | * _.takeRight([1, 2, 3], 2);
|
8194 | * // => [2, 3]
|
8195 | *
|
8196 | * _.takeRight([1, 2, 3], 5);
|
8197 | * // => [1, 2, 3]
|
8198 | *
|
8199 | * _.takeRight([1, 2, 3], 0);
|
8200 | * // => []
|
8201 | */
|
8202 | function takeRight(array, n, guard) {
|
8203 | var length = array == null ? 0 : array.length;
|
8204 | if (!length) {
|
8205 | return [];
|
8206 | }
|
8207 | n = (guard || n === undefined) ? 1 : toInteger(n);
|
8208 | n = length - n;
|
8209 | return baseSlice(array, n < 0 ? 0 : n, length);
|
8210 | }
|
8211 |
|
8212 | /**
|
8213 | * Creates a slice of `array` with elements taken from the end. Elements are
|
8214 | * taken until `predicate` returns falsey. The predicate is invoked with
|
8215 | * three arguments: (value, index, array).
|
8216 | *
|
8217 | * @static
|
8218 | * @memberOf _
|
8219 | * @since 3.0.0
|
8220 | * @category Array
|
8221 | * @param {Array} array The array to query.
|
8222 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
8223 | * @returns {Array} Returns the slice of `array`.
|
8224 | * @example
|
8225 | *
|
8226 | * var users = [
|
8227 | * { 'user': 'barney', 'active': true },
|
8228 | * { 'user': 'fred', 'active': false },
|
8229 | * { 'user': 'pebbles', 'active': false }
|
8230 | * ];
|
8231 | *
|
8232 | * _.takeRightWhile(users, function(o) { return !o.active; });
|
8233 | * // => objects for ['fred', 'pebbles']
|
8234 | *
|
8235 | * // The `_.matches` iteratee shorthand.
|
8236 | * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
|
8237 | * // => objects for ['pebbles']
|
8238 | *
|
8239 | * // The `_.matchesProperty` iteratee shorthand.
|
8240 | * _.takeRightWhile(users, ['active', false]);
|
8241 | * // => objects for ['fred', 'pebbles']
|
8242 | *
|
8243 | * // The `_.property` iteratee shorthand.
|
8244 | * _.takeRightWhile(users, 'active');
|
8245 | * // => []
|
8246 | */
|
8247 | function takeRightWhile(array, predicate) {
|
8248 | return (array && array.length)
|
8249 | ? baseWhile(array, getIteratee(predicate, 3), false, true)
|
8250 | : [];
|
8251 | }
|
8252 |
|
8253 | /**
|
8254 | * Creates a slice of `array` with elements taken from the beginning. Elements
|
8255 | * are taken until `predicate` returns falsey. The predicate is invoked with
|
8256 | * three arguments: (value, index, array).
|
8257 | *
|
8258 | * @static
|
8259 | * @memberOf _
|
8260 | * @since 3.0.0
|
8261 | * @category Array
|
8262 | * @param {Array} array The array to query.
|
8263 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
8264 | * @returns {Array} Returns the slice of `array`.
|
8265 | * @example
|
8266 | *
|
8267 | * var users = [
|
8268 | * { 'user': 'barney', 'active': false },
|
8269 | * { 'user': 'fred', 'active': false },
|
8270 | * { 'user': 'pebbles', 'active': true }
|
8271 | * ];
|
8272 | *
|
8273 | * _.takeWhile(users, function(o) { return !o.active; });
|
8274 | * // => objects for ['barney', 'fred']
|
8275 | *
|
8276 | * // The `_.matches` iteratee shorthand.
|
8277 | * _.takeWhile(users, { 'user': 'barney', 'active': false });
|
8278 | * // => objects for ['barney']
|
8279 | *
|
8280 | * // The `_.matchesProperty` iteratee shorthand.
|
8281 | * _.takeWhile(users, ['active', false]);
|
8282 | * // => objects for ['barney', 'fred']
|
8283 | *
|
8284 | * // The `_.property` iteratee shorthand.
|
8285 | * _.takeWhile(users, 'active');
|
8286 | * // => []
|
8287 | */
|
8288 | function takeWhile(array, predicate) {
|
8289 | return (array && array.length)
|
8290 | ? baseWhile(array, getIteratee(predicate, 3))
|
8291 | : [];
|
8292 | }
|
8293 |
|
8294 | /**
|
8295 | * Creates an array of unique values, in order, from all given arrays using
|
8296 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
8297 | * for equality comparisons.
|
8298 | *
|
8299 | * @static
|
8300 | * @memberOf _
|
8301 | * @since 0.1.0
|
8302 | * @category Array
|
8303 | * @param {...Array} [arrays] The arrays to inspect.
|
8304 | * @returns {Array} Returns the new array of combined values.
|
8305 | * @example
|
8306 | *
|
8307 | * _.union([2], [1, 2]);
|
8308 | * // => [2, 1]
|
8309 | */
|
8310 | var union = baseRest(function(arrays) {
|
8311 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
|
8312 | });
|
8313 |
|
8314 | /**
|
8315 | * This method is like `_.union` except that it accepts `iteratee` which is
|
8316 | * invoked for each element of each `arrays` to generate the criterion by
|
8317 | * which uniqueness is computed. Result values are chosen from the first
|
8318 | * array in which the value occurs. The iteratee is invoked with one argument:
|
8319 | * (value).
|
8320 | *
|
8321 | * @static
|
8322 | * @memberOf _
|
8323 | * @since 4.0.0
|
8324 | * @category Array
|
8325 | * @param {...Array} [arrays] The arrays to inspect.
|
8326 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
8327 | * @returns {Array} Returns the new array of combined values.
|
8328 | * @example
|
8329 | *
|
8330 | * _.unionBy([2.1], [1.2, 2.3], Math.floor);
|
8331 | * // => [2.1, 1.2]
|
8332 | *
|
8333 | * // The `_.property` iteratee shorthand.
|
8334 | * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
8335 | * // => [{ 'x': 1 }, { 'x': 2 }]
|
8336 | */
|
8337 | var unionBy = baseRest(function(arrays) {
|
8338 | var iteratee = last(arrays);
|
8339 | if (isArrayLikeObject(iteratee)) {
|
8340 | iteratee = undefined;
|
8341 | }
|
8342 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
|
8343 | });
|
8344 |
|
8345 | /**
|
8346 | * This method is like `_.union` except that it accepts `comparator` which
|
8347 | * is invoked to compare elements of `arrays`. Result values are chosen from
|
8348 | * the first array in which the value occurs. The comparator is invoked
|
8349 | * with two arguments: (arrVal, othVal).
|
8350 | *
|
8351 | * @static
|
8352 | * @memberOf _
|
8353 | * @since 4.0.0
|
8354 | * @category Array
|
8355 | * @param {...Array} [arrays] The arrays to inspect.
|
8356 | * @param {Function} [comparator] The comparator invoked per element.
|
8357 | * @returns {Array} Returns the new array of combined values.
|
8358 | * @example
|
8359 | *
|
8360 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
8361 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
8362 | *
|
8363 | * _.unionWith(objects, others, _.isEqual);
|
8364 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
8365 | */
|
8366 | var unionWith = baseRest(function(arrays) {
|
8367 | var comparator = last(arrays);
|
8368 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
8369 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
|
8370 | });
|
8371 |
|
8372 | /**
|
8373 | * Creates a duplicate-free version of an array, using
|
8374 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
8375 | * for equality comparisons, in which only the first occurrence of each element
|
8376 | * is kept. The order of result values is determined by the order they occur
|
8377 | * in the array.
|
8378 | *
|
8379 | * @static
|
8380 | * @memberOf _
|
8381 | * @since 0.1.0
|
8382 | * @category Array
|
8383 | * @param {Array} array The array to inspect.
|
8384 | * @returns {Array} Returns the new duplicate free array.
|
8385 | * @example
|
8386 | *
|
8387 | * _.uniq([2, 1, 2]);
|
8388 | * // => [2, 1]
|
8389 | */
|
8390 | function uniq(array) {
|
8391 | return (array && array.length) ? baseUniq(array) : [];
|
8392 | }
|
8393 |
|
8394 | /**
|
8395 | * This method is like `_.uniq` except that it accepts `iteratee` which is
|
8396 | * invoked for each element in `array` to generate the criterion by which
|
8397 | * uniqueness is computed. The order of result values is determined by the
|
8398 | * order they occur in the array. The iteratee is invoked with one argument:
|
8399 | * (value).
|
8400 | *
|
8401 | * @static
|
8402 | * @memberOf _
|
8403 | * @since 4.0.0
|
8404 | * @category Array
|
8405 | * @param {Array} array The array to inspect.
|
8406 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
8407 | * @returns {Array} Returns the new duplicate free array.
|
8408 | * @example
|
8409 | *
|
8410 | * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
|
8411 | * // => [2.1, 1.2]
|
8412 | *
|
8413 | * // The `_.property` iteratee shorthand.
|
8414 | * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
8415 | * // => [{ 'x': 1 }, { 'x': 2 }]
|
8416 | */
|
8417 | function uniqBy(array, iteratee) {
|
8418 | return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
|
8419 | }
|
8420 |
|
8421 | /**
|
8422 | * This method is like `_.uniq` except that it accepts `comparator` which
|
8423 | * is invoked to compare elements of `array`. The order of result values is
|
8424 | * determined by the order they occur in the array.The comparator is invoked
|
8425 | * with two arguments: (arrVal, othVal).
|
8426 | *
|
8427 | * @static
|
8428 | * @memberOf _
|
8429 | * @since 4.0.0
|
8430 | * @category Array
|
8431 | * @param {Array} array The array to inspect.
|
8432 | * @param {Function} [comparator] The comparator invoked per element.
|
8433 | * @returns {Array} Returns the new duplicate free array.
|
8434 | * @example
|
8435 | *
|
8436 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
8437 | *
|
8438 | * _.uniqWith(objects, _.isEqual);
|
8439 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
|
8440 | */
|
8441 | function uniqWith(array, comparator) {
|
8442 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
8443 | return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
|
8444 | }
|
8445 |
|
8446 | /**
|
8447 | * This method is like `_.zip` except that it accepts an array of grouped
|
8448 | * elements and creates an array regrouping the elements to their pre-zip
|
8449 | * configuration.
|
8450 | *
|
8451 | * @static
|
8452 | * @memberOf _
|
8453 | * @since 1.2.0
|
8454 | * @category Array
|
8455 | * @param {Array} array The array of grouped elements to process.
|
8456 | * @returns {Array} Returns the new array of regrouped elements.
|
8457 | * @example
|
8458 | *
|
8459 | * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
|
8460 | * // => [['a', 1, true], ['b', 2, false]]
|
8461 | *
|
8462 | * _.unzip(zipped);
|
8463 | * // => [['a', 'b'], [1, 2], [true, false]]
|
8464 | */
|
8465 | function unzip(array) {
|
8466 | if (!(array && array.length)) {
|
8467 | return [];
|
8468 | }
|
8469 | var length = 0;
|
8470 | array = arrayFilter(array, function(group) {
|
8471 | if (isArrayLikeObject(group)) {
|
8472 | length = nativeMax(group.length, length);
|
8473 | return true;
|
8474 | }
|
8475 | });
|
8476 | return baseTimes(length, function(index) {
|
8477 | return arrayMap(array, baseProperty(index));
|
8478 | });
|
8479 | }
|
8480 |
|
8481 | /**
|
8482 | * This method is like `_.unzip` except that it accepts `iteratee` to specify
|
8483 | * how regrouped values should be combined. The iteratee is invoked with the
|
8484 | * elements of each group: (...group).
|
8485 | *
|
8486 | * @static
|
8487 | * @memberOf _
|
8488 | * @since 3.8.0
|
8489 | * @category Array
|
8490 | * @param {Array} array The array of grouped elements to process.
|
8491 | * @param {Function} [iteratee=_.identity] The function to combine
|
8492 | * regrouped values.
|
8493 | * @returns {Array} Returns the new array of regrouped elements.
|
8494 | * @example
|
8495 | *
|
8496 | * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
|
8497 | * // => [[1, 10, 100], [2, 20, 200]]
|
8498 | *
|
8499 | * _.unzipWith(zipped, _.add);
|
8500 | * // => [3, 30, 300]
|
8501 | */
|
8502 | function unzipWith(array, iteratee) {
|
8503 | if (!(array && array.length)) {
|
8504 | return [];
|
8505 | }
|
8506 | var result = unzip(array);
|
8507 | if (iteratee == null) {
|
8508 | return result;
|
8509 | }
|
8510 | return arrayMap(result, function(group) {
|
8511 | return apply(iteratee, undefined, group);
|
8512 | });
|
8513 | }
|
8514 |
|
8515 | /**
|
8516 | * Creates an array excluding all given values using
|
8517 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
8518 | * for equality comparisons.
|
8519 | *
|
8520 | * **Note:** Unlike `_.pull`, this method returns a new array.
|
8521 | *
|
8522 | * @static
|
8523 | * @memberOf _
|
8524 | * @since 0.1.0
|
8525 | * @category Array
|
8526 | * @param {Array} array The array to inspect.
|
8527 | * @param {...*} [values] The values to exclude.
|
8528 | * @returns {Array} Returns the new array of filtered values.
|
8529 | * @see _.difference, _.xor
|
8530 | * @example
|
8531 | *
|
8532 | * _.without([2, 1, 2, 3], 1, 2);
|
8533 | * // => [3]
|
8534 | */
|
8535 | var without = baseRest(function(array, values) {
|
8536 | return isArrayLikeObject(array)
|
8537 | ? baseDifference(array, values)
|
8538 | : [];
|
8539 | });
|
8540 |
|
8541 | /**
|
8542 | * Creates an array of unique values that is the
|
8543 | * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
|
8544 | * of the given arrays. The order of result values is determined by the order
|
8545 | * they occur in the arrays.
|
8546 | *
|
8547 | * @static
|
8548 | * @memberOf _
|
8549 | * @since 2.4.0
|
8550 | * @category Array
|
8551 | * @param {...Array} [arrays] The arrays to inspect.
|
8552 | * @returns {Array} Returns the new array of filtered values.
|
8553 | * @see _.difference, _.without
|
8554 | * @example
|
8555 | *
|
8556 | * _.xor([2, 1], [2, 3]);
|
8557 | * // => [1, 3]
|
8558 | */
|
8559 | var xor = baseRest(function(arrays) {
|
8560 | return baseXor(arrayFilter(arrays, isArrayLikeObject));
|
8561 | });
|
8562 |
|
8563 | /**
|
8564 | * This method is like `_.xor` except that it accepts `iteratee` which is
|
8565 | * invoked for each element of each `arrays` to generate the criterion by
|
8566 | * which by which they're compared. The order of result values is determined
|
8567 | * by the order they occur in the arrays. The iteratee is invoked with one
|
8568 | * argument: (value).
|
8569 | *
|
8570 | * @static
|
8571 | * @memberOf _
|
8572 | * @since 4.0.0
|
8573 | * @category Array
|
8574 | * @param {...Array} [arrays] The arrays to inspect.
|
8575 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
8576 | * @returns {Array} Returns the new array of filtered values.
|
8577 | * @example
|
8578 | *
|
8579 | * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
|
8580 | * // => [1.2, 3.4]
|
8581 | *
|
8582 | * // The `_.property` iteratee shorthand.
|
8583 | * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
8584 | * // => [{ 'x': 2 }]
|
8585 | */
|
8586 | var xorBy = baseRest(function(arrays) {
|
8587 | var iteratee = last(arrays);
|
8588 | if (isArrayLikeObject(iteratee)) {
|
8589 | iteratee = undefined;
|
8590 | }
|
8591 | return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
|
8592 | });
|
8593 |
|
8594 | /**
|
8595 | * This method is like `_.xor` except that it accepts `comparator` which is
|
8596 | * invoked to compare elements of `arrays`. The order of result values is
|
8597 | * determined by the order they occur in the arrays. The comparator is invoked
|
8598 | * with two arguments: (arrVal, othVal).
|
8599 | *
|
8600 | * @static
|
8601 | * @memberOf _
|
8602 | * @since 4.0.0
|
8603 | * @category Array
|
8604 | * @param {...Array} [arrays] The arrays to inspect.
|
8605 | * @param {Function} [comparator] The comparator invoked per element.
|
8606 | * @returns {Array} Returns the new array of filtered values.
|
8607 | * @example
|
8608 | *
|
8609 | * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
|
8610 | * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
|
8611 | *
|
8612 | * _.xorWith(objects, others, _.isEqual);
|
8613 | * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
|
8614 | */
|
8615 | var xorWith = baseRest(function(arrays) {
|
8616 | var comparator = last(arrays);
|
8617 | comparator = typeof comparator == 'function' ? comparator : undefined;
|
8618 | return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
|
8619 | });
|
8620 |
|
8621 | /**
|
8622 | * Creates an array of grouped elements, the first of which contains the
|
8623 | * first elements of the given arrays, the second of which contains the
|
8624 | * second elements of the given arrays, and so on.
|
8625 | *
|
8626 | * @static
|
8627 | * @memberOf _
|
8628 | * @since 0.1.0
|
8629 | * @category Array
|
8630 | * @param {...Array} [arrays] The arrays to process.
|
8631 | * @returns {Array} Returns the new array of grouped elements.
|
8632 | * @example
|
8633 | *
|
8634 | * _.zip(['a', 'b'], [1, 2], [true, false]);
|
8635 | * // => [['a', 1, true], ['b', 2, false]]
|
8636 | */
|
8637 | var zip = baseRest(unzip);
|
8638 |
|
8639 | /**
|
8640 | * This method is like `_.fromPairs` except that it accepts two arrays,
|
8641 | * one of property identifiers and one of corresponding values.
|
8642 | *
|
8643 | * @static
|
8644 | * @memberOf _
|
8645 | * @since 0.4.0
|
8646 | * @category Array
|
8647 | * @param {Array} [props=[]] The property identifiers.
|
8648 | * @param {Array} [values=[]] The property values.
|
8649 | * @returns {Object} Returns the new object.
|
8650 | * @example
|
8651 | *
|
8652 | * _.zipObject(['a', 'b'], [1, 2]);
|
8653 | * // => { 'a': 1, 'b': 2 }
|
8654 | */
|
8655 | function zipObject(props, values) {
|
8656 | return baseZipObject(props || [], values || [], assignValue);
|
8657 | }
|
8658 |
|
8659 | /**
|
8660 | * This method is like `_.zipObject` except that it supports property paths.
|
8661 | *
|
8662 | * @static
|
8663 | * @memberOf _
|
8664 | * @since 4.1.0
|
8665 | * @category Array
|
8666 | * @param {Array} [props=[]] The property identifiers.
|
8667 | * @param {Array} [values=[]] The property values.
|
8668 | * @returns {Object} Returns the new object.
|
8669 | * @example
|
8670 | *
|
8671 | * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
|
8672 | * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
|
8673 | */
|
8674 | function zipObjectDeep(props, values) {
|
8675 | return baseZipObject(props || [], values || [], baseSet);
|
8676 | }
|
8677 |
|
8678 | /**
|
8679 | * This method is like `_.zip` except that it accepts `iteratee` to specify
|
8680 | * how grouped values should be combined. The iteratee is invoked with the
|
8681 | * elements of each group: (...group).
|
8682 | *
|
8683 | * @static
|
8684 | * @memberOf _
|
8685 | * @since 3.8.0
|
8686 | * @category Array
|
8687 | * @param {...Array} [arrays] The arrays to process.
|
8688 | * @param {Function} [iteratee=_.identity] The function to combine
|
8689 | * grouped values.
|
8690 | * @returns {Array} Returns the new array of grouped elements.
|
8691 | * @example
|
8692 | *
|
8693 | * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
|
8694 | * return a + b + c;
|
8695 | * });
|
8696 | * // => [111, 222]
|
8697 | */
|
8698 | var zipWith = baseRest(function(arrays) {
|
8699 | var length = arrays.length,
|
8700 | iteratee = length > 1 ? arrays[length - 1] : undefined;
|
8701 |
|
8702 | iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
|
8703 | return unzipWith(arrays, iteratee);
|
8704 | });
|
8705 |
|
8706 | /*------------------------------------------------------------------------*/
|
8707 |
|
8708 | /**
|
8709 | * Creates a `lodash` wrapper instance that wraps `value` with explicit method
|
8710 | * chain sequences enabled. The result of such sequences must be unwrapped
|
8711 | * with `_#value`.
|
8712 | *
|
8713 | * @static
|
8714 | * @memberOf _
|
8715 | * @since 1.3.0
|
8716 | * @category Seq
|
8717 | * @param {*} value The value to wrap.
|
8718 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
8719 | * @example
|
8720 | *
|
8721 | * var users = [
|
8722 | * { 'user': 'barney', 'age': 36 },
|
8723 | * { 'user': 'fred', 'age': 40 },
|
8724 | * { 'user': 'pebbles', 'age': 1 }
|
8725 | * ];
|
8726 | *
|
8727 | * var youngest = _
|
8728 | * .chain(users)
|
8729 | * .sortBy('age')
|
8730 | * .map(function(o) {
|
8731 | * return o.user + ' is ' + o.age;
|
8732 | * })
|
8733 | * .head()
|
8734 | * .value();
|
8735 | * // => 'pebbles is 1'
|
8736 | */
|
8737 | function chain(value) {
|
8738 | var result = lodash(value);
|
8739 | result.__chain__ = true;
|
8740 | return result;
|
8741 | }
|
8742 |
|
8743 | /**
|
8744 | * This method invokes `interceptor` and returns `value`. The interceptor
|
8745 | * is invoked with one argument; (value). The purpose of this method is to
|
8746 | * "tap into" a method chain sequence in order to modify intermediate results.
|
8747 | *
|
8748 | * @static
|
8749 | * @memberOf _
|
8750 | * @since 0.1.0
|
8751 | * @category Seq
|
8752 | * @param {*} value The value to provide to `interceptor`.
|
8753 | * @param {Function} interceptor The function to invoke.
|
8754 | * @returns {*} Returns `value`.
|
8755 | * @example
|
8756 | *
|
8757 | * _([1, 2, 3])
|
8758 | * .tap(function(array) {
|
8759 | * // Mutate input array.
|
8760 | * array.pop();
|
8761 | * })
|
8762 | * .reverse()
|
8763 | * .value();
|
8764 | * // => [2, 1]
|
8765 | */
|
8766 | function tap(value, interceptor) {
|
8767 | interceptor(value);
|
8768 | return value;
|
8769 | }
|
8770 |
|
8771 | /**
|
8772 | * This method is like `_.tap` except that it returns the result of `interceptor`.
|
8773 | * The purpose of this method is to "pass thru" values replacing intermediate
|
8774 | * results in a method chain sequence.
|
8775 | *
|
8776 | * @static
|
8777 | * @memberOf _
|
8778 | * @since 3.0.0
|
8779 | * @category Seq
|
8780 | * @param {*} value The value to provide to `interceptor`.
|
8781 | * @param {Function} interceptor The function to invoke.
|
8782 | * @returns {*} Returns the result of `interceptor`.
|
8783 | * @example
|
8784 | *
|
8785 | * _(' abc ')
|
8786 | * .chain()
|
8787 | * .trim()
|
8788 | * .thru(function(value) {
|
8789 | * return [value];
|
8790 | * })
|
8791 | * .value();
|
8792 | * // => ['abc']
|
8793 | */
|
8794 | function thru(value, interceptor) {
|
8795 | return interceptor(value);
|
8796 | }
|
8797 |
|
8798 | /**
|
8799 | * This method is the wrapper version of `_.at`.
|
8800 | *
|
8801 | * @name at
|
8802 | * @memberOf _
|
8803 | * @since 1.0.0
|
8804 | * @category Seq
|
8805 | * @param {...(string|string[])} [paths] The property paths to pick.
|
8806 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
8807 | * @example
|
8808 | *
|
8809 | * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
|
8810 | *
|
8811 | * _(object).at(['a[0].b.c', 'a[1]']).value();
|
8812 | * // => [3, 4]
|
8813 | */
|
8814 | var wrapperAt = flatRest(function(paths) {
|
8815 | var length = paths.length,
|
8816 | start = length ? paths[0] : 0,
|
8817 | value = this.__wrapped__,
|
8818 | interceptor = function(object) { return baseAt(object, paths); };
|
8819 |
|
8820 | if (length > 1 || this.__actions__.length ||
|
8821 | !(value instanceof LazyWrapper) || !isIndex(start)) {
|
8822 | return this.thru(interceptor);
|
8823 | }
|
8824 | value = value.slice(start, +start + (length ? 1 : 0));
|
8825 | value.__actions__.push({
|
8826 | 'func': thru,
|
8827 | 'args': [interceptor],
|
8828 | 'thisArg': undefined
|
8829 | });
|
8830 | return new LodashWrapper(value, this.__chain__).thru(function(array) {
|
8831 | if (length && !array.length) {
|
8832 | array.push(undefined);
|
8833 | }
|
8834 | return array;
|
8835 | });
|
8836 | });
|
8837 |
|
8838 | /**
|
8839 | * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
|
8840 | *
|
8841 | * @name chain
|
8842 | * @memberOf _
|
8843 | * @since 0.1.0
|
8844 | * @category Seq
|
8845 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
8846 | * @example
|
8847 | *
|
8848 | * var users = [
|
8849 | * { 'user': 'barney', 'age': 36 },
|
8850 | * { 'user': 'fred', 'age': 40 }
|
8851 | * ];
|
8852 | *
|
8853 | * // A sequence without explicit chaining.
|
8854 | * _(users).head();
|
8855 | * // => { 'user': 'barney', 'age': 36 }
|
8856 | *
|
8857 | * // A sequence with explicit chaining.
|
8858 | * _(users)
|
8859 | * .chain()
|
8860 | * .head()
|
8861 | * .pick('user')
|
8862 | * .value();
|
8863 | * // => { 'user': 'barney' }
|
8864 | */
|
8865 | function wrapperChain() {
|
8866 | return chain(this);
|
8867 | }
|
8868 |
|
8869 | /**
|
8870 | * Executes the chain sequence and returns the wrapped result.
|
8871 | *
|
8872 | * @name commit
|
8873 | * @memberOf _
|
8874 | * @since 3.2.0
|
8875 | * @category Seq
|
8876 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
8877 | * @example
|
8878 | *
|
8879 | * var array = [1, 2];
|
8880 | * var wrapped = _(array).push(3);
|
8881 | *
|
8882 | * console.log(array);
|
8883 | * // => [1, 2]
|
8884 | *
|
8885 | * wrapped = wrapped.commit();
|
8886 | * console.log(array);
|
8887 | * // => [1, 2, 3]
|
8888 | *
|
8889 | * wrapped.last();
|
8890 | * // => 3
|
8891 | *
|
8892 | * console.log(array);
|
8893 | * // => [1, 2, 3]
|
8894 | */
|
8895 | function wrapperCommit() {
|
8896 | return new LodashWrapper(this.value(), this.__chain__);
|
8897 | }
|
8898 |
|
8899 | /**
|
8900 | * Gets the next value on a wrapped object following the
|
8901 | * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
|
8902 | *
|
8903 | * @name next
|
8904 | * @memberOf _
|
8905 | * @since 4.0.0
|
8906 | * @category Seq
|
8907 | * @returns {Object} Returns the next iterator value.
|
8908 | * @example
|
8909 | *
|
8910 | * var wrapped = _([1, 2]);
|
8911 | *
|
8912 | * wrapped.next();
|
8913 | * // => { 'done': false, 'value': 1 }
|
8914 | *
|
8915 | * wrapped.next();
|
8916 | * // => { 'done': false, 'value': 2 }
|
8917 | *
|
8918 | * wrapped.next();
|
8919 | * // => { 'done': true, 'value': undefined }
|
8920 | */
|
8921 | function wrapperNext() {
|
8922 | if (this.__values__ === undefined) {
|
8923 | this.__values__ = toArray(this.value());
|
8924 | }
|
8925 | var done = this.__index__ >= this.__values__.length,
|
8926 | value = done ? undefined : this.__values__[this.__index__++];
|
8927 |
|
8928 | return { 'done': done, 'value': value };
|
8929 | }
|
8930 |
|
8931 | /**
|
8932 | * Enables the wrapper to be iterable.
|
8933 | *
|
8934 | * @name Symbol.iterator
|
8935 | * @memberOf _
|
8936 | * @since 4.0.0
|
8937 | * @category Seq
|
8938 | * @returns {Object} Returns the wrapper object.
|
8939 | * @example
|
8940 | *
|
8941 | * var wrapped = _([1, 2]);
|
8942 | *
|
8943 | * wrapped[Symbol.iterator]() === wrapped;
|
8944 | * // => true
|
8945 | *
|
8946 | * Array.from(wrapped);
|
8947 | * // => [1, 2]
|
8948 | */
|
8949 | function wrapperToIterator() {
|
8950 | return this;
|
8951 | }
|
8952 |
|
8953 | /**
|
8954 | * Creates a clone of the chain sequence planting `value` as the wrapped value.
|
8955 | *
|
8956 | * @name plant
|
8957 | * @memberOf _
|
8958 | * @since 3.2.0
|
8959 | * @category Seq
|
8960 | * @param {*} value The value to plant.
|
8961 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
8962 | * @example
|
8963 | *
|
8964 | * function square(n) {
|
8965 | * return n * n;
|
8966 | * }
|
8967 | *
|
8968 | * var wrapped = _([1, 2]).map(square);
|
8969 | * var other = wrapped.plant([3, 4]);
|
8970 | *
|
8971 | * other.value();
|
8972 | * // => [9, 16]
|
8973 | *
|
8974 | * wrapped.value();
|
8975 | * // => [1, 4]
|
8976 | */
|
8977 | function wrapperPlant(value) {
|
8978 | var result,
|
8979 | parent = this;
|
8980 |
|
8981 | while (parent instanceof baseLodash) {
|
8982 | var clone = wrapperClone(parent);
|
8983 | clone.__index__ = 0;
|
8984 | clone.__values__ = undefined;
|
8985 | if (result) {
|
8986 | previous.__wrapped__ = clone;
|
8987 | } else {
|
8988 | result = clone;
|
8989 | }
|
8990 | var previous = clone;
|
8991 | parent = parent.__wrapped__;
|
8992 | }
|
8993 | previous.__wrapped__ = value;
|
8994 | return result;
|
8995 | }
|
8996 |
|
8997 | /**
|
8998 | * This method is the wrapper version of `_.reverse`.
|
8999 | *
|
9000 | * **Note:** This method mutates the wrapped array.
|
9001 | *
|
9002 | * @name reverse
|
9003 | * @memberOf _
|
9004 | * @since 0.1.0
|
9005 | * @category Seq
|
9006 | * @returns {Object} Returns the new `lodash` wrapper instance.
|
9007 | * @example
|
9008 | *
|
9009 | * var array = [1, 2, 3];
|
9010 | *
|
9011 | * _(array).reverse().value()
|
9012 | * // => [3, 2, 1]
|
9013 | *
|
9014 | * console.log(array);
|
9015 | * // => [3, 2, 1]
|
9016 | */
|
9017 | function wrapperReverse() {
|
9018 | var value = this.__wrapped__;
|
9019 | if (value instanceof LazyWrapper) {
|
9020 | var wrapped = value;
|
9021 | if (this.__actions__.length) {
|
9022 | wrapped = new LazyWrapper(this);
|
9023 | }
|
9024 | wrapped = wrapped.reverse();
|
9025 | wrapped.__actions__.push({
|
9026 | 'func': thru,
|
9027 | 'args': [reverse],
|
9028 | 'thisArg': undefined
|
9029 | });
|
9030 | return new LodashWrapper(wrapped, this.__chain__);
|
9031 | }
|
9032 | return this.thru(reverse);
|
9033 | }
|
9034 |
|
9035 | /**
|
9036 | * Executes the chain sequence to resolve the unwrapped value.
|
9037 | *
|
9038 | * @name value
|
9039 | * @memberOf _
|
9040 | * @since 0.1.0
|
9041 | * @alias toJSON, valueOf
|
9042 | * @category Seq
|
9043 | * @returns {*} Returns the resolved unwrapped value.
|
9044 | * @example
|
9045 | *
|
9046 | * _([1, 2, 3]).value();
|
9047 | * // => [1, 2, 3]
|
9048 | */
|
9049 | function wrapperValue() {
|
9050 | return baseWrapperValue(this.__wrapped__, this.__actions__);
|
9051 | }
|
9052 |
|
9053 | /*------------------------------------------------------------------------*/
|
9054 |
|
9055 | /**
|
9056 | * Creates an object composed of keys generated from the results of running
|
9057 | * each element of `collection` thru `iteratee`. The corresponding value of
|
9058 | * each key is the number of times the key was returned by `iteratee`. The
|
9059 | * iteratee is invoked with one argument: (value).
|
9060 | *
|
9061 | * @static
|
9062 | * @memberOf _
|
9063 | * @since 0.5.0
|
9064 | * @category Collection
|
9065 | * @param {Array|Object} collection The collection to iterate over.
|
9066 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
9067 | * @returns {Object} Returns the composed aggregate object.
|
9068 | * @example
|
9069 | *
|
9070 | * _.countBy([6.1, 4.2, 6.3], Math.floor);
|
9071 | * // => { '4': 1, '6': 2 }
|
9072 | *
|
9073 | * // The `_.property` iteratee shorthand.
|
9074 | * _.countBy(['one', 'two', 'three'], 'length');
|
9075 | * // => { '3': 2, '5': 1 }
|
9076 | */
|
9077 | var countBy = createAggregator(function(result, value, key) {
|
9078 | if (hasOwnProperty.call(result, key)) {
|
9079 | ++result[key];
|
9080 | } else {
|
9081 | baseAssignValue(result, key, 1);
|
9082 | }
|
9083 | });
|
9084 |
|
9085 | /**
|
9086 | * Checks if `predicate` returns truthy for **all** elements of `collection`.
|
9087 | * Iteration is stopped once `predicate` returns falsey. The predicate is
|
9088 | * invoked with three arguments: (value, index|key, collection).
|
9089 | *
|
9090 | * **Note:** This method returns `true` for
|
9091 | * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
|
9092 | * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
|
9093 | * elements of empty collections.
|
9094 | *
|
9095 | * @static
|
9096 | * @memberOf _
|
9097 | * @since 0.1.0
|
9098 | * @category Collection
|
9099 | * @param {Array|Object} collection The collection to iterate over.
|
9100 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
9101 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
9102 | * @returns {boolean} Returns `true` if all elements pass the predicate check,
|
9103 | * else `false`.
|
9104 | * @example
|
9105 | *
|
9106 | * _.every([true, 1, null, 'yes'], Boolean);
|
9107 | * // => false
|
9108 | *
|
9109 | * var users = [
|
9110 | * { 'user': 'barney', 'age': 36, 'active': false },
|
9111 | * { 'user': 'fred', 'age': 40, 'active': false }
|
9112 | * ];
|
9113 | *
|
9114 | * // The `_.matches` iteratee shorthand.
|
9115 | * _.every(users, { 'user': 'barney', 'active': false });
|
9116 | * // => false
|
9117 | *
|
9118 | * // The `_.matchesProperty` iteratee shorthand.
|
9119 | * _.every(users, ['active', false]);
|
9120 | * // => true
|
9121 | *
|
9122 | * // The `_.property` iteratee shorthand.
|
9123 | * _.every(users, 'active');
|
9124 | * // => false
|
9125 | */
|
9126 | function every(collection, predicate, guard) {
|
9127 | var func = isArray(collection) ? arrayEvery : baseEvery;
|
9128 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
9129 | predicate = undefined;
|
9130 | }
|
9131 | return func(collection, getIteratee(predicate, 3));
|
9132 | }
|
9133 |
|
9134 | /**
|
9135 | * Iterates over elements of `collection`, returning an array of all elements
|
9136 | * `predicate` returns truthy for. The predicate is invoked with three
|
9137 | * arguments: (value, index|key, collection).
|
9138 | *
|
9139 | * **Note:** Unlike `_.remove`, this method returns a new array.
|
9140 | *
|
9141 | * @static
|
9142 | * @memberOf _
|
9143 | * @since 0.1.0
|
9144 | * @category Collection
|
9145 | * @param {Array|Object} collection The collection to iterate over.
|
9146 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
9147 | * @returns {Array} Returns the new filtered array.
|
9148 | * @see _.reject
|
9149 | * @example
|
9150 | *
|
9151 | * var users = [
|
9152 | * { 'user': 'barney', 'age': 36, 'active': true },
|
9153 | * { 'user': 'fred', 'age': 40, 'active': false }
|
9154 | * ];
|
9155 | *
|
9156 | * _.filter(users, function(o) { return !o.active; });
|
9157 | * // => objects for ['fred']
|
9158 | *
|
9159 | * // The `_.matches` iteratee shorthand.
|
9160 | * _.filter(users, { 'age': 36, 'active': true });
|
9161 | * // => objects for ['barney']
|
9162 | *
|
9163 | * // The `_.matchesProperty` iteratee shorthand.
|
9164 | * _.filter(users, ['active', false]);
|
9165 | * // => objects for ['fred']
|
9166 | *
|
9167 | * // The `_.property` iteratee shorthand.
|
9168 | * _.filter(users, 'active');
|
9169 | * // => objects for ['barney']
|
9170 | */
|
9171 | function filter(collection, predicate) {
|
9172 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
9173 | return func(collection, getIteratee(predicate, 3));
|
9174 | }
|
9175 |
|
9176 | /**
|
9177 | * Iterates over elements of `collection`, returning the first element
|
9178 | * `predicate` returns truthy for. The predicate is invoked with three
|
9179 | * arguments: (value, index|key, collection).
|
9180 | *
|
9181 | * @static
|
9182 | * @memberOf _
|
9183 | * @since 0.1.0
|
9184 | * @category Collection
|
9185 | * @param {Array|Object} collection The collection to inspect.
|
9186 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
9187 | * @param {number} [fromIndex=0] The index to search from.
|
9188 | * @returns {*} Returns the matched element, else `undefined`.
|
9189 | * @example
|
9190 | *
|
9191 | * var users = [
|
9192 | * { 'user': 'barney', 'age': 36, 'active': true },
|
9193 | * { 'user': 'fred', 'age': 40, 'active': false },
|
9194 | * { 'user': 'pebbles', 'age': 1, 'active': true }
|
9195 | * ];
|
9196 | *
|
9197 | * _.find(users, function(o) { return o.age < 40; });
|
9198 | * // => object for 'barney'
|
9199 | *
|
9200 | * // The `_.matches` iteratee shorthand.
|
9201 | * _.find(users, { 'age': 1, 'active': true });
|
9202 | * // => object for 'pebbles'
|
9203 | *
|
9204 | * // The `_.matchesProperty` iteratee shorthand.
|
9205 | * _.find(users, ['active', false]);
|
9206 | * // => object for 'fred'
|
9207 | *
|
9208 | * // The `_.property` iteratee shorthand.
|
9209 | * _.find(users, 'active');
|
9210 | * // => object for 'barney'
|
9211 | */
|
9212 | var find = createFind(findIndex);
|
9213 |
|
9214 | /**
|
9215 | * This method is like `_.find` except that it iterates over elements of
|
9216 | * `collection` from right to left.
|
9217 | *
|
9218 | * @static
|
9219 | * @memberOf _
|
9220 | * @since 2.0.0
|
9221 | * @category Collection
|
9222 | * @param {Array|Object} collection The collection to inspect.
|
9223 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
9224 | * @param {number} [fromIndex=collection.length-1] The index to search from.
|
9225 | * @returns {*} Returns the matched element, else `undefined`.
|
9226 | * @example
|
9227 | *
|
9228 | * _.findLast([1, 2, 3, 4], function(n) {
|
9229 | * return n % 2 == 1;
|
9230 | * });
|
9231 | * // => 3
|
9232 | */
|
9233 | var findLast = createFind(findLastIndex);
|
9234 |
|
9235 | /**
|
9236 | * Creates a flattened array of values by running each element in `collection`
|
9237 | * thru `iteratee` and flattening the mapped results. The iteratee is invoked
|
9238 | * with three arguments: (value, index|key, collection).
|
9239 | *
|
9240 | * @static
|
9241 | * @memberOf _
|
9242 | * @since 4.0.0
|
9243 | * @category Collection
|
9244 | * @param {Array|Object} collection The collection to iterate over.
|
9245 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9246 | * @returns {Array} Returns the new flattened array.
|
9247 | * @example
|
9248 | *
|
9249 | * function duplicate(n) {
|
9250 | * return [n, n];
|
9251 | * }
|
9252 | *
|
9253 | * _.flatMap([1, 2], duplicate);
|
9254 | * // => [1, 1, 2, 2]
|
9255 | */
|
9256 | function flatMap(collection, iteratee) {
|
9257 | return baseFlatten(map(collection, iteratee), 1);
|
9258 | }
|
9259 |
|
9260 | /**
|
9261 | * This method is like `_.flatMap` except that it recursively flattens the
|
9262 | * mapped results.
|
9263 | *
|
9264 | * @static
|
9265 | * @memberOf _
|
9266 | * @since 4.7.0
|
9267 | * @category Collection
|
9268 | * @param {Array|Object} collection The collection to iterate over.
|
9269 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9270 | * @returns {Array} Returns the new flattened array.
|
9271 | * @example
|
9272 | *
|
9273 | * function duplicate(n) {
|
9274 | * return [[[n, n]]];
|
9275 | * }
|
9276 | *
|
9277 | * _.flatMapDeep([1, 2], duplicate);
|
9278 | * // => [1, 1, 2, 2]
|
9279 | */
|
9280 | function flatMapDeep(collection, iteratee) {
|
9281 | return baseFlatten(map(collection, iteratee), INFINITY);
|
9282 | }
|
9283 |
|
9284 | /**
|
9285 | * This method is like `_.flatMap` except that it recursively flattens the
|
9286 | * mapped results up to `depth` times.
|
9287 | *
|
9288 | * @static
|
9289 | * @memberOf _
|
9290 | * @since 4.7.0
|
9291 | * @category Collection
|
9292 | * @param {Array|Object} collection The collection to iterate over.
|
9293 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9294 | * @param {number} [depth=1] The maximum recursion depth.
|
9295 | * @returns {Array} Returns the new flattened array.
|
9296 | * @example
|
9297 | *
|
9298 | * function duplicate(n) {
|
9299 | * return [[[n, n]]];
|
9300 | * }
|
9301 | *
|
9302 | * _.flatMapDepth([1, 2], duplicate, 2);
|
9303 | * // => [[1, 1], [2, 2]]
|
9304 | */
|
9305 | function flatMapDepth(collection, iteratee, depth) {
|
9306 | depth = depth === undefined ? 1 : toInteger(depth);
|
9307 | return baseFlatten(map(collection, iteratee), depth);
|
9308 | }
|
9309 |
|
9310 | /**
|
9311 | * Iterates over elements of `collection` and invokes `iteratee` for each element.
|
9312 | * The iteratee is invoked with three arguments: (value, index|key, collection).
|
9313 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
9314 | *
|
9315 | * **Note:** As with other "Collections" methods, objects with a "length"
|
9316 | * property are iterated like arrays. To avoid this behavior use `_.forIn`
|
9317 | * or `_.forOwn` for object iteration.
|
9318 | *
|
9319 | * @static
|
9320 | * @memberOf _
|
9321 | * @since 0.1.0
|
9322 | * @alias each
|
9323 | * @category Collection
|
9324 | * @param {Array|Object} collection The collection to iterate over.
|
9325 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9326 | * @returns {Array|Object} Returns `collection`.
|
9327 | * @see _.forEachRight
|
9328 | * @example
|
9329 | *
|
9330 | * _.forEach([1, 2], function(value) {
|
9331 | * console.log(value);
|
9332 | * });
|
9333 | * // => Logs `1` then `2`.
|
9334 | *
|
9335 | * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
|
9336 | * console.log(key);
|
9337 | * });
|
9338 | * // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
9339 | */
|
9340 | function forEach(collection, iteratee) {
|
9341 | var func = isArray(collection) ? arrayEach : baseEach;
|
9342 | return func(collection, getIteratee(iteratee, 3));
|
9343 | }
|
9344 |
|
9345 | /**
|
9346 | * This method is like `_.forEach` except that it iterates over elements of
|
9347 | * `collection` from right to left.
|
9348 | *
|
9349 | * @static
|
9350 | * @memberOf _
|
9351 | * @since 2.0.0
|
9352 | * @alias eachRight
|
9353 | * @category Collection
|
9354 | * @param {Array|Object} collection The collection to iterate over.
|
9355 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9356 | * @returns {Array|Object} Returns `collection`.
|
9357 | * @see _.forEach
|
9358 | * @example
|
9359 | *
|
9360 | * _.forEachRight([1, 2], function(value) {
|
9361 | * console.log(value);
|
9362 | * });
|
9363 | * // => Logs `2` then `1`.
|
9364 | */
|
9365 | function forEachRight(collection, iteratee) {
|
9366 | var func = isArray(collection) ? arrayEachRight : baseEachRight;
|
9367 | return func(collection, getIteratee(iteratee, 3));
|
9368 | }
|
9369 |
|
9370 | /**
|
9371 | * Creates an object composed of keys generated from the results of running
|
9372 | * each element of `collection` thru `iteratee`. The order of grouped values
|
9373 | * is determined by the order they occur in `collection`. The corresponding
|
9374 | * value of each key is an array of elements responsible for generating the
|
9375 | * key. The iteratee is invoked with one argument: (value).
|
9376 | *
|
9377 | * @static
|
9378 | * @memberOf _
|
9379 | * @since 0.1.0
|
9380 | * @category Collection
|
9381 | * @param {Array|Object} collection The collection to iterate over.
|
9382 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
9383 | * @returns {Object} Returns the composed aggregate object.
|
9384 | * @example
|
9385 | *
|
9386 | * _.groupBy([6.1, 4.2, 6.3], Math.floor);
|
9387 | * // => { '4': [4.2], '6': [6.1, 6.3] }
|
9388 | *
|
9389 | * // The `_.property` iteratee shorthand.
|
9390 | * _.groupBy(['one', 'two', 'three'], 'length');
|
9391 | * // => { '3': ['one', 'two'], '5': ['three'] }
|
9392 | */
|
9393 | var groupBy = createAggregator(function(result, value, key) {
|
9394 | if (hasOwnProperty.call(result, key)) {
|
9395 | result[key].push(value);
|
9396 | } else {
|
9397 | baseAssignValue(result, key, [value]);
|
9398 | }
|
9399 | });
|
9400 |
|
9401 | /**
|
9402 | * Checks if `value` is in `collection`. If `collection` is a string, it's
|
9403 | * checked for a substring of `value`, otherwise
|
9404 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
9405 | * is used for equality comparisons. If `fromIndex` is negative, it's used as
|
9406 | * the offset from the end of `collection`.
|
9407 | *
|
9408 | * @static
|
9409 | * @memberOf _
|
9410 | * @since 0.1.0
|
9411 | * @category Collection
|
9412 | * @param {Array|Object|string} collection The collection to inspect.
|
9413 | * @param {*} value The value to search for.
|
9414 | * @param {number} [fromIndex=0] The index to search from.
|
9415 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
9416 | * @returns {boolean} Returns `true` if `value` is found, else `false`.
|
9417 | * @example
|
9418 | *
|
9419 | * _.includes([1, 2, 3], 1);
|
9420 | * // => true
|
9421 | *
|
9422 | * _.includes([1, 2, 3], 1, 2);
|
9423 | * // => false
|
9424 | *
|
9425 | * _.includes({ 'a': 1, 'b': 2 }, 1);
|
9426 | * // => true
|
9427 | *
|
9428 | * _.includes('abcd', 'bc');
|
9429 | * // => true
|
9430 | */
|
9431 | function includes(collection, value, fromIndex, guard) {
|
9432 | collection = isArrayLike(collection) ? collection : values(collection);
|
9433 | fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
|
9434 |
|
9435 | var length = collection.length;
|
9436 | if (fromIndex < 0) {
|
9437 | fromIndex = nativeMax(length + fromIndex, 0);
|
9438 | }
|
9439 | return isString(collection)
|
9440 | ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
|
9441 | : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
|
9442 | }
|
9443 |
|
9444 | /**
|
9445 | * Invokes the method at `path` of each element in `collection`, returning
|
9446 | * an array of the results of each invoked method. Any additional arguments
|
9447 | * are provided to each invoked method. If `path` is a function, it's invoked
|
9448 | * for, and `this` bound to, each element in `collection`.
|
9449 | *
|
9450 | * @static
|
9451 | * @memberOf _
|
9452 | * @since 4.0.0
|
9453 | * @category Collection
|
9454 | * @param {Array|Object} collection The collection to iterate over.
|
9455 | * @param {Array|Function|string} path The path of the method to invoke or
|
9456 | * the function invoked per iteration.
|
9457 | * @param {...*} [args] The arguments to invoke each method with.
|
9458 | * @returns {Array} Returns the array of results.
|
9459 | * @example
|
9460 | *
|
9461 | * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
|
9462 | * // => [[1, 5, 7], [1, 2, 3]]
|
9463 | *
|
9464 | * _.invokeMap([123, 456], String.prototype.split, '');
|
9465 | * // => [['1', '2', '3'], ['4', '5', '6']]
|
9466 | */
|
9467 | var invokeMap = baseRest(function(collection, path, args) {
|
9468 | var index = -1,
|
9469 | isFunc = typeof path == 'function',
|
9470 | result = isArrayLike(collection) ? Array(collection.length) : [];
|
9471 |
|
9472 | baseEach(collection, function(value) {
|
9473 | result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
|
9474 | });
|
9475 | return result;
|
9476 | });
|
9477 |
|
9478 | /**
|
9479 | * Creates an object composed of keys generated from the results of running
|
9480 | * each element of `collection` thru `iteratee`. The corresponding value of
|
9481 | * each key is the last element responsible for generating the key. The
|
9482 | * iteratee is invoked with one argument: (value).
|
9483 | *
|
9484 | * @static
|
9485 | * @memberOf _
|
9486 | * @since 4.0.0
|
9487 | * @category Collection
|
9488 | * @param {Array|Object} collection The collection to iterate over.
|
9489 | * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
9490 | * @returns {Object} Returns the composed aggregate object.
|
9491 | * @example
|
9492 | *
|
9493 | * var array = [
|
9494 | * { 'dir': 'left', 'code': 97 },
|
9495 | * { 'dir': 'right', 'code': 100 }
|
9496 | * ];
|
9497 | *
|
9498 | * _.keyBy(array, function(o) {
|
9499 | * return String.fromCharCode(o.code);
|
9500 | * });
|
9501 | * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
9502 | *
|
9503 | * _.keyBy(array, 'dir');
|
9504 | * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
9505 | */
|
9506 | var keyBy = createAggregator(function(result, value, key) {
|
9507 | baseAssignValue(result, key, value);
|
9508 | });
|
9509 |
|
9510 | /**
|
9511 | * Creates an array of values by running each element in `collection` thru
|
9512 | * `iteratee`. The iteratee is invoked with three arguments:
|
9513 | * (value, index|key, collection).
|
9514 | *
|
9515 | * Many lodash methods are guarded to work as iteratees for methods like
|
9516 | * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
9517 | *
|
9518 | * The guarded methods are:
|
9519 | * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
|
9520 | * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
|
9521 | * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
|
9522 | * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
|
9523 | *
|
9524 | * @static
|
9525 | * @memberOf _
|
9526 | * @since 0.1.0
|
9527 | * @category Collection
|
9528 | * @param {Array|Object} collection The collection to iterate over.
|
9529 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9530 | * @returns {Array} Returns the new mapped array.
|
9531 | * @example
|
9532 | *
|
9533 | * function square(n) {
|
9534 | * return n * n;
|
9535 | * }
|
9536 | *
|
9537 | * _.map([4, 8], square);
|
9538 | * // => [16, 64]
|
9539 | *
|
9540 | * _.map({ 'a': 4, 'b': 8 }, square);
|
9541 | * // => [16, 64] (iteration order is not guaranteed)
|
9542 | *
|
9543 | * var users = [
|
9544 | * { 'user': 'barney' },
|
9545 | * { 'user': 'fred' }
|
9546 | * ];
|
9547 | *
|
9548 | * // The `_.property` iteratee shorthand.
|
9549 | * _.map(users, 'user');
|
9550 | * // => ['barney', 'fred']
|
9551 | */
|
9552 | function map(collection, iteratee) {
|
9553 | var func = isArray(collection) ? arrayMap : baseMap;
|
9554 | return func(collection, getIteratee(iteratee, 3));
|
9555 | }
|
9556 |
|
9557 | /**
|
9558 | * This method is like `_.sortBy` except that it allows specifying the sort
|
9559 | * orders of the iteratees to sort by. If `orders` is unspecified, all values
|
9560 | * are sorted in ascending order. Otherwise, specify an order of "desc" for
|
9561 | * descending or "asc" for ascending sort order of corresponding values.
|
9562 | *
|
9563 | * @static
|
9564 | * @memberOf _
|
9565 | * @since 4.0.0
|
9566 | * @category Collection
|
9567 | * @param {Array|Object} collection The collection to iterate over.
|
9568 | * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
|
9569 | * The iteratees to sort by.
|
9570 | * @param {string[]} [orders] The sort orders of `iteratees`.
|
9571 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
|
9572 | * @returns {Array} Returns the new sorted array.
|
9573 | * @example
|
9574 | *
|
9575 | * var users = [
|
9576 | * { 'user': 'fred', 'age': 48 },
|
9577 | * { 'user': 'barney', 'age': 34 },
|
9578 | * { 'user': 'fred', 'age': 40 },
|
9579 | * { 'user': 'barney', 'age': 36 }
|
9580 | * ];
|
9581 | *
|
9582 | * // Sort by `user` in ascending order and by `age` in descending order.
|
9583 | * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
|
9584 | * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
9585 | */
|
9586 | function orderBy(collection, iteratees, orders, guard) {
|
9587 | if (collection == null) {
|
9588 | return [];
|
9589 | }
|
9590 | if (!isArray(iteratees)) {
|
9591 | iteratees = iteratees == null ? [] : [iteratees];
|
9592 | }
|
9593 | orders = guard ? undefined : orders;
|
9594 | if (!isArray(orders)) {
|
9595 | orders = orders == null ? [] : [orders];
|
9596 | }
|
9597 | return baseOrderBy(collection, iteratees, orders);
|
9598 | }
|
9599 |
|
9600 | /**
|
9601 | * Creates an array of elements split into two groups, the first of which
|
9602 | * contains elements `predicate` returns truthy for, the second of which
|
9603 | * contains elements `predicate` returns falsey for. The predicate is
|
9604 | * invoked with one argument: (value).
|
9605 | *
|
9606 | * @static
|
9607 | * @memberOf _
|
9608 | * @since 3.0.0
|
9609 | * @category Collection
|
9610 | * @param {Array|Object} collection The collection to iterate over.
|
9611 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
9612 | * @returns {Array} Returns the array of grouped elements.
|
9613 | * @example
|
9614 | *
|
9615 | * var users = [
|
9616 | * { 'user': 'barney', 'age': 36, 'active': false },
|
9617 | * { 'user': 'fred', 'age': 40, 'active': true },
|
9618 | * { 'user': 'pebbles', 'age': 1, 'active': false }
|
9619 | * ];
|
9620 | *
|
9621 | * _.partition(users, function(o) { return o.active; });
|
9622 | * // => objects for [['fred'], ['barney', 'pebbles']]
|
9623 | *
|
9624 | * // The `_.matches` iteratee shorthand.
|
9625 | * _.partition(users, { 'age': 1, 'active': false });
|
9626 | * // => objects for [['pebbles'], ['barney', 'fred']]
|
9627 | *
|
9628 | * // The `_.matchesProperty` iteratee shorthand.
|
9629 | * _.partition(users, ['active', false]);
|
9630 | * // => objects for [['barney', 'pebbles'], ['fred']]
|
9631 | *
|
9632 | * // The `_.property` iteratee shorthand.
|
9633 | * _.partition(users, 'active');
|
9634 | * // => objects for [['fred'], ['barney', 'pebbles']]
|
9635 | */
|
9636 | var partition = createAggregator(function(result, value, key) {
|
9637 | result[key ? 0 : 1].push(value);
|
9638 | }, function() { return [[], []]; });
|
9639 |
|
9640 | /**
|
9641 | * Reduces `collection` to a value which is the accumulated result of running
|
9642 | * each element in `collection` thru `iteratee`, where each successive
|
9643 | * invocation is supplied the return value of the previous. If `accumulator`
|
9644 | * is not given, the first element of `collection` is used as the initial
|
9645 | * value. The iteratee is invoked with four arguments:
|
9646 | * (accumulator, value, index|key, collection).
|
9647 | *
|
9648 | * Many lodash methods are guarded to work as iteratees for methods like
|
9649 | * `_.reduce`, `_.reduceRight`, and `_.transform`.
|
9650 | *
|
9651 | * The guarded methods are:
|
9652 | * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
|
9653 | * and `sortBy`
|
9654 | *
|
9655 | * @static
|
9656 | * @memberOf _
|
9657 | * @since 0.1.0
|
9658 | * @category Collection
|
9659 | * @param {Array|Object} collection The collection to iterate over.
|
9660 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9661 | * @param {*} [accumulator] The initial value.
|
9662 | * @returns {*} Returns the accumulated value.
|
9663 | * @see _.reduceRight
|
9664 | * @example
|
9665 | *
|
9666 | * _.reduce([1, 2], function(sum, n) {
|
9667 | * return sum + n;
|
9668 | * }, 0);
|
9669 | * // => 3
|
9670 | *
|
9671 | * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
9672 | * (result[value] || (result[value] = [])).push(key);
|
9673 | * return result;
|
9674 | * }, {});
|
9675 | * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
|
9676 | */
|
9677 | function reduce(collection, iteratee, accumulator) {
|
9678 | var func = isArray(collection) ? arrayReduce : baseReduce,
|
9679 | initAccum = arguments.length < 3;
|
9680 |
|
9681 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
|
9682 | }
|
9683 |
|
9684 | /**
|
9685 | * This method is like `_.reduce` except that it iterates over elements of
|
9686 | * `collection` from right to left.
|
9687 | *
|
9688 | * @static
|
9689 | * @memberOf _
|
9690 | * @since 0.1.0
|
9691 | * @category Collection
|
9692 | * @param {Array|Object} collection The collection to iterate over.
|
9693 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
9694 | * @param {*} [accumulator] The initial value.
|
9695 | * @returns {*} Returns the accumulated value.
|
9696 | * @see _.reduce
|
9697 | * @example
|
9698 | *
|
9699 | * var array = [[0, 1], [2, 3], [4, 5]];
|
9700 | *
|
9701 | * _.reduceRight(array, function(flattened, other) {
|
9702 | * return flattened.concat(other);
|
9703 | * }, []);
|
9704 | * // => [4, 5, 2, 3, 0, 1]
|
9705 | */
|
9706 | function reduceRight(collection, iteratee, accumulator) {
|
9707 | var func = isArray(collection) ? arrayReduceRight : baseReduce,
|
9708 | initAccum = arguments.length < 3;
|
9709 |
|
9710 | return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
|
9711 | }
|
9712 |
|
9713 | /**
|
9714 | * The opposite of `_.filter`; this method returns the elements of `collection`
|
9715 | * that `predicate` does **not** return truthy for.
|
9716 | *
|
9717 | * @static
|
9718 | * @memberOf _
|
9719 | * @since 0.1.0
|
9720 | * @category Collection
|
9721 | * @param {Array|Object} collection The collection to iterate over.
|
9722 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
9723 | * @returns {Array} Returns the new filtered array.
|
9724 | * @see _.filter
|
9725 | * @example
|
9726 | *
|
9727 | * var users = [
|
9728 | * { 'user': 'barney', 'age': 36, 'active': false },
|
9729 | * { 'user': 'fred', 'age': 40, 'active': true }
|
9730 | * ];
|
9731 | *
|
9732 | * _.reject(users, function(o) { return !o.active; });
|
9733 | * // => objects for ['fred']
|
9734 | *
|
9735 | * // The `_.matches` iteratee shorthand.
|
9736 | * _.reject(users, { 'age': 40, 'active': true });
|
9737 | * // => objects for ['barney']
|
9738 | *
|
9739 | * // The `_.matchesProperty` iteratee shorthand.
|
9740 | * _.reject(users, ['active', false]);
|
9741 | * // => objects for ['fred']
|
9742 | *
|
9743 | * // The `_.property` iteratee shorthand.
|
9744 | * _.reject(users, 'active');
|
9745 | * // => objects for ['barney']
|
9746 | */
|
9747 | function reject(collection, predicate) {
|
9748 | var func = isArray(collection) ? arrayFilter : baseFilter;
|
9749 | return func(collection, negate(getIteratee(predicate, 3)));
|
9750 | }
|
9751 |
|
9752 | /**
|
9753 | * Gets a random element from `collection`.
|
9754 | *
|
9755 | * @static
|
9756 | * @memberOf _
|
9757 | * @since 2.0.0
|
9758 | * @category Collection
|
9759 | * @param {Array|Object} collection The collection to sample.
|
9760 | * @returns {*} Returns the random element.
|
9761 | * @example
|
9762 | *
|
9763 | * _.sample([1, 2, 3, 4]);
|
9764 | * // => 2
|
9765 | */
|
9766 | function sample(collection) {
|
9767 | var func = isArray(collection) ? arraySample : baseSample;
|
9768 | return func(collection);
|
9769 | }
|
9770 |
|
9771 | /**
|
9772 | * Gets `n` random elements at unique keys from `collection` up to the
|
9773 | * size of `collection`.
|
9774 | *
|
9775 | * @static
|
9776 | * @memberOf _
|
9777 | * @since 4.0.0
|
9778 | * @category Collection
|
9779 | * @param {Array|Object} collection The collection to sample.
|
9780 | * @param {number} [n=1] The number of elements to sample.
|
9781 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
9782 | * @returns {Array} Returns the random elements.
|
9783 | * @example
|
9784 | *
|
9785 | * _.sampleSize([1, 2, 3], 2);
|
9786 | * // => [3, 1]
|
9787 | *
|
9788 | * _.sampleSize([1, 2, 3], 4);
|
9789 | * // => [2, 3, 1]
|
9790 | */
|
9791 | function sampleSize(collection, n, guard) {
|
9792 | if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
|
9793 | n = 1;
|
9794 | } else {
|
9795 | n = toInteger(n);
|
9796 | }
|
9797 | var func = isArray(collection) ? arraySampleSize : baseSampleSize;
|
9798 | return func(collection, n);
|
9799 | }
|
9800 |
|
9801 | /**
|
9802 | * Creates an array of shuffled values, using a version of the
|
9803 | * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
9804 | *
|
9805 | * @static
|
9806 | * @memberOf _
|
9807 | * @since 0.1.0
|
9808 | * @category Collection
|
9809 | * @param {Array|Object} collection The collection to shuffle.
|
9810 | * @returns {Array} Returns the new shuffled array.
|
9811 | * @example
|
9812 | *
|
9813 | * _.shuffle([1, 2, 3, 4]);
|
9814 | * // => [4, 1, 3, 2]
|
9815 | */
|
9816 | function shuffle(collection) {
|
9817 | var func = isArray(collection) ? arrayShuffle : baseShuffle;
|
9818 | return func(collection);
|
9819 | }
|
9820 |
|
9821 | /**
|
9822 | * Gets the size of `collection` by returning its length for array-like
|
9823 | * values or the number of own enumerable string keyed properties for objects.
|
9824 | *
|
9825 | * @static
|
9826 | * @memberOf _
|
9827 | * @since 0.1.0
|
9828 | * @category Collection
|
9829 | * @param {Array|Object|string} collection The collection to inspect.
|
9830 | * @returns {number} Returns the collection size.
|
9831 | * @example
|
9832 | *
|
9833 | * _.size([1, 2, 3]);
|
9834 | * // => 3
|
9835 | *
|
9836 | * _.size({ 'a': 1, 'b': 2 });
|
9837 | * // => 2
|
9838 | *
|
9839 | * _.size('pebbles');
|
9840 | * // => 7
|
9841 | */
|
9842 | function size(collection) {
|
9843 | if (collection == null) {
|
9844 | return 0;
|
9845 | }
|
9846 | if (isArrayLike(collection)) {
|
9847 | return isString(collection) ? stringSize(collection) : collection.length;
|
9848 | }
|
9849 | var tag = getTag(collection);
|
9850 | if (tag == mapTag || tag == setTag) {
|
9851 | return collection.size;
|
9852 | }
|
9853 | return baseKeys(collection).length;
|
9854 | }
|
9855 |
|
9856 | /**
|
9857 | * Checks if `predicate` returns truthy for **any** element of `collection`.
|
9858 | * Iteration is stopped once `predicate` returns truthy. The predicate is
|
9859 | * invoked with three arguments: (value, index|key, collection).
|
9860 | *
|
9861 | * @static
|
9862 | * @memberOf _
|
9863 | * @since 0.1.0
|
9864 | * @category Collection
|
9865 | * @param {Array|Object} collection The collection to iterate over.
|
9866 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
9867 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
9868 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
9869 | * else `false`.
|
9870 | * @example
|
9871 | *
|
9872 | * _.some([null, 0, 'yes', false], Boolean);
|
9873 | * // => true
|
9874 | *
|
9875 | * var users = [
|
9876 | * { 'user': 'barney', 'active': true },
|
9877 | * { 'user': 'fred', 'active': false }
|
9878 | * ];
|
9879 | *
|
9880 | * // The `_.matches` iteratee shorthand.
|
9881 | * _.some(users, { 'user': 'barney', 'active': false });
|
9882 | * // => false
|
9883 | *
|
9884 | * // The `_.matchesProperty` iteratee shorthand.
|
9885 | * _.some(users, ['active', false]);
|
9886 | * // => true
|
9887 | *
|
9888 | * // The `_.property` iteratee shorthand.
|
9889 | * _.some(users, 'active');
|
9890 | * // => true
|
9891 | */
|
9892 | function some(collection, predicate, guard) {
|
9893 | var func = isArray(collection) ? arraySome : baseSome;
|
9894 | if (guard && isIterateeCall(collection, predicate, guard)) {
|
9895 | predicate = undefined;
|
9896 | }
|
9897 | return func(collection, getIteratee(predicate, 3));
|
9898 | }
|
9899 |
|
9900 | /**
|
9901 | * Creates an array of elements, sorted in ascending order by the results of
|
9902 | * running each element in a collection thru each iteratee. This method
|
9903 | * performs a stable sort, that is, it preserves the original sort order of
|
9904 | * equal elements. The iteratees are invoked with one argument: (value).
|
9905 | *
|
9906 | * @static
|
9907 | * @memberOf _
|
9908 | * @since 0.1.0
|
9909 | * @category Collection
|
9910 | * @param {Array|Object} collection The collection to iterate over.
|
9911 | * @param {...(Function|Function[])} [iteratees=[_.identity]]
|
9912 | * The iteratees to sort by.
|
9913 | * @returns {Array} Returns the new sorted array.
|
9914 | * @example
|
9915 | *
|
9916 | * var users = [
|
9917 | * { 'user': 'fred', 'age': 48 },
|
9918 | * { 'user': 'barney', 'age': 36 },
|
9919 | * { 'user': 'fred', 'age': 40 },
|
9920 | * { 'user': 'barney', 'age': 34 }
|
9921 | * ];
|
9922 | *
|
9923 | * _.sortBy(users, [function(o) { return o.user; }]);
|
9924 | * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
|
9925 | *
|
9926 | * _.sortBy(users, ['user', 'age']);
|
9927 | * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
|
9928 | */
|
9929 | var sortBy = baseRest(function(collection, iteratees) {
|
9930 | if (collection == null) {
|
9931 | return [];
|
9932 | }
|
9933 | var length = iteratees.length;
|
9934 | if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
|
9935 | iteratees = [];
|
9936 | } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
|
9937 | iteratees = [iteratees[0]];
|
9938 | }
|
9939 | return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
|
9940 | });
|
9941 |
|
9942 | /*------------------------------------------------------------------------*/
|
9943 |
|
9944 | /**
|
9945 | * Gets the timestamp of the number of milliseconds that have elapsed since
|
9946 | * the Unix epoch (1 January 1970 00:00:00 UTC).
|
9947 | *
|
9948 | * @static
|
9949 | * @memberOf _
|
9950 | * @since 2.4.0
|
9951 | * @category Date
|
9952 | * @returns {number} Returns the timestamp.
|
9953 | * @example
|
9954 | *
|
9955 | * _.defer(function(stamp) {
|
9956 | * console.log(_.now() - stamp);
|
9957 | * }, _.now());
|
9958 | * // => Logs the number of milliseconds it took for the deferred invocation.
|
9959 | */
|
9960 | var now = ctxNow || function() {
|
9961 | return root.Date.now();
|
9962 | };
|
9963 |
|
9964 | /*------------------------------------------------------------------------*/
|
9965 |
|
9966 | /**
|
9967 | * The opposite of `_.before`; this method creates a function that invokes
|
9968 | * `func` once it's called `n` or more times.
|
9969 | *
|
9970 | * @static
|
9971 | * @memberOf _
|
9972 | * @since 0.1.0
|
9973 | * @category Function
|
9974 | * @param {number} n The number of calls before `func` is invoked.
|
9975 | * @param {Function} func The function to restrict.
|
9976 | * @returns {Function} Returns the new restricted function.
|
9977 | * @example
|
9978 | *
|
9979 | * var saves = ['profile', 'settings'];
|
9980 | *
|
9981 | * var done = _.after(saves.length, function() {
|
9982 | * console.log('done saving!');
|
9983 | * });
|
9984 | *
|
9985 | * _.forEach(saves, function(type) {
|
9986 | * asyncSave({ 'type': type, 'complete': done });
|
9987 | * });
|
9988 | * // => Logs 'done saving!' after the two async saves have completed.
|
9989 | */
|
9990 | function after(n, func) {
|
9991 | if (typeof func != 'function') {
|
9992 | throw new TypeError(FUNC_ERROR_TEXT);
|
9993 | }
|
9994 | n = toInteger(n);
|
9995 | return function() {
|
9996 | if (--n < 1) {
|
9997 | return func.apply(this, arguments);
|
9998 | }
|
9999 | };
|
10000 | }
|
10001 |
|
10002 | /**
|
10003 | * Creates a function that invokes `func`, with up to `n` arguments,
|
10004 | * ignoring any additional arguments.
|
10005 | *
|
10006 | * @static
|
10007 | * @memberOf _
|
10008 | * @since 3.0.0
|
10009 | * @category Function
|
10010 | * @param {Function} func The function to cap arguments for.
|
10011 | * @param {number} [n=func.length] The arity cap.
|
10012 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
10013 | * @returns {Function} Returns the new capped function.
|
10014 | * @example
|
10015 | *
|
10016 | * _.map(['6', '8', '10'], _.ary(parseInt, 1));
|
10017 | * // => [6, 8, 10]
|
10018 | */
|
10019 | function ary(func, n, guard) {
|
10020 | n = guard ? undefined : n;
|
10021 | n = (func && n == null) ? func.length : n;
|
10022 | return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
|
10023 | }
|
10024 |
|
10025 | /**
|
10026 | * Creates a function that invokes `func`, with the `this` binding and arguments
|
10027 | * of the created function, while it's called less than `n` times. Subsequent
|
10028 | * calls to the created function return the result of the last `func` invocation.
|
10029 | *
|
10030 | * @static
|
10031 | * @memberOf _
|
10032 | * @since 3.0.0
|
10033 | * @category Function
|
10034 | * @param {number} n The number of calls at which `func` is no longer invoked.
|
10035 | * @param {Function} func The function to restrict.
|
10036 | * @returns {Function} Returns the new restricted function.
|
10037 | * @example
|
10038 | *
|
10039 | * jQuery(element).on('click', _.before(5, addContactToList));
|
10040 | * // => Allows adding up to 4 contacts to the list.
|
10041 | */
|
10042 | function before(n, func) {
|
10043 | var result;
|
10044 | if (typeof func != 'function') {
|
10045 | throw new TypeError(FUNC_ERROR_TEXT);
|
10046 | }
|
10047 | n = toInteger(n);
|
10048 | return function() {
|
10049 | if (--n > 0) {
|
10050 | result = func.apply(this, arguments);
|
10051 | }
|
10052 | if (n <= 1) {
|
10053 | func = undefined;
|
10054 | }
|
10055 | return result;
|
10056 | };
|
10057 | }
|
10058 |
|
10059 | /**
|
10060 | * Creates a function that invokes `func` with the `this` binding of `thisArg`
|
10061 | * and `partials` prepended to the arguments it receives.
|
10062 | *
|
10063 | * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
10064 | * may be used as a placeholder for partially applied arguments.
|
10065 | *
|
10066 | * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
|
10067 | * property of bound functions.
|
10068 | *
|
10069 | * @static
|
10070 | * @memberOf _
|
10071 | * @since 0.1.0
|
10072 | * @category Function
|
10073 | * @param {Function} func The function to bind.
|
10074 | * @param {*} thisArg The `this` binding of `func`.
|
10075 | * @param {...*} [partials] The arguments to be partially applied.
|
10076 | * @returns {Function} Returns the new bound function.
|
10077 | * @example
|
10078 | *
|
10079 | * function greet(greeting, punctuation) {
|
10080 | * return greeting + ' ' + this.user + punctuation;
|
10081 | * }
|
10082 | *
|
10083 | * var object = { 'user': 'fred' };
|
10084 | *
|
10085 | * var bound = _.bind(greet, object, 'hi');
|
10086 | * bound('!');
|
10087 | * // => 'hi fred!'
|
10088 | *
|
10089 | * // Bound with placeholders.
|
10090 | * var bound = _.bind(greet, object, _, '!');
|
10091 | * bound('hi');
|
10092 | * // => 'hi fred!'
|
10093 | */
|
10094 | var bind = baseRest(function(func, thisArg, partials) {
|
10095 | var bitmask = WRAP_BIND_FLAG;
|
10096 | if (partials.length) {
|
10097 | var holders = replaceHolders(partials, getHolder(bind));
|
10098 | bitmask |= WRAP_PARTIAL_FLAG;
|
10099 | }
|
10100 | return createWrap(func, bitmask, thisArg, partials, holders);
|
10101 | });
|
10102 |
|
10103 | /**
|
10104 | * Creates a function that invokes the method at `object[key]` with `partials`
|
10105 | * prepended to the arguments it receives.
|
10106 | *
|
10107 | * This method differs from `_.bind` by allowing bound functions to reference
|
10108 | * methods that may be redefined or don't yet exist. See
|
10109 | * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
|
10110 | * for more details.
|
10111 | *
|
10112 | * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
10113 | * builds, may be used as a placeholder for partially applied arguments.
|
10114 | *
|
10115 | * @static
|
10116 | * @memberOf _
|
10117 | * @since 0.10.0
|
10118 | * @category Function
|
10119 | * @param {Object} object The object to invoke the method on.
|
10120 | * @param {string} key The key of the method.
|
10121 | * @param {...*} [partials] The arguments to be partially applied.
|
10122 | * @returns {Function} Returns the new bound function.
|
10123 | * @example
|
10124 | *
|
10125 | * var object = {
|
10126 | * 'user': 'fred',
|
10127 | * 'greet': function(greeting, punctuation) {
|
10128 | * return greeting + ' ' + this.user + punctuation;
|
10129 | * }
|
10130 | * };
|
10131 | *
|
10132 | * var bound = _.bindKey(object, 'greet', 'hi');
|
10133 | * bound('!');
|
10134 | * // => 'hi fred!'
|
10135 | *
|
10136 | * object.greet = function(greeting, punctuation) {
|
10137 | * return greeting + 'ya ' + this.user + punctuation;
|
10138 | * };
|
10139 | *
|
10140 | * bound('!');
|
10141 | * // => 'hiya fred!'
|
10142 | *
|
10143 | * // Bound with placeholders.
|
10144 | * var bound = _.bindKey(object, 'greet', _, '!');
|
10145 | * bound('hi');
|
10146 | * // => 'hiya fred!'
|
10147 | */
|
10148 | var bindKey = baseRest(function(object, key, partials) {
|
10149 | var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
|
10150 | if (partials.length) {
|
10151 | var holders = replaceHolders(partials, getHolder(bindKey));
|
10152 | bitmask |= WRAP_PARTIAL_FLAG;
|
10153 | }
|
10154 | return createWrap(key, bitmask, object, partials, holders);
|
10155 | });
|
10156 |
|
10157 | /**
|
10158 | * Creates a function that accepts arguments of `func` and either invokes
|
10159 | * `func` returning its result, if at least `arity` number of arguments have
|
10160 | * been provided, or returns a function that accepts the remaining `func`
|
10161 | * arguments, and so on. The arity of `func` may be specified if `func.length`
|
10162 | * is not sufficient.
|
10163 | *
|
10164 | * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
10165 | * may be used as a placeholder for provided arguments.
|
10166 | *
|
10167 | * **Note:** This method doesn't set the "length" property of curried functions.
|
10168 | *
|
10169 | * @static
|
10170 | * @memberOf _
|
10171 | * @since 2.0.0
|
10172 | * @category Function
|
10173 | * @param {Function} func The function to curry.
|
10174 | * @param {number} [arity=func.length] The arity of `func`.
|
10175 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
10176 | * @returns {Function} Returns the new curried function.
|
10177 | * @example
|
10178 | *
|
10179 | * var abc = function(a, b, c) {
|
10180 | * return [a, b, c];
|
10181 | * };
|
10182 | *
|
10183 | * var curried = _.curry(abc);
|
10184 | *
|
10185 | * curried(1)(2)(3);
|
10186 | * // => [1, 2, 3]
|
10187 | *
|
10188 | * curried(1, 2)(3);
|
10189 | * // => [1, 2, 3]
|
10190 | *
|
10191 | * curried(1, 2, 3);
|
10192 | * // => [1, 2, 3]
|
10193 | *
|
10194 | * // Curried with placeholders.
|
10195 | * curried(1)(_, 3)(2);
|
10196 | * // => [1, 2, 3]
|
10197 | */
|
10198 | function curry(func, arity, guard) {
|
10199 | arity = guard ? undefined : arity;
|
10200 | var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
10201 | result.placeholder = curry.placeholder;
|
10202 | return result;
|
10203 | }
|
10204 |
|
10205 | /**
|
10206 | * This method is like `_.curry` except that arguments are applied to `func`
|
10207 | * in the manner of `_.partialRight` instead of `_.partial`.
|
10208 | *
|
10209 | * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
10210 | * builds, may be used as a placeholder for provided arguments.
|
10211 | *
|
10212 | * **Note:** This method doesn't set the "length" property of curried functions.
|
10213 | *
|
10214 | * @static
|
10215 | * @memberOf _
|
10216 | * @since 3.0.0
|
10217 | * @category Function
|
10218 | * @param {Function} func The function to curry.
|
10219 | * @param {number} [arity=func.length] The arity of `func`.
|
10220 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
10221 | * @returns {Function} Returns the new curried function.
|
10222 | * @example
|
10223 | *
|
10224 | * var abc = function(a, b, c) {
|
10225 | * return [a, b, c];
|
10226 | * };
|
10227 | *
|
10228 | * var curried = _.curryRight(abc);
|
10229 | *
|
10230 | * curried(3)(2)(1);
|
10231 | * // => [1, 2, 3]
|
10232 | *
|
10233 | * curried(2, 3)(1);
|
10234 | * // => [1, 2, 3]
|
10235 | *
|
10236 | * curried(1, 2, 3);
|
10237 | * // => [1, 2, 3]
|
10238 | *
|
10239 | * // Curried with placeholders.
|
10240 | * curried(3)(1, _)(2);
|
10241 | * // => [1, 2, 3]
|
10242 | */
|
10243 | function curryRight(func, arity, guard) {
|
10244 | arity = guard ? undefined : arity;
|
10245 | var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
10246 | result.placeholder = curryRight.placeholder;
|
10247 | return result;
|
10248 | }
|
10249 |
|
10250 | /**
|
10251 | * Creates a debounced function that delays invoking `func` until after `wait`
|
10252 | * milliseconds have elapsed since the last time the debounced function was
|
10253 | * invoked. The debounced function comes with a `cancel` method to cancel
|
10254 | * delayed `func` invocations and a `flush` method to immediately invoke them.
|
10255 | * Provide `options` to indicate whether `func` should be invoked on the
|
10256 | * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
|
10257 | * with the last arguments provided to the debounced function. Subsequent
|
10258 | * calls to the debounced function return the result of the last `func`
|
10259 | * invocation.
|
10260 | *
|
10261 | * **Note:** If `leading` and `trailing` options are `true`, `func` is
|
10262 | * invoked on the trailing edge of the timeout only if the debounced function
|
10263 | * is invoked more than once during the `wait` timeout.
|
10264 | *
|
10265 | * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
10266 | * until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
10267 | *
|
10268 | * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
10269 | * for details over the differences between `_.debounce` and `_.throttle`.
|
10270 | *
|
10271 | * @static
|
10272 | * @memberOf _
|
10273 | * @since 0.1.0
|
10274 | * @category Function
|
10275 | * @param {Function} func The function to debounce.
|
10276 | * @param {number} [wait=0] The number of milliseconds to delay.
|
10277 | * @param {Object} [options={}] The options object.
|
10278 | * @param {boolean} [options.leading=false]
|
10279 | * Specify invoking on the leading edge of the timeout.
|
10280 | * @param {number} [options.maxWait]
|
10281 | * The maximum time `func` is allowed to be delayed before it's invoked.
|
10282 | * @param {boolean} [options.trailing=true]
|
10283 | * Specify invoking on the trailing edge of the timeout.
|
10284 | * @returns {Function} Returns the new debounced function.
|
10285 | * @example
|
10286 | *
|
10287 | * // Avoid costly calculations while the window size is in flux.
|
10288 | * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
|
10289 | *
|
10290 | * // Invoke `sendMail` when clicked, debouncing subsequent calls.
|
10291 | * jQuery(element).on('click', _.debounce(sendMail, 300, {
|
10292 | * 'leading': true,
|
10293 | * 'trailing': false
|
10294 | * }));
|
10295 | *
|
10296 | * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
|
10297 | * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
|
10298 | * var source = new EventSource('/stream');
|
10299 | * jQuery(source).on('message', debounced);
|
10300 | *
|
10301 | * // Cancel the trailing debounced invocation.
|
10302 | * jQuery(window).on('popstate', debounced.cancel);
|
10303 | */
|
10304 | function debounce(func, wait, options) {
|
10305 | var lastArgs,
|
10306 | lastThis,
|
10307 | maxWait,
|
10308 | result,
|
10309 | timerId,
|
10310 | lastCallTime,
|
10311 | lastInvokeTime = 0,
|
10312 | leading = false,
|
10313 | maxing = false,
|
10314 | trailing = true;
|
10315 |
|
10316 | if (typeof func != 'function') {
|
10317 | throw new TypeError(FUNC_ERROR_TEXT);
|
10318 | }
|
10319 | wait = toNumber(wait) || 0;
|
10320 | if (isObject(options)) {
|
10321 | leading = !!options.leading;
|
10322 | maxing = 'maxWait' in options;
|
10323 | maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
10324 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
10325 | }
|
10326 |
|
10327 | function invokeFunc(time) {
|
10328 | var args = lastArgs,
|
10329 | thisArg = lastThis;
|
10330 |
|
10331 | lastArgs = lastThis = undefined;
|
10332 | lastInvokeTime = time;
|
10333 | result = func.apply(thisArg, args);
|
10334 | return result;
|
10335 | }
|
10336 |
|
10337 | function leadingEdge(time) {
|
10338 | // Reset any `maxWait` timer.
|
10339 | lastInvokeTime = time;
|
10340 | // Start the timer for the trailing edge.
|
10341 | timerId = setTimeout(timerExpired, wait);
|
10342 | // Invoke the leading edge.
|
10343 | return leading ? invokeFunc(time) : result;
|
10344 | }
|
10345 |
|
10346 | function remainingWait(time) {
|
10347 | var timeSinceLastCall = time - lastCallTime,
|
10348 | timeSinceLastInvoke = time - lastInvokeTime,
|
10349 | timeWaiting = wait - timeSinceLastCall;
|
10350 |
|
10351 | return maxing
|
10352 | ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
|
10353 | : timeWaiting;
|
10354 | }
|
10355 |
|
10356 | function shouldInvoke(time) {
|
10357 | var timeSinceLastCall = time - lastCallTime,
|
10358 | timeSinceLastInvoke = time - lastInvokeTime;
|
10359 |
|
10360 | // Either this is the first call, activity has stopped and we're at the
|
10361 | // trailing edge, the system time has gone backwards and we're treating
|
10362 | // it as the trailing edge, or we've hit the `maxWait` limit.
|
10363 | return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
|
10364 | (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
|
10365 | }
|
10366 |
|
10367 | function timerExpired() {
|
10368 | var time = now();
|
10369 | if (shouldInvoke(time)) {
|
10370 | return trailingEdge(time);
|
10371 | }
|
10372 | // Restart the timer.
|
10373 | timerId = setTimeout(timerExpired, remainingWait(time));
|
10374 | }
|
10375 |
|
10376 | function trailingEdge(time) {
|
10377 | timerId = undefined;
|
10378 |
|
10379 | // Only invoke if we have `lastArgs` which means `func` has been
|
10380 | // debounced at least once.
|
10381 | if (trailing && lastArgs) {
|
10382 | return invokeFunc(time);
|
10383 | }
|
10384 | lastArgs = lastThis = undefined;
|
10385 | return result;
|
10386 | }
|
10387 |
|
10388 | function cancel() {
|
10389 | if (timerId !== undefined) {
|
10390 | clearTimeout(timerId);
|
10391 | }
|
10392 | lastInvokeTime = 0;
|
10393 | lastArgs = lastCallTime = lastThis = timerId = undefined;
|
10394 | }
|
10395 |
|
10396 | function flush() {
|
10397 | return timerId === undefined ? result : trailingEdge(now());
|
10398 | }
|
10399 |
|
10400 | function debounced() {
|
10401 | var time = now(),
|
10402 | isInvoking = shouldInvoke(time);
|
10403 |
|
10404 | lastArgs = arguments;
|
10405 | lastThis = this;
|
10406 | lastCallTime = time;
|
10407 |
|
10408 | if (isInvoking) {
|
10409 | if (timerId === undefined) {
|
10410 | return leadingEdge(lastCallTime);
|
10411 | }
|
10412 | if (maxing) {
|
10413 | // Handle invocations in a tight loop.
|
10414 | timerId = setTimeout(timerExpired, wait);
|
10415 | return invokeFunc(lastCallTime);
|
10416 | }
|
10417 | }
|
10418 | if (timerId === undefined) {
|
10419 | timerId = setTimeout(timerExpired, wait);
|
10420 | }
|
10421 | return result;
|
10422 | }
|
10423 | debounced.cancel = cancel;
|
10424 | debounced.flush = flush;
|
10425 | return debounced;
|
10426 | }
|
10427 |
|
10428 | /**
|
10429 | * Defers invoking the `func` until the current call stack has cleared. Any
|
10430 | * additional arguments are provided to `func` when it's invoked.
|
10431 | *
|
10432 | * @static
|
10433 | * @memberOf _
|
10434 | * @since 0.1.0
|
10435 | * @category Function
|
10436 | * @param {Function} func The function to defer.
|
10437 | * @param {...*} [args] The arguments to invoke `func` with.
|
10438 | * @returns {number} Returns the timer id.
|
10439 | * @example
|
10440 | *
|
10441 | * _.defer(function(text) {
|
10442 | * console.log(text);
|
10443 | * }, 'deferred');
|
10444 | * // => Logs 'deferred' after one millisecond.
|
10445 | */
|
10446 | var defer = baseRest(function(func, args) {
|
10447 | return baseDelay(func, 1, args);
|
10448 | });
|
10449 |
|
10450 | /**
|
10451 | * Invokes `func` after `wait` milliseconds. Any additional arguments are
|
10452 | * provided to `func` when it's invoked.
|
10453 | *
|
10454 | * @static
|
10455 | * @memberOf _
|
10456 | * @since 0.1.0
|
10457 | * @category Function
|
10458 | * @param {Function} func The function to delay.
|
10459 | * @param {number} wait The number of milliseconds to delay invocation.
|
10460 | * @param {...*} [args] The arguments to invoke `func` with.
|
10461 | * @returns {number} Returns the timer id.
|
10462 | * @example
|
10463 | *
|
10464 | * _.delay(function(text) {
|
10465 | * console.log(text);
|
10466 | * }, 1000, 'later');
|
10467 | * // => Logs 'later' after one second.
|
10468 | */
|
10469 | var delay = baseRest(function(func, wait, args) {
|
10470 | return baseDelay(func, toNumber(wait) || 0, args);
|
10471 | });
|
10472 |
|
10473 | /**
|
10474 | * Creates a function that invokes `func` with arguments reversed.
|
10475 | *
|
10476 | * @static
|
10477 | * @memberOf _
|
10478 | * @since 4.0.0
|
10479 | * @category Function
|
10480 | * @param {Function} func The function to flip arguments for.
|
10481 | * @returns {Function} Returns the new flipped function.
|
10482 | * @example
|
10483 | *
|
10484 | * var flipped = _.flip(function() {
|
10485 | * return _.toArray(arguments);
|
10486 | * });
|
10487 | *
|
10488 | * flipped('a', 'b', 'c', 'd');
|
10489 | * // => ['d', 'c', 'b', 'a']
|
10490 | */
|
10491 | function flip(func) {
|
10492 | return createWrap(func, WRAP_FLIP_FLAG);
|
10493 | }
|
10494 |
|
10495 | /**
|
10496 | * Creates a function that memoizes the result of `func`. If `resolver` is
|
10497 | * provided, it determines the cache key for storing the result based on the
|
10498 | * arguments provided to the memoized function. By default, the first argument
|
10499 | * provided to the memoized function is used as the map cache key. The `func`
|
10500 | * is invoked with the `this` binding of the memoized function.
|
10501 | *
|
10502 | * **Note:** The cache is exposed as the `cache` property on the memoized
|
10503 | * function. Its creation may be customized by replacing the `_.memoize.Cache`
|
10504 | * constructor with one whose instances implement the
|
10505 | * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
|
10506 | * method interface of `clear`, `delete`, `get`, `has`, and `set`.
|
10507 | *
|
10508 | * @static
|
10509 | * @memberOf _
|
10510 | * @since 0.1.0
|
10511 | * @category Function
|
10512 | * @param {Function} func The function to have its output memoized.
|
10513 | * @param {Function} [resolver] The function to resolve the cache key.
|
10514 | * @returns {Function} Returns the new memoized function.
|
10515 | * @example
|
10516 | *
|
10517 | * var object = { 'a': 1, 'b': 2 };
|
10518 | * var other = { 'c': 3, 'd': 4 };
|
10519 | *
|
10520 | * var values = _.memoize(_.values);
|
10521 | * values(object);
|
10522 | * // => [1, 2]
|
10523 | *
|
10524 | * values(other);
|
10525 | * // => [3, 4]
|
10526 | *
|
10527 | * object.a = 2;
|
10528 | * values(object);
|
10529 | * // => [1, 2]
|
10530 | *
|
10531 | * // Modify the result cache.
|
10532 | * values.cache.set(object, ['a', 'b']);
|
10533 | * values(object);
|
10534 | * // => ['a', 'b']
|
10535 | *
|
10536 | * // Replace `_.memoize.Cache`.
|
10537 | * _.memoize.Cache = WeakMap;
|
10538 | */
|
10539 | function memoize(func, resolver) {
|
10540 | if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
10541 | throw new TypeError(FUNC_ERROR_TEXT);
|
10542 | }
|
10543 | var memoized = function() {
|
10544 | var args = arguments,
|
10545 | key = resolver ? resolver.apply(this, args) : args[0],
|
10546 | cache = memoized.cache;
|
10547 |
|
10548 | if (cache.has(key)) {
|
10549 | return cache.get(key);
|
10550 | }
|
10551 | var result = func.apply(this, args);
|
10552 | memoized.cache = cache.set(key, result) || cache;
|
10553 | return result;
|
10554 | };
|
10555 | memoized.cache = new (memoize.Cache || MapCache);
|
10556 | return memoized;
|
10557 | }
|
10558 |
|
10559 | // Expose `MapCache`.
|
10560 | memoize.Cache = MapCache;
|
10561 |
|
10562 | /**
|
10563 | * Creates a function that negates the result of the predicate `func`. The
|
10564 | * `func` predicate is invoked with the `this` binding and arguments of the
|
10565 | * created function.
|
10566 | *
|
10567 | * @static
|
10568 | * @memberOf _
|
10569 | * @since 3.0.0
|
10570 | * @category Function
|
10571 | * @param {Function} predicate The predicate to negate.
|
10572 | * @returns {Function} Returns the new negated function.
|
10573 | * @example
|
10574 | *
|
10575 | * function isEven(n) {
|
10576 | * return n % 2 == 0;
|
10577 | * }
|
10578 | *
|
10579 | * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
|
10580 | * // => [1, 3, 5]
|
10581 | */
|
10582 | function negate(predicate) {
|
10583 | if (typeof predicate != 'function') {
|
10584 | throw new TypeError(FUNC_ERROR_TEXT);
|
10585 | }
|
10586 | return function() {
|
10587 | var args = arguments;
|
10588 | switch (args.length) {
|
10589 | case 0: return !predicate.call(this);
|
10590 | case 1: return !predicate.call(this, args[0]);
|
10591 | case 2: return !predicate.call(this, args[0], args[1]);
|
10592 | case 3: return !predicate.call(this, args[0], args[1], args[2]);
|
10593 | }
|
10594 | return !predicate.apply(this, args);
|
10595 | };
|
10596 | }
|
10597 |
|
10598 | /**
|
10599 | * Creates a function that is restricted to invoking `func` once. Repeat calls
|
10600 | * to the function return the value of the first invocation. The `func` is
|
10601 | * invoked with the `this` binding and arguments of the created function.
|
10602 | *
|
10603 | * @static
|
10604 | * @memberOf _
|
10605 | * @since 0.1.0
|
10606 | * @category Function
|
10607 | * @param {Function} func The function to restrict.
|
10608 | * @returns {Function} Returns the new restricted function.
|
10609 | * @example
|
10610 | *
|
10611 | * var initialize = _.once(createApplication);
|
10612 | * initialize();
|
10613 | * initialize();
|
10614 | * // => `createApplication` is invoked once
|
10615 | */
|
10616 | function once(func) {
|
10617 | return before(2, func);
|
10618 | }
|
10619 |
|
10620 | /**
|
10621 | * Creates a function that invokes `func` with its arguments transformed.
|
10622 | *
|
10623 | * @static
|
10624 | * @since 4.0.0
|
10625 | * @memberOf _
|
10626 | * @category Function
|
10627 | * @param {Function} func The function to wrap.
|
10628 | * @param {...(Function|Function[])} [transforms=[_.identity]]
|
10629 | * The argument transforms.
|
10630 | * @returns {Function} Returns the new function.
|
10631 | * @example
|
10632 | *
|
10633 | * function doubled(n) {
|
10634 | * return n * 2;
|
10635 | * }
|
10636 | *
|
10637 | * function square(n) {
|
10638 | * return n * n;
|
10639 | * }
|
10640 | *
|
10641 | * var func = _.overArgs(function(x, y) {
|
10642 | * return [x, y];
|
10643 | * }, [square, doubled]);
|
10644 | *
|
10645 | * func(9, 3);
|
10646 | * // => [81, 6]
|
10647 | *
|
10648 | * func(10, 5);
|
10649 | * // => [100, 10]
|
10650 | */
|
10651 | var overArgs = castRest(function(func, transforms) {
|
10652 | transforms = (transforms.length == 1 && isArray(transforms[0]))
|
10653 | ? arrayMap(transforms[0], baseUnary(getIteratee()))
|
10654 | : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
|
10655 |
|
10656 | var funcsLength = transforms.length;
|
10657 | return baseRest(function(args) {
|
10658 | var index = -1,
|
10659 | length = nativeMin(args.length, funcsLength);
|
10660 |
|
10661 | while (++index < length) {
|
10662 | args[index] = transforms[index].call(this, args[index]);
|
10663 | }
|
10664 | return apply(func, this, args);
|
10665 | });
|
10666 | });
|
10667 |
|
10668 | /**
|
10669 | * Creates a function that invokes `func` with `partials` prepended to the
|
10670 | * arguments it receives. This method is like `_.bind` except it does **not**
|
10671 | * alter the `this` binding.
|
10672 | *
|
10673 | * The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
10674 | * builds, may be used as a placeholder for partially applied arguments.
|
10675 | *
|
10676 | * **Note:** This method doesn't set the "length" property of partially
|
10677 | * applied functions.
|
10678 | *
|
10679 | * @static
|
10680 | * @memberOf _
|
10681 | * @since 0.2.0
|
10682 | * @category Function
|
10683 | * @param {Function} func The function to partially apply arguments to.
|
10684 | * @param {...*} [partials] The arguments to be partially applied.
|
10685 | * @returns {Function} Returns the new partially applied function.
|
10686 | * @example
|
10687 | *
|
10688 | * function greet(greeting, name) {
|
10689 | * return greeting + ' ' + name;
|
10690 | * }
|
10691 | *
|
10692 | * var sayHelloTo = _.partial(greet, 'hello');
|
10693 | * sayHelloTo('fred');
|
10694 | * // => 'hello fred'
|
10695 | *
|
10696 | * // Partially applied with placeholders.
|
10697 | * var greetFred = _.partial(greet, _, 'fred');
|
10698 | * greetFred('hi');
|
10699 | * // => 'hi fred'
|
10700 | */
|
10701 | var partial = baseRest(function(func, partials) {
|
10702 | var holders = replaceHolders(partials, getHolder(partial));
|
10703 | return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
|
10704 | });
|
10705 |
|
10706 | /**
|
10707 | * This method is like `_.partial` except that partially applied arguments
|
10708 | * are appended to the arguments it receives.
|
10709 | *
|
10710 | * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
10711 | * builds, may be used as a placeholder for partially applied arguments.
|
10712 | *
|
10713 | * **Note:** This method doesn't set the "length" property of partially
|
10714 | * applied functions.
|
10715 | *
|
10716 | * @static
|
10717 | * @memberOf _
|
10718 | * @since 1.0.0
|
10719 | * @category Function
|
10720 | * @param {Function} func The function to partially apply arguments to.
|
10721 | * @param {...*} [partials] The arguments to be partially applied.
|
10722 | * @returns {Function} Returns the new partially applied function.
|
10723 | * @example
|
10724 | *
|
10725 | * function greet(greeting, name) {
|
10726 | * return greeting + ' ' + name;
|
10727 | * }
|
10728 | *
|
10729 | * var greetFred = _.partialRight(greet, 'fred');
|
10730 | * greetFred('hi');
|
10731 | * // => 'hi fred'
|
10732 | *
|
10733 | * // Partially applied with placeholders.
|
10734 | * var sayHelloTo = _.partialRight(greet, 'hello', _);
|
10735 | * sayHelloTo('fred');
|
10736 | * // => 'hello fred'
|
10737 | */
|
10738 | var partialRight = baseRest(function(func, partials) {
|
10739 | var holders = replaceHolders(partials, getHolder(partialRight));
|
10740 | return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
|
10741 | });
|
10742 |
|
10743 | /**
|
10744 | * Creates a function that invokes `func` with arguments arranged according
|
10745 | * to the specified `indexes` where the argument value at the first index is
|
10746 | * provided as the first argument, the argument value at the second index is
|
10747 | * provided as the second argument, and so on.
|
10748 | *
|
10749 | * @static
|
10750 | * @memberOf _
|
10751 | * @since 3.0.0
|
10752 | * @category Function
|
10753 | * @param {Function} func The function to rearrange arguments for.
|
10754 | * @param {...(number|number[])} indexes The arranged argument indexes.
|
10755 | * @returns {Function} Returns the new function.
|
10756 | * @example
|
10757 | *
|
10758 | * var rearged = _.rearg(function(a, b, c) {
|
10759 | * return [a, b, c];
|
10760 | * }, [2, 0, 1]);
|
10761 | *
|
10762 | * rearged('b', 'c', 'a')
|
10763 | * // => ['a', 'b', 'c']
|
10764 | */
|
10765 | var rearg = flatRest(function(func, indexes) {
|
10766 | return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
|
10767 | });
|
10768 |
|
10769 | /**
|
10770 | * Creates a function that invokes `func` with the `this` binding of the
|
10771 | * created function and arguments from `start` and beyond provided as
|
10772 | * an array.
|
10773 | *
|
10774 | * **Note:** This method is based on the
|
10775 | * [rest parameter](https://mdn.io/rest_parameters).
|
10776 | *
|
10777 | * @static
|
10778 | * @memberOf _
|
10779 | * @since 4.0.0
|
10780 | * @category Function
|
10781 | * @param {Function} func The function to apply a rest parameter to.
|
10782 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
10783 | * @returns {Function} Returns the new function.
|
10784 | * @example
|
10785 | *
|
10786 | * var say = _.rest(function(what, names) {
|
10787 | * return what + ' ' + _.initial(names).join(', ') +
|
10788 | * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
10789 | * });
|
10790 | *
|
10791 | * say('hello', 'fred', 'barney', 'pebbles');
|
10792 | * // => 'hello fred, barney, & pebbles'
|
10793 | */
|
10794 | function rest(func, start) {
|
10795 | if (typeof func != 'function') {
|
10796 | throw new TypeError(FUNC_ERROR_TEXT);
|
10797 | }
|
10798 | start = start === undefined ? start : toInteger(start);
|
10799 | return baseRest(func, start);
|
10800 | }
|
10801 |
|
10802 | /**
|
10803 | * Creates a function that invokes `func` with the `this` binding of the
|
10804 | * create function and an array of arguments much like
|
10805 | * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
|
10806 | *
|
10807 | * **Note:** This method is based on the
|
10808 | * [spread operator](https://mdn.io/spread_operator).
|
10809 | *
|
10810 | * @static
|
10811 | * @memberOf _
|
10812 | * @since 3.2.0
|
10813 | * @category Function
|
10814 | * @param {Function} func The function to spread arguments over.
|
10815 | * @param {number} [start=0] The start position of the spread.
|
10816 | * @returns {Function} Returns the new function.
|
10817 | * @example
|
10818 | *
|
10819 | * var say = _.spread(function(who, what) {
|
10820 | * return who + ' says ' + what;
|
10821 | * });
|
10822 | *
|
10823 | * say(['fred', 'hello']);
|
10824 | * // => 'fred says hello'
|
10825 | *
|
10826 | * var numbers = Promise.all([
|
10827 | * Promise.resolve(40),
|
10828 | * Promise.resolve(36)
|
10829 | * ]);
|
10830 | *
|
10831 | * numbers.then(_.spread(function(x, y) {
|
10832 | * return x + y;
|
10833 | * }));
|
10834 | * // => a Promise of 76
|
10835 | */
|
10836 | function spread(func, start) {
|
10837 | if (typeof func != 'function') {
|
10838 | throw new TypeError(FUNC_ERROR_TEXT);
|
10839 | }
|
10840 | start = start == null ? 0 : nativeMax(toInteger(start), 0);
|
10841 | return baseRest(function(args) {
|
10842 | var array = args[start],
|
10843 | otherArgs = castSlice(args, 0, start);
|
10844 |
|
10845 | if (array) {
|
10846 | arrayPush(otherArgs, array);
|
10847 | }
|
10848 | return apply(func, this, otherArgs);
|
10849 | });
|
10850 | }
|
10851 |
|
10852 | /**
|
10853 | * Creates a throttled function that only invokes `func` at most once per
|
10854 | * every `wait` milliseconds. The throttled function comes with a `cancel`
|
10855 | * method to cancel delayed `func` invocations and a `flush` method to
|
10856 | * immediately invoke them. Provide `options` to indicate whether `func`
|
10857 | * should be invoked on the leading and/or trailing edge of the `wait`
|
10858 | * timeout. The `func` is invoked with the last arguments provided to the
|
10859 | * throttled function. Subsequent calls to the throttled function return the
|
10860 | * result of the last `func` invocation.
|
10861 | *
|
10862 | * **Note:** If `leading` and `trailing` options are `true`, `func` is
|
10863 | * invoked on the trailing edge of the timeout only if the throttled function
|
10864 | * is invoked more than once during the `wait` timeout.
|
10865 | *
|
10866 | * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
10867 | * until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
10868 | *
|
10869 | * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
10870 | * for details over the differences between `_.throttle` and `_.debounce`.
|
10871 | *
|
10872 | * @static
|
10873 | * @memberOf _
|
10874 | * @since 0.1.0
|
10875 | * @category Function
|
10876 | * @param {Function} func The function to throttle.
|
10877 | * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
10878 | * @param {Object} [options={}] The options object.
|
10879 | * @param {boolean} [options.leading=true]
|
10880 | * Specify invoking on the leading edge of the timeout.
|
10881 | * @param {boolean} [options.trailing=true]
|
10882 | * Specify invoking on the trailing edge of the timeout.
|
10883 | * @returns {Function} Returns the new throttled function.
|
10884 | * @example
|
10885 | *
|
10886 | * // Avoid excessively updating the position while scrolling.
|
10887 | * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
10888 | *
|
10889 | * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
10890 | * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
10891 | * jQuery(element).on('click', throttled);
|
10892 | *
|
10893 | * // Cancel the trailing throttled invocation.
|
10894 | * jQuery(window).on('popstate', throttled.cancel);
|
10895 | */
|
10896 | function throttle(func, wait, options) {
|
10897 | var leading = true,
|
10898 | trailing = true;
|
10899 |
|
10900 | if (typeof func != 'function') {
|
10901 | throw new TypeError(FUNC_ERROR_TEXT);
|
10902 | }
|
10903 | if (isObject(options)) {
|
10904 | leading = 'leading' in options ? !!options.leading : leading;
|
10905 | trailing = 'trailing' in options ? !!options.trailing : trailing;
|
10906 | }
|
10907 | return debounce(func, wait, {
|
10908 | 'leading': leading,
|
10909 | 'maxWait': wait,
|
10910 | 'trailing': trailing
|
10911 | });
|
10912 | }
|
10913 |
|
10914 | /**
|
10915 | * Creates a function that accepts up to one argument, ignoring any
|
10916 | * additional arguments.
|
10917 | *
|
10918 | * @static
|
10919 | * @memberOf _
|
10920 | * @since 4.0.0
|
10921 | * @category Function
|
10922 | * @param {Function} func The function to cap arguments for.
|
10923 | * @returns {Function} Returns the new capped function.
|
10924 | * @example
|
10925 | *
|
10926 | * _.map(['6', '8', '10'], _.unary(parseInt));
|
10927 | * // => [6, 8, 10]
|
10928 | */
|
10929 | function unary(func) {
|
10930 | return ary(func, 1);
|
10931 | }
|
10932 |
|
10933 | /**
|
10934 | * Creates a function that provides `value` to `wrapper` as its first
|
10935 | * argument. Any additional arguments provided to the function are appended
|
10936 | * to those provided to the `wrapper`. The wrapper is invoked with the `this`
|
10937 | * binding of the created function.
|
10938 | *
|
10939 | * @static
|
10940 | * @memberOf _
|
10941 | * @since 0.1.0
|
10942 | * @category Function
|
10943 | * @param {*} value The value to wrap.
|
10944 | * @param {Function} [wrapper=identity] The wrapper function.
|
10945 | * @returns {Function} Returns the new function.
|
10946 | * @example
|
10947 | *
|
10948 | * var p = _.wrap(_.escape, function(func, text) {
|
10949 | * return '<p>' + func(text) + '</p>';
|
10950 | * });
|
10951 | *
|
10952 | * p('fred, barney, & pebbles');
|
10953 | * // => '<p>fred, barney, & pebbles</p>'
|
10954 | */
|
10955 | function wrap(value, wrapper) {
|
10956 | return partial(castFunction(wrapper), value);
|
10957 | }
|
10958 |
|
10959 | /*------------------------------------------------------------------------*/
|
10960 |
|
10961 | /**
|
10962 | * Casts `value` as an array if it's not one.
|
10963 | *
|
10964 | * @static
|
10965 | * @memberOf _
|
10966 | * @since 4.4.0
|
10967 | * @category Lang
|
10968 | * @param {*} value The value to inspect.
|
10969 | * @returns {Array} Returns the cast array.
|
10970 | * @example
|
10971 | *
|
10972 | * _.castArray(1);
|
10973 | * // => [1]
|
10974 | *
|
10975 | * _.castArray({ 'a': 1 });
|
10976 | * // => [{ 'a': 1 }]
|
10977 | *
|
10978 | * _.castArray('abc');
|
10979 | * // => ['abc']
|
10980 | *
|
10981 | * _.castArray(null);
|
10982 | * // => [null]
|
10983 | *
|
10984 | * _.castArray(undefined);
|
10985 | * // => [undefined]
|
10986 | *
|
10987 | * _.castArray();
|
10988 | * // => []
|
10989 | *
|
10990 | * var array = [1, 2, 3];
|
10991 | * console.log(_.castArray(array) === array);
|
10992 | * // => true
|
10993 | */
|
10994 | function castArray() {
|
10995 | if (!arguments.length) {
|
10996 | return [];
|
10997 | }
|
10998 | var value = arguments[0];
|
10999 | return isArray(value) ? value : [value];
|
11000 | }
|
11001 |
|
11002 | /**
|
11003 | * Creates a shallow clone of `value`.
|
11004 | *
|
11005 | * **Note:** This method is loosely based on the
|
11006 | * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
|
11007 | * and supports cloning arrays, array buffers, booleans, date objects, maps,
|
11008 | * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
|
11009 | * arrays. The own enumerable properties of `arguments` objects are cloned
|
11010 | * as plain objects. An empty object is returned for uncloneable values such
|
11011 | * as error objects, functions, DOM nodes, and WeakMaps.
|
11012 | *
|
11013 | * @static
|
11014 | * @memberOf _
|
11015 | * @since 0.1.0
|
11016 | * @category Lang
|
11017 | * @param {*} value The value to clone.
|
11018 | * @returns {*} Returns the cloned value.
|
11019 | * @see _.cloneDeep
|
11020 | * @example
|
11021 | *
|
11022 | * var objects = [{ 'a': 1 }, { 'b': 2 }];
|
11023 | *
|
11024 | * var shallow = _.clone(objects);
|
11025 | * console.log(shallow[0] === objects[0]);
|
11026 | * // => true
|
11027 | */
|
11028 | function clone(value) {
|
11029 | return baseClone(value, CLONE_SYMBOLS_FLAG);
|
11030 | }
|
11031 |
|
11032 | /**
|
11033 | * This method is like `_.clone` except that it accepts `customizer` which
|
11034 | * is invoked to produce the cloned value. If `customizer` returns `undefined`,
|
11035 | * cloning is handled by the method instead. The `customizer` is invoked with
|
11036 | * up to four arguments; (value [, index|key, object, stack]).
|
11037 | *
|
11038 | * @static
|
11039 | * @memberOf _
|
11040 | * @since 4.0.0
|
11041 | * @category Lang
|
11042 | * @param {*} value The value to clone.
|
11043 | * @param {Function} [customizer] The function to customize cloning.
|
11044 | * @returns {*} Returns the cloned value.
|
11045 | * @see _.cloneDeepWith
|
11046 | * @example
|
11047 | *
|
11048 | * function customizer(value) {
|
11049 | * if (_.isElement(value)) {
|
11050 | * return value.cloneNode(false);
|
11051 | * }
|
11052 | * }
|
11053 | *
|
11054 | * var el = _.cloneWith(document.body, customizer);
|
11055 | *
|
11056 | * console.log(el === document.body);
|
11057 | * // => false
|
11058 | * console.log(el.nodeName);
|
11059 | * // => 'BODY'
|
11060 | * console.log(el.childNodes.length);
|
11061 | * // => 0
|
11062 | */
|
11063 | function cloneWith(value, customizer) {
|
11064 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
11065 | return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
|
11066 | }
|
11067 |
|
11068 | /**
|
11069 | * This method is like `_.clone` except that it recursively clones `value`.
|
11070 | *
|
11071 | * @static
|
11072 | * @memberOf _
|
11073 | * @since 1.0.0
|
11074 | * @category Lang
|
11075 | * @param {*} value The value to recursively clone.
|
11076 | * @returns {*} Returns the deep cloned value.
|
11077 | * @see _.clone
|
11078 | * @example
|
11079 | *
|
11080 | * var objects = [{ 'a': 1 }, { 'b': 2 }];
|
11081 | *
|
11082 | * var deep = _.cloneDeep(objects);
|
11083 | * console.log(deep[0] === objects[0]);
|
11084 | * // => false
|
11085 | */
|
11086 | function cloneDeep(value) {
|
11087 | return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
|
11088 | }
|
11089 |
|
11090 | /**
|
11091 | * This method is like `_.cloneWith` except that it recursively clones `value`.
|
11092 | *
|
11093 | * @static
|
11094 | * @memberOf _
|
11095 | * @since 4.0.0
|
11096 | * @category Lang
|
11097 | * @param {*} value The value to recursively clone.
|
11098 | * @param {Function} [customizer] The function to customize cloning.
|
11099 | * @returns {*} Returns the deep cloned value.
|
11100 | * @see _.cloneWith
|
11101 | * @example
|
11102 | *
|
11103 | * function customizer(value) {
|
11104 | * if (_.isElement(value)) {
|
11105 | * return value.cloneNode(true);
|
11106 | * }
|
11107 | * }
|
11108 | *
|
11109 | * var el = _.cloneDeepWith(document.body, customizer);
|
11110 | *
|
11111 | * console.log(el === document.body);
|
11112 | * // => false
|
11113 | * console.log(el.nodeName);
|
11114 | * // => 'BODY'
|
11115 | * console.log(el.childNodes.length);
|
11116 | * // => 20
|
11117 | */
|
11118 | function cloneDeepWith(value, customizer) {
|
11119 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
11120 | return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
|
11121 | }
|
11122 |
|
11123 | /**
|
11124 | * Checks if `object` conforms to `source` by invoking the predicate
|
11125 | * properties of `source` with the corresponding property values of `object`.
|
11126 | *
|
11127 | * **Note:** This method is equivalent to `_.conforms` when `source` is
|
11128 | * partially applied.
|
11129 | *
|
11130 | * @static
|
11131 | * @memberOf _
|
11132 | * @since 4.14.0
|
11133 | * @category Lang
|
11134 | * @param {Object} object The object to inspect.
|
11135 | * @param {Object} source The object of property predicates to conform to.
|
11136 | * @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
11137 | * @example
|
11138 | *
|
11139 | * var object = { 'a': 1, 'b': 2 };
|
11140 | *
|
11141 | * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
|
11142 | * // => true
|
11143 | *
|
11144 | * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
|
11145 | * // => false
|
11146 | */
|
11147 | function conformsTo(object, source) {
|
11148 | return source == null || baseConformsTo(object, source, keys(source));
|
11149 | }
|
11150 |
|
11151 | /**
|
11152 | * Performs a
|
11153 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
11154 | * comparison between two values to determine if they are equivalent.
|
11155 | *
|
11156 | * @static
|
11157 | * @memberOf _
|
11158 | * @since 4.0.0
|
11159 | * @category Lang
|
11160 | * @param {*} value The value to compare.
|
11161 | * @param {*} other The other value to compare.
|
11162 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
11163 | * @example
|
11164 | *
|
11165 | * var object = { 'a': 1 };
|
11166 | * var other = { 'a': 1 };
|
11167 | *
|
11168 | * _.eq(object, object);
|
11169 | * // => true
|
11170 | *
|
11171 | * _.eq(object, other);
|
11172 | * // => false
|
11173 | *
|
11174 | * _.eq('a', 'a');
|
11175 | * // => true
|
11176 | *
|
11177 | * _.eq('a', Object('a'));
|
11178 | * // => false
|
11179 | *
|
11180 | * _.eq(NaN, NaN);
|
11181 | * // => true
|
11182 | */
|
11183 | function eq(value, other) {
|
11184 | return value === other || (value !== value && other !== other);
|
11185 | }
|
11186 |
|
11187 | /**
|
11188 | * Checks if `value` is greater than `other`.
|
11189 | *
|
11190 | * @static
|
11191 | * @memberOf _
|
11192 | * @since 3.9.0
|
11193 | * @category Lang
|
11194 | * @param {*} value The value to compare.
|
11195 | * @param {*} other The other value to compare.
|
11196 | * @returns {boolean} Returns `true` if `value` is greater than `other`,
|
11197 | * else `false`.
|
11198 | * @see _.lt
|
11199 | * @example
|
11200 | *
|
11201 | * _.gt(3, 1);
|
11202 | * // => true
|
11203 | *
|
11204 | * _.gt(3, 3);
|
11205 | * // => false
|
11206 | *
|
11207 | * _.gt(1, 3);
|
11208 | * // => false
|
11209 | */
|
11210 | var gt = createRelationalOperation(baseGt);
|
11211 |
|
11212 | /**
|
11213 | * Checks if `value` is greater than or equal to `other`.
|
11214 | *
|
11215 | * @static
|
11216 | * @memberOf _
|
11217 | * @since 3.9.0
|
11218 | * @category Lang
|
11219 | * @param {*} value The value to compare.
|
11220 | * @param {*} other The other value to compare.
|
11221 | * @returns {boolean} Returns `true` if `value` is greater than or equal to
|
11222 | * `other`, else `false`.
|
11223 | * @see _.lte
|
11224 | * @example
|
11225 | *
|
11226 | * _.gte(3, 1);
|
11227 | * // => true
|
11228 | *
|
11229 | * _.gte(3, 3);
|
11230 | * // => true
|
11231 | *
|
11232 | * _.gte(1, 3);
|
11233 | * // => false
|
11234 | */
|
11235 | var gte = createRelationalOperation(function(value, other) {
|
11236 | return value >= other;
|
11237 | });
|
11238 |
|
11239 | /**
|
11240 | * Checks if `value` is likely an `arguments` object.
|
11241 | *
|
11242 | * @static
|
11243 | * @memberOf _
|
11244 | * @since 0.1.0
|
11245 | * @category Lang
|
11246 | * @param {*} value The value to check.
|
11247 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
11248 | * else `false`.
|
11249 | * @example
|
11250 | *
|
11251 | * _.isArguments(function() { return arguments; }());
|
11252 | * // => true
|
11253 | *
|
11254 | * _.isArguments([1, 2, 3]);
|
11255 | * // => false
|
11256 | */
|
11257 | var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
|
11258 | return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
|
11259 | !propertyIsEnumerable.call(value, 'callee');
|
11260 | };
|
11261 |
|
11262 | /**
|
11263 | * Checks if `value` is classified as an `Array` object.
|
11264 | *
|
11265 | * @static
|
11266 | * @memberOf _
|
11267 | * @since 0.1.0
|
11268 | * @category Lang
|
11269 | * @param {*} value The value to check.
|
11270 | * @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
11271 | * @example
|
11272 | *
|
11273 | * _.isArray([1, 2, 3]);
|
11274 | * // => true
|
11275 | *
|
11276 | * _.isArray(document.body.children);
|
11277 | * // => false
|
11278 | *
|
11279 | * _.isArray('abc');
|
11280 | * // => false
|
11281 | *
|
11282 | * _.isArray(_.noop);
|
11283 | * // => false
|
11284 | */
|
11285 | var isArray = Array.isArray;
|
11286 |
|
11287 | /**
|
11288 | * Checks if `value` is classified as an `ArrayBuffer` object.
|
11289 | *
|
11290 | * @static
|
11291 | * @memberOf _
|
11292 | * @since 4.3.0
|
11293 | * @category Lang
|
11294 | * @param {*} value The value to check.
|
11295 | * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
|
11296 | * @example
|
11297 | *
|
11298 | * _.isArrayBuffer(new ArrayBuffer(2));
|
11299 | * // => true
|
11300 | *
|
11301 | * _.isArrayBuffer(new Array(2));
|
11302 | * // => false
|
11303 | */
|
11304 | var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
|
11305 |
|
11306 | /**
|
11307 | * Checks if `value` is array-like. A value is considered array-like if it's
|
11308 | * not a function and has a `value.length` that's an integer greater than or
|
11309 | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
11310 | *
|
11311 | * @static
|
11312 | * @memberOf _
|
11313 | * @since 4.0.0
|
11314 | * @category Lang
|
11315 | * @param {*} value The value to check.
|
11316 | * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
11317 | * @example
|
11318 | *
|
11319 | * _.isArrayLike([1, 2, 3]);
|
11320 | * // => true
|
11321 | *
|
11322 | * _.isArrayLike(document.body.children);
|
11323 | * // => true
|
11324 | *
|
11325 | * _.isArrayLike('abc');
|
11326 | * // => true
|
11327 | *
|
11328 | * _.isArrayLike(_.noop);
|
11329 | * // => false
|
11330 | */
|
11331 | function isArrayLike(value) {
|
11332 | return value != null && isLength(value.length) && !isFunction(value);
|
11333 | }
|
11334 |
|
11335 | /**
|
11336 | * This method is like `_.isArrayLike` except that it also checks if `value`
|
11337 | * is an object.
|
11338 | *
|
11339 | * @static
|
11340 | * @memberOf _
|
11341 | * @since 4.0.0
|
11342 | * @category Lang
|
11343 | * @param {*} value The value to check.
|
11344 | * @returns {boolean} Returns `true` if `value` is an array-like object,
|
11345 | * else `false`.
|
11346 | * @example
|
11347 | *
|
11348 | * _.isArrayLikeObject([1, 2, 3]);
|
11349 | * // => true
|
11350 | *
|
11351 | * _.isArrayLikeObject(document.body.children);
|
11352 | * // => true
|
11353 | *
|
11354 | * _.isArrayLikeObject('abc');
|
11355 | * // => false
|
11356 | *
|
11357 | * _.isArrayLikeObject(_.noop);
|
11358 | * // => false
|
11359 | */
|
11360 | function isArrayLikeObject(value) {
|
11361 | return isObjectLike(value) && isArrayLike(value);
|
11362 | }
|
11363 |
|
11364 | /**
|
11365 | * Checks if `value` is classified as a boolean primitive or object.
|
11366 | *
|
11367 | * @static
|
11368 | * @memberOf _
|
11369 | * @since 0.1.0
|
11370 | * @category Lang
|
11371 | * @param {*} value The value to check.
|
11372 | * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
|
11373 | * @example
|
11374 | *
|
11375 | * _.isBoolean(false);
|
11376 | * // => true
|
11377 | *
|
11378 | * _.isBoolean(null);
|
11379 | * // => false
|
11380 | */
|
11381 | function isBoolean(value) {
|
11382 | return value === true || value === false ||
|
11383 | (isObjectLike(value) && baseGetTag(value) == boolTag);
|
11384 | }
|
11385 |
|
11386 | /**
|
11387 | * Checks if `value` is a buffer.
|
11388 | *
|
11389 | * @static
|
11390 | * @memberOf _
|
11391 | * @since 4.3.0
|
11392 | * @category Lang
|
11393 | * @param {*} value The value to check.
|
11394 | * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
11395 | * @example
|
11396 | *
|
11397 | * _.isBuffer(new Buffer(2));
|
11398 | * // => true
|
11399 | *
|
11400 | * _.isBuffer(new Uint8Array(2));
|
11401 | * // => false
|
11402 | */
|
11403 | var isBuffer = nativeIsBuffer || stubFalse;
|
11404 |
|
11405 | /**
|
11406 | * Checks if `value` is classified as a `Date` object.
|
11407 | *
|
11408 | * @static
|
11409 | * @memberOf _
|
11410 | * @since 0.1.0
|
11411 | * @category Lang
|
11412 | * @param {*} value The value to check.
|
11413 | * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
|
11414 | * @example
|
11415 | *
|
11416 | * _.isDate(new Date);
|
11417 | * // => true
|
11418 | *
|
11419 | * _.isDate('Mon April 23 2012');
|
11420 | * // => false
|
11421 | */
|
11422 | var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
|
11423 |
|
11424 | /**
|
11425 | * Checks if `value` is likely a DOM element.
|
11426 | *
|
11427 | * @static
|
11428 | * @memberOf _
|
11429 | * @since 0.1.0
|
11430 | * @category Lang
|
11431 | * @param {*} value The value to check.
|
11432 | * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
|
11433 | * @example
|
11434 | *
|
11435 | * _.isElement(document.body);
|
11436 | * // => true
|
11437 | *
|
11438 | * _.isElement('<body>');
|
11439 | * // => false
|
11440 | */
|
11441 | function isElement(value) {
|
11442 | return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
|
11443 | }
|
11444 |
|
11445 | /**
|
11446 | * Checks if `value` is an empty object, collection, map, or set.
|
11447 | *
|
11448 | * Objects are considered empty if they have no own enumerable string keyed
|
11449 | * properties.
|
11450 | *
|
11451 | * Array-like values such as `arguments` objects, arrays, buffers, strings, or
|
11452 | * jQuery-like collections are considered empty if they have a `length` of `0`.
|
11453 | * Similarly, maps and sets are considered empty if they have a `size` of `0`.
|
11454 | *
|
11455 | * @static
|
11456 | * @memberOf _
|
11457 | * @since 0.1.0
|
11458 | * @category Lang
|
11459 | * @param {*} value The value to check.
|
11460 | * @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
11461 | * @example
|
11462 | *
|
11463 | * _.isEmpty(null);
|
11464 | * // => true
|
11465 | *
|
11466 | * _.isEmpty(true);
|
11467 | * // => true
|
11468 | *
|
11469 | * _.isEmpty(1);
|
11470 | * // => true
|
11471 | *
|
11472 | * _.isEmpty([1, 2, 3]);
|
11473 | * // => false
|
11474 | *
|
11475 | * _.isEmpty({ 'a': 1 });
|
11476 | * // => false
|
11477 | */
|
11478 | function isEmpty(value) {
|
11479 | if (value == null) {
|
11480 | return true;
|
11481 | }
|
11482 | if (isArrayLike(value) &&
|
11483 | (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
|
11484 | isBuffer(value) || isTypedArray(value) || isArguments(value))) {
|
11485 | return !value.length;
|
11486 | }
|
11487 | var tag = getTag(value);
|
11488 | if (tag == mapTag || tag == setTag) {
|
11489 | return !value.size;
|
11490 | }
|
11491 | if (isPrototype(value)) {
|
11492 | return !baseKeys(value).length;
|
11493 | }
|
11494 | for (var key in value) {
|
11495 | if (hasOwnProperty.call(value, key)) {
|
11496 | return false;
|
11497 | }
|
11498 | }
|
11499 | return true;
|
11500 | }
|
11501 |
|
11502 | /**
|
11503 | * Performs a deep comparison between two values to determine if they are
|
11504 | * equivalent.
|
11505 | *
|
11506 | * **Note:** This method supports comparing arrays, array buffers, booleans,
|
11507 | * date objects, error objects, maps, numbers, `Object` objects, regexes,
|
11508 | * sets, strings, symbols, and typed arrays. `Object` objects are compared
|
11509 | * by their own, not inherited, enumerable properties. Functions and DOM
|
11510 | * nodes are compared by strict equality, i.e. `===`.
|
11511 | *
|
11512 | * @static
|
11513 | * @memberOf _
|
11514 | * @since 0.1.0
|
11515 | * @category Lang
|
11516 | * @param {*} value The value to compare.
|
11517 | * @param {*} other The other value to compare.
|
11518 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
11519 | * @example
|
11520 | *
|
11521 | * var object = { 'a': 1 };
|
11522 | * var other = { 'a': 1 };
|
11523 | *
|
11524 | * _.isEqual(object, other);
|
11525 | * // => true
|
11526 | *
|
11527 | * object === other;
|
11528 | * // => false
|
11529 | */
|
11530 | function isEqual(value, other) {
|
11531 | return baseIsEqual(value, other);
|
11532 | }
|
11533 |
|
11534 | /**
|
11535 | * This method is like `_.isEqual` except that it accepts `customizer` which
|
11536 | * is invoked to compare values. If `customizer` returns `undefined`, comparisons
|
11537 | * are handled by the method instead. The `customizer` is invoked with up to
|
11538 | * six arguments: (objValue, othValue [, index|key, object, other, stack]).
|
11539 | *
|
11540 | * @static
|
11541 | * @memberOf _
|
11542 | * @since 4.0.0
|
11543 | * @category Lang
|
11544 | * @param {*} value The value to compare.
|
11545 | * @param {*} other The other value to compare.
|
11546 | * @param {Function} [customizer] The function to customize comparisons.
|
11547 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
11548 | * @example
|
11549 | *
|
11550 | * function isGreeting(value) {
|
11551 | * return /^h(?:i|ello)$/.test(value);
|
11552 | * }
|
11553 | *
|
11554 | * function customizer(objValue, othValue) {
|
11555 | * if (isGreeting(objValue) && isGreeting(othValue)) {
|
11556 | * return true;
|
11557 | * }
|
11558 | * }
|
11559 | *
|
11560 | * var array = ['hello', 'goodbye'];
|
11561 | * var other = ['hi', 'goodbye'];
|
11562 | *
|
11563 | * _.isEqualWith(array, other, customizer);
|
11564 | * // => true
|
11565 | */
|
11566 | function isEqualWith(value, other, customizer) {
|
11567 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
11568 | var result = customizer ? customizer(value, other) : undefined;
|
11569 | return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
|
11570 | }
|
11571 |
|
11572 | /**
|
11573 | * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
|
11574 | * `SyntaxError`, `TypeError`, or `URIError` object.
|
11575 | *
|
11576 | * @static
|
11577 | * @memberOf _
|
11578 | * @since 3.0.0
|
11579 | * @category Lang
|
11580 | * @param {*} value The value to check.
|
11581 | * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
|
11582 | * @example
|
11583 | *
|
11584 | * _.isError(new Error);
|
11585 | * // => true
|
11586 | *
|
11587 | * _.isError(Error);
|
11588 | * // => false
|
11589 | */
|
11590 | function isError(value) {
|
11591 | if (!isObjectLike(value)) {
|
11592 | return false;
|
11593 | }
|
11594 | var tag = baseGetTag(value);
|
11595 | return tag == errorTag || tag == domExcTag ||
|
11596 | (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
|
11597 | }
|
11598 |
|
11599 | /**
|
11600 | * Checks if `value` is a finite primitive number.
|
11601 | *
|
11602 | * **Note:** This method is based on
|
11603 | * [`Number.isFinite`](https://mdn.io/Number/isFinite).
|
11604 | *
|
11605 | * @static
|
11606 | * @memberOf _
|
11607 | * @since 0.1.0
|
11608 | * @category Lang
|
11609 | * @param {*} value The value to check.
|
11610 | * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
|
11611 | * @example
|
11612 | *
|
11613 | * _.isFinite(3);
|
11614 | * // => true
|
11615 | *
|
11616 | * _.isFinite(Number.MIN_VALUE);
|
11617 | * // => true
|
11618 | *
|
11619 | * _.isFinite(Infinity);
|
11620 | * // => false
|
11621 | *
|
11622 | * _.isFinite('3');
|
11623 | * // => false
|
11624 | */
|
11625 | function isFinite(value) {
|
11626 | return typeof value == 'number' && nativeIsFinite(value);
|
11627 | }
|
11628 |
|
11629 | /**
|
11630 | * Checks if `value` is classified as a `Function` object.
|
11631 | *
|
11632 | * @static
|
11633 | * @memberOf _
|
11634 | * @since 0.1.0
|
11635 | * @category Lang
|
11636 | * @param {*} value The value to check.
|
11637 | * @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
11638 | * @example
|
11639 | *
|
11640 | * _.isFunction(_);
|
11641 | * // => true
|
11642 | *
|
11643 | * _.isFunction(/abc/);
|
11644 | * // => false
|
11645 | */
|
11646 | function isFunction(value) {
|
11647 | if (!isObject(value)) {
|
11648 | return false;
|
11649 | }
|
11650 | // The use of `Object#toString` avoids issues with the `typeof` operator
|
11651 | // in Safari 9 which returns 'object' for typed arrays and other constructors.
|
11652 | var tag = baseGetTag(value);
|
11653 | return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
11654 | }
|
11655 |
|
11656 | /**
|
11657 | * Checks if `value` is an integer.
|
11658 | *
|
11659 | * **Note:** This method is based on
|
11660 | * [`Number.isInteger`](https://mdn.io/Number/isInteger).
|
11661 | *
|
11662 | * @static
|
11663 | * @memberOf _
|
11664 | * @since 4.0.0
|
11665 | * @category Lang
|
11666 | * @param {*} value The value to check.
|
11667 | * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
|
11668 | * @example
|
11669 | *
|
11670 | * _.isInteger(3);
|
11671 | * // => true
|
11672 | *
|
11673 | * _.isInteger(Number.MIN_VALUE);
|
11674 | * // => false
|
11675 | *
|
11676 | * _.isInteger(Infinity);
|
11677 | * // => false
|
11678 | *
|
11679 | * _.isInteger('3');
|
11680 | * // => false
|
11681 | */
|
11682 | function isInteger(value) {
|
11683 | return typeof value == 'number' && value == toInteger(value);
|
11684 | }
|
11685 |
|
11686 | /**
|
11687 | * Checks if `value` is a valid array-like length.
|
11688 | *
|
11689 | * **Note:** This method is loosely based on
|
11690 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
11691 | *
|
11692 | * @static
|
11693 | * @memberOf _
|
11694 | * @since 4.0.0
|
11695 | * @category Lang
|
11696 | * @param {*} value The value to check.
|
11697 | * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
11698 | * @example
|
11699 | *
|
11700 | * _.isLength(3);
|
11701 | * // => true
|
11702 | *
|
11703 | * _.isLength(Number.MIN_VALUE);
|
11704 | * // => false
|
11705 | *
|
11706 | * _.isLength(Infinity);
|
11707 | * // => false
|
11708 | *
|
11709 | * _.isLength('3');
|
11710 | * // => false
|
11711 | */
|
11712 | function isLength(value) {
|
11713 | return typeof value == 'number' &&
|
11714 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
11715 | }
|
11716 |
|
11717 | /**
|
11718 | * Checks if `value` is the
|
11719 | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
11720 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
11721 | *
|
11722 | * @static
|
11723 | * @memberOf _
|
11724 | * @since 0.1.0
|
11725 | * @category Lang
|
11726 | * @param {*} value The value to check.
|
11727 | * @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
11728 | * @example
|
11729 | *
|
11730 | * _.isObject({});
|
11731 | * // => true
|
11732 | *
|
11733 | * _.isObject([1, 2, 3]);
|
11734 | * // => true
|
11735 | *
|
11736 | * _.isObject(_.noop);
|
11737 | * // => true
|
11738 | *
|
11739 | * _.isObject(null);
|
11740 | * // => false
|
11741 | */
|
11742 | function isObject(value) {
|
11743 | var type = typeof value;
|
11744 | return value != null && (type == 'object' || type == 'function');
|
11745 | }
|
11746 |
|
11747 | /**
|
11748 | * Checks if `value` is object-like. A value is object-like if it's not `null`
|
11749 | * and has a `typeof` result of "object".
|
11750 | *
|
11751 | * @static
|
11752 | * @memberOf _
|
11753 | * @since 4.0.0
|
11754 | * @category Lang
|
11755 | * @param {*} value The value to check.
|
11756 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
11757 | * @example
|
11758 | *
|
11759 | * _.isObjectLike({});
|
11760 | * // => true
|
11761 | *
|
11762 | * _.isObjectLike([1, 2, 3]);
|
11763 | * // => true
|
11764 | *
|
11765 | * _.isObjectLike(_.noop);
|
11766 | * // => false
|
11767 | *
|
11768 | * _.isObjectLike(null);
|
11769 | * // => false
|
11770 | */
|
11771 | function isObjectLike(value) {
|
11772 | return value != null && typeof value == 'object';
|
11773 | }
|
11774 |
|
11775 | /**
|
11776 | * Checks if `value` is classified as a `Map` object.
|
11777 | *
|
11778 | * @static
|
11779 | * @memberOf _
|
11780 | * @since 4.3.0
|
11781 | * @category Lang
|
11782 | * @param {*} value The value to check.
|
11783 | * @returns {boolean} Returns `true` if `value` is a map, else `false`.
|
11784 | * @example
|
11785 | *
|
11786 | * _.isMap(new Map);
|
11787 | * // => true
|
11788 | *
|
11789 | * _.isMap(new WeakMap);
|
11790 | * // => false
|
11791 | */
|
11792 | var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
|
11793 |
|
11794 | /**
|
11795 | * Performs a partial deep comparison between `object` and `source` to
|
11796 | * determine if `object` contains equivalent property values.
|
11797 | *
|
11798 | * **Note:** This method is equivalent to `_.matches` when `source` is
|
11799 | * partially applied.
|
11800 | *
|
11801 | * Partial comparisons will match empty array and empty object `source`
|
11802 | * values against any array or object value, respectively. See `_.isEqual`
|
11803 | * for a list of supported value comparisons.
|
11804 | *
|
11805 | * @static
|
11806 | * @memberOf _
|
11807 | * @since 3.0.0
|
11808 | * @category Lang
|
11809 | * @param {Object} object The object to inspect.
|
11810 | * @param {Object} source The object of property values to match.
|
11811 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
11812 | * @example
|
11813 | *
|
11814 | * var object = { 'a': 1, 'b': 2 };
|
11815 | *
|
11816 | * _.isMatch(object, { 'b': 2 });
|
11817 | * // => true
|
11818 | *
|
11819 | * _.isMatch(object, { 'b': 1 });
|
11820 | * // => false
|
11821 | */
|
11822 | function isMatch(object, source) {
|
11823 | return object === source || baseIsMatch(object, source, getMatchData(source));
|
11824 | }
|
11825 |
|
11826 | /**
|
11827 | * This method is like `_.isMatch` except that it accepts `customizer` which
|
11828 | * is invoked to compare values. If `customizer` returns `undefined`, comparisons
|
11829 | * are handled by the method instead. The `customizer` is invoked with five
|
11830 | * arguments: (objValue, srcValue, index|key, object, source).
|
11831 | *
|
11832 | * @static
|
11833 | * @memberOf _
|
11834 | * @since 4.0.0
|
11835 | * @category Lang
|
11836 | * @param {Object} object The object to inspect.
|
11837 | * @param {Object} source The object of property values to match.
|
11838 | * @param {Function} [customizer] The function to customize comparisons.
|
11839 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
11840 | * @example
|
11841 | *
|
11842 | * function isGreeting(value) {
|
11843 | * return /^h(?:i|ello)$/.test(value);
|
11844 | * }
|
11845 | *
|
11846 | * function customizer(objValue, srcValue) {
|
11847 | * if (isGreeting(objValue) && isGreeting(srcValue)) {
|
11848 | * return true;
|
11849 | * }
|
11850 | * }
|
11851 | *
|
11852 | * var object = { 'greeting': 'hello' };
|
11853 | * var source = { 'greeting': 'hi' };
|
11854 | *
|
11855 | * _.isMatchWith(object, source, customizer);
|
11856 | * // => true
|
11857 | */
|
11858 | function isMatchWith(object, source, customizer) {
|
11859 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
11860 | return baseIsMatch(object, source, getMatchData(source), customizer);
|
11861 | }
|
11862 |
|
11863 | /**
|
11864 | * Checks if `value` is `NaN`.
|
11865 | *
|
11866 | * **Note:** This method is based on
|
11867 | * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
|
11868 | * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
|
11869 | * `undefined` and other non-number values.
|
11870 | *
|
11871 | * @static
|
11872 | * @memberOf _
|
11873 | * @since 0.1.0
|
11874 | * @category Lang
|
11875 | * @param {*} value The value to check.
|
11876 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
11877 | * @example
|
11878 | *
|
11879 | * _.isNaN(NaN);
|
11880 | * // => true
|
11881 | *
|
11882 | * _.isNaN(new Number(NaN));
|
11883 | * // => true
|
11884 | *
|
11885 | * isNaN(undefined);
|
11886 | * // => true
|
11887 | *
|
11888 | * _.isNaN(undefined);
|
11889 | * // => false
|
11890 | */
|
11891 | function isNaN(value) {
|
11892 | // An `NaN` primitive is the only value that is not equal to itself.
|
11893 | // Perform the `toStringTag` check first to avoid errors with some
|
11894 | // ActiveX objects in IE.
|
11895 | return isNumber(value) && value != +value;
|
11896 | }
|
11897 |
|
11898 | /**
|
11899 | * Checks if `value` is a pristine native function.
|
11900 | *
|
11901 | * **Note:** This method can't reliably detect native functions in the presence
|
11902 | * of the core-js package because core-js circumvents this kind of detection.
|
11903 | * Despite multiple requests, the core-js maintainer has made it clear: any
|
11904 | * attempt to fix the detection will be obstructed. As a result, we're left
|
11905 | * with little choice but to throw an error. Unfortunately, this also affects
|
11906 | * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
|
11907 | * which rely on core-js.
|
11908 | *
|
11909 | * @static
|
11910 | * @memberOf _
|
11911 | * @since 3.0.0
|
11912 | * @category Lang
|
11913 | * @param {*} value The value to check.
|
11914 | * @returns {boolean} Returns `true` if `value` is a native function,
|
11915 | * else `false`.
|
11916 | * @example
|
11917 | *
|
11918 | * _.isNative(Array.prototype.push);
|
11919 | * // => true
|
11920 | *
|
11921 | * _.isNative(_);
|
11922 | * // => false
|
11923 | */
|
11924 | function isNative(value) {
|
11925 | if (isMaskable(value)) {
|
11926 | throw new Error(CORE_ERROR_TEXT);
|
11927 | }
|
11928 | return baseIsNative(value);
|
11929 | }
|
11930 |
|
11931 | /**
|
11932 | * Checks if `value` is `null`.
|
11933 | *
|
11934 | * @static
|
11935 | * @memberOf _
|
11936 | * @since 0.1.0
|
11937 | * @category Lang
|
11938 | * @param {*} value The value to check.
|
11939 | * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
|
11940 | * @example
|
11941 | *
|
11942 | * _.isNull(null);
|
11943 | * // => true
|
11944 | *
|
11945 | * _.isNull(void 0);
|
11946 | * // => false
|
11947 | */
|
11948 | function isNull(value) {
|
11949 | return value === null;
|
11950 | }
|
11951 |
|
11952 | /**
|
11953 | * Checks if `value` is `null` or `undefined`.
|
11954 | *
|
11955 | * @static
|
11956 | * @memberOf _
|
11957 | * @since 4.0.0
|
11958 | * @category Lang
|
11959 | * @param {*} value The value to check.
|
11960 | * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
|
11961 | * @example
|
11962 | *
|
11963 | * _.isNil(null);
|
11964 | * // => true
|
11965 | *
|
11966 | * _.isNil(void 0);
|
11967 | * // => true
|
11968 | *
|
11969 | * _.isNil(NaN);
|
11970 | * // => false
|
11971 | */
|
11972 | function isNil(value) {
|
11973 | return value == null;
|
11974 | }
|
11975 |
|
11976 | /**
|
11977 | * Checks if `value` is classified as a `Number` primitive or object.
|
11978 | *
|
11979 | * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
|
11980 | * classified as numbers, use the `_.isFinite` method.
|
11981 | *
|
11982 | * @static
|
11983 | * @memberOf _
|
11984 | * @since 0.1.0
|
11985 | * @category Lang
|
11986 | * @param {*} value The value to check.
|
11987 | * @returns {boolean} Returns `true` if `value` is a number, else `false`.
|
11988 | * @example
|
11989 | *
|
11990 | * _.isNumber(3);
|
11991 | * // => true
|
11992 | *
|
11993 | * _.isNumber(Number.MIN_VALUE);
|
11994 | * // => true
|
11995 | *
|
11996 | * _.isNumber(Infinity);
|
11997 | * // => true
|
11998 | *
|
11999 | * _.isNumber('3');
|
12000 | * // => false
|
12001 | */
|
12002 | function isNumber(value) {
|
12003 | return typeof value == 'number' ||
|
12004 | (isObjectLike(value) && baseGetTag(value) == numberTag);
|
12005 | }
|
12006 |
|
12007 | /**
|
12008 | * Checks if `value` is a plain object, that is, an object created by the
|
12009 | * `Object` constructor or one with a `[[Prototype]]` of `null`.
|
12010 | *
|
12011 | * @static
|
12012 | * @memberOf _
|
12013 | * @since 0.8.0
|
12014 | * @category Lang
|
12015 | * @param {*} value The value to check.
|
12016 | * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
12017 | * @example
|
12018 | *
|
12019 | * function Foo() {
|
12020 | * this.a = 1;
|
12021 | * }
|
12022 | *
|
12023 | * _.isPlainObject(new Foo);
|
12024 | * // => false
|
12025 | *
|
12026 | * _.isPlainObject([1, 2, 3]);
|
12027 | * // => false
|
12028 | *
|
12029 | * _.isPlainObject({ 'x': 0, 'y': 0 });
|
12030 | * // => true
|
12031 | *
|
12032 | * _.isPlainObject(Object.create(null));
|
12033 | * // => true
|
12034 | */
|
12035 | function isPlainObject(value) {
|
12036 | if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
|
12037 | return false;
|
12038 | }
|
12039 | var proto = getPrototype(value);
|
12040 | if (proto === null) {
|
12041 | return true;
|
12042 | }
|
12043 | var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
|
12044 | return typeof Ctor == 'function' && Ctor instanceof Ctor &&
|
12045 | funcToString.call(Ctor) == objectCtorString;
|
12046 | }
|
12047 |
|
12048 | /**
|
12049 | * Checks if `value` is classified as a `RegExp` object.
|
12050 | *
|
12051 | * @static
|
12052 | * @memberOf _
|
12053 | * @since 0.1.0
|
12054 | * @category Lang
|
12055 | * @param {*} value The value to check.
|
12056 | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
|
12057 | * @example
|
12058 | *
|
12059 | * _.isRegExp(/abc/);
|
12060 | * // => true
|
12061 | *
|
12062 | * _.isRegExp('/abc/');
|
12063 | * // => false
|
12064 | */
|
12065 | var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
|
12066 |
|
12067 | /**
|
12068 | * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
|
12069 | * double precision number which isn't the result of a rounded unsafe integer.
|
12070 | *
|
12071 | * **Note:** This method is based on
|
12072 | * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
|
12073 | *
|
12074 | * @static
|
12075 | * @memberOf _
|
12076 | * @since 4.0.0
|
12077 | * @category Lang
|
12078 | * @param {*} value The value to check.
|
12079 | * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
|
12080 | * @example
|
12081 | *
|
12082 | * _.isSafeInteger(3);
|
12083 | * // => true
|
12084 | *
|
12085 | * _.isSafeInteger(Number.MIN_VALUE);
|
12086 | * // => false
|
12087 | *
|
12088 | * _.isSafeInteger(Infinity);
|
12089 | * // => false
|
12090 | *
|
12091 | * _.isSafeInteger('3');
|
12092 | * // => false
|
12093 | */
|
12094 | function isSafeInteger(value) {
|
12095 | return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
12096 | }
|
12097 |
|
12098 | /**
|
12099 | * Checks if `value` is classified as a `Set` object.
|
12100 | *
|
12101 | * @static
|
12102 | * @memberOf _
|
12103 | * @since 4.3.0
|
12104 | * @category Lang
|
12105 | * @param {*} value The value to check.
|
12106 | * @returns {boolean} Returns `true` if `value` is a set, else `false`.
|
12107 | * @example
|
12108 | *
|
12109 | * _.isSet(new Set);
|
12110 | * // => true
|
12111 | *
|
12112 | * _.isSet(new WeakSet);
|
12113 | * // => false
|
12114 | */
|
12115 | var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
12116 |
|
12117 | /**
|
12118 | * Checks if `value` is classified as a `String` primitive or object.
|
12119 | *
|
12120 | * @static
|
12121 | * @since 0.1.0
|
12122 | * @memberOf _
|
12123 | * @category Lang
|
12124 | * @param {*} value The value to check.
|
12125 | * @returns {boolean} Returns `true` if `value` is a string, else `false`.
|
12126 | * @example
|
12127 | *
|
12128 | * _.isString('abc');
|
12129 | * // => true
|
12130 | *
|
12131 | * _.isString(1);
|
12132 | * // => false
|
12133 | */
|
12134 | function isString(value) {
|
12135 | return typeof value == 'string' ||
|
12136 | (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
|
12137 | }
|
12138 |
|
12139 | /**
|
12140 | * Checks if `value` is classified as a `Symbol` primitive or object.
|
12141 | *
|
12142 | * @static
|
12143 | * @memberOf _
|
12144 | * @since 4.0.0
|
12145 | * @category Lang
|
12146 | * @param {*} value The value to check.
|
12147 | * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
12148 | * @example
|
12149 | *
|
12150 | * _.isSymbol(Symbol.iterator);
|
12151 | * // => true
|
12152 | *
|
12153 | * _.isSymbol('abc');
|
12154 | * // => false
|
12155 | */
|
12156 | function isSymbol(value) {
|
12157 | return typeof value == 'symbol' ||
|
12158 | (isObjectLike(value) && baseGetTag(value) == symbolTag);
|
12159 | }
|
12160 |
|
12161 | /**
|
12162 | * Checks if `value` is classified as a typed array.
|
12163 | *
|
12164 | * @static
|
12165 | * @memberOf _
|
12166 | * @since 3.0.0
|
12167 | * @category Lang
|
12168 | * @param {*} value The value to check.
|
12169 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
12170 | * @example
|
12171 | *
|
12172 | * _.isTypedArray(new Uint8Array);
|
12173 | * // => true
|
12174 | *
|
12175 | * _.isTypedArray([]);
|
12176 | * // => false
|
12177 | */
|
12178 | var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
|
12179 |
|
12180 | /**
|
12181 | * Checks if `value` is `undefined`.
|
12182 | *
|
12183 | * @static
|
12184 | * @since 0.1.0
|
12185 | * @memberOf _
|
12186 | * @category Lang
|
12187 | * @param {*} value The value to check.
|
12188 | * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
|
12189 | * @example
|
12190 | *
|
12191 | * _.isUndefined(void 0);
|
12192 | * // => true
|
12193 | *
|
12194 | * _.isUndefined(null);
|
12195 | * // => false
|
12196 | */
|
12197 | function isUndefined(value) {
|
12198 | return value === undefined;
|
12199 | }
|
12200 |
|
12201 | /**
|
12202 | * Checks if `value` is classified as a `WeakMap` object.
|
12203 | *
|
12204 | * @static
|
12205 | * @memberOf _
|
12206 | * @since 4.3.0
|
12207 | * @category Lang
|
12208 | * @param {*} value The value to check.
|
12209 | * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
|
12210 | * @example
|
12211 | *
|
12212 | * _.isWeakMap(new WeakMap);
|
12213 | * // => true
|
12214 | *
|
12215 | * _.isWeakMap(new Map);
|
12216 | * // => false
|
12217 | */
|
12218 | function isWeakMap(value) {
|
12219 | return isObjectLike(value) && getTag(value) == weakMapTag;
|
12220 | }
|
12221 |
|
12222 | /**
|
12223 | * Checks if `value` is classified as a `WeakSet` object.
|
12224 | *
|
12225 | * @static
|
12226 | * @memberOf _
|
12227 | * @since 4.3.0
|
12228 | * @category Lang
|
12229 | * @param {*} value The value to check.
|
12230 | * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
|
12231 | * @example
|
12232 | *
|
12233 | * _.isWeakSet(new WeakSet);
|
12234 | * // => true
|
12235 | *
|
12236 | * _.isWeakSet(new Set);
|
12237 | * // => false
|
12238 | */
|
12239 | function isWeakSet(value) {
|
12240 | return isObjectLike(value) && baseGetTag(value) == weakSetTag;
|
12241 | }
|
12242 |
|
12243 | /**
|
12244 | * Checks if `value` is less than `other`.
|
12245 | *
|
12246 | * @static
|
12247 | * @memberOf _
|
12248 | * @since 3.9.0
|
12249 | * @category Lang
|
12250 | * @param {*} value The value to compare.
|
12251 | * @param {*} other The other value to compare.
|
12252 | * @returns {boolean} Returns `true` if `value` is less than `other`,
|
12253 | * else `false`.
|
12254 | * @see _.gt
|
12255 | * @example
|
12256 | *
|
12257 | * _.lt(1, 3);
|
12258 | * // => true
|
12259 | *
|
12260 | * _.lt(3, 3);
|
12261 | * // => false
|
12262 | *
|
12263 | * _.lt(3, 1);
|
12264 | * // => false
|
12265 | */
|
12266 | var lt = createRelationalOperation(baseLt);
|
12267 |
|
12268 | /**
|
12269 | * Checks if `value` is less than or equal to `other`.
|
12270 | *
|
12271 | * @static
|
12272 | * @memberOf _
|
12273 | * @since 3.9.0
|
12274 | * @category Lang
|
12275 | * @param {*} value The value to compare.
|
12276 | * @param {*} other The other value to compare.
|
12277 | * @returns {boolean} Returns `true` if `value` is less than or equal to
|
12278 | * `other`, else `false`.
|
12279 | * @see _.gte
|
12280 | * @example
|
12281 | *
|
12282 | * _.lte(1, 3);
|
12283 | * // => true
|
12284 | *
|
12285 | * _.lte(3, 3);
|
12286 | * // => true
|
12287 | *
|
12288 | * _.lte(3, 1);
|
12289 | * // => false
|
12290 | */
|
12291 | var lte = createRelationalOperation(function(value, other) {
|
12292 | return value <= other;
|
12293 | });
|
12294 |
|
12295 | /**
|
12296 | * Converts `value` to an array.
|
12297 | *
|
12298 | * @static
|
12299 | * @since 0.1.0
|
12300 | * @memberOf _
|
12301 | * @category Lang
|
12302 | * @param {*} value The value to convert.
|
12303 | * @returns {Array} Returns the converted array.
|
12304 | * @example
|
12305 | *
|
12306 | * _.toArray({ 'a': 1, 'b': 2 });
|
12307 | * // => [1, 2]
|
12308 | *
|
12309 | * _.toArray('abc');
|
12310 | * // => ['a', 'b', 'c']
|
12311 | *
|
12312 | * _.toArray(1);
|
12313 | * // => []
|
12314 | *
|
12315 | * _.toArray(null);
|
12316 | * // => []
|
12317 | */
|
12318 | function toArray(value) {
|
12319 | if (!value) {
|
12320 | return [];
|
12321 | }
|
12322 | if (isArrayLike(value)) {
|
12323 | return isString(value) ? stringToArray(value) : copyArray(value);
|
12324 | }
|
12325 | if (symIterator && value[symIterator]) {
|
12326 | return iteratorToArray(value[symIterator]());
|
12327 | }
|
12328 | var tag = getTag(value),
|
12329 | func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
|
12330 |
|
12331 | return func(value);
|
12332 | }
|
12333 |
|
12334 | /**
|
12335 | * Converts `value` to a finite number.
|
12336 | *
|
12337 | * @static
|
12338 | * @memberOf _
|
12339 | * @since 4.12.0
|
12340 | * @category Lang
|
12341 | * @param {*} value The value to convert.
|
12342 | * @returns {number} Returns the converted number.
|
12343 | * @example
|
12344 | *
|
12345 | * _.toFinite(3.2);
|
12346 | * // => 3.2
|
12347 | *
|
12348 | * _.toFinite(Number.MIN_VALUE);
|
12349 | * // => 5e-324
|
12350 | *
|
12351 | * _.toFinite(Infinity);
|
12352 | * // => 1.7976931348623157e+308
|
12353 | *
|
12354 | * _.toFinite('3.2');
|
12355 | * // => 3.2
|
12356 | */
|
12357 | function toFinite(value) {
|
12358 | if (!value) {
|
12359 | return value === 0 ? value : 0;
|
12360 | }
|
12361 | value = toNumber(value);
|
12362 | if (value === INFINITY || value === -INFINITY) {
|
12363 | var sign = (value < 0 ? -1 : 1);
|
12364 | return sign * MAX_INTEGER;
|
12365 | }
|
12366 | return value === value ? value : 0;
|
12367 | }
|
12368 |
|
12369 | /**
|
12370 | * Converts `value` to an integer.
|
12371 | *
|
12372 | * **Note:** This method is loosely based on
|
12373 | * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
|
12374 | *
|
12375 | * @static
|
12376 | * @memberOf _
|
12377 | * @since 4.0.0
|
12378 | * @category Lang
|
12379 | * @param {*} value The value to convert.
|
12380 | * @returns {number} Returns the converted integer.
|
12381 | * @example
|
12382 | *
|
12383 | * _.toInteger(3.2);
|
12384 | * // => 3
|
12385 | *
|
12386 | * _.toInteger(Number.MIN_VALUE);
|
12387 | * // => 0
|
12388 | *
|
12389 | * _.toInteger(Infinity);
|
12390 | * // => 1.7976931348623157e+308
|
12391 | *
|
12392 | * _.toInteger('3.2');
|
12393 | * // => 3
|
12394 | */
|
12395 | function toInteger(value) {
|
12396 | var result = toFinite(value),
|
12397 | remainder = result % 1;
|
12398 |
|
12399 | return result === result ? (remainder ? result - remainder : result) : 0;
|
12400 | }
|
12401 |
|
12402 | /**
|
12403 | * Converts `value` to an integer suitable for use as the length of an
|
12404 | * array-like object.
|
12405 | *
|
12406 | * **Note:** This method is based on
|
12407 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
12408 | *
|
12409 | * @static
|
12410 | * @memberOf _
|
12411 | * @since 4.0.0
|
12412 | * @category Lang
|
12413 | * @param {*} value The value to convert.
|
12414 | * @returns {number} Returns the converted integer.
|
12415 | * @example
|
12416 | *
|
12417 | * _.toLength(3.2);
|
12418 | * // => 3
|
12419 | *
|
12420 | * _.toLength(Number.MIN_VALUE);
|
12421 | * // => 0
|
12422 | *
|
12423 | * _.toLength(Infinity);
|
12424 | * // => 4294967295
|
12425 | *
|
12426 | * _.toLength('3.2');
|
12427 | * // => 3
|
12428 | */
|
12429 | function toLength(value) {
|
12430 | return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
|
12431 | }
|
12432 |
|
12433 | /**
|
12434 | * Converts `value` to a number.
|
12435 | *
|
12436 | * @static
|
12437 | * @memberOf _
|
12438 | * @since 4.0.0
|
12439 | * @category Lang
|
12440 | * @param {*} value The value to process.
|
12441 | * @returns {number} Returns the number.
|
12442 | * @example
|
12443 | *
|
12444 | * _.toNumber(3.2);
|
12445 | * // => 3.2
|
12446 | *
|
12447 | * _.toNumber(Number.MIN_VALUE);
|
12448 | * // => 5e-324
|
12449 | *
|
12450 | * _.toNumber(Infinity);
|
12451 | * // => Infinity
|
12452 | *
|
12453 | * _.toNumber('3.2');
|
12454 | * // => 3.2
|
12455 | */
|
12456 | function toNumber(value) {
|
12457 | if (typeof value == 'number') {
|
12458 | return value;
|
12459 | }
|
12460 | if (isSymbol(value)) {
|
12461 | return NAN;
|
12462 | }
|
12463 | if (isObject(value)) {
|
12464 | var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
12465 | value = isObject(other) ? (other + '') : other;
|
12466 | }
|
12467 | if (typeof value != 'string') {
|
12468 | return value === 0 ? value : +value;
|
12469 | }
|
12470 | value = value.replace(reTrim, '');
|
12471 | var isBinary = reIsBinary.test(value);
|
12472 | return (isBinary || reIsOctal.test(value))
|
12473 | ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
12474 | : (reIsBadHex.test(value) ? NAN : +value);
|
12475 | }
|
12476 |
|
12477 | /**
|
12478 | * Converts `value` to a plain object flattening inherited enumerable string
|
12479 | * keyed properties of `value` to own properties of the plain object.
|
12480 | *
|
12481 | * @static
|
12482 | * @memberOf _
|
12483 | * @since 3.0.0
|
12484 | * @category Lang
|
12485 | * @param {*} value The value to convert.
|
12486 | * @returns {Object} Returns the converted plain object.
|
12487 | * @example
|
12488 | *
|
12489 | * function Foo() {
|
12490 | * this.b = 2;
|
12491 | * }
|
12492 | *
|
12493 | * Foo.prototype.c = 3;
|
12494 | *
|
12495 | * _.assign({ 'a': 1 }, new Foo);
|
12496 | * // => { 'a': 1, 'b': 2 }
|
12497 | *
|
12498 | * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
|
12499 | * // => { 'a': 1, 'b': 2, 'c': 3 }
|
12500 | */
|
12501 | function toPlainObject(value) {
|
12502 | return copyObject(value, keysIn(value));
|
12503 | }
|
12504 |
|
12505 | /**
|
12506 | * Converts `value` to a safe integer. A safe integer can be compared and
|
12507 | * represented correctly.
|
12508 | *
|
12509 | * @static
|
12510 | * @memberOf _
|
12511 | * @since 4.0.0
|
12512 | * @category Lang
|
12513 | * @param {*} value The value to convert.
|
12514 | * @returns {number} Returns the converted integer.
|
12515 | * @example
|
12516 | *
|
12517 | * _.toSafeInteger(3.2);
|
12518 | * // => 3
|
12519 | *
|
12520 | * _.toSafeInteger(Number.MIN_VALUE);
|
12521 | * // => 0
|
12522 | *
|
12523 | * _.toSafeInteger(Infinity);
|
12524 | * // => 9007199254740991
|
12525 | *
|
12526 | * _.toSafeInteger('3.2');
|
12527 | * // => 3
|
12528 | */
|
12529 | function toSafeInteger(value) {
|
12530 | return value
|
12531 | ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
|
12532 | : (value === 0 ? value : 0);
|
12533 | }
|
12534 |
|
12535 | /**
|
12536 | * Converts `value` to a string. An empty string is returned for `null`
|
12537 | * and `undefined` values. The sign of `-0` is preserved.
|
12538 | *
|
12539 | * @static
|
12540 | * @memberOf _
|
12541 | * @since 4.0.0
|
12542 | * @category Lang
|
12543 | * @param {*} value The value to convert.
|
12544 | * @returns {string} Returns the converted string.
|
12545 | * @example
|
12546 | *
|
12547 | * _.toString(null);
|
12548 | * // => ''
|
12549 | *
|
12550 | * _.toString(-0);
|
12551 | * // => '-0'
|
12552 | *
|
12553 | * _.toString([1, 2, 3]);
|
12554 | * // => '1,2,3'
|
12555 | */
|
12556 | function toString(value) {
|
12557 | return value == null ? '' : baseToString(value);
|
12558 | }
|
12559 |
|
12560 | /*------------------------------------------------------------------------*/
|
12561 |
|
12562 | /**
|
12563 | * Assigns own enumerable string keyed properties of source objects to the
|
12564 | * destination object. Source objects are applied from left to right.
|
12565 | * Subsequent sources overwrite property assignments of previous sources.
|
12566 | *
|
12567 | * **Note:** This method mutates `object` and is loosely based on
|
12568 | * [`Object.assign`](https://mdn.io/Object/assign).
|
12569 | *
|
12570 | * @static
|
12571 | * @memberOf _
|
12572 | * @since 0.10.0
|
12573 | * @category Object
|
12574 | * @param {Object} object The destination object.
|
12575 | * @param {...Object} [sources] The source objects.
|
12576 | * @returns {Object} Returns `object`.
|
12577 | * @see _.assignIn
|
12578 | * @example
|
12579 | *
|
12580 | * function Foo() {
|
12581 | * this.a = 1;
|
12582 | * }
|
12583 | *
|
12584 | * function Bar() {
|
12585 | * this.c = 3;
|
12586 | * }
|
12587 | *
|
12588 | * Foo.prototype.b = 2;
|
12589 | * Bar.prototype.d = 4;
|
12590 | *
|
12591 | * _.assign({ 'a': 0 }, new Foo, new Bar);
|
12592 | * // => { 'a': 1, 'c': 3 }
|
12593 | */
|
12594 | var assign = createAssigner(function(object, source) {
|
12595 | if (isPrototype(source) || isArrayLike(source)) {
|
12596 | copyObject(source, keys(source), object);
|
12597 | return;
|
12598 | }
|
12599 | for (var key in source) {
|
12600 | if (hasOwnProperty.call(source, key)) {
|
12601 | assignValue(object, key, source[key]);
|
12602 | }
|
12603 | }
|
12604 | });
|
12605 |
|
12606 | /**
|
12607 | * This method is like `_.assign` except that it iterates over own and
|
12608 | * inherited source properties.
|
12609 | *
|
12610 | * **Note:** This method mutates `object`.
|
12611 | *
|
12612 | * @static
|
12613 | * @memberOf _
|
12614 | * @since 4.0.0
|
12615 | * @alias extend
|
12616 | * @category Object
|
12617 | * @param {Object} object The destination object.
|
12618 | * @param {...Object} [sources] The source objects.
|
12619 | * @returns {Object} Returns `object`.
|
12620 | * @see _.assign
|
12621 | * @example
|
12622 | *
|
12623 | * function Foo() {
|
12624 | * this.a = 1;
|
12625 | * }
|
12626 | *
|
12627 | * function Bar() {
|
12628 | * this.c = 3;
|
12629 | * }
|
12630 | *
|
12631 | * Foo.prototype.b = 2;
|
12632 | * Bar.prototype.d = 4;
|
12633 | *
|
12634 | * _.assignIn({ 'a': 0 }, new Foo, new Bar);
|
12635 | * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
12636 | */
|
12637 | var assignIn = createAssigner(function(object, source) {
|
12638 | copyObject(source, keysIn(source), object);
|
12639 | });
|
12640 |
|
12641 | /**
|
12642 | * This method is like `_.assignIn` except that it accepts `customizer`
|
12643 | * which is invoked to produce the assigned values. If `customizer` returns
|
12644 | * `undefined`, assignment is handled by the method instead. The `customizer`
|
12645 | * is invoked with five arguments: (objValue, srcValue, key, object, source).
|
12646 | *
|
12647 | * **Note:** This method mutates `object`.
|
12648 | *
|
12649 | * @static
|
12650 | * @memberOf _
|
12651 | * @since 4.0.0
|
12652 | * @alias extendWith
|
12653 | * @category Object
|
12654 | * @param {Object} object The destination object.
|
12655 | * @param {...Object} sources The source objects.
|
12656 | * @param {Function} [customizer] The function to customize assigned values.
|
12657 | * @returns {Object} Returns `object`.
|
12658 | * @see _.assignWith
|
12659 | * @example
|
12660 | *
|
12661 | * function customizer(objValue, srcValue) {
|
12662 | * return _.isUndefined(objValue) ? srcValue : objValue;
|
12663 | * }
|
12664 | *
|
12665 | * var defaults = _.partialRight(_.assignInWith, customizer);
|
12666 | *
|
12667 | * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
12668 | * // => { 'a': 1, 'b': 2 }
|
12669 | */
|
12670 | var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
|
12671 | copyObject(source, keysIn(source), object, customizer);
|
12672 | });
|
12673 |
|
12674 | /**
|
12675 | * This method is like `_.assign` except that it accepts `customizer`
|
12676 | * which is invoked to produce the assigned values. If `customizer` returns
|
12677 | * `undefined`, assignment is handled by the method instead. The `customizer`
|
12678 | * is invoked with five arguments: (objValue, srcValue, key, object, source).
|
12679 | *
|
12680 | * **Note:** This method mutates `object`.
|
12681 | *
|
12682 | * @static
|
12683 | * @memberOf _
|
12684 | * @since 4.0.0
|
12685 | * @category Object
|
12686 | * @param {Object} object The destination object.
|
12687 | * @param {...Object} sources The source objects.
|
12688 | * @param {Function} [customizer] The function to customize assigned values.
|
12689 | * @returns {Object} Returns `object`.
|
12690 | * @see _.assignInWith
|
12691 | * @example
|
12692 | *
|
12693 | * function customizer(objValue, srcValue) {
|
12694 | * return _.isUndefined(objValue) ? srcValue : objValue;
|
12695 | * }
|
12696 | *
|
12697 | * var defaults = _.partialRight(_.assignWith, customizer);
|
12698 | *
|
12699 | * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
12700 | * // => { 'a': 1, 'b': 2 }
|
12701 | */
|
12702 | var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
|
12703 | copyObject(source, keys(source), object, customizer);
|
12704 | });
|
12705 |
|
12706 | /**
|
12707 | * Creates an array of values corresponding to `paths` of `object`.
|
12708 | *
|
12709 | * @static
|
12710 | * @memberOf _
|
12711 | * @since 1.0.0
|
12712 | * @category Object
|
12713 | * @param {Object} object The object to iterate over.
|
12714 | * @param {...(string|string[])} [paths] The property paths to pick.
|
12715 | * @returns {Array} Returns the picked values.
|
12716 | * @example
|
12717 | *
|
12718 | * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
|
12719 | *
|
12720 | * _.at(object, ['a[0].b.c', 'a[1]']);
|
12721 | * // => [3, 4]
|
12722 | */
|
12723 | var at = flatRest(baseAt);
|
12724 |
|
12725 | /**
|
12726 | * Creates an object that inherits from the `prototype` object. If a
|
12727 | * `properties` object is given, its own enumerable string keyed properties
|
12728 | * are assigned to the created object.
|
12729 | *
|
12730 | * @static
|
12731 | * @memberOf _
|
12732 | * @since 2.3.0
|
12733 | * @category Object
|
12734 | * @param {Object} prototype The object to inherit from.
|
12735 | * @param {Object} [properties] The properties to assign to the object.
|
12736 | * @returns {Object} Returns the new object.
|
12737 | * @example
|
12738 | *
|
12739 | * function Shape() {
|
12740 | * this.x = 0;
|
12741 | * this.y = 0;
|
12742 | * }
|
12743 | *
|
12744 | * function Circle() {
|
12745 | * Shape.call(this);
|
12746 | * }
|
12747 | *
|
12748 | * Circle.prototype = _.create(Shape.prototype, {
|
12749 | * 'constructor': Circle
|
12750 | * });
|
12751 | *
|
12752 | * var circle = new Circle;
|
12753 | * circle instanceof Circle;
|
12754 | * // => true
|
12755 | *
|
12756 | * circle instanceof Shape;
|
12757 | * // => true
|
12758 | */
|
12759 | function create(prototype, properties) {
|
12760 | var result = baseCreate(prototype);
|
12761 | return properties == null ? result : baseAssign(result, properties);
|
12762 | }
|
12763 |
|
12764 | /**
|
12765 | * Assigns own and inherited enumerable string keyed properties of source
|
12766 | * objects to the destination object for all destination properties that
|
12767 | * resolve to `undefined`. Source objects are applied from left to right.
|
12768 | * Once a property is set, additional values of the same property are ignored.
|
12769 | *
|
12770 | * **Note:** This method mutates `object`.
|
12771 | *
|
12772 | * @static
|
12773 | * @since 0.1.0
|
12774 | * @memberOf _
|
12775 | * @category Object
|
12776 | * @param {Object} object The destination object.
|
12777 | * @param {...Object} [sources] The source objects.
|
12778 | * @returns {Object} Returns `object`.
|
12779 | * @see _.defaultsDeep
|
12780 | * @example
|
12781 | *
|
12782 | * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
12783 | * // => { 'a': 1, 'b': 2 }
|
12784 | */
|
12785 | var defaults = baseRest(function(object, sources) {
|
12786 | object = Object(object);
|
12787 |
|
12788 | var index = -1;
|
12789 | var length = sources.length;
|
12790 | var guard = length > 2 ? sources[2] : undefined;
|
12791 |
|
12792 | if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
12793 | length = 1;
|
12794 | }
|
12795 |
|
12796 | while (++index < length) {
|
12797 | var source = sources[index];
|
12798 | var props = keysIn(source);
|
12799 | var propsIndex = -1;
|
12800 | var propsLength = props.length;
|
12801 |
|
12802 | while (++propsIndex < propsLength) {
|
12803 | var key = props[propsIndex];
|
12804 | var value = object[key];
|
12805 |
|
12806 | if (value === undefined ||
|
12807 | (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
12808 | object[key] = source[key];
|
12809 | }
|
12810 | }
|
12811 | }
|
12812 |
|
12813 | return object;
|
12814 | });
|
12815 |
|
12816 | /**
|
12817 | * This method is like `_.defaults` except that it recursively assigns
|
12818 | * default properties.
|
12819 | *
|
12820 | * **Note:** This method mutates `object`.
|
12821 | *
|
12822 | * @static
|
12823 | * @memberOf _
|
12824 | * @since 3.10.0
|
12825 | * @category Object
|
12826 | * @param {Object} object The destination object.
|
12827 | * @param {...Object} [sources] The source objects.
|
12828 | * @returns {Object} Returns `object`.
|
12829 | * @see _.defaults
|
12830 | * @example
|
12831 | *
|
12832 | * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
|
12833 | * // => { 'a': { 'b': 2, 'c': 3 } }
|
12834 | */
|
12835 | var defaultsDeep = baseRest(function(args) {
|
12836 | args.push(undefined, customDefaultsMerge);
|
12837 | return apply(mergeWith, undefined, args);
|
12838 | });
|
12839 |
|
12840 | /**
|
12841 | * This method is like `_.find` except that it returns the key of the first
|
12842 | * element `predicate` returns truthy for instead of the element itself.
|
12843 | *
|
12844 | * @static
|
12845 | * @memberOf _
|
12846 | * @since 1.1.0
|
12847 | * @category Object
|
12848 | * @param {Object} object The object to inspect.
|
12849 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
12850 | * @returns {string|undefined} Returns the key of the matched element,
|
12851 | * else `undefined`.
|
12852 | * @example
|
12853 | *
|
12854 | * var users = {
|
12855 | * 'barney': { 'age': 36, 'active': true },
|
12856 | * 'fred': { 'age': 40, 'active': false },
|
12857 | * 'pebbles': { 'age': 1, 'active': true }
|
12858 | * };
|
12859 | *
|
12860 | * _.findKey(users, function(o) { return o.age < 40; });
|
12861 | * // => 'barney' (iteration order is not guaranteed)
|
12862 | *
|
12863 | * // The `_.matches` iteratee shorthand.
|
12864 | * _.findKey(users, { 'age': 1, 'active': true });
|
12865 | * // => 'pebbles'
|
12866 | *
|
12867 | * // The `_.matchesProperty` iteratee shorthand.
|
12868 | * _.findKey(users, ['active', false]);
|
12869 | * // => 'fred'
|
12870 | *
|
12871 | * // The `_.property` iteratee shorthand.
|
12872 | * _.findKey(users, 'active');
|
12873 | * // => 'barney'
|
12874 | */
|
12875 | function findKey(object, predicate) {
|
12876 | return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
|
12877 | }
|
12878 |
|
12879 | /**
|
12880 | * This method is like `_.findKey` except that it iterates over elements of
|
12881 | * a collection in the opposite order.
|
12882 | *
|
12883 | * @static
|
12884 | * @memberOf _
|
12885 | * @since 2.0.0
|
12886 | * @category Object
|
12887 | * @param {Object} object The object to inspect.
|
12888 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
12889 | * @returns {string|undefined} Returns the key of the matched element,
|
12890 | * else `undefined`.
|
12891 | * @example
|
12892 | *
|
12893 | * var users = {
|
12894 | * 'barney': { 'age': 36, 'active': true },
|
12895 | * 'fred': { 'age': 40, 'active': false },
|
12896 | * 'pebbles': { 'age': 1, 'active': true }
|
12897 | * };
|
12898 | *
|
12899 | * _.findLastKey(users, function(o) { return o.age < 40; });
|
12900 | * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
|
12901 | *
|
12902 | * // The `_.matches` iteratee shorthand.
|
12903 | * _.findLastKey(users, { 'age': 36, 'active': true });
|
12904 | * // => 'barney'
|
12905 | *
|
12906 | * // The `_.matchesProperty` iteratee shorthand.
|
12907 | * _.findLastKey(users, ['active', false]);
|
12908 | * // => 'fred'
|
12909 | *
|
12910 | * // The `_.property` iteratee shorthand.
|
12911 | * _.findLastKey(users, 'active');
|
12912 | * // => 'pebbles'
|
12913 | */
|
12914 | function findLastKey(object, predicate) {
|
12915 | return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
|
12916 | }
|
12917 |
|
12918 | /**
|
12919 | * Iterates over own and inherited enumerable string keyed properties of an
|
12920 | * object and invokes `iteratee` for each property. The iteratee is invoked
|
12921 | * with three arguments: (value, key, object). Iteratee functions may exit
|
12922 | * iteration early by explicitly returning `false`.
|
12923 | *
|
12924 | * @static
|
12925 | * @memberOf _
|
12926 | * @since 0.3.0
|
12927 | * @category Object
|
12928 | * @param {Object} object The object to iterate over.
|
12929 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
12930 | * @returns {Object} Returns `object`.
|
12931 | * @see _.forInRight
|
12932 | * @example
|
12933 | *
|
12934 | * function Foo() {
|
12935 | * this.a = 1;
|
12936 | * this.b = 2;
|
12937 | * }
|
12938 | *
|
12939 | * Foo.prototype.c = 3;
|
12940 | *
|
12941 | * _.forIn(new Foo, function(value, key) {
|
12942 | * console.log(key);
|
12943 | * });
|
12944 | * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
|
12945 | */
|
12946 | function forIn(object, iteratee) {
|
12947 | return object == null
|
12948 | ? object
|
12949 | : baseFor(object, getIteratee(iteratee, 3), keysIn);
|
12950 | }
|
12951 |
|
12952 | /**
|
12953 | * This method is like `_.forIn` except that it iterates over properties of
|
12954 | * `object` in the opposite order.
|
12955 | *
|
12956 | * @static
|
12957 | * @memberOf _
|
12958 | * @since 2.0.0
|
12959 | * @category Object
|
12960 | * @param {Object} object The object to iterate over.
|
12961 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
12962 | * @returns {Object} Returns `object`.
|
12963 | * @see _.forIn
|
12964 | * @example
|
12965 | *
|
12966 | * function Foo() {
|
12967 | * this.a = 1;
|
12968 | * this.b = 2;
|
12969 | * }
|
12970 | *
|
12971 | * Foo.prototype.c = 3;
|
12972 | *
|
12973 | * _.forInRight(new Foo, function(value, key) {
|
12974 | * console.log(key);
|
12975 | * });
|
12976 | * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
|
12977 | */
|
12978 | function forInRight(object, iteratee) {
|
12979 | return object == null
|
12980 | ? object
|
12981 | : baseForRight(object, getIteratee(iteratee, 3), keysIn);
|
12982 | }
|
12983 |
|
12984 | /**
|
12985 | * Iterates over own enumerable string keyed properties of an object and
|
12986 | * invokes `iteratee` for each property. The iteratee is invoked with three
|
12987 | * arguments: (value, key, object). Iteratee functions may exit iteration
|
12988 | * early by explicitly returning `false`.
|
12989 | *
|
12990 | * @static
|
12991 | * @memberOf _
|
12992 | * @since 0.3.0
|
12993 | * @category Object
|
12994 | * @param {Object} object The object to iterate over.
|
12995 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
12996 | * @returns {Object} Returns `object`.
|
12997 | * @see _.forOwnRight
|
12998 | * @example
|
12999 | *
|
13000 | * function Foo() {
|
13001 | * this.a = 1;
|
13002 | * this.b = 2;
|
13003 | * }
|
13004 | *
|
13005 | * Foo.prototype.c = 3;
|
13006 | *
|
13007 | * _.forOwn(new Foo, function(value, key) {
|
13008 | * console.log(key);
|
13009 | * });
|
13010 | * // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
13011 | */
|
13012 | function forOwn(object, iteratee) {
|
13013 | return object && baseForOwn(object, getIteratee(iteratee, 3));
|
13014 | }
|
13015 |
|
13016 | /**
|
13017 | * This method is like `_.forOwn` except that it iterates over properties of
|
13018 | * `object` in the opposite order.
|
13019 | *
|
13020 | * @static
|
13021 | * @memberOf _
|
13022 | * @since 2.0.0
|
13023 | * @category Object
|
13024 | * @param {Object} object The object to iterate over.
|
13025 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
13026 | * @returns {Object} Returns `object`.
|
13027 | * @see _.forOwn
|
13028 | * @example
|
13029 | *
|
13030 | * function Foo() {
|
13031 | * this.a = 1;
|
13032 | * this.b = 2;
|
13033 | * }
|
13034 | *
|
13035 | * Foo.prototype.c = 3;
|
13036 | *
|
13037 | * _.forOwnRight(new Foo, function(value, key) {
|
13038 | * console.log(key);
|
13039 | * });
|
13040 | * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
|
13041 | */
|
13042 | function forOwnRight(object, iteratee) {
|
13043 | return object && baseForOwnRight(object, getIteratee(iteratee, 3));
|
13044 | }
|
13045 |
|
13046 | /**
|
13047 | * Creates an array of function property names from own enumerable properties
|
13048 | * of `object`.
|
13049 | *
|
13050 | * @static
|
13051 | * @since 0.1.0
|
13052 | * @memberOf _
|
13053 | * @category Object
|
13054 | * @param {Object} object The object to inspect.
|
13055 | * @returns {Array} Returns the function names.
|
13056 | * @see _.functionsIn
|
13057 | * @example
|
13058 | *
|
13059 | * function Foo() {
|
13060 | * this.a = _.constant('a');
|
13061 | * this.b = _.constant('b');
|
13062 | * }
|
13063 | *
|
13064 | * Foo.prototype.c = _.constant('c');
|
13065 | *
|
13066 | * _.functions(new Foo);
|
13067 | * // => ['a', 'b']
|
13068 | */
|
13069 | function functions(object) {
|
13070 | return object == null ? [] : baseFunctions(object, keys(object));
|
13071 | }
|
13072 |
|
13073 | /**
|
13074 | * Creates an array of function property names from own and inherited
|
13075 | * enumerable properties of `object`.
|
13076 | *
|
13077 | * @static
|
13078 | * @memberOf _
|
13079 | * @since 4.0.0
|
13080 | * @category Object
|
13081 | * @param {Object} object The object to inspect.
|
13082 | * @returns {Array} Returns the function names.
|
13083 | * @see _.functions
|
13084 | * @example
|
13085 | *
|
13086 | * function Foo() {
|
13087 | * this.a = _.constant('a');
|
13088 | * this.b = _.constant('b');
|
13089 | * }
|
13090 | *
|
13091 | * Foo.prototype.c = _.constant('c');
|
13092 | *
|
13093 | * _.functionsIn(new Foo);
|
13094 | * // => ['a', 'b', 'c']
|
13095 | */
|
13096 | function functionsIn(object) {
|
13097 | return object == null ? [] : baseFunctions(object, keysIn(object));
|
13098 | }
|
13099 |
|
13100 | /**
|
13101 | * Gets the value at `path` of `object`. If the resolved value is
|
13102 | * `undefined`, the `defaultValue` is returned in its place.
|
13103 | *
|
13104 | * @static
|
13105 | * @memberOf _
|
13106 | * @since 3.7.0
|
13107 | * @category Object
|
13108 | * @param {Object} object The object to query.
|
13109 | * @param {Array|string} path The path of the property to get.
|
13110 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
13111 | * @returns {*} Returns the resolved value.
|
13112 | * @example
|
13113 | *
|
13114 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
13115 | *
|
13116 | * _.get(object, 'a[0].b.c');
|
13117 | * // => 3
|
13118 | *
|
13119 | * _.get(object, ['a', '0', 'b', 'c']);
|
13120 | * // => 3
|
13121 | *
|
13122 | * _.get(object, 'a.b.c', 'default');
|
13123 | * // => 'default'
|
13124 | */
|
13125 | function get(object, path, defaultValue) {
|
13126 | var result = object == null ? undefined : baseGet(object, path);
|
13127 | return result === undefined ? defaultValue : result;
|
13128 | }
|
13129 |
|
13130 | /**
|
13131 | * Checks if `path` is a direct property of `object`.
|
13132 | *
|
13133 | * @static
|
13134 | * @since 0.1.0
|
13135 | * @memberOf _
|
13136 | * @category Object
|
13137 | * @param {Object} object The object to query.
|
13138 | * @param {Array|string} path The path to check.
|
13139 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
13140 | * @example
|
13141 | *
|
13142 | * var object = { 'a': { 'b': 2 } };
|
13143 | * var other = _.create({ 'a': _.create({ 'b': 2 }) });
|
13144 | *
|
13145 | * _.has(object, 'a');
|
13146 | * // => true
|
13147 | *
|
13148 | * _.has(object, 'a.b');
|
13149 | * // => true
|
13150 | *
|
13151 | * _.has(object, ['a', 'b']);
|
13152 | * // => true
|
13153 | *
|
13154 | * _.has(other, 'a');
|
13155 | * // => false
|
13156 | */
|
13157 | function has(object, path) {
|
13158 | return object != null && hasPath(object, path, baseHas);
|
13159 | }
|
13160 |
|
13161 | /**
|
13162 | * Checks if `path` is a direct or inherited property of `object`.
|
13163 | *
|
13164 | * @static
|
13165 | * @memberOf _
|
13166 | * @since 4.0.0
|
13167 | * @category Object
|
13168 | * @param {Object} object The object to query.
|
13169 | * @param {Array|string} path The path to check.
|
13170 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
13171 | * @example
|
13172 | *
|
13173 | * var object = _.create({ 'a': _.create({ 'b': 2 }) });
|
13174 | *
|
13175 | * _.hasIn(object, 'a');
|
13176 | * // => true
|
13177 | *
|
13178 | * _.hasIn(object, 'a.b');
|
13179 | * // => true
|
13180 | *
|
13181 | * _.hasIn(object, ['a', 'b']);
|
13182 | * // => true
|
13183 | *
|
13184 | * _.hasIn(object, 'b');
|
13185 | * // => false
|
13186 | */
|
13187 | function hasIn(object, path) {
|
13188 | return object != null && hasPath(object, path, baseHasIn);
|
13189 | }
|
13190 |
|
13191 | /**
|
13192 | * Creates an object composed of the inverted keys and values of `object`.
|
13193 | * If `object` contains duplicate values, subsequent values overwrite
|
13194 | * property assignments of previous values.
|
13195 | *
|
13196 | * @static
|
13197 | * @memberOf _
|
13198 | * @since 0.7.0
|
13199 | * @category Object
|
13200 | * @param {Object} object The object to invert.
|
13201 | * @returns {Object} Returns the new inverted object.
|
13202 | * @example
|
13203 | *
|
13204 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
13205 | *
|
13206 | * _.invert(object);
|
13207 | * // => { '1': 'c', '2': 'b' }
|
13208 | */
|
13209 | var invert = createInverter(function(result, value, key) {
|
13210 | if (value != null &&
|
13211 | typeof value.toString != 'function') {
|
13212 | value = nativeObjectToString.call(value);
|
13213 | }
|
13214 |
|
13215 | result[value] = key;
|
13216 | }, constant(identity));
|
13217 |
|
13218 | /**
|
13219 | * This method is like `_.invert` except that the inverted object is generated
|
13220 | * from the results of running each element of `object` thru `iteratee`. The
|
13221 | * corresponding inverted value of each inverted key is an array of keys
|
13222 | * responsible for generating the inverted value. The iteratee is invoked
|
13223 | * with one argument: (value).
|
13224 | *
|
13225 | * @static
|
13226 | * @memberOf _
|
13227 | * @since 4.1.0
|
13228 | * @category Object
|
13229 | * @param {Object} object The object to invert.
|
13230 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
13231 | * @returns {Object} Returns the new inverted object.
|
13232 | * @example
|
13233 | *
|
13234 | * var object = { 'a': 1, 'b': 2, 'c': 1 };
|
13235 | *
|
13236 | * _.invertBy(object);
|
13237 | * // => { '1': ['a', 'c'], '2': ['b'] }
|
13238 | *
|
13239 | * _.invertBy(object, function(value) {
|
13240 | * return 'group' + value;
|
13241 | * });
|
13242 | * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
13243 | */
|
13244 | var invertBy = createInverter(function(result, value, key) {
|
13245 | if (value != null &&
|
13246 | typeof value.toString != 'function') {
|
13247 | value = nativeObjectToString.call(value);
|
13248 | }
|
13249 |
|
13250 | if (hasOwnProperty.call(result, value)) {
|
13251 | result[value].push(key);
|
13252 | } else {
|
13253 | result[value] = [key];
|
13254 | }
|
13255 | }, getIteratee);
|
13256 |
|
13257 | /**
|
13258 | * Invokes the method at `path` of `object`.
|
13259 | *
|
13260 | * @static
|
13261 | * @memberOf _
|
13262 | * @since 4.0.0
|
13263 | * @category Object
|
13264 | * @param {Object} object The object to query.
|
13265 | * @param {Array|string} path The path of the method to invoke.
|
13266 | * @param {...*} [args] The arguments to invoke the method with.
|
13267 | * @returns {*} Returns the result of the invoked method.
|
13268 | * @example
|
13269 | *
|
13270 | * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
|
13271 | *
|
13272 | * _.invoke(object, 'a[0].b.c.slice', 1, 3);
|
13273 | * // => [2, 3]
|
13274 | */
|
13275 | var invoke = baseRest(baseInvoke);
|
13276 |
|
13277 | /**
|
13278 | * Creates an array of the own enumerable property names of `object`.
|
13279 | *
|
13280 | * **Note:** Non-object values are coerced to objects. See the
|
13281 | * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
13282 | * for more details.
|
13283 | *
|
13284 | * @static
|
13285 | * @since 0.1.0
|
13286 | * @memberOf _
|
13287 | * @category Object
|
13288 | * @param {Object} object The object to query.
|
13289 | * @returns {Array} Returns the array of property names.
|
13290 | * @example
|
13291 | *
|
13292 | * function Foo() {
|
13293 | * this.a = 1;
|
13294 | * this.b = 2;
|
13295 | * }
|
13296 | *
|
13297 | * Foo.prototype.c = 3;
|
13298 | *
|
13299 | * _.keys(new Foo);
|
13300 | * // => ['a', 'b'] (iteration order is not guaranteed)
|
13301 | *
|
13302 | * _.keys('hi');
|
13303 | * // => ['0', '1']
|
13304 | */
|
13305 | function keys(object) {
|
13306 | return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
13307 | }
|
13308 |
|
13309 | /**
|
13310 | * Creates an array of the own and inherited enumerable property names of `object`.
|
13311 | *
|
13312 | * **Note:** Non-object values are coerced to objects.
|
13313 | *
|
13314 | * @static
|
13315 | * @memberOf _
|
13316 | * @since 3.0.0
|
13317 | * @category Object
|
13318 | * @param {Object} object The object to query.
|
13319 | * @returns {Array} Returns the array of property names.
|
13320 | * @example
|
13321 | *
|
13322 | * function Foo() {
|
13323 | * this.a = 1;
|
13324 | * this.b = 2;
|
13325 | * }
|
13326 | *
|
13327 | * Foo.prototype.c = 3;
|
13328 | *
|
13329 | * _.keysIn(new Foo);
|
13330 | * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
13331 | */
|
13332 | function keysIn(object) {
|
13333 | return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
|
13334 | }
|
13335 |
|
13336 | /**
|
13337 | * The opposite of `_.mapValues`; this method creates an object with the
|
13338 | * same values as `object` and keys generated by running each own enumerable
|
13339 | * string keyed property of `object` thru `iteratee`. The iteratee is invoked
|
13340 | * with three arguments: (value, key, object).
|
13341 | *
|
13342 | * @static
|
13343 | * @memberOf _
|
13344 | * @since 3.8.0
|
13345 | * @category Object
|
13346 | * @param {Object} object The object to iterate over.
|
13347 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
13348 | * @returns {Object} Returns the new mapped object.
|
13349 | * @see _.mapValues
|
13350 | * @example
|
13351 | *
|
13352 | * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
|
13353 | * return key + value;
|
13354 | * });
|
13355 | * // => { 'a1': 1, 'b2': 2 }
|
13356 | */
|
13357 | function mapKeys(object, iteratee) {
|
13358 | var result = {};
|
13359 | iteratee = getIteratee(iteratee, 3);
|
13360 |
|
13361 | baseForOwn(object, function(value, key, object) {
|
13362 | baseAssignValue(result, iteratee(value, key, object), value);
|
13363 | });
|
13364 | return result;
|
13365 | }
|
13366 |
|
13367 | /**
|
13368 | * Creates an object with the same keys as `object` and values generated
|
13369 | * by running each own enumerable string keyed property of `object` thru
|
13370 | * `iteratee`. The iteratee is invoked with three arguments:
|
13371 | * (value, key, object).
|
13372 | *
|
13373 | * @static
|
13374 | * @memberOf _
|
13375 | * @since 2.4.0
|
13376 | * @category Object
|
13377 | * @param {Object} object The object to iterate over.
|
13378 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
13379 | * @returns {Object} Returns the new mapped object.
|
13380 | * @see _.mapKeys
|
13381 | * @example
|
13382 | *
|
13383 | * var users = {
|
13384 | * 'fred': { 'user': 'fred', 'age': 40 },
|
13385 | * 'pebbles': { 'user': 'pebbles', 'age': 1 }
|
13386 | * };
|
13387 | *
|
13388 | * _.mapValues(users, function(o) { return o.age; });
|
13389 | * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
13390 | *
|
13391 | * // The `_.property` iteratee shorthand.
|
13392 | * _.mapValues(users, 'age');
|
13393 | * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
13394 | */
|
13395 | function mapValues(object, iteratee) {
|
13396 | var result = {};
|
13397 | iteratee = getIteratee(iteratee, 3);
|
13398 |
|
13399 | baseForOwn(object, function(value, key, object) {
|
13400 | baseAssignValue(result, key, iteratee(value, key, object));
|
13401 | });
|
13402 | return result;
|
13403 | }
|
13404 |
|
13405 | /**
|
13406 | * This method is like `_.assign` except that it recursively merges own and
|
13407 | * inherited enumerable string keyed properties of source objects into the
|
13408 | * destination object. Source properties that resolve to `undefined` are
|
13409 | * skipped if a destination value exists. Array and plain object properties
|
13410 | * are merged recursively. Other objects and value types are overridden by
|
13411 | * assignment. Source objects are applied from left to right. Subsequent
|
13412 | * sources overwrite property assignments of previous sources.
|
13413 | *
|
13414 | * **Note:** This method mutates `object`.
|
13415 | *
|
13416 | * @static
|
13417 | * @memberOf _
|
13418 | * @since 0.5.0
|
13419 | * @category Object
|
13420 | * @param {Object} object The destination object.
|
13421 | * @param {...Object} [sources] The source objects.
|
13422 | * @returns {Object} Returns `object`.
|
13423 | * @example
|
13424 | *
|
13425 | * var object = {
|
13426 | * 'a': [{ 'b': 2 }, { 'd': 4 }]
|
13427 | * };
|
13428 | *
|
13429 | * var other = {
|
13430 | * 'a': [{ 'c': 3 }, { 'e': 5 }]
|
13431 | * };
|
13432 | *
|
13433 | * _.merge(object, other);
|
13434 | * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
|
13435 | */
|
13436 | var merge = createAssigner(function(object, source, srcIndex) {
|
13437 | baseMerge(object, source, srcIndex);
|
13438 | });
|
13439 |
|
13440 | /**
|
13441 | * This method is like `_.merge` except that it accepts `customizer` which
|
13442 | * is invoked to produce the merged values of the destination and source
|
13443 | * properties. If `customizer` returns `undefined`, merging is handled by the
|
13444 | * method instead. The `customizer` is invoked with six arguments:
|
13445 | * (objValue, srcValue, key, object, source, stack).
|
13446 | *
|
13447 | * **Note:** This method mutates `object`.
|
13448 | *
|
13449 | * @static
|
13450 | * @memberOf _
|
13451 | * @since 4.0.0
|
13452 | * @category Object
|
13453 | * @param {Object} object The destination object.
|
13454 | * @param {...Object} sources The source objects.
|
13455 | * @param {Function} customizer The function to customize assigned values.
|
13456 | * @returns {Object} Returns `object`.
|
13457 | * @example
|
13458 | *
|
13459 | * function customizer(objValue, srcValue) {
|
13460 | * if (_.isArray(objValue)) {
|
13461 | * return objValue.concat(srcValue);
|
13462 | * }
|
13463 | * }
|
13464 | *
|
13465 | * var object = { 'a': [1], 'b': [2] };
|
13466 | * var other = { 'a': [3], 'b': [4] };
|
13467 | *
|
13468 | * _.mergeWith(object, other, customizer);
|
13469 | * // => { 'a': [1, 3], 'b': [2, 4] }
|
13470 | */
|
13471 | var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
|
13472 | baseMerge(object, source, srcIndex, customizer);
|
13473 | });
|
13474 |
|
13475 | /**
|
13476 | * The opposite of `_.pick`; this method creates an object composed of the
|
13477 | * own and inherited enumerable property paths of `object` that are not omitted.
|
13478 | *
|
13479 | * **Note:** This method is considerably slower than `_.pick`.
|
13480 | *
|
13481 | * @static
|
13482 | * @since 0.1.0
|
13483 | * @memberOf _
|
13484 | * @category Object
|
13485 | * @param {Object} object The source object.
|
13486 | * @param {...(string|string[])} [paths] The property paths to omit.
|
13487 | * @returns {Object} Returns the new object.
|
13488 | * @example
|
13489 | *
|
13490 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
13491 | *
|
13492 | * _.omit(object, ['a', 'c']);
|
13493 | * // => { 'b': '2' }
|
13494 | */
|
13495 | var omit = flatRest(function(object, paths) {
|
13496 | var result = {};
|
13497 | if (object == null) {
|
13498 | return result;
|
13499 | }
|
13500 | var isDeep = false;
|
13501 | paths = arrayMap(paths, function(path) {
|
13502 | path = castPath(path, object);
|
13503 | isDeep || (isDeep = path.length > 1);
|
13504 | return path;
|
13505 | });
|
13506 | copyObject(object, getAllKeysIn(object), result);
|
13507 | if (isDeep) {
|
13508 | result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
|
13509 | }
|
13510 | var length = paths.length;
|
13511 | while (length--) {
|
13512 | baseUnset(result, paths[length]);
|
13513 | }
|
13514 | return result;
|
13515 | });
|
13516 |
|
13517 | /**
|
13518 | * The opposite of `_.pickBy`; this method creates an object composed of
|
13519 | * the own and inherited enumerable string keyed properties of `object` that
|
13520 | * `predicate` doesn't return truthy for. The predicate is invoked with two
|
13521 | * arguments: (value, key).
|
13522 | *
|
13523 | * @static
|
13524 | * @memberOf _
|
13525 | * @since 4.0.0
|
13526 | * @category Object
|
13527 | * @param {Object} object The source object.
|
13528 | * @param {Function} [predicate=_.identity] The function invoked per property.
|
13529 | * @returns {Object} Returns the new object.
|
13530 | * @example
|
13531 | *
|
13532 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
13533 | *
|
13534 | * _.omitBy(object, _.isNumber);
|
13535 | * // => { 'b': '2' }
|
13536 | */
|
13537 | function omitBy(object, predicate) {
|
13538 | return pickBy(object, negate(getIteratee(predicate)));
|
13539 | }
|
13540 |
|
13541 | /**
|
13542 | * Creates an object composed of the picked `object` properties.
|
13543 | *
|
13544 | * @static
|
13545 | * @since 0.1.0
|
13546 | * @memberOf _
|
13547 | * @category Object
|
13548 | * @param {Object} object The source object.
|
13549 | * @param {...(string|string[])} [paths] The property paths to pick.
|
13550 | * @returns {Object} Returns the new object.
|
13551 | * @example
|
13552 | *
|
13553 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
13554 | *
|
13555 | * _.pick(object, ['a', 'c']);
|
13556 | * // => { 'a': 1, 'c': 3 }
|
13557 | */
|
13558 | var pick = flatRest(function(object, paths) {
|
13559 | return object == null ? {} : basePick(object, paths);
|
13560 | });
|
13561 |
|
13562 | /**
|
13563 | * Creates an object composed of the `object` properties `predicate` returns
|
13564 | * truthy for. The predicate is invoked with two arguments: (value, key).
|
13565 | *
|
13566 | * @static
|
13567 | * @memberOf _
|
13568 | * @since 4.0.0
|
13569 | * @category Object
|
13570 | * @param {Object} object The source object.
|
13571 | * @param {Function} [predicate=_.identity] The function invoked per property.
|
13572 | * @returns {Object} Returns the new object.
|
13573 | * @example
|
13574 | *
|
13575 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
13576 | *
|
13577 | * _.pickBy(object, _.isNumber);
|
13578 | * // => { 'a': 1, 'c': 3 }
|
13579 | */
|
13580 | function pickBy(object, predicate) {
|
13581 | if (object == null) {
|
13582 | return {};
|
13583 | }
|
13584 | var props = arrayMap(getAllKeysIn(object), function(prop) {
|
13585 | return [prop];
|
13586 | });
|
13587 | predicate = getIteratee(predicate);
|
13588 | return basePickBy(object, props, function(value, path) {
|
13589 | return predicate(value, path[0]);
|
13590 | });
|
13591 | }
|
13592 |
|
13593 | /**
|
13594 | * This method is like `_.get` except that if the resolved value is a
|
13595 | * function it's invoked with the `this` binding of its parent object and
|
13596 | * its result is returned.
|
13597 | *
|
13598 | * @static
|
13599 | * @since 0.1.0
|
13600 | * @memberOf _
|
13601 | * @category Object
|
13602 | * @param {Object} object The object to query.
|
13603 | * @param {Array|string} path The path of the property to resolve.
|
13604 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
13605 | * @returns {*} Returns the resolved value.
|
13606 | * @example
|
13607 | *
|
13608 | * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
|
13609 | *
|
13610 | * _.result(object, 'a[0].b.c1');
|
13611 | * // => 3
|
13612 | *
|
13613 | * _.result(object, 'a[0].b.c2');
|
13614 | * // => 4
|
13615 | *
|
13616 | * _.result(object, 'a[0].b.c3', 'default');
|
13617 | * // => 'default'
|
13618 | *
|
13619 | * _.result(object, 'a[0].b.c3', _.constant('default'));
|
13620 | * // => 'default'
|
13621 | */
|
13622 | function result(object, path, defaultValue) {
|
13623 | path = castPath(path, object);
|
13624 |
|
13625 | var index = -1,
|
13626 | length = path.length;
|
13627 |
|
13628 | // Ensure the loop is entered when path is empty.
|
13629 | if (!length) {
|
13630 | length = 1;
|
13631 | object = undefined;
|
13632 | }
|
13633 | while (++index < length) {
|
13634 | var value = object == null ? undefined : object[toKey(path[index])];
|
13635 | if (value === undefined) {
|
13636 | index = length;
|
13637 | value = defaultValue;
|
13638 | }
|
13639 | object = isFunction(value) ? value.call(object) : value;
|
13640 | }
|
13641 | return object;
|
13642 | }
|
13643 |
|
13644 | /**
|
13645 | * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
|
13646 | * it's created. Arrays are created for missing index properties while objects
|
13647 | * are created for all other missing properties. Use `_.setWith` to customize
|
13648 | * `path` creation.
|
13649 | *
|
13650 | * **Note:** This method mutates `object`.
|
13651 | *
|
13652 | * @static
|
13653 | * @memberOf _
|
13654 | * @since 3.7.0
|
13655 | * @category Object
|
13656 | * @param {Object} object The object to modify.
|
13657 | * @param {Array|string} path The path of the property to set.
|
13658 | * @param {*} value The value to set.
|
13659 | * @returns {Object} Returns `object`.
|
13660 | * @example
|
13661 | *
|
13662 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
13663 | *
|
13664 | * _.set(object, 'a[0].b.c', 4);
|
13665 | * console.log(object.a[0].b.c);
|
13666 | * // => 4
|
13667 | *
|
13668 | * _.set(object, ['x', '0', 'y', 'z'], 5);
|
13669 | * console.log(object.x[0].y.z);
|
13670 | * // => 5
|
13671 | */
|
13672 | function set(object, path, value) {
|
13673 | return object == null ? object : baseSet(object, path, value);
|
13674 | }
|
13675 |
|
13676 | /**
|
13677 | * This method is like `_.set` except that it accepts `customizer` which is
|
13678 | * invoked to produce the objects of `path`. If `customizer` returns `undefined`
|
13679 | * path creation is handled by the method instead. The `customizer` is invoked
|
13680 | * with three arguments: (nsValue, key, nsObject).
|
13681 | *
|
13682 | * **Note:** This method mutates `object`.
|
13683 | *
|
13684 | * @static
|
13685 | * @memberOf _
|
13686 | * @since 4.0.0
|
13687 | * @category Object
|
13688 | * @param {Object} object The object to modify.
|
13689 | * @param {Array|string} path The path of the property to set.
|
13690 | * @param {*} value The value to set.
|
13691 | * @param {Function} [customizer] The function to customize assigned values.
|
13692 | * @returns {Object} Returns `object`.
|
13693 | * @example
|
13694 | *
|
13695 | * var object = {};
|
13696 | *
|
13697 | * _.setWith(object, '[0][1]', 'a', Object);
|
13698 | * // => { '0': { '1': 'a' } }
|
13699 | */
|
13700 | function setWith(object, path, value, customizer) {
|
13701 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
13702 | return object == null ? object : baseSet(object, path, value, customizer);
|
13703 | }
|
13704 |
|
13705 | /**
|
13706 | * Creates an array of own enumerable string keyed-value pairs for `object`
|
13707 | * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
|
13708 | * entries are returned.
|
13709 | *
|
13710 | * @static
|
13711 | * @memberOf _
|
13712 | * @since 4.0.0
|
13713 | * @alias entries
|
13714 | * @category Object
|
13715 | * @param {Object} object The object to query.
|
13716 | * @returns {Array} Returns the key-value pairs.
|
13717 | * @example
|
13718 | *
|
13719 | * function Foo() {
|
13720 | * this.a = 1;
|
13721 | * this.b = 2;
|
13722 | * }
|
13723 | *
|
13724 | * Foo.prototype.c = 3;
|
13725 | *
|
13726 | * _.toPairs(new Foo);
|
13727 | * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
|
13728 | */
|
13729 | var toPairs = createToPairs(keys);
|
13730 |
|
13731 | /**
|
13732 | * Creates an array of own and inherited enumerable string keyed-value pairs
|
13733 | * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
|
13734 | * or set, its entries are returned.
|
13735 | *
|
13736 | * @static
|
13737 | * @memberOf _
|
13738 | * @since 4.0.0
|
13739 | * @alias entriesIn
|
13740 | * @category Object
|
13741 | * @param {Object} object The object to query.
|
13742 | * @returns {Array} Returns the key-value pairs.
|
13743 | * @example
|
13744 | *
|
13745 | * function Foo() {
|
13746 | * this.a = 1;
|
13747 | * this.b = 2;
|
13748 | * }
|
13749 | *
|
13750 | * Foo.prototype.c = 3;
|
13751 | *
|
13752 | * _.toPairsIn(new Foo);
|
13753 | * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
|
13754 | */
|
13755 | var toPairsIn = createToPairs(keysIn);
|
13756 |
|
13757 | /**
|
13758 | * An alternative to `_.reduce`; this method transforms `object` to a new
|
13759 | * `accumulator` object which is the result of running each of its own
|
13760 | * enumerable string keyed properties thru `iteratee`, with each invocation
|
13761 | * potentially mutating the `accumulator` object. If `accumulator` is not
|
13762 | * provided, a new object with the same `[[Prototype]]` will be used. The
|
13763 | * iteratee is invoked with four arguments: (accumulator, value, key, object).
|
13764 | * Iteratee functions may exit iteration early by explicitly returning `false`.
|
13765 | *
|
13766 | * @static
|
13767 | * @memberOf _
|
13768 | * @since 1.3.0
|
13769 | * @category Object
|
13770 | * @param {Object} object The object to iterate over.
|
13771 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
13772 | * @param {*} [accumulator] The custom accumulator value.
|
13773 | * @returns {*} Returns the accumulated value.
|
13774 | * @example
|
13775 | *
|
13776 | * _.transform([2, 3, 4], function(result, n) {
|
13777 | * result.push(n *= n);
|
13778 | * return n % 2 == 0;
|
13779 | * }, []);
|
13780 | * // => [4, 9]
|
13781 | *
|
13782 | * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
13783 | * (result[value] || (result[value] = [])).push(key);
|
13784 | * }, {});
|
13785 | * // => { '1': ['a', 'c'], '2': ['b'] }
|
13786 | */
|
13787 | function transform(object, iteratee, accumulator) {
|
13788 | var isArr = isArray(object),
|
13789 | isArrLike = isArr || isBuffer(object) || isTypedArray(object);
|
13790 |
|
13791 | iteratee = getIteratee(iteratee, 4);
|
13792 | if (accumulator == null) {
|
13793 | var Ctor = object && object.constructor;
|
13794 | if (isArrLike) {
|
13795 | accumulator = isArr ? new Ctor : [];
|
13796 | }
|
13797 | else if (isObject(object)) {
|
13798 | accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
|
13799 | }
|
13800 | else {
|
13801 | accumulator = {};
|
13802 | }
|
13803 | }
|
13804 | (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
|
13805 | return iteratee(accumulator, value, index, object);
|
13806 | });
|
13807 | return accumulator;
|
13808 | }
|
13809 |
|
13810 | /**
|
13811 | * Removes the property at `path` of `object`.
|
13812 | *
|
13813 | * **Note:** This method mutates `object`.
|
13814 | *
|
13815 | * @static
|
13816 | * @memberOf _
|
13817 | * @since 4.0.0
|
13818 | * @category Object
|
13819 | * @param {Object} object The object to modify.
|
13820 | * @param {Array|string} path The path of the property to unset.
|
13821 | * @returns {boolean} Returns `true` if the property is deleted, else `false`.
|
13822 | * @example
|
13823 | *
|
13824 | * var object = { 'a': [{ 'b': { 'c': 7 } }] };
|
13825 | * _.unset(object, 'a[0].b.c');
|
13826 | * // => true
|
13827 | *
|
13828 | * console.log(object);
|
13829 | * // => { 'a': [{ 'b': {} }] };
|
13830 | *
|
13831 | * _.unset(object, ['a', '0', 'b', 'c']);
|
13832 | * // => true
|
13833 | *
|
13834 | * console.log(object);
|
13835 | * // => { 'a': [{ 'b': {} }] };
|
13836 | */
|
13837 | function unset(object, path) {
|
13838 | return object == null ? true : baseUnset(object, path);
|
13839 | }
|
13840 |
|
13841 | /**
|
13842 | * This method is like `_.set` except that accepts `updater` to produce the
|
13843 | * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
|
13844 | * is invoked with one argument: (value).
|
13845 | *
|
13846 | * **Note:** This method mutates `object`.
|
13847 | *
|
13848 | * @static
|
13849 | * @memberOf _
|
13850 | * @since 4.6.0
|
13851 | * @category Object
|
13852 | * @param {Object} object The object to modify.
|
13853 | * @param {Array|string} path The path of the property to set.
|
13854 | * @param {Function} updater The function to produce the updated value.
|
13855 | * @returns {Object} Returns `object`.
|
13856 | * @example
|
13857 | *
|
13858 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
13859 | *
|
13860 | * _.update(object, 'a[0].b.c', function(n) { return n * n; });
|
13861 | * console.log(object.a[0].b.c);
|
13862 | * // => 9
|
13863 | *
|
13864 | * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
|
13865 | * console.log(object.x[0].y.z);
|
13866 | * // => 0
|
13867 | */
|
13868 | function update(object, path, updater) {
|
13869 | return object == null ? object : baseUpdate(object, path, castFunction(updater));
|
13870 | }
|
13871 |
|
13872 | /**
|
13873 | * This method is like `_.update` except that it accepts `customizer` which is
|
13874 | * invoked to produce the objects of `path`. If `customizer` returns `undefined`
|
13875 | * path creation is handled by the method instead. The `customizer` is invoked
|
13876 | * with three arguments: (nsValue, key, nsObject).
|
13877 | *
|
13878 | * **Note:** This method mutates `object`.
|
13879 | *
|
13880 | * @static
|
13881 | * @memberOf _
|
13882 | * @since 4.6.0
|
13883 | * @category Object
|
13884 | * @param {Object} object The object to modify.
|
13885 | * @param {Array|string} path The path of the property to set.
|
13886 | * @param {Function} updater The function to produce the updated value.
|
13887 | * @param {Function} [customizer] The function to customize assigned values.
|
13888 | * @returns {Object} Returns `object`.
|
13889 | * @example
|
13890 | *
|
13891 | * var object = {};
|
13892 | *
|
13893 | * _.updateWith(object, '[0][1]', _.constant('a'), Object);
|
13894 | * // => { '0': { '1': 'a' } }
|
13895 | */
|
13896 | function updateWith(object, path, updater, customizer) {
|
13897 | customizer = typeof customizer == 'function' ? customizer : undefined;
|
13898 | return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
|
13899 | }
|
13900 |
|
13901 | /**
|
13902 | * Creates an array of the own enumerable string keyed property values of `object`.
|
13903 | *
|
13904 | * **Note:** Non-object values are coerced to objects.
|
13905 | *
|
13906 | * @static
|
13907 | * @since 0.1.0
|
13908 | * @memberOf _
|
13909 | * @category Object
|
13910 | * @param {Object} object The object to query.
|
13911 | * @returns {Array} Returns the array of property values.
|
13912 | * @example
|
13913 | *
|
13914 | * function Foo() {
|
13915 | * this.a = 1;
|
13916 | * this.b = 2;
|
13917 | * }
|
13918 | *
|
13919 | * Foo.prototype.c = 3;
|
13920 | *
|
13921 | * _.values(new Foo);
|
13922 | * // => [1, 2] (iteration order is not guaranteed)
|
13923 | *
|
13924 | * _.values('hi');
|
13925 | * // => ['h', 'i']
|
13926 | */
|
13927 | function values(object) {
|
13928 | return object == null ? [] : baseValues(object, keys(object));
|
13929 | }
|
13930 |
|
13931 | /**
|
13932 | * Creates an array of the own and inherited enumerable string keyed property
|
13933 | * values of `object`.
|
13934 | *
|
13935 | * **Note:** Non-object values are coerced to objects.
|
13936 | *
|
13937 | * @static
|
13938 | * @memberOf _
|
13939 | * @since 3.0.0
|
13940 | * @category Object
|
13941 | * @param {Object} object The object to query.
|
13942 | * @returns {Array} Returns the array of property values.
|
13943 | * @example
|
13944 | *
|
13945 | * function Foo() {
|
13946 | * this.a = 1;
|
13947 | * this.b = 2;
|
13948 | * }
|
13949 | *
|
13950 | * Foo.prototype.c = 3;
|
13951 | *
|
13952 | * _.valuesIn(new Foo);
|
13953 | * // => [1, 2, 3] (iteration order is not guaranteed)
|
13954 | */
|
13955 | function valuesIn(object) {
|
13956 | return object == null ? [] : baseValues(object, keysIn(object));
|
13957 | }
|
13958 |
|
13959 | /*------------------------------------------------------------------------*/
|
13960 |
|
13961 | /**
|
13962 | * Clamps `number` within the inclusive `lower` and `upper` bounds.
|
13963 | *
|
13964 | * @static
|
13965 | * @memberOf _
|
13966 | * @since 4.0.0
|
13967 | * @category Number
|
13968 | * @param {number} number The number to clamp.
|
13969 | * @param {number} [lower] The lower bound.
|
13970 | * @param {number} upper The upper bound.
|
13971 | * @returns {number} Returns the clamped number.
|
13972 | * @example
|
13973 | *
|
13974 | * _.clamp(-10, -5, 5);
|
13975 | * // => -5
|
13976 | *
|
13977 | * _.clamp(10, -5, 5);
|
13978 | * // => 5
|
13979 | */
|
13980 | function clamp(number, lower, upper) {
|
13981 | if (upper === undefined) {
|
13982 | upper = lower;
|
13983 | lower = undefined;
|
13984 | }
|
13985 | if (upper !== undefined) {
|
13986 | upper = toNumber(upper);
|
13987 | upper = upper === upper ? upper : 0;
|
13988 | }
|
13989 | if (lower !== undefined) {
|
13990 | lower = toNumber(lower);
|
13991 | lower = lower === lower ? lower : 0;
|
13992 | }
|
13993 | return baseClamp(toNumber(number), lower, upper);
|
13994 | }
|
13995 |
|
13996 | /**
|
13997 | * Checks if `n` is between `start` and up to, but not including, `end`. If
|
13998 | * `end` is not specified, it's set to `start` with `start` then set to `0`.
|
13999 | * If `start` is greater than `end` the params are swapped to support
|
14000 | * negative ranges.
|
14001 | *
|
14002 | * @static
|
14003 | * @memberOf _
|
14004 | * @since 3.3.0
|
14005 | * @category Number
|
14006 | * @param {number} number The number to check.
|
14007 | * @param {number} [start=0] The start of the range.
|
14008 | * @param {number} end The end of the range.
|
14009 | * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
|
14010 | * @see _.range, _.rangeRight
|
14011 | * @example
|
14012 | *
|
14013 | * _.inRange(3, 2, 4);
|
14014 | * // => true
|
14015 | *
|
14016 | * _.inRange(4, 8);
|
14017 | * // => true
|
14018 | *
|
14019 | * _.inRange(4, 2);
|
14020 | * // => false
|
14021 | *
|
14022 | * _.inRange(2, 2);
|
14023 | * // => false
|
14024 | *
|
14025 | * _.inRange(1.2, 2);
|
14026 | * // => true
|
14027 | *
|
14028 | * _.inRange(5.2, 4);
|
14029 | * // => false
|
14030 | *
|
14031 | * _.inRange(-3, -2, -6);
|
14032 | * // => true
|
14033 | */
|
14034 | function inRange(number, start, end) {
|
14035 | start = toFinite(start);
|
14036 | if (end === undefined) {
|
14037 | end = start;
|
14038 | start = 0;
|
14039 | } else {
|
14040 | end = toFinite(end);
|
14041 | }
|
14042 | number = toNumber(number);
|
14043 | return baseInRange(number, start, end);
|
14044 | }
|
14045 |
|
14046 | /**
|
14047 | * Produces a random number between the inclusive `lower` and `upper` bounds.
|
14048 | * If only one argument is provided a number between `0` and the given number
|
14049 | * is returned. If `floating` is `true`, or either `lower` or `upper` are
|
14050 | * floats, a floating-point number is returned instead of an integer.
|
14051 | *
|
14052 | * **Note:** JavaScript follows the IEEE-754 standard for resolving
|
14053 | * floating-point values which can produce unexpected results.
|
14054 | *
|
14055 | * @static
|
14056 | * @memberOf _
|
14057 | * @since 0.7.0
|
14058 | * @category Number
|
14059 | * @param {number} [lower=0] The lower bound.
|
14060 | * @param {number} [upper=1] The upper bound.
|
14061 | * @param {boolean} [floating] Specify returning a floating-point number.
|
14062 | * @returns {number} Returns the random number.
|
14063 | * @example
|
14064 | *
|
14065 | * _.random(0, 5);
|
14066 | * // => an integer between 0 and 5
|
14067 | *
|
14068 | * _.random(5);
|
14069 | * // => also an integer between 0 and 5
|
14070 | *
|
14071 | * _.random(5, true);
|
14072 | * // => a floating-point number between 0 and 5
|
14073 | *
|
14074 | * _.random(1.2, 5.2);
|
14075 | * // => a floating-point number between 1.2 and 5.2
|
14076 | */
|
14077 | function random(lower, upper, floating) {
|
14078 | if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
|
14079 | upper = floating = undefined;
|
14080 | }
|
14081 | if (floating === undefined) {
|
14082 | if (typeof upper == 'boolean') {
|
14083 | floating = upper;
|
14084 | upper = undefined;
|
14085 | }
|
14086 | else if (typeof lower == 'boolean') {
|
14087 | floating = lower;
|
14088 | lower = undefined;
|
14089 | }
|
14090 | }
|
14091 | if (lower === undefined && upper === undefined) {
|
14092 | lower = 0;
|
14093 | upper = 1;
|
14094 | }
|
14095 | else {
|
14096 | lower = toFinite(lower);
|
14097 | if (upper === undefined) {
|
14098 | upper = lower;
|
14099 | lower = 0;
|
14100 | } else {
|
14101 | upper = toFinite(upper);
|
14102 | }
|
14103 | }
|
14104 | if (lower > upper) {
|
14105 | var temp = lower;
|
14106 | lower = upper;
|
14107 | upper = temp;
|
14108 | }
|
14109 | if (floating || lower % 1 || upper % 1) {
|
14110 | var rand = nativeRandom();
|
14111 | return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
|
14112 | }
|
14113 | return baseRandom(lower, upper);
|
14114 | }
|
14115 |
|
14116 | /*------------------------------------------------------------------------*/
|
14117 |
|
14118 | /**
|
14119 | * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
|
14120 | *
|
14121 | * @static
|
14122 | * @memberOf _
|
14123 | * @since 3.0.0
|
14124 | * @category String
|
14125 | * @param {string} [string=''] The string to convert.
|
14126 | * @returns {string} Returns the camel cased string.
|
14127 | * @example
|
14128 | *
|
14129 | * _.camelCase('Foo Bar');
|
14130 | * // => 'fooBar'
|
14131 | *
|
14132 | * _.camelCase('--foo-bar--');
|
14133 | * // => 'fooBar'
|
14134 | *
|
14135 | * _.camelCase('__FOO_BAR__');
|
14136 | * // => 'fooBar'
|
14137 | */
|
14138 | var camelCase = createCompounder(function(result, word, index) {
|
14139 | word = word.toLowerCase();
|
14140 | return result + (index ? capitalize(word) : word);
|
14141 | });
|
14142 |
|
14143 | /**
|
14144 | * Converts the first character of `string` to upper case and the remaining
|
14145 | * to lower case.
|
14146 | *
|
14147 | * @static
|
14148 | * @memberOf _
|
14149 | * @since 3.0.0
|
14150 | * @category String
|
14151 | * @param {string} [string=''] The string to capitalize.
|
14152 | * @returns {string} Returns the capitalized string.
|
14153 | * @example
|
14154 | *
|
14155 | * _.capitalize('FRED');
|
14156 | * // => 'Fred'
|
14157 | */
|
14158 | function capitalize(string) {
|
14159 | return upperFirst(toString(string).toLowerCase());
|
14160 | }
|
14161 |
|
14162 | /**
|
14163 | * Deburrs `string` by converting
|
14164 | * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
14165 | * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
|
14166 | * letters to basic Latin letters and removing
|
14167 | * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
14168 | *
|
14169 | * @static
|
14170 | * @memberOf _
|
14171 | * @since 3.0.0
|
14172 | * @category String
|
14173 | * @param {string} [string=''] The string to deburr.
|
14174 | * @returns {string} Returns the deburred string.
|
14175 | * @example
|
14176 | *
|
14177 | * _.deburr('déjà vu');
|
14178 | * // => 'deja vu'
|
14179 | */
|
14180 | function deburr(string) {
|
14181 | string = toString(string);
|
14182 | return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
|
14183 | }
|
14184 |
|
14185 | /**
|
14186 | * Checks if `string` ends with the given target string.
|
14187 | *
|
14188 | * @static
|
14189 | * @memberOf _
|
14190 | * @since 3.0.0
|
14191 | * @category String
|
14192 | * @param {string} [string=''] The string to inspect.
|
14193 | * @param {string} [target] The string to search for.
|
14194 | * @param {number} [position=string.length] The position to search up to.
|
14195 | * @returns {boolean} Returns `true` if `string` ends with `target`,
|
14196 | * else `false`.
|
14197 | * @example
|
14198 | *
|
14199 | * _.endsWith('abc', 'c');
|
14200 | * // => true
|
14201 | *
|
14202 | * _.endsWith('abc', 'b');
|
14203 | * // => false
|
14204 | *
|
14205 | * _.endsWith('abc', 'b', 2);
|
14206 | * // => true
|
14207 | */
|
14208 | function endsWith(string, target, position) {
|
14209 | string = toString(string);
|
14210 | target = baseToString(target);
|
14211 |
|
14212 | var length = string.length;
|
14213 | position = position === undefined
|
14214 | ? length
|
14215 | : baseClamp(toInteger(position), 0, length);
|
14216 |
|
14217 | var end = position;
|
14218 | position -= target.length;
|
14219 | return position >= 0 && string.slice(position, end) == target;
|
14220 | }
|
14221 |
|
14222 | /**
|
14223 | * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
|
14224 | * corresponding HTML entities.
|
14225 | *
|
14226 | * **Note:** No other characters are escaped. To escape additional
|
14227 | * characters use a third-party library like [_he_](https://mths.be/he).
|
14228 | *
|
14229 | * Though the ">" character is escaped for symmetry, characters like
|
14230 | * ">" and "/" don't need escaping in HTML and have no special meaning
|
14231 | * unless they're part of a tag or unquoted attribute value. See
|
14232 | * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
|
14233 | * (under "semi-related fun fact") for more details.
|
14234 | *
|
14235 | * When working with HTML you should always
|
14236 | * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
|
14237 | * XSS vectors.
|
14238 | *
|
14239 | * @static
|
14240 | * @since 0.1.0
|
14241 | * @memberOf _
|
14242 | * @category String
|
14243 | * @param {string} [string=''] The string to escape.
|
14244 | * @returns {string} Returns the escaped string.
|
14245 | * @example
|
14246 | *
|
14247 | * _.escape('fred, barney, & pebbles');
|
14248 | * // => 'fred, barney, & pebbles'
|
14249 | */
|
14250 | function escape(string) {
|
14251 | string = toString(string);
|
14252 | return (string && reHasUnescapedHtml.test(string))
|
14253 | ? string.replace(reUnescapedHtml, escapeHtmlChar)
|
14254 | : string;
|
14255 | }
|
14256 |
|
14257 | /**
|
14258 | * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
|
14259 | * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
|
14260 | *
|
14261 | * @static
|
14262 | * @memberOf _
|
14263 | * @since 3.0.0
|
14264 | * @category String
|
14265 | * @param {string} [string=''] The string to escape.
|
14266 | * @returns {string} Returns the escaped string.
|
14267 | * @example
|
14268 | *
|
14269 | * _.escapeRegExp('[lodash](https://lodash.com/)');
|
14270 | * // => '\[lodash\]\(https://lodash\.com/\)'
|
14271 | */
|
14272 | function escapeRegExp(string) {
|
14273 | string = toString(string);
|
14274 | return (string && reHasRegExpChar.test(string))
|
14275 | ? string.replace(reRegExpChar, '\\$&')
|
14276 | : string;
|
14277 | }
|
14278 |
|
14279 | /**
|
14280 | * Converts `string` to
|
14281 | * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
|
14282 | *
|
14283 | * @static
|
14284 | * @memberOf _
|
14285 | * @since 3.0.0
|
14286 | * @category String
|
14287 | * @param {string} [string=''] The string to convert.
|
14288 | * @returns {string} Returns the kebab cased string.
|
14289 | * @example
|
14290 | *
|
14291 | * _.kebabCase('Foo Bar');
|
14292 | * // => 'foo-bar'
|
14293 | *
|
14294 | * _.kebabCase('fooBar');
|
14295 | * // => 'foo-bar'
|
14296 | *
|
14297 | * _.kebabCase('__FOO_BAR__');
|
14298 | * // => 'foo-bar'
|
14299 | */
|
14300 | var kebabCase = createCompounder(function(result, word, index) {
|
14301 | return result + (index ? '-' : '') + word.toLowerCase();
|
14302 | });
|
14303 |
|
14304 | /**
|
14305 | * Converts `string`, as space separated words, to lower case.
|
14306 | *
|
14307 | * @static
|
14308 | * @memberOf _
|
14309 | * @since 4.0.0
|
14310 | * @category String
|
14311 | * @param {string} [string=''] The string to convert.
|
14312 | * @returns {string} Returns the lower cased string.
|
14313 | * @example
|
14314 | *
|
14315 | * _.lowerCase('--Foo-Bar--');
|
14316 | * // => 'foo bar'
|
14317 | *
|
14318 | * _.lowerCase('fooBar');
|
14319 | * // => 'foo bar'
|
14320 | *
|
14321 | * _.lowerCase('__FOO_BAR__');
|
14322 | * // => 'foo bar'
|
14323 | */
|
14324 | var lowerCase = createCompounder(function(result, word, index) {
|
14325 | return result + (index ? ' ' : '') + word.toLowerCase();
|
14326 | });
|
14327 |
|
14328 | /**
|
14329 | * Converts the first character of `string` to lower case.
|
14330 | *
|
14331 | * @static
|
14332 | * @memberOf _
|
14333 | * @since 4.0.0
|
14334 | * @category String
|
14335 | * @param {string} [string=''] The string to convert.
|
14336 | * @returns {string} Returns the converted string.
|
14337 | * @example
|
14338 | *
|
14339 | * _.lowerFirst('Fred');
|
14340 | * // => 'fred'
|
14341 | *
|
14342 | * _.lowerFirst('FRED');
|
14343 | * // => 'fRED'
|
14344 | */
|
14345 | var lowerFirst = createCaseFirst('toLowerCase');
|
14346 |
|
14347 | /**
|
14348 | * Pads `string` on the left and right sides if it's shorter than `length`.
|
14349 | * Padding characters are truncated if they can't be evenly divided by `length`.
|
14350 | *
|
14351 | * @static
|
14352 | * @memberOf _
|
14353 | * @since 3.0.0
|
14354 | * @category String
|
14355 | * @param {string} [string=''] The string to pad.
|
14356 | * @param {number} [length=0] The padding length.
|
14357 | * @param {string} [chars=' '] The string used as padding.
|
14358 | * @returns {string} Returns the padded string.
|
14359 | * @example
|
14360 | *
|
14361 | * _.pad('abc', 8);
|
14362 | * // => ' abc '
|
14363 | *
|
14364 | * _.pad('abc', 8, '_-');
|
14365 | * // => '_-abc_-_'
|
14366 | *
|
14367 | * _.pad('abc', 3);
|
14368 | * // => 'abc'
|
14369 | */
|
14370 | function pad(string, length, chars) {
|
14371 | string = toString(string);
|
14372 | length = toInteger(length);
|
14373 |
|
14374 | var strLength = length ? stringSize(string) : 0;
|
14375 | if (!length || strLength >= length) {
|
14376 | return string;
|
14377 | }
|
14378 | var mid = (length - strLength) / 2;
|
14379 | return (
|
14380 | createPadding(nativeFloor(mid), chars) +
|
14381 | string +
|
14382 | createPadding(nativeCeil(mid), chars)
|
14383 | );
|
14384 | }
|
14385 |
|
14386 | /**
|
14387 | * Pads `string` on the right side if it's shorter than `length`. Padding
|
14388 | * characters are truncated if they exceed `length`.
|
14389 | *
|
14390 | * @static
|
14391 | * @memberOf _
|
14392 | * @since 4.0.0
|
14393 | * @category String
|
14394 | * @param {string} [string=''] The string to pad.
|
14395 | * @param {number} [length=0] The padding length.
|
14396 | * @param {string} [chars=' '] The string used as padding.
|
14397 | * @returns {string} Returns the padded string.
|
14398 | * @example
|
14399 | *
|
14400 | * _.padEnd('abc', 6);
|
14401 | * // => 'abc '
|
14402 | *
|
14403 | * _.padEnd('abc', 6, '_-');
|
14404 | * // => 'abc_-_'
|
14405 | *
|
14406 | * _.padEnd('abc', 3);
|
14407 | * // => 'abc'
|
14408 | */
|
14409 | function padEnd(string, length, chars) {
|
14410 | string = toString(string);
|
14411 | length = toInteger(length);
|
14412 |
|
14413 | var strLength = length ? stringSize(string) : 0;
|
14414 | return (length && strLength < length)
|
14415 | ? (string + createPadding(length - strLength, chars))
|
14416 | : string;
|
14417 | }
|
14418 |
|
14419 | /**
|
14420 | * Pads `string` on the left side if it's shorter than `length`. Padding
|
14421 | * characters are truncated if they exceed `length`.
|
14422 | *
|
14423 | * @static
|
14424 | * @memberOf _
|
14425 | * @since 4.0.0
|
14426 | * @category String
|
14427 | * @param {string} [string=''] The string to pad.
|
14428 | * @param {number} [length=0] The padding length.
|
14429 | * @param {string} [chars=' '] The string used as padding.
|
14430 | * @returns {string} Returns the padded string.
|
14431 | * @example
|
14432 | *
|
14433 | * _.padStart('abc', 6);
|
14434 | * // => ' abc'
|
14435 | *
|
14436 | * _.padStart('abc', 6, '_-');
|
14437 | * // => '_-_abc'
|
14438 | *
|
14439 | * _.padStart('abc', 3);
|
14440 | * // => 'abc'
|
14441 | */
|
14442 | function padStart(string, length, chars) {
|
14443 | string = toString(string);
|
14444 | length = toInteger(length);
|
14445 |
|
14446 | var strLength = length ? stringSize(string) : 0;
|
14447 | return (length && strLength < length)
|
14448 | ? (createPadding(length - strLength, chars) + string)
|
14449 | : string;
|
14450 | }
|
14451 |
|
14452 | /**
|
14453 | * Converts `string` to an integer of the specified radix. If `radix` is
|
14454 | * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
|
14455 | * hexadecimal, in which case a `radix` of `16` is used.
|
14456 | *
|
14457 | * **Note:** This method aligns with the
|
14458 | * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
|
14459 | *
|
14460 | * @static
|
14461 | * @memberOf _
|
14462 | * @since 1.1.0
|
14463 | * @category String
|
14464 | * @param {string} string The string to convert.
|
14465 | * @param {number} [radix=10] The radix to interpret `value` by.
|
14466 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
14467 | * @returns {number} Returns the converted integer.
|
14468 | * @example
|
14469 | *
|
14470 | * _.parseInt('08');
|
14471 | * // => 8
|
14472 | *
|
14473 | * _.map(['6', '08', '10'], _.parseInt);
|
14474 | * // => [6, 8, 10]
|
14475 | */
|
14476 | function parseInt(string, radix, guard) {
|
14477 | if (guard || radix == null) {
|
14478 | radix = 0;
|
14479 | } else if (radix) {
|
14480 | radix = +radix;
|
14481 | }
|
14482 | return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
|
14483 | }
|
14484 |
|
14485 | /**
|
14486 | * Repeats the given string `n` times.
|
14487 | *
|
14488 | * @static
|
14489 | * @memberOf _
|
14490 | * @since 3.0.0
|
14491 | * @category String
|
14492 | * @param {string} [string=''] The string to repeat.
|
14493 | * @param {number} [n=1] The number of times to repeat the string.
|
14494 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
14495 | * @returns {string} Returns the repeated string.
|
14496 | * @example
|
14497 | *
|
14498 | * _.repeat('*', 3);
|
14499 | * // => '***'
|
14500 | *
|
14501 | * _.repeat('abc', 2);
|
14502 | * // => 'abcabc'
|
14503 | *
|
14504 | * _.repeat('abc', 0);
|
14505 | * // => ''
|
14506 | */
|
14507 | function repeat(string, n, guard) {
|
14508 | if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
|
14509 | n = 1;
|
14510 | } else {
|
14511 | n = toInteger(n);
|
14512 | }
|
14513 | return baseRepeat(toString(string), n);
|
14514 | }
|
14515 |
|
14516 | /**
|
14517 | * Replaces matches for `pattern` in `string` with `replacement`.
|
14518 | *
|
14519 | * **Note:** This method is based on
|
14520 | * [`String#replace`](https://mdn.io/String/replace).
|
14521 | *
|
14522 | * @static
|
14523 | * @memberOf _
|
14524 | * @since 4.0.0
|
14525 | * @category String
|
14526 | * @param {string} [string=''] The string to modify.
|
14527 | * @param {RegExp|string} pattern The pattern to replace.
|
14528 | * @param {Function|string} replacement The match replacement.
|
14529 | * @returns {string} Returns the modified string.
|
14530 | * @example
|
14531 | *
|
14532 | * _.replace('Hi Fred', 'Fred', 'Barney');
|
14533 | * // => 'Hi Barney'
|
14534 | */
|
14535 | function replace() {
|
14536 | var args = arguments,
|
14537 | string = toString(args[0]);
|
14538 |
|
14539 | return args.length < 3 ? string : string.replace(args[1], args[2]);
|
14540 | }
|
14541 |
|
14542 | /**
|
14543 | * Converts `string` to
|
14544 | * [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
14545 | *
|
14546 | * @static
|
14547 | * @memberOf _
|
14548 | * @since 3.0.0
|
14549 | * @category String
|
14550 | * @param {string} [string=''] The string to convert.
|
14551 | * @returns {string} Returns the snake cased string.
|
14552 | * @example
|
14553 | *
|
14554 | * _.snakeCase('Foo Bar');
|
14555 | * // => 'foo_bar'
|
14556 | *
|
14557 | * _.snakeCase('fooBar');
|
14558 | * // => 'foo_bar'
|
14559 | *
|
14560 | * _.snakeCase('--FOO-BAR--');
|
14561 | * // => 'foo_bar'
|
14562 | */
|
14563 | var snakeCase = createCompounder(function(result, word, index) {
|
14564 | return result + (index ? '_' : '') + word.toLowerCase();
|
14565 | });
|
14566 |
|
14567 | /**
|
14568 | * Splits `string` by `separator`.
|
14569 | *
|
14570 | * **Note:** This method is based on
|
14571 | * [`String#split`](https://mdn.io/String/split).
|
14572 | *
|
14573 | * @static
|
14574 | * @memberOf _
|
14575 | * @since 4.0.0
|
14576 | * @category String
|
14577 | * @param {string} [string=''] The string to split.
|
14578 | * @param {RegExp|string} separator The separator pattern to split by.
|
14579 | * @param {number} [limit] The length to truncate results to.
|
14580 | * @returns {Array} Returns the string segments.
|
14581 | * @example
|
14582 | *
|
14583 | * _.split('a-b-c', '-', 2);
|
14584 | * // => ['a', 'b']
|
14585 | */
|
14586 | function split(string, separator, limit) {
|
14587 | if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
|
14588 | separator = limit = undefined;
|
14589 | }
|
14590 | limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
|
14591 | if (!limit) {
|
14592 | return [];
|
14593 | }
|
14594 | string = toString(string);
|
14595 | if (string && (
|
14596 | typeof separator == 'string' ||
|
14597 | (separator != null && !isRegExp(separator))
|
14598 | )) {
|
14599 | separator = baseToString(separator);
|
14600 | if (!separator && hasUnicode(string)) {
|
14601 | return castSlice(stringToArray(string), 0, limit);
|
14602 | }
|
14603 | }
|
14604 | return string.split(separator, limit);
|
14605 | }
|
14606 |
|
14607 | /**
|
14608 | * Converts `string` to
|
14609 | * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
|
14610 | *
|
14611 | * @static
|
14612 | * @memberOf _
|
14613 | * @since 3.1.0
|
14614 | * @category String
|
14615 | * @param {string} [string=''] The string to convert.
|
14616 | * @returns {string} Returns the start cased string.
|
14617 | * @example
|
14618 | *
|
14619 | * _.startCase('--foo-bar--');
|
14620 | * // => 'Foo Bar'
|
14621 | *
|
14622 | * _.startCase('fooBar');
|
14623 | * // => 'Foo Bar'
|
14624 | *
|
14625 | * _.startCase('__FOO_BAR__');
|
14626 | * // => 'FOO BAR'
|
14627 | */
|
14628 | var startCase = createCompounder(function(result, word, index) {
|
14629 | return result + (index ? ' ' : '') + upperFirst(word);
|
14630 | });
|
14631 |
|
14632 | /**
|
14633 | * Checks if `string` starts with the given target string.
|
14634 | *
|
14635 | * @static
|
14636 | * @memberOf _
|
14637 | * @since 3.0.0
|
14638 | * @category String
|
14639 | * @param {string} [string=''] The string to inspect.
|
14640 | * @param {string} [target] The string to search for.
|
14641 | * @param {number} [position=0] The position to search from.
|
14642 | * @returns {boolean} Returns `true` if `string` starts with `target`,
|
14643 | * else `false`.
|
14644 | * @example
|
14645 | *
|
14646 | * _.startsWith('abc', 'a');
|
14647 | * // => true
|
14648 | *
|
14649 | * _.startsWith('abc', 'b');
|
14650 | * // => false
|
14651 | *
|
14652 | * _.startsWith('abc', 'b', 1);
|
14653 | * // => true
|
14654 | */
|
14655 | function startsWith(string, target, position) {
|
14656 | string = toString(string);
|
14657 | position = position == null
|
14658 | ? 0
|
14659 | : baseClamp(toInteger(position), 0, string.length);
|
14660 |
|
14661 | target = baseToString(target);
|
14662 | return string.slice(position, position + target.length) == target;
|
14663 | }
|
14664 |
|
14665 | /**
|
14666 | * Creates a compiled template function that can interpolate data properties
|
14667 | * in "interpolate" delimiters, HTML-escape interpolated data properties in
|
14668 | * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
|
14669 | * properties may be accessed as free variables in the template. If a setting
|
14670 | * object is given, it takes precedence over `_.templateSettings` values.
|
14671 | *
|
14672 | * **Note:** In the development build `_.template` utilizes
|
14673 | * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
|
14674 | * for easier debugging.
|
14675 | *
|
14676 | * For more information on precompiling templates see
|
14677 | * [lodash's custom builds documentation](https://lodash.com/custom-builds).
|
14678 | *
|
14679 | * For more information on Chrome extension sandboxes see
|
14680 | * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
|
14681 | *
|
14682 | * @static
|
14683 | * @since 0.1.0
|
14684 | * @memberOf _
|
14685 | * @category String
|
14686 | * @param {string} [string=''] The template string.
|
14687 | * @param {Object} [options={}] The options object.
|
14688 | * @param {RegExp} [options.escape=_.templateSettings.escape]
|
14689 | * The HTML "escape" delimiter.
|
14690 | * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
|
14691 | * The "evaluate" delimiter.
|
14692 | * @param {Object} [options.imports=_.templateSettings.imports]
|
14693 | * An object to import into the template as free variables.
|
14694 | * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
|
14695 | * The "interpolate" delimiter.
|
14696 | * @param {string} [options.sourceURL='lodash.templateSources[n]']
|
14697 | * The sourceURL of the compiled template.
|
14698 | * @param {string} [options.variable='obj']
|
14699 | * The data object variable name.
|
14700 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
14701 | * @returns {Function} Returns the compiled template function.
|
14702 | * @example
|
14703 | *
|
14704 | * // Use the "interpolate" delimiter to create a compiled template.
|
14705 | * var compiled = _.template('hello <%= user %>!');
|
14706 | * compiled({ 'user': 'fred' });
|
14707 | * // => 'hello fred!'
|
14708 | *
|
14709 | * // Use the HTML "escape" delimiter to escape data property values.
|
14710 | * var compiled = _.template('<b><%- value %></b>');
|
14711 | * compiled({ 'value': '<script>' });
|
14712 | * // => '<b><script></b>'
|
14713 | *
|
14714 | * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
|
14715 | * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
14716 | * compiled({ 'users': ['fred', 'barney'] });
|
14717 | * // => '<li>fred</li><li>barney</li>'
|
14718 | *
|
14719 | * // Use the internal `print` function in "evaluate" delimiters.
|
14720 | * var compiled = _.template('<% print("hello " + user); %>!');
|
14721 | * compiled({ 'user': 'barney' });
|
14722 | * // => 'hello barney!'
|
14723 | *
|
14724 | * // Use the ES template literal delimiter as an "interpolate" delimiter.
|
14725 | * // Disable support by replacing the "interpolate" delimiter.
|
14726 | * var compiled = _.template('hello ${ user }!');
|
14727 | * compiled({ 'user': 'pebbles' });
|
14728 | * // => 'hello pebbles!'
|
14729 | *
|
14730 | * // Use backslashes to treat delimiters as plain text.
|
14731 | * var compiled = _.template('<%= "\\<%- value %\\>" %>');
|
14732 | * compiled({ 'value': 'ignored' });
|
14733 | * // => '<%- value %>'
|
14734 | *
|
14735 | * // Use the `imports` option to import `jQuery` as `jq`.
|
14736 | * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
|
14737 | * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
|
14738 | * compiled({ 'users': ['fred', 'barney'] });
|
14739 | * // => '<li>fred</li><li>barney</li>'
|
14740 | *
|
14741 | * // Use the `sourceURL` option to specify a custom sourceURL for the template.
|
14742 | * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
|
14743 | * compiled(data);
|
14744 | * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
|
14745 | *
|
14746 | * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
|
14747 | * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
|
14748 | * compiled.source;
|
14749 | * // => function(data) {
|
14750 | * // var __t, __p = '';
|
14751 | * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
|
14752 | * // return __p;
|
14753 | * // }
|
14754 | *
|
14755 | * // Use custom template delimiters.
|
14756 | * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
14757 | * var compiled = _.template('hello {{ user }}!');
|
14758 | * compiled({ 'user': 'mustache' });
|
14759 | * // => 'hello mustache!'
|
14760 | *
|
14761 | * // Use the `source` property to inline compiled templates for meaningful
|
14762 | * // line numbers in error messages and stack traces.
|
14763 | * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
|
14764 | * var JST = {\
|
14765 | * "main": ' + _.template(mainText).source + '\
|
14766 | * };\
|
14767 | * ');
|
14768 | */
|
14769 | function template(string, options, guard) {
|
14770 | // Based on John Resig's `tmpl` implementation
|
14771 | // (http://ejohn.org/blog/javascript-micro-templating/)
|
14772 | // and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
14773 | var settings = lodash.templateSettings;
|
14774 |
|
14775 | if (guard && isIterateeCall(string, options, guard)) {
|
14776 | options = undefined;
|
14777 | }
|
14778 | string = toString(string);
|
14779 | options = assignInWith({}, options, settings, customDefaultsAssignIn);
|
14780 |
|
14781 | var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
|
14782 | importsKeys = keys(imports),
|
14783 | importsValues = baseValues(imports, importsKeys);
|
14784 |
|
14785 | var isEscaping,
|
14786 | isEvaluating,
|
14787 | index = 0,
|
14788 | interpolate = options.interpolate || reNoMatch,
|
14789 | source = "__p += '";
|
14790 |
|
14791 | // Compile the regexp to match each delimiter.
|
14792 | var reDelimiters = RegExp(
|
14793 | (options.escape || reNoMatch).source + '|' +
|
14794 | interpolate.source + '|' +
|
14795 | (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
|
14796 | (options.evaluate || reNoMatch).source + '|$'
|
14797 | , 'g');
|
14798 |
|
14799 | // Use a sourceURL for easier debugging.
|
14800 | var sourceURL = '//# sourceURL=' +
|
14801 | ('sourceURL' in options
|
14802 | ? options.sourceURL
|
14803 | : ('lodash.templateSources[' + (++templateCounter) + ']')
|
14804 | ) + '\n';
|
14805 |
|
14806 | string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
|
14807 | interpolateValue || (interpolateValue = esTemplateValue);
|
14808 |
|
14809 | // Escape characters that can't be included in string literals.
|
14810 | source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
|
14811 |
|
14812 | // Replace delimiters with snippets.
|
14813 | if (escapeValue) {
|
14814 | isEscaping = true;
|
14815 | source += "' +\n__e(" + escapeValue + ") +\n'";
|
14816 | }
|
14817 | if (evaluateValue) {
|
14818 | isEvaluating = true;
|
14819 | source += "';\n" + evaluateValue + ";\n__p += '";
|
14820 | }
|
14821 | if (interpolateValue) {
|
14822 | source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
|
14823 | }
|
14824 | index = offset + match.length;
|
14825 |
|
14826 | // The JS engine embedded in Adobe products needs `match` returned in
|
14827 | // order to produce the correct `offset` value.
|
14828 | return match;
|
14829 | });
|
14830 |
|
14831 | source += "';\n";
|
14832 |
|
14833 | // If `variable` is not specified wrap a with-statement around the generated
|
14834 | // code to add the data object to the top of the scope chain.
|
14835 | var variable = options.variable;
|
14836 | if (!variable) {
|
14837 | source = 'with (obj) {\n' + source + '\n}\n';
|
14838 | }
|
14839 | // Cleanup code by stripping empty strings.
|
14840 | source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
14841 | .replace(reEmptyStringMiddle, '$1')
|
14842 | .replace(reEmptyStringTrailing, '$1;');
|
14843 |
|
14844 | // Frame code as the function body.
|
14845 | source = 'function(' + (variable || 'obj') + ') {\n' +
|
14846 | (variable
|
14847 | ? ''
|
14848 | : 'obj || (obj = {});\n'
|
14849 | ) +
|
14850 | "var __t, __p = ''" +
|
14851 | (isEscaping
|
14852 | ? ', __e = _.escape'
|
14853 | : ''
|
14854 | ) +
|
14855 | (isEvaluating
|
14856 | ? ', __j = Array.prototype.join;\n' +
|
14857 | "function print() { __p += __j.call(arguments, '') }\n"
|
14858 | : ';\n'
|
14859 | ) +
|
14860 | source +
|
14861 | 'return __p\n}';
|
14862 |
|
14863 | var result = attempt(function() {
|
14864 | return Function(importsKeys, sourceURL + 'return ' + source)
|
14865 | .apply(undefined, importsValues);
|
14866 | });
|
14867 |
|
14868 | // Provide the compiled function's source by its `toString` method or
|
14869 | // the `source` property as a convenience for inlining compiled templates.
|
14870 | result.source = source;
|
14871 | if (isError(result)) {
|
14872 | throw result;
|
14873 | }
|
14874 | return result;
|
14875 | }
|
14876 |
|
14877 | /**
|
14878 | * Converts `string`, as a whole, to lower case just like
|
14879 | * [String#toLowerCase](https://mdn.io/toLowerCase).
|
14880 | *
|
14881 | * @static
|
14882 | * @memberOf _
|
14883 | * @since 4.0.0
|
14884 | * @category String
|
14885 | * @param {string} [string=''] The string to convert.
|
14886 | * @returns {string} Returns the lower cased string.
|
14887 | * @example
|
14888 | *
|
14889 | * _.toLower('--Foo-Bar--');
|
14890 | * // => '--foo-bar--'
|
14891 | *
|
14892 | * _.toLower('fooBar');
|
14893 | * // => 'foobar'
|
14894 | *
|
14895 | * _.toLower('__FOO_BAR__');
|
14896 | * // => '__foo_bar__'
|
14897 | */
|
14898 | function toLower(value) {
|
14899 | return toString(value).toLowerCase();
|
14900 | }
|
14901 |
|
14902 | /**
|
14903 | * Converts `string`, as a whole, to upper case just like
|
14904 | * [String#toUpperCase](https://mdn.io/toUpperCase).
|
14905 | *
|
14906 | * @static
|
14907 | * @memberOf _
|
14908 | * @since 4.0.0
|
14909 | * @category String
|
14910 | * @param {string} [string=''] The string to convert.
|
14911 | * @returns {string} Returns the upper cased string.
|
14912 | * @example
|
14913 | *
|
14914 | * _.toUpper('--foo-bar--');
|
14915 | * // => '--FOO-BAR--'
|
14916 | *
|
14917 | * _.toUpper('fooBar');
|
14918 | * // => 'FOOBAR'
|
14919 | *
|
14920 | * _.toUpper('__foo_bar__');
|
14921 | * // => '__FOO_BAR__'
|
14922 | */
|
14923 | function toUpper(value) {
|
14924 | return toString(value).toUpperCase();
|
14925 | }
|
14926 |
|
14927 | /**
|
14928 | * Removes leading and trailing whitespace or specified characters from `string`.
|
14929 | *
|
14930 | * @static
|
14931 | * @memberOf _
|
14932 | * @since 3.0.0
|
14933 | * @category String
|
14934 | * @param {string} [string=''] The string to trim.
|
14935 | * @param {string} [chars=whitespace] The characters to trim.
|
14936 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
14937 | * @returns {string} Returns the trimmed string.
|
14938 | * @example
|
14939 | *
|
14940 | * _.trim(' abc ');
|
14941 | * // => 'abc'
|
14942 | *
|
14943 | * _.trim('-_-abc-_-', '_-');
|
14944 | * // => 'abc'
|
14945 | *
|
14946 | * _.map([' foo ', ' bar '], _.trim);
|
14947 | * // => ['foo', 'bar']
|
14948 | */
|
14949 | function trim(string, chars, guard) {
|
14950 | string = toString(string);
|
14951 | if (string && (guard || chars === undefined)) {
|
14952 | return string.replace(reTrim, '');
|
14953 | }
|
14954 | if (!string || !(chars = baseToString(chars))) {
|
14955 | return string;
|
14956 | }
|
14957 | var strSymbols = stringToArray(string),
|
14958 | chrSymbols = stringToArray(chars),
|
14959 | start = charsStartIndex(strSymbols, chrSymbols),
|
14960 | end = charsEndIndex(strSymbols, chrSymbols) + 1;
|
14961 |
|
14962 | return castSlice(strSymbols, start, end).join('');
|
14963 | }
|
14964 |
|
14965 | /**
|
14966 | * Removes trailing whitespace or specified characters from `string`.
|
14967 | *
|
14968 | * @static
|
14969 | * @memberOf _
|
14970 | * @since 4.0.0
|
14971 | * @category String
|
14972 | * @param {string} [string=''] The string to trim.
|
14973 | * @param {string} [chars=whitespace] The characters to trim.
|
14974 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
14975 | * @returns {string} Returns the trimmed string.
|
14976 | * @example
|
14977 | *
|
14978 | * _.trimEnd(' abc ');
|
14979 | * // => ' abc'
|
14980 | *
|
14981 | * _.trimEnd('-_-abc-_-', '_-');
|
14982 | * // => '-_-abc'
|
14983 | */
|
14984 | function trimEnd(string, chars, guard) {
|
14985 | string = toString(string);
|
14986 | if (string && (guard || chars === undefined)) {
|
14987 | return string.replace(reTrimEnd, '');
|
14988 | }
|
14989 | if (!string || !(chars = baseToString(chars))) {
|
14990 | return string;
|
14991 | }
|
14992 | var strSymbols = stringToArray(string),
|
14993 | end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
|
14994 |
|
14995 | return castSlice(strSymbols, 0, end).join('');
|
14996 | }
|
14997 |
|
14998 | /**
|
14999 | * Removes leading whitespace or specified characters from `string`.
|
15000 | *
|
15001 | * @static
|
15002 | * @memberOf _
|
15003 | * @since 4.0.0
|
15004 | * @category String
|
15005 | * @param {string} [string=''] The string to trim.
|
15006 | * @param {string} [chars=whitespace] The characters to trim.
|
15007 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
15008 | * @returns {string} Returns the trimmed string.
|
15009 | * @example
|
15010 | *
|
15011 | * _.trimStart(' abc ');
|
15012 | * // => 'abc '
|
15013 | *
|
15014 | * _.trimStart('-_-abc-_-', '_-');
|
15015 | * // => 'abc-_-'
|
15016 | */
|
15017 | function trimStart(string, chars, guard) {
|
15018 | string = toString(string);
|
15019 | if (string && (guard || chars === undefined)) {
|
15020 | return string.replace(reTrimStart, '');
|
15021 | }
|
15022 | if (!string || !(chars = baseToString(chars))) {
|
15023 | return string;
|
15024 | }
|
15025 | var strSymbols = stringToArray(string),
|
15026 | start = charsStartIndex(strSymbols, stringToArray(chars));
|
15027 |
|
15028 | return castSlice(strSymbols, start).join('');
|
15029 | }
|
15030 |
|
15031 | /**
|
15032 | * Truncates `string` if it's longer than the given maximum string length.
|
15033 | * The last characters of the truncated string are replaced with the omission
|
15034 | * string which defaults to "...".
|
15035 | *
|
15036 | * @static
|
15037 | * @memberOf _
|
15038 | * @since 4.0.0
|
15039 | * @category String
|
15040 | * @param {string} [string=''] The string to truncate.
|
15041 | * @param {Object} [options={}] The options object.
|
15042 | * @param {number} [options.length=30] The maximum string length.
|
15043 | * @param {string} [options.omission='...'] The string to indicate text is omitted.
|
15044 | * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
|
15045 | * @returns {string} Returns the truncated string.
|
15046 | * @example
|
15047 | *
|
15048 | * _.truncate('hi-diddly-ho there, neighborino');
|
15049 | * // => 'hi-diddly-ho there, neighbo...'
|
15050 | *
|
15051 | * _.truncate('hi-diddly-ho there, neighborino', {
|
15052 | * 'length': 24,
|
15053 | * 'separator': ' '
|
15054 | * });
|
15055 | * // => 'hi-diddly-ho there,...'
|
15056 | *
|
15057 | * _.truncate('hi-diddly-ho there, neighborino', {
|
15058 | * 'length': 24,
|
15059 | * 'separator': /,? +/
|
15060 | * });
|
15061 | * // => 'hi-diddly-ho there...'
|
15062 | *
|
15063 | * _.truncate('hi-diddly-ho there, neighborino', {
|
15064 | * 'omission': ' [...]'
|
15065 | * });
|
15066 | * // => 'hi-diddly-ho there, neig [...]'
|
15067 | */
|
15068 | function truncate(string, options) {
|
15069 | var length = DEFAULT_TRUNC_LENGTH,
|
15070 | omission = DEFAULT_TRUNC_OMISSION;
|
15071 |
|
15072 | if (isObject(options)) {
|
15073 | var separator = 'separator' in options ? options.separator : separator;
|
15074 | length = 'length' in options ? toInteger(options.length) : length;
|
15075 | omission = 'omission' in options ? baseToString(options.omission) : omission;
|
15076 | }
|
15077 | string = toString(string);
|
15078 |
|
15079 | var strLength = string.length;
|
15080 | if (hasUnicode(string)) {
|
15081 | var strSymbols = stringToArray(string);
|
15082 | strLength = strSymbols.length;
|
15083 | }
|
15084 | if (length >= strLength) {
|
15085 | return string;
|
15086 | }
|
15087 | var end = length - stringSize(omission);
|
15088 | if (end < 1) {
|
15089 | return omission;
|
15090 | }
|
15091 | var result = strSymbols
|
15092 | ? castSlice(strSymbols, 0, end).join('')
|
15093 | : string.slice(0, end);
|
15094 |
|
15095 | if (separator === undefined) {
|
15096 | return result + omission;
|
15097 | }
|
15098 | if (strSymbols) {
|
15099 | end += (result.length - end);
|
15100 | }
|
15101 | if (isRegExp(separator)) {
|
15102 | if (string.slice(end).search(separator)) {
|
15103 | var match,
|
15104 | substring = result;
|
15105 |
|
15106 | if (!separator.global) {
|
15107 | separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
|
15108 | }
|
15109 | separator.lastIndex = 0;
|
15110 | while ((match = separator.exec(substring))) {
|
15111 | var newEnd = match.index;
|
15112 | }
|
15113 | result = result.slice(0, newEnd === undefined ? end : newEnd);
|
15114 | }
|
15115 | } else if (string.indexOf(baseToString(separator), end) != end) {
|
15116 | var index = result.lastIndexOf(separator);
|
15117 | if (index > -1) {
|
15118 | result = result.slice(0, index);
|
15119 | }
|
15120 | }
|
15121 | return result + omission;
|
15122 | }
|
15123 |
|
15124 | /**
|
15125 | * The inverse of `_.escape`; this method converts the HTML entities
|
15126 | * `&`, `<`, `>`, `"`, and `'` in `string` to
|
15127 | * their corresponding characters.
|
15128 | *
|
15129 | * **Note:** No other HTML entities are unescaped. To unescape additional
|
15130 | * HTML entities use a third-party library like [_he_](https://mths.be/he).
|
15131 | *
|
15132 | * @static
|
15133 | * @memberOf _
|
15134 | * @since 0.6.0
|
15135 | * @category String
|
15136 | * @param {string} [string=''] The string to unescape.
|
15137 | * @returns {string} Returns the unescaped string.
|
15138 | * @example
|
15139 | *
|
15140 | * _.unescape('fred, barney, & pebbles');
|
15141 | * // => 'fred, barney, & pebbles'
|
15142 | */
|
15143 | function unescape(string) {
|
15144 | string = toString(string);
|
15145 | return (string && reHasEscapedHtml.test(string))
|
15146 | ? string.replace(reEscapedHtml, unescapeHtmlChar)
|
15147 | : string;
|
15148 | }
|
15149 |
|
15150 | /**
|
15151 | * Converts `string`, as space separated words, to upper case.
|
15152 | *
|
15153 | * @static
|
15154 | * @memberOf _
|
15155 | * @since 4.0.0
|
15156 | * @category String
|
15157 | * @param {string} [string=''] The string to convert.
|
15158 | * @returns {string} Returns the upper cased string.
|
15159 | * @example
|
15160 | *
|
15161 | * _.upperCase('--foo-bar');
|
15162 | * // => 'FOO BAR'
|
15163 | *
|
15164 | * _.upperCase('fooBar');
|
15165 | * // => 'FOO BAR'
|
15166 | *
|
15167 | * _.upperCase('__foo_bar__');
|
15168 | * // => 'FOO BAR'
|
15169 | */
|
15170 | var upperCase = createCompounder(function(result, word, index) {
|
15171 | return result + (index ? ' ' : '') + word.toUpperCase();
|
15172 | });
|
15173 |
|
15174 | /**
|
15175 | * Converts the first character of `string` to upper case.
|
15176 | *
|
15177 | * @static
|
15178 | * @memberOf _
|
15179 | * @since 4.0.0
|
15180 | * @category String
|
15181 | * @param {string} [string=''] The string to convert.
|
15182 | * @returns {string} Returns the converted string.
|
15183 | * @example
|
15184 | *
|
15185 | * _.upperFirst('fred');
|
15186 | * // => 'Fred'
|
15187 | *
|
15188 | * _.upperFirst('FRED');
|
15189 | * // => 'FRED'
|
15190 | */
|
15191 | var upperFirst = createCaseFirst('toUpperCase');
|
15192 |
|
15193 | /**
|
15194 | * Splits `string` into an array of its words.
|
15195 | *
|
15196 | * @static
|
15197 | * @memberOf _
|
15198 | * @since 3.0.0
|
15199 | * @category String
|
15200 | * @param {string} [string=''] The string to inspect.
|
15201 | * @param {RegExp|string} [pattern] The pattern to match words.
|
15202 | * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
15203 | * @returns {Array} Returns the words of `string`.
|
15204 | * @example
|
15205 | *
|
15206 | * _.words('fred, barney, & pebbles');
|
15207 | * // => ['fred', 'barney', 'pebbles']
|
15208 | *
|
15209 | * _.words('fred, barney, & pebbles', /[^, ]+/g);
|
15210 | * // => ['fred', 'barney', '&', 'pebbles']
|
15211 | */
|
15212 | function words(string, pattern, guard) {
|
15213 | string = toString(string);
|
15214 | pattern = guard ? undefined : pattern;
|
15215 |
|
15216 | if (pattern === undefined) {
|
15217 | return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
|
15218 | }
|
15219 | return string.match(pattern) || [];
|
15220 | }
|
15221 |
|
15222 | /*------------------------------------------------------------------------*/
|
15223 |
|
15224 | /**
|
15225 | * Attempts to invoke `func`, returning either the result or the caught error
|
15226 | * object. Any additional arguments are provided to `func` when it's invoked.
|
15227 | *
|
15228 | * @static
|
15229 | * @memberOf _
|
15230 | * @since 3.0.0
|
15231 | * @category Util
|
15232 | * @param {Function} func The function to attempt.
|
15233 | * @param {...*} [args] The arguments to invoke `func` with.
|
15234 | * @returns {*} Returns the `func` result or error object.
|
15235 | * @example
|
15236 | *
|
15237 | * // Avoid throwing errors for invalid selectors.
|
15238 | * var elements = _.attempt(function(selector) {
|
15239 | * return document.querySelectorAll(selector);
|
15240 | * }, '>_>');
|
15241 | *
|
15242 | * if (_.isError(elements)) {
|
15243 | * elements = [];
|
15244 | * }
|
15245 | */
|
15246 | var attempt = baseRest(function(func, args) {
|
15247 | try {
|
15248 | return apply(func, undefined, args);
|
15249 | } catch (e) {
|
15250 | return isError(e) ? e : new Error(e);
|
15251 | }
|
15252 | });
|
15253 |
|
15254 | /**
|
15255 | * Binds methods of an object to the object itself, overwriting the existing
|
15256 | * method.
|
15257 | *
|
15258 | * **Note:** This method doesn't set the "length" property of bound functions.
|
15259 | *
|
15260 | * @static
|
15261 | * @since 0.1.0
|
15262 | * @memberOf _
|
15263 | * @category Util
|
15264 | * @param {Object} object The object to bind and assign the bound methods to.
|
15265 | * @param {...(string|string[])} methodNames The object method names to bind.
|
15266 | * @returns {Object} Returns `object`.
|
15267 | * @example
|
15268 | *
|
15269 | * var view = {
|
15270 | * 'label': 'docs',
|
15271 | * 'click': function() {
|
15272 | * console.log('clicked ' + this.label);
|
15273 | * }
|
15274 | * };
|
15275 | *
|
15276 | * _.bindAll(view, ['click']);
|
15277 | * jQuery(element).on('click', view.click);
|
15278 | * // => Logs 'clicked docs' when clicked.
|
15279 | */
|
15280 | var bindAll = flatRest(function(object, methodNames) {
|
15281 | arrayEach(methodNames, function(key) {
|
15282 | key = toKey(key);
|
15283 | baseAssignValue(object, key, bind(object[key], object));
|
15284 | });
|
15285 | return object;
|
15286 | });
|
15287 |
|
15288 | /**
|
15289 | * Creates a function that iterates over `pairs` and invokes the corresponding
|
15290 | * function of the first predicate to return truthy. The predicate-function
|
15291 | * pairs are invoked with the `this` binding and arguments of the created
|
15292 | * function.
|
15293 | *
|
15294 | * @static
|
15295 | * @memberOf _
|
15296 | * @since 4.0.0
|
15297 | * @category Util
|
15298 | * @param {Array} pairs The predicate-function pairs.
|
15299 | * @returns {Function} Returns the new composite function.
|
15300 | * @example
|
15301 | *
|
15302 | * var func = _.cond([
|
15303 | * [_.matches({ 'a': 1 }), _.constant('matches A')],
|
15304 | * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
|
15305 | * [_.stubTrue, _.constant('no match')]
|
15306 | * ]);
|
15307 | *
|
15308 | * func({ 'a': 1, 'b': 2 });
|
15309 | * // => 'matches A'
|
15310 | *
|
15311 | * func({ 'a': 0, 'b': 1 });
|
15312 | * // => 'matches B'
|
15313 | *
|
15314 | * func({ 'a': '1', 'b': '2' });
|
15315 | * // => 'no match'
|
15316 | */
|
15317 | function cond(pairs) {
|
15318 | var length = pairs == null ? 0 : pairs.length,
|
15319 | toIteratee = getIteratee();
|
15320 |
|
15321 | pairs = !length ? [] : arrayMap(pairs, function(pair) {
|
15322 | if (typeof pair[1] != 'function') {
|
15323 | throw new TypeError(FUNC_ERROR_TEXT);
|
15324 | }
|
15325 | return [toIteratee(pair[0]), pair[1]];
|
15326 | });
|
15327 |
|
15328 | return baseRest(function(args) {
|
15329 | var index = -1;
|
15330 | while (++index < length) {
|
15331 | var pair = pairs[index];
|
15332 | if (apply(pair[0], this, args)) {
|
15333 | return apply(pair[1], this, args);
|
15334 | }
|
15335 | }
|
15336 | });
|
15337 | }
|
15338 |
|
15339 | /**
|
15340 | * Creates a function that invokes the predicate properties of `source` with
|
15341 | * the corresponding property values of a given object, returning `true` if
|
15342 | * all predicates return truthy, else `false`.
|
15343 | *
|
15344 | * **Note:** The created function is equivalent to `_.conformsTo` with
|
15345 | * `source` partially applied.
|
15346 | *
|
15347 | * @static
|
15348 | * @memberOf _
|
15349 | * @since 4.0.0
|
15350 | * @category Util
|
15351 | * @param {Object} source The object of property predicates to conform to.
|
15352 | * @returns {Function} Returns the new spec function.
|
15353 | * @example
|
15354 | *
|
15355 | * var objects = [
|
15356 | * { 'a': 2, 'b': 1 },
|
15357 | * { 'a': 1, 'b': 2 }
|
15358 | * ];
|
15359 | *
|
15360 | * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
|
15361 | * // => [{ 'a': 1, 'b': 2 }]
|
15362 | */
|
15363 | function conforms(source) {
|
15364 | return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
|
15365 | }
|
15366 |
|
15367 | /**
|
15368 | * Creates a function that returns `value`.
|
15369 | *
|
15370 | * @static
|
15371 | * @memberOf _
|
15372 | * @since 2.4.0
|
15373 | * @category Util
|
15374 | * @param {*} value The value to return from the new function.
|
15375 | * @returns {Function} Returns the new constant function.
|
15376 | * @example
|
15377 | *
|
15378 | * var objects = _.times(2, _.constant({ 'a': 1 }));
|
15379 | *
|
15380 | * console.log(objects);
|
15381 | * // => [{ 'a': 1 }, { 'a': 1 }]
|
15382 | *
|
15383 | * console.log(objects[0] === objects[1]);
|
15384 | * // => true
|
15385 | */
|
15386 | function constant(value) {
|
15387 | return function() {
|
15388 | return value;
|
15389 | };
|
15390 | }
|
15391 |
|
15392 | /**
|
15393 | * Checks `value` to determine whether a default value should be returned in
|
15394 | * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
|
15395 | * or `undefined`.
|
15396 | *
|
15397 | * @static
|
15398 | * @memberOf _
|
15399 | * @since 4.14.0
|
15400 | * @category Util
|
15401 | * @param {*} value The value to check.
|
15402 | * @param {*} defaultValue The default value.
|
15403 | * @returns {*} Returns the resolved value.
|
15404 | * @example
|
15405 | *
|
15406 | * _.defaultTo(1, 10);
|
15407 | * // => 1
|
15408 | *
|
15409 | * _.defaultTo(undefined, 10);
|
15410 | * // => 10
|
15411 | */
|
15412 | function defaultTo(value, defaultValue) {
|
15413 | return (value == null || value !== value) ? defaultValue : value;
|
15414 | }
|
15415 |
|
15416 | /**
|
15417 | * Creates a function that returns the result of invoking the given functions
|
15418 | * with the `this` binding of the created function, where each successive
|
15419 | * invocation is supplied the return value of the previous.
|
15420 | *
|
15421 | * @static
|
15422 | * @memberOf _
|
15423 | * @since 3.0.0
|
15424 | * @category Util
|
15425 | * @param {...(Function|Function[])} [funcs] The functions to invoke.
|
15426 | * @returns {Function} Returns the new composite function.
|
15427 | * @see _.flowRight
|
15428 | * @example
|
15429 | *
|
15430 | * function square(n) {
|
15431 | * return n * n;
|
15432 | * }
|
15433 | *
|
15434 | * var addSquare = _.flow([_.add, square]);
|
15435 | * addSquare(1, 2);
|
15436 | * // => 9
|
15437 | */
|
15438 | var flow = createFlow();
|
15439 |
|
15440 | /**
|
15441 | * This method is like `_.flow` except that it creates a function that
|
15442 | * invokes the given functions from right to left.
|
15443 | *
|
15444 | * @static
|
15445 | * @since 3.0.0
|
15446 | * @memberOf _
|
15447 | * @category Util
|
15448 | * @param {...(Function|Function[])} [funcs] The functions to invoke.
|
15449 | * @returns {Function} Returns the new composite function.
|
15450 | * @see _.flow
|
15451 | * @example
|
15452 | *
|
15453 | * function square(n) {
|
15454 | * return n * n;
|
15455 | * }
|
15456 | *
|
15457 | * var addSquare = _.flowRight([square, _.add]);
|
15458 | * addSquare(1, 2);
|
15459 | * // => 9
|
15460 | */
|
15461 | var flowRight = createFlow(true);
|
15462 |
|
15463 | /**
|
15464 | * This method returns the first argument it receives.
|
15465 | *
|
15466 | * @static
|
15467 | * @since 0.1.0
|
15468 | * @memberOf _
|
15469 | * @category Util
|
15470 | * @param {*} value Any value.
|
15471 | * @returns {*} Returns `value`.
|
15472 | * @example
|
15473 | *
|
15474 | * var object = { 'a': 1 };
|
15475 | *
|
15476 | * console.log(_.identity(object) === object);
|
15477 | * // => true
|
15478 | */
|
15479 | function identity(value) {
|
15480 | return value;
|
15481 | }
|
15482 |
|
15483 | /**
|
15484 | * Creates a function that invokes `func` with the arguments of the created
|
15485 | * function. If `func` is a property name, the created function returns the
|
15486 | * property value for a given element. If `func` is an array or object, the
|
15487 | * created function returns `true` for elements that contain the equivalent
|
15488 | * source properties, otherwise it returns `false`.
|
15489 | *
|
15490 | * @static
|
15491 | * @since 4.0.0
|
15492 | * @memberOf _
|
15493 | * @category Util
|
15494 | * @param {*} [func=_.identity] The value to convert to a callback.
|
15495 | * @returns {Function} Returns the callback.
|
15496 | * @example
|
15497 | *
|
15498 | * var users = [
|
15499 | * { 'user': 'barney', 'age': 36, 'active': true },
|
15500 | * { 'user': 'fred', 'age': 40, 'active': false }
|
15501 | * ];
|
15502 | *
|
15503 | * // The `_.matches` iteratee shorthand.
|
15504 | * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
|
15505 | * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
|
15506 | *
|
15507 | * // The `_.matchesProperty` iteratee shorthand.
|
15508 | * _.filter(users, _.iteratee(['user', 'fred']));
|
15509 | * // => [{ 'user': 'fred', 'age': 40 }]
|
15510 | *
|
15511 | * // The `_.property` iteratee shorthand.
|
15512 | * _.map(users, _.iteratee('user'));
|
15513 | * // => ['barney', 'fred']
|
15514 | *
|
15515 | * // Create custom iteratee shorthands.
|
15516 | * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
|
15517 | * return !_.isRegExp(func) ? iteratee(func) : function(string) {
|
15518 | * return func.test(string);
|
15519 | * };
|
15520 | * });
|
15521 | *
|
15522 | * _.filter(['abc', 'def'], /ef/);
|
15523 | * // => ['def']
|
15524 | */
|
15525 | function iteratee(func) {
|
15526 | return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
|
15527 | }
|
15528 |
|
15529 | /**
|
15530 | * Creates a function that performs a partial deep comparison between a given
|
15531 | * object and `source`, returning `true` if the given object has equivalent
|
15532 | * property values, else `false`.
|
15533 | *
|
15534 | * **Note:** The created function is equivalent to `_.isMatch` with `source`
|
15535 | * partially applied.
|
15536 | *
|
15537 | * Partial comparisons will match empty array and empty object `source`
|
15538 | * values against any array or object value, respectively. See `_.isEqual`
|
15539 | * for a list of supported value comparisons.
|
15540 | *
|
15541 | * @static
|
15542 | * @memberOf _
|
15543 | * @since 3.0.0
|
15544 | * @category Util
|
15545 | * @param {Object} source The object of property values to match.
|
15546 | * @returns {Function} Returns the new spec function.
|
15547 | * @example
|
15548 | *
|
15549 | * var objects = [
|
15550 | * { 'a': 1, 'b': 2, 'c': 3 },
|
15551 | * { 'a': 4, 'b': 5, 'c': 6 }
|
15552 | * ];
|
15553 | *
|
15554 | * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
|
15555 | * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
|
15556 | */
|
15557 | function matches(source) {
|
15558 | return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
|
15559 | }
|
15560 |
|
15561 | /**
|
15562 | * Creates a function that performs a partial deep comparison between the
|
15563 | * value at `path` of a given object to `srcValue`, returning `true` if the
|
15564 | * object value is equivalent, else `false`.
|
15565 | *
|
15566 | * **Note:** Partial comparisons will match empty array and empty object
|
15567 | * `srcValue` values against any array or object value, respectively. See
|
15568 | * `_.isEqual` for a list of supported value comparisons.
|
15569 | *
|
15570 | * @static
|
15571 | * @memberOf _
|
15572 | * @since 3.2.0
|
15573 | * @category Util
|
15574 | * @param {Array|string} path The path of the property to get.
|
15575 | * @param {*} srcValue The value to match.
|
15576 | * @returns {Function} Returns the new spec function.
|
15577 | * @example
|
15578 | *
|
15579 | * var objects = [
|
15580 | * { 'a': 1, 'b': 2, 'c': 3 },
|
15581 | * { 'a': 4, 'b': 5, 'c': 6 }
|
15582 | * ];
|
15583 | *
|
15584 | * _.find(objects, _.matchesProperty('a', 4));
|
15585 | * // => { 'a': 4, 'b': 5, 'c': 6 }
|
15586 | */
|
15587 | function matchesProperty(path, srcValue) {
|
15588 | return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
|
15589 | }
|
15590 |
|
15591 | /**
|
15592 | * Creates a function that invokes the method at `path` of a given object.
|
15593 | * Any additional arguments are provided to the invoked method.
|
15594 | *
|
15595 | * @static
|
15596 | * @memberOf _
|
15597 | * @since 3.7.0
|
15598 | * @category Util
|
15599 | * @param {Array|string} path The path of the method to invoke.
|
15600 | * @param {...*} [args] The arguments to invoke the method with.
|
15601 | * @returns {Function} Returns the new invoker function.
|
15602 | * @example
|
15603 | *
|
15604 | * var objects = [
|
15605 | * { 'a': { 'b': _.constant(2) } },
|
15606 | * { 'a': { 'b': _.constant(1) } }
|
15607 | * ];
|
15608 | *
|
15609 | * _.map(objects, _.method('a.b'));
|
15610 | * // => [2, 1]
|
15611 | *
|
15612 | * _.map(objects, _.method(['a', 'b']));
|
15613 | * // => [2, 1]
|
15614 | */
|
15615 | var method = baseRest(function(path, args) {
|
15616 | return function(object) {
|
15617 | return baseInvoke(object, path, args);
|
15618 | };
|
15619 | });
|
15620 |
|
15621 | /**
|
15622 | * The opposite of `_.method`; this method creates a function that invokes
|
15623 | * the method at a given path of `object`. Any additional arguments are
|
15624 | * provided to the invoked method.
|
15625 | *
|
15626 | * @static
|
15627 | * @memberOf _
|
15628 | * @since 3.7.0
|
15629 | * @category Util
|
15630 | * @param {Object} object The object to query.
|
15631 | * @param {...*} [args] The arguments to invoke the method with.
|
15632 | * @returns {Function} Returns the new invoker function.
|
15633 | * @example
|
15634 | *
|
15635 | * var array = _.times(3, _.constant),
|
15636 | * object = { 'a': array, 'b': array, 'c': array };
|
15637 | *
|
15638 | * _.map(['a[2]', 'c[0]'], _.methodOf(object));
|
15639 | * // => [2, 0]
|
15640 | *
|
15641 | * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
|
15642 | * // => [2, 0]
|
15643 | */
|
15644 | var methodOf = baseRest(function(object, args) {
|
15645 | return function(path) {
|
15646 | return baseInvoke(object, path, args);
|
15647 | };
|
15648 | });
|
15649 |
|
15650 | /**
|
15651 | * Adds all own enumerable string keyed function properties of a source
|
15652 | * object to the destination object. If `object` is a function, then methods
|
15653 | * are added to its prototype as well.
|
15654 | *
|
15655 | * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
|
15656 | * avoid conflicts caused by modifying the original.
|
15657 | *
|
15658 | * @static
|
15659 | * @since 0.1.0
|
15660 | * @memberOf _
|
15661 | * @category Util
|
15662 | * @param {Function|Object} [object=lodash] The destination object.
|
15663 | * @param {Object} source The object of functions to add.
|
15664 | * @param {Object} [options={}] The options object.
|
15665 | * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
|
15666 | * @returns {Function|Object} Returns `object`.
|
15667 | * @example
|
15668 | *
|
15669 | * function vowels(string) {
|
15670 | * return _.filter(string, function(v) {
|
15671 | * return /[aeiou]/i.test(v);
|
15672 | * });
|
15673 | * }
|
15674 | *
|
15675 | * _.mixin({ 'vowels': vowels });
|
15676 | * _.vowels('fred');
|
15677 | * // => ['e']
|
15678 | *
|
15679 | * _('fred').vowels().value();
|
15680 | * // => ['e']
|
15681 | *
|
15682 | * _.mixin({ 'vowels': vowels }, { 'chain': false });
|
15683 | * _('fred').vowels();
|
15684 | * // => ['e']
|
15685 | */
|
15686 | function mixin(object, source, options) {
|
15687 | var props = keys(source),
|
15688 | methodNames = baseFunctions(source, props);
|
15689 |
|
15690 | if (options == null &&
|
15691 | !(isObject(source) && (methodNames.length || !props.length))) {
|
15692 | options = source;
|
15693 | source = object;
|
15694 | object = this;
|
15695 | methodNames = baseFunctions(source, keys(source));
|
15696 | }
|
15697 | var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
|
15698 | isFunc = isFunction(object);
|
15699 |
|
15700 | arrayEach(methodNames, function(methodName) {
|
15701 | var func = source[methodName];
|
15702 | object[methodName] = func;
|
15703 | if (isFunc) {
|
15704 | object.prototype[methodName] = function() {
|
15705 | var chainAll = this.__chain__;
|
15706 | if (chain || chainAll) {
|
15707 | var result = object(this.__wrapped__),
|
15708 | actions = result.__actions__ = copyArray(this.__actions__);
|
15709 |
|
15710 | actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
15711 | result.__chain__ = chainAll;
|
15712 | return result;
|
15713 | }
|
15714 | return func.apply(object, arrayPush([this.value()], arguments));
|
15715 | };
|
15716 | }
|
15717 | });
|
15718 |
|
15719 | return object;
|
15720 | }
|
15721 |
|
15722 | /**
|
15723 | * Reverts the `_` variable to its previous value and returns a reference to
|
15724 | * the `lodash` function.
|
15725 | *
|
15726 | * @static
|
15727 | * @since 0.1.0
|
15728 | * @memberOf _
|
15729 | * @category Util
|
15730 | * @returns {Function} Returns the `lodash` function.
|
15731 | * @example
|
15732 | *
|
15733 | * var lodash = _.noConflict();
|
15734 | */
|
15735 | function noConflict() {
|
15736 | if (root._ === this) {
|
15737 | root._ = oldDash;
|
15738 | }
|
15739 | return this;
|
15740 | }
|
15741 |
|
15742 | /**
|
15743 | * This method returns `undefined`.
|
15744 | *
|
15745 | * @static
|
15746 | * @memberOf _
|
15747 | * @since 2.3.0
|
15748 | * @category Util
|
15749 | * @example
|
15750 | *
|
15751 | * _.times(2, _.noop);
|
15752 | * // => [undefined, undefined]
|
15753 | */
|
15754 | function noop() {
|
15755 | // No operation performed.
|
15756 | }
|
15757 |
|
15758 | /**
|
15759 | * Creates a function that gets the argument at index `n`. If `n` is negative,
|
15760 | * the nth argument from the end is returned.
|
15761 | *
|
15762 | * @static
|
15763 | * @memberOf _
|
15764 | * @since 4.0.0
|
15765 | * @category Util
|
15766 | * @param {number} [n=0] The index of the argument to return.
|
15767 | * @returns {Function} Returns the new pass-thru function.
|
15768 | * @example
|
15769 | *
|
15770 | * var func = _.nthArg(1);
|
15771 | * func('a', 'b', 'c', 'd');
|
15772 | * // => 'b'
|
15773 | *
|
15774 | * var func = _.nthArg(-2);
|
15775 | * func('a', 'b', 'c', 'd');
|
15776 | * // => 'c'
|
15777 | */
|
15778 | function nthArg(n) {
|
15779 | n = toInteger(n);
|
15780 | return baseRest(function(args) {
|
15781 | return baseNth(args, n);
|
15782 | });
|
15783 | }
|
15784 |
|
15785 | /**
|
15786 | * Creates a function that invokes `iteratees` with the arguments it receives
|
15787 | * and returns their results.
|
15788 | *
|
15789 | * @static
|
15790 | * @memberOf _
|
15791 | * @since 4.0.0
|
15792 | * @category Util
|
15793 | * @param {...(Function|Function[])} [iteratees=[_.identity]]
|
15794 | * The iteratees to invoke.
|
15795 | * @returns {Function} Returns the new function.
|
15796 | * @example
|
15797 | *
|
15798 | * var func = _.over([Math.max, Math.min]);
|
15799 | *
|
15800 | * func(1, 2, 3, 4);
|
15801 | * // => [4, 1]
|
15802 | */
|
15803 | var over = createOver(arrayMap);
|
15804 |
|
15805 | /**
|
15806 | * Creates a function that checks if **all** of the `predicates` return
|
15807 | * truthy when invoked with the arguments it receives.
|
15808 | *
|
15809 | * @static
|
15810 | * @memberOf _
|
15811 | * @since 4.0.0
|
15812 | * @category Util
|
15813 | * @param {...(Function|Function[])} [predicates=[_.identity]]
|
15814 | * The predicates to check.
|
15815 | * @returns {Function} Returns the new function.
|
15816 | * @example
|
15817 | *
|
15818 | * var func = _.overEvery([Boolean, isFinite]);
|
15819 | *
|
15820 | * func('1');
|
15821 | * // => true
|
15822 | *
|
15823 | * func(null);
|
15824 | * // => false
|
15825 | *
|
15826 | * func(NaN);
|
15827 | * // => false
|
15828 | */
|
15829 | var overEvery = createOver(arrayEvery);
|
15830 |
|
15831 | /**
|
15832 | * Creates a function that checks if **any** of the `predicates` return
|
15833 | * truthy when invoked with the arguments it receives.
|
15834 | *
|
15835 | * @static
|
15836 | * @memberOf _
|
15837 | * @since 4.0.0
|
15838 | * @category Util
|
15839 | * @param {...(Function|Function[])} [predicates=[_.identity]]
|
15840 | * The predicates to check.
|
15841 | * @returns {Function} Returns the new function.
|
15842 | * @example
|
15843 | *
|
15844 | * var func = _.overSome([Boolean, isFinite]);
|
15845 | *
|
15846 | * func('1');
|
15847 | * // => true
|
15848 | *
|
15849 | * func(null);
|
15850 | * // => true
|
15851 | *
|
15852 | * func(NaN);
|
15853 | * // => false
|
15854 | */
|
15855 | var overSome = createOver(arraySome);
|
15856 |
|
15857 | /**
|
15858 | * Creates a function that returns the value at `path` of a given object.
|
15859 | *
|
15860 | * @static
|
15861 | * @memberOf _
|
15862 | * @since 2.4.0
|
15863 | * @category Util
|
15864 | * @param {Array|string} path The path of the property to get.
|
15865 | * @returns {Function} Returns the new accessor function.
|
15866 | * @example
|
15867 | *
|
15868 | * var objects = [
|
15869 | * { 'a': { 'b': 2 } },
|
15870 | * { 'a': { 'b': 1 } }
|
15871 | * ];
|
15872 | *
|
15873 | * _.map(objects, _.property('a.b'));
|
15874 | * // => [2, 1]
|
15875 | *
|
15876 | * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
|
15877 | * // => [1, 2]
|
15878 | */
|
15879 | function property(path) {
|
15880 | return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
|
15881 | }
|
15882 |
|
15883 | /**
|
15884 | * The opposite of `_.property`; this method creates a function that returns
|
15885 | * the value at a given path of `object`.
|
15886 | *
|
15887 | * @static
|
15888 | * @memberOf _
|
15889 | * @since 3.0.0
|
15890 | * @category Util
|
15891 | * @param {Object} object The object to query.
|
15892 | * @returns {Function} Returns the new accessor function.
|
15893 | * @example
|
15894 | *
|
15895 | * var array = [0, 1, 2],
|
15896 | * object = { 'a': array, 'b': array, 'c': array };
|
15897 | *
|
15898 | * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
|
15899 | * // => [2, 0]
|
15900 | *
|
15901 | * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
|
15902 | * // => [2, 0]
|
15903 | */
|
15904 | function propertyOf(object) {
|
15905 | return function(path) {
|
15906 | return object == null ? undefined : baseGet(object, path);
|
15907 | };
|
15908 | }
|
15909 |
|
15910 | /**
|
15911 | * Creates an array of numbers (positive and/or negative) progressing from
|
15912 | * `start` up to, but not including, `end`. A step of `-1` is used if a negative
|
15913 | * `start` is specified without an `end` or `step`. If `end` is not specified,
|
15914 | * it's set to `start` with `start` then set to `0`.
|
15915 | *
|
15916 | * **Note:** JavaScript follows the IEEE-754 standard for resolving
|
15917 | * floating-point values which can produce unexpected results.
|
15918 | *
|
15919 | * @static
|
15920 | * @since 0.1.0
|
15921 | * @memberOf _
|
15922 | * @category Util
|
15923 | * @param {number} [start=0] The start of the range.
|
15924 | * @param {number} end The end of the range.
|
15925 | * @param {number} [step=1] The value to increment or decrement by.
|
15926 | * @returns {Array} Returns the range of numbers.
|
15927 | * @see _.inRange, _.rangeRight
|
15928 | * @example
|
15929 | *
|
15930 | * _.range(4);
|
15931 | * // => [0, 1, 2, 3]
|
15932 | *
|
15933 | * _.range(-4);
|
15934 | * // => [0, -1, -2, -3]
|
15935 | *
|
15936 | * _.range(1, 5);
|
15937 | * // => [1, 2, 3, 4]
|
15938 | *
|
15939 | * _.range(0, 20, 5);
|
15940 | * // => [0, 5, 10, 15]
|
15941 | *
|
15942 | * _.range(0, -4, -1);
|
15943 | * // => [0, -1, -2, -3]
|
15944 | *
|
15945 | * _.range(1, 4, 0);
|
15946 | * // => [1, 1, 1]
|
15947 | *
|
15948 | * _.range(0);
|
15949 | * // => []
|
15950 | */
|
15951 | var range = createRange();
|
15952 |
|
15953 | /**
|
15954 | * This method is like `_.range` except that it populates values in
|
15955 | * descending order.
|
15956 | *
|
15957 | * @static
|
15958 | * @memberOf _
|
15959 | * @since 4.0.0
|
15960 | * @category Util
|
15961 | * @param {number} [start=0] The start of the range.
|
15962 | * @param {number} end The end of the range.
|
15963 | * @param {number} [step=1] The value to increment or decrement by.
|
15964 | * @returns {Array} Returns the range of numbers.
|
15965 | * @see _.inRange, _.range
|
15966 | * @example
|
15967 | *
|
15968 | * _.rangeRight(4);
|
15969 | * // => [3, 2, 1, 0]
|
15970 | *
|
15971 | * _.rangeRight(-4);
|
15972 | * // => [-3, -2, -1, 0]
|
15973 | *
|
15974 | * _.rangeRight(1, 5);
|
15975 | * // => [4, 3, 2, 1]
|
15976 | *
|
15977 | * _.rangeRight(0, 20, 5);
|
15978 | * // => [15, 10, 5, 0]
|
15979 | *
|
15980 | * _.rangeRight(0, -4, -1);
|
15981 | * // => [-3, -2, -1, 0]
|
15982 | *
|
15983 | * _.rangeRight(1, 4, 0);
|
15984 | * // => [1, 1, 1]
|
15985 | *
|
15986 | * _.rangeRight(0);
|
15987 | * // => []
|
15988 | */
|
15989 | var rangeRight = createRange(true);
|
15990 |
|
15991 | /**
|
15992 | * This method returns a new empty array.
|
15993 | *
|
15994 | * @static
|
15995 | * @memberOf _
|
15996 | * @since 4.13.0
|
15997 | * @category Util
|
15998 | * @returns {Array} Returns the new empty array.
|
15999 | * @example
|
16000 | *
|
16001 | * var arrays = _.times(2, _.stubArray);
|
16002 | *
|
16003 | * console.log(arrays);
|
16004 | * // => [[], []]
|
16005 | *
|
16006 | * console.log(arrays[0] === arrays[1]);
|
16007 | * // => false
|
16008 | */
|
16009 | function stubArray() {
|
16010 | return [];
|
16011 | }
|
16012 |
|
16013 | /**
|
16014 | * This method returns `false`.
|
16015 | *
|
16016 | * @static
|
16017 | * @memberOf _
|
16018 | * @since 4.13.0
|
16019 | * @category Util
|
16020 | * @returns {boolean} Returns `false`.
|
16021 | * @example
|
16022 | *
|
16023 | * _.times(2, _.stubFalse);
|
16024 | * // => [false, false]
|
16025 | */
|
16026 | function stubFalse() {
|
16027 | return false;
|
16028 | }
|
16029 |
|
16030 | /**
|
16031 | * This method returns a new empty object.
|
16032 | *
|
16033 | * @static
|
16034 | * @memberOf _
|
16035 | * @since 4.13.0
|
16036 | * @category Util
|
16037 | * @returns {Object} Returns the new empty object.
|
16038 | * @example
|
16039 | *
|
16040 | * var objects = _.times(2, _.stubObject);
|
16041 | *
|
16042 | * console.log(objects);
|
16043 | * // => [{}, {}]
|
16044 | *
|
16045 | * console.log(objects[0] === objects[1]);
|
16046 | * // => false
|
16047 | */
|
16048 | function stubObject() {
|
16049 | return {};
|
16050 | }
|
16051 |
|
16052 | /**
|
16053 | * This method returns an empty string.
|
16054 | *
|
16055 | * @static
|
16056 | * @memberOf _
|
16057 | * @since 4.13.0
|
16058 | * @category Util
|
16059 | * @returns {string} Returns the empty string.
|
16060 | * @example
|
16061 | *
|
16062 | * _.times(2, _.stubString);
|
16063 | * // => ['', '']
|
16064 | */
|
16065 | function stubString() {
|
16066 | return '';
|
16067 | }
|
16068 |
|
16069 | /**
|
16070 | * This method returns `true`.
|
16071 | *
|
16072 | * @static
|
16073 | * @memberOf _
|
16074 | * @since 4.13.0
|
16075 | * @category Util
|
16076 | * @returns {boolean} Returns `true`.
|
16077 | * @example
|
16078 | *
|
16079 | * _.times(2, _.stubTrue);
|
16080 | * // => [true, true]
|
16081 | */
|
16082 | function stubTrue() {
|
16083 | return true;
|
16084 | }
|
16085 |
|
16086 | /**
|
16087 | * Invokes the iteratee `n` times, returning an array of the results of
|
16088 | * each invocation. The iteratee is invoked with one argument; (index).
|
16089 | *
|
16090 | * @static
|
16091 | * @since 0.1.0
|
16092 | * @memberOf _
|
16093 | * @category Util
|
16094 | * @param {number} n The number of times to invoke `iteratee`.
|
16095 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
16096 | * @returns {Array} Returns the array of results.
|
16097 | * @example
|
16098 | *
|
16099 | * _.times(3, String);
|
16100 | * // => ['0', '1', '2']
|
16101 | *
|
16102 | * _.times(4, _.constant(0));
|
16103 | * // => [0, 0, 0, 0]
|
16104 | */
|
16105 | function times(n, iteratee) {
|
16106 | n = toInteger(n);
|
16107 | if (n < 1 || n > MAX_SAFE_INTEGER) {
|
16108 | return [];
|
16109 | }
|
16110 | var index = MAX_ARRAY_LENGTH,
|
16111 | length = nativeMin(n, MAX_ARRAY_LENGTH);
|
16112 |
|
16113 | iteratee = getIteratee(iteratee);
|
16114 | n -= MAX_ARRAY_LENGTH;
|
16115 |
|
16116 | var result = baseTimes(length, iteratee);
|
16117 | while (++index < n) {
|
16118 | iteratee(index);
|
16119 | }
|
16120 | return result;
|
16121 | }
|
16122 |
|
16123 | /**
|
16124 | * Converts `value` to a property path array.
|
16125 | *
|
16126 | * @static
|
16127 | * @memberOf _
|
16128 | * @since 4.0.0
|
16129 | * @category Util
|
16130 | * @param {*} value The value to convert.
|
16131 | * @returns {Array} Returns the new property path array.
|
16132 | * @example
|
16133 | *
|
16134 | * _.toPath('a.b.c');
|
16135 | * // => ['a', 'b', 'c']
|
16136 | *
|
16137 | * _.toPath('a[0].b.c');
|
16138 | * // => ['a', '0', 'b', 'c']
|
16139 | */
|
16140 | function toPath(value) {
|
16141 | if (isArray(value)) {
|
16142 | return arrayMap(value, toKey);
|
16143 | }
|
16144 | return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
|
16145 | }
|
16146 |
|
16147 | /**
|
16148 | * Generates a unique ID. If `prefix` is given, the ID is appended to it.
|
16149 | *
|
16150 | * @static
|
16151 | * @since 0.1.0
|
16152 | * @memberOf _
|
16153 | * @category Util
|
16154 | * @param {string} [prefix=''] The value to prefix the ID with.
|
16155 | * @returns {string} Returns the unique ID.
|
16156 | * @example
|
16157 | *
|
16158 | * _.uniqueId('contact_');
|
16159 | * // => 'contact_104'
|
16160 | *
|
16161 | * _.uniqueId();
|
16162 | * // => '105'
|
16163 | */
|
16164 | function uniqueId(prefix) {
|
16165 | var id = ++idCounter;
|
16166 | return toString(prefix) + id;
|
16167 | }
|
16168 |
|
16169 | /*------------------------------------------------------------------------*/
|
16170 |
|
16171 | /**
|
16172 | * Adds two numbers.
|
16173 | *
|
16174 | * @static
|
16175 | * @memberOf _
|
16176 | * @since 3.4.0
|
16177 | * @category Math
|
16178 | * @param {number} augend The first number in an addition.
|
16179 | * @param {number} addend The second number in an addition.
|
16180 | * @returns {number} Returns the total.
|
16181 | * @example
|
16182 | *
|
16183 | * _.add(6, 4);
|
16184 | * // => 10
|
16185 | */
|
16186 | var add = createMathOperation(function(augend, addend) {
|
16187 | return augend + addend;
|
16188 | }, 0);
|
16189 |
|
16190 | /**
|
16191 | * Computes `number` rounded up to `precision`.
|
16192 | *
|
16193 | * @static
|
16194 | * @memberOf _
|
16195 | * @since 3.10.0
|
16196 | * @category Math
|
16197 | * @param {number} number The number to round up.
|
16198 | * @param {number} [precision=0] The precision to round up to.
|
16199 | * @returns {number} Returns the rounded up number.
|
16200 | * @example
|
16201 | *
|
16202 | * _.ceil(4.006);
|
16203 | * // => 5
|
16204 | *
|
16205 | * _.ceil(6.004, 2);
|
16206 | * // => 6.01
|
16207 | *
|
16208 | * _.ceil(6040, -2);
|
16209 | * // => 6100
|
16210 | */
|
16211 | var ceil = createRound('ceil');
|
16212 |
|
16213 | /**
|
16214 | * Divide two numbers.
|
16215 | *
|
16216 | * @static
|
16217 | * @memberOf _
|
16218 | * @since 4.7.0
|
16219 | * @category Math
|
16220 | * @param {number} dividend The first number in a division.
|
16221 | * @param {number} divisor The second number in a division.
|
16222 | * @returns {number} Returns the quotient.
|
16223 | * @example
|
16224 | *
|
16225 | * _.divide(6, 4);
|
16226 | * // => 1.5
|
16227 | */
|
16228 | var divide = createMathOperation(function(dividend, divisor) {
|
16229 | return dividend / divisor;
|
16230 | }, 1);
|
16231 |
|
16232 | /**
|
16233 | * Computes `number` rounded down to `precision`.
|
16234 | *
|
16235 | * @static
|
16236 | * @memberOf _
|
16237 | * @since 3.10.0
|
16238 | * @category Math
|
16239 | * @param {number} number The number to round down.
|
16240 | * @param {number} [precision=0] The precision to round down to.
|
16241 | * @returns {number} Returns the rounded down number.
|
16242 | * @example
|
16243 | *
|
16244 | * _.floor(4.006);
|
16245 | * // => 4
|
16246 | *
|
16247 | * _.floor(0.046, 2);
|
16248 | * // => 0.04
|
16249 | *
|
16250 | * _.floor(4060, -2);
|
16251 | * // => 4000
|
16252 | */
|
16253 | var floor = createRound('floor');
|
16254 |
|
16255 | /**
|
16256 | * Computes the maximum value of `array`. If `array` is empty or falsey,
|
16257 | * `undefined` is returned.
|
16258 | *
|
16259 | * @static
|
16260 | * @since 0.1.0
|
16261 | * @memberOf _
|
16262 | * @category Math
|
16263 | * @param {Array} array The array to iterate over.
|
16264 | * @returns {*} Returns the maximum value.
|
16265 | * @example
|
16266 | *
|
16267 | * _.max([4, 2, 8, 6]);
|
16268 | * // => 8
|
16269 | *
|
16270 | * _.max([]);
|
16271 | * // => undefined
|
16272 | */
|
16273 | function max(array) {
|
16274 | return (array && array.length)
|
16275 | ? baseExtremum(array, identity, baseGt)
|
16276 | : undefined;
|
16277 | }
|
16278 |
|
16279 | /**
|
16280 | * This method is like `_.max` except that it accepts `iteratee` which is
|
16281 | * invoked for each element in `array` to generate the criterion by which
|
16282 | * the value is ranked. The iteratee is invoked with one argument: (value).
|
16283 | *
|
16284 | * @static
|
16285 | * @memberOf _
|
16286 | * @since 4.0.0
|
16287 | * @category Math
|
16288 | * @param {Array} array The array to iterate over.
|
16289 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
16290 | * @returns {*} Returns the maximum value.
|
16291 | * @example
|
16292 | *
|
16293 | * var objects = [{ 'n': 1 }, { 'n': 2 }];
|
16294 | *
|
16295 | * _.maxBy(objects, function(o) { return o.n; });
|
16296 | * // => { 'n': 2 }
|
16297 | *
|
16298 | * // The `_.property` iteratee shorthand.
|
16299 | * _.maxBy(objects, 'n');
|
16300 | * // => { 'n': 2 }
|
16301 | */
|
16302 | function maxBy(array, iteratee) {
|
16303 | return (array && array.length)
|
16304 | ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
|
16305 | : undefined;
|
16306 | }
|
16307 |
|
16308 | /**
|
16309 | * Computes the mean of the values in `array`.
|
16310 | *
|
16311 | * @static
|
16312 | * @memberOf _
|
16313 | * @since 4.0.0
|
16314 | * @category Math
|
16315 | * @param {Array} array The array to iterate over.
|
16316 | * @returns {number} Returns the mean.
|
16317 | * @example
|
16318 | *
|
16319 | * _.mean([4, 2, 8, 6]);
|
16320 | * // => 5
|
16321 | */
|
16322 | function mean(array) {
|
16323 | return baseMean(array, identity);
|
16324 | }
|
16325 |
|
16326 | /**
|
16327 | * This method is like `_.mean` except that it accepts `iteratee` which is
|
16328 | * invoked for each element in `array` to generate the value to be averaged.
|
16329 | * The iteratee is invoked with one argument: (value).
|
16330 | *
|
16331 | * @static
|
16332 | * @memberOf _
|
16333 | * @since 4.7.0
|
16334 | * @category Math
|
16335 | * @param {Array} array The array to iterate over.
|
16336 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
16337 | * @returns {number} Returns the mean.
|
16338 | * @example
|
16339 | *
|
16340 | * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
|
16341 | *
|
16342 | * _.meanBy(objects, function(o) { return o.n; });
|
16343 | * // => 5
|
16344 | *
|
16345 | * // The `_.property` iteratee shorthand.
|
16346 | * _.meanBy(objects, 'n');
|
16347 | * // => 5
|
16348 | */
|
16349 | function meanBy(array, iteratee) {
|
16350 | return baseMean(array, getIteratee(iteratee, 2));
|
16351 | }
|
16352 |
|
16353 | /**
|
16354 | * Computes the minimum value of `array`. If `array` is empty or falsey,
|
16355 | * `undefined` is returned.
|
16356 | *
|
16357 | * @static
|
16358 | * @since 0.1.0
|
16359 | * @memberOf _
|
16360 | * @category Math
|
16361 | * @param {Array} array The array to iterate over.
|
16362 | * @returns {*} Returns the minimum value.
|
16363 | * @example
|
16364 | *
|
16365 | * _.min([4, 2, 8, 6]);
|
16366 | * // => 2
|
16367 | *
|
16368 | * _.min([]);
|
16369 | * // => undefined
|
16370 | */
|
16371 | function min(array) {
|
16372 | return (array && array.length)
|
16373 | ? baseExtremum(array, identity, baseLt)
|
16374 | : undefined;
|
16375 | }
|
16376 |
|
16377 | /**
|
16378 | * This method is like `_.min` except that it accepts `iteratee` which is
|
16379 | * invoked for each element in `array` to generate the criterion by which
|
16380 | * the value is ranked. The iteratee is invoked with one argument: (value).
|
16381 | *
|
16382 | * @static
|
16383 | * @memberOf _
|
16384 | * @since 4.0.0
|
16385 | * @category Math
|
16386 | * @param {Array} array The array to iterate over.
|
16387 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
16388 | * @returns {*} Returns the minimum value.
|
16389 | * @example
|
16390 | *
|
16391 | * var objects = [{ 'n': 1 }, { 'n': 2 }];
|
16392 | *
|
16393 | * _.minBy(objects, function(o) { return o.n; });
|
16394 | * // => { 'n': 1 }
|
16395 | *
|
16396 | * // The `_.property` iteratee shorthand.
|
16397 | * _.minBy(objects, 'n');
|
16398 | * // => { 'n': 1 }
|
16399 | */
|
16400 | function minBy(array, iteratee) {
|
16401 | return (array && array.length)
|
16402 | ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
|
16403 | : undefined;
|
16404 | }
|
16405 |
|
16406 | /**
|
16407 | * Multiply two numbers.
|
16408 | *
|
16409 | * @static
|
16410 | * @memberOf _
|
16411 | * @since 4.7.0
|
16412 | * @category Math
|
16413 | * @param {number} multiplier The first number in a multiplication.
|
16414 | * @param {number} multiplicand The second number in a multiplication.
|
16415 | * @returns {number} Returns the product.
|
16416 | * @example
|
16417 | *
|
16418 | * _.multiply(6, 4);
|
16419 | * // => 24
|
16420 | */
|
16421 | var multiply = createMathOperation(function(multiplier, multiplicand) {
|
16422 | return multiplier * multiplicand;
|
16423 | }, 1);
|
16424 |
|
16425 | /**
|
16426 | * Computes `number` rounded to `precision`.
|
16427 | *
|
16428 | * @static
|
16429 | * @memberOf _
|
16430 | * @since 3.10.0
|
16431 | * @category Math
|
16432 | * @param {number} number The number to round.
|
16433 | * @param {number} [precision=0] The precision to round to.
|
16434 | * @returns {number} Returns the rounded number.
|
16435 | * @example
|
16436 | *
|
16437 | * _.round(4.006);
|
16438 | * // => 4
|
16439 | *
|
16440 | * _.round(4.006, 2);
|
16441 | * // => 4.01
|
16442 | *
|
16443 | * _.round(4060, -2);
|
16444 | * // => 4100
|
16445 | */
|
16446 | var round = createRound('round');
|
16447 |
|
16448 | /**
|
16449 | * Subtract two numbers.
|
16450 | *
|
16451 | * @static
|
16452 | * @memberOf _
|
16453 | * @since 4.0.0
|
16454 | * @category Math
|
16455 | * @param {number} minuend The first number in a subtraction.
|
16456 | * @param {number} subtrahend The second number in a subtraction.
|
16457 | * @returns {number} Returns the difference.
|
16458 | * @example
|
16459 | *
|
16460 | * _.subtract(6, 4);
|
16461 | * // => 2
|
16462 | */
|
16463 | var subtract = createMathOperation(function(minuend, subtrahend) {
|
16464 | return minuend - subtrahend;
|
16465 | }, 0);
|
16466 |
|
16467 | /**
|
16468 | * Computes the sum of the values in `array`.
|
16469 | *
|
16470 | * @static
|
16471 | * @memberOf _
|
16472 | * @since 3.4.0
|
16473 | * @category Math
|
16474 | * @param {Array} array The array to iterate over.
|
16475 | * @returns {number} Returns the sum.
|
16476 | * @example
|
16477 | *
|
16478 | * _.sum([4, 2, 8, 6]);
|
16479 | * // => 20
|
16480 | */
|
16481 | function sum(array) {
|
16482 | return (array && array.length)
|
16483 | ? baseSum(array, identity)
|
16484 | : 0;
|
16485 | }
|
16486 |
|
16487 | /**
|
16488 | * This method is like `_.sum` except that it accepts `iteratee` which is
|
16489 | * invoked for each element in `array` to generate the value to be summed.
|
16490 | * The iteratee is invoked with one argument: (value).
|
16491 | *
|
16492 | * @static
|
16493 | * @memberOf _
|
16494 | * @since 4.0.0
|
16495 | * @category Math
|
16496 | * @param {Array} array The array to iterate over.
|
16497 | * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
|
16498 | * @returns {number} Returns the sum.
|
16499 | * @example
|
16500 | *
|
16501 | * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
|
16502 | *
|
16503 | * _.sumBy(objects, function(o) { return o.n; });
|
16504 | * // => 20
|
16505 | *
|
16506 | * // The `_.property` iteratee shorthand.
|
16507 | * _.sumBy(objects, 'n');
|
16508 | * // => 20
|
16509 | */
|
16510 | function sumBy(array, iteratee) {
|
16511 | return (array && array.length)
|
16512 | ? baseSum(array, getIteratee(iteratee, 2))
|
16513 | : 0;
|
16514 | }
|
16515 |
|
16516 | /*------------------------------------------------------------------------*/
|
16517 |
|
16518 | // Add methods that return wrapped values in chain sequences.
|
16519 | lodash.after = after;
|
16520 | lodash.ary = ary;
|
16521 | lodash.assign = assign;
|
16522 | lodash.assignIn = assignIn;
|
16523 | lodash.assignInWith = assignInWith;
|
16524 | lodash.assignWith = assignWith;
|
16525 | lodash.at = at;
|
16526 | lodash.before = before;
|
16527 | lodash.bind = bind;
|
16528 | lodash.bindAll = bindAll;
|
16529 | lodash.bindKey = bindKey;
|
16530 | lodash.castArray = castArray;
|
16531 | lodash.chain = chain;
|
16532 | lodash.chunk = chunk;
|
16533 | lodash.compact = compact;
|
16534 | lodash.concat = concat;
|
16535 | lodash.cond = cond;
|
16536 | lodash.conforms = conforms;
|
16537 | lodash.constant = constant;
|
16538 | lodash.countBy = countBy;
|
16539 | lodash.create = create;
|
16540 | lodash.curry = curry;
|
16541 | lodash.curryRight = curryRight;
|
16542 | lodash.debounce = debounce;
|
16543 | lodash.defaults = defaults;
|
16544 | lodash.defaultsDeep = defaultsDeep;
|
16545 | lodash.defer = defer;
|
16546 | lodash.delay = delay;
|
16547 | lodash.difference = difference;
|
16548 | lodash.differenceBy = differenceBy;
|
16549 | lodash.differenceWith = differenceWith;
|
16550 | lodash.drop = drop;
|
16551 | lodash.dropRight = dropRight;
|
16552 | lodash.dropRightWhile = dropRightWhile;
|
16553 | lodash.dropWhile = dropWhile;
|
16554 | lodash.fill = fill;
|
16555 | lodash.filter = filter;
|
16556 | lodash.flatMap = flatMap;
|
16557 | lodash.flatMapDeep = flatMapDeep;
|
16558 | lodash.flatMapDepth = flatMapDepth;
|
16559 | lodash.flatten = flatten;
|
16560 | lodash.flattenDeep = flattenDeep;
|
16561 | lodash.flattenDepth = flattenDepth;
|
16562 | lodash.flip = flip;
|
16563 | lodash.flow = flow;
|
16564 | lodash.flowRight = flowRight;
|
16565 | lodash.fromPairs = fromPairs;
|
16566 | lodash.functions = functions;
|
16567 | lodash.functionsIn = functionsIn;
|
16568 | lodash.groupBy = groupBy;
|
16569 | lodash.initial = initial;
|
16570 | lodash.intersection = intersection;
|
16571 | lodash.intersectionBy = intersectionBy;
|
16572 | lodash.intersectionWith = intersectionWith;
|
16573 | lodash.invert = invert;
|
16574 | lodash.invertBy = invertBy;
|
16575 | lodash.invokeMap = invokeMap;
|
16576 | lodash.iteratee = iteratee;
|
16577 | lodash.keyBy = keyBy;
|
16578 | lodash.keys = keys;
|
16579 | lodash.keysIn = keysIn;
|
16580 | lodash.map = map;
|
16581 | lodash.mapKeys = mapKeys;
|
16582 | lodash.mapValues = mapValues;
|
16583 | lodash.matches = matches;
|
16584 | lodash.matchesProperty = matchesProperty;
|
16585 | lodash.memoize = memoize;
|
16586 | lodash.merge = merge;
|
16587 | lodash.mergeWith = mergeWith;
|
16588 | lodash.method = method;
|
16589 | lodash.methodOf = methodOf;
|
16590 | lodash.mixin = mixin;
|
16591 | lodash.negate = negate;
|
16592 | lodash.nthArg = nthArg;
|
16593 | lodash.omit = omit;
|
16594 | lodash.omitBy = omitBy;
|
16595 | lodash.once = once;
|
16596 | lodash.orderBy = orderBy;
|
16597 | lodash.over = over;
|
16598 | lodash.overArgs = overArgs;
|
16599 | lodash.overEvery = overEvery;
|
16600 | lodash.overSome = overSome;
|
16601 | lodash.partial = partial;
|
16602 | lodash.partialRight = partialRight;
|
16603 | lodash.partition = partition;
|
16604 | lodash.pick = pick;
|
16605 | lodash.pickBy = pickBy;
|
16606 | lodash.property = property;
|
16607 | lodash.propertyOf = propertyOf;
|
16608 | lodash.pull = pull;
|
16609 | lodash.pullAll = pullAll;
|
16610 | lodash.pullAllBy = pullAllBy;
|
16611 | lodash.pullAllWith = pullAllWith;
|
16612 | lodash.pullAt = pullAt;
|
16613 | lodash.range = range;
|
16614 | lodash.rangeRight = rangeRight;
|
16615 | lodash.rearg = rearg;
|
16616 | lodash.reject = reject;
|
16617 | lodash.remove = remove;
|
16618 | lodash.rest = rest;
|
16619 | lodash.reverse = reverse;
|
16620 | lodash.sampleSize = sampleSize;
|
16621 | lodash.set = set;
|
16622 | lodash.setWith = setWith;
|
16623 | lodash.shuffle = shuffle;
|
16624 | lodash.slice = slice;
|
16625 | lodash.sortBy = sortBy;
|
16626 | lodash.sortedUniq = sortedUniq;
|
16627 | lodash.sortedUniqBy = sortedUniqBy;
|
16628 | lodash.split = split;
|
16629 | lodash.spread = spread;
|
16630 | lodash.tail = tail;
|
16631 | lodash.take = take;
|
16632 | lodash.takeRight = takeRight;
|
16633 | lodash.takeRightWhile = takeRightWhile;
|
16634 | lodash.takeWhile = takeWhile;
|
16635 | lodash.tap = tap;
|
16636 | lodash.throttle = throttle;
|
16637 | lodash.thru = thru;
|
16638 | lodash.toArray = toArray;
|
16639 | lodash.toPairs = toPairs;
|
16640 | lodash.toPairsIn = toPairsIn;
|
16641 | lodash.toPath = toPath;
|
16642 | lodash.toPlainObject = toPlainObject;
|
16643 | lodash.transform = transform;
|
16644 | lodash.unary = unary;
|
16645 | lodash.union = union;
|
16646 | lodash.unionBy = unionBy;
|
16647 | lodash.unionWith = unionWith;
|
16648 | lodash.uniq = uniq;
|
16649 | lodash.uniqBy = uniqBy;
|
16650 | lodash.uniqWith = uniqWith;
|
16651 | lodash.unset = unset;
|
16652 | lodash.unzip = unzip;
|
16653 | lodash.unzipWith = unzipWith;
|
16654 | lodash.update = update;
|
16655 | lodash.updateWith = updateWith;
|
16656 | lodash.values = values;
|
16657 | lodash.valuesIn = valuesIn;
|
16658 | lodash.without = without;
|
16659 | lodash.words = words;
|
16660 | lodash.wrap = wrap;
|
16661 | lodash.xor = xor;
|
16662 | lodash.xorBy = xorBy;
|
16663 | lodash.xorWith = xorWith;
|
16664 | lodash.zip = zip;
|
16665 | lodash.zipObject = zipObject;
|
16666 | lodash.zipObjectDeep = zipObjectDeep;
|
16667 | lodash.zipWith = zipWith;
|
16668 |
|
16669 | // Add aliases.
|
16670 | lodash.entries = toPairs;
|
16671 | lodash.entriesIn = toPairsIn;
|
16672 | lodash.extend = assignIn;
|
16673 | lodash.extendWith = assignInWith;
|
16674 |
|
16675 | // Add methods to `lodash.prototype`.
|
16676 | mixin(lodash, lodash);
|
16677 |
|
16678 | /*------------------------------------------------------------------------*/
|
16679 |
|
16680 | // Add methods that return unwrapped values in chain sequences.
|
16681 | lodash.add = add;
|
16682 | lodash.attempt = attempt;
|
16683 | lodash.camelCase = camelCase;
|
16684 | lodash.capitalize = capitalize;
|
16685 | lodash.ceil = ceil;
|
16686 | lodash.clamp = clamp;
|
16687 | lodash.clone = clone;
|
16688 | lodash.cloneDeep = cloneDeep;
|
16689 | lodash.cloneDeepWith = cloneDeepWith;
|
16690 | lodash.cloneWith = cloneWith;
|
16691 | lodash.conformsTo = conformsTo;
|
16692 | lodash.deburr = deburr;
|
16693 | lodash.defaultTo = defaultTo;
|
16694 | lodash.divide = divide;
|
16695 | lodash.endsWith = endsWith;
|
16696 | lodash.eq = eq;
|
16697 | lodash.escape = escape;
|
16698 | lodash.escapeRegExp = escapeRegExp;
|
16699 | lodash.every = every;
|
16700 | lodash.find = find;
|
16701 | lodash.findIndex = findIndex;
|
16702 | lodash.findKey = findKey;
|
16703 | lodash.findLast = findLast;
|
16704 | lodash.findLastIndex = findLastIndex;
|
16705 | lodash.findLastKey = findLastKey;
|
16706 | lodash.floor = floor;
|
16707 | lodash.forEach = forEach;
|
16708 | lodash.forEachRight = forEachRight;
|
16709 | lodash.forIn = forIn;
|
16710 | lodash.forInRight = forInRight;
|
16711 | lodash.forOwn = forOwn;
|
16712 | lodash.forOwnRight = forOwnRight;
|
16713 | lodash.get = get;
|
16714 | lodash.gt = gt;
|
16715 | lodash.gte = gte;
|
16716 | lodash.has = has;
|
16717 | lodash.hasIn = hasIn;
|
16718 | lodash.head = head;
|
16719 | lodash.identity = identity;
|
16720 | lodash.includes = includes;
|
16721 | lodash.indexOf = indexOf;
|
16722 | lodash.inRange = inRange;
|
16723 | lodash.invoke = invoke;
|
16724 | lodash.isArguments = isArguments;
|
16725 | lodash.isArray = isArray;
|
16726 | lodash.isArrayBuffer = isArrayBuffer;
|
16727 | lodash.isArrayLike = isArrayLike;
|
16728 | lodash.isArrayLikeObject = isArrayLikeObject;
|
16729 | lodash.isBoolean = isBoolean;
|
16730 | lodash.isBuffer = isBuffer;
|
16731 | lodash.isDate = isDate;
|
16732 | lodash.isElement = isElement;
|
16733 | lodash.isEmpty = isEmpty;
|
16734 | lodash.isEqual = isEqual;
|
16735 | lodash.isEqualWith = isEqualWith;
|
16736 | lodash.isError = isError;
|
16737 | lodash.isFinite = isFinite;
|
16738 | lodash.isFunction = isFunction;
|
16739 | lodash.isInteger = isInteger;
|
16740 | lodash.isLength = isLength;
|
16741 | lodash.isMap = isMap;
|
16742 | lodash.isMatch = isMatch;
|
16743 | lodash.isMatchWith = isMatchWith;
|
16744 | lodash.isNaN = isNaN;
|
16745 | lodash.isNative = isNative;
|
16746 | lodash.isNil = isNil;
|
16747 | lodash.isNull = isNull;
|
16748 | lodash.isNumber = isNumber;
|
16749 | lodash.isObject = isObject;
|
16750 | lodash.isObjectLike = isObjectLike;
|
16751 | lodash.isPlainObject = isPlainObject;
|
16752 | lodash.isRegExp = isRegExp;
|
16753 | lodash.isSafeInteger = isSafeInteger;
|
16754 | lodash.isSet = isSet;
|
16755 | lodash.isString = isString;
|
16756 | lodash.isSymbol = isSymbol;
|
16757 | lodash.isTypedArray = isTypedArray;
|
16758 | lodash.isUndefined = isUndefined;
|
16759 | lodash.isWeakMap = isWeakMap;
|
16760 | lodash.isWeakSet = isWeakSet;
|
16761 | lodash.join = join;
|
16762 | lodash.kebabCase = kebabCase;
|
16763 | lodash.last = last;
|
16764 | lodash.lastIndexOf = lastIndexOf;
|
16765 | lodash.lowerCase = lowerCase;
|
16766 | lodash.lowerFirst = lowerFirst;
|
16767 | lodash.lt = lt;
|
16768 | lodash.lte = lte;
|
16769 | lodash.max = max;
|
16770 | lodash.maxBy = maxBy;
|
16771 | lodash.mean = mean;
|
16772 | lodash.meanBy = meanBy;
|
16773 | lodash.min = min;
|
16774 | lodash.minBy = minBy;
|
16775 | lodash.stubArray = stubArray;
|
16776 | lodash.stubFalse = stubFalse;
|
16777 | lodash.stubObject = stubObject;
|
16778 | lodash.stubString = stubString;
|
16779 | lodash.stubTrue = stubTrue;
|
16780 | lodash.multiply = multiply;
|
16781 | lodash.nth = nth;
|
16782 | lodash.noConflict = noConflict;
|
16783 | lodash.noop = noop;
|
16784 | lodash.now = now;
|
16785 | lodash.pad = pad;
|
16786 | lodash.padEnd = padEnd;
|
16787 | lodash.padStart = padStart;
|
16788 | lodash.parseInt = parseInt;
|
16789 | lodash.random = random;
|
16790 | lodash.reduce = reduce;
|
16791 | lodash.reduceRight = reduceRight;
|
16792 | lodash.repeat = repeat;
|
16793 | lodash.replace = replace;
|
16794 | lodash.result = result;
|
16795 | lodash.round = round;
|
16796 | lodash.runInContext = runInContext;
|
16797 | lodash.sample = sample;
|
16798 | lodash.size = size;
|
16799 | lodash.snakeCase = snakeCase;
|
16800 | lodash.some = some;
|
16801 | lodash.sortedIndex = sortedIndex;
|
16802 | lodash.sortedIndexBy = sortedIndexBy;
|
16803 | lodash.sortedIndexOf = sortedIndexOf;
|
16804 | lodash.sortedLastIndex = sortedLastIndex;
|
16805 | lodash.sortedLastIndexBy = sortedLastIndexBy;
|
16806 | lodash.sortedLastIndexOf = sortedLastIndexOf;
|
16807 | lodash.startCase = startCase;
|
16808 | lodash.startsWith = startsWith;
|
16809 | lodash.subtract = subtract;
|
16810 | lodash.sum = sum;
|
16811 | lodash.sumBy = sumBy;
|
16812 | lodash.template = template;
|
16813 | lodash.times = times;
|
16814 | lodash.toFinite = toFinite;
|
16815 | lodash.toInteger = toInteger;
|
16816 | lodash.toLength = toLength;
|
16817 | lodash.toLower = toLower;
|
16818 | lodash.toNumber = toNumber;
|
16819 | lodash.toSafeInteger = toSafeInteger;
|
16820 | lodash.toString = toString;
|
16821 | lodash.toUpper = toUpper;
|
16822 | lodash.trim = trim;
|
16823 | lodash.trimEnd = trimEnd;
|
16824 | lodash.trimStart = trimStart;
|
16825 | lodash.truncate = truncate;
|
16826 | lodash.unescape = unescape;
|
16827 | lodash.uniqueId = uniqueId;
|
16828 | lodash.upperCase = upperCase;
|
16829 | lodash.upperFirst = upperFirst;
|
16830 |
|
16831 | // Add aliases.
|
16832 | lodash.each = forEach;
|
16833 | lodash.eachRight = forEachRight;
|
16834 | lodash.first = head;
|
16835 |
|
16836 | mixin(lodash, (function() {
|
16837 | var source = {};
|
16838 | baseForOwn(lodash, function(func, methodName) {
|
16839 | if (!hasOwnProperty.call(lodash.prototype, methodName)) {
|
16840 | source[methodName] = func;
|
16841 | }
|
16842 | });
|
16843 | return source;
|
16844 | }()), { 'chain': false });
|
16845 |
|
16846 | /*------------------------------------------------------------------------*/
|
16847 |
|
16848 | /**
|
16849 | * The semantic version number.
|
16850 | *
|
16851 | * @static
|
16852 | * @memberOf _
|
16853 | * @type {string}
|
16854 | */
|
16855 | lodash.VERSION = VERSION;
|
16856 |
|
16857 | // Assign default placeholders.
|
16858 | arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
|
16859 | lodash[methodName].placeholder = lodash;
|
16860 | });
|
16861 |
|
16862 | // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
|
16863 | arrayEach(['drop', 'take'], function(methodName, index) {
|
16864 | LazyWrapper.prototype[methodName] = function(n) {
|
16865 | n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
|
16866 |
|
16867 | var result = (this.__filtered__ && !index)
|
16868 | ? new LazyWrapper(this)
|
16869 | : this.clone();
|
16870 |
|
16871 | if (result.__filtered__) {
|
16872 | result.__takeCount__ = nativeMin(n, result.__takeCount__);
|
16873 | } else {
|
16874 | result.__views__.push({
|
16875 | 'size': nativeMin(n, MAX_ARRAY_LENGTH),
|
16876 | 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
|
16877 | });
|
16878 | }
|
16879 | return result;
|
16880 | };
|
16881 |
|
16882 | LazyWrapper.prototype[methodName + 'Right'] = function(n) {
|
16883 | return this.reverse()[methodName](n).reverse();
|
16884 | };
|
16885 | });
|
16886 |
|
16887 | // Add `LazyWrapper` methods that accept an `iteratee` value.
|
16888 | arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
|
16889 | var type = index + 1,
|
16890 | isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
|
16891 |
|
16892 | LazyWrapper.prototype[methodName] = function(iteratee) {
|
16893 | var result = this.clone();
|
16894 | result.__iteratees__.push({
|
16895 | 'iteratee': getIteratee(iteratee, 3),
|
16896 | 'type': type
|
16897 | });
|
16898 | result.__filtered__ = result.__filtered__ || isFilter;
|
16899 | return result;
|
16900 | };
|
16901 | });
|
16902 |
|
16903 | // Add `LazyWrapper` methods for `_.head` and `_.last`.
|
16904 | arrayEach(['head', 'last'], function(methodName, index) {
|
16905 | var takeName = 'take' + (index ? 'Right' : '');
|
16906 |
|
16907 | LazyWrapper.prototype[methodName] = function() {
|
16908 | return this[takeName](1).value()[0];
|
16909 | };
|
16910 | });
|
16911 |
|
16912 | // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
|
16913 | arrayEach(['initial', 'tail'], function(methodName, index) {
|
16914 | var dropName = 'drop' + (index ? '' : 'Right');
|
16915 |
|
16916 | LazyWrapper.prototype[methodName] = function() {
|
16917 | return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
|
16918 | };
|
16919 | });
|
16920 |
|
16921 | LazyWrapper.prototype.compact = function() {
|
16922 | return this.filter(identity);
|
16923 | };
|
16924 |
|
16925 | LazyWrapper.prototype.find = function(predicate) {
|
16926 | return this.filter(predicate).head();
|
16927 | };
|
16928 |
|
16929 | LazyWrapper.prototype.findLast = function(predicate) {
|
16930 | return this.reverse().find(predicate);
|
16931 | };
|
16932 |
|
16933 | LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
|
16934 | if (typeof path == 'function') {
|
16935 | return new LazyWrapper(this);
|
16936 | }
|
16937 | return this.map(function(value) {
|
16938 | return baseInvoke(value, path, args);
|
16939 | });
|
16940 | });
|
16941 |
|
16942 | LazyWrapper.prototype.reject = function(predicate) {
|
16943 | return this.filter(negate(getIteratee(predicate)));
|
16944 | };
|
16945 |
|
16946 | LazyWrapper.prototype.slice = function(start, end) {
|
16947 | start = toInteger(start);
|
16948 |
|
16949 | var result = this;
|
16950 | if (result.__filtered__ && (start > 0 || end < 0)) {
|
16951 | return new LazyWrapper(result);
|
16952 | }
|
16953 | if (start < 0) {
|
16954 | result = result.takeRight(-start);
|
16955 | } else if (start) {
|
16956 | result = result.drop(start);
|
16957 | }
|
16958 | if (end !== undefined) {
|
16959 | end = toInteger(end);
|
16960 | result = end < 0 ? result.dropRight(-end) : result.take(end - start);
|
16961 | }
|
16962 | return result;
|
16963 | };
|
16964 |
|
16965 | LazyWrapper.prototype.takeRightWhile = function(predicate) {
|
16966 | return this.reverse().takeWhile(predicate).reverse();
|
16967 | };
|
16968 |
|
16969 | LazyWrapper.prototype.toArray = function() {
|
16970 | return this.take(MAX_ARRAY_LENGTH);
|
16971 | };
|
16972 |
|
16973 | // Add `LazyWrapper` methods to `lodash.prototype`.
|
16974 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
16975 | var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
|
16976 | isTaker = /^(?:head|last)$/.test(methodName),
|
16977 | lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
|
16978 | retUnwrapped = isTaker || /^find/.test(methodName);
|
16979 |
|
16980 | if (!lodashFunc) {
|
16981 | return;
|
16982 | }
|
16983 | lodash.prototype[methodName] = function() {
|
16984 | var value = this.__wrapped__,
|
16985 | args = isTaker ? [1] : arguments,
|
16986 | isLazy = value instanceof LazyWrapper,
|
16987 | iteratee = args[0],
|
16988 | useLazy = isLazy || isArray(value);
|
16989 |
|
16990 | var interceptor = function(value) {
|
16991 | var result = lodashFunc.apply(lodash, arrayPush([value], args));
|
16992 | return (isTaker && chainAll) ? result[0] : result;
|
16993 | };
|
16994 |
|
16995 | if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
|
16996 | // Avoid lazy use if the iteratee has a "length" value other than `1`.
|
16997 | isLazy = useLazy = false;
|
16998 | }
|
16999 | var chainAll = this.__chain__,
|
17000 | isHybrid = !!this.__actions__.length,
|
17001 | isUnwrapped = retUnwrapped && !chainAll,
|
17002 | onlyLazy = isLazy && !isHybrid;
|
17003 |
|
17004 | if (!retUnwrapped && useLazy) {
|
17005 | value = onlyLazy ? value : new LazyWrapper(this);
|
17006 | var result = func.apply(value, args);
|
17007 | result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
|
17008 | return new LodashWrapper(result, chainAll);
|
17009 | }
|
17010 | if (isUnwrapped && onlyLazy) {
|
17011 | return func.apply(this, args);
|
17012 | }
|
17013 | result = this.thru(interceptor);
|
17014 | return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
|
17015 | };
|
17016 | });
|
17017 |
|
17018 | // Add `Array` methods to `lodash.prototype`.
|
17019 | arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
|
17020 | var func = arrayProto[methodName],
|
17021 | chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
|
17022 | retUnwrapped = /^(?:pop|shift)$/.test(methodName);
|
17023 |
|
17024 | lodash.prototype[methodName] = function() {
|
17025 | var args = arguments;
|
17026 | if (retUnwrapped && !this.__chain__) {
|
17027 | var value = this.value();
|
17028 | return func.apply(isArray(value) ? value : [], args);
|
17029 | }
|
17030 | return this[chainName](function(value) {
|
17031 | return func.apply(isArray(value) ? value : [], args);
|
17032 | });
|
17033 | };
|
17034 | });
|
17035 |
|
17036 | // Map minified method names to their real names.
|
17037 | baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
17038 | var lodashFunc = lodash[methodName];
|
17039 | if (lodashFunc) {
|
17040 | var key = (lodashFunc.name + ''),
|
17041 | names = realNames[key] || (realNames[key] = []);
|
17042 |
|
17043 | names.push({ 'name': methodName, 'func': lodashFunc });
|
17044 | }
|
17045 | });
|
17046 |
|
17047 | realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
|
17048 | 'name': 'wrapper',
|
17049 | 'func': undefined
|
17050 | }];
|
17051 |
|
17052 | // Add methods to `LazyWrapper`.
|
17053 | LazyWrapper.prototype.clone = lazyClone;
|
17054 | LazyWrapper.prototype.reverse = lazyReverse;
|
17055 | LazyWrapper.prototype.value = lazyValue;
|
17056 |
|
17057 | // Add chain sequence methods to the `lodash` wrapper.
|
17058 | lodash.prototype.at = wrapperAt;
|
17059 | lodash.prototype.chain = wrapperChain;
|
17060 | lodash.prototype.commit = wrapperCommit;
|
17061 | lodash.prototype.next = wrapperNext;
|
17062 | lodash.prototype.plant = wrapperPlant;
|
17063 | lodash.prototype.reverse = wrapperReverse;
|
17064 | lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
17065 |
|
17066 | // Add lazy aliases.
|
17067 | lodash.prototype.first = lodash.prototype.head;
|
17068 |
|
17069 | if (symIterator) {
|
17070 | lodash.prototype[symIterator] = wrapperToIterator;
|
17071 | }
|
17072 | return lodash;
|
17073 | });
|
17074 |
|
17075 | /*--------------------------------------------------------------------------*/
|
17076 |
|
17077 | // Export lodash.
|
17078 | var _ = runInContext();
|
17079 |
|
17080 | // Some AMD build optimizers, like r.js, check for condition patterns like:
|
17081 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
17082 | // Expose Lodash on the global object to prevent errors when Lodash is
|
17083 | // loaded by a script tag in the presence of an AMD loader.
|
17084 | // See http://requirejs.org/docs/errors.html#mismatch for more details.
|
17085 | // Use `_.noConflict` to remove Lodash from the global object.
|
17086 | root._ = _;
|
17087 |
|
17088 | // Define as an anonymous module so, through path mapping, it can be
|
17089 | // referenced as the "underscore" module.
|
17090 | define(function() {
|
17091 | return _;
|
17092 | });
|
17093 | }
|
17094 | // Check for `exports` after `define` in case a build optimizer adds it.
|
17095 | else if (freeModule) {
|
17096 | // Export for Node.js.
|
17097 | (freeModule.exports = _)._ = _;
|
17098 | // Export for CommonJS support.
|
17099 | freeExports._ = _;
|
17100 | }
|
17101 | else {
|
17102 | // Export to the global object.
|
17103 | root._ = _;
|
17104 | }
|
17105 | }.call(this));
|