index.js 26 KB

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