lodash-rails 3.10.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/lodash/rails/version.rb +1 -1
- data/vendor/assets/javascripts/lodash.core.js +3825 -0
- data/vendor/assets/javascripts/lodash.core.min.js +29 -0
- data/vendor/assets/javascripts/lodash.js +6595 -4547
- data/vendor/assets/javascripts/lodash.min.js +114 -95
- metadata +5 -5
- data/vendor/assets/javascripts/lodash.compat.js +0 -12557
- data/vendor/assets/javascripts/lodash.compat.min.js +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c383062767b34d64f945f014565aafc07f2344a0
|
4
|
+
data.tar.gz: 0f65a16f6a49c36ecf4fba3a7da5cee034c7d03e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa7c1c37e5a3090d081008695471c2055de443660dc3c78ded82f2809f68ddf42876074829abbc7a8af5ed5bf56aa0c9a1dc62ac4e88a3bf17986b9b6347694a
|
7
|
+
data.tar.gz: e07ce11e5abaa593e77620de344efa1e1f4253156f4f87046bc72318aa6a5f038ba7f47b04cae34655d8206b6a4b5452d4fabcac8dcec16df12723a21d46ba1e
|
data/README.md
CHANGED
@@ -18,11 +18,11 @@ Add the necessary library to `app/assets/javascripts/application.js`:
|
|
18
18
|
|
19
19
|
## What's included?
|
20
20
|
|
21
|
-
lodash
|
21
|
+
lodash 4.0.0:
|
22
22
|
|
23
|
+
* lodash.core.js
|
24
|
+
* lodash.core.min.js
|
23
25
|
* lodash.js
|
24
26
|
* lodash.min.js
|
25
|
-
* lodash.compat.js
|
26
|
-
* lodash.compat.min.js
|
27
27
|
|
28
28
|
Copyright Richard Hubers, released under the MIT License.
|
data/lib/lodash/rails/version.rb
CHANGED
@@ -0,0 +1,3825 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* lodash 4.0.0 (Custom Build) <https://lodash.com/>
|
4
|
+
* Build: `lodash core -o ./dist/lodash.core.js`
|
5
|
+
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
|
6
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
7
|
+
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
8
|
+
* Available under MIT license <https://lodash.com/license>
|
9
|
+
*/
|
10
|
+
;(function() {
|
11
|
+
|
12
|
+
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
13
|
+
var undefined;
|
14
|
+
|
15
|
+
/** Used as the semantic version number. */
|
16
|
+
var VERSION = '4.0.0';
|
17
|
+
|
18
|
+
/** Used to compose bitmasks for wrapper metadata. */
|
19
|
+
var BIND_FLAG = 1,
|
20
|
+
PARTIAL_FLAG = 32;
|
21
|
+
|
22
|
+
/** Used to compose bitmasks for comparison styles. */
|
23
|
+
var UNORDERED_COMPARE_FLAG = 1,
|
24
|
+
PARTIAL_COMPARE_FLAG = 2;
|
25
|
+
|
26
|
+
/** Used as the `TypeError` message for "Functions" methods. */
|
27
|
+
var FUNC_ERROR_TEXT = 'Expected a function';
|
28
|
+
|
29
|
+
/** Used as references for various `Number` constants. */
|
30
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
31
|
+
|
32
|
+
/** `Object#toString` result references. */
|
33
|
+
var argsTag = '[object Arguments]',
|
34
|
+
arrayTag = '[object Array]',
|
35
|
+
boolTag = '[object Boolean]',
|
36
|
+
dateTag = '[object Date]',
|
37
|
+
errorTag = '[object Error]',
|
38
|
+
funcTag = '[object Function]',
|
39
|
+
genTag = '[object GeneratorFunction]',
|
40
|
+
numberTag = '[object Number]',
|
41
|
+
objectTag = '[object Object]',
|
42
|
+
regexpTag = '[object RegExp]',
|
43
|
+
stringTag = '[object String]';
|
44
|
+
|
45
|
+
/** Used to match HTML entities and HTML characters. */
|
46
|
+
var reUnescapedHtml = /[&<>"'`]/g,
|
47
|
+
reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
48
|
+
|
49
|
+
/** Used to detect unsigned integer values. */
|
50
|
+
var reIsUint = /^(?:0|[1-9]\d*)$/;
|
51
|
+
|
52
|
+
/** Used to map characters to HTML entities. */
|
53
|
+
var htmlEscapes = {
|
54
|
+
'&': '&',
|
55
|
+
'<': '<',
|
56
|
+
'>': '>',
|
57
|
+
'"': '"',
|
58
|
+
"'": ''',
|
59
|
+
'`': '`'
|
60
|
+
};
|
61
|
+
|
62
|
+
/** Used to determine if values are of the language type `Object`. */
|
63
|
+
var objectTypes = {
|
64
|
+
'function': true,
|
65
|
+
'object': true
|
66
|
+
};
|
67
|
+
|
68
|
+
/** Detect free variable `exports`. */
|
69
|
+
var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) ? exports : null;
|
70
|
+
|
71
|
+
/** Detect free variable `module`. */
|
72
|
+
var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ? module : null;
|
73
|
+
|
74
|
+
/** Detect free variable `global` from Node.js. */
|
75
|
+
var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
|
76
|
+
|
77
|
+
/** Detect free variable `self`. */
|
78
|
+
var freeSelf = checkGlobal(objectTypes[typeof self] && self);
|
79
|
+
|
80
|
+
/** Detect free variable `window`. */
|
81
|
+
var freeWindow = checkGlobal(objectTypes[typeof window] && window);
|
82
|
+
|
83
|
+
/** Detect the popular CommonJS extension `module.exports`. */
|
84
|
+
var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeExports : null;
|
85
|
+
|
86
|
+
/** Detect `this` as the global object. */
|
87
|
+
var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Used as a reference to the global object.
|
91
|
+
*
|
92
|
+
* The `this` value is used if it's the global object to avoid Greasemonkey's
|
93
|
+
* restricted `window` object, otherwise the `window` object is used.
|
94
|
+
*/
|
95
|
+
var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || freeSelf || thisGlobal || Function('return this')();
|
96
|
+
|
97
|
+
/*--------------------------------------------------------------------------*/
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Creates a new array concatenating `array` with `other`.
|
101
|
+
*
|
102
|
+
* @private
|
103
|
+
* @param {Array} array The first array to concatenate.
|
104
|
+
* @param {Array} other The second array to concatenate.
|
105
|
+
* @returns {Array} Returns the new concatenated array.
|
106
|
+
*/
|
107
|
+
function arrayConcat(array, other) {
|
108
|
+
return arrayPush(copyArray(array), values);
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Appends the elements of `values` to `array`.
|
113
|
+
*
|
114
|
+
* @private
|
115
|
+
* @param {Array} array The array to modify.
|
116
|
+
* @param {Array} values The values to append.
|
117
|
+
* @returns {Array} Returns `array`.
|
118
|
+
*/
|
119
|
+
function arrayPush(array, values) {
|
120
|
+
var index = -1,
|
121
|
+
length = values.length,
|
122
|
+
offset = array.length;
|
123
|
+
|
124
|
+
while (++index < length) {
|
125
|
+
array[offset + index] = values[index];
|
126
|
+
}
|
127
|
+
return array;
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* The base implementation of methods like `_.max` and `_.min` which accepts a
|
132
|
+
* `comparator` to determine the extremum value.
|
133
|
+
*
|
134
|
+
* @private
|
135
|
+
* @param {Array} array The array to iterate over.
|
136
|
+
* @param {Function} iteratee The iteratee invoked per iteration.
|
137
|
+
* @param {Function} comparator The comparator used to compare values.
|
138
|
+
* @returns {*} Returns the extremum value.
|
139
|
+
*/
|
140
|
+
function baseExtremum(array, iteratee, comparator) {
|
141
|
+
var index = -1,
|
142
|
+
length = array.length;
|
143
|
+
|
144
|
+
while (++index < length) {
|
145
|
+
var value = array[index],
|
146
|
+
current = iteratee(value);
|
147
|
+
|
148
|
+
if (current != null && (computed === undefined
|
149
|
+
? current === current
|
150
|
+
: comparator(current, computed)
|
151
|
+
)) {
|
152
|
+
var computed = current,
|
153
|
+
result = value;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
return result;
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
* The base implementation of methods like `_.find` and `_.findKey`, without
|
161
|
+
* support for iteratee shorthands, which iterates over `collection` using
|
162
|
+
* the provided `eachFunc`.
|
163
|
+
*
|
164
|
+
* @private
|
165
|
+
* @param {Array|Object} collection The collection to search.
|
166
|
+
* @param {Function} predicate The function invoked per iteration.
|
167
|
+
* @param {Function} eachFunc The function to iterate over `collection`.
|
168
|
+
* @param {boolean} [retKey] Specify returning the key of the found element instead of the element itself.
|
169
|
+
* @returns {*} Returns the found element or its key, else `undefined`.
|
170
|
+
*/
|
171
|
+
function baseFind(collection, predicate, eachFunc, retKey) {
|
172
|
+
var result;
|
173
|
+
eachFunc(collection, function(value, key, collection) {
|
174
|
+
if (predicate(value, key, collection)) {
|
175
|
+
result = retKey ? key : value;
|
176
|
+
return false;
|
177
|
+
}
|
178
|
+
});
|
179
|
+
return result;
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* The base implementation of `_.reduce` and `_.reduceRight`, without support
|
184
|
+
* for iteratee shorthands, which iterates over `collection` using the provided
|
185
|
+
* `eachFunc`.
|
186
|
+
*
|
187
|
+
* @private
|
188
|
+
* @param {Array|Object} collection The collection to iterate over.
|
189
|
+
* @param {Function} iteratee The function invoked per iteration.
|
190
|
+
* @param {*} accumulator The initial value.
|
191
|
+
* @param {boolean} initFromCollection Specify using the first or last element of `collection` as the initial value.
|
192
|
+
* @param {Function} eachFunc The function to iterate over `collection`.
|
193
|
+
* @returns {*} Returns the accumulated value.
|
194
|
+
*/
|
195
|
+
function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
|
196
|
+
eachFunc(collection, function(value, index, collection) {
|
197
|
+
accumulator = initFromCollection
|
198
|
+
? (initFromCollection = false, value)
|
199
|
+
: iteratee(accumulator, value, index, collection);
|
200
|
+
});
|
201
|
+
return accumulator;
|
202
|
+
}
|
203
|
+
|
204
|
+
/**
|
205
|
+
* The base implementation of `_.times` without support for iteratee shorthands
|
206
|
+
* or max array length checks.
|
207
|
+
*
|
208
|
+
* @private
|
209
|
+
* @param {number} n The number of times to invoke `iteratee`.
|
210
|
+
* @param {Function} iteratee The function invoked per iteration.
|
211
|
+
* @returns {Array} Returns the array of results.
|
212
|
+
*/
|
213
|
+
function baseTimes(n, iteratee) {
|
214
|
+
var index = -1,
|
215
|
+
result = Array(n);
|
216
|
+
|
217
|
+
while (++index < n) {
|
218
|
+
result[index] = iteratee(index);
|
219
|
+
}
|
220
|
+
return result;
|
221
|
+
}
|
222
|
+
|
223
|
+
/**
|
224
|
+
* The base implementation of `_.values` and `_.valuesIn` which creates an
|
225
|
+
* array of `object` property values corresponding to the property names
|
226
|
+
* of `props`.
|
227
|
+
*
|
228
|
+
* @private
|
229
|
+
* @param {Object} object The object to query.
|
230
|
+
* @param {Array} props The property names to get values for.
|
231
|
+
* @returns {Object} Returns the array of property values.
|
232
|
+
*/
|
233
|
+
function baseValues(object, props) {
|
234
|
+
return baseMap(props, function(key) {
|
235
|
+
return object[key];
|
236
|
+
});
|
237
|
+
}
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Checks if `value` is a global object.
|
241
|
+
*
|
242
|
+
* @private
|
243
|
+
* @param {*} value The value to check.
|
244
|
+
* @returns {null|Object} Returns `value` if it's a global object, else `null`.
|
245
|
+
*/
|
246
|
+
function checkGlobal(value) {
|
247
|
+
return (value && value.Object === Object) ? value : null;
|
248
|
+
}
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Compares values to sort them in ascending order.
|
252
|
+
*
|
253
|
+
* @private
|
254
|
+
* @param {*} value The value to compare.
|
255
|
+
* @param {*} other The other value to compare.
|
256
|
+
* @returns {number} Returns the sort order indicator for `value`.
|
257
|
+
*/
|
258
|
+
function compareAscending(value, other) {
|
259
|
+
if (value !== other) {
|
260
|
+
var valIsNull = value === null,
|
261
|
+
valIsUndef = value === undefined,
|
262
|
+
valIsReflexive = value === value;
|
263
|
+
|
264
|
+
var othIsNull = other === null,
|
265
|
+
othIsUndef = other === undefined,
|
266
|
+
othIsReflexive = other === other;
|
267
|
+
|
268
|
+
if ((value > other && !othIsNull) || !valIsReflexive ||
|
269
|
+
(valIsNull && !othIsUndef && othIsReflexive) ||
|
270
|
+
(valIsUndef && othIsReflexive)) {
|
271
|
+
return 1;
|
272
|
+
}
|
273
|
+
if ((value < other && !valIsNull) || !othIsReflexive ||
|
274
|
+
(othIsNull && !valIsUndef && valIsReflexive) ||
|
275
|
+
(othIsUndef && valIsReflexive)) {
|
276
|
+
return -1;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
return 0;
|
280
|
+
}
|
281
|
+
|
282
|
+
/**
|
283
|
+
* Used by `_.escape` to convert characters to HTML entities.
|
284
|
+
*
|
285
|
+
* @private
|
286
|
+
* @param {string} chr The matched character to escape.
|
287
|
+
* @returns {string} Returns the escaped character.
|
288
|
+
*/
|
289
|
+
function escapeHtmlChar(chr) {
|
290
|
+
return htmlEscapes[chr];
|
291
|
+
}
|
292
|
+
|
293
|
+
/**
|
294
|
+
* Checks if `value` is a host object in IE < 9.
|
295
|
+
*
|
296
|
+
* @private
|
297
|
+
* @param {*} value The value to check.
|
298
|
+
* @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
299
|
+
*/
|
300
|
+
function isHostObject(value) {
|
301
|
+
// Many host objects are `Object` objects that can coerce to strings
|
302
|
+
// despite having improperly defined `toString` methods.
|
303
|
+
var result = false;
|
304
|
+
if (value != null && typeof value.toString != 'function') {
|
305
|
+
try {
|
306
|
+
result = !!(value + '');
|
307
|
+
} catch (e) {}
|
308
|
+
}
|
309
|
+
return result;
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Checks if `value` is a valid array-like index.
|
314
|
+
*
|
315
|
+
* @private
|
316
|
+
* @param {*} value The value to check.
|
317
|
+
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
318
|
+
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
319
|
+
*/
|
320
|
+
function isIndex(value, length) {
|
321
|
+
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
|
322
|
+
length = length == null ? MAX_SAFE_INTEGER : length;
|
323
|
+
return value > -1 && value % 1 == 0 && value < length;
|
324
|
+
}
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Converts `iterator` to an array.
|
328
|
+
*
|
329
|
+
* @private
|
330
|
+
* @param {Object} iterator The iterator to convert.
|
331
|
+
* @returns {Array} Returns the converted array.
|
332
|
+
*/
|
333
|
+
function iteratorToArray(iterator) {
|
334
|
+
var data,
|
335
|
+
result = [];
|
336
|
+
|
337
|
+
while (!(data = iterator.next()).done) {
|
338
|
+
result.push(data.value);
|
339
|
+
}
|
340
|
+
return result;
|
341
|
+
}
|
342
|
+
|
343
|
+
/*--------------------------------------------------------------------------*/
|
344
|
+
|
345
|
+
/** Used for built-in method references. */
|
346
|
+
var arrayProto = Array.prototype,
|
347
|
+
objectProto = Object.prototype;
|
348
|
+
|
349
|
+
/** Used to check objects for own properties. */
|
350
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
351
|
+
|
352
|
+
/** Used to generate unique IDs. */
|
353
|
+
var idCounter = 0;
|
354
|
+
|
355
|
+
/**
|
356
|
+
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
357
|
+
* of values.
|
358
|
+
*/
|
359
|
+
var objectToString = objectProto.toString;
|
360
|
+
|
361
|
+
/** Used to restore the original `_` reference in `_.noConflict`. */
|
362
|
+
var oldDash = root._;
|
363
|
+
|
364
|
+
/** Built-in value references. */
|
365
|
+
var _Symbol = root.Symbol,
|
366
|
+
Reflect = root.Reflect,
|
367
|
+
Uint8Array = root.Uint8Array,
|
368
|
+
enumerate = Reflect ? Reflect.enumerate : undefined,
|
369
|
+
propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
370
|
+
|
371
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */
|
372
|
+
var nativeIsFinite = root.isFinite,
|
373
|
+
nativeKeys = Object.keys,
|
374
|
+
nativeMax = Math.max;
|
375
|
+
|
376
|
+
/*------------------------------------------------------------------------*/
|
377
|
+
|
378
|
+
/**
|
379
|
+
* Creates a `lodash` object which wraps `value` to enable implicit method
|
380
|
+
* chaining. Methods that operate on and return arrays, collections, and
|
381
|
+
* functions can be chained together. Methods that retrieve a single value or
|
382
|
+
* may return a primitive value will automatically end the chain sequence and
|
383
|
+
* return the unwrapped value. Otherwise, the value must be unwrapped with
|
384
|
+
* `_#value`.
|
385
|
+
*
|
386
|
+
* Explicit chaining, which must be unwrapped with `_#value` in all cases,
|
387
|
+
* may be enabled using `_.chain`.
|
388
|
+
*
|
389
|
+
* The execution of chained methods is lazy, that is, it's deferred until
|
390
|
+
* `_#value` is implicitly or explicitly called.
|
391
|
+
*
|
392
|
+
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut
|
393
|
+
* fusion is an optimization to merge iteratee calls; this avoids the creation
|
394
|
+
* of intermediate arrays and can greatly reduce the number of iteratee executions.
|
395
|
+
* Sections of a chain sequence qualify for shortcut fusion if the section is
|
396
|
+
* applied to an array of at least two hundred elements and any iteratees
|
397
|
+
* accept only one argument. The heuristic for whether a section qualifies
|
398
|
+
* for shortcut fusion is subject to change.
|
399
|
+
*
|
400
|
+
* Chaining is supported in custom builds as long as the `_#value` method is
|
401
|
+
* directly or indirectly included in the build.
|
402
|
+
*
|
403
|
+
* In addition to lodash methods, wrappers have `Array` and `String` methods.
|
404
|
+
*
|
405
|
+
* The wrapper `Array` methods are:
|
406
|
+
* `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
|
407
|
+
*
|
408
|
+
* The wrapper `String` methods are:
|
409
|
+
* `replace` and `split`
|
410
|
+
*
|
411
|
+
* The wrapper methods that support shortcut fusion are:
|
412
|
+
* `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
|
413
|
+
* `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
|
414
|
+
* `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
|
415
|
+
*
|
416
|
+
* The chainable wrapper methods are:
|
417
|
+
* `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
|
418
|
+
* `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
|
419
|
+
* `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry`,
|
420
|
+
* `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
|
421
|
+
* `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
|
422
|
+
* `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
|
423
|
+
* `flowRight`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
|
424
|
+
* `forOwnRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initial`,
|
425
|
+
* `intersection`, `intersectionBy`, `intersectionWith`, invert`, `invokeMap`,
|
426
|
+
* `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
|
427
|
+
* `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
|
428
|
+
* `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `orderBy`,
|
429
|
+
* `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
|
430
|
+
* `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
|
431
|
+
* `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
|
432
|
+
* `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
|
433
|
+
* `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
|
434
|
+
* `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
|
435
|
+
* `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`,
|
436
|
+
* `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
|
437
|
+
* `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`,
|
438
|
+
* `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
|
439
|
+
*
|
440
|
+
* The wrapper methods that are **not** chainable by default are:
|
441
|
+
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
|
442
|
+
* `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
|
443
|
+
* `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
|
444
|
+
* `findLast`, `findLastIndex`, `findLastKey`, `floor`, `get`, `gt`, `gte`,
|
445
|
+
* `has`, `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`,
|
446
|
+
* `invoke`, `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`,
|
447
|
+
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
|
448
|
+
* `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`,
|
449
|
+
* `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
|
450
|
+
* `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
|
451
|
+
* `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`, `last`,
|
452
|
+
* `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`,
|
453
|
+
* `mean`, `min`, `minBy`, `noConflict`, `noop`, `now`, `pad`, `padEnd`,
|
454
|
+
* `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`,
|
455
|
+
* `result`, `round`, `runInContext`, `sample`, `shift`, `size`, `snakeCase`,
|
456
|
+
* `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`,
|
457
|
+
* `startCase`, `startsWith`, `subtract`, `sum`, sumBy`, `template`, `times`,
|
458
|
+
* `toLower`, `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, toString`,
|
459
|
+
* `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`,
|
460
|
+
* `upperCase`, `upperFirst`, `value`, and `words`
|
461
|
+
*
|
462
|
+
* @name _
|
463
|
+
* @constructor
|
464
|
+
* @category Seq
|
465
|
+
* @param {*} value The value to wrap in a `lodash` instance.
|
466
|
+
* @returns {Object} Returns the new `lodash` wrapper instance.
|
467
|
+
* @example
|
468
|
+
*
|
469
|
+
* function square(n) {
|
470
|
+
* return n * n;
|
471
|
+
* }
|
472
|
+
*
|
473
|
+
* var wrapped = _([1, 2, 3]);
|
474
|
+
*
|
475
|
+
* // returns an unwrapped value
|
476
|
+
* wrapped.reduce(_.add);
|
477
|
+
* // => 6
|
478
|
+
*
|
479
|
+
* // returns a wrapped value
|
480
|
+
* var squares = wrapped.map(square);
|
481
|
+
*
|
482
|
+
* _.isArray(squares);
|
483
|
+
* // => false
|
484
|
+
*
|
485
|
+
* _.isArray(squares.value());
|
486
|
+
* // => true
|
487
|
+
*/
|
488
|
+
function lodash(value) {
|
489
|
+
if (isObjectLike(value) && !isArray(value)) {
|
490
|
+
if (value instanceof LodashWrapper) {
|
491
|
+
return value;
|
492
|
+
}
|
493
|
+
if (hasOwnProperty.call(value, '__wrapped__')) {
|
494
|
+
return wrapperClone(value);
|
495
|
+
}
|
496
|
+
}
|
497
|
+
return new LodashWrapper(value);
|
498
|
+
}
|
499
|
+
|
500
|
+
/**
|
501
|
+
* The base constructor for creating `lodash` wrapper objects.
|
502
|
+
*
|
503
|
+
* @private
|
504
|
+
* @param {*} value The value to wrap.
|
505
|
+
* @param {boolean} [chainAll] Enable chaining for all wrapper methods.
|
506
|
+
*/
|
507
|
+
function LodashWrapper(value, chainAll) {
|
508
|
+
this.__wrapped__ = value;
|
509
|
+
this.__actions__ = [];
|
510
|
+
this.__chain__ = !!chainAll;
|
511
|
+
}
|
512
|
+
|
513
|
+
/*------------------------------------------------------------------------*/
|
514
|
+
|
515
|
+
/**
|
516
|
+
* Used by `_.defaults` to customize its `_.assignIn` use.
|
517
|
+
*
|
518
|
+
* @private
|
519
|
+
* @param {*} objValue The destination value.
|
520
|
+
* @param {*} srcValue The source value.
|
521
|
+
* @param {string} key The key of the property to assign.
|
522
|
+
* @param {Object} object The parent object of `objValue`.
|
523
|
+
* @returns {*} Returns the value to assign.
|
524
|
+
*/
|
525
|
+
function assignInDefaults(objValue, srcValue, key, object) {
|
526
|
+
if (objValue === undefined ||
|
527
|
+
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
|
528
|
+
return srcValue;
|
529
|
+
}
|
530
|
+
return objValue;
|
531
|
+
}
|
532
|
+
|
533
|
+
/**
|
534
|
+
* Assigns `value` to `key` of `object` if the existing value is not equivalent
|
535
|
+
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
536
|
+
* for equality comparisons.
|
537
|
+
*
|
538
|
+
* @private
|
539
|
+
* @param {Object} object The object to modify.
|
540
|
+
* @param {string} key The key of the property to assign.
|
541
|
+
* @param {*} value The value to assign.
|
542
|
+
*/
|
543
|
+
function assignValue(object, key, value) {
|
544
|
+
var objValue = object[key];
|
545
|
+
if ((!eq(objValue, value) ||
|
546
|
+
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
|
547
|
+
(value === undefined && !(key in object))) {
|
548
|
+
object[key] = value;
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
/**
|
553
|
+
* The base implementation of `_.create` without support for assigning
|
554
|
+
* properties to the created object.
|
555
|
+
*
|
556
|
+
* @private
|
557
|
+
* @param {Object} prototype The object to inherit from.
|
558
|
+
* @returns {Object} Returns the new object.
|
559
|
+
*/
|
560
|
+
var baseCreate = (function() {
|
561
|
+
function object() {}
|
562
|
+
return function(prototype) {
|
563
|
+
if (isObject(prototype)) {
|
564
|
+
object.prototype = prototype;
|
565
|
+
var result = new object;
|
566
|
+
object.prototype = undefined;
|
567
|
+
}
|
568
|
+
return result || {};
|
569
|
+
};
|
570
|
+
}());
|
571
|
+
|
572
|
+
/**
|
573
|
+
* The base implementation of `_.delay` and `_.defer` which accepts an array
|
574
|
+
* of `func` arguments.
|
575
|
+
*
|
576
|
+
* @private
|
577
|
+
* @param {Function} func The function to delay.
|
578
|
+
* @param {number} wait The number of milliseconds to delay invocation.
|
579
|
+
* @param {Object} args The arguments provide to `func`.
|
580
|
+
* @returns {number} Returns the timer id.
|
581
|
+
*/
|
582
|
+
function baseDelay(func, wait, args) {
|
583
|
+
if (typeof func != 'function') {
|
584
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
585
|
+
}
|
586
|
+
return setTimeout(function() { func.apply(undefined, args); }, wait);
|
587
|
+
}
|
588
|
+
|
589
|
+
/**
|
590
|
+
* The base implementation of `_.forEach` without support for iteratee shorthands.
|
591
|
+
*
|
592
|
+
* @private
|
593
|
+
* @param {Array|Object} collection The collection to iterate over.
|
594
|
+
* @param {Function} iteratee The function invoked per iteration.
|
595
|
+
* @returns {Array|Object} Returns `collection`.
|
596
|
+
*/
|
597
|
+
var baseEach = createBaseEach(baseForOwn);
|
598
|
+
|
599
|
+
/**
|
600
|
+
* The base implementation of `_.every` without support for iteratee shorthands.
|
601
|
+
*
|
602
|
+
* @private
|
603
|
+
* @param {Array|Object} collection The collection to iterate over.
|
604
|
+
* @param {Function} predicate The function invoked per iteration.
|
605
|
+
* @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`
|
606
|
+
*/
|
607
|
+
function baseEvery(collection, predicate) {
|
608
|
+
var result = true;
|
609
|
+
baseEach(collection, function(value, index, collection) {
|
610
|
+
result = !!predicate(value, index, collection);
|
611
|
+
return result;
|
612
|
+
});
|
613
|
+
return result;
|
614
|
+
}
|
615
|
+
|
616
|
+
/**
|
617
|
+
* The base implementation of `_.filter` without support for iteratee shorthands.
|
618
|
+
*
|
619
|
+
* @private
|
620
|
+
* @param {Array|Object} collection The collection to iterate over.
|
621
|
+
* @param {Function} predicate The function invoked per iteration.
|
622
|
+
* @returns {Array} Returns the new filtered array.
|
623
|
+
*/
|
624
|
+
function baseFilter(collection, predicate) {
|
625
|
+
var result = [];
|
626
|
+
baseEach(collection, function(value, index, collection) {
|
627
|
+
if (predicate(value, index, collection)) {
|
628
|
+
result.push(value);
|
629
|
+
}
|
630
|
+
});
|
631
|
+
return result;
|
632
|
+
}
|
633
|
+
|
634
|
+
/**
|
635
|
+
* The base implementation of `_.flatten` with support for restricting flattening.
|
636
|
+
*
|
637
|
+
* @private
|
638
|
+
* @param {Array} array The array to flatten.
|
639
|
+
* @param {boolean} [isDeep] Specify a deep flatten.
|
640
|
+
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
|
641
|
+
* @param {Array} [result=[]] The initial result value.
|
642
|
+
* @returns {Array} Returns the new flattened array.
|
643
|
+
*/
|
644
|
+
function baseFlatten(array, isDeep, isStrict, result) {
|
645
|
+
result || (result = []);
|
646
|
+
|
647
|
+
var index = -1,
|
648
|
+
length = array.length;
|
649
|
+
|
650
|
+
while (++index < length) {
|
651
|
+
var value = array[index];
|
652
|
+
if (isArrayLikeObject(value) &&
|
653
|
+
(isStrict || isArray(value) || isArguments(value))) {
|
654
|
+
if (isDeep) {
|
655
|
+
// Recursively flatten arrays (susceptible to call stack limits).
|
656
|
+
baseFlatten(value, isDeep, isStrict, result);
|
657
|
+
} else {
|
658
|
+
arrayPush(result, value);
|
659
|
+
}
|
660
|
+
} else if (!isStrict) {
|
661
|
+
result[result.length] = value;
|
662
|
+
}
|
663
|
+
}
|
664
|
+
return result;
|
665
|
+
}
|
666
|
+
|
667
|
+
/**
|
668
|
+
* The base implementation of `baseForIn` and `baseForOwn` which iterates
|
669
|
+
* over `object` properties returned by `keysFunc` invoking `iteratee` for
|
670
|
+
* each property. Iteratee functions may exit iteration early by explicitly
|
671
|
+
* returning `false`.
|
672
|
+
*
|
673
|
+
* @private
|
674
|
+
* @param {Object} object The object to iterate over.
|
675
|
+
* @param {Function} iteratee The function invoked per iteration.
|
676
|
+
* @param {Function} keysFunc The function to get the keys of `object`.
|
677
|
+
* @returns {Object} Returns `object`.
|
678
|
+
*/
|
679
|
+
var baseFor = createBaseFor();
|
680
|
+
|
681
|
+
/**
|
682
|
+
* The base implementation of `_.forOwn` without support for iteratee shorthands.
|
683
|
+
*
|
684
|
+
* @private
|
685
|
+
* @param {Object} object The object to iterate over.
|
686
|
+
* @param {Function} iteratee The function invoked per iteration.
|
687
|
+
* @returns {Object} Returns `object`.
|
688
|
+
*/
|
689
|
+
function baseForOwn(object, iteratee) {
|
690
|
+
return object && baseFor(object, iteratee, keys);
|
691
|
+
}
|
692
|
+
|
693
|
+
/**
|
694
|
+
* The base implementation of `_.functions` which creates an array of
|
695
|
+
* `object` function property names filtered from those provided.
|
696
|
+
*
|
697
|
+
* @private
|
698
|
+
* @param {Object} object The object to inspect.
|
699
|
+
* @param {Array} props The property names to filter.
|
700
|
+
* @returns {Array} Returns the new array of filtered property names.
|
701
|
+
*/
|
702
|
+
function baseFunctions(object, props) {
|
703
|
+
return baseFilter(props, function(key) {
|
704
|
+
return isFunction(object[key]);
|
705
|
+
});
|
706
|
+
}
|
707
|
+
|
708
|
+
/**
|
709
|
+
* The base implementation of `_.isEqual` which supports partial comparisons
|
710
|
+
* and tracks traversed objects.
|
711
|
+
*
|
712
|
+
* @private
|
713
|
+
* @param {*} value The value to compare.
|
714
|
+
* @param {*} other The other value to compare.
|
715
|
+
* @param {Function} [customizer] The function to customize comparisons.
|
716
|
+
* @param {boolean} [bitmask] The bitmask of comparison flags.
|
717
|
+
* The bitmask may be composed of the following flags:
|
718
|
+
* 1 - Unordered comparison
|
719
|
+
* 2 - Partial comparison
|
720
|
+
* @param {Object} [stack] Tracks traversed `value` and `other` objects.
|
721
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
722
|
+
*/
|
723
|
+
function baseIsEqual(value, other, customizer, bitmask, stack) {
|
724
|
+
if (value === other) {
|
725
|
+
return true;
|
726
|
+
}
|
727
|
+
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
|
728
|
+
return value !== value && other !== other;
|
729
|
+
}
|
730
|
+
return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
|
731
|
+
}
|
732
|
+
|
733
|
+
/**
|
734
|
+
* A specialized version of `baseIsEqual` for arrays and objects which performs
|
735
|
+
* deep comparisons and tracks traversed objects enabling objects with circular
|
736
|
+
* references to be compared.
|
737
|
+
*
|
738
|
+
* @private
|
739
|
+
* @param {Object} object The object to compare.
|
740
|
+
* @param {Object} other The other object to compare.
|
741
|
+
* @param {Function} equalFunc The function to determine equivalents of values.
|
742
|
+
* @param {Function} [customizer] The function to customize comparisons.
|
743
|
+
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
|
744
|
+
* @param {Object} [stack] Tracks traversed `object` and `other` objects.
|
745
|
+
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
746
|
+
*/
|
747
|
+
function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
|
748
|
+
var objIsArr = isArray(object),
|
749
|
+
othIsArr = isArray(other),
|
750
|
+
objTag = arrayTag,
|
751
|
+
othTag = arrayTag;
|
752
|
+
|
753
|
+
if (!objIsArr) {
|
754
|
+
objTag = objectToString.call(object);
|
755
|
+
if (objTag == argsTag) {
|
756
|
+
objTag = objectTag;
|
757
|
+
}
|
758
|
+
}
|
759
|
+
if (!othIsArr) {
|
760
|
+
othTag = objectToString.call(other);
|
761
|
+
if (othTag == argsTag) {
|
762
|
+
othTag = objectTag;
|
763
|
+
}
|
764
|
+
}
|
765
|
+
var objIsObj = objTag == objectTag && !isHostObject(object),
|
766
|
+
othIsObj = othTag == objectTag && !isHostObject(other),
|
767
|
+
isSameTag = objTag == othTag;
|
768
|
+
|
769
|
+
if (isSameTag && !(objIsArr || objIsObj)) {
|
770
|
+
return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
|
771
|
+
}
|
772
|
+
var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
|
773
|
+
if (!isPartial) {
|
774
|
+
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
775
|
+
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
776
|
+
|
777
|
+
if (objIsWrapped || othIsWrapped) {
|
778
|
+
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
|
779
|
+
}
|
780
|
+
}
|
781
|
+
if (!isSameTag) {
|
782
|
+
return false;
|
783
|
+
}
|
784
|
+
stack || (stack = []);
|
785
|
+
var stacked = find(stack, function(entry) {
|
786
|
+
return entry[0] === object;
|
787
|
+
});
|
788
|
+
if (stacked && stacked[1]) {
|
789
|
+
return stacked[1] == other;
|
790
|
+
}
|
791
|
+
stack.push([object, other]);
|
792
|
+
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
|
793
|
+
stack.pop();
|
794
|
+
return result;
|
795
|
+
}
|
796
|
+
|
797
|
+
/**
|
798
|
+
* The base implementation of `_.iteratee`.
|
799
|
+
*
|
800
|
+
* @private
|
801
|
+
* @param {*} [value=_.identity] The value to convert to an iteratee.
|
802
|
+
* @returns {Function} Returns the iteratee.
|
803
|
+
*/
|
804
|
+
function baseIteratee(func) {
|
805
|
+
var type = typeof func;
|
806
|
+
if (type == 'function') {
|
807
|
+
return func;
|
808
|
+
}
|
809
|
+
return func == null
|
810
|
+
? identity
|
811
|
+
: (type == 'object' ? baseMatches : baseProperty)(func);
|
812
|
+
}
|
813
|
+
|
814
|
+
/**
|
815
|
+
* The base implementation of `_.keys` which doesn't skip the constructor
|
816
|
+
* property of prototypes or treat sparse arrays as dense.
|
817
|
+
*
|
818
|
+
* @private
|
819
|
+
* @type Function
|
820
|
+
* @param {Object} object The object to query.
|
821
|
+
* @returns {Array} Returns the array of property names.
|
822
|
+
*/
|
823
|
+
function baseKeys(object) {
|
824
|
+
return nativeKeys(Object(object));
|
825
|
+
}
|
826
|
+
|
827
|
+
/**
|
828
|
+
* The base implementation of `_.keysIn` which doesn't skip the constructor
|
829
|
+
* property of prototypes or treat sparse arrays as dense.
|
830
|
+
*
|
831
|
+
* @private
|
832
|
+
* @param {Object} object The object to query.
|
833
|
+
* @returns {Array} Returns the array of property names.
|
834
|
+
*/
|
835
|
+
function baseKeysIn(object) {
|
836
|
+
object = object == null ? object : Object(object);
|
837
|
+
|
838
|
+
var result = [];
|
839
|
+
for (var key in object) {
|
840
|
+
result.push(key);
|
841
|
+
}
|
842
|
+
return result;
|
843
|
+
}
|
844
|
+
|
845
|
+
// Fallback for IE < 9 with es6-shim.
|
846
|
+
if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
|
847
|
+
baseKeysIn = function(object) {
|
848
|
+
return iteratorToArray(enumerate(object));
|
849
|
+
};
|
850
|
+
}
|
851
|
+
|
852
|
+
/**
|
853
|
+
* The base implementation of `_.map` without support for iteratee shorthands.
|
854
|
+
*
|
855
|
+
* @private
|
856
|
+
* @param {Array|Object} collection The collection to iterate over.
|
857
|
+
* @param {Function} iteratee The function invoked per iteration.
|
858
|
+
* @returns {Array} Returns the new mapped array.
|
859
|
+
*/
|
860
|
+
function baseMap(collection, iteratee) {
|
861
|
+
var index = -1,
|
862
|
+
result = isArrayLike(collection) ? Array(collection.length) : [];
|
863
|
+
|
864
|
+
baseEach(collection, function(value, key, collection) {
|
865
|
+
result[++index] = iteratee(value, key, collection);
|
866
|
+
});
|
867
|
+
return result;
|
868
|
+
}
|
869
|
+
|
870
|
+
/**
|
871
|
+
* The base implementation of `_.matches` which doesn't clone `source`.
|
872
|
+
*
|
873
|
+
* @private
|
874
|
+
* @param {Object} source The object of property values to match.
|
875
|
+
* @returns {Function} Returns the new function.
|
876
|
+
*/
|
877
|
+
function baseMatches(source) {
|
878
|
+
var props = keys(source),
|
879
|
+
length = props.length;
|
880
|
+
|
881
|
+
return function(object) {
|
882
|
+
if (object == null) {
|
883
|
+
return !length;
|
884
|
+
}
|
885
|
+
object = Object(object);
|
886
|
+
while (length--) {
|
887
|
+
var key = props[length];
|
888
|
+
if (!(key in object && baseIsEqual(source[key], object[key], undefined, true))) {
|
889
|
+
return false;
|
890
|
+
}
|
891
|
+
}
|
892
|
+
return true;
|
893
|
+
};
|
894
|
+
}
|
895
|
+
|
896
|
+
/**
|
897
|
+
* The base implementation of `_.pick` without support for individual
|
898
|
+
* property names.
|
899
|
+
*
|
900
|
+
* @private
|
901
|
+
* @param {Object} object The source object.
|
902
|
+
* @param {string[]} props The property names to pick.
|
903
|
+
* @returns {Object} Returns the new object.
|
904
|
+
*/
|
905
|
+
function basePick(object, props) {
|
906
|
+
object = Object(object);
|
907
|
+
return reduce(props, function(result, key) {
|
908
|
+
if (key in object) {
|
909
|
+
result[key] = object[key];
|
910
|
+
}
|
911
|
+
return result;
|
912
|
+
}, {});
|
913
|
+
}
|
914
|
+
|
915
|
+
/**
|
916
|
+
* The base implementation of `_.property` without support for deep paths.
|
917
|
+
*
|
918
|
+
* @private
|
919
|
+
* @param {string} key The key of the property to get.
|
920
|
+
* @returns {Function} Returns the new function.
|
921
|
+
*/
|
922
|
+
function baseProperty(key) {
|
923
|
+
return function(object) {
|
924
|
+
return object == null ? undefined : object[key];
|
925
|
+
};
|
926
|
+
}
|
927
|
+
|
928
|
+
/**
|
929
|
+
* The base implementation of `_.slice` without an iteratee call guard.
|
930
|
+
*
|
931
|
+
* @private
|
932
|
+
* @param {Array} array The array to slice.
|
933
|
+
* @param {number} [start=0] The start position.
|
934
|
+
* @param {number} [end=array.length] The end position.
|
935
|
+
* @returns {Array} Returns the slice of `array`.
|
936
|
+
*/
|
937
|
+
function baseSlice(array, start, end) {
|
938
|
+
var index = -1,
|
939
|
+
length = array.length;
|
940
|
+
|
941
|
+
if (start < 0) {
|
942
|
+
start = -start > length ? 0 : (length + start);
|
943
|
+
}
|
944
|
+
end = end > length ? length : end;
|
945
|
+
if (end < 0) {
|
946
|
+
end += length;
|
947
|
+
}
|
948
|
+
length = start > end ? 0 : ((end - start) >>> 0);
|
949
|
+
start >>>= 0;
|
950
|
+
|
951
|
+
var result = Array(length);
|
952
|
+
while (++index < length) {
|
953
|
+
result[index] = array[index + start];
|
954
|
+
}
|
955
|
+
return result;
|
956
|
+
}
|
957
|
+
|
958
|
+
/**
|
959
|
+
* Copies the values of `source` to `array`.
|
960
|
+
*
|
961
|
+
* @private
|
962
|
+
* @param {Array} source The array to copy values from.
|
963
|
+
* @param {Array} [array=[]] The array to copy values to.
|
964
|
+
* @returns {Array} Returns `array`.
|
965
|
+
*/
|
966
|
+
function copyArray(source) {
|
967
|
+
return baseSlice(source, 0, source.length);
|
968
|
+
}
|
969
|
+
|
970
|
+
/**
|
971
|
+
* The base implementation of `_.some` without support for iteratee shorthands.
|
972
|
+
*
|
973
|
+
* @private
|
974
|
+
* @param {Array|Object} collection The collection to iterate over.
|
975
|
+
* @param {Function} predicate The function invoked per iteration.
|
976
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
977
|
+
*/
|
978
|
+
function baseSome(collection, predicate) {
|
979
|
+
var result;
|
980
|
+
|
981
|
+
baseEach(collection, function(value, index, collection) {
|
982
|
+
result = predicate(value, index, collection);
|
983
|
+
return !result;
|
984
|
+
});
|
985
|
+
return !!result;
|
986
|
+
}
|
987
|
+
|
988
|
+
/**
|
989
|
+
* The base implementation of `wrapperValue` which returns the result of
|
990
|
+
* performing a sequence of actions on the unwrapped `value`, where each
|
991
|
+
* successive action is supplied the return value of the previous.
|
992
|
+
*
|
993
|
+
* @private
|
994
|
+
* @param {*} value The unwrapped value.
|
995
|
+
* @param {Array} actions Actions to perform to resolve the unwrapped value.
|
996
|
+
* @returns {*} Returns the resolved value.
|
997
|
+
*/
|
998
|
+
function baseWrapperValue(value, actions) {
|
999
|
+
var result = value;
|
1000
|
+
return reduce(actions, function(result, action) {
|
1001
|
+
return action.func.apply(action.thisArg, arrayPush([result], action.args));
|
1002
|
+
}, result);
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
/**
|
1006
|
+
* Copies properties of `source` to `object`.
|
1007
|
+
*
|
1008
|
+
* @private
|
1009
|
+
* @param {Object} source The object to copy properties from.
|
1010
|
+
* @param {Array} props The property names to copy.
|
1011
|
+
* @param {Object} [object={}] The object to copy properties to.
|
1012
|
+
* @returns {Object} Returns `object`.
|
1013
|
+
*/
|
1014
|
+
var copyObject = copyObjectWith;
|
1015
|
+
|
1016
|
+
/**
|
1017
|
+
* This function is like `copyObject` except that it accepts a function to
|
1018
|
+
* customize copied values.
|
1019
|
+
*
|
1020
|
+
* @private
|
1021
|
+
* @param {Object} source The object to copy properties from.
|
1022
|
+
* @param {Array} props The property names to copy.
|
1023
|
+
* @param {Object} [object={}] The object to copy properties to.
|
1024
|
+
* @param {Function} [customizer] The function to customize copied values.
|
1025
|
+
* @returns {Object} Returns `object`.
|
1026
|
+
*/
|
1027
|
+
function copyObjectWith(source, props, object, customizer) {
|
1028
|
+
object || (object = {});
|
1029
|
+
|
1030
|
+
var index = -1,
|
1031
|
+
length = props.length;
|
1032
|
+
|
1033
|
+
while (++index < length) {
|
1034
|
+
var key = props[index],
|
1035
|
+
newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
|
1036
|
+
|
1037
|
+
assignValue(object, key, newValue);
|
1038
|
+
}
|
1039
|
+
return object;
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
/**
|
1043
|
+
* Creates a function like `_.assign`.
|
1044
|
+
*
|
1045
|
+
* @private
|
1046
|
+
* @param {Function} assigner The function to assign values.
|
1047
|
+
* @returns {Function} Returns the new assigner function.
|
1048
|
+
*/
|
1049
|
+
function createAssigner(assigner) {
|
1050
|
+
return rest(function(object, sources) {
|
1051
|
+
var index = -1,
|
1052
|
+
length = sources.length,
|
1053
|
+
customizer = length > 1 ? sources[length - 1] : undefined;
|
1054
|
+
|
1055
|
+
customizer = typeof customizer == 'function' ? (length--, customizer) : undefined;
|
1056
|
+
object = Object(object);
|
1057
|
+
while (++index < length) {
|
1058
|
+
var source = sources[index];
|
1059
|
+
if (source) {
|
1060
|
+
assigner(object, source, customizer);
|
1061
|
+
}
|
1062
|
+
}
|
1063
|
+
return object;
|
1064
|
+
});
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
/**
|
1068
|
+
* Creates a `baseEach` or `baseEachRight` function.
|
1069
|
+
*
|
1070
|
+
* @private
|
1071
|
+
* @param {Function} eachFunc The function to iterate over a collection.
|
1072
|
+
* @param {boolean} [fromRight] Specify iterating from right to left.
|
1073
|
+
* @returns {Function} Returns the new base function.
|
1074
|
+
*/
|
1075
|
+
function createBaseEach(eachFunc, fromRight) {
|
1076
|
+
return function(collection, iteratee) {
|
1077
|
+
if (collection == null) {
|
1078
|
+
return collection;
|
1079
|
+
}
|
1080
|
+
if (!isArrayLike(collection)) {
|
1081
|
+
return eachFunc(collection, iteratee);
|
1082
|
+
}
|
1083
|
+
var length = collection.length,
|
1084
|
+
index = fromRight ? length : -1,
|
1085
|
+
iterable = Object(collection);
|
1086
|
+
|
1087
|
+
while ((fromRight ? index-- : ++index < length)) {
|
1088
|
+
if (iteratee(iterable[index], index, iterable) === false) {
|
1089
|
+
break;
|
1090
|
+
}
|
1091
|
+
}
|
1092
|
+
return collection;
|
1093
|
+
};
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
/**
|
1097
|
+
* Creates a base function for methods like `_.forIn`.
|
1098
|
+
*
|
1099
|
+
* @private
|
1100
|
+
* @param {boolean} [fromRight] Specify iterating from right to left.
|
1101
|
+
* @returns {Function} Returns the new base function.
|
1102
|
+
*/
|
1103
|
+
function createBaseFor(fromRight) {
|
1104
|
+
return function(object, iteratee, keysFunc) {
|
1105
|
+
var index = -1,
|
1106
|
+
iterable = Object(object),
|
1107
|
+
props = keysFunc(object),
|
1108
|
+
length = props.length;
|
1109
|
+
|
1110
|
+
while (length--) {
|
1111
|
+
var key = props[fromRight ? length : ++index];
|
1112
|
+
if (iteratee(iterable[key], key, iterable) === false) {
|
1113
|
+
break;
|
1114
|
+
}
|
1115
|
+
}
|
1116
|
+
return object;
|
1117
|
+
};
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
/**
|
1121
|
+
* Creates a function that produces an instance of `Ctor` regardless of
|
1122
|
+
* whether it was invoked as part of a `new` expression or by `call` or `apply`.
|
1123
|
+
*
|
1124
|
+
* @private
|
1125
|
+
* @param {Function} Ctor The constructor to wrap.
|
1126
|
+
* @returns {Function} Returns the new wrapped function.
|
1127
|
+
*/
|
1128
|
+
function createCtorWrapper(Ctor) {
|
1129
|
+
return function() {
|
1130
|
+
// Use a `switch` statement to work with class constructors.
|
1131
|
+
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
1132
|
+
// for more details.
|
1133
|
+
var args = arguments;
|
1134
|
+
var thisBinding = baseCreate(Ctor.prototype),
|
1135
|
+
result = Ctor.apply(thisBinding, args);
|
1136
|
+
|
1137
|
+
// Mimic the constructor's `return` behavior.
|
1138
|
+
// See https://es5.github.io/#x13.2.2 for more details.
|
1139
|
+
return isObject(result) ? result : thisBinding;
|
1140
|
+
};
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
/**
|
1144
|
+
* Creates a function that wraps `func` to invoke it with the optional `this`
|
1145
|
+
* binding of `thisArg` and the `partials` prepended to those provided to
|
1146
|
+
* the wrapper.
|
1147
|
+
*
|
1148
|
+
* @private
|
1149
|
+
* @param {Function} func The function to wrap.
|
1150
|
+
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
|
1151
|
+
* @param {*} thisArg The `this` binding of `func`.
|
1152
|
+
* @param {Array} partials The arguments to prepend to those provided to the new function.
|
1153
|
+
* @returns {Function} Returns the new wrapped function.
|
1154
|
+
*/
|
1155
|
+
function createPartialWrapper(func, bitmask, thisArg, partials) {
|
1156
|
+
if (typeof func != 'function') {
|
1157
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
1158
|
+
}
|
1159
|
+
var isBind = bitmask & BIND_FLAG,
|
1160
|
+
Ctor = createCtorWrapper(func);
|
1161
|
+
|
1162
|
+
function wrapper() {
|
1163
|
+
var argsIndex = -1,
|
1164
|
+
argsLength = arguments.length,
|
1165
|
+
leftIndex = -1,
|
1166
|
+
leftLength = partials.length,
|
1167
|
+
args = Array(leftLength + argsLength),
|
1168
|
+
fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
1169
|
+
|
1170
|
+
while (++leftIndex < leftLength) {
|
1171
|
+
args[leftIndex] = partials[leftIndex];
|
1172
|
+
}
|
1173
|
+
while (argsLength--) {
|
1174
|
+
args[leftIndex++] = arguments[++argsIndex];
|
1175
|
+
}
|
1176
|
+
return fn.apply(isBind ? thisArg : this, args);
|
1177
|
+
}
|
1178
|
+
return wrapper;
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
/**
|
1182
|
+
* A specialized version of `baseIsEqualDeep` for arrays with support for
|
1183
|
+
* partial deep comparisons.
|
1184
|
+
*
|
1185
|
+
* @private
|
1186
|
+
* @param {Array} array The array to compare.
|
1187
|
+
* @param {Array} other The other array to compare.
|
1188
|
+
* @param {Function} equalFunc The function to determine equivalents of values.
|
1189
|
+
* @param {Function} [customizer] The function to customize comparisons.
|
1190
|
+
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
|
1191
|
+
* @param {Object} [stack] Tracks traversed `array` and `other` objects.
|
1192
|
+
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
|
1193
|
+
*/
|
1194
|
+
function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
|
1195
|
+
var index = -1,
|
1196
|
+
isPartial = bitmask & PARTIAL_COMPARE_FLAG,
|
1197
|
+
isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
|
1198
|
+
arrLength = array.length,
|
1199
|
+
othLength = other.length;
|
1200
|
+
|
1201
|
+
if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
1202
|
+
return false;
|
1203
|
+
}
|
1204
|
+
var result = true;
|
1205
|
+
|
1206
|
+
// Ignore non-index properties.
|
1207
|
+
while (++index < arrLength) {
|
1208
|
+
var arrValue = array[index],
|
1209
|
+
othValue = other[index];
|
1210
|
+
|
1211
|
+
var compared;
|
1212
|
+
if (compared !== undefined) {
|
1213
|
+
if (compared) {
|
1214
|
+
continue;
|
1215
|
+
}
|
1216
|
+
result = false;
|
1217
|
+
break;
|
1218
|
+
}
|
1219
|
+
// Recursively compare arrays (susceptible to call stack limits).
|
1220
|
+
if (isUnordered) {
|
1221
|
+
if (!baseSome(other, function(othValue) {
|
1222
|
+
return arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack);
|
1223
|
+
})) {
|
1224
|
+
result = false;
|
1225
|
+
break;
|
1226
|
+
}
|
1227
|
+
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
|
1228
|
+
result = false;
|
1229
|
+
break;
|
1230
|
+
}
|
1231
|
+
}
|
1232
|
+
return result;
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
/**
|
1236
|
+
* A specialized version of `baseIsEqualDeep` for comparing objects of
|
1237
|
+
* the same `toStringTag`.
|
1238
|
+
*
|
1239
|
+
* **Note:** This function only supports comparing values with tags of
|
1240
|
+
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
1241
|
+
*
|
1242
|
+
* @private
|
1243
|
+
* @param {Object} object The object to compare.
|
1244
|
+
* @param {Object} other The other object to compare.
|
1245
|
+
* @param {string} tag The `toStringTag` of the objects to compare.
|
1246
|
+
* @param {Function} equalFunc The function to determine equivalents of values.
|
1247
|
+
* @param {Function} [customizer] The function to customize comparisons.
|
1248
|
+
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
|
1249
|
+
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
1250
|
+
*/
|
1251
|
+
function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
|
1252
|
+
switch (tag) {
|
1253
|
+
|
1254
|
+
case boolTag:
|
1255
|
+
case dateTag:
|
1256
|
+
// Coerce dates and booleans to numbers, dates to milliseconds and booleans
|
1257
|
+
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
|
1258
|
+
return +object == +other;
|
1259
|
+
|
1260
|
+
case errorTag:
|
1261
|
+
return object.name == other.name && object.message == other.message;
|
1262
|
+
|
1263
|
+
case numberTag:
|
1264
|
+
// Treat `NaN` vs. `NaN` as equal.
|
1265
|
+
return (object != +object) ? other != +other : object == +other;
|
1266
|
+
|
1267
|
+
case regexpTag:
|
1268
|
+
case stringTag:
|
1269
|
+
// Coerce regexes to strings and treat strings primitives and string
|
1270
|
+
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
|
1271
|
+
return object == (other + '');
|
1272
|
+
|
1273
|
+
}
|
1274
|
+
return false;
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
/**
|
1278
|
+
* A specialized version of `baseIsEqualDeep` for objects with support for
|
1279
|
+
* partial deep comparisons.
|
1280
|
+
*
|
1281
|
+
* @private
|
1282
|
+
* @param {Object} object The object to compare.
|
1283
|
+
* @param {Object} other The other object to compare.
|
1284
|
+
* @param {Function} equalFunc The function to determine equivalents of values.
|
1285
|
+
* @param {Function} [customizer] The function to customize comparisons.
|
1286
|
+
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` for more details.
|
1287
|
+
* @param {Object} [stack] Tracks traversed `object` and `other` objects.
|
1288
|
+
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
1289
|
+
*/
|
1290
|
+
function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
|
1291
|
+
var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
|
1292
|
+
isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
|
1293
|
+
objProps = keys(object),
|
1294
|
+
objLength = objProps.length,
|
1295
|
+
othProps = keys(other),
|
1296
|
+
othLength = othProps.length;
|
1297
|
+
|
1298
|
+
if (objLength != othLength && !isPartial) {
|
1299
|
+
return false;
|
1300
|
+
}
|
1301
|
+
var index = objLength;
|
1302
|
+
while (index--) {
|
1303
|
+
var key = objProps[index];
|
1304
|
+
if (!(isPartial ? key in other : hasOwnProperty.call(other, key)) ||
|
1305
|
+
!(isUnordered || key == othProps[index])) {
|
1306
|
+
return false;
|
1307
|
+
}
|
1308
|
+
}
|
1309
|
+
var result = true;
|
1310
|
+
|
1311
|
+
var skipCtor = isPartial;
|
1312
|
+
while (++index < objLength) {
|
1313
|
+
key = objProps[index];
|
1314
|
+
var objValue = object[key],
|
1315
|
+
othValue = other[key];
|
1316
|
+
|
1317
|
+
var compared;
|
1318
|
+
// Recursively compare objects (susceptible to call stack limits).
|
1319
|
+
if (!(compared === undefined
|
1320
|
+
? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
|
1321
|
+
: compared
|
1322
|
+
)) {
|
1323
|
+
result = false;
|
1324
|
+
break;
|
1325
|
+
}
|
1326
|
+
skipCtor || (skipCtor = key == 'constructor');
|
1327
|
+
}
|
1328
|
+
if (result && !skipCtor) {
|
1329
|
+
var objCtor = object.constructor,
|
1330
|
+
othCtor = other.constructor;
|
1331
|
+
|
1332
|
+
// Non `Object` object instances with different constructors are not equal.
|
1333
|
+
if (objCtor != othCtor &&
|
1334
|
+
('constructor' in object && 'constructor' in other) &&
|
1335
|
+
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
1336
|
+
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
1337
|
+
result = false;
|
1338
|
+
}
|
1339
|
+
}
|
1340
|
+
return result;
|
1341
|
+
}
|
1342
|
+
|
1343
|
+
/**
|
1344
|
+
* Gets the "length" property value of `object`.
|
1345
|
+
*
|
1346
|
+
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
1347
|
+
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
1348
|
+
*
|
1349
|
+
* @private
|
1350
|
+
* @param {Object} object The object to query.
|
1351
|
+
* @returns {*} Returns the "length" value.
|
1352
|
+
*/
|
1353
|
+
var getLength = baseProperty('length');
|
1354
|
+
|
1355
|
+
/**
|
1356
|
+
* Creates an array of index keys for `object` values of arrays,
|
1357
|
+
* `arguments` objects, and strings, otherwise `null` is returned.
|
1358
|
+
*
|
1359
|
+
* @private
|
1360
|
+
* @param {Object} object The object to query.
|
1361
|
+
* @returns {Array|null} Returns index keys, else `null`.
|
1362
|
+
*/
|
1363
|
+
function indexKeys(object) {
|
1364
|
+
var length = object ? object.length : undefined;
|
1365
|
+
return (isLength(length) && (isArray(object) || isString(object) || isArguments(object)))
|
1366
|
+
? baseTimes(length, String)
|
1367
|
+
: null;
|
1368
|
+
}
|
1369
|
+
|
1370
|
+
/**
|
1371
|
+
* Checks if `value` is likely a prototype object.
|
1372
|
+
*
|
1373
|
+
* @private
|
1374
|
+
* @param {*} value The value to check.
|
1375
|
+
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
1376
|
+
*/
|
1377
|
+
function isPrototype(value) {
|
1378
|
+
var Ctor = value && value.constructor,
|
1379
|
+
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
1380
|
+
|
1381
|
+
return value === proto;
|
1382
|
+
}
|
1383
|
+
|
1384
|
+
/**
|
1385
|
+
* Converts `value` to a function if it's not one.
|
1386
|
+
*
|
1387
|
+
* @private
|
1388
|
+
* @param {*} value The value to process.
|
1389
|
+
* @returns {Function} Returns the function.
|
1390
|
+
*/
|
1391
|
+
function toFunction(value) {
|
1392
|
+
return typeof value == 'function' ? value : identity;
|
1393
|
+
}
|
1394
|
+
|
1395
|
+
/**
|
1396
|
+
* Creates a clone of `wrapper`.
|
1397
|
+
*
|
1398
|
+
* @private
|
1399
|
+
* @param {Object} wrapper The wrapper to clone.
|
1400
|
+
* @returns {Object} Returns the cloned wrapper.
|
1401
|
+
*/
|
1402
|
+
function wrapperClone(wrapper) {
|
1403
|
+
var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
|
1404
|
+
result.__actions__ = copyArray(wrapper.__actions__);
|
1405
|
+
return result;
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
/*------------------------------------------------------------------------*/
|
1409
|
+
|
1410
|
+
/**
|
1411
|
+
* Creates an array with all falsey values removed. The values `false`, `null`,
|
1412
|
+
* `0`, `""`, `undefined`, and `NaN` are falsey.
|
1413
|
+
*
|
1414
|
+
* @static
|
1415
|
+
* @memberOf _
|
1416
|
+
* @category Array
|
1417
|
+
* @param {Array} array The array to compact.
|
1418
|
+
* @returns {Array} Returns the new array of filtered values.
|
1419
|
+
* @example
|
1420
|
+
*
|
1421
|
+
* _.compact([0, 1, false, 2, '', 3]);
|
1422
|
+
* // => [1, 2, 3]
|
1423
|
+
*/
|
1424
|
+
function compact(array) {
|
1425
|
+
return baseFilter(array, Boolean);
|
1426
|
+
}
|
1427
|
+
|
1428
|
+
/**
|
1429
|
+
* Creates a new array concatenating `array` with any additional arrays
|
1430
|
+
* and/or values.
|
1431
|
+
*
|
1432
|
+
* @static
|
1433
|
+
* @memberOf _
|
1434
|
+
* @category Array
|
1435
|
+
* @param {Array} array The array to concatenate.
|
1436
|
+
* @param {...*} [values] The values to concatenate.
|
1437
|
+
* @returns {Array} Returns the new concatenated array.
|
1438
|
+
* @example
|
1439
|
+
*
|
1440
|
+
* var array = [1];
|
1441
|
+
* var other = _.concat(array, 2, [3], [[4]]);
|
1442
|
+
*
|
1443
|
+
* console.log(other);
|
1444
|
+
* // => [1, 2, 3, [4]]
|
1445
|
+
*
|
1446
|
+
* console.log(array);
|
1447
|
+
* // => [1]
|
1448
|
+
*/
|
1449
|
+
var concat = rest(function(array, values) {
|
1450
|
+
values = baseFlatten(values);
|
1451
|
+
return arrayConcat(isArray(array) ? array : [Object(array)], values);
|
1452
|
+
});
|
1453
|
+
|
1454
|
+
/**
|
1455
|
+
* Flattens `array` a single level.
|
1456
|
+
*
|
1457
|
+
* @static
|
1458
|
+
* @memberOf _
|
1459
|
+
* @category Array
|
1460
|
+
* @param {Array} array The array to flatten.
|
1461
|
+
* @returns {Array} Returns the new flattened array.
|
1462
|
+
* @example
|
1463
|
+
*
|
1464
|
+
* _.flatten([1, [2, 3, [4]]]);
|
1465
|
+
* // => [1, 2, 3, [4]]
|
1466
|
+
*/
|
1467
|
+
function flatten(array) {
|
1468
|
+
var length = array ? array.length : 0;
|
1469
|
+
return length ? baseFlatten(array) : [];
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
/**
|
1473
|
+
* This method is like `_.flatten` except that it recursively flattens `array`.
|
1474
|
+
*
|
1475
|
+
* @static
|
1476
|
+
* @memberOf _
|
1477
|
+
* @category Array
|
1478
|
+
* @param {Array} array The array to recursively flatten.
|
1479
|
+
* @returns {Array} Returns the new flattened array.
|
1480
|
+
* @example
|
1481
|
+
*
|
1482
|
+
* _.flattenDeep([1, [2, 3, [4]]]);
|
1483
|
+
* // => [1, 2, 3, 4]
|
1484
|
+
*/
|
1485
|
+
function flattenDeep(array) {
|
1486
|
+
var length = array ? array.length : 0;
|
1487
|
+
return length ? baseFlatten(array, true) : [];
|
1488
|
+
}
|
1489
|
+
|
1490
|
+
/**
|
1491
|
+
* Gets the first element of `array`.
|
1492
|
+
*
|
1493
|
+
* @static
|
1494
|
+
* @memberOf _
|
1495
|
+
* @alias first
|
1496
|
+
* @category Array
|
1497
|
+
* @param {Array} array The array to query.
|
1498
|
+
* @returns {*} Returns the first element of `array`.
|
1499
|
+
* @example
|
1500
|
+
*
|
1501
|
+
* _.head([1, 2, 3]);
|
1502
|
+
* // => 1
|
1503
|
+
*
|
1504
|
+
* _.head([]);
|
1505
|
+
* // => undefined
|
1506
|
+
*/
|
1507
|
+
function head(array) {
|
1508
|
+
return array ? array[0] : undefined;
|
1509
|
+
}
|
1510
|
+
|
1511
|
+
/**
|
1512
|
+
* Gets the index at which the first occurrence of `value` is found in `array`
|
1513
|
+
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
1514
|
+
* for equality comparisons. If `fromIndex` is negative, it's used as the offset
|
1515
|
+
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
|
1516
|
+
* performs a faster binary search.
|
1517
|
+
*
|
1518
|
+
* @static
|
1519
|
+
* @memberOf _
|
1520
|
+
* @category Array
|
1521
|
+
* @param {Array} array The array to search.
|
1522
|
+
* @param {*} value The value to search for.
|
1523
|
+
* @param {number} [fromIndex=0] The index to search from.
|
1524
|
+
* @returns {number} Returns the index of the matched value, else `-1`.
|
1525
|
+
* @example
|
1526
|
+
*
|
1527
|
+
* _.indexOf([1, 2, 1, 2], 2);
|
1528
|
+
* // => 1
|
1529
|
+
*
|
1530
|
+
* // using `fromIndex`
|
1531
|
+
* _.indexOf([1, 2, 1, 2], 2, 2);
|
1532
|
+
* // => 3
|
1533
|
+
*/
|
1534
|
+
function indexOf(array, value, fromIndex) {
|
1535
|
+
var length = array ? array.length : 0;
|
1536
|
+
if (typeof fromIndex == 'number') {
|
1537
|
+
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
1538
|
+
} else {
|
1539
|
+
fromIndex = 0;
|
1540
|
+
}
|
1541
|
+
var index = (fromIndex || 0) - 1,
|
1542
|
+
isReflexive = value === value;
|
1543
|
+
|
1544
|
+
while (++index < length) {
|
1545
|
+
var other = array[index];
|
1546
|
+
if ((isReflexive ? other === value : other !== other)) {
|
1547
|
+
return index;
|
1548
|
+
}
|
1549
|
+
}
|
1550
|
+
return -1;
|
1551
|
+
}
|
1552
|
+
|
1553
|
+
/**
|
1554
|
+
* Gets the last element of `array`.
|
1555
|
+
*
|
1556
|
+
* @static
|
1557
|
+
* @memberOf _
|
1558
|
+
* @category Array
|
1559
|
+
* @param {Array} array The array to query.
|
1560
|
+
* @returns {*} Returns the last element of `array`.
|
1561
|
+
* @example
|
1562
|
+
*
|
1563
|
+
* _.last([1, 2, 3]);
|
1564
|
+
* // => 3
|
1565
|
+
*/
|
1566
|
+
function last(array) {
|
1567
|
+
var length = array ? array.length : 0;
|
1568
|
+
return length ? array[length - 1] : undefined;
|
1569
|
+
}
|
1570
|
+
|
1571
|
+
/**
|
1572
|
+
* Creates a slice of `array` from `start` up to, but not including, `end`.
|
1573
|
+
*
|
1574
|
+
* **Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/slice)
|
1575
|
+
* to ensure dense arrays are returned.
|
1576
|
+
*
|
1577
|
+
* @static
|
1578
|
+
* @memberOf _
|
1579
|
+
* @category Array
|
1580
|
+
* @param {Array} array The array to slice.
|
1581
|
+
* @param {number} [start=0] The start position.
|
1582
|
+
* @param {number} [end=array.length] The end position.
|
1583
|
+
* @returns {Array} Returns the slice of `array`.
|
1584
|
+
*/
|
1585
|
+
function slice(array, start, end) {
|
1586
|
+
var length = array ? array.length : 0;
|
1587
|
+
return length ? baseSlice(array, start, end) : [];
|
1588
|
+
}
|
1589
|
+
|
1590
|
+
/*------------------------------------------------------------------------*/
|
1591
|
+
|
1592
|
+
/**
|
1593
|
+
* Creates a `lodash` object that wraps `value` with explicit method chaining enabled.
|
1594
|
+
* The result of such method chaining must be unwrapped with `_#value`.
|
1595
|
+
*
|
1596
|
+
* @static
|
1597
|
+
* @memberOf _
|
1598
|
+
* @category Seq
|
1599
|
+
* @param {*} value The value to wrap.
|
1600
|
+
* @returns {Object} Returns the new `lodash` wrapper instance.
|
1601
|
+
* @example
|
1602
|
+
*
|
1603
|
+
* var users = [
|
1604
|
+
* { 'user': 'barney', 'age': 36 },
|
1605
|
+
* { 'user': 'fred', 'age': 40 },
|
1606
|
+
* { 'user': 'pebbles', 'age': 1 }
|
1607
|
+
* ];
|
1608
|
+
*
|
1609
|
+
* var youngest = _
|
1610
|
+
* .chain(users)
|
1611
|
+
* .sortBy('age')
|
1612
|
+
* .map(function(o) {
|
1613
|
+
* return o.user + ' is ' + o.age;
|
1614
|
+
* })
|
1615
|
+
* .head()
|
1616
|
+
* .value();
|
1617
|
+
* // => 'pebbles is 1'
|
1618
|
+
*/
|
1619
|
+
function chain(value) {
|
1620
|
+
var result = lodash(value);
|
1621
|
+
result.__chain__ = true;
|
1622
|
+
return result;
|
1623
|
+
}
|
1624
|
+
|
1625
|
+
/**
|
1626
|
+
* This method invokes `interceptor` and returns `value`. The interceptor is
|
1627
|
+
* invoked with one argument; (value). The purpose of this method is to "tap into"
|
1628
|
+
* a method chain in order to perform operations on intermediate results within
|
1629
|
+
* the chain.
|
1630
|
+
*
|
1631
|
+
* @static
|
1632
|
+
* @memberOf _
|
1633
|
+
* @category Seq
|
1634
|
+
* @param {*} value The value to provide to `interceptor`.
|
1635
|
+
* @param {Function} interceptor The function to invoke.
|
1636
|
+
* @returns {*} Returns `value`.
|
1637
|
+
* @example
|
1638
|
+
*
|
1639
|
+
* _([1, 2, 3])
|
1640
|
+
* .tap(function(array) {
|
1641
|
+
* array.pop();
|
1642
|
+
* })
|
1643
|
+
* .reverse()
|
1644
|
+
* .value();
|
1645
|
+
* // => [2, 1]
|
1646
|
+
*/
|
1647
|
+
function tap(value, interceptor) {
|
1648
|
+
interceptor(value);
|
1649
|
+
return value;
|
1650
|
+
}
|
1651
|
+
|
1652
|
+
/**
|
1653
|
+
* This method is like `_.tap` except that it returns the result of `interceptor`.
|
1654
|
+
*
|
1655
|
+
* @static
|
1656
|
+
* @memberOf _
|
1657
|
+
* @category Seq
|
1658
|
+
* @param {*} value The value to provide to `interceptor`.
|
1659
|
+
* @param {Function} interceptor The function to invoke.
|
1660
|
+
* @returns {*} Returns the result of `interceptor`.
|
1661
|
+
* @example
|
1662
|
+
*
|
1663
|
+
* _(' abc ')
|
1664
|
+
* .chain()
|
1665
|
+
* .trim()
|
1666
|
+
* .thru(function(value) {
|
1667
|
+
* return [value];
|
1668
|
+
* })
|
1669
|
+
* .value();
|
1670
|
+
* // => ['abc']
|
1671
|
+
*/
|
1672
|
+
function thru(value, interceptor) {
|
1673
|
+
return interceptor(value);
|
1674
|
+
}
|
1675
|
+
|
1676
|
+
/**
|
1677
|
+
* Enables explicit method chaining on the wrapper object.
|
1678
|
+
*
|
1679
|
+
* @name chain
|
1680
|
+
* @memberOf _
|
1681
|
+
* @category Seq
|
1682
|
+
* @returns {Object} Returns the new `lodash` wrapper instance.
|
1683
|
+
* @example
|
1684
|
+
*
|
1685
|
+
* var users = [
|
1686
|
+
* { 'user': 'barney', 'age': 36 },
|
1687
|
+
* { 'user': 'fred', 'age': 40 }
|
1688
|
+
* ];
|
1689
|
+
*
|
1690
|
+
* // without explicit chaining
|
1691
|
+
* _(users).head();
|
1692
|
+
* // => { 'user': 'barney', 'age': 36 }
|
1693
|
+
*
|
1694
|
+
* // with explicit chaining
|
1695
|
+
* _(users)
|
1696
|
+
* .chain()
|
1697
|
+
* .head()
|
1698
|
+
* .pick('user')
|
1699
|
+
* .value();
|
1700
|
+
* // => { 'user': 'barney' }
|
1701
|
+
*/
|
1702
|
+
function wrapperChain() {
|
1703
|
+
return chain(this);
|
1704
|
+
}
|
1705
|
+
|
1706
|
+
/**
|
1707
|
+
* Executes the chained sequence to extract the unwrapped value.
|
1708
|
+
*
|
1709
|
+
* @name value
|
1710
|
+
* @memberOf _
|
1711
|
+
* @alias run, toJSON, valueOf
|
1712
|
+
* @category Seq
|
1713
|
+
* @returns {*} Returns the resolved unwrapped value.
|
1714
|
+
* @example
|
1715
|
+
*
|
1716
|
+
* _([1, 2, 3]).value();
|
1717
|
+
* // => [1, 2, 3]
|
1718
|
+
*/
|
1719
|
+
function wrapperValue() {
|
1720
|
+
return baseWrapperValue(this.__wrapped__, this.__actions__);
|
1721
|
+
}
|
1722
|
+
|
1723
|
+
/*------------------------------------------------------------------------*/
|
1724
|
+
|
1725
|
+
/**
|
1726
|
+
* Checks if `predicate` returns truthy for **all** elements of `collection`.
|
1727
|
+
* Iteration is stopped once `predicate` returns falsey. The predicate is
|
1728
|
+
* invoked with three arguments: (value, index|key, collection).
|
1729
|
+
*
|
1730
|
+
* @static
|
1731
|
+
* @memberOf _
|
1732
|
+
* @category Collection
|
1733
|
+
* @param {Array|Object} collection The collection to iterate over.
|
1734
|
+
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
|
1735
|
+
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
|
1736
|
+
* @returns {boolean} Returns `true` if all elements pass the predicate check, else `false`.
|
1737
|
+
* @example
|
1738
|
+
*
|
1739
|
+
* _.every([true, 1, null, 'yes'], Boolean);
|
1740
|
+
* // => false
|
1741
|
+
*
|
1742
|
+
* var users = [
|
1743
|
+
* { 'user': 'barney', 'active': false },
|
1744
|
+
* { 'user': 'fred', 'active': false }
|
1745
|
+
* ];
|
1746
|
+
*
|
1747
|
+
* // using the `_.matches` iteratee shorthand
|
1748
|
+
* _.every(users, { 'user': 'barney', 'active': false });
|
1749
|
+
* // => false
|
1750
|
+
*
|
1751
|
+
* // using the `_.matchesProperty` iteratee shorthand
|
1752
|
+
* _.every(users, ['active', false]);
|
1753
|
+
* // => true
|
1754
|
+
*
|
1755
|
+
* // using the `_.property` iteratee shorthand
|
1756
|
+
* _.every(users, 'active');
|
1757
|
+
* // => false
|
1758
|
+
*/
|
1759
|
+
function every(collection, predicate, guard) {
|
1760
|
+
predicate = guard ? undefined : predicate;
|
1761
|
+
return baseEvery(collection, baseIteratee(predicate));
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
/**
|
1765
|
+
* Iterates over elements of `collection`, returning an array of all elements
|
1766
|
+
* `predicate` returns truthy for. The predicate is invoked with three arguments:
|
1767
|
+
* (value, index|key, collection).
|
1768
|
+
*
|
1769
|
+
* @static
|
1770
|
+
* @memberOf _
|
1771
|
+
* @category Collection
|
1772
|
+
* @param {Array|Object} collection The collection to iterate over.
|
1773
|
+
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
|
1774
|
+
* @returns {Array} Returns the new filtered array.
|
1775
|
+
* @example
|
1776
|
+
*
|
1777
|
+
* var users = [
|
1778
|
+
* { 'user': 'barney', 'age': 36, 'active': true },
|
1779
|
+
* { 'user': 'fred', 'age': 40, 'active': false }
|
1780
|
+
* ];
|
1781
|
+
*
|
1782
|
+
* _.filter(users, function(o) { return !o.active; });
|
1783
|
+
* // => objects for ['fred']
|
1784
|
+
*
|
1785
|
+
* // using the `_.matches` iteratee shorthand
|
1786
|
+
* _.filter(users, { 'age': 36, 'active': true });
|
1787
|
+
* // => objects for ['barney']
|
1788
|
+
*
|
1789
|
+
* // using the `_.matchesProperty` iteratee shorthand
|
1790
|
+
* _.filter(users, ['active', false]);
|
1791
|
+
* // => objects for ['fred']
|
1792
|
+
*
|
1793
|
+
* // using the `_.property` iteratee shorthand
|
1794
|
+
* _.filter(users, 'active');
|
1795
|
+
* // => objects for ['barney']
|
1796
|
+
*/
|
1797
|
+
function filter(collection, predicate) {
|
1798
|
+
return baseFilter(collection, baseIteratee(predicate));
|
1799
|
+
}
|
1800
|
+
|
1801
|
+
/**
|
1802
|
+
* Iterates over elements of `collection`, returning the first element
|
1803
|
+
* `predicate` returns truthy for. The predicate is invoked with three arguments:
|
1804
|
+
* (value, index|key, collection).
|
1805
|
+
*
|
1806
|
+
* @static
|
1807
|
+
* @memberOf _
|
1808
|
+
* @category Collection
|
1809
|
+
* @param {Array|Object} collection The collection to search.
|
1810
|
+
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
|
1811
|
+
* @returns {*} Returns the matched element, else `undefined`.
|
1812
|
+
* @example
|
1813
|
+
*
|
1814
|
+
* var users = [
|
1815
|
+
* { 'user': 'barney', 'age': 36, 'active': true },
|
1816
|
+
* { 'user': 'fred', 'age': 40, 'active': false },
|
1817
|
+
* { 'user': 'pebbles', 'age': 1, 'active': true }
|
1818
|
+
* ];
|
1819
|
+
*
|
1820
|
+
* _.find(users, function(o) { return o.age < 40; });
|
1821
|
+
* // => object for 'barney'
|
1822
|
+
*
|
1823
|
+
* // using the `_.matches` iteratee shorthand
|
1824
|
+
* _.find(users, { 'age': 1, 'active': true });
|
1825
|
+
* // => object for 'pebbles'
|
1826
|
+
*
|
1827
|
+
* // using the `_.matchesProperty` iteratee shorthand
|
1828
|
+
* _.find(users, ['active', false]);
|
1829
|
+
* // => object for 'fred'
|
1830
|
+
*
|
1831
|
+
* // using the `_.property` iteratee shorthand
|
1832
|
+
* _.find(users, 'active');
|
1833
|
+
* // => object for 'barney'
|
1834
|
+
*/
|
1835
|
+
function find(collection, predicate) {
|
1836
|
+
return baseFind(collection, baseIteratee(predicate), baseEach);
|
1837
|
+
}
|
1838
|
+
|
1839
|
+
/**
|
1840
|
+
* Iterates over elements of `collection` invoking `iteratee` for each element.
|
1841
|
+
* The iteratee is invoked with three arguments: (value, index|key, collection).
|
1842
|
+
* Iteratee functions may exit iteration early by explicitly returning `false`.
|
1843
|
+
*
|
1844
|
+
* **Note:** As with other "Collections" methods, objects with a "length" property
|
1845
|
+
* are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn`
|
1846
|
+
* for object iteration.
|
1847
|
+
*
|
1848
|
+
* @static
|
1849
|
+
* @memberOf _
|
1850
|
+
* @alias each
|
1851
|
+
* @category Collection
|
1852
|
+
* @param {Array|Object} collection The collection to iterate over.
|
1853
|
+
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
1854
|
+
* @returns {Array|Object} Returns `collection`.
|
1855
|
+
* @example
|
1856
|
+
*
|
1857
|
+
* _([1, 2]).forEach(function(value) {
|
1858
|
+
* console.log(value);
|
1859
|
+
* });
|
1860
|
+
* // => logs `1` then `2`
|
1861
|
+
*
|
1862
|
+
* _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
|
1863
|
+
* console.log(key);
|
1864
|
+
* });
|
1865
|
+
* // => logs 'a' then 'b' (iteration order is not guaranteed)
|
1866
|
+
*/
|
1867
|
+
function forEach(collection, iteratee) {
|
1868
|
+
return baseEach(collection, toFunction(iteratee));
|
1869
|
+
}
|
1870
|
+
|
1871
|
+
/**
|
1872
|
+
* Invokes the method at `path` of each element in `collection`, returning
|
1873
|
+
* an array of the results of each invoked method. Any additional arguments
|
1874
|
+
* are provided to each invoked method. If `methodName` is a function it's
|
1875
|
+
* invoked for, and `this` bound to, each element in `collection`.
|
1876
|
+
*
|
1877
|
+
* @static
|
1878
|
+
* @memberOf _
|
1879
|
+
* @category Collection
|
1880
|
+
* @param {Array|Object} collection The collection to iterate over.
|
1881
|
+
* @param {Array|Function|string} path The path of the method to invoke or
|
1882
|
+
* the function invoked per iteration.
|
1883
|
+
* @param {...*} [args] The arguments to invoke each method with.
|
1884
|
+
* @returns {Array} Returns the array of results.
|
1885
|
+
* @example
|
1886
|
+
*
|
1887
|
+
* _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
|
1888
|
+
* // => [[1, 5, 7], [1, 2, 3]]
|
1889
|
+
*
|
1890
|
+
* _.invokeMap([123, 456], String.prototype.split, '');
|
1891
|
+
* // => [['1', '2', '3'], ['4', '5', '6']]
|
1892
|
+
*/
|
1893
|
+
var invokeMap = rest(function(collection, path, args) {
|
1894
|
+
var isFunc = typeof path == 'function';
|
1895
|
+
return baseMap(collection, function(value) {
|
1896
|
+
var func = isFunc ? path : value[path];
|
1897
|
+
return func == null ? func : func.apply(value, args);
|
1898
|
+
});
|
1899
|
+
});
|
1900
|
+
|
1901
|
+
/**
|
1902
|
+
* Creates an array of values by running each element in `collection` through
|
1903
|
+
* `iteratee`. The iteratee is invoked with three arguments:
|
1904
|
+
* (value, index|key, collection).
|
1905
|
+
*
|
1906
|
+
* Many lodash methods are guarded to work as iteratees for methods like
|
1907
|
+
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
1908
|
+
*
|
1909
|
+
* The guarded methods are:
|
1910
|
+
* `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
|
1911
|
+
* `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
|
1912
|
+
* `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
|
1913
|
+
* and `words`
|
1914
|
+
*
|
1915
|
+
* @static
|
1916
|
+
* @memberOf _
|
1917
|
+
* @category Collection
|
1918
|
+
* @param {Array|Object} collection The collection to iterate over.
|
1919
|
+
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
|
1920
|
+
* @returns {Array} Returns the new mapped array.
|
1921
|
+
* @example
|
1922
|
+
*
|
1923
|
+
* function square(n) {
|
1924
|
+
* return n * n;
|
1925
|
+
* }
|
1926
|
+
*
|
1927
|
+
* _.map([1, 2], square);
|
1928
|
+
* // => [3, 6]
|
1929
|
+
*
|
1930
|
+
* _.map({ 'a': 1, 'b': 2 }, square);
|
1931
|
+
* // => [3, 6] (iteration order is not guaranteed)
|
1932
|
+
*
|
1933
|
+
* var users = [
|
1934
|
+
* { 'user': 'barney' },
|
1935
|
+
* { 'user': 'fred' }
|
1936
|
+
* ];
|
1937
|
+
*
|
1938
|
+
* // using the `_.property` iteratee shorthand
|
1939
|
+
* _.map(users, 'user');
|
1940
|
+
* // => ['barney', 'fred']
|
1941
|
+
*/
|
1942
|
+
function map(collection, iteratee) {
|
1943
|
+
return baseMap(collection, baseIteratee(iteratee));
|
1944
|
+
}
|
1945
|
+
|
1946
|
+
/**
|
1947
|
+
* Reduces `collection` to a value which is the accumulated result of running
|
1948
|
+
* each element in `collection` through `iteratee`, where each successive
|
1949
|
+
* invocation is supplied the return value of the previous. If `accumulator`
|
1950
|
+
* is not provided the first element of `collection` is used as the initial
|
1951
|
+
* value. The iteratee is invoked with four arguments:
|
1952
|
+
* (accumulator, value, index|key, collection).
|
1953
|
+
*
|
1954
|
+
* Many lodash methods are guarded to work as iteratees for methods like
|
1955
|
+
* `_.reduce`, `_.reduceRight`, and `_.transform`.
|
1956
|
+
*
|
1957
|
+
* The guarded methods are:
|
1958
|
+
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
|
1959
|
+
* and `sortBy`
|
1960
|
+
*
|
1961
|
+
* @static
|
1962
|
+
* @memberOf _
|
1963
|
+
* @category Collection
|
1964
|
+
* @param {Array|Object} collection The collection to iterate over.
|
1965
|
+
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
1966
|
+
* @param {*} [accumulator] The initial value.
|
1967
|
+
* @returns {*} Returns the accumulated value.
|
1968
|
+
* @example
|
1969
|
+
*
|
1970
|
+
* _.reduce([1, 2], function(sum, n) {
|
1971
|
+
* return sum + n;
|
1972
|
+
* });
|
1973
|
+
* // => 3
|
1974
|
+
*
|
1975
|
+
* _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
|
1976
|
+
* (result[value] || (result[value] = [])).push(key);
|
1977
|
+
* return result;
|
1978
|
+
* }, {});
|
1979
|
+
* // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
|
1980
|
+
*/
|
1981
|
+
function reduce(collection, iteratee, accumulator) {
|
1982
|
+
return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
|
1983
|
+
}
|
1984
|
+
|
1985
|
+
/**
|
1986
|
+
* Gets the size of `collection` by returning its length for array-like
|
1987
|
+
* values or the number of own enumerable properties for objects.
|
1988
|
+
*
|
1989
|
+
* @static
|
1990
|
+
* @memberOf _
|
1991
|
+
* @category Collection
|
1992
|
+
* @param {Array|Object} collection The collection to inspect.
|
1993
|
+
* @returns {number} Returns the collection size.
|
1994
|
+
* @example
|
1995
|
+
*
|
1996
|
+
* _.size([1, 2, 3]);
|
1997
|
+
* // => 3
|
1998
|
+
*
|
1999
|
+
* _.size({ 'a': 1, 'b': 2 });
|
2000
|
+
* // => 2
|
2001
|
+
*
|
2002
|
+
* _.size('pebbles');
|
2003
|
+
* // => 7
|
2004
|
+
*/
|
2005
|
+
function size(collection) {
|
2006
|
+
if (collection == null) {
|
2007
|
+
return 0;
|
2008
|
+
}
|
2009
|
+
collection = isArrayLike(collection) ? collection : keys(collection);
|
2010
|
+
return collection.length;
|
2011
|
+
}
|
2012
|
+
|
2013
|
+
/**
|
2014
|
+
* Checks if `predicate` returns truthy for **any** element of `collection`.
|
2015
|
+
* Iteration is stopped once `predicate` returns truthy. The predicate is
|
2016
|
+
* invoked with three arguments: (value, index|key, collection).
|
2017
|
+
*
|
2018
|
+
* @static
|
2019
|
+
* @memberOf _
|
2020
|
+
* @category Collection
|
2021
|
+
* @param {Array|Object} collection The collection to iterate over.
|
2022
|
+
* @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
|
2023
|
+
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
|
2024
|
+
* @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
|
2025
|
+
* @example
|
2026
|
+
*
|
2027
|
+
* _.some([null, 0, 'yes', false], Boolean);
|
2028
|
+
* // => true
|
2029
|
+
*
|
2030
|
+
* var users = [
|
2031
|
+
* { 'user': 'barney', 'active': true },
|
2032
|
+
* { 'user': 'fred', 'active': false }
|
2033
|
+
* ];
|
2034
|
+
*
|
2035
|
+
* // using the `_.matches` iteratee shorthand
|
2036
|
+
* _.some(users, { 'user': 'barney', 'active': false });
|
2037
|
+
* // => false
|
2038
|
+
*
|
2039
|
+
* // using the `_.matchesProperty` iteratee shorthand
|
2040
|
+
* _.some(users, ['active', false]);
|
2041
|
+
* // => true
|
2042
|
+
*
|
2043
|
+
* // using the `_.property` iteratee shorthand
|
2044
|
+
* _.some(users, 'active');
|
2045
|
+
* // => true
|
2046
|
+
*/
|
2047
|
+
function some(collection, predicate, guard) {
|
2048
|
+
predicate = guard ? undefined : predicate;
|
2049
|
+
return baseSome(collection, baseIteratee(predicate));
|
2050
|
+
}
|
2051
|
+
|
2052
|
+
/**
|
2053
|
+
* Creates an array of elements, sorted in ascending order by the results of
|
2054
|
+
* running each element in a collection through each iteratee. This method
|
2055
|
+
* performs a stable sort, that is, it preserves the original sort order of
|
2056
|
+
* equal elements. The iteratees are invoked with one argument: (value).
|
2057
|
+
*
|
2058
|
+
* @static
|
2059
|
+
* @memberOf _
|
2060
|
+
* @category Collection
|
2061
|
+
* @param {Array|Object} collection The collection to iterate over.
|
2062
|
+
* @param {...(Function|Function[]|Object|Object[]|string|string[])} [iteratees=[_.identity]]
|
2063
|
+
* The iteratees to sort by, specified individually or in arrays.
|
2064
|
+
* @returns {Array} Returns the new sorted array.
|
2065
|
+
* @example
|
2066
|
+
*
|
2067
|
+
* var users = [
|
2068
|
+
* { 'user': 'fred', 'age': 48 },
|
2069
|
+
* { 'user': 'barney', 'age': 36 },
|
2070
|
+
* { 'user': 'fred', 'age': 42 },
|
2071
|
+
* { 'user': 'barney', 'age': 34 }
|
2072
|
+
* ];
|
2073
|
+
*
|
2074
|
+
* _.sortBy(users, function(o) { return o.user; });
|
2075
|
+
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
2076
|
+
*
|
2077
|
+
* _.sortBy(users, ['user', 'age']);
|
2078
|
+
* // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
|
2079
|
+
*
|
2080
|
+
* _.sortBy(users, 'user', function(o) {
|
2081
|
+
* return Math.floor(o.age / 10);
|
2082
|
+
* });
|
2083
|
+
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
2084
|
+
*/
|
2085
|
+
function sortBy(collection, iteratee) {
|
2086
|
+
var index = 0;
|
2087
|
+
iteratee = baseIteratee(iteratee);
|
2088
|
+
|
2089
|
+
return baseMap(baseMap(collection, function(value, key, collection) {
|
2090
|
+
return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
|
2091
|
+
}).sort(function(object, other) {
|
2092
|
+
return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
|
2093
|
+
}), baseProperty('value'));
|
2094
|
+
}
|
2095
|
+
|
2096
|
+
/*------------------------------------------------------------------------*/
|
2097
|
+
|
2098
|
+
/**
|
2099
|
+
* Gets the timestamp of the number of milliseconds that have elapsed since
|
2100
|
+
* the Unix epoch (1 January 1970 00:00:00 UTC).
|
2101
|
+
*
|
2102
|
+
* @static
|
2103
|
+
* @memberOf _
|
2104
|
+
* @type Function
|
2105
|
+
* @category Date
|
2106
|
+
* @returns {number} Returns the timestamp.
|
2107
|
+
* @example
|
2108
|
+
*
|
2109
|
+
* _.defer(function(stamp) {
|
2110
|
+
* console.log(_.now() - stamp);
|
2111
|
+
* }, _.now());
|
2112
|
+
* // => logs the number of milliseconds it took for the deferred function to be invoked
|
2113
|
+
*/
|
2114
|
+
var now = Date.now;
|
2115
|
+
|
2116
|
+
/*------------------------------------------------------------------------*/
|
2117
|
+
|
2118
|
+
/**
|
2119
|
+
* Creates a function that invokes `func`, with the `this` binding and arguments
|
2120
|
+
* of the created function, while it's called less than `n` times. Subsequent
|
2121
|
+
* calls to the created function return the result of the last `func` invocation.
|
2122
|
+
*
|
2123
|
+
* @static
|
2124
|
+
* @memberOf _
|
2125
|
+
* @category Function
|
2126
|
+
* @param {number} n The number of calls at which `func` is no longer invoked.
|
2127
|
+
* @param {Function} func The function to restrict.
|
2128
|
+
* @returns {Function} Returns the new restricted function.
|
2129
|
+
* @example
|
2130
|
+
*
|
2131
|
+
* jQuery(element).on('click', _.before(5, addContactToList));
|
2132
|
+
* // => allows adding up to 4 contacts to the list
|
2133
|
+
*/
|
2134
|
+
function before(n, func) {
|
2135
|
+
var result;
|
2136
|
+
if (typeof func != 'function') {
|
2137
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
2138
|
+
}
|
2139
|
+
n = toInteger(n);
|
2140
|
+
return function() {
|
2141
|
+
if (--n > 0) {
|
2142
|
+
result = func.apply(this, arguments);
|
2143
|
+
}
|
2144
|
+
if (n <= 1) {
|
2145
|
+
func = undefined;
|
2146
|
+
}
|
2147
|
+
return result;
|
2148
|
+
};
|
2149
|
+
}
|
2150
|
+
|
2151
|
+
/**
|
2152
|
+
* Creates a function that invokes `func` with the `this` binding of `thisArg`
|
2153
|
+
* and prepends any additional `_.bind` arguments to those provided to the
|
2154
|
+
* bound function.
|
2155
|
+
*
|
2156
|
+
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
2157
|
+
* may be used as a placeholder for partially applied arguments.
|
2158
|
+
*
|
2159
|
+
* **Note:** Unlike native `Function#bind` this method doesn't set the "length"
|
2160
|
+
* property of bound functions.
|
2161
|
+
*
|
2162
|
+
* @static
|
2163
|
+
* @memberOf _
|
2164
|
+
* @category Function
|
2165
|
+
* @param {Function} func The function to bind.
|
2166
|
+
* @param {*} thisArg The `this` binding of `func`.
|
2167
|
+
* @param {...*} [partials] The arguments to be partially applied.
|
2168
|
+
* @returns {Function} Returns the new bound function.
|
2169
|
+
* @example
|
2170
|
+
*
|
2171
|
+
* var greet = function(greeting, punctuation) {
|
2172
|
+
* return greeting + ' ' + this.user + punctuation;
|
2173
|
+
* };
|
2174
|
+
*
|
2175
|
+
* var object = { 'user': 'fred' };
|
2176
|
+
*
|
2177
|
+
* var bound = _.bind(greet, object, 'hi');
|
2178
|
+
* bound('!');
|
2179
|
+
* // => 'hi fred!'
|
2180
|
+
*
|
2181
|
+
* // using placeholders
|
2182
|
+
* var bound = _.bind(greet, object, _, '!');
|
2183
|
+
* bound('hi');
|
2184
|
+
* // => 'hi fred!'
|
2185
|
+
*/
|
2186
|
+
var bind = rest(function(func, thisArg, partials) {
|
2187
|
+
return createPartialWrapper(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
|
2188
|
+
});
|
2189
|
+
|
2190
|
+
/**
|
2191
|
+
* Defers invoking the `func` until the current call stack has cleared. Any
|
2192
|
+
* additional arguments are provided to `func` when it's invoked.
|
2193
|
+
*
|
2194
|
+
* @static
|
2195
|
+
* @memberOf _
|
2196
|
+
* @category Function
|
2197
|
+
* @param {Function} func The function to defer.
|
2198
|
+
* @param {...*} [args] The arguments to invoke `func` with.
|
2199
|
+
* @returns {number} Returns the timer id.
|
2200
|
+
* @example
|
2201
|
+
*
|
2202
|
+
* _.defer(function(text) {
|
2203
|
+
* console.log(text);
|
2204
|
+
* }, 'deferred');
|
2205
|
+
* // logs 'deferred' after one or more milliseconds
|
2206
|
+
*/
|
2207
|
+
var defer = rest(function(func, args) {
|
2208
|
+
return baseDelay(func, 1, args);
|
2209
|
+
});
|
2210
|
+
|
2211
|
+
/**
|
2212
|
+
* Invokes `func` after `wait` milliseconds. Any additional arguments are
|
2213
|
+
* provided to `func` when it's invoked.
|
2214
|
+
*
|
2215
|
+
* @static
|
2216
|
+
* @memberOf _
|
2217
|
+
* @category Function
|
2218
|
+
* @param {Function} func The function to delay.
|
2219
|
+
* @param {number} wait The number of milliseconds to delay invocation.
|
2220
|
+
* @param {...*} [args] The arguments to invoke `func` with.
|
2221
|
+
* @returns {number} Returns the timer id.
|
2222
|
+
* @example
|
2223
|
+
*
|
2224
|
+
* _.delay(function(text) {
|
2225
|
+
* console.log(text);
|
2226
|
+
* }, 1000, 'later');
|
2227
|
+
* // => logs 'later' after one second
|
2228
|
+
*/
|
2229
|
+
var delay = rest(function(func, wait, args) {
|
2230
|
+
return baseDelay(func, toNumber(wait) || 0, args);
|
2231
|
+
});
|
2232
|
+
|
2233
|
+
/**
|
2234
|
+
* Creates a function that negates the result of the predicate `func`. The
|
2235
|
+
* `func` predicate is invoked with the `this` binding and arguments of the
|
2236
|
+
* created function.
|
2237
|
+
*
|
2238
|
+
* @static
|
2239
|
+
* @memberOf _
|
2240
|
+
* @category Function
|
2241
|
+
* @param {Function} predicate The predicate to negate.
|
2242
|
+
* @returns {Function} Returns the new function.
|
2243
|
+
* @example
|
2244
|
+
*
|
2245
|
+
* function isEven(n) {
|
2246
|
+
* return n % 2 == 0;
|
2247
|
+
* }
|
2248
|
+
*
|
2249
|
+
* _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
|
2250
|
+
* // => [1, 3, 5]
|
2251
|
+
*/
|
2252
|
+
function negate(predicate) {
|
2253
|
+
if (typeof predicate != 'function') {
|
2254
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
2255
|
+
}
|
2256
|
+
return function() {
|
2257
|
+
return !predicate.apply(this, arguments);
|
2258
|
+
};
|
2259
|
+
}
|
2260
|
+
|
2261
|
+
/**
|
2262
|
+
* Creates a function that is restricted to invoking `func` once. Repeat calls
|
2263
|
+
* to the function return the value of the first invocation. The `func` is
|
2264
|
+
* invoked with the `this` binding and arguments of the created function.
|
2265
|
+
*
|
2266
|
+
* @static
|
2267
|
+
* @memberOf _
|
2268
|
+
* @category Function
|
2269
|
+
* @param {Function} func The function to restrict.
|
2270
|
+
* @returns {Function} Returns the new restricted function.
|
2271
|
+
* @example
|
2272
|
+
*
|
2273
|
+
* var initialize = _.once(createApplication);
|
2274
|
+
* initialize();
|
2275
|
+
* initialize();
|
2276
|
+
* // `initialize` invokes `createApplication` once
|
2277
|
+
*/
|
2278
|
+
function once(func) {
|
2279
|
+
return before(2, func);
|
2280
|
+
}
|
2281
|
+
|
2282
|
+
/**
|
2283
|
+
* Creates a function that invokes `func` with the `this` binding of the
|
2284
|
+
* created function and arguments from `start` and beyond provided as an array.
|
2285
|
+
*
|
2286
|
+
* **Note:** This method is based on the [rest parameter](https://mdn.io/rest_parameters).
|
2287
|
+
*
|
2288
|
+
* @static
|
2289
|
+
* @memberOf _
|
2290
|
+
* @category Function
|
2291
|
+
* @param {Function} func The function to apply a rest parameter to.
|
2292
|
+
* @param {number} [start=func.length-1] The start position of the rest parameter.
|
2293
|
+
* @returns {Function} Returns the new function.
|
2294
|
+
* @example
|
2295
|
+
*
|
2296
|
+
* var say = _.rest(function(what, names) {
|
2297
|
+
* return what + ' ' + _.initial(names).join(', ') +
|
2298
|
+
* (_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
2299
|
+
* });
|
2300
|
+
*
|
2301
|
+
* say('hello', 'fred', 'barney', 'pebbles');
|
2302
|
+
* // => 'hello fred, barney, & pebbles'
|
2303
|
+
*/
|
2304
|
+
function rest(func, start) {
|
2305
|
+
if (typeof func != 'function') {
|
2306
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
2307
|
+
}
|
2308
|
+
start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
|
2309
|
+
return function() {
|
2310
|
+
var args = arguments,
|
2311
|
+
index = -1,
|
2312
|
+
length = nativeMax(args.length - start, 0),
|
2313
|
+
array = Array(length);
|
2314
|
+
|
2315
|
+
while (++index < length) {
|
2316
|
+
array[index] = args[start + index];
|
2317
|
+
}
|
2318
|
+
var otherArgs = Array(start + 1);
|
2319
|
+
index = -1;
|
2320
|
+
while (++index < start) {
|
2321
|
+
otherArgs[index] = args[index];
|
2322
|
+
}
|
2323
|
+
otherArgs[start] = array;
|
2324
|
+
return func.apply(this, otherArgs);
|
2325
|
+
};
|
2326
|
+
}
|
2327
|
+
|
2328
|
+
/*------------------------------------------------------------------------*/
|
2329
|
+
|
2330
|
+
/**
|
2331
|
+
* Creates a shallow clone of `value`.
|
2332
|
+
*
|
2333
|
+
* **Note:** This method is loosely based on the
|
2334
|
+
* [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
|
2335
|
+
* and supports cloning arrays, array buffers, booleans, date objects, maps,
|
2336
|
+
* numbers, `Object` objects, regexes, sets, strings, symbols, and typed
|
2337
|
+
* arrays. The own enumerable properties of `arguments` objects are cloned
|
2338
|
+
* as plain objects. An empty object is returned for uncloneable values such
|
2339
|
+
* as error objects, functions, DOM nodes, and WeakMaps.
|
2340
|
+
*
|
2341
|
+
* @static
|
2342
|
+
* @memberOf _
|
2343
|
+
* @category Lang
|
2344
|
+
* @param {*} value The value to clone.
|
2345
|
+
* @returns {*} Returns the cloned value.
|
2346
|
+
* @example
|
2347
|
+
*
|
2348
|
+
* var objects = [{ 'a': 1 }, { 'b': 2 }];
|
2349
|
+
*
|
2350
|
+
* var shallow = _.clone(objects);
|
2351
|
+
* console.log(shallow[0] === objects[0]);
|
2352
|
+
* // => true
|
2353
|
+
*/
|
2354
|
+
function clone(value) {
|
2355
|
+
if (!isObject(value)) {
|
2356
|
+
return value;
|
2357
|
+
}
|
2358
|
+
return isArray(value) ? copyArray(value) : copyObject(value, keys(value));
|
2359
|
+
}
|
2360
|
+
|
2361
|
+
/**
|
2362
|
+
* Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
2363
|
+
* comparison between two values to determine if they are equivalent.
|
2364
|
+
*
|
2365
|
+
* @static
|
2366
|
+
* @memberOf _
|
2367
|
+
* @category Lang
|
2368
|
+
* @param {*} value The value to compare.
|
2369
|
+
* @param {*} other The other value to compare.
|
2370
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
2371
|
+
* @example
|
2372
|
+
*
|
2373
|
+
* var object = { 'user': 'fred' };
|
2374
|
+
* var other = { 'user': 'fred' };
|
2375
|
+
*
|
2376
|
+
* _.eq(object, object);
|
2377
|
+
* // => true
|
2378
|
+
*
|
2379
|
+
* _.eq(object, other);
|
2380
|
+
* // => false
|
2381
|
+
*
|
2382
|
+
* _.eq('a', 'a');
|
2383
|
+
* // => true
|
2384
|
+
*
|
2385
|
+
* _.eq('a', Object('a'));
|
2386
|
+
* // => false
|
2387
|
+
*
|
2388
|
+
* _.eq(NaN, NaN);
|
2389
|
+
* // => true
|
2390
|
+
*/
|
2391
|
+
function eq(value, other) {
|
2392
|
+
return value === other || (value !== value && other !== other);
|
2393
|
+
}
|
2394
|
+
|
2395
|
+
/**
|
2396
|
+
* Checks if `value` is greater than `other`.
|
2397
|
+
*
|
2398
|
+
* @static
|
2399
|
+
* @memberOf _
|
2400
|
+
* @category Lang
|
2401
|
+
* @param {*} value The value to compare.
|
2402
|
+
* @param {*} other The other value to compare.
|
2403
|
+
* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
|
2404
|
+
* @example
|
2405
|
+
*
|
2406
|
+
* _.gt(3, 1);
|
2407
|
+
* // => true
|
2408
|
+
*
|
2409
|
+
* _.gt(3, 3);
|
2410
|
+
* // => false
|
2411
|
+
*
|
2412
|
+
* _.gt(1, 3);
|
2413
|
+
* // => false
|
2414
|
+
*/
|
2415
|
+
function gt(value, other) {
|
2416
|
+
return value > other;
|
2417
|
+
}
|
2418
|
+
|
2419
|
+
/**
|
2420
|
+
* Checks if `value` is likely an `arguments` object.
|
2421
|
+
*
|
2422
|
+
* @static
|
2423
|
+
* @memberOf _
|
2424
|
+
* @category Lang
|
2425
|
+
* @param {*} value The value to check.
|
2426
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2427
|
+
* @example
|
2428
|
+
*
|
2429
|
+
* _.isArguments(function() { return arguments; }());
|
2430
|
+
* // => true
|
2431
|
+
*
|
2432
|
+
* _.isArguments([1, 2, 3]);
|
2433
|
+
* // => false
|
2434
|
+
*/
|
2435
|
+
function isArguments(value) {
|
2436
|
+
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
|
2437
|
+
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
|
2438
|
+
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
|
2439
|
+
}
|
2440
|
+
|
2441
|
+
/**
|
2442
|
+
* Checks if `value` is classified as an `Array` object.
|
2443
|
+
*
|
2444
|
+
* @static
|
2445
|
+
* @memberOf _
|
2446
|
+
* @type Function
|
2447
|
+
* @category Lang
|
2448
|
+
* @param {*} value The value to check.
|
2449
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2450
|
+
* @example
|
2451
|
+
*
|
2452
|
+
* _.isArray([1, 2, 3]);
|
2453
|
+
* // => true
|
2454
|
+
*
|
2455
|
+
* _.isArray(document.body.children);
|
2456
|
+
* // => false
|
2457
|
+
*
|
2458
|
+
* _.isArray('abc');
|
2459
|
+
* // => false
|
2460
|
+
*
|
2461
|
+
* _.isArray(_.noop);
|
2462
|
+
* // => false
|
2463
|
+
*/
|
2464
|
+
var isArray = Array.isArray;
|
2465
|
+
|
2466
|
+
/**
|
2467
|
+
* Checks if `value` is array-like. A value is considered array-like if it's
|
2468
|
+
* not a function and has a `value.length` that's an integer greater than or
|
2469
|
+
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
2470
|
+
*
|
2471
|
+
* @static
|
2472
|
+
* @memberOf _
|
2473
|
+
* @type Function
|
2474
|
+
* @category Lang
|
2475
|
+
* @param {*} value The value to check.
|
2476
|
+
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
2477
|
+
* @example
|
2478
|
+
*
|
2479
|
+
* _.isArrayLike([1, 2, 3]);
|
2480
|
+
* // => true
|
2481
|
+
*
|
2482
|
+
* _.isArrayLike(document.body.children);
|
2483
|
+
* // => true
|
2484
|
+
*
|
2485
|
+
* _.isArrayLike('abc');
|
2486
|
+
* // => true
|
2487
|
+
*
|
2488
|
+
* _.isArrayLike(_.noop);
|
2489
|
+
* // => false
|
2490
|
+
*/
|
2491
|
+
function isArrayLike(value) {
|
2492
|
+
return value != null &&
|
2493
|
+
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
|
2494
|
+
}
|
2495
|
+
|
2496
|
+
/**
|
2497
|
+
* This method is like `_.isArrayLike` except that it also checks if `value`
|
2498
|
+
* is an object.
|
2499
|
+
*
|
2500
|
+
* @static
|
2501
|
+
* @memberOf _
|
2502
|
+
* @type Function
|
2503
|
+
* @category Lang
|
2504
|
+
* @param {*} value The value to check.
|
2505
|
+
* @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
|
2506
|
+
* @example
|
2507
|
+
*
|
2508
|
+
* _.isArrayLikeObject([1, 2, 3]);
|
2509
|
+
* // => true
|
2510
|
+
*
|
2511
|
+
* _.isArrayLikeObject(document.body.children);
|
2512
|
+
* // => true
|
2513
|
+
*
|
2514
|
+
* _.isArrayLikeObject('abc');
|
2515
|
+
* // => false
|
2516
|
+
*
|
2517
|
+
* _.isArrayLikeObject(_.noop);
|
2518
|
+
* // => false
|
2519
|
+
*/
|
2520
|
+
function isArrayLikeObject(value) {
|
2521
|
+
return isObjectLike(value) && isArrayLike(value);
|
2522
|
+
}
|
2523
|
+
|
2524
|
+
/**
|
2525
|
+
* Checks if `value` is classified as a boolean primitive or object.
|
2526
|
+
*
|
2527
|
+
* @static
|
2528
|
+
* @memberOf _
|
2529
|
+
* @category Lang
|
2530
|
+
* @param {*} value The value to check.
|
2531
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2532
|
+
* @example
|
2533
|
+
*
|
2534
|
+
* _.isBoolean(false);
|
2535
|
+
* // => true
|
2536
|
+
*
|
2537
|
+
* _.isBoolean(null);
|
2538
|
+
* // => false
|
2539
|
+
*/
|
2540
|
+
function isBoolean(value) {
|
2541
|
+
return value === true || value === false ||
|
2542
|
+
(isObjectLike(value) && objectToString.call(value) == boolTag);
|
2543
|
+
}
|
2544
|
+
|
2545
|
+
/**
|
2546
|
+
* Checks if `value` is classified as a `Date` object.
|
2547
|
+
*
|
2548
|
+
* @static
|
2549
|
+
* @memberOf _
|
2550
|
+
* @category Lang
|
2551
|
+
* @param {*} value The value to check.
|
2552
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2553
|
+
* @example
|
2554
|
+
*
|
2555
|
+
* _.isDate(new Date);
|
2556
|
+
* // => true
|
2557
|
+
*
|
2558
|
+
* _.isDate('Mon April 23 2012');
|
2559
|
+
* // => false
|
2560
|
+
*/
|
2561
|
+
function isDate(value) {
|
2562
|
+
return isObjectLike(value) && objectToString.call(value) == dateTag;
|
2563
|
+
}
|
2564
|
+
|
2565
|
+
/**
|
2566
|
+
* Checks if `value` is empty. A value is considered empty unless it's an
|
2567
|
+
* `arguments` object, array, string, or jQuery-like collection with a length
|
2568
|
+
* greater than `0` or an object with own enumerable properties.
|
2569
|
+
*
|
2570
|
+
* @static
|
2571
|
+
* @memberOf _
|
2572
|
+
* @category Lang
|
2573
|
+
* @param {Array|Object|string} value The value to inspect.
|
2574
|
+
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
2575
|
+
* @example
|
2576
|
+
*
|
2577
|
+
* _.isEmpty(null);
|
2578
|
+
* // => true
|
2579
|
+
*
|
2580
|
+
* _.isEmpty(true);
|
2581
|
+
* // => true
|
2582
|
+
*
|
2583
|
+
* _.isEmpty(1);
|
2584
|
+
* // => true
|
2585
|
+
*
|
2586
|
+
* _.isEmpty([1, 2, 3]);
|
2587
|
+
* // => false
|
2588
|
+
*
|
2589
|
+
* _.isEmpty({ 'a': 1 });
|
2590
|
+
* // => false
|
2591
|
+
*/
|
2592
|
+
function isEmpty(value) {
|
2593
|
+
return (!isObjectLike(value) || isFunction(value.splice))
|
2594
|
+
? !size(value)
|
2595
|
+
: !keys(value).length;
|
2596
|
+
}
|
2597
|
+
|
2598
|
+
/**
|
2599
|
+
* Performs a deep comparison between two values to determine if they are
|
2600
|
+
* equivalent.
|
2601
|
+
*
|
2602
|
+
* **Note:** This method supports comparing arrays, array buffers, booleans,
|
2603
|
+
* date objects, error objects, maps, numbers, `Object` objects, regexes,
|
2604
|
+
* sets, strings, symbols, and typed arrays. `Object` objects are compared
|
2605
|
+
* by their own, not inherited, enumerable properties. Functions and DOM
|
2606
|
+
* nodes are **not** supported.
|
2607
|
+
*
|
2608
|
+
* @static
|
2609
|
+
* @memberOf _
|
2610
|
+
* @category Lang
|
2611
|
+
* @param {*} value The value to compare.
|
2612
|
+
* @param {*} other The other value to compare.
|
2613
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
2614
|
+
* @example
|
2615
|
+
*
|
2616
|
+
* var object = { 'user': 'fred' };
|
2617
|
+
* var other = { 'user': 'fred' };
|
2618
|
+
*
|
2619
|
+
* _.isEqual(object, other);
|
2620
|
+
* // => true
|
2621
|
+
*
|
2622
|
+
* object === other;
|
2623
|
+
* // => false
|
2624
|
+
*/
|
2625
|
+
function isEqual(value, other) {
|
2626
|
+
return baseIsEqual(value, other);
|
2627
|
+
}
|
2628
|
+
|
2629
|
+
/**
|
2630
|
+
* Checks if `value` is a finite primitive number.
|
2631
|
+
*
|
2632
|
+
* **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFinite).
|
2633
|
+
*
|
2634
|
+
* @static
|
2635
|
+
* @memberOf _
|
2636
|
+
* @category Lang
|
2637
|
+
* @param {*} value The value to check.
|
2638
|
+
* @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
|
2639
|
+
* @example
|
2640
|
+
*
|
2641
|
+
* _.isFinite(3);
|
2642
|
+
* // => true
|
2643
|
+
*
|
2644
|
+
* _.isFinite(Number.MAX_VALUE);
|
2645
|
+
* // => true
|
2646
|
+
*
|
2647
|
+
* _.isFinite(3.14);
|
2648
|
+
* // => true
|
2649
|
+
*
|
2650
|
+
* _.isFinite(Infinity);
|
2651
|
+
* // => false
|
2652
|
+
*/
|
2653
|
+
function isFinite(value) {
|
2654
|
+
return typeof value == 'number' && nativeIsFinite(value);
|
2655
|
+
}
|
2656
|
+
|
2657
|
+
/**
|
2658
|
+
* Checks if `value` is classified as a `Function` object.
|
2659
|
+
*
|
2660
|
+
* @static
|
2661
|
+
* @memberOf _
|
2662
|
+
* @category Lang
|
2663
|
+
* @param {*} value The value to check.
|
2664
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2665
|
+
* @example
|
2666
|
+
*
|
2667
|
+
* _.isFunction(_);
|
2668
|
+
* // => true
|
2669
|
+
*
|
2670
|
+
* _.isFunction(/abc/);
|
2671
|
+
* // => false
|
2672
|
+
*/
|
2673
|
+
function isFunction(value) {
|
2674
|
+
// The use of `Object#toString` avoids issues with the `typeof` operator
|
2675
|
+
// in Safari 8 which returns 'object' for typed array constructors, and
|
2676
|
+
// PhantomJS 1.9 which returns 'function' for `NodeList` instances.
|
2677
|
+
var tag = isObject(value) ? objectToString.call(value) : '';
|
2678
|
+
return tag == funcTag || tag == genTag;
|
2679
|
+
}
|
2680
|
+
|
2681
|
+
/**
|
2682
|
+
* Checks if `value` is a valid array-like length.
|
2683
|
+
*
|
2684
|
+
* **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
2685
|
+
*
|
2686
|
+
* @static
|
2687
|
+
* @memberOf _
|
2688
|
+
* @category Lang
|
2689
|
+
* @param {*} value The value to check.
|
2690
|
+
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
2691
|
+
* @example
|
2692
|
+
*
|
2693
|
+
* _.isLength(3);
|
2694
|
+
* // => true
|
2695
|
+
*
|
2696
|
+
* _.isLength(Number.MIN_VALUE);
|
2697
|
+
* // => false
|
2698
|
+
*
|
2699
|
+
* _.isLength(Infinity);
|
2700
|
+
* // => false
|
2701
|
+
*
|
2702
|
+
* _.isLength('3');
|
2703
|
+
* // => false
|
2704
|
+
*/
|
2705
|
+
function isLength(value) {
|
2706
|
+
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
2707
|
+
}
|
2708
|
+
|
2709
|
+
/**
|
2710
|
+
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
2711
|
+
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
2712
|
+
*
|
2713
|
+
* @static
|
2714
|
+
* @memberOf _
|
2715
|
+
* @category Lang
|
2716
|
+
* @param {*} value The value to check.
|
2717
|
+
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
2718
|
+
* @example
|
2719
|
+
*
|
2720
|
+
* _.isObject({});
|
2721
|
+
* // => true
|
2722
|
+
*
|
2723
|
+
* _.isObject([1, 2, 3]);
|
2724
|
+
* // => true
|
2725
|
+
*
|
2726
|
+
* _.isObject(_.noop);
|
2727
|
+
* // => true
|
2728
|
+
*
|
2729
|
+
* _.isObject(null);
|
2730
|
+
* // => false
|
2731
|
+
*/
|
2732
|
+
function isObject(value) {
|
2733
|
+
// Avoid a V8 JIT bug in Chrome 19-20.
|
2734
|
+
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
2735
|
+
var type = typeof value;
|
2736
|
+
return !!value && (type == 'object' || type == 'function');
|
2737
|
+
}
|
2738
|
+
|
2739
|
+
/**
|
2740
|
+
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
2741
|
+
* and has a `typeof` result of "object".
|
2742
|
+
*
|
2743
|
+
* @static
|
2744
|
+
* @memberOf _
|
2745
|
+
* @category Lang
|
2746
|
+
* @param {*} value The value to check.
|
2747
|
+
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
2748
|
+
* @example
|
2749
|
+
*
|
2750
|
+
* _.isObjectLike({});
|
2751
|
+
* // => true
|
2752
|
+
*
|
2753
|
+
* _.isObjectLike([1, 2, 3]);
|
2754
|
+
* // => true
|
2755
|
+
*
|
2756
|
+
* _.isObjectLike(_.noop);
|
2757
|
+
* // => false
|
2758
|
+
*
|
2759
|
+
* _.isObjectLike(null);
|
2760
|
+
* // => false
|
2761
|
+
*/
|
2762
|
+
function isObjectLike(value) {
|
2763
|
+
return !!value && typeof value == 'object';
|
2764
|
+
}
|
2765
|
+
|
2766
|
+
/**
|
2767
|
+
* Checks if `value` is `NaN`.
|
2768
|
+
*
|
2769
|
+
* **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
|
2770
|
+
* which returns `true` for `undefined` and other non-numeric values.
|
2771
|
+
*
|
2772
|
+
* @static
|
2773
|
+
* @memberOf _
|
2774
|
+
* @category Lang
|
2775
|
+
* @param {*} value The value to check.
|
2776
|
+
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
2777
|
+
* @example
|
2778
|
+
*
|
2779
|
+
* _.isNaN(NaN);
|
2780
|
+
* // => true
|
2781
|
+
*
|
2782
|
+
* _.isNaN(new Number(NaN));
|
2783
|
+
* // => true
|
2784
|
+
*
|
2785
|
+
* isNaN(undefined);
|
2786
|
+
* // => true
|
2787
|
+
*
|
2788
|
+
* _.isNaN(undefined);
|
2789
|
+
* // => false
|
2790
|
+
*/
|
2791
|
+
function isNaN(value) {
|
2792
|
+
// An `NaN` primitive is the only value that is not equal to itself.
|
2793
|
+
// Perform the `toStringTag` check first to avoid errors with some ActiveX objects in IE.
|
2794
|
+
return isNumber(value) && value != +value;
|
2795
|
+
}
|
2796
|
+
|
2797
|
+
/**
|
2798
|
+
* Checks if `value` is `null`.
|
2799
|
+
*
|
2800
|
+
* @static
|
2801
|
+
* @memberOf _
|
2802
|
+
* @category Lang
|
2803
|
+
* @param {*} value The value to check.
|
2804
|
+
* @returns {boolean} Returns `true` if `value` is `null`, else `false`.
|
2805
|
+
* @example
|
2806
|
+
*
|
2807
|
+
* _.isNull(null);
|
2808
|
+
* // => true
|
2809
|
+
*
|
2810
|
+
* _.isNull(void 0);
|
2811
|
+
* // => false
|
2812
|
+
*/
|
2813
|
+
function isNull(value) {
|
2814
|
+
return value === null;
|
2815
|
+
}
|
2816
|
+
|
2817
|
+
/**
|
2818
|
+
* Checks if `value` is classified as a `Number` primitive or object.
|
2819
|
+
*
|
2820
|
+
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
|
2821
|
+
* as numbers, use the `_.isFinite` method.
|
2822
|
+
*
|
2823
|
+
* @static
|
2824
|
+
* @memberOf _
|
2825
|
+
* @category Lang
|
2826
|
+
* @param {*} value The value to check.
|
2827
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2828
|
+
* @example
|
2829
|
+
*
|
2830
|
+
* _.isNumber(3);
|
2831
|
+
* // => true
|
2832
|
+
*
|
2833
|
+
* _.isNumber(Number.MIN_VALUE);
|
2834
|
+
* // => true
|
2835
|
+
*
|
2836
|
+
* _.isNumber(Infinity);
|
2837
|
+
* // => true
|
2838
|
+
*
|
2839
|
+
* _.isNumber('3');
|
2840
|
+
* // => false
|
2841
|
+
*/
|
2842
|
+
function isNumber(value) {
|
2843
|
+
return typeof value == 'number' ||
|
2844
|
+
(isObjectLike(value) && objectToString.call(value) == numberTag);
|
2845
|
+
}
|
2846
|
+
|
2847
|
+
/**
|
2848
|
+
* Checks if `value` is classified as a `RegExp` object.
|
2849
|
+
*
|
2850
|
+
* @static
|
2851
|
+
* @memberOf _
|
2852
|
+
* @category Lang
|
2853
|
+
* @param {*} value The value to check.
|
2854
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2855
|
+
* @example
|
2856
|
+
*
|
2857
|
+
* _.isRegExp(/abc/);
|
2858
|
+
* // => true
|
2859
|
+
*
|
2860
|
+
* _.isRegExp('/abc/');
|
2861
|
+
* // => false
|
2862
|
+
*/
|
2863
|
+
function isRegExp(value) {
|
2864
|
+
return isObject(value) && objectToString.call(value) == regexpTag;
|
2865
|
+
}
|
2866
|
+
|
2867
|
+
/**
|
2868
|
+
* Checks if `value` is classified as a `String` primitive or object.
|
2869
|
+
*
|
2870
|
+
* @static
|
2871
|
+
* @memberOf _
|
2872
|
+
* @category Lang
|
2873
|
+
* @param {*} value The value to check.
|
2874
|
+
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
2875
|
+
* @example
|
2876
|
+
*
|
2877
|
+
* _.isString('abc');
|
2878
|
+
* // => true
|
2879
|
+
*
|
2880
|
+
* _.isString(1);
|
2881
|
+
* // => false
|
2882
|
+
*/
|
2883
|
+
function isString(value) {
|
2884
|
+
return typeof value == 'string' ||
|
2885
|
+
(!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
|
2886
|
+
}
|
2887
|
+
|
2888
|
+
/**
|
2889
|
+
* Checks if `value` is `undefined`.
|
2890
|
+
*
|
2891
|
+
* @static
|
2892
|
+
* @memberOf _
|
2893
|
+
* @category Lang
|
2894
|
+
* @param {*} value The value to check.
|
2895
|
+
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
|
2896
|
+
* @example
|
2897
|
+
*
|
2898
|
+
* _.isUndefined(void 0);
|
2899
|
+
* // => true
|
2900
|
+
*
|
2901
|
+
* _.isUndefined(null);
|
2902
|
+
* // => false
|
2903
|
+
*/
|
2904
|
+
function isUndefined(value) {
|
2905
|
+
return value === undefined;
|
2906
|
+
}
|
2907
|
+
|
2908
|
+
/**
|
2909
|
+
* Checks if `value` is less than `other`.
|
2910
|
+
*
|
2911
|
+
* @static
|
2912
|
+
* @memberOf _
|
2913
|
+
* @category Lang
|
2914
|
+
* @param {*} value The value to compare.
|
2915
|
+
* @param {*} other The other value to compare.
|
2916
|
+
* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
|
2917
|
+
* @example
|
2918
|
+
*
|
2919
|
+
* _.lt(1, 3);
|
2920
|
+
* // => true
|
2921
|
+
*
|
2922
|
+
* _.lt(3, 3);
|
2923
|
+
* // => false
|
2924
|
+
*
|
2925
|
+
* _.lt(3, 1);
|
2926
|
+
* // => false
|
2927
|
+
*/
|
2928
|
+
function lt(value, other) {
|
2929
|
+
return value < other;
|
2930
|
+
}
|
2931
|
+
|
2932
|
+
/**
|
2933
|
+
* Converts `value` to an array.
|
2934
|
+
*
|
2935
|
+
* @static
|
2936
|
+
* @memberOf _
|
2937
|
+
* @category Lang
|
2938
|
+
* @param {*} value The value to convert.
|
2939
|
+
* @returns {Array} Returns the converted array.
|
2940
|
+
* @example
|
2941
|
+
*
|
2942
|
+
* _.toArray({ 'a': 1, 'b': 2 });
|
2943
|
+
* // => [1, 2]
|
2944
|
+
*
|
2945
|
+
* _.toArray('abc');
|
2946
|
+
* // => ['a', 'b', 'c']
|
2947
|
+
*
|
2948
|
+
* _.toArray(1);
|
2949
|
+
* // => []
|
2950
|
+
*
|
2951
|
+
* _.toArray(null);
|
2952
|
+
* // => []
|
2953
|
+
*/
|
2954
|
+
function toArray(value) {
|
2955
|
+
if (!isArrayLike(value)) {
|
2956
|
+
return values(value);
|
2957
|
+
}
|
2958
|
+
return value.length ? copyArray(value) : [];
|
2959
|
+
}
|
2960
|
+
|
2961
|
+
/**
|
2962
|
+
* Converts `value` to an integer.
|
2963
|
+
*
|
2964
|
+
* **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
|
2965
|
+
*
|
2966
|
+
* @static
|
2967
|
+
* @memberOf _
|
2968
|
+
* @category Lang
|
2969
|
+
* @param {*} value The value to convert.
|
2970
|
+
* @returns {number} Returns the converted integer.
|
2971
|
+
* @example
|
2972
|
+
*
|
2973
|
+
* _.toInteger(3);
|
2974
|
+
* // => 3
|
2975
|
+
*
|
2976
|
+
* _.toInteger(Number.MIN_VALUE);
|
2977
|
+
* // => 0
|
2978
|
+
*
|
2979
|
+
* _.toInteger(Infinity);
|
2980
|
+
* // => 1.7976931348623157e+308
|
2981
|
+
*
|
2982
|
+
* _.toInteger('3');
|
2983
|
+
* // => 3
|
2984
|
+
*/
|
2985
|
+
var toInteger = Number;
|
2986
|
+
|
2987
|
+
/**
|
2988
|
+
* Converts `value` to a number.
|
2989
|
+
*
|
2990
|
+
* @static
|
2991
|
+
* @memberOf _
|
2992
|
+
* @category Lang
|
2993
|
+
* @param {*} value The value to process.
|
2994
|
+
* @returns {number} Returns the number.
|
2995
|
+
* @example
|
2996
|
+
*
|
2997
|
+
* _.toNumber(3);
|
2998
|
+
* // => 3
|
2999
|
+
*
|
3000
|
+
* _.toNumber(Number.MIN_VALUE);
|
3001
|
+
* // => 5e-324
|
3002
|
+
*
|
3003
|
+
* _.toNumber(Infinity);
|
3004
|
+
* // => Infinity
|
3005
|
+
*
|
3006
|
+
* _.toNumber('3');
|
3007
|
+
* // => 3
|
3008
|
+
*/
|
3009
|
+
var toNumber = Number;
|
3010
|
+
|
3011
|
+
/**
|
3012
|
+
* Converts `value` to a string if it's not one. An empty string is returned
|
3013
|
+
* for `null` and `undefined` values. The sign of `-0` is preserved.
|
3014
|
+
*
|
3015
|
+
* @static
|
3016
|
+
* @memberOf _
|
3017
|
+
* @category Lang
|
3018
|
+
* @param {*} value The value to process.
|
3019
|
+
* @returns {string} Returns the string.
|
3020
|
+
* @example
|
3021
|
+
*
|
3022
|
+
* _.toString(null);
|
3023
|
+
* // => ''
|
3024
|
+
*
|
3025
|
+
* _.toString(-0);
|
3026
|
+
* // => '-0'
|
3027
|
+
*
|
3028
|
+
* _.toString([1, 2, 3]);
|
3029
|
+
* // => '1,2,3'
|
3030
|
+
*/
|
3031
|
+
function toString(value) {
|
3032
|
+
if (typeof value == 'string') {
|
3033
|
+
return value;
|
3034
|
+
}
|
3035
|
+
return value == null ? '' : (value + '');
|
3036
|
+
}
|
3037
|
+
|
3038
|
+
/*------------------------------------------------------------------------*/
|
3039
|
+
|
3040
|
+
/**
|
3041
|
+
* Assigns own enumerable properties of source objects to the destination
|
3042
|
+
* object. Source objects are applied from left to right. Subsequent sources
|
3043
|
+
* overwrite property assignments of previous sources.
|
3044
|
+
*
|
3045
|
+
* **Note:** This method mutates `object` and is loosely based on
|
3046
|
+
* [`Object.assign`](https://mdn.io/Object/assign).
|
3047
|
+
*
|
3048
|
+
* @static
|
3049
|
+
* @memberOf _
|
3050
|
+
* @category Object
|
3051
|
+
* @param {Object} object The destination object.
|
3052
|
+
* @param {...Object} [sources] The source objects.
|
3053
|
+
* @returns {Object} Returns `object`.
|
3054
|
+
* @example
|
3055
|
+
*
|
3056
|
+
* function Foo() {
|
3057
|
+
* this.c = 3;
|
3058
|
+
* }
|
3059
|
+
*
|
3060
|
+
* function Bar() {
|
3061
|
+
* this.e = 5;
|
3062
|
+
* }
|
3063
|
+
*
|
3064
|
+
* Foo.prototype.d = 4;
|
3065
|
+
* Bar.prototype.f = 6;
|
3066
|
+
*
|
3067
|
+
* _.assign({ 'a': 1 }, new Foo, new Bar);
|
3068
|
+
* // => { 'a': 1, 'c': 3, 'e': 5 }
|
3069
|
+
*/
|
3070
|
+
var assign = createAssigner(function(object, source) {
|
3071
|
+
copyObject(source, keys(source), object);
|
3072
|
+
});
|
3073
|
+
|
3074
|
+
/**
|
3075
|
+
* This method is like `_.assign` except that it iterates over own and
|
3076
|
+
* inherited source properties.
|
3077
|
+
*
|
3078
|
+
* **Note:** This method mutates `object`.
|
3079
|
+
*
|
3080
|
+
* @static
|
3081
|
+
* @memberOf _
|
3082
|
+
* @alias extend
|
3083
|
+
* @category Object
|
3084
|
+
* @param {Object} object The destination object.
|
3085
|
+
* @param {...Object} [sources] The source objects.
|
3086
|
+
* @returns {Object} Returns `object`.
|
3087
|
+
* @example
|
3088
|
+
*
|
3089
|
+
* function Foo() {
|
3090
|
+
* this.b = 2;
|
3091
|
+
* }
|
3092
|
+
*
|
3093
|
+
* function Bar() {
|
3094
|
+
* this.d = 4;
|
3095
|
+
* }
|
3096
|
+
*
|
3097
|
+
* Foo.prototype.c = 3;
|
3098
|
+
* Bar.prototype.e = 5;
|
3099
|
+
*
|
3100
|
+
* _.assignIn({ 'a': 1 }, new Foo, new Bar);
|
3101
|
+
* // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
|
3102
|
+
*/
|
3103
|
+
var assignIn = createAssigner(function(object, source) {
|
3104
|
+
copyObject(source, keysIn(source), object);
|
3105
|
+
});
|
3106
|
+
|
3107
|
+
/**
|
3108
|
+
* This method is like `_.assignIn` except that it accepts `customizer` which
|
3109
|
+
* is invoked to produce the assigned values. If `customizer` returns `undefined`
|
3110
|
+
* assignment is handled by the method instead. The `customizer` is invoked
|
3111
|
+
* with five arguments: (objValue, srcValue, key, object, source).
|
3112
|
+
*
|
3113
|
+
* **Note:** This method mutates `object`.
|
3114
|
+
*
|
3115
|
+
* @static
|
3116
|
+
* @memberOf _
|
3117
|
+
* @alias extendWith
|
3118
|
+
* @category Object
|
3119
|
+
* @param {Object} object The destination object.
|
3120
|
+
* @param {...Object} sources The source objects.
|
3121
|
+
* @param {Function} [customizer] The function to customize assigned values.
|
3122
|
+
* @returns {Object} Returns `object`.
|
3123
|
+
* @example
|
3124
|
+
*
|
3125
|
+
* function customizer(objValue, srcValue) {
|
3126
|
+
* return _.isUndefined(objValue) ? srcValue : objValue;
|
3127
|
+
* }
|
3128
|
+
*
|
3129
|
+
* var defaults = _.partialRight(_.assignInWith, customizer);
|
3130
|
+
*
|
3131
|
+
* defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
3132
|
+
* // => { 'a': 1, 'b': 2 }
|
3133
|
+
*/
|
3134
|
+
var assignInWith = createAssigner(function(object, source, customizer) {
|
3135
|
+
copyObjectWith(source, keysIn(source), object, customizer);
|
3136
|
+
});
|
3137
|
+
|
3138
|
+
/**
|
3139
|
+
* Creates an object that inherits from the `prototype` object. If a `properties`
|
3140
|
+
* object is provided its own enumerable properties are assigned to the created object.
|
3141
|
+
*
|
3142
|
+
* @static
|
3143
|
+
* @memberOf _
|
3144
|
+
* @category Object
|
3145
|
+
* @param {Object} prototype The object to inherit from.
|
3146
|
+
* @param {Object} [properties] The properties to assign to the object.
|
3147
|
+
* @returns {Object} Returns the new object.
|
3148
|
+
* @example
|
3149
|
+
*
|
3150
|
+
* function Shape() {
|
3151
|
+
* this.x = 0;
|
3152
|
+
* this.y = 0;
|
3153
|
+
* }
|
3154
|
+
*
|
3155
|
+
* function Circle() {
|
3156
|
+
* Shape.call(this);
|
3157
|
+
* }
|
3158
|
+
*
|
3159
|
+
* Circle.prototype = _.create(Shape.prototype, {
|
3160
|
+
* 'constructor': Circle
|
3161
|
+
* });
|
3162
|
+
*
|
3163
|
+
* var circle = new Circle;
|
3164
|
+
* circle instanceof Circle;
|
3165
|
+
* // => true
|
3166
|
+
*
|
3167
|
+
* circle instanceof Shape;
|
3168
|
+
* // => true
|
3169
|
+
*/
|
3170
|
+
function create(prototype, properties) {
|
3171
|
+
var result = baseCreate(prototype);
|
3172
|
+
return properties ? assign(result, properties) : result;
|
3173
|
+
}
|
3174
|
+
|
3175
|
+
/**
|
3176
|
+
* Assigns own and inherited enumerable properties of source objects to the
|
3177
|
+
* destination object for all destination properties that resolve to `undefined`.
|
3178
|
+
* Source objects are applied from left to right. Once a property is set,
|
3179
|
+
* additional values of the same property are ignored.
|
3180
|
+
*
|
3181
|
+
* **Note:** This method mutates `object`.
|
3182
|
+
*
|
3183
|
+
* @static
|
3184
|
+
* @memberOf _
|
3185
|
+
* @category Object
|
3186
|
+
* @param {Object} object The destination object.
|
3187
|
+
* @param {...Object} [sources] The source objects.
|
3188
|
+
* @returns {Object} Returns `object`.
|
3189
|
+
* @example
|
3190
|
+
*
|
3191
|
+
* _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
|
3192
|
+
* // => { 'user': 'barney', 'age': 36 }
|
3193
|
+
*/
|
3194
|
+
var defaults = rest(function(args) {
|
3195
|
+
args.push(undefined, assignInDefaults);
|
3196
|
+
return assignInWith.apply(undefined, args);
|
3197
|
+
});
|
3198
|
+
|
3199
|
+
/**
|
3200
|
+
* Checks if `path` is a direct property of `object`.
|
3201
|
+
*
|
3202
|
+
* @static
|
3203
|
+
* @memberOf _
|
3204
|
+
* @category Object
|
3205
|
+
* @param {Object} object The object to query.
|
3206
|
+
* @param {Array|string} path The path to check.
|
3207
|
+
* @returns {boolean} Returns `true` if `path` exists, else `false`.
|
3208
|
+
* @example
|
3209
|
+
*
|
3210
|
+
* var object = { 'a': { 'b': { 'c': 3 } } };
|
3211
|
+
* var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) });
|
3212
|
+
*
|
3213
|
+
* _.has(object, 'a');
|
3214
|
+
* // => true
|
3215
|
+
*
|
3216
|
+
* _.has(object, 'a.b.c');
|
3217
|
+
* // => true
|
3218
|
+
*
|
3219
|
+
* _.has(object, ['a', 'b', 'c']);
|
3220
|
+
* // => true
|
3221
|
+
*
|
3222
|
+
* _.has(other, 'a');
|
3223
|
+
* // => false
|
3224
|
+
*/
|
3225
|
+
function has(object, path) {
|
3226
|
+
return object != null && hasOwnProperty.call(object, path);
|
3227
|
+
}
|
3228
|
+
|
3229
|
+
/**
|
3230
|
+
* Creates an array of the own enumerable property names of `object`.
|
3231
|
+
*
|
3232
|
+
* **Note:** Non-object values are coerced to objects. See the
|
3233
|
+
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
|
3234
|
+
* for more details.
|
3235
|
+
*
|
3236
|
+
* @static
|
3237
|
+
* @memberOf _
|
3238
|
+
* @category Object
|
3239
|
+
* @param {Object} object The object to query.
|
3240
|
+
* @returns {Array} Returns the array of property names.
|
3241
|
+
* @example
|
3242
|
+
*
|
3243
|
+
* function Foo() {
|
3244
|
+
* this.a = 1;
|
3245
|
+
* this.b = 2;
|
3246
|
+
* }
|
3247
|
+
*
|
3248
|
+
* Foo.prototype.c = 3;
|
3249
|
+
*
|
3250
|
+
* _.keys(new Foo);
|
3251
|
+
* // => ['a', 'b'] (iteration order is not guaranteed)
|
3252
|
+
*
|
3253
|
+
* _.keys('hi');
|
3254
|
+
* // => ['0', '1']
|
3255
|
+
*/
|
3256
|
+
function keys(object) {
|
3257
|
+
var isProto = isPrototype(object);
|
3258
|
+
if (!(isProto || isArrayLike(object))) {
|
3259
|
+
return baseKeys(object);
|
3260
|
+
}
|
3261
|
+
var indexes = indexKeys(object),
|
3262
|
+
skipIndexes = !!indexes,
|
3263
|
+
result = indexes || [],
|
3264
|
+
length = result.length;
|
3265
|
+
|
3266
|
+
for (var key in object) {
|
3267
|
+
if (hasOwnProperty.call(object, key) &&
|
3268
|
+
!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
|
3269
|
+
!(isProto && key == 'constructor')) {
|
3270
|
+
result.push(key);
|
3271
|
+
}
|
3272
|
+
}
|
3273
|
+
return result;
|
3274
|
+
}
|
3275
|
+
|
3276
|
+
/**
|
3277
|
+
* Creates an array of the own and inherited enumerable property names of `object`.
|
3278
|
+
*
|
3279
|
+
* **Note:** Non-object values are coerced to objects.
|
3280
|
+
*
|
3281
|
+
* @static
|
3282
|
+
* @memberOf _
|
3283
|
+
* @category Object
|
3284
|
+
* @param {Object} object The object to query.
|
3285
|
+
* @returns {Array} Returns the array of property names.
|
3286
|
+
* @example
|
3287
|
+
*
|
3288
|
+
* function Foo() {
|
3289
|
+
* this.a = 1;
|
3290
|
+
* this.b = 2;
|
3291
|
+
* }
|
3292
|
+
*
|
3293
|
+
* Foo.prototype.c = 3;
|
3294
|
+
*
|
3295
|
+
* _.keysIn(new Foo);
|
3296
|
+
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
3297
|
+
*/
|
3298
|
+
function keysIn(object) {
|
3299
|
+
var index = -1,
|
3300
|
+
isProto = isPrototype(object),
|
3301
|
+
props = baseKeysIn(object),
|
3302
|
+
propsLength = props.length,
|
3303
|
+
indexes = indexKeys(object),
|
3304
|
+
skipIndexes = !!indexes,
|
3305
|
+
result = indexes || [],
|
3306
|
+
length = result.length;
|
3307
|
+
|
3308
|
+
while (++index < propsLength) {
|
3309
|
+
var key = props[index];
|
3310
|
+
if (!(skipIndexes && (key == 'length' || isIndex(key, length))) &&
|
3311
|
+
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
3312
|
+
result.push(key);
|
3313
|
+
}
|
3314
|
+
}
|
3315
|
+
return result;
|
3316
|
+
}
|
3317
|
+
|
3318
|
+
/**
|
3319
|
+
* Creates an object composed of the picked `object` properties.
|
3320
|
+
*
|
3321
|
+
* @static
|
3322
|
+
* @memberOf _
|
3323
|
+
* @category Object
|
3324
|
+
* @param {Object} object The source object.
|
3325
|
+
* @param {...(string|string[])} [props] The property names to pick, specified
|
3326
|
+
* individually or in arrays.
|
3327
|
+
* @returns {Object} Returns the new object.
|
3328
|
+
* @example
|
3329
|
+
*
|
3330
|
+
* var object = { 'a': 1, 'b': '2', 'c': 3 };
|
3331
|
+
*
|
3332
|
+
* _.pick(object, ['a', 'c']);
|
3333
|
+
* // => { 'a': 1, 'c': 3 }
|
3334
|
+
*/
|
3335
|
+
var pick = rest(function(object, props) {
|
3336
|
+
return object == null ? {} : basePick(object, baseFlatten(props));
|
3337
|
+
});
|
3338
|
+
|
3339
|
+
/**
|
3340
|
+
* This method is like `_.get` except that if the resolved value is a function
|
3341
|
+
* it's invoked with the `this` binding of its parent object and its result
|
3342
|
+
* is returned.
|
3343
|
+
*
|
3344
|
+
* @static
|
3345
|
+
* @memberOf _
|
3346
|
+
* @category Object
|
3347
|
+
* @param {Object} object The object to query.
|
3348
|
+
* @param {Array|string} path The path of the property to resolve.
|
3349
|
+
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
|
3350
|
+
* @returns {*} Returns the resolved value.
|
3351
|
+
* @example
|
3352
|
+
*
|
3353
|
+
* var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
|
3354
|
+
*
|
3355
|
+
* _.result(object, 'a[0].b.c1');
|
3356
|
+
* // => 3
|
3357
|
+
*
|
3358
|
+
* _.result(object, 'a[0].b.c2');
|
3359
|
+
* // => 4
|
3360
|
+
*
|
3361
|
+
* _.result(object, 'a[0].b.c3', 'default');
|
3362
|
+
* // => 'default'
|
3363
|
+
*
|
3364
|
+
* _.result(object, 'a[0].b.c3', _.constant('default'));
|
3365
|
+
* // => 'default'
|
3366
|
+
*/
|
3367
|
+
function result(object, path, defaultValue) {
|
3368
|
+
var value = object == null ? undefined : object[path];
|
3369
|
+
if (value === undefined) {
|
3370
|
+
value = defaultValue;
|
3371
|
+
}
|
3372
|
+
return isFunction(value) ? value.call(object) : value;
|
3373
|
+
}
|
3374
|
+
|
3375
|
+
/**
|
3376
|
+
* Creates an array of the own enumerable property values of `object`.
|
3377
|
+
*
|
3378
|
+
* **Note:** Non-object values are coerced to objects.
|
3379
|
+
*
|
3380
|
+
* @static
|
3381
|
+
* @memberOf _
|
3382
|
+
* @category Object
|
3383
|
+
* @param {Object} object The object to query.
|
3384
|
+
* @returns {Array} Returns the array of property values.
|
3385
|
+
* @example
|
3386
|
+
*
|
3387
|
+
* function Foo() {
|
3388
|
+
* this.a = 1;
|
3389
|
+
* this.b = 2;
|
3390
|
+
* }
|
3391
|
+
*
|
3392
|
+
* Foo.prototype.c = 3;
|
3393
|
+
*
|
3394
|
+
* _.values(new Foo);
|
3395
|
+
* // => [1, 2] (iteration order is not guaranteed)
|
3396
|
+
*
|
3397
|
+
* _.values('hi');
|
3398
|
+
* // => ['h', 'i']
|
3399
|
+
*/
|
3400
|
+
function values(object) {
|
3401
|
+
return object ? baseValues(object, keys(object)) : [];
|
3402
|
+
}
|
3403
|
+
|
3404
|
+
/*------------------------------------------------------------------------*/
|
3405
|
+
|
3406
|
+
/**
|
3407
|
+
* Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
|
3408
|
+
* their corresponding HTML entities.
|
3409
|
+
*
|
3410
|
+
* **Note:** No other characters are escaped. To escape additional
|
3411
|
+
* characters use a third-party library like [_he_](https://mths.be/he).
|
3412
|
+
*
|
3413
|
+
* Though the ">" character is escaped for symmetry, characters like
|
3414
|
+
* ">" and "/" don't need escaping in HTML and have no special meaning
|
3415
|
+
* unless they're part of a tag or unquoted attribute value.
|
3416
|
+
* See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
|
3417
|
+
* (under "semi-related fun fact") for more details.
|
3418
|
+
*
|
3419
|
+
* Backticks are escaped because in IE < 9, they can break out of
|
3420
|
+
* attribute values or HTML comments. See [#59](https://html5sec.org/#59),
|
3421
|
+
* [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
|
3422
|
+
* [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
|
3423
|
+
* for more details.
|
3424
|
+
*
|
3425
|
+
* When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
|
3426
|
+
* to reduce XSS vectors.
|
3427
|
+
*
|
3428
|
+
* @static
|
3429
|
+
* @memberOf _
|
3430
|
+
* @category String
|
3431
|
+
* @param {string} [string=''] The string to escape.
|
3432
|
+
* @returns {string} Returns the escaped string.
|
3433
|
+
* @example
|
3434
|
+
*
|
3435
|
+
* _.escape('fred, barney, & pebbles');
|
3436
|
+
* // => 'fred, barney, & pebbles'
|
3437
|
+
*/
|
3438
|
+
function escape(string) {
|
3439
|
+
string = toString(string);
|
3440
|
+
return (string && reHasUnescapedHtml.test(string))
|
3441
|
+
? string.replace(reUnescapedHtml, escapeHtmlChar)
|
3442
|
+
: string;
|
3443
|
+
}
|
3444
|
+
|
3445
|
+
/*------------------------------------------------------------------------*/
|
3446
|
+
|
3447
|
+
/**
|
3448
|
+
* This method returns the first argument provided to it.
|
3449
|
+
*
|
3450
|
+
* @static
|
3451
|
+
* @memberOf _
|
3452
|
+
* @category Util
|
3453
|
+
* @param {*} value Any value.
|
3454
|
+
* @returns {*} Returns `value`.
|
3455
|
+
* @example
|
3456
|
+
*
|
3457
|
+
* var object = { 'user': 'fred' };
|
3458
|
+
*
|
3459
|
+
* _.identity(object) === object;
|
3460
|
+
* // => true
|
3461
|
+
*/
|
3462
|
+
function identity(value) {
|
3463
|
+
return value;
|
3464
|
+
}
|
3465
|
+
|
3466
|
+
/**
|
3467
|
+
* Creates a function that invokes `func` with the arguments of the created
|
3468
|
+
* function. If `func` is a property name the created callback returns the
|
3469
|
+
* property value for a given element. If `func` is an object the created
|
3470
|
+
* callback returns `true` for elements that contain the equivalent object properties, otherwise it returns `false`.
|
3471
|
+
*
|
3472
|
+
* @static
|
3473
|
+
* @memberOf _
|
3474
|
+
* @category Util
|
3475
|
+
* @param {*} [func=_.identity] The value to convert to a callback.
|
3476
|
+
* @returns {Function} Returns the callback.
|
3477
|
+
* @example
|
3478
|
+
*
|
3479
|
+
* var users = [
|
3480
|
+
* { 'user': 'barney', 'age': 36 },
|
3481
|
+
* { 'user': 'fred', 'age': 40 }
|
3482
|
+
* ];
|
3483
|
+
*
|
3484
|
+
* // create custom iteratee shorthands
|
3485
|
+
* _.iteratee = _.wrap(_.iteratee, function(callback, func) {
|
3486
|
+
* var p = /^(\S+)\s*([<>])\s*(\S+)$/.exec(func);
|
3487
|
+
* return !p ? callback(func) : function(object) {
|
3488
|
+
* return (p[2] == '>' ? object[p[1]] > p[3] : object[p[1]] < p[3]);
|
3489
|
+
* };
|
3490
|
+
* });
|
3491
|
+
*
|
3492
|
+
* _.filter(users, 'age > 36');
|
3493
|
+
* // => [{ 'user': 'fred', 'age': 40 }]
|
3494
|
+
*/
|
3495
|
+
var iteratee = baseIteratee;
|
3496
|
+
|
3497
|
+
/**
|
3498
|
+
* Adds all own enumerable function properties of a source object to the
|
3499
|
+
* destination object. If `object` is a function then methods are added to
|
3500
|
+
* its prototype as well.
|
3501
|
+
*
|
3502
|
+
* **Note:** Use `_.runInContext` to create a pristine `lodash` function to
|
3503
|
+
* avoid conflicts caused by modifying the original.
|
3504
|
+
*
|
3505
|
+
* @static
|
3506
|
+
* @memberOf _
|
3507
|
+
* @category Util
|
3508
|
+
* @param {Function|Object} [object=lodash] The destination object.
|
3509
|
+
* @param {Object} source The object of functions to add.
|
3510
|
+
* @param {Object} [options] The options object.
|
3511
|
+
* @param {boolean} [options.chain=true] Specify whether the functions added
|
3512
|
+
* are chainable.
|
3513
|
+
* @returns {Function|Object} Returns `object`.
|
3514
|
+
* @example
|
3515
|
+
*
|
3516
|
+
* function vowels(string) {
|
3517
|
+
* return _.filter(string, function(v) {
|
3518
|
+
* return /[aeiou]/i.test(v);
|
3519
|
+
* });
|
3520
|
+
* }
|
3521
|
+
*
|
3522
|
+
* _.mixin({ 'vowels': vowels });
|
3523
|
+
* _.vowels('fred');
|
3524
|
+
* // => ['e']
|
3525
|
+
*
|
3526
|
+
* _('fred').vowels().value();
|
3527
|
+
* // => ['e']
|
3528
|
+
*
|
3529
|
+
* _.mixin({ 'vowels': vowels }, { 'chain': false });
|
3530
|
+
* _('fred').vowels();
|
3531
|
+
* // => ['e']
|
3532
|
+
*/
|
3533
|
+
function mixin(object, source, options) {
|
3534
|
+
var props = keys(source),
|
3535
|
+
methodNames = baseFunctions(source, props);
|
3536
|
+
|
3537
|
+
if (options == null &&
|
3538
|
+
!(isObject(source) && (methodNames.length || !props.length))) {
|
3539
|
+
options = source;
|
3540
|
+
source = object;
|
3541
|
+
object = this;
|
3542
|
+
methodNames = baseFunctions(source, keys(source));
|
3543
|
+
}
|
3544
|
+
var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
|
3545
|
+
isFunc = isFunction(object);
|
3546
|
+
|
3547
|
+
baseEach(methodNames, function(methodName) {
|
3548
|
+
var func = source[methodName];
|
3549
|
+
object[methodName] = func;
|
3550
|
+
if (isFunc) {
|
3551
|
+
object.prototype[methodName] = function() {
|
3552
|
+
var chainAll = this.__chain__;
|
3553
|
+
if (chain || chainAll) {
|
3554
|
+
var result = object(this.__wrapped__),
|
3555
|
+
actions = result.__actions__ = copyArray(this.__actions__);
|
3556
|
+
|
3557
|
+
actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
3558
|
+
result.__chain__ = chainAll;
|
3559
|
+
return result;
|
3560
|
+
}
|
3561
|
+
return func.apply(object, arrayPush([this.value()], arguments));
|
3562
|
+
};
|
3563
|
+
}
|
3564
|
+
});
|
3565
|
+
|
3566
|
+
return object;
|
3567
|
+
}
|
3568
|
+
|
3569
|
+
/**
|
3570
|
+
* Reverts the `_` variable to its previous value and returns a reference to
|
3571
|
+
* the `lodash` function.
|
3572
|
+
*
|
3573
|
+
* @static
|
3574
|
+
* @memberOf _
|
3575
|
+
* @category Util
|
3576
|
+
* @returns {Function} Returns the `lodash` function.
|
3577
|
+
* @example
|
3578
|
+
*
|
3579
|
+
* var lodash = _.noConflict();
|
3580
|
+
*/
|
3581
|
+
function noConflict() {
|
3582
|
+
root._ = oldDash;
|
3583
|
+
return this;
|
3584
|
+
}
|
3585
|
+
|
3586
|
+
/**
|
3587
|
+
* A no-operation function that returns `undefined` regardless of the
|
3588
|
+
* arguments it receives.
|
3589
|
+
*
|
3590
|
+
* @static
|
3591
|
+
* @memberOf _
|
3592
|
+
* @category Util
|
3593
|
+
* @example
|
3594
|
+
*
|
3595
|
+
* var object = { 'user': 'fred' };
|
3596
|
+
*
|
3597
|
+
* _.noop(object) === undefined;
|
3598
|
+
* // => true
|
3599
|
+
*/
|
3600
|
+
function noop() {
|
3601
|
+
// No operation performed.
|
3602
|
+
}
|
3603
|
+
|
3604
|
+
/**
|
3605
|
+
* Generates a unique ID. If `prefix` is provided the ID is appended to it.
|
3606
|
+
*
|
3607
|
+
* @static
|
3608
|
+
* @memberOf _
|
3609
|
+
* @category Util
|
3610
|
+
* @param {string} [prefix] The value to prefix the ID with.
|
3611
|
+
* @returns {string} Returns the unique ID.
|
3612
|
+
* @example
|
3613
|
+
*
|
3614
|
+
* _.uniqueId('contact_');
|
3615
|
+
* // => 'contact_104'
|
3616
|
+
*
|
3617
|
+
* _.uniqueId();
|
3618
|
+
* // => '105'
|
3619
|
+
*/
|
3620
|
+
function uniqueId(prefix) {
|
3621
|
+
var id = ++idCounter;
|
3622
|
+
return toString(prefix) + id;
|
3623
|
+
}
|
3624
|
+
|
3625
|
+
/*------------------------------------------------------------------------*/
|
3626
|
+
|
3627
|
+
/**
|
3628
|
+
* Computes the maximum value of `array`. If `array` is empty or falsey
|
3629
|
+
* `undefined` is returned.
|
3630
|
+
*
|
3631
|
+
* @static
|
3632
|
+
* @memberOf _
|
3633
|
+
* @category Math
|
3634
|
+
* @param {Array} array The array to iterate over.
|
3635
|
+
* @returns {*} Returns the maximum value.
|
3636
|
+
* @example
|
3637
|
+
*
|
3638
|
+
* _.max([4, 2, 8, 6]);
|
3639
|
+
* // => 8
|
3640
|
+
*
|
3641
|
+
* _.max([]);
|
3642
|
+
* // => undefined
|
3643
|
+
*/
|
3644
|
+
function max(array) {
|
3645
|
+
return (array && array.length)
|
3646
|
+
? baseExtremum(array, identity, gt)
|
3647
|
+
: undefined;
|
3648
|
+
}
|
3649
|
+
|
3650
|
+
/**
|
3651
|
+
* Computes the minimum value of `array`. If `array` is empty or falsey
|
3652
|
+
* `undefined` is returned.
|
3653
|
+
*
|
3654
|
+
* @static
|
3655
|
+
* @memberOf _
|
3656
|
+
* @category Math
|
3657
|
+
* @param {Array} array The array to iterate over.
|
3658
|
+
* @returns {*} Returns the minimum value.
|
3659
|
+
* @example
|
3660
|
+
*
|
3661
|
+
* _.min([4, 2, 8, 6]);
|
3662
|
+
* // => 2
|
3663
|
+
*
|
3664
|
+
* _.min([]);
|
3665
|
+
* // => undefined
|
3666
|
+
*/
|
3667
|
+
function min(array) {
|
3668
|
+
return (array && array.length)
|
3669
|
+
? baseExtremum(array, identity, lt)
|
3670
|
+
: undefined;
|
3671
|
+
}
|
3672
|
+
|
3673
|
+
/*------------------------------------------------------------------------*/
|
3674
|
+
|
3675
|
+
LodashWrapper.prototype = baseCreate(lodash.prototype);
|
3676
|
+
LodashWrapper.prototype.constructor = LodashWrapper;
|
3677
|
+
|
3678
|
+
// Add functions that return wrapped values when chaining.
|
3679
|
+
lodash.assignIn = assignIn;
|
3680
|
+
lodash.before = before;
|
3681
|
+
lodash.bind = bind;
|
3682
|
+
lodash.chain = chain;
|
3683
|
+
lodash.compact = compact;
|
3684
|
+
lodash.concat = concat;
|
3685
|
+
lodash.create = create;
|
3686
|
+
lodash.defaults = defaults;
|
3687
|
+
lodash.defer = defer;
|
3688
|
+
lodash.delay = delay;
|
3689
|
+
lodash.filter = filter;
|
3690
|
+
lodash.flatten = flatten;
|
3691
|
+
lodash.flattenDeep = flattenDeep;
|
3692
|
+
lodash.invokeMap = invokeMap;
|
3693
|
+
lodash.iteratee = iteratee;
|
3694
|
+
lodash.keys = keys;
|
3695
|
+
lodash.map = map;
|
3696
|
+
lodash.mixin = mixin;
|
3697
|
+
lodash.negate = negate;
|
3698
|
+
lodash.once = once;
|
3699
|
+
lodash.pick = pick;
|
3700
|
+
lodash.slice = slice;
|
3701
|
+
lodash.sortBy = sortBy;
|
3702
|
+
lodash.tap = tap;
|
3703
|
+
lodash.thru = thru;
|
3704
|
+
lodash.toArray = toArray;
|
3705
|
+
lodash.values = values;
|
3706
|
+
|
3707
|
+
// Add aliases.
|
3708
|
+
lodash.each = forEach;
|
3709
|
+
lodash.extend = assignIn;
|
3710
|
+
|
3711
|
+
// Add functions to `lodash.prototype`.
|
3712
|
+
mixin(lodash, lodash);
|
3713
|
+
|
3714
|
+
/*------------------------------------------------------------------------*/
|
3715
|
+
|
3716
|
+
// Add functions that return unwrapped values when chaining.
|
3717
|
+
lodash.clone = clone;
|
3718
|
+
lodash.escape = escape;
|
3719
|
+
lodash.every = every;
|
3720
|
+
lodash.find = find;
|
3721
|
+
lodash.forEach = forEach;
|
3722
|
+
lodash.has = has;
|
3723
|
+
lodash.head = head;
|
3724
|
+
lodash.identity = identity;
|
3725
|
+
lodash.indexOf = indexOf;
|
3726
|
+
lodash.isArguments = isArguments;
|
3727
|
+
lodash.isArray = isArray;
|
3728
|
+
lodash.isBoolean = isBoolean;
|
3729
|
+
lodash.isDate = isDate;
|
3730
|
+
lodash.isEmpty = isEmpty;
|
3731
|
+
lodash.isEqual = isEqual;
|
3732
|
+
lodash.isFinite = isFinite;
|
3733
|
+
lodash.isFunction = isFunction;
|
3734
|
+
lodash.isNaN = isNaN;
|
3735
|
+
lodash.isNull = isNull;
|
3736
|
+
lodash.isNumber = isNumber;
|
3737
|
+
lodash.isObject = isObject;
|
3738
|
+
lodash.isRegExp = isRegExp;
|
3739
|
+
lodash.isString = isString;
|
3740
|
+
lodash.isUndefined = isUndefined;
|
3741
|
+
lodash.last = last;
|
3742
|
+
lodash.max = max;
|
3743
|
+
lodash.min = min;
|
3744
|
+
lodash.noConflict = noConflict;
|
3745
|
+
lodash.noop = noop;
|
3746
|
+
lodash.now = now;
|
3747
|
+
lodash.reduce = reduce;
|
3748
|
+
lodash.result = result;
|
3749
|
+
lodash.size = size;
|
3750
|
+
lodash.some = some;
|
3751
|
+
lodash.uniqueId = uniqueId;
|
3752
|
+
|
3753
|
+
// Add aliases.
|
3754
|
+
lodash.first = head;
|
3755
|
+
|
3756
|
+
mixin(lodash, (function() {
|
3757
|
+
var source = {};
|
3758
|
+
baseForOwn(lodash, function(func, methodName) {
|
3759
|
+
if (!hasOwnProperty.call(lodash.prototype, methodName)) {
|
3760
|
+
source[methodName] = func;
|
3761
|
+
}
|
3762
|
+
});
|
3763
|
+
return source;
|
3764
|
+
}()), { 'chain': false });
|
3765
|
+
|
3766
|
+
/*------------------------------------------------------------------------*/
|
3767
|
+
|
3768
|
+
/**
|
3769
|
+
* The semantic version number.
|
3770
|
+
*
|
3771
|
+
* @static
|
3772
|
+
* @memberOf _
|
3773
|
+
* @type string
|
3774
|
+
*/
|
3775
|
+
lodash.VERSION = VERSION;
|
3776
|
+
|
3777
|
+
// Add `Array` and `String` methods to `lodash.prototype`.
|
3778
|
+
baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
|
3779
|
+
var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
|
3780
|
+
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
|
3781
|
+
retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
|
3782
|
+
|
3783
|
+
lodash.prototype[methodName] = function() {
|
3784
|
+
var args = arguments;
|
3785
|
+
if (retUnwrapped && !this.__chain__) {
|
3786
|
+
return func.apply(this.value(), args);
|
3787
|
+
}
|
3788
|
+
return this[chainName](function(value) {
|
3789
|
+
return func.apply(value, args);
|
3790
|
+
});
|
3791
|
+
};
|
3792
|
+
});
|
3793
|
+
|
3794
|
+
// Add chaining functions to the `lodash` wrapper.
|
3795
|
+
lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
3796
|
+
|
3797
|
+
/*--------------------------------------------------------------------------*/
|
3798
|
+
|
3799
|
+
// Expose lodash on the free variable `window` or `self` when available. This
|
3800
|
+
// prevents errors in cases where lodash is loaded by a script tag in the presence
|
3801
|
+
// of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for more details.
|
3802
|
+
(freeWindow || freeSelf || {})._ = lodash;
|
3803
|
+
|
3804
|
+
// Some AMD build optimizers like r.js check for condition patterns like the following:
|
3805
|
+
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
3806
|
+
// Define as an anonymous module so, through path mapping, it can be
|
3807
|
+
// referenced as the "underscore" module.
|
3808
|
+
define(function() {
|
3809
|
+
return lodash;
|
3810
|
+
});
|
3811
|
+
}
|
3812
|
+
// Check for `exports` after `define` in case a build optimizer adds an `exports` object.
|
3813
|
+
else if (freeExports && freeModule) {
|
3814
|
+
// Export for Node.js.
|
3815
|
+
if (moduleExports) {
|
3816
|
+
(freeModule.exports = lodash)._ = lodash;
|
3817
|
+
}
|
3818
|
+
// Export for CommonJS support.
|
3819
|
+
freeExports._ = lodash;
|
3820
|
+
}
|
3821
|
+
else {
|
3822
|
+
// Export to the global object.
|
3823
|
+
root._ = lodash;
|
3824
|
+
}
|
3825
|
+
}.call(this));
|