You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2630 lines
71 KiB

  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 as the `TypeError` message for "Functions" methods. */
  12. var FUNC_ERROR_TEXT = 'Expected a function';
  13. /** Used to stand-in for `undefined` hash values. */
  14. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  15. /** Used to compose bitmasks for comparison styles. */
  16. var UNORDERED_COMPARE_FLAG = 1,
  17. PARTIAL_COMPARE_FLAG = 2;
  18. /** Used as references for various `Number` constants. */
  19. var INFINITY = 1 / 0,
  20. MAX_SAFE_INTEGER = 9007199254740991;
  21. /** `Object#toString` result references. */
  22. var argsTag = '[object Arguments]',
  23. arrayTag = '[object Array]',
  24. boolTag = '[object Boolean]',
  25. dateTag = '[object Date]',
  26. errorTag = '[object Error]',
  27. funcTag = '[object Function]',
  28. genTag = '[object GeneratorFunction]',
  29. mapTag = '[object Map]',
  30. numberTag = '[object Number]',
  31. objectTag = '[object Object]',
  32. promiseTag = '[object Promise]',
  33. regexpTag = '[object RegExp]',
  34. setTag = '[object Set]',
  35. stringTag = '[object String]',
  36. symbolTag = '[object Symbol]',
  37. weakMapTag = '[object WeakMap]';
  38. var arrayBufferTag = '[object ArrayBuffer]',
  39. dataViewTag = '[object DataView]',
  40. float32Tag = '[object Float32Array]',
  41. float64Tag = '[object Float64Array]',
  42. int8Tag = '[object Int8Array]',
  43. int16Tag = '[object Int16Array]',
  44. int32Tag = '[object Int32Array]',
  45. uint8Tag = '[object Uint8Array]',
  46. uint8ClampedTag = '[object Uint8ClampedArray]',
  47. uint16Tag = '[object Uint16Array]',
  48. uint32Tag = '[object Uint32Array]';
  49. /** Used to match property names within property paths. */
  50. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  51. reIsPlainProp = /^\w*$/,
  52. reLeadingDot = /^\./,
  53. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  54. /**
  55. * Used to match `RegExp`
  56. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  57. */
  58. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  59. /** Used to match backslashes in property paths. */
  60. var reEscapeChar = /\\(\\)?/g;
  61. /** Used to detect host constructors (Safari). */
  62. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  63. /** Used to detect unsigned integer values. */
  64. var reIsUint = /^(?:0|[1-9]\d*)$/;
  65. /** Used to identify `toStringTag` values of typed arrays. */
  66. var typedArrayTags = {};
  67. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  68. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  69. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  70. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  71. typedArrayTags[uint32Tag] = true;
  72. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  73. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  74. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  75. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  76. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  77. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  78. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  79. typedArrayTags[weakMapTag] = false;
  80. /** Detect free variable `global` from Node.js. */
  81. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  82. /** Detect free variable `self`. */
  83. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  84. /** Used as a reference to the global object. */
  85. var root = freeGlobal || freeSelf || Function('return this')();
  86. /** Detect free variable `exports`. */
  87. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  88. /** Detect free variable `module`. */
  89. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  90. /** Detect the popular CommonJS extension `module.exports`. */
  91. var moduleExports = freeModule && freeModule.exports === freeExports;
  92. /** Detect free variable `process` from Node.js. */
  93. var freeProcess = moduleExports && freeGlobal.process;
  94. /** Used to access faster Node.js helpers. */
  95. var nodeUtil = (function() {
  96. try {
  97. return freeProcess && freeProcess.binding('util');
  98. } catch (e) {}
  99. }());
  100. /* Node.js helper references. */
  101. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  102. /**
  103. * A faster alternative to `Function#apply`, this function invokes `func`
  104. * with the `this` binding of `thisArg` and the arguments of `args`.
  105. *
  106. * @private
  107. * @param {Function} func The function to invoke.
  108. * @param {*} thisArg The `this` binding of `func`.
  109. * @param {Array} args The arguments to invoke `func` with.
  110. * @returns {*} Returns the result of `func`.
  111. */
  112. function apply(func, thisArg, args) {
  113. switch (args.length) {
  114. case 0: return func.call(thisArg);
  115. case 1: return func.call(thisArg, args[0]);
  116. case 2: return func.call(thisArg, args[0], args[1]);
  117. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  118. }
  119. return func.apply(thisArg, args);
  120. }
  121. /**
  122. * A specialized version of `_.map` for arrays without support for iteratee
  123. * shorthands.
  124. *
  125. * @private
  126. * @param {Array} [array] The array to iterate over.
  127. * @param {Function} iteratee The function invoked per iteration.
  128. * @returns {Array} Returns the new mapped array.
  129. */
  130. function arrayMap(array, iteratee) {
  131. var index = -1,
  132. length = array ? array.length : 0,
  133. result = Array(length);
  134. while (++index < length) {
  135. result[index] = iteratee(array[index], index, array);
  136. }
  137. return result;
  138. }
  139. /**
  140. * Appends the elements of `values` to `array`.
  141. *
  142. * @private
  143. * @param {Array} array The array to modify.
  144. * @param {Array} values The values to append.
  145. * @returns {Array} Returns `array`.
  146. */
  147. function arrayPush(array, values) {
  148. var index = -1,
  149. length = values.length,
  150. offset = array.length;
  151. while (++index < length) {
  152. array[offset + index] = values[index];
  153. }
  154. return array;
  155. }
  156. /**
  157. * A specialized version of `_.some` for arrays without support for iteratee
  158. * shorthands.
  159. *
  160. * @private
  161. * @param {Array} [array] The array to iterate over.
  162. * @param {Function} predicate The function invoked per iteration.
  163. * @returns {boolean} Returns `true` if any element passes the predicate check,
  164. * else `false`.
  165. */
  166. function arraySome(array, predicate) {
  167. var index = -1,
  168. length = array ? array.length : 0;
  169. while (++index < length) {
  170. if (predicate(array[index], index, array)) {
  171. return true;
  172. }
  173. }
  174. return false;
  175. }
  176. /**
  177. * The base implementation of `_.property` without support for deep paths.
  178. *
  179. * @private
  180. * @param {string} key The key of the property to get.
  181. * @returns {Function} Returns the new accessor function.
  182. */
  183. function baseProperty(key) {
  184. return function(object) {
  185. return object == null ? undefined : object[key];
  186. };
  187. }
  188. /**
  189. * The base implementation of `_.sortBy` which uses `comparer` to define the
  190. * sort order of `array` and replaces criteria objects with their corresponding
  191. * values.
  192. *
  193. * @private
  194. * @param {Array} array The array to sort.
  195. * @param {Function} comparer The function to define sort order.
  196. * @returns {Array} Returns `array`.
  197. */
  198. function baseSortBy(array, comparer) {
  199. var length = array.length;
  200. array.sort(comparer);
  201. while (length--) {
  202. array[length] = array[length].value;
  203. }
  204. return array;
  205. }
  206. /**
  207. * The base implementation of `_.times` without support for iteratee shorthands
  208. * or max array length checks.
  209. *
  210. * @private
  211. * @param {number} n The number of times to invoke `iteratee`.
  212. * @param {Function} iteratee The function invoked per iteration.
  213. * @returns {Array} Returns the array of results.
  214. */
  215. function baseTimes(n, iteratee) {
  216. var index = -1,
  217. result = Array(n);
  218. while (++index < n) {
  219. result[index] = iteratee(index);
  220. }
  221. return result;
  222. }
  223. /**
  224. * The base implementation of `_.unary` without support for storing metadata.
  225. *
  226. * @private
  227. * @param {Function} func The function to cap arguments for.
  228. * @returns {Function} Returns the new capped function.
  229. */
  230. function baseUnary(func) {
  231. return function(value) {
  232. return func(value);
  233. };
  234. }
  235. /**
  236. * Gets the value at `key` of `object`.
  237. *
  238. * @private
  239. * @param {Object} [object] The object to query.
  240. * @param {string} key The key of the property to get.
  241. * @returns {*} Returns the property value.
  242. */
  243. function getValue(object, key) {
  244. return object == null ? undefined : object[key];
  245. }
  246. /**
  247. * Checks if `value` is a host object in IE < 9.
  248. *
  249. * @private
  250. * @param {*} value The value to check.
  251. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  252. */
  253. function isHostObject(value) {
  254. // Many host objects are `Object` objects that can coerce to strings
  255. // despite having improperly defined `toString` methods.
  256. var result = false;
  257. if (value != null && typeof value.toString != 'function') {
  258. try {
  259. result = !!(value + '');
  260. } catch (e) {}
  261. }
  262. return result;
  263. }
  264. /**
  265. * Converts `map` to its key-value pairs.
  266. *
  267. * @private
  268. * @param {Object} map The map to convert.
  269. * @returns {Array} Returns the key-value pairs.
  270. */
  271. function mapToArray(map) {
  272. var index = -1,
  273. result = Array(map.size);
  274. map.forEach(function(value, key) {
  275. result[++index] = [key, value];
  276. });
  277. return result;
  278. }
  279. /**
  280. * Creates a unary function that invokes `func` with its argument transformed.
  281. *
  282. * @private
  283. * @param {Function} func The function to wrap.
  284. * @param {Function} transform The argument transform.
  285. * @returns {Function} Returns the new function.
  286. */
  287. function overArg(func, transform) {
  288. return function(arg) {
  289. return func(transform(arg));
  290. };
  291. }
  292. /**
  293. * Converts `set` to an array of its values.
  294. *
  295. * @private
  296. * @param {Object} set The set to convert.
  297. * @returns {Array} Returns the values.
  298. */
  299. function setToArray(set) {
  300. var index = -1,
  301. result = Array(set.size);
  302. set.forEach(function(value) {
  303. result[++index] = value;
  304. });
  305. return result;
  306. }
  307. /** Used for built-in method references. */
  308. var arrayProto = Array.prototype,
  309. funcProto = Function.prototype,
  310. objectProto = Object.prototype;
  311. /** Used to detect overreaching core-js shims. */
  312. var coreJsData = root['__core-js_shared__'];
  313. /** Used to detect methods masquerading as native. */
  314. var maskSrcKey = (function() {
  315. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  316. return uid ? ('Symbol(src)_1.' + uid) : '';
  317. }());
  318. /** Used to resolve the decompiled source of functions. */
  319. var funcToString = funcProto.toString;
  320. /** Used to check objects for own properties. */
  321. var hasOwnProperty = objectProto.hasOwnProperty;
  322. /**
  323. * Used to resolve the
  324. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  325. * of values.
  326. */
  327. var objectToString = objectProto.toString;
  328. /** Used to detect if a method is native. */
  329. var reIsNative = RegExp('^' +
  330. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  331. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  332. );
  333. /** Built-in value references. */
  334. var Symbol = root.Symbol,
  335. Uint8Array = root.Uint8Array,
  336. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  337. splice = arrayProto.splice,
  338. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;
  339. /* Built-in method references for those with the same name as other `lodash` methods. */
  340. var nativeKeys = overArg(Object.keys, Object),
  341. nativeMax = Math.max;
  342. /* Built-in method references that are verified to be native. */
  343. var DataView = getNative(root, 'DataView'),
  344. Map = getNative(root, 'Map'),
  345. Promise = getNative(root, 'Promise'),
  346. Set = getNative(root, 'Set'),
  347. WeakMap = getNative(root, 'WeakMap'),
  348. nativeCreate = getNative(Object, 'create');
  349. /** Used to detect maps, sets, and weakmaps. */
  350. var dataViewCtorString = toSource(DataView),
  351. mapCtorString = toSource(Map),
  352. promiseCtorString = toSource(Promise),
  353. setCtorString = toSource(Set),
  354. weakMapCtorString = toSource(WeakMap);
  355. /** Used to convert symbols to primitives and strings. */
  356. var symbolProto = Symbol ? Symbol.prototype : undefined,
  357. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  358. symbolToString = symbolProto ? symbolProto.toString : undefined;
  359. /**
  360. * Creates a hash object.
  361. *
  362. * @private
  363. * @constructor
  364. * @param {Array} [entries] The key-value pairs to cache.
  365. */
  366. function Hash(entries) {
  367. var index = -1,
  368. length = entries ? entries.length : 0;
  369. this.clear();
  370. while (++index < length) {
  371. var entry = entries[index];
  372. this.set(entry[0], entry[1]);
  373. }
  374. }
  375. /**
  376. * Removes all key-value entries from the hash.
  377. *
  378. * @private
  379. * @name clear
  380. * @memberOf Hash
  381. */
  382. function hashClear() {
  383. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  384. }
  385. /**
  386. * Removes `key` and its value from the hash.
  387. *
  388. * @private
  389. * @name delete
  390. * @memberOf Hash
  391. * @param {Object} hash The hash to modify.
  392. * @param {string} key The key of the value to remove.
  393. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  394. */
  395. function hashDelete(key) {
  396. return this.has(key) && delete this.__data__[key];
  397. }
  398. /**
  399. * Gets the hash value for `key`.
  400. *
  401. * @private
  402. * @name get
  403. * @memberOf Hash
  404. * @param {string} key The key of the value to get.
  405. * @returns {*} Returns the entry value.
  406. */
  407. function hashGet(key) {
  408. var data = this.__data__;
  409. if (nativeCreate) {
  410. var result = data[key];
  411. return result === HASH_UNDEFINED ? undefined : result;
  412. }
  413. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  414. }
  415. /**
  416. * Checks if a hash value for `key` exists.
  417. *
  418. * @private
  419. * @name has
  420. * @memberOf Hash
  421. * @param {string} key The key of the entry to check.
  422. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  423. */
  424. function hashHas(key) {
  425. var data = this.__data__;
  426. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  427. }
  428. /**
  429. * Sets the hash `key` to `value`.
  430. *
  431. * @private
  432. * @name set
  433. * @memberOf Hash
  434. * @param {string} key The key of the value to set.
  435. * @param {*} value The value to set.
  436. * @returns {Object} Returns the hash instance.
  437. */
  438. function hashSet(key, value) {
  439. var data = this.__data__;
  440. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  441. return this;
  442. }
  443. // Add methods to `Hash`.
  444. Hash.prototype.clear = hashClear;
  445. Hash.prototype['delete'] = hashDelete;
  446. Hash.prototype.get = hashGet;
  447. Hash.prototype.has = hashHas;
  448. Hash.prototype.set = hashSet;
  449. /**
  450. * Creates an list cache object.
  451. *
  452. * @private
  453. * @constructor
  454. * @param {Array} [entries] The key-value pairs to cache.
  455. */
  456. function ListCache(entries) {
  457. var index = -1,
  458. length = entries ? entries.length : 0;
  459. this.clear();
  460. while (++index < length) {
  461. var entry = entries[index];
  462. this.set(entry[0], entry[1]);
  463. }
  464. }
  465. /**
  466. * Removes all key-value entries from the list cache.
  467. *
  468. * @private
  469. * @name clear
  470. * @memberOf ListCache
  471. */
  472. function listCacheClear() {
  473. this.__data__ = [];
  474. }
  475. /**
  476. * Removes `key` and its value from the list cache.
  477. *
  478. * @private
  479. * @name delete
  480. * @memberOf ListCache
  481. * @param {string} key The key of the value to remove.
  482. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  483. */
  484. function listCacheDelete(key) {
  485. var data = this.__data__,
  486. index = assocIndexOf(data, key);
  487. if (index < 0) {
  488. return false;
  489. }
  490. var lastIndex = data.length - 1;
  491. if (index == lastIndex) {
  492. data.pop();
  493. } else {
  494. splice.call(data, index, 1);
  495. }
  496. return true;
  497. }
  498. /**
  499. * Gets the list cache value for `key`.
  500. *
  501. * @private
  502. * @name get
  503. * @memberOf ListCache
  504. * @param {string} key The key of the value to get.
  505. * @returns {*} Returns the entry value.
  506. */
  507. function listCacheGet(key) {
  508. var data = this.__data__,
  509. index = assocIndexOf(data, key);
  510. return index < 0 ? undefined : data[index][1];
  511. }
  512. /**
  513. * Checks if a list cache value for `key` exists.
  514. *
  515. * @private
  516. * @name has
  517. * @memberOf ListCache
  518. * @param {string} key The key of the entry to check.
  519. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  520. */
  521. function listCacheHas(key) {
  522. return assocIndexOf(this.__data__, key) > -1;
  523. }
  524. /**
  525. * Sets the list cache `key` to `value`.
  526. *
  527. * @private
  528. * @name set
  529. * @memberOf ListCache
  530. * @param {string} key The key of the value to set.
  531. * @param {*} value The value to set.
  532. * @returns {Object} Returns the list cache instance.
  533. */
  534. function listCacheSet(key, value) {
  535. var data = this.__data__,
  536. index = assocIndexOf(data, key);
  537. if (index < 0) {
  538. data.push([key, value]);
  539. } else {
  540. data[index][1] = value;
  541. }
  542. return this;
  543. }
  544. // Add methods to `ListCache`.
  545. ListCache.prototype.clear = listCacheClear;
  546. ListCache.prototype['delete'] = listCacheDelete;
  547. ListCache.prototype.get = listCacheGet;
  548. ListCache.prototype.has = listCacheHas;
  549. ListCache.prototype.set = listCacheSet;
  550. /**
  551. * Creates a map cache object to store key-value pairs.
  552. *
  553. * @private
  554. * @constructor
  555. * @param {Array} [entries] The key-value pairs to cache.
  556. */
  557. function MapCache(entries) {
  558. var index = -1,
  559. length = entries ? entries.length : 0;
  560. this.clear();
  561. while (++index < length) {
  562. var entry = entries[index];
  563. this.set(entry[0], entry[1]);
  564. }
  565. }
  566. /**
  567. * Removes all key-value entries from the map.
  568. *
  569. * @private
  570. * @name clear
  571. * @memberOf MapCache
  572. */
  573. function mapCacheClear() {
  574. this.__data__ = {
  575. 'hash': new Hash,
  576. 'map': new (Map || ListCache),
  577. 'string': new Hash
  578. };
  579. }
  580. /**
  581. * Removes `key` and its value from the map.
  582. *
  583. * @private
  584. * @name delete
  585. * @memberOf MapCache
  586. * @param {string} key The key of the value to remove.
  587. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  588. */
  589. function mapCacheDelete(key) {
  590. return getMapData(this, key)['delete'](key);
  591. }
  592. /**
  593. * Gets the map value for `key`.
  594. *
  595. * @private
  596. * @name get
  597. * @memberOf MapCache
  598. * @param {string} key The key of the value to get.
  599. * @returns {*} Returns the entry value.
  600. */
  601. function mapCacheGet(key) {
  602. return getMapData(this, key).get(key);
  603. }
  604. /**
  605. * Checks if a map value for `key` exists.
  606. *
  607. * @private
  608. * @name has
  609. * @memberOf MapCache
  610. * @param {string} key The key of the entry to check.
  611. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  612. */
  613. function mapCacheHas(key) {
  614. return getMapData(this, key).has(key);
  615. }
  616. /**
  617. * Sets the map `key` to `value`.
  618. *
  619. * @private
  620. * @name set
  621. * @memberOf MapCache
  622. * @param {string} key The key of the value to set.
  623. * @param {*} value The value to set.
  624. * @returns {Object} Returns the map cache instance.
  625. */
  626. function mapCacheSet(key, value) {
  627. getMapData(this, key).set(key, value);
  628. return this;
  629. }
  630. // Add methods to `MapCache`.
  631. MapCache.prototype.clear = mapCacheClear;
  632. MapCache.prototype['delete'] = mapCacheDelete;
  633. MapCache.prototype.get = mapCacheGet;
  634. MapCache.prototype.has = mapCacheHas;
  635. MapCache.prototype.set = mapCacheSet;
  636. /**
  637. *
  638. * Creates an array cache object to store unique values.
  639. *
  640. * @private
  641. * @constructor
  642. * @param {Array} [values] The values to cache.
  643. */
  644. function SetCache(values) {
  645. var index = -1,
  646. length = values ? values.length : 0;
  647. this.__data__ = new MapCache;
  648. while (++index < length) {
  649. this.add(values[index]);
  650. }
  651. }
  652. /**
  653. * Adds `value` to the array cache.
  654. *
  655. * @private
  656. * @name add
  657. * @memberOf SetCache
  658. * @alias push
  659. * @param {*} value The value to cache.
  660. * @returns {Object} Returns the cache instance.
  661. */
  662. function setCacheAdd(value) {
  663. this.__data__.set(value, HASH_UNDEFINED);
  664. return this;
  665. }
  666. /**
  667. * Checks if `value` is in the array cache.
  668. *
  669. * @private
  670. * @name has
  671. * @memberOf SetCache
  672. * @param {*} value The value to search for.
  673. * @returns {number} Returns `true` if `value` is found, else `false`.
  674. */
  675. function setCacheHas(value) {
  676. return this.__data__.has(value);
  677. }
  678. // Add methods to `SetCache`.
  679. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  680. SetCache.prototype.has = setCacheHas;
  681. /**
  682. * Creates a stack cache object to store key-value pairs.
  683. *
  684. * @private
  685. * @constructor
  686. * @param {Array} [entries] The key-value pairs to cache.
  687. */
  688. function Stack(entries) {
  689. this.__data__ = new ListCache(entries);
  690. }
  691. /**
  692. * Removes all key-value entries from the stack.
  693. *
  694. * @private
  695. * @name clear
  696. * @memberOf Stack
  697. */
  698. function stackClear() {
  699. this.__data__ = new ListCache;
  700. }
  701. /**
  702. * Removes `key` and its value from the stack.
  703. *
  704. * @private
  705. * @name delete
  706. * @memberOf Stack
  707. * @param {string} key The key of the value to remove.
  708. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  709. */
  710. function stackDelete(key) {
  711. return this.__data__['delete'](key);
  712. }
  713. /**
  714. * Gets the stack value for `key`.
  715. *
  716. * @private
  717. * @name get
  718. * @memberOf Stack
  719. * @param {string} key The key of the value to get.
  720. * @returns {*} Returns the entry value.
  721. */
  722. function stackGet(key) {
  723. return this.__data__.get(key);
  724. }
  725. /**
  726. * Checks if a stack value for `key` exists.
  727. *
  728. * @private
  729. * @name has
  730. * @memberOf Stack
  731. * @param {string} key The key of the entry to check.
  732. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  733. */
  734. function stackHas(key) {
  735. return this.__data__.has(key);
  736. }
  737. /**
  738. * Sets the stack `key` to `value`.
  739. *
  740. * @private
  741. * @name set
  742. * @memberOf Stack
  743. * @param {string} key The key of the value to set.
  744. * @param {*} value The value to set.
  745. * @returns {Object} Returns the stack cache instance.
  746. */
  747. function stackSet(key, value) {
  748. var cache = this.__data__;
  749. if (cache instanceof ListCache) {
  750. var pairs = cache.__data__;
  751. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  752. pairs.push([key, value]);
  753. return this;
  754. }
  755. cache = this.__data__ = new MapCache(pairs);
  756. }
  757. cache.set(key, value);
  758. return this;
  759. }
  760. // Add methods to `Stack`.
  761. Stack.prototype.clear = stackClear;
  762. Stack.prototype['delete'] = stackDelete;
  763. Stack.prototype.get = stackGet;
  764. Stack.prototype.has = stackHas;
  765. Stack.prototype.set = stackSet;
  766. /**
  767. * Creates an array of the enumerable property names of the array-like `value`.
  768. *
  769. * @private
  770. * @param {*} value The value to query.
  771. * @param {boolean} inherited Specify returning inherited property names.
  772. * @returns {Array} Returns the array of property names.
  773. */
  774. function arrayLikeKeys(value, inherited) {
  775. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  776. // Safari 9 makes `arguments.length` enumerable in strict mode.
  777. var result = (isArray(value) || isArguments(value))
  778. ? baseTimes(value.length, String)
  779. : [];
  780. var length = result.length,
  781. skipIndexes = !!length;
  782. for (var key in value) {
  783. if ((inherited || hasOwnProperty.call(value, key)) &&
  784. !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  785. result.push(key);
  786. }
  787. }
  788. return result;
  789. }
  790. /**
  791. * Gets the index at which the `key` is found in `array` of key-value pairs.
  792. *
  793. * @private
  794. * @param {Array} array The array to inspect.
  795. * @param {*} key The key to search for.
  796. * @returns {number} Returns the index of the matched value, else `-1`.
  797. */
  798. function assocIndexOf(array, key) {
  799. var length = array.length;
  800. while (length--) {
  801. if (eq(array[length][0], key)) {
  802. return length;
  803. }
  804. }
  805. return -1;
  806. }
  807. /**
  808. * The base implementation of `_.forEach` without support for iteratee shorthands.
  809. *
  810. * @private
  811. * @param {Array|Object} collection The collection to iterate over.
  812. * @param {Function} iteratee The function invoked per iteration.
  813. * @returns {Array|Object} Returns `collection`.
  814. */
  815. var baseEach = createBaseEach(baseForOwn);
  816. /**
  817. * The base implementation of `_.flatten` with support for restricting flattening.
  818. *
  819. * @private
  820. * @param {Array} array The array to flatten.
  821. * @param {number} depth The maximum recursion depth.
  822. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  823. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  824. * @param {Array} [result=[]] The initial result value.
  825. * @returns {Array} Returns the new flattened array.
  826. */
  827. function baseFlatten(array, depth, predicate, isStrict, result) {
  828. var index = -1,
  829. length = array.length;
  830. predicate || (predicate = isFlattenable);
  831. result || (result = []);
  832. while (++index < length) {
  833. var value = array[index];
  834. if (depth > 0 && predicate(value)) {
  835. if (depth > 1) {
  836. // Recursively flatten arrays (susceptible to call stack limits).
  837. baseFlatten(value, depth - 1, predicate, isStrict, result);
  838. } else {
  839. arrayPush(result, value);
  840. }
  841. } else if (!isStrict) {
  842. result[result.length] = value;
  843. }
  844. }
  845. return result;
  846. }
  847. /**
  848. * The base implementation of `baseForOwn` which iterates over `object`
  849. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  850. * Iteratee functions may exit iteration early by explicitly returning `false`.
  851. *
  852. * @private
  853. * @param {Object} object The object to iterate over.
  854. * @param {Function} iteratee The function invoked per iteration.
  855. * @param {Function} keysFunc The function to get the keys of `object`.
  856. * @returns {Object} Returns `object`.
  857. */
  858. var baseFor = createBaseFor();
  859. /**
  860. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  861. *
  862. * @private
  863. * @param {Object} object The object to iterate over.
  864. * @param {Function} iteratee The function invoked per iteration.
  865. * @returns {Object} Returns `object`.
  866. */
  867. function baseForOwn(object, iteratee) {
  868. return object && baseFor(object, iteratee, keys);
  869. }
  870. /**
  871. * The base implementation of `_.get` without support for default values.
  872. *
  873. * @private
  874. * @param {Object} object The object to query.
  875. * @param {Array|string} path The path of the property to get.
  876. * @returns {*} Returns the resolved value.
  877. */
  878. function baseGet(object, path) {
  879. path = isKey(path, object) ? [path] : castPath(path);
  880. var index = 0,
  881. length = path.length;
  882. while (object != null && index < length) {
  883. object = object[toKey(path[index++])];
  884. }
  885. return (index && index == length) ? object : undefined;
  886. }
  887. /**
  888. * The base implementation of `getTag`.
  889. *
  890. * @private
  891. * @param {*} value The value to query.
  892. * @returns {string} Returns the `toStringTag`.
  893. */
  894. function baseGetTag(value) {
  895. return objectToString.call(value);
  896. }
  897. /**
  898. * The base implementation of `_.hasIn` without support for deep paths.
  899. *
  900. * @private
  901. * @param {Object} [object] The object to query.
  902. * @param {Array|string} key The key to check.
  903. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  904. */
  905. function baseHasIn(object, key) {
  906. return object != null && key in Object(object);
  907. }
  908. /**
  909. * The base implementation of `_.isEqual` which supports partial comparisons
  910. * and tracks traversed objects.
  911. *
  912. * @private
  913. * @param {*} value The value to compare.
  914. * @param {*} other The other value to compare.
  915. * @param {Function} [customizer] The function to customize comparisons.
  916. * @param {boolean} [bitmask] The bitmask of comparison flags.
  917. * The bitmask may be composed of the following flags:
  918. * 1 - Unordered comparison
  919. * 2 - Partial comparison
  920. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  921. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  922. */
  923. function baseIsEqual(value, other, customizer, bitmask, stack) {
  924. if (value === other) {
  925. return true;
  926. }
  927. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  928. return value !== value && other !== other;
  929. }
  930. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  931. }
  932. /**
  933. * A specialized version of `baseIsEqual` for arrays and objects which performs
  934. * deep comparisons and tracks traversed objects enabling objects with circular
  935. * references to be compared.
  936. *
  937. * @private
  938. * @param {Object} object The object to compare.
  939. * @param {Object} other The other object to compare.
  940. * @param {Function} equalFunc The function to determine equivalents of values.
  941. * @param {Function} [customizer] The function to customize comparisons.
  942. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  943. * for more details.
  944. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  945. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  946. */
  947. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  948. var objIsArr = isArray(object),
  949. othIsArr = isArray(other),
  950. objTag = arrayTag,
  951. othTag = arrayTag;
  952. if (!objIsArr) {
  953. objTag = getTag(object);
  954. objTag = objTag == argsTag ? objectTag : objTag;
  955. }
  956. if (!othIsArr) {
  957. othTag = getTag(other);
  958. othTag = othTag == argsTag ? objectTag : othTag;
  959. }
  960. var objIsObj = objTag == objectTag && !isHostObject(object),
  961. othIsObj = othTag == objectTag && !isHostObject(other),
  962. isSameTag = objTag == othTag;
  963. if (isSameTag && !objIsObj) {
  964. stack || (stack = new Stack);
  965. return (objIsArr || isTypedArray(object))
  966. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  967. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  968. }
  969. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  970. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  971. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  972. if (objIsWrapped || othIsWrapped) {
  973. var objUnwrapped = objIsWrapped ? object.value() : object,
  974. othUnwrapped = othIsWrapped ? other.value() : other;
  975. stack || (stack = new Stack);
  976. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  977. }
  978. }
  979. if (!isSameTag) {
  980. return false;
  981. }
  982. stack || (stack = new Stack);
  983. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  984. }
  985. /**
  986. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  987. *
  988. * @private
  989. * @param {Object} object The object to inspect.
  990. * @param {Object} source The object of property values to match.
  991. * @param {Array} matchData The property names, values, and compare flags to match.
  992. * @param {Function} [customizer] The function to customize comparisons.
  993. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  994. */
  995. function baseIsMatch(object, source, matchData, customizer) {
  996. var index = matchData.length,
  997. length = index,
  998. noCustomizer = !customizer;
  999. if (object == null) {
  1000. return !length;
  1001. }
  1002. object = Object(object);
  1003. while (index--) {
  1004. var data = matchData[index];
  1005. if ((noCustomizer && data[2])
  1006. ? data[1] !== object[data[0]]
  1007. : !(data[0] in object)
  1008. ) {
  1009. return false;
  1010. }
  1011. }
  1012. while (++index < length) {
  1013. data = matchData[index];
  1014. var key = data[0],
  1015. objValue = object[key],
  1016. srcValue = data[1];
  1017. if (noCustomizer && data[2]) {
  1018. if (objValue === undefined && !(key in object)) {
  1019. return false;
  1020. }
  1021. } else {
  1022. var stack = new Stack;
  1023. if (customizer) {
  1024. var result = customizer(objValue, srcValue, key, object, source, stack);
  1025. }
  1026. if (!(result === undefined
  1027. ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
  1028. : result
  1029. )) {
  1030. return false;
  1031. }
  1032. }
  1033. }
  1034. return true;
  1035. }
  1036. /**
  1037. * The base implementation of `_.isNative` without bad shim checks.
  1038. *
  1039. * @private
  1040. * @param {*} value The value to check.
  1041. * @returns {boolean} Returns `true` if `value` is a native function,
  1042. * else `false`.
  1043. */
  1044. function baseIsNative(value) {
  1045. if (!isObject(value) || isMasked(value)) {
  1046. return false;
  1047. }
  1048. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  1049. return pattern.test(toSource(value));
  1050. }
  1051. /**
  1052. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  1053. *
  1054. * @private
  1055. * @param {*} value The value to check.
  1056. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  1057. */
  1058. function baseIsTypedArray(value) {
  1059. return isObjectLike(value) &&
  1060. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  1061. }
  1062. /**
  1063. * The base implementation of `_.iteratee`.
  1064. *
  1065. * @private
  1066. * @param {*} [value=_.identity] The value to convert to an iteratee.
  1067. * @returns {Function} Returns the iteratee.
  1068. */
  1069. function baseIteratee(value) {
  1070. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  1071. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  1072. if (typeof value == 'function') {
  1073. return value;
  1074. }
  1075. if (value == null) {
  1076. return identity;
  1077. }
  1078. if (typeof value == 'object') {
  1079. return isArray(value)
  1080. ? baseMatchesProperty(value[0], value[1])
  1081. : baseMatches(value);
  1082. }
  1083. return property(value);
  1084. }
  1085. /**
  1086. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  1087. *
  1088. * @private
  1089. * @param {Object} object The object to query.
  1090. * @returns {Array} Returns the array of property names.
  1091. */
  1092. function baseKeys(object) {
  1093. if (!isPrototype(object)) {
  1094. return nativeKeys(object);
  1095. }
  1096. var result = [];
  1097. for (var key in Object(object)) {
  1098. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  1099. result.push(key);
  1100. }
  1101. }
  1102. return result;
  1103. }
  1104. /**
  1105. * The base implementation of `_.map` without support for iteratee shorthands.
  1106. *
  1107. * @private
  1108. * @param {Array|Object} collection The collection to iterate over.
  1109. * @param {Function} iteratee The function invoked per iteration.
  1110. * @returns {Array} Returns the new mapped array.
  1111. */
  1112. function baseMap(collection, iteratee) {
  1113. var index = -1,
  1114. result = isArrayLike(collection) ? Array(collection.length) : [];
  1115. baseEach(collection, function(value, key, collection) {
  1116. result[++index] = iteratee(value, key, collection);
  1117. });
  1118. return result;
  1119. }
  1120. /**
  1121. * The base implementation of `_.matches` which doesn't clone `source`.
  1122. *
  1123. * @private
  1124. * @param {Object} source The object of property values to match.
  1125. * @returns {Function} Returns the new spec function.
  1126. */
  1127. function baseMatches(source) {
  1128. var matchData = getMatchData(source);
  1129. if (matchData.length == 1 && matchData[0][2]) {
  1130. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  1131. }
  1132. return function(object) {
  1133. return object === source || baseIsMatch(object, source, matchData);
  1134. };
  1135. }
  1136. /**
  1137. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  1138. *
  1139. * @private
  1140. * @param {string} path The path of the property to get.
  1141. * @param {*} srcValue The value to match.
  1142. * @returns {Function} Returns the new spec function.
  1143. */
  1144. function baseMatchesProperty(path, srcValue) {
  1145. if (isKey(path) && isStrictComparable(srcValue)) {
  1146. return matchesStrictComparable(toKey(path), srcValue);
  1147. }
  1148. return function(object) {
  1149. var objValue = get(object, path);
  1150. return (objValue === undefined && objValue === srcValue)
  1151. ? hasIn(object, path)
  1152. : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  1153. };
  1154. }
  1155. /**
  1156. * The base implementation of `_.orderBy` without param guards.
  1157. *
  1158. * @private
  1159. * @param {Array|Object} collection The collection to iterate over.
  1160. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  1161. * @param {string[]} orders The sort orders of `iteratees`.
  1162. * @returns {Array} Returns the new sorted array.
  1163. */
  1164. function baseOrderBy(collection, iteratees, orders) {
  1165. var index = -1;
  1166. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(baseIteratee));
  1167. var result = baseMap(collection, function(value, key, collection) {
  1168. var criteria = arrayMap(iteratees, function(iteratee) {
  1169. return iteratee(value);
  1170. });
  1171. return { 'criteria': criteria, 'index': ++index, 'value': value };
  1172. });
  1173. return baseSortBy(result, function(object, other) {
  1174. return compareMultiple(object, other, orders);
  1175. });
  1176. }
  1177. /**
  1178. * A specialized version of `baseProperty` which supports deep paths.
  1179. *
  1180. * @private
  1181. * @param {Array|string} path The path of the property to get.
  1182. * @returns {Function} Returns the new accessor function.
  1183. */
  1184. function basePropertyDeep(path) {
  1185. return function(object) {
  1186. return baseGet(object, path);
  1187. };
  1188. }
  1189. /**
  1190. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  1191. *
  1192. * @private
  1193. * @param {Function} func The function to apply a rest parameter to.
  1194. * @param {number} [start=func.length-1] The start position of the rest parameter.
  1195. * @returns {Function} Returns the new function.
  1196. */
  1197. function baseRest(func, start) {
  1198. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  1199. return function() {
  1200. var args = arguments,
  1201. index = -1,
  1202. length = nativeMax(args.length - start, 0),
  1203. array = Array(length);
  1204. while (++index < length) {
  1205. array[index] = args[start + index];
  1206. }
  1207. index = -1;
  1208. var otherArgs = Array(start + 1);
  1209. while (++index < start) {
  1210. otherArgs[index] = args[index];
  1211. }
  1212. otherArgs[start] = array;
  1213. return apply(func, this, otherArgs);
  1214. };
  1215. }
  1216. /**
  1217. * The base implementation of `_.toString` which doesn't convert nullish
  1218. * values to empty strings.
  1219. *
  1220. * @private
  1221. * @param {*} value The value to process.
  1222. * @returns {string} Returns the string.
  1223. */
  1224. function baseToString(value) {
  1225. // Exit early for strings to avoid a performance hit in some environments.
  1226. if (typeof value == 'string') {
  1227. return value;
  1228. }
  1229. if (isSymbol(value)) {
  1230. return symbolToString ? symbolToString.call(value) : '';
  1231. }
  1232. var result = (value + '');
  1233. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  1234. }
  1235. /**
  1236. * Casts `value` to a path array if it's not one.
  1237. *
  1238. * @private
  1239. * @param {*} value The value to inspect.
  1240. * @returns {Array} Returns the cast property path array.
  1241. */
  1242. function castPath(value) {
  1243. return isArray(value) ? value : stringToPath(value);
  1244. }
  1245. /**
  1246. * Compares values to sort them in ascending order.
  1247. *
  1248. * @private
  1249. * @param {*} value The value to compare.
  1250. * @param {*} other The other value to compare.
  1251. * @returns {number} Returns the sort order indicator for `value`.
  1252. */
  1253. function compareAscending(value, other) {
  1254. if (value !== other) {
  1255. var valIsDefined = value !== undefined,
  1256. valIsNull = value === null,
  1257. valIsReflexive = value === value,
  1258. valIsSymbol = isSymbol(value);
  1259. var othIsDefined = other !== undefined,
  1260. othIsNull = other === null,
  1261. othIsReflexive = other === other,
  1262. othIsSymbol = isSymbol(other);
  1263. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  1264. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  1265. (valIsNull && othIsDefined && othIsReflexive) ||
  1266. (!valIsDefined && othIsReflexive) ||
  1267. !valIsReflexive) {
  1268. return 1;
  1269. }
  1270. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  1271. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  1272. (othIsNull && valIsDefined && valIsReflexive) ||
  1273. (!othIsDefined && valIsReflexive) ||
  1274. !othIsReflexive) {
  1275. return -1;
  1276. }
  1277. }
  1278. return 0;
  1279. }
  1280. /**
  1281. * Used by `_.orderBy` to compare multiple properties of a value to another
  1282. * and stable sort them.
  1283. *
  1284. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  1285. * specify an order of "desc" for descending or "asc" for ascending sort order
  1286. * of corresponding values.
  1287. *
  1288. * @private
  1289. * @param {Object} object The object to compare.
  1290. * @param {Object} other The other object to compare.
  1291. * @param {boolean[]|string[]} orders The order to sort by for each property.
  1292. * @returns {number} Returns the sort order indicator for `object`.
  1293. */
  1294. function compareMultiple(object, other, orders) {
  1295. var index = -1,
  1296. objCriteria = object.criteria,
  1297. othCriteria = other.criteria,
  1298. length = objCriteria.length,
  1299. ordersLength = orders.length;
  1300. while (++index < length) {
  1301. var result = compareAscending(objCriteria[index], othCriteria[index]);
  1302. if (result) {
  1303. if (index >= ordersLength) {
  1304. return result;
  1305. }
  1306. var order = orders[index];
  1307. return result * (order == 'desc' ? -1 : 1);
  1308. }
  1309. }
  1310. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  1311. // that causes it, under certain circumstances, to provide the same value for
  1312. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  1313. // for more details.
  1314. //
  1315. // This also ensures a stable sort in V8 and other engines.
  1316. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  1317. return object.index - other.index;
  1318. }
  1319. /**
  1320. * Creates a `baseEach` or `baseEachRight` function.
  1321. *
  1322. * @private
  1323. * @param {Function} eachFunc The function to iterate over a collection.
  1324. * @param {boolean} [fromRight] Specify iterating from right to left.
  1325. * @returns {Function} Returns the new base function.
  1326. */
  1327. function createBaseEach(eachFunc, fromRight) {
  1328. return function(collection, iteratee) {
  1329. if (collection == null) {
  1330. return collection;
  1331. }
  1332. if (!isArrayLike(collection)) {
  1333. return eachFunc(collection, iteratee);
  1334. }
  1335. var length = collection.length,
  1336. index = fromRight ? length : -1,
  1337. iterable = Object(collection);
  1338. while ((fromRight ? index-- : ++index < length)) {
  1339. if (iteratee(iterable[index], index, iterable) === false) {
  1340. break;
  1341. }
  1342. }
  1343. return collection;
  1344. };
  1345. }
  1346. /**
  1347. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  1348. *
  1349. * @private
  1350. * @param {boolean} [fromRight] Specify iterating from right to left.
  1351. * @returns {Function} Returns the new base function.
  1352. */
  1353. function createBaseFor(fromRight) {
  1354. return function(object, iteratee, keysFunc) {
  1355. var index = -1,
  1356. iterable = Object(object),
  1357. props = keysFunc(object),
  1358. length = props.length;
  1359. while (length--) {
  1360. var key = props[fromRight ? length : ++index];
  1361. if (iteratee(iterable[key], key, iterable) === false) {
  1362. break;
  1363. }
  1364. }
  1365. return object;
  1366. };
  1367. }
  1368. /**
  1369. * A specialized version of `baseIsEqualDeep` for arrays with support for
  1370. * partial deep comparisons.
  1371. *
  1372. * @private
  1373. * @param {Array} array The array to compare.
  1374. * @param {Array} other The other array to compare.
  1375. * @param {Function} equalFunc The function to determine equivalents of values.
  1376. * @param {Function} customizer The function to customize comparisons.
  1377. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1378. * for more details.
  1379. * @param {Object} stack Tracks traversed `array` and `other` objects.
  1380. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  1381. */
  1382. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  1383. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  1384. arrLength = array.length,
  1385. othLength = other.length;
  1386. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  1387. return false;
  1388. }
  1389. // Assume cyclic values are equal.
  1390. var stacked = stack.get(array);
  1391. if (stacked && stack.get(other)) {
  1392. return stacked == other;
  1393. }
  1394. var index = -1,
  1395. result = true,
  1396. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
  1397. stack.set(array, other);
  1398. stack.set(other, array);
  1399. // Ignore non-index properties.
  1400. while (++index < arrLength) {
  1401. var arrValue = array[index],
  1402. othValue = other[index];
  1403. if (customizer) {
  1404. var compared = isPartial
  1405. ? customizer(othValue, arrValue, index, other, array, stack)
  1406. : customizer(arrValue, othValue, index, array, other, stack);
  1407. }
  1408. if (compared !== undefined) {
  1409. if (compared) {
  1410. continue;
  1411. }
  1412. result = false;
  1413. break;
  1414. }
  1415. // Recursively compare arrays (susceptible to call stack limits).
  1416. if (seen) {
  1417. if (!arraySome(other, function(othValue, othIndex) {
  1418. if (!seen.has(othIndex) &&
  1419. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  1420. return seen.add(othIndex);
  1421. }
  1422. })) {
  1423. result = false;
  1424. break;
  1425. }
  1426. } else if (!(
  1427. arrValue === othValue ||
  1428. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  1429. )) {
  1430. result = false;
  1431. break;
  1432. }
  1433. }
  1434. stack['delete'](array);
  1435. stack['delete'](other);
  1436. return result;
  1437. }
  1438. /**
  1439. * A specialized version of `baseIsEqualDeep` for comparing objects of
  1440. * the same `toStringTag`.
  1441. *
  1442. * **Note:** This function only supports comparing values with tags of
  1443. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  1444. *
  1445. * @private
  1446. * @param {Object} object The object to compare.
  1447. * @param {Object} other The other object to compare.
  1448. * @param {string} tag The `toStringTag` of the objects to compare.
  1449. * @param {Function} equalFunc The function to determine equivalents of values.
  1450. * @param {Function} customizer The function to customize comparisons.
  1451. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1452. * for more details.
  1453. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1454. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1455. */
  1456. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  1457. switch (tag) {
  1458. case dataViewTag:
  1459. if ((object.byteLength != other.byteLength) ||
  1460. (object.byteOffset != other.byteOffset)) {
  1461. return false;
  1462. }
  1463. object = object.buffer;
  1464. other = other.buffer;
  1465. case arrayBufferTag:
  1466. if ((object.byteLength != other.byteLength) ||
  1467. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  1468. return false;
  1469. }
  1470. return true;
  1471. case boolTag:
  1472. case dateTag:
  1473. case numberTag:
  1474. // Coerce booleans to `1` or `0` and dates to milliseconds.
  1475. // Invalid dates are coerced to `NaN`.
  1476. return eq(+object, +other);
  1477. case errorTag:
  1478. return object.name == other.name && object.message == other.message;
  1479. case regexpTag:
  1480. case stringTag:
  1481. // Coerce regexes to strings and treat strings, primitives and objects,
  1482. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  1483. // for more details.
  1484. return object == (other + '');
  1485. case mapTag:
  1486. var convert = mapToArray;
  1487. case setTag:
  1488. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  1489. convert || (convert = setToArray);
  1490. if (object.size != other.size && !isPartial) {
  1491. return false;
  1492. }
  1493. // Assume cyclic values are equal.
  1494. var stacked = stack.get(object);
  1495. if (stacked) {
  1496. return stacked == other;
  1497. }
  1498. bitmask |= UNORDERED_COMPARE_FLAG;
  1499. // Recursively compare objects (susceptible to call stack limits).
  1500. stack.set(object, other);
  1501. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  1502. stack['delete'](object);
  1503. return result;
  1504. case symbolTag:
  1505. if (symbolValueOf) {
  1506. return symbolValueOf.call(object) == symbolValueOf.call(other);
  1507. }
  1508. }
  1509. return false;
  1510. }
  1511. /**
  1512. * A specialized version of `baseIsEqualDeep` for objects with support for
  1513. * partial deep comparisons.
  1514. *
  1515. * @private
  1516. * @param {Object} object The object to compare.
  1517. * @param {Object} other The other object to compare.
  1518. * @param {Function} equalFunc The function to determine equivalents of values.
  1519. * @param {Function} customizer The function to customize comparisons.
  1520. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1521. * for more details.
  1522. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1523. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1524. */
  1525. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  1526. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  1527. objProps = keys(object),
  1528. objLength = objProps.length,
  1529. othProps = keys(other),
  1530. othLength = othProps.length;
  1531. if (objLength != othLength && !isPartial) {
  1532. return false;
  1533. }
  1534. var index = objLength;
  1535. while (index--) {
  1536. var key = objProps[index];
  1537. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  1538. return false;
  1539. }
  1540. }
  1541. // Assume cyclic values are equal.
  1542. var stacked = stack.get(object);
  1543. if (stacked && stack.get(other)) {
  1544. return stacked == other;
  1545. }
  1546. var result = true;
  1547. stack.set(object, other);
  1548. stack.set(other, object);
  1549. var skipCtor = isPartial;
  1550. while (++index < objLength) {
  1551. key = objProps[index];
  1552. var objValue = object[key],
  1553. othValue = other[key];
  1554. if (customizer) {
  1555. var compared = isPartial
  1556. ? customizer(othValue, objValue, key, other, object, stack)
  1557. : customizer(objValue, othValue, key, object, other, stack);
  1558. }
  1559. // Recursively compare objects (susceptible to call stack limits).
  1560. if (!(compared === undefined
  1561. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  1562. : compared
  1563. )) {
  1564. result = false;
  1565. break;
  1566. }
  1567. skipCtor || (skipCtor = key == 'constructor');
  1568. }
  1569. if (result && !skipCtor) {
  1570. var objCtor = object.constructor,
  1571. othCtor = other.constructor;
  1572. // Non `Object` object instances with different constructors are not equal.
  1573. if (objCtor != othCtor &&
  1574. ('constructor' in object && 'constructor' in other) &&
  1575. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  1576. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  1577. result = false;
  1578. }
  1579. }
  1580. stack['delete'](object);
  1581. stack['delete'](other);
  1582. return result;
  1583. }
  1584. /**
  1585. * Gets the data for `map`.
  1586. *
  1587. * @private
  1588. * @param {Object} map The map to query.
  1589. * @param {string} key The reference key.
  1590. * @returns {*} Returns the map data.
  1591. */
  1592. function getMapData(map, key) {
  1593. var data = map.__data__;
  1594. return isKeyable(key)
  1595. ? data[typeof key == 'string' ? 'string' : 'hash']
  1596. : data.map;
  1597. }
  1598. /**
  1599. * Gets the property names, values, and compare flags of `object`.
  1600. *
  1601. * @private
  1602. * @param {Object} object The object to query.
  1603. * @returns {Array} Returns the match data of `object`.
  1604. */
  1605. function getMatchData(object) {
  1606. var result = keys(object),
  1607. length = result.length;
  1608. while (length--) {
  1609. var key = result[length],
  1610. value = object[key];
  1611. result[length] = [key, value, isStrictComparable(value)];
  1612. }
  1613. return result;
  1614. }
  1615. /**
  1616. * Gets the native function at `key` of `object`.
  1617. *
  1618. * @private
  1619. * @param {Object} object The object to query.
  1620. * @param {string} key The key of the method to get.
  1621. * @returns {*} Returns the function if it's native, else `undefined`.
  1622. */
  1623. function getNative(object, key) {
  1624. var value = getValue(object, key);
  1625. return baseIsNative(value) ? value : undefined;
  1626. }
  1627. /**
  1628. * Gets the `toStringTag` of `value`.
  1629. *
  1630. * @private
  1631. * @param {*} value The value to query.
  1632. * @returns {string} Returns the `toStringTag`.
  1633. */
  1634. var getTag = baseGetTag;
  1635. // Fallback for data views, maps, sets, and weak maps in IE 11,
  1636. // for data views in Edge < 14, and promises in Node.js.
  1637. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  1638. (Map && getTag(new Map) != mapTag) ||
  1639. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  1640. (Set && getTag(new Set) != setTag) ||
  1641. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  1642. getTag = function(value) {
  1643. var result = objectToString.call(value),
  1644. Ctor = result == objectTag ? value.constructor : undefined,
  1645. ctorString = Ctor ? toSource(Ctor) : undefined;
  1646. if (ctorString) {
  1647. switch (ctorString) {
  1648. case dataViewCtorString: return dataViewTag;
  1649. case mapCtorString: return mapTag;
  1650. case promiseCtorString: return promiseTag;
  1651. case setCtorString: return setTag;
  1652. case weakMapCtorString: return weakMapTag;
  1653. }
  1654. }
  1655. return result;
  1656. };
  1657. }
  1658. /**
  1659. * Checks if `path` exists on `object`.
  1660. *
  1661. * @private
  1662. * @param {Object} object The object to query.
  1663. * @param {Array|string} path The path to check.
  1664. * @param {Function} hasFunc The function to check properties.
  1665. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  1666. */
  1667. function hasPath(object, path, hasFunc) {
  1668. path = isKey(path, object) ? [path] : castPath(path);
  1669. var result,
  1670. index = -1,
  1671. length = path.length;
  1672. while (++index < length) {
  1673. var key = toKey(path[index]);
  1674. if (!(result = object != null && hasFunc(object, key))) {
  1675. break;
  1676. }
  1677. object = object[key];
  1678. }
  1679. if (result) {
  1680. return result;
  1681. }
  1682. var length = object ? object.length : 0;
  1683. return !!length && isLength(length) && isIndex(key, length) &&
  1684. (isArray(object) || isArguments(object));
  1685. }
  1686. /**
  1687. * Checks if `value` is a flattenable `arguments` object or array.
  1688. *
  1689. * @private
  1690. * @param {*} value The value to check.
  1691. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  1692. */
  1693. function isFlattenable(value) {
  1694. return isArray(value) || isArguments(value) ||
  1695. !!(spreadableSymbol && value && value[spreadableSymbol]);
  1696. }
  1697. /**
  1698. * Checks if `value` is a valid array-like index.
  1699. *
  1700. * @private
  1701. * @param {*} value The value to check.
  1702. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  1703. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  1704. */
  1705. function isIndex(value, length) {
  1706. length = length == null ? MAX_SAFE_INTEGER : length;
  1707. return !!length &&
  1708. (typeof value == 'number' || reIsUint.test(value)) &&
  1709. (value > -1 && value % 1 == 0 && value < length);
  1710. }
  1711. /**
  1712. * Checks if the given arguments are from an iteratee call.
  1713. *
  1714. * @private
  1715. * @param {*} value The potential iteratee value argument.
  1716. * @param {*} index The potential iteratee index or key argument.
  1717. * @param {*} object The potential iteratee object argument.
  1718. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  1719. * else `false`.
  1720. */
  1721. function isIterateeCall(value, index, object) {
  1722. if (!isObject(object)) {
  1723. return false;
  1724. }
  1725. var type = typeof index;
  1726. if (type == 'number'
  1727. ? (isArrayLike(object) && isIndex(index, object.length))
  1728. : (type == 'string' && index in object)
  1729. ) {
  1730. return eq(object[index], value);
  1731. }
  1732. return false;
  1733. }
  1734. /**
  1735. * Checks if `value` is a property name and not a property path.
  1736. *
  1737. * @private
  1738. * @param {*} value The value to check.
  1739. * @param {Object} [object] The object to query keys on.
  1740. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  1741. */
  1742. function isKey(value, object) {
  1743. if (isArray(value)) {
  1744. return false;
  1745. }
  1746. var type = typeof value;
  1747. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  1748. value == null || isSymbol(value)) {
  1749. return true;
  1750. }
  1751. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  1752. (object != null && value in Object(object));
  1753. }
  1754. /**
  1755. * Checks if `value` is suitable for use as unique object key.
  1756. *
  1757. * @private
  1758. * @param {*} value The value to check.
  1759. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  1760. */
  1761. function isKeyable(value) {
  1762. var type = typeof value;
  1763. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  1764. ? (value !== '__proto__')
  1765. : (value === null);
  1766. }
  1767. /**
  1768. * Checks if `func` has its source masked.
  1769. *
  1770. * @private
  1771. * @param {Function} func The function to check.
  1772. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  1773. */
  1774. function isMasked(func) {
  1775. return !!maskSrcKey && (maskSrcKey in func);
  1776. }
  1777. /**
  1778. * Checks if `value` is likely a prototype object.
  1779. *
  1780. * @private
  1781. * @param {*} value The value to check.
  1782. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  1783. */
  1784. function isPrototype(value) {
  1785. var Ctor = value && value.constructor,
  1786. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  1787. return value === proto;
  1788. }
  1789. /**
  1790. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  1791. *
  1792. * @private
  1793. * @param {*} value The value to check.
  1794. * @returns {boolean} Returns `true` if `value` if suitable for strict
  1795. * equality comparisons, else `false`.
  1796. */
  1797. function isStrictComparable(value) {
  1798. return value === value && !isObject(value);
  1799. }
  1800. /**
  1801. * A specialized version of `matchesProperty` for source values suitable
  1802. * for strict equality comparisons, i.e. `===`.
  1803. *
  1804. * @private
  1805. * @param {string} key The key of the property to get.
  1806. * @param {*} srcValue The value to match.
  1807. * @returns {Function} Returns the new spec function.
  1808. */
  1809. function matchesStrictComparable(key, srcValue) {
  1810. return function(object) {
  1811. if (object == null) {
  1812. return false;
  1813. }
  1814. return object[key] === srcValue &&
  1815. (srcValue !== undefined || (key in Object(object)));
  1816. };
  1817. }
  1818. /**
  1819. * Converts `string` to a property path array.
  1820. *
  1821. * @private
  1822. * @param {string} string The string to convert.
  1823. * @returns {Array} Returns the property path array.
  1824. */
  1825. var stringToPath = memoize(function(string) {
  1826. string = toString(string);
  1827. var result = [];
  1828. if (reLeadingDot.test(string)) {
  1829. result.push('');
  1830. }
  1831. string.replace(rePropName, function(match, number, quote, string) {
  1832. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  1833. });
  1834. return result;
  1835. });
  1836. /**
  1837. * Converts `value` to a string key if it's not a string or symbol.
  1838. *
  1839. * @private
  1840. * @param {*} value The value to inspect.
  1841. * @returns {string|symbol} Returns the key.
  1842. */
  1843. function toKey(value) {
  1844. if (typeof value == 'string' || isSymbol(value)) {
  1845. return value;
  1846. }
  1847. var result = (value + '');
  1848. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  1849. }
  1850. /**
  1851. * Converts `func` to its source code.
  1852. *
  1853. * @private
  1854. * @param {Function} func The function to process.
  1855. * @returns {string} Returns the source code.
  1856. */
  1857. function toSource(func) {
  1858. if (func != null) {
  1859. try {
  1860. return funcToString.call(func);
  1861. } catch (e) {}
  1862. try {
  1863. return (func + '');
  1864. } catch (e) {}
  1865. }
  1866. return '';
  1867. }
  1868. /**
  1869. * Creates an array of elements, sorted in ascending order by the results of
  1870. * running each element in a collection thru each iteratee. This method
  1871. * performs a stable sort, that is, it preserves the original sort order of
  1872. * equal elements. The iteratees are invoked with one argument: (value).
  1873. *
  1874. * @static
  1875. * @memberOf _
  1876. * @since 0.1.0
  1877. * @category Collection
  1878. * @param {Array|Object} collection The collection to iterate over.
  1879. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  1880. * The iteratees to sort by.
  1881. * @returns {Array} Returns the new sorted array.
  1882. * @example
  1883. *
  1884. * var users = [
  1885. * { 'user': 'fred', 'age': 48 },
  1886. * { 'user': 'barney', 'age': 36 },
  1887. * { 'user': 'fred', 'age': 40 },
  1888. * { 'user': 'barney', 'age': 34 }
  1889. * ];
  1890. *
  1891. * _.sortBy(users, function(o) { return o.user; });
  1892. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  1893. *
  1894. * _.sortBy(users, ['user', 'age']);
  1895. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  1896. *
  1897. * _.sortBy(users, 'user', function(o) {
  1898. * return Math.floor(o.age / 10);
  1899. * });
  1900. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  1901. */
  1902. var sortBy = baseRest(function(collection, iteratees) {
  1903. if (collection == null) {
  1904. return [];
  1905. }
  1906. var length = iteratees.length;
  1907. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  1908. iteratees = [];
  1909. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  1910. iteratees = [iteratees[0]];
  1911. }
  1912. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  1913. });
  1914. /**
  1915. * Creates a function that memoizes the result of `func`. If `resolver` is
  1916. * provided, it determines the cache key for storing the result based on the
  1917. * arguments provided to the memoized function. By default, the first argument
  1918. * provided to the memoized function is used as the map cache key. The `func`
  1919. * is invoked with the `this` binding of the memoized function.
  1920. *
  1921. * **Note:** The cache is exposed as the `cache` property on the memoized
  1922. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  1923. * constructor with one whose instances implement the
  1924. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  1925. * method interface of `delete`, `get`, `has`, and `set`.
  1926. *
  1927. * @static
  1928. * @memberOf _
  1929. * @since 0.1.0
  1930. * @category Function
  1931. * @param {Function} func The function to have its output memoized.
  1932. * @param {Function} [resolver] The function to resolve the cache key.
  1933. * @returns {Function} Returns the new memoized function.
  1934. * @example
  1935. *
  1936. * var object = { 'a': 1, 'b': 2 };
  1937. * var other = { 'c': 3, 'd': 4 };
  1938. *
  1939. * var values = _.memoize(_.values);
  1940. * values(object);
  1941. * // => [1, 2]
  1942. *
  1943. * values(other);
  1944. * // => [3, 4]
  1945. *
  1946. * object.a = 2;
  1947. * values(object);
  1948. * // => [1, 2]
  1949. *
  1950. * // Modify the result cache.
  1951. * values.cache.set(object, ['a', 'b']);
  1952. * values(object);
  1953. * // => ['a', 'b']
  1954. *
  1955. * // Replace `_.memoize.Cache`.
  1956. * _.memoize.Cache = WeakMap;
  1957. */
  1958. function memoize(func, resolver) {
  1959. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  1960. throw new TypeError(FUNC_ERROR_TEXT);
  1961. }
  1962. var memoized = function() {
  1963. var args = arguments,
  1964. key = resolver ? resolver.apply(this, args) : args[0],
  1965. cache = memoized.cache;
  1966. if (cache.has(key)) {
  1967. return cache.get(key);
  1968. }
  1969. var result = func.apply(this, args);
  1970. memoized.cache = cache.set(key, result);
  1971. return result;
  1972. };
  1973. memoized.cache = new (memoize.Cache || MapCache);
  1974. return memoized;
  1975. }
  1976. // Assign cache to `_.memoize`.
  1977. memoize.Cache = MapCache;
  1978. /**
  1979. * Performs a
  1980. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1981. * comparison between two values to determine if they are equivalent.
  1982. *
  1983. * @static
  1984. * @memberOf _
  1985. * @since 4.0.0
  1986. * @category Lang
  1987. * @param {*} value The value to compare.
  1988. * @param {*} other The other value to compare.
  1989. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  1990. * @example
  1991. *
  1992. * var object = { 'a': 1 };
  1993. * var other = { 'a': 1 };
  1994. *
  1995. * _.eq(object, object);
  1996. * // => true
  1997. *
  1998. * _.eq(object, other);
  1999. * // => false
  2000. *
  2001. * _.eq('a', 'a');
  2002. * // => true
  2003. *
  2004. * _.eq('a', Object('a'));
  2005. * // => false
  2006. *
  2007. * _.eq(NaN, NaN);
  2008. * // => true
  2009. */
  2010. function eq(value, other) {
  2011. return value === other || (value !== value && other !== other);
  2012. }
  2013. /**
  2014. * Checks if `value` is likely an `arguments` object.
  2015. *
  2016. * @static
  2017. * @memberOf _
  2018. * @since 0.1.0
  2019. * @category Lang
  2020. * @param {*} value The value to check.
  2021. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2022. * else `false`.
  2023. * @example
  2024. *
  2025. * _.isArguments(function() { return arguments; }());
  2026. * // => true
  2027. *
  2028. * _.isArguments([1, 2, 3]);
  2029. * // => false
  2030. */
  2031. function isArguments(value) {
  2032. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  2033. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  2034. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  2035. }
  2036. /**
  2037. * Checks if `value` is classified as an `Array` object.
  2038. *
  2039. * @static
  2040. * @memberOf _
  2041. * @since 0.1.0
  2042. * @category Lang
  2043. * @param {*} value The value to check.
  2044. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  2045. * @example
  2046. *
  2047. * _.isArray([1, 2, 3]);
  2048. * // => true
  2049. *
  2050. * _.isArray(document.body.children);
  2051. * // => false
  2052. *
  2053. * _.isArray('abc');
  2054. * // => false
  2055. *
  2056. * _.isArray(_.noop);
  2057. * // => false
  2058. */
  2059. var isArray = Array.isArray;
  2060. /**
  2061. * Checks if `value` is array-like. A value is considered array-like if it's
  2062. * not a function and has a `value.length` that's an integer greater than or
  2063. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  2064. *
  2065. * @static
  2066. * @memberOf _
  2067. * @since 4.0.0
  2068. * @category Lang
  2069. * @param {*} value The value to check.
  2070. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  2071. * @example
  2072. *
  2073. * _.isArrayLike([1, 2, 3]);
  2074. * // => true
  2075. *
  2076. * _.isArrayLike(document.body.children);
  2077. * // => true
  2078. *
  2079. * _.isArrayLike('abc');
  2080. * // => true
  2081. *
  2082. * _.isArrayLike(_.noop);
  2083. * // => false
  2084. */
  2085. function isArrayLike(value) {
  2086. return value != null && isLength(value.length) && !isFunction(value);
  2087. }
  2088. /**
  2089. * This method is like `_.isArrayLike` except that it also checks if `value`
  2090. * is an object.
  2091. *
  2092. * @static
  2093. * @memberOf _
  2094. * @since 4.0.0
  2095. * @category Lang
  2096. * @param {*} value The value to check.
  2097. * @returns {boolean} Returns `true` if `value` is an array-like object,
  2098. * else `false`.
  2099. * @example
  2100. *
  2101. * _.isArrayLikeObject([1, 2, 3]);
  2102. * // => true
  2103. *
  2104. * _.isArrayLikeObject(document.body.children);
  2105. * // => true
  2106. *
  2107. * _.isArrayLikeObject('abc');
  2108. * // => false
  2109. *
  2110. * _.isArrayLikeObject(_.noop);
  2111. * // => false
  2112. */
  2113. function isArrayLikeObject(value) {
  2114. return isObjectLike(value) && isArrayLike(value);
  2115. }
  2116. /**
  2117. * Checks if `value` is classified as a `Function` object.
  2118. *
  2119. * @static
  2120. * @memberOf _
  2121. * @since 0.1.0
  2122. * @category Lang
  2123. * @param {*} value The value to check.
  2124. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  2125. * @example
  2126. *
  2127. * _.isFunction(_);
  2128. * // => true
  2129. *
  2130. * _.isFunction(/abc/);
  2131. * // => false
  2132. */
  2133. function isFunction(value) {
  2134. // The use of `Object#toString` avoids issues with the `typeof` operator
  2135. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  2136. var tag = isObject(value) ? objectToString.call(value) : '';
  2137. return tag == funcTag || tag == genTag;
  2138. }
  2139. /**
  2140. * Checks if `value` is a valid array-like length.
  2141. *
  2142. * **Note:** This method is loosely based on
  2143. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  2144. *
  2145. * @static
  2146. * @memberOf _
  2147. * @since 4.0.0
  2148. * @category Lang
  2149. * @param {*} value The value to check.
  2150. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  2151. * @example
  2152. *
  2153. * _.isLength(3);
  2154. * // => true
  2155. *
  2156. * _.isLength(Number.MIN_VALUE);
  2157. * // => false
  2158. *
  2159. * _.isLength(Infinity);
  2160. * // => false
  2161. *
  2162. * _.isLength('3');
  2163. * // => false
  2164. */
  2165. function isLength(value) {
  2166. return typeof value == 'number' &&
  2167. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  2168. }
  2169. /**
  2170. * Checks if `value` is the
  2171. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  2172. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  2173. *
  2174. * @static
  2175. * @memberOf _
  2176. * @since 0.1.0
  2177. * @category Lang
  2178. * @param {*} value The value to check.
  2179. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  2180. * @example
  2181. *
  2182. * _.isObject({});
  2183. * // => true
  2184. *
  2185. * _.isObject([1, 2, 3]);
  2186. * // => true
  2187. *
  2188. * _.isObject(_.noop);
  2189. * // => true
  2190. *
  2191. * _.isObject(null);
  2192. * // => false
  2193. */
  2194. function isObject(value) {
  2195. var type = typeof value;
  2196. return !!value && (type == 'object' || type == 'function');
  2197. }
  2198. /**
  2199. * Checks if `value` is object-like. A value is object-like if it's not `null`
  2200. * and has a `typeof` result of "object".
  2201. *
  2202. * @static
  2203. * @memberOf _
  2204. * @since 4.0.0
  2205. * @category Lang
  2206. * @param {*} value The value to check.
  2207. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  2208. * @example
  2209. *
  2210. * _.isObjectLike({});
  2211. * // => true
  2212. *
  2213. * _.isObjectLike([1, 2, 3]);
  2214. * // => true
  2215. *
  2216. * _.isObjectLike(_.noop);
  2217. * // => false
  2218. *
  2219. * _.isObjectLike(null);
  2220. * // => false
  2221. */
  2222. function isObjectLike(value) {
  2223. return !!value && typeof value == 'object';
  2224. }
  2225. /**
  2226. * Checks if `value` is classified as a `Symbol` primitive or object.
  2227. *
  2228. * @static
  2229. * @memberOf _
  2230. * @since 4.0.0
  2231. * @category Lang
  2232. * @param {*} value The value to check.
  2233. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  2234. * @example
  2235. *
  2236. * _.isSymbol(Symbol.iterator);
  2237. * // => true
  2238. *
  2239. * _.isSymbol('abc');
  2240. * // => false
  2241. */
  2242. function isSymbol(value) {
  2243. return typeof value == 'symbol' ||
  2244. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  2245. }
  2246. /**
  2247. * Checks if `value` is classified as a typed array.
  2248. *
  2249. * @static
  2250. * @memberOf _
  2251. * @since 3.0.0
  2252. * @category Lang
  2253. * @param {*} value The value to check.
  2254. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  2255. * @example
  2256. *
  2257. * _.isTypedArray(new Uint8Array);
  2258. * // => true
  2259. *
  2260. * _.isTypedArray([]);
  2261. * // => false
  2262. */
  2263. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  2264. /**
  2265. * Converts `value` to a string. An empty string is returned for `null`
  2266. * and `undefined` values. The sign of `-0` is preserved.
  2267. *
  2268. * @static
  2269. * @memberOf _
  2270. * @since 4.0.0
  2271. * @category Lang
  2272. * @param {*} value The value to process.
  2273. * @returns {string} Returns the string.
  2274. * @example
  2275. *
  2276. * _.toString(null);
  2277. * // => ''
  2278. *
  2279. * _.toString(-0);
  2280. * // => '-0'
  2281. *
  2282. * _.toString([1, 2, 3]);
  2283. * // => '1,2,3'
  2284. */
  2285. function toString(value) {
  2286. return value == null ? '' : baseToString(value);
  2287. }
  2288. /**
  2289. * Gets the value at `path` of `object`. If the resolved value is
  2290. * `undefined`, the `defaultValue` is returned in its place.
  2291. *
  2292. * @static
  2293. * @memberOf _
  2294. * @since 3.7.0
  2295. * @category Object
  2296. * @param {Object} object The object to query.
  2297. * @param {Array|string} path The path of the property to get.
  2298. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  2299. * @returns {*} Returns the resolved value.
  2300. * @example
  2301. *
  2302. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  2303. *
  2304. * _.get(object, 'a[0].b.c');
  2305. * // => 3
  2306. *
  2307. * _.get(object, ['a', '0', 'b', 'c']);
  2308. * // => 3
  2309. *
  2310. * _.get(object, 'a.b.c', 'default');
  2311. * // => 'default'
  2312. */
  2313. function get(object, path, defaultValue) {
  2314. var result = object == null ? undefined : baseGet(object, path);
  2315. return result === undefined ? defaultValue : result;
  2316. }
  2317. /**
  2318. * Checks if `path` is a direct or inherited property of `object`.
  2319. *
  2320. * @static
  2321. * @memberOf _
  2322. * @since 4.0.0
  2323. * @category Object
  2324. * @param {Object} object The object to query.
  2325. * @param {Array|string} path The path to check.
  2326. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  2327. * @example
  2328. *
  2329. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  2330. *
  2331. * _.hasIn(object, 'a');
  2332. * // => true
  2333. *
  2334. * _.hasIn(object, 'a.b');
  2335. * // => true
  2336. *
  2337. * _.hasIn(object, ['a', 'b']);
  2338. * // => true
  2339. *
  2340. * _.hasIn(object, 'b');
  2341. * // => false
  2342. */
  2343. function hasIn(object, path) {
  2344. return object != null && hasPath(object, path, baseHasIn);
  2345. }
  2346. /**
  2347. * Creates an array of the own enumerable property names of `object`.
  2348. *
  2349. * **Note:** Non-object values are coerced to objects. See the
  2350. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  2351. * for more details.
  2352. *
  2353. * @static
  2354. * @since 0.1.0
  2355. * @memberOf _
  2356. * @category Object
  2357. * @param {Object} object The object to query.
  2358. * @returns {Array} Returns the array of property names.
  2359. * @example
  2360. *
  2361. * function Foo() {
  2362. * this.a = 1;
  2363. * this.b = 2;
  2364. * }
  2365. *
  2366. * Foo.prototype.c = 3;
  2367. *
  2368. * _.keys(new Foo);
  2369. * // => ['a', 'b'] (iteration order is not guaranteed)
  2370. *
  2371. * _.keys('hi');
  2372. * // => ['0', '1']
  2373. */
  2374. function keys(object) {
  2375. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  2376. }
  2377. /**
  2378. * This method returns the first argument it receives.
  2379. *
  2380. * @static
  2381. * @since 0.1.0
  2382. * @memberOf _
  2383. * @category Util
  2384. * @param {*} value Any value.
  2385. * @returns {*} Returns `value`.
  2386. * @example
  2387. *
  2388. * var object = { 'a': 1 };
  2389. *
  2390. * console.log(_.identity(object) === object);
  2391. * // => true
  2392. */
  2393. function identity(value) {
  2394. return value;
  2395. }
  2396. /**
  2397. * Creates a function that returns the value at `path` of a given object.
  2398. *
  2399. * @static
  2400. * @memberOf _
  2401. * @since 2.4.0
  2402. * @category Util
  2403. * @param {Array|string} path The path of the property to get.
  2404. * @returns {Function} Returns the new accessor function.
  2405. * @example
  2406. *
  2407. * var objects = [
  2408. * { 'a': { 'b': 2 } },
  2409. * { 'a': { 'b': 1 } }
  2410. * ];
  2411. *
  2412. * _.map(objects, _.property('a.b'));
  2413. * // => [2, 1]
  2414. *
  2415. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  2416. * // => [1, 2]
  2417. */
  2418. function property(path) {
  2419. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  2420. }
  2421. module.exports = sortBy;