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