1 | /**
|
2 | * lodash (Custom Build) <https://lodash.com/>
|
3 | * Build: `lodash modularize exports="npm" -o ./`
|
4 | * Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
5 | * Released under MIT license <https://lodash.com/license>
|
6 | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
7 | * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
8 | */
|
9 |
|
10 | /** Used as the size to enable large array optimizations. */
|
11 | var LARGE_ARRAY_SIZE = 200;
|
12 |
|
13 | /** Used to stand-in for `undefined` hash values. */
|
14 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
15 |
|
16 | /** Used as references for various `Number` constants. */
|
17 | var MAX_SAFE_INTEGER = 9007199254740991;
|
18 |
|
19 | /** `Object#toString` result references. */
|
20 | var funcTag = '[object Function]',
|
21 | genTag = '[object GeneratorFunction]';
|
22 |
|
23 | /**
|
24 | * Used to match `RegExp`
|
25 | * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
|
26 | */
|
27 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
28 |
|
29 | /** Used to detect host constructors (Safari). */
|
30 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
31 |
|
32 | /** Detect free variable `global` from Node.js. */
|
33 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
34 |
|
35 | /** Detect free variable `self`. */
|
36 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
37 |
|
38 | /** Used as a reference to the global object. */
|
39 | var root = freeGlobal || freeSelf || Function('return this')();
|
40 |
|
41 | /**
|
42 | * A faster alternative to `Function#apply`, this function invokes `func`
|
43 | * with the `this` binding of `thisArg` and the arguments of `args`.
|
44 | *
|
45 | * @private
|
46 | * @param {Function} func The function to invoke.
|
47 | * @param {*} thisArg The `this` binding of `func`.
|
48 | * @param {Array} args The arguments to invoke `func` with.
|
49 | * @returns {*} Returns the result of `func`.
|
50 | */
|
51 | function apply(func, thisArg, args) {
|
52 | switch (args.length) {
|
53 | case 0: return func.call(thisArg);
|
54 | case 1: return func.call(thisArg, args[0]);
|
55 | case 2: return func.call(thisArg, args[0], args[1]);
|
56 | case 3: return func.call(thisArg, args[0], args[1], args[2]);
|
57 | }
|
58 | return func.apply(thisArg, args);
|
59 | }
|
60 |
|
61 | /**
|
62 | * A specialized version of `_.includes` for arrays without support for
|
63 | * specifying an index to search from.
|
64 | *
|
65 | * @private
|
66 | * @param {Array} [array] The array to search.
|
67 | * @param {*} target The value to search for.
|
68 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
69 | */
|
70 | function arrayIncludes(array, value) {
|
71 | var length = array ? array.length : 0;
|
72 | return !!length && baseIndexOf(array, value, 0) > -1;
|
73 | }
|
74 |
|
75 | /**
|
76 | * This function is like `arrayIncludes` except that it accepts a comparator.
|
77 | *
|
78 | * @private
|
79 | * @param {Array} [array] The array to search.
|
80 | * @param {*} target The value to search for.
|
81 | * @param {Function} comparator The comparator invoked per element.
|
82 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
83 | */
|
84 | function arrayIncludesWith(array, value, comparator) {
|
85 | var index = -1,
|
86 | length = array ? array.length : 0;
|
87 |
|
88 | while (++index < length) {
|
89 | if (comparator(value, array[index])) {
|
90 | return true;
|
91 | }
|
92 | }
|
93 | return false;
|
94 | }
|
95 |
|
96 | /**
|
97 | * A specialized version of `_.map` for arrays without support for iteratee
|
98 | * shorthands.
|
99 | *
|
100 | * @private
|
101 | * @param {Array} [array] The array to iterate over.
|
102 | * @param {Function} iteratee The function invoked per iteration.
|
103 | * @returns {Array} Returns the new mapped array.
|
104 | */
|
105 | function arrayMap(array, iteratee) {
|
106 | var index = -1,
|
107 | length = array ? array.length : 0,
|
108 | result = Array(length);
|
109 |
|
110 | while (++index < length) {
|
111 | result[index] = iteratee(array[index], index, array);
|
112 | }
|
113 | return result;
|
114 | }
|
115 |
|
116 | /**
|
117 | * The base implementation of `_.findIndex` and `_.findLastIndex` without
|
118 | * support for iteratee shorthands.
|
119 | *
|
120 | * @private
|
121 | * @param {Array} array The array to search.
|
122 | * @param {Function} predicate The function invoked per iteration.
|
123 | * @param {number} fromIndex The index to search from.
|
124 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
125 | * @returns {number} Returns the index of the matched value, else `-1`.
|
126 | */
|
127 | function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
128 | var length = array.length,
|
129 | index = fromIndex + (fromRight ? 1 : -1);
|
130 |
|
131 | while ((fromRight ? index-- : ++index < length)) {
|
132 | if (predicate(array[index], index, array)) {
|
133 | return index;
|
134 | }
|
135 | }
|
136 | return -1;
|
137 | }
|
138 |
|
139 | /**
|
140 | * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
|
141 | *
|
142 | * @private
|
143 | * @param {Array} array The array to search.
|
144 | * @param {*} value The value to search for.
|
145 | * @param {number} fromIndex The index to search from.
|
146 | * @returns {number} Returns the index of the matched value, else `-1`.
|
147 | */
|
148 | function baseIndexOf(array, value, fromIndex) {
|
149 | if (value !== value) {
|
150 | return baseFindIndex(array, baseIsNaN, fromIndex);
|
151 | }
|
152 | var index = fromIndex - 1,
|
153 | length = array.length;
|
154 |
|
155 | while (++index < length) {
|
156 | if (array[index] === value) {
|
157 | return index;
|
158 | }
|
159 | }
|
160 | return -1;
|
161 | }
|
162 |
|
163 | /**
|
164 | * The base implementation of `_.isNaN` without support for number objects.
|
165 | *
|
166 | * @private
|
167 | * @param {*} value The value to check.
|
168 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
169 | */
|
170 | function baseIsNaN(value) {
|
171 | return value !== value;
|
172 | }
|
173 |
|
174 | /**
|
175 | * The base implementation of `_.property` without support for deep paths.
|
176 | *
|
177 | * @private
|
178 | * @param {string} key The key of the property to get.
|
179 | * @returns {Function} Returns the new accessor function.
|
180 | */
|
181 | function baseProperty(key) {
|
182 | return function(object) {
|
183 | return object == null ? undefined : object[key];
|
184 | };
|
185 | }
|
186 |
|
187 | /**
|
188 | * The base implementation of `_.unary` without support for storing metadata.
|
189 | *
|
190 | * @private
|
191 | * @param {Function} func The function to cap arguments for.
|
192 | * @returns {Function} Returns the new capped function.
|
193 | */
|
194 | function baseUnary(func) {
|
195 | return function(value) {
|
196 | return func(value);
|
197 | };
|
198 | }
|
199 |
|
200 | /**
|
201 | * Checks if a cache value for `key` exists.
|
202 | *
|
203 | * @private
|
204 | * @param {Object} cache The cache to query.
|
205 | * @param {string} key The key of the entry to check.
|
206 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
207 | */
|
208 | function cacheHas(cache, key) {
|
209 | return cache.has(key);
|
210 | }
|
211 |
|
212 | /**
|
213 | * Gets the value at `key` of `object`.
|
214 | *
|
215 | * @private
|
216 | * @param {Object} [object] The object to query.
|
217 | * @param {string} key The key of the property to get.
|
218 | * @returns {*} Returns the property value.
|
219 | */
|
220 | function getValue(object, key) {
|
221 | return object == null ? undefined : object[key];
|
222 | }
|
223 |
|
224 | /**
|
225 | * Checks if `value` is a host object in IE < 9.
|
226 | *
|
227 | * @private
|
228 | * @param {*} value The value to check.
|
229 | * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
230 | */
|
231 | function isHostObject(value) {
|
232 | // Many host objects are `Object` objects that can coerce to strings
|
233 | // despite having improperly defined `toString` methods.
|
234 | var result = false;
|
235 | if (value != null && typeof value.toString != 'function') {
|
236 | try {
|
237 | result = !!(value + '');
|
238 | } catch (e) {}
|
239 | }
|
240 | return result;
|
241 | }
|
242 |
|
243 | /** Used for built-in method references. */
|
244 | var arrayProto = Array.prototype,
|
245 | objectProto = Object.prototype;
|
246 |
|
247 | /** Used to detect overreaching core-js shims. */
|
248 | var coreJsData = root['__core-js_shared__'];
|
249 |
|
250 | /** Used to detect methods masquerading as native. */
|
251 | var maskSrcKey = (function() {
|
252 | var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
253 | return uid ? ('Symbol(src)_1.' + uid) : '';
|
254 | }());
|
255 |
|
256 | /** Used to resolve the decompiled source of functions. */
|
257 | var funcToString = Function.prototype.toString;
|
258 |
|
259 | /** Used to check objects for own properties. */
|
260 | var hasOwnProperty = objectProto.hasOwnProperty;
|
261 |
|
262 | /**
|
263 | * Used to resolve the
|
264 | * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
265 | * of values.
|
266 | */
|
267 | var objectToString = objectProto.toString;
|
268 |
|
269 | /** Used to detect if a method is native. */
|
270 | var reIsNative = RegExp('^' +
|
271 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
272 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
273 | );
|
274 |
|
275 | /** Built-in value references. */
|
276 | var splice = arrayProto.splice;
|
277 |
|
278 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
279 | var nativeMax = Math.max;
|
280 |
|
281 | /* Built-in method references that are verified to be native. */
|
282 | var Map = getNative(root, 'Map'),
|
283 | nativeCreate = getNative(Object, 'create');
|
284 |
|
285 | /**
|
286 | * Creates a hash object.
|
287 | *
|
288 | * @private
|
289 | * @constructor
|
290 | * @param {Array} [entries] The key-value pairs to cache.
|
291 | */
|
292 | function Hash(entries) {
|
293 | var index = -1,
|
294 | length = entries ? entries.length : 0;
|
295 |
|
296 | this.clear();
|
297 | while (++index < length) {
|
298 | var entry = entries[index];
|
299 | this.set(entry[0], entry[1]);
|
300 | }
|
301 | }
|
302 |
|
303 | /**
|
304 | * Removes all key-value entries from the hash.
|
305 | *
|
306 | * @private
|
307 | * @name clear
|
308 | * @memberOf Hash
|
309 | */
|
310 | function hashClear() {
|
311 | this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
312 | }
|
313 |
|
314 | /**
|
315 | * Removes `key` and its value from the hash.
|
316 | *
|
317 | * @private
|
318 | * @name delete
|
319 | * @memberOf Hash
|
320 | * @param {Object} hash The hash to modify.
|
321 | * @param {string} key The key of the value to remove.
|
322 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
323 | */
|
324 | function hashDelete(key) {
|
325 | return this.has(key) && delete this.__data__[key];
|
326 | }
|
327 |
|
328 | /**
|
329 | * Gets the hash value for `key`.
|
330 | *
|
331 | * @private
|
332 | * @name get
|
333 | * @memberOf Hash
|
334 | * @param {string} key The key of the value to get.
|
335 | * @returns {*} Returns the entry value.
|
336 | */
|
337 | function hashGet(key) {
|
338 | var data = this.__data__;
|
339 | if (nativeCreate) {
|
340 | var result = data[key];
|
341 | return result === HASH_UNDEFINED ? undefined : result;
|
342 | }
|
343 | return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
344 | }
|
345 |
|
346 | /**
|
347 | * Checks if a hash value for `key` exists.
|
348 | *
|
349 | * @private
|
350 | * @name has
|
351 | * @memberOf Hash
|
352 | * @param {string} key The key of the entry to check.
|
353 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
354 | */
|
355 | function hashHas(key) {
|
356 | var data = this.__data__;
|
357 | return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
|
358 | }
|
359 |
|
360 | /**
|
361 | * Sets the hash `key` to `value`.
|
362 | *
|
363 | * @private
|
364 | * @name set
|
365 | * @memberOf Hash
|
366 | * @param {string} key The key of the value to set.
|
367 | * @param {*} value The value to set.
|
368 | * @returns {Object} Returns the hash instance.
|
369 | */
|
370 | function hashSet(key, value) {
|
371 | var data = this.__data__;
|
372 | data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
373 | return this;
|
374 | }
|
375 |
|
376 | // Add methods to `Hash`.
|
377 | Hash.prototype.clear = hashClear;
|
378 | Hash.prototype['delete'] = hashDelete;
|
379 | Hash.prototype.get = hashGet;
|
380 | Hash.prototype.has = hashHas;
|
381 | Hash.prototype.set = hashSet;
|
382 |
|
383 | /**
|
384 | * Creates an list cache object.
|
385 | *
|
386 | * @private
|
387 | * @constructor
|
388 | * @param {Array} [entries] The key-value pairs to cache.
|
389 | */
|
390 | function ListCache(entries) {
|
391 | var index = -1,
|
392 | length = entries ? entries.length : 0;
|
393 |
|
394 | this.clear();
|
395 | while (++index < length) {
|
396 | var entry = entries[index];
|
397 | this.set(entry[0], entry[1]);
|
398 | }
|
399 | }
|
400 |
|
401 | /**
|
402 | * Removes all key-value entries from the list cache.
|
403 | *
|
404 | * @private
|
405 | * @name clear
|
406 | * @memberOf ListCache
|
407 | */
|
408 | function listCacheClear() {
|
409 | this.__data__ = [];
|
410 | }
|
411 |
|
412 | /**
|
413 | * Removes `key` and its value from the list cache.
|
414 | *
|
415 | * @private
|
416 | * @name delete
|
417 | * @memberOf ListCache
|
418 | * @param {string} key The key of the value to remove.
|
419 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
420 | */
|
421 | function listCacheDelete(key) {
|
422 | var data = this.__data__,
|
423 | index = assocIndexOf(data, key);
|
424 |
|
425 | if (index < 0) {
|
426 | return false;
|
427 | }
|
428 | var lastIndex = data.length - 1;
|
429 | if (index == lastIndex) {
|
430 | data.pop();
|
431 | } else {
|
432 | splice.call(data, index, 1);
|
433 | }
|
434 | return true;
|
435 | }
|
436 |
|
437 | /**
|
438 | * Gets the list cache value for `key`.
|
439 | *
|
440 | * @private
|
441 | * @name get
|
442 | * @memberOf ListCache
|
443 | * @param {string} key The key of the value to get.
|
444 | * @returns {*} Returns the entry value.
|
445 | */
|
446 | function listCacheGet(key) {
|
447 | var data = this.__data__,
|
448 | index = assocIndexOf(data, key);
|
449 |
|
450 | return index < 0 ? undefined : data[index][1];
|
451 | }
|
452 |
|
453 | /**
|
454 | * Checks if a list cache value for `key` exists.
|
455 | *
|
456 | * @private
|
457 | * @name has
|
458 | * @memberOf ListCache
|
459 | * @param {string} key The key of the entry to check.
|
460 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
461 | */
|
462 | function listCacheHas(key) {
|
463 | return assocIndexOf(this.__data__, key) > -1;
|
464 | }
|
465 |
|
466 | /**
|
467 | * Sets the list cache `key` to `value`.
|
468 | *
|
469 | * @private
|
470 | * @name set
|
471 | * @memberOf ListCache
|
472 | * @param {string} key The key of the value to set.
|
473 | * @param {*} value The value to set.
|
474 | * @returns {Object} Returns the list cache instance.
|
475 | */
|
476 | function listCacheSet(key, value) {
|
477 | var data = this.__data__,
|
478 | index = assocIndexOf(data, key);
|
479 |
|
480 | if (index < 0) {
|
481 | data.push([key, value]);
|
482 | } else {
|
483 | data[index][1] = value;
|
484 | }
|
485 | return this;
|
486 | }
|
487 |
|
488 | // Add methods to `ListCache`.
|
489 | ListCache.prototype.clear = listCacheClear;
|
490 | ListCache.prototype['delete'] = listCacheDelete;
|
491 | ListCache.prototype.get = listCacheGet;
|
492 | ListCache.prototype.has = listCacheHas;
|
493 | ListCache.prototype.set = listCacheSet;
|
494 |
|
495 | /**
|
496 | * Creates a map cache object to store key-value pairs.
|
497 | *
|
498 | * @private
|
499 | * @constructor
|
500 | * @param {Array} [entries] The key-value pairs to cache.
|
501 | */
|
502 | function MapCache(entries) {
|
503 | var index = -1,
|
504 | length = entries ? entries.length : 0;
|
505 |
|
506 | this.clear();
|
507 | while (++index < length) {
|
508 | var entry = entries[index];
|
509 | this.set(entry[0], entry[1]);
|
510 | }
|
511 | }
|
512 |
|
513 | /**
|
514 | * Removes all key-value entries from the map.
|
515 | *
|
516 | * @private
|
517 | * @name clear
|
518 | * @memberOf MapCache
|
519 | */
|
520 | function mapCacheClear() {
|
521 | this.__data__ = {
|
522 | 'hash': new Hash,
|
523 | 'map': new (Map || ListCache),
|
524 | 'string': new Hash
|
525 | };
|
526 | }
|
527 |
|
528 | /**
|
529 | * Removes `key` and its value from the map.
|
530 | *
|
531 | * @private
|
532 | * @name delete
|
533 | * @memberOf MapCache
|
534 | * @param {string} key The key of the value to remove.
|
535 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
536 | */
|
537 | function mapCacheDelete(key) {
|
538 | return getMapData(this, key)['delete'](key);
|
539 | }
|
540 |
|
541 | /**
|
542 | * Gets the map value for `key`.
|
543 | *
|
544 | * @private
|
545 | * @name get
|
546 | * @memberOf MapCache
|
547 | * @param {string} key The key of the value to get.
|
548 | * @returns {*} Returns the entry value.
|
549 | */
|
550 | function mapCacheGet(key) {
|
551 | return getMapData(this, key).get(key);
|
552 | }
|
553 |
|
554 | /**
|
555 | * Checks if a map value for `key` exists.
|
556 | *
|
557 | * @private
|
558 | * @name has
|
559 | * @memberOf MapCache
|
560 | * @param {string} key The key of the entry to check.
|
561 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
562 | */
|
563 | function mapCacheHas(key) {
|
564 | return getMapData(this, key).has(key);
|
565 | }
|
566 |
|
567 | /**
|
568 | * Sets the map `key` to `value`.
|
569 | *
|
570 | * @private
|
571 | * @name set
|
572 | * @memberOf MapCache
|
573 | * @param {string} key The key of the value to set.
|
574 | * @param {*} value The value to set.
|
575 | * @returns {Object} Returns the map cache instance.
|
576 | */
|
577 | function mapCacheSet(key, value) {
|
578 | getMapData(this, key).set(key, value);
|
579 | return this;
|
580 | }
|
581 |
|
582 | // Add methods to `MapCache`.
|
583 | MapCache.prototype.clear = mapCacheClear;
|
584 | MapCache.prototype['delete'] = mapCacheDelete;
|
585 | MapCache.prototype.get = mapCacheGet;
|
586 | MapCache.prototype.has = mapCacheHas;
|
587 | MapCache.prototype.set = mapCacheSet;
|
588 |
|
589 | /**
|
590 | *
|
591 | * Creates an array cache object to store unique values.
|
592 | *
|
593 | * @private
|
594 | * @constructor
|
595 | * @param {Array} [values] The values to cache.
|
596 | */
|
597 | function SetCache(values) {
|
598 | var index = -1,
|
599 | length = values ? values.length : 0;
|
600 |
|
601 | this.__data__ = new MapCache;
|
602 | while (++index < length) {
|
603 | this.add(values[index]);
|
604 | }
|
605 | }
|
606 |
|
607 | /**
|
608 | * Adds `value` to the array cache.
|
609 | *
|
610 | * @private
|
611 | * @name add
|
612 | * @memberOf SetCache
|
613 | * @alias push
|
614 | * @param {*} value The value to cache.
|
615 | * @returns {Object} Returns the cache instance.
|
616 | */
|
617 | function setCacheAdd(value) {
|
618 | this.__data__.set(value, HASH_UNDEFINED);
|
619 | return this;
|
620 | }
|
621 |
|
622 | /**
|
623 | * Checks if `value` is in the array cache.
|
624 | *
|
625 | * @private
|
626 | * @name has
|
627 | * @memberOf SetCache
|
628 | * @param {*} value The value to search for.
|
629 | * @returns {number} Returns `true` if `value` is found, else `false`.
|
630 | */
|
631 | function setCacheHas(value) {
|
632 | return this.__data__.has(value);
|
633 | }
|
634 |
|
635 | // Add methods to `SetCache`.
|
636 | SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
637 | SetCache.prototype.has = setCacheHas;
|
638 |
|
639 | /**
|
640 | * Gets the index at which the `key` is found in `array` of key-value pairs.
|
641 | *
|
642 | * @private
|
643 | * @param {Array} array The array to search.
|
644 | * @param {*} key The key to search for.
|
645 | * @returns {number} Returns the index of the matched value, else `-1`.
|
646 | */
|
647 | function assocIndexOf(array, key) {
|
648 | var length = array.length;
|
649 | while (length--) {
|
650 | if (eq(array[length][0], key)) {
|
651 | return length;
|
652 | }
|
653 | }
|
654 | return -1;
|
655 | }
|
656 |
|
657 | /**
|
658 | * The base implementation of methods like `_.difference` without support
|
659 | * for excluding multiple arrays or iteratee shorthands.
|
660 | *
|
661 | * @private
|
662 | * @param {Array} array The array to inspect.
|
663 | * @param {Array} values The values to exclude.
|
664 | * @param {Function} [iteratee] The iteratee invoked per element.
|
665 | * @param {Function} [comparator] The comparator invoked per element.
|
666 | * @returns {Array} Returns the new array of filtered values.
|
667 | */
|
668 | function baseDifference(array, values, iteratee, comparator) {
|
669 | var index = -1,
|
670 | includes = arrayIncludes,
|
671 | isCommon = true,
|
672 | length = array.length,
|
673 | result = [],
|
674 | valuesLength = values.length;
|
675 |
|
676 | if (!length) {
|
677 | return result;
|
678 | }
|
679 | if (iteratee) {
|
680 | values = arrayMap(values, baseUnary(iteratee));
|
681 | }
|
682 | if (comparator) {
|
683 | includes = arrayIncludesWith;
|
684 | isCommon = false;
|
685 | }
|
686 | else if (values.length >= LARGE_ARRAY_SIZE) {
|
687 | includes = cacheHas;
|
688 | isCommon = false;
|
689 | values = new SetCache(values);
|
690 | }
|
691 | outer:
|
692 | while (++index < length) {
|
693 | var value = array[index],
|
694 | computed = iteratee ? iteratee(value) : value;
|
695 |
|
696 | value = (comparator || value !== 0) ? value : 0;
|
697 | if (isCommon && computed === computed) {
|
698 | var valuesIndex = valuesLength;
|
699 | while (valuesIndex--) {
|
700 | if (values[valuesIndex] === computed) {
|
701 | continue outer;
|
702 | }
|
703 | }
|
704 | result.push(value);
|
705 | }
|
706 | else if (!includes(values, computed, comparator)) {
|
707 | result.push(value);
|
708 | }
|
709 | }
|
710 | return result;
|
711 | }
|
712 |
|
713 | /**
|
714 | * The base implementation of `_.isNative` without bad shim checks.
|
715 | *
|
716 | * @private
|
717 | * @param {*} value The value to check.
|
718 | * @returns {boolean} Returns `true` if `value` is a native function,
|
719 | * else `false`.
|
720 | */
|
721 | function baseIsNative(value) {
|
722 | if (!isObject(value) || isMasked(value)) {
|
723 | return false;
|
724 | }
|
725 | var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
|
726 | return pattern.test(toSource(value));
|
727 | }
|
728 |
|
729 | /**
|
730 | * The base implementation of `_.rest` which doesn't validate or coerce arguments.
|
731 | *
|
732 | * @private
|
733 | * @param {Function} func The function to apply a rest parameter to.
|
734 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
735 | * @returns {Function} Returns the new function.
|
736 | */
|
737 | function baseRest(func, start) {
|
738 | start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
739 | return function() {
|
740 | var args = arguments,
|
741 | index = -1,
|
742 | length = nativeMax(args.length - start, 0),
|
743 | array = Array(length);
|
744 |
|
745 | while (++index < length) {
|
746 | array[index] = args[start + index];
|
747 | }
|
748 | index = -1;
|
749 | var otherArgs = Array(start + 1);
|
750 | while (++index < start) {
|
751 | otherArgs[index] = args[index];
|
752 | }
|
753 | otherArgs[start] = array;
|
754 | return apply(func, this, otherArgs);
|
755 | };
|
756 | }
|
757 |
|
758 | /**
|
759 | * Gets the "length" property value of `object`.
|
760 | *
|
761 | * **Note:** This function is used to avoid a
|
762 | * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
|
763 | * Safari on at least iOS 8.1-8.3 ARM64.
|
764 | *
|
765 | * @private
|
766 | * @param {Object} object The object to query.
|
767 | * @returns {*} Returns the "length" value.
|
768 | */
|
769 | var getLength = baseProperty('length');
|
770 |
|
771 | /**
|
772 | * Gets the data for `map`.
|
773 | *
|
774 | * @private
|
775 | * @param {Object} map The map to query.
|
776 | * @param {string} key The reference key.
|
777 | * @returns {*} Returns the map data.
|
778 | */
|
779 | function getMapData(map, key) {
|
780 | var data = map.__data__;
|
781 | return isKeyable(key)
|
782 | ? data[typeof key == 'string' ? 'string' : 'hash']
|
783 | : data.map;
|
784 | }
|
785 |
|
786 | /**
|
787 | * Gets the native function at `key` of `object`.
|
788 | *
|
789 | * @private
|
790 | * @param {Object} object The object to query.
|
791 | * @param {string} key The key of the method to get.
|
792 | * @returns {*} Returns the function if it's native, else `undefined`.
|
793 | */
|
794 | function getNative(object, key) {
|
795 | var value = getValue(object, key);
|
796 | return baseIsNative(value) ? value : undefined;
|
797 | }
|
798 |
|
799 | /**
|
800 | * Checks if `value` is suitable for use as unique object key.
|
801 | *
|
802 | * @private
|
803 | * @param {*} value The value to check.
|
804 | * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
805 | */
|
806 | function isKeyable(value) {
|
807 | var type = typeof value;
|
808 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
809 | ? (value !== '__proto__')
|
810 | : (value === null);
|
811 | }
|
812 |
|
813 | /**
|
814 | * Checks if `func` has its source masked.
|
815 | *
|
816 | * @private
|
817 | * @param {Function} func The function to check.
|
818 | * @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
819 | */
|
820 | function isMasked(func) {
|
821 | return !!maskSrcKey && (maskSrcKey in func);
|
822 | }
|
823 |
|
824 | /**
|
825 | * Converts `func` to its source code.
|
826 | *
|
827 | * @private
|
828 | * @param {Function} func The function to process.
|
829 | * @returns {string} Returns the source code.
|
830 | */
|
831 | function toSource(func) {
|
832 | if (func != null) {
|
833 | try {
|
834 | return funcToString.call(func);
|
835 | } catch (e) {}
|
836 | try {
|
837 | return (func + '');
|
838 | } catch (e) {}
|
839 | }
|
840 | return '';
|
841 | }
|
842 |
|
843 | /**
|
844 | * Creates an array excluding all given values using
|
845 | * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
846 | * for equality comparisons.
|
847 | *
|
848 | * **Note:** Unlike `_.pull`, this method returns a new array.
|
849 | *
|
850 | * @static
|
851 | * @memberOf _
|
852 | * @since 0.1.0
|
853 | * @category Array
|
854 | * @param {Array} array The array to inspect.
|
855 | * @param {...*} [values] The values to exclude.
|
856 | * @returns {Array} Returns the new array of filtered values.
|
857 | * @see _.difference, _.xor
|
858 | * @example
|
859 | *
|
860 | * _.without([2, 1, 2, 3], 1, 2);
|
861 | * // => [3]
|
862 | */
|
863 | var without = baseRest(function(array, values) {
|
864 | return isArrayLikeObject(array)
|
865 | ? baseDifference(array, values)
|
866 | : [];
|
867 | });
|
868 |
|
869 | /**
|
870 | * Performs a
|
871 | * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
872 | * comparison between two values to determine if they are equivalent.
|
873 | *
|
874 | * @static
|
875 | * @memberOf _
|
876 | * @since 4.0.0
|
877 | * @category Lang
|
878 | * @param {*} value The value to compare.
|
879 | * @param {*} other The other value to compare.
|
880 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
881 | * @example
|
882 | *
|
883 | * var object = { 'a': 1 };
|
884 | * var other = { 'a': 1 };
|
885 | *
|
886 | * _.eq(object, object);
|
887 | * // => true
|
888 | *
|
889 | * _.eq(object, other);
|
890 | * // => false
|
891 | *
|
892 | * _.eq('a', 'a');
|
893 | * // => true
|
894 | *
|
895 | * _.eq('a', Object('a'));
|
896 | * // => false
|
897 | *
|
898 | * _.eq(NaN, NaN);
|
899 | * // => true
|
900 | */
|
901 | function eq(value, other) {
|
902 | return value === other || (value !== value && other !== other);
|
903 | }
|
904 |
|
905 | /**
|
906 | * Checks if `value` is array-like. A value is considered array-like if it's
|
907 | * not a function and has a `value.length` that's an integer greater than or
|
908 | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
909 | *
|
910 | * @static
|
911 | * @memberOf _
|
912 | * @since 4.0.0
|
913 | * @category Lang
|
914 | * @param {*} value The value to check.
|
915 | * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
916 | * @example
|
917 | *
|
918 | * _.isArrayLike([1, 2, 3]);
|
919 | * // => true
|
920 | *
|
921 | * _.isArrayLike(document.body.children);
|
922 | * // => true
|
923 | *
|
924 | * _.isArrayLike('abc');
|
925 | * // => true
|
926 | *
|
927 | * _.isArrayLike(_.noop);
|
928 | * // => false
|
929 | */
|
930 | function isArrayLike(value) {
|
931 | return value != null && isLength(getLength(value)) && !isFunction(value);
|
932 | }
|
933 |
|
934 | /**
|
935 | * This method is like `_.isArrayLike` except that it also checks if `value`
|
936 | * is an object.
|
937 | *
|
938 | * @static
|
939 | * @memberOf _
|
940 | * @since 4.0.0
|
941 | * @category Lang
|
942 | * @param {*} value The value to check.
|
943 | * @returns {boolean} Returns `true` if `value` is an array-like object,
|
944 | * else `false`.
|
945 | * @example
|
946 | *
|
947 | * _.isArrayLikeObject([1, 2, 3]);
|
948 | * // => true
|
949 | *
|
950 | * _.isArrayLikeObject(document.body.children);
|
951 | * // => true
|
952 | *
|
953 | * _.isArrayLikeObject('abc');
|
954 | * // => false
|
955 | *
|
956 | * _.isArrayLikeObject(_.noop);
|
957 | * // => false
|
958 | */
|
959 | function isArrayLikeObject(value) {
|
960 | return isObjectLike(value) && isArrayLike(value);
|
961 | }
|
962 |
|
963 | /**
|
964 | * Checks if `value` is classified as a `Function` object.
|
965 | *
|
966 | * @static
|
967 | * @memberOf _
|
968 | * @since 0.1.0
|
969 | * @category Lang
|
970 | * @param {*} value The value to check.
|
971 | * @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
972 | * @example
|
973 | *
|
974 | * _.isFunction(_);
|
975 | * // => true
|
976 | *
|
977 | * _.isFunction(/abc/);
|
978 | * // => false
|
979 | */
|
980 | function isFunction(value) {
|
981 | // The use of `Object#toString` avoids issues with the `typeof` operator
|
982 | // in Safari 8 which returns 'object' for typed array and weak map constructors,
|
983 | // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
|
984 | var tag = isObject(value) ? objectToString.call(value) : '';
|
985 | return tag == funcTag || tag == genTag;
|
986 | }
|
987 |
|
988 | /**
|
989 | * Checks if `value` is a valid array-like length.
|
990 | *
|
991 | * **Note:** This function is loosely based on
|
992 | * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
993 | *
|
994 | * @static
|
995 | * @memberOf _
|
996 | * @since 4.0.0
|
997 | * @category Lang
|
998 | * @param {*} value The value to check.
|
999 | * @returns {boolean} Returns `true` if `value` is a valid length,
|
1000 | * else `false`.
|
1001 | * @example
|
1002 | *
|
1003 | * _.isLength(3);
|
1004 | * // => true
|
1005 | *
|
1006 | * _.isLength(Number.MIN_VALUE);
|
1007 | * // => false
|
1008 | *
|
1009 | * _.isLength(Infinity);
|
1010 | * // => false
|
1011 | *
|
1012 | * _.isLength('3');
|
1013 | * // => false
|
1014 | */
|
1015 | function isLength(value) {
|
1016 | return typeof value == 'number' &&
|
1017 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
1018 | }
|
1019 |
|
1020 | /**
|
1021 | * Checks if `value` is the
|
1022 | * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
|
1023 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
1024 | *
|
1025 | * @static
|
1026 | * @memberOf _
|
1027 | * @since 0.1.0
|
1028 | * @category Lang
|
1029 | * @param {*} value The value to check.
|
1030 | * @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
1031 | * @example
|
1032 | *
|
1033 | * _.isObject({});
|
1034 | * // => true
|
1035 | *
|
1036 | * _.isObject([1, 2, 3]);
|
1037 | * // => true
|
1038 | *
|
1039 | * _.isObject(_.noop);
|
1040 | * // => true
|
1041 | *
|
1042 | * _.isObject(null);
|
1043 | * // => false
|
1044 | */
|
1045 | function isObject(value) {
|
1046 | var type = typeof value;
|
1047 | return !!value && (type == 'object' || type == 'function');
|
1048 | }
|
1049 |
|
1050 | /**
|
1051 | * Checks if `value` is object-like. A value is object-like if it's not `null`
|
1052 | * and has a `typeof` result of "object".
|
1053 | *
|
1054 | * @static
|
1055 | * @memberOf _
|
1056 | * @since 4.0.0
|
1057 | * @category Lang
|
1058 | * @param {*} value The value to check.
|
1059 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
1060 | * @example
|
1061 | *
|
1062 | * _.isObjectLike({});
|
1063 | * // => true
|
1064 | *
|
1065 | * _.isObjectLike([1, 2, 3]);
|
1066 | * // => true
|
1067 | *
|
1068 | * _.isObjectLike(_.noop);
|
1069 | * // => false
|
1070 | *
|
1071 | * _.isObjectLike(null);
|
1072 | * // => false
|
1073 | */
|
1074 | function isObjectLike(value) {
|
1075 | return !!value && typeof value == 'object';
|
1076 | }
|
1077 |
|
1078 | module.exports = without;
|