index.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  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 `TypeError` message for "Functions" methods. */
  10. var FUNC_ERROR_TEXT = 'Expected a function';
  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 INFINITY = 1 / 0,
  15. MAX_SAFE_INTEGER = 9007199254740991;
  16. /** `Object#toString` result references. */
  17. var argsTag = '[object Arguments]',
  18. funcTag = '[object Function]',
  19. genTag = '[object GeneratorFunction]',
  20. symbolTag = '[object Symbol]';
  21. /** Used to match property names within property paths. */
  22. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  23. reIsPlainProp = /^\w*$/,
  24. reLeadingDot = /^\./,
  25. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  26. /**
  27. * Used to match `RegExp`
  28. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  29. */
  30. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  31. /** Used to match backslashes in property paths. */
  32. var reEscapeChar = /\\(\\)?/g;
  33. /** Used to detect host constructors (Safari). */
  34. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  35. /** Used to detect unsigned integer values. */
  36. var reIsUint = /^(?:0|[1-9]\d*)$/;
  37. /** Detect free variable `global` from Node.js. */
  38. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  39. /** Detect free variable `self`. */
  40. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  41. /** Used as a reference to the global object. */
  42. var root = freeGlobal || freeSelf || Function('return this')();
  43. /**
  44. * A faster alternative to `Function#apply`, this function invokes `func`
  45. * with the `this` binding of `thisArg` and the arguments of `args`.
  46. *
  47. * @private
  48. * @param {Function} func The function to invoke.
  49. * @param {*} thisArg The `this` binding of `func`.
  50. * @param {Array} args The arguments to invoke `func` with.
  51. * @returns {*} Returns the result of `func`.
  52. */
  53. function apply(func, thisArg, args) {
  54. switch (args.length) {
  55. case 0: return func.call(thisArg);
  56. case 1: return func.call(thisArg, args[0]);
  57. case 2: return func.call(thisArg, args[0], args[1]);
  58. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  59. }
  60. return func.apply(thisArg, args);
  61. }
  62. /**
  63. * The base implementation of `_.times` without support for iteratee shorthands
  64. * or max array length checks.
  65. *
  66. * @private
  67. * @param {number} n The number of times to invoke `iteratee`.
  68. * @param {Function} iteratee The function invoked per iteration.
  69. * @returns {Array} Returns the array of results.
  70. */
  71. function baseTimes(n, iteratee) {
  72. var index = -1,
  73. result = Array(n);
  74. while (++index < n) {
  75. result[index] = iteratee(index);
  76. }
  77. return result;
  78. }
  79. /**
  80. * Gets the value at `key` of `object`.
  81. *
  82. * @private
  83. * @param {Object} [object] The object to query.
  84. * @param {string} key The key of the property to get.
  85. * @returns {*} Returns the property value.
  86. */
  87. function getValue(object, key) {
  88. return object == null ? undefined : object[key];
  89. }
  90. /**
  91. * Checks if `value` is a host object in IE < 9.
  92. *
  93. * @private
  94. * @param {*} value The value to check.
  95. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  96. */
  97. function isHostObject(value) {
  98. // Many host objects are `Object` objects that can coerce to strings
  99. // despite having improperly defined `toString` methods.
  100. var result = false;
  101. if (value != null && typeof value.toString != 'function') {
  102. try {
  103. result = !!(value + '');
  104. } catch (e) {}
  105. }
  106. return result;
  107. }
  108. /**
  109. * Creates a unary function that invokes `func` with its argument transformed.
  110. *
  111. * @private
  112. * @param {Function} func The function to wrap.
  113. * @param {Function} transform The argument transform.
  114. * @returns {Function} Returns the new function.
  115. */
  116. function overArg(func, transform) {
  117. return function(arg) {
  118. return func(transform(arg));
  119. };
  120. }
  121. /** Used for built-in method references. */
  122. var arrayProto = Array.prototype,
  123. funcProto = Function.prototype,
  124. objectProto = Object.prototype;
  125. /** Used to detect overreaching core-js shims. */
  126. var coreJsData = root['__core-js_shared__'];
  127. /** Used to detect methods masquerading as native. */
  128. var maskSrcKey = (function() {
  129. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  130. return uid ? ('Symbol(src)_1.' + uid) : '';
  131. }());
  132. /** Used to resolve the decompiled source of functions. */
  133. var funcToString = funcProto.toString;
  134. /** Used to check objects for own properties. */
  135. var hasOwnProperty = objectProto.hasOwnProperty;
  136. /**
  137. * Used to resolve the
  138. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  139. * of values.
  140. */
  141. var objectToString = objectProto.toString;
  142. /** Used to detect if a method is native. */
  143. var reIsNative = RegExp('^' +
  144. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  145. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  146. );
  147. /** Built-in value references. */
  148. var Symbol = root.Symbol,
  149. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  150. splice = arrayProto.splice;
  151. /* Built-in method references for those with the same name as other `lodash` methods. */
  152. var nativeKeys = overArg(Object.keys, Object),
  153. nativeMax = Math.max;
  154. /* Built-in method references that are verified to be native. */
  155. var Map = getNative(root, 'Map'),
  156. nativeCreate = getNative(Object, 'create');
  157. /** Used to convert symbols to primitives and strings. */
  158. var symbolProto = Symbol ? Symbol.prototype : undefined,
  159. symbolToString = symbolProto ? symbolProto.toString : undefined;
  160. /**
  161. * Creates a hash object.
  162. *
  163. * @private
  164. * @constructor
  165. * @param {Array} [entries] The key-value pairs to cache.
  166. */
  167. function Hash(entries) {
  168. var index = -1,
  169. length = entries ? entries.length : 0;
  170. this.clear();
  171. while (++index < length) {
  172. var entry = entries[index];
  173. this.set(entry[0], entry[1]);
  174. }
  175. }
  176. /**
  177. * Removes all key-value entries from the hash.
  178. *
  179. * @private
  180. * @name clear
  181. * @memberOf Hash
  182. */
  183. function hashClear() {
  184. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  185. }
  186. /**
  187. * Removes `key` and its value from the hash.
  188. *
  189. * @private
  190. * @name delete
  191. * @memberOf Hash
  192. * @param {Object} hash The hash to modify.
  193. * @param {string} key The key of the value to remove.
  194. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  195. */
  196. function hashDelete(key) {
  197. return this.has(key) && delete this.__data__[key];
  198. }
  199. /**
  200. * Gets the hash value for `key`.
  201. *
  202. * @private
  203. * @name get
  204. * @memberOf Hash
  205. * @param {string} key The key of the value to get.
  206. * @returns {*} Returns the entry value.
  207. */
  208. function hashGet(key) {
  209. var data = this.__data__;
  210. if (nativeCreate) {
  211. var result = data[key];
  212. return result === HASH_UNDEFINED ? undefined : result;
  213. }
  214. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  215. }
  216. /**
  217. * Checks if a hash value for `key` exists.
  218. *
  219. * @private
  220. * @name has
  221. * @memberOf Hash
  222. * @param {string} key The key of the entry to check.
  223. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  224. */
  225. function hashHas(key) {
  226. var data = this.__data__;
  227. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  228. }
  229. /**
  230. * Sets the hash `key` to `value`.
  231. *
  232. * @private
  233. * @name set
  234. * @memberOf Hash
  235. * @param {string} key The key of the value to set.
  236. * @param {*} value The value to set.
  237. * @returns {Object} Returns the hash instance.
  238. */
  239. function hashSet(key, value) {
  240. var data = this.__data__;
  241. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  242. return this;
  243. }
  244. // Add methods to `Hash`.
  245. Hash.prototype.clear = hashClear;
  246. Hash.prototype['delete'] = hashDelete;
  247. Hash.prototype.get = hashGet;
  248. Hash.prototype.has = hashHas;
  249. Hash.prototype.set = hashSet;
  250. /**
  251. * Creates an list cache object.
  252. *
  253. * @private
  254. * @constructor
  255. * @param {Array} [entries] The key-value pairs to cache.
  256. */
  257. function ListCache(entries) {
  258. var index = -1,
  259. length = entries ? entries.length : 0;
  260. this.clear();
  261. while (++index < length) {
  262. var entry = entries[index];
  263. this.set(entry[0], entry[1]);
  264. }
  265. }
  266. /**
  267. * Removes all key-value entries from the list cache.
  268. *
  269. * @private
  270. * @name clear
  271. * @memberOf ListCache
  272. */
  273. function listCacheClear() {
  274. this.__data__ = [];
  275. }
  276. /**
  277. * Removes `key` and its value from the list cache.
  278. *
  279. * @private
  280. * @name delete
  281. * @memberOf ListCache
  282. * @param {string} key The key of the value to remove.
  283. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  284. */
  285. function listCacheDelete(key) {
  286. var data = this.__data__,
  287. index = assocIndexOf(data, key);
  288. if (index < 0) {
  289. return false;
  290. }
  291. var lastIndex = data.length - 1;
  292. if (index == lastIndex) {
  293. data.pop();
  294. } else {
  295. splice.call(data, index, 1);
  296. }
  297. return true;
  298. }
  299. /**
  300. * Gets the list cache value for `key`.
  301. *
  302. * @private
  303. * @name get
  304. * @memberOf ListCache
  305. * @param {string} key The key of the value to get.
  306. * @returns {*} Returns the entry value.
  307. */
  308. function listCacheGet(key) {
  309. var data = this.__data__,
  310. index = assocIndexOf(data, key);
  311. return index < 0 ? undefined : data[index][1];
  312. }
  313. /**
  314. * Checks if a list cache value for `key` exists.
  315. *
  316. * @private
  317. * @name has
  318. * @memberOf ListCache
  319. * @param {string} key The key of the entry to check.
  320. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  321. */
  322. function listCacheHas(key) {
  323. return assocIndexOf(this.__data__, key) > -1;
  324. }
  325. /**
  326. * Sets the list cache `key` to `value`.
  327. *
  328. * @private
  329. * @name set
  330. * @memberOf ListCache
  331. * @param {string} key The key of the value to set.
  332. * @param {*} value The value to set.
  333. * @returns {Object} Returns the list cache instance.
  334. */
  335. function listCacheSet(key, value) {
  336. var data = this.__data__,
  337. index = assocIndexOf(data, key);
  338. if (index < 0) {
  339. data.push([key, value]);
  340. } else {
  341. data[index][1] = value;
  342. }
  343. return this;
  344. }
  345. // Add methods to `ListCache`.
  346. ListCache.prototype.clear = listCacheClear;
  347. ListCache.prototype['delete'] = listCacheDelete;
  348. ListCache.prototype.get = listCacheGet;
  349. ListCache.prototype.has = listCacheHas;
  350. ListCache.prototype.set = listCacheSet;
  351. /**
  352. * Creates a map cache object to store key-value pairs.
  353. *
  354. * @private
  355. * @constructor
  356. * @param {Array} [entries] The key-value pairs to cache.
  357. */
  358. function MapCache(entries) {
  359. var index = -1,
  360. length = entries ? entries.length : 0;
  361. this.clear();
  362. while (++index < length) {
  363. var entry = entries[index];
  364. this.set(entry[0], entry[1]);
  365. }
  366. }
  367. /**
  368. * Removes all key-value entries from the map.
  369. *
  370. * @private
  371. * @name clear
  372. * @memberOf MapCache
  373. */
  374. function mapCacheClear() {
  375. this.__data__ = {
  376. 'hash': new Hash,
  377. 'map': new (Map || ListCache),
  378. 'string': new Hash
  379. };
  380. }
  381. /**
  382. * Removes `key` and its value from the map.
  383. *
  384. * @private
  385. * @name delete
  386. * @memberOf MapCache
  387. * @param {string} key The key of the value to remove.
  388. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  389. */
  390. function mapCacheDelete(key) {
  391. return getMapData(this, key)['delete'](key);
  392. }
  393. /**
  394. * Gets the map value for `key`.
  395. *
  396. * @private
  397. * @name get
  398. * @memberOf MapCache
  399. * @param {string} key The key of the value to get.
  400. * @returns {*} Returns the entry value.
  401. */
  402. function mapCacheGet(key) {
  403. return getMapData(this, key).get(key);
  404. }
  405. /**
  406. * Checks if a map value for `key` exists.
  407. *
  408. * @private
  409. * @name has
  410. * @memberOf MapCache
  411. * @param {string} key The key of the entry to check.
  412. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  413. */
  414. function mapCacheHas(key) {
  415. return getMapData(this, key).has(key);
  416. }
  417. /**
  418. * Sets the map `key` to `value`.
  419. *
  420. * @private
  421. * @name set
  422. * @memberOf MapCache
  423. * @param {string} key The key of the value to set.
  424. * @param {*} value The value to set.
  425. * @returns {Object} Returns the map cache instance.
  426. */
  427. function mapCacheSet(key, value) {
  428. getMapData(this, key).set(key, value);
  429. return this;
  430. }
  431. // Add methods to `MapCache`.
  432. MapCache.prototype.clear = mapCacheClear;
  433. MapCache.prototype['delete'] = mapCacheDelete;
  434. MapCache.prototype.get = mapCacheGet;
  435. MapCache.prototype.has = mapCacheHas;
  436. MapCache.prototype.set = mapCacheSet;
  437. /**
  438. * Creates an array of the enumerable property names of the array-like `value`.
  439. *
  440. * @private
  441. * @param {*} value The value to query.
  442. * @param {boolean} inherited Specify returning inherited property names.
  443. * @returns {Array} Returns the array of property names.
  444. */
  445. function arrayLikeKeys(value, inherited) {
  446. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  447. // Safari 9 makes `arguments.length` enumerable in strict mode.
  448. var result = (isArray(value) || isArguments(value))
  449. ? baseTimes(value.length, String)
  450. : [];
  451. var length = result.length,
  452. skipIndexes = !!length;
  453. for (var key in value) {
  454. if ((inherited || hasOwnProperty.call(value, key)) &&
  455. !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  456. result.push(key);
  457. }
  458. }
  459. return result;
  460. }
  461. /**
  462. * Gets the index at which the `key` is found in `array` of key-value pairs.
  463. *
  464. * @private
  465. * @param {Array} array The array to inspect.
  466. * @param {*} key The key to search for.
  467. * @returns {number} Returns the index of the matched value, else `-1`.
  468. */
  469. function assocIndexOf(array, key) {
  470. var length = array.length;
  471. while (length--) {
  472. if (eq(array[length][0], key)) {
  473. return length;
  474. }
  475. }
  476. return -1;
  477. }
  478. /**
  479. * The base implementation of `_.forEach` without support for iteratee shorthands.
  480. *
  481. * @private
  482. * @param {Array|Object} collection The collection to iterate over.
  483. * @param {Function} iteratee The function invoked per iteration.
  484. * @returns {Array|Object} Returns `collection`.
  485. */
  486. var baseEach = createBaseEach(baseForOwn);
  487. /**
  488. * The base implementation of `baseForOwn` which iterates over `object`
  489. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  490. * Iteratee functions may exit iteration early by explicitly returning `false`.
  491. *
  492. * @private
  493. * @param {Object} object The object to iterate over.
  494. * @param {Function} iteratee The function invoked per iteration.
  495. * @param {Function} keysFunc The function to get the keys of `object`.
  496. * @returns {Object} Returns `object`.
  497. */
  498. var baseFor = createBaseFor();
  499. /**
  500. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  501. *
  502. * @private
  503. * @param {Object} object The object to iterate over.
  504. * @param {Function} iteratee The function invoked per iteration.
  505. * @returns {Object} Returns `object`.
  506. */
  507. function baseForOwn(object, iteratee) {
  508. return object && baseFor(object, iteratee, keys);
  509. }
  510. /**
  511. * The base implementation of `_.get` without support for default values.
  512. *
  513. * @private
  514. * @param {Object} object The object to query.
  515. * @param {Array|string} path The path of the property to get.
  516. * @returns {*} Returns the resolved value.
  517. */
  518. function baseGet(object, path) {
  519. path = isKey(path, object) ? [path] : castPath(path);
  520. var index = 0,
  521. length = path.length;
  522. while (object != null && index < length) {
  523. object = object[toKey(path[index++])];
  524. }
  525. return (index && index == length) ? object : undefined;
  526. }
  527. /**
  528. * The base implementation of `_.invoke` without support for individual
  529. * method arguments.
  530. *
  531. * @private
  532. * @param {Object} object The object to query.
  533. * @param {Array|string} path The path of the method to invoke.
  534. * @param {Array} args The arguments to invoke the method with.
  535. * @returns {*} Returns the result of the invoked method.
  536. */
  537. function baseInvoke(object, path, args) {
  538. if (!isKey(path, object)) {
  539. path = castPath(path);
  540. object = parent(object, path);
  541. path = last(path);
  542. }
  543. var func = object == null ? object : object[toKey(path)];
  544. return func == null ? undefined : apply(func, object, args);
  545. }
  546. /**
  547. * The base implementation of `_.isNative` without bad shim checks.
  548. *
  549. * @private
  550. * @param {*} value The value to check.
  551. * @returns {boolean} Returns `true` if `value` is a native function,
  552. * else `false`.
  553. */
  554. function baseIsNative(value) {
  555. if (!isObject(value) || isMasked(value)) {
  556. return false;
  557. }
  558. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  559. return pattern.test(toSource(value));
  560. }
  561. /**
  562. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  563. *
  564. * @private
  565. * @param {Object} object The object to query.
  566. * @returns {Array} Returns the array of property names.
  567. */
  568. function baseKeys(object) {
  569. if (!isPrototype(object)) {
  570. return nativeKeys(object);
  571. }
  572. var result = [];
  573. for (var key in Object(object)) {
  574. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  575. result.push(key);
  576. }
  577. }
  578. return result;
  579. }
  580. /**
  581. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  582. *
  583. * @private
  584. * @param {Function} func The function to apply a rest parameter to.
  585. * @param {number} [start=func.length-1] The start position of the rest parameter.
  586. * @returns {Function} Returns the new function.
  587. */
  588. function baseRest(func, start) {
  589. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  590. return function() {
  591. var args = arguments,
  592. index = -1,
  593. length = nativeMax(args.length - start, 0),
  594. array = Array(length);
  595. while (++index < length) {
  596. array[index] = args[start + index];
  597. }
  598. index = -1;
  599. var otherArgs = Array(start + 1);
  600. while (++index < start) {
  601. otherArgs[index] = args[index];
  602. }
  603. otherArgs[start] = array;
  604. return apply(func, this, otherArgs);
  605. };
  606. }
  607. /**
  608. * The base implementation of `_.slice` without an iteratee call guard.
  609. *
  610. * @private
  611. * @param {Array} array The array to slice.
  612. * @param {number} [start=0] The start position.
  613. * @param {number} [end=array.length] The end position.
  614. * @returns {Array} Returns the slice of `array`.
  615. */
  616. function baseSlice(array, start, end) {
  617. var index = -1,
  618. length = array.length;
  619. if (start < 0) {
  620. start = -start > length ? 0 : (length + start);
  621. }
  622. end = end > length ? length : end;
  623. if (end < 0) {
  624. end += length;
  625. }
  626. length = start > end ? 0 : ((end - start) >>> 0);
  627. start >>>= 0;
  628. var result = Array(length);
  629. while (++index < length) {
  630. result[index] = array[index + start];
  631. }
  632. return result;
  633. }
  634. /**
  635. * The base implementation of `_.toString` which doesn't convert nullish
  636. * values to empty strings.
  637. *
  638. * @private
  639. * @param {*} value The value to process.
  640. * @returns {string} Returns the string.
  641. */
  642. function baseToString(value) {
  643. // Exit early for strings to avoid a performance hit in some environments.
  644. if (typeof value == 'string') {
  645. return value;
  646. }
  647. if (isSymbol(value)) {
  648. return symbolToString ? symbolToString.call(value) : '';
  649. }
  650. var result = (value + '');
  651. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  652. }
  653. /**
  654. * Casts `value` to a path array if it's not one.
  655. *
  656. * @private
  657. * @param {*} value The value to inspect.
  658. * @returns {Array} Returns the cast property path array.
  659. */
  660. function castPath(value) {
  661. return isArray(value) ? value : stringToPath(value);
  662. }
  663. /**
  664. * Creates a `baseEach` or `baseEachRight` function.
  665. *
  666. * @private
  667. * @param {Function} eachFunc The function to iterate over a collection.
  668. * @param {boolean} [fromRight] Specify iterating from right to left.
  669. * @returns {Function} Returns the new base function.
  670. */
  671. function createBaseEach(eachFunc, fromRight) {
  672. return function(collection, iteratee) {
  673. if (collection == null) {
  674. return collection;
  675. }
  676. if (!isArrayLike(collection)) {
  677. return eachFunc(collection, iteratee);
  678. }
  679. var length = collection.length,
  680. index = fromRight ? length : -1,
  681. iterable = Object(collection);
  682. while ((fromRight ? index-- : ++index < length)) {
  683. if (iteratee(iterable[index], index, iterable) === false) {
  684. break;
  685. }
  686. }
  687. return collection;
  688. };
  689. }
  690. /**
  691. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  692. *
  693. * @private
  694. * @param {boolean} [fromRight] Specify iterating from right to left.
  695. * @returns {Function} Returns the new base function.
  696. */
  697. function createBaseFor(fromRight) {
  698. return function(object, iteratee, keysFunc) {
  699. var index = -1,
  700. iterable = Object(object),
  701. props = keysFunc(object),
  702. length = props.length;
  703. while (length--) {
  704. var key = props[fromRight ? length : ++index];
  705. if (iteratee(iterable[key], key, iterable) === false) {
  706. break;
  707. }
  708. }
  709. return object;
  710. };
  711. }
  712. /**
  713. * Gets the data for `map`.
  714. *
  715. * @private
  716. * @param {Object} map The map to query.
  717. * @param {string} key The reference key.
  718. * @returns {*} Returns the map data.
  719. */
  720. function getMapData(map, key) {
  721. var data = map.__data__;
  722. return isKeyable(key)
  723. ? data[typeof key == 'string' ? 'string' : 'hash']
  724. : data.map;
  725. }
  726. /**
  727. * Gets the native function at `key` of `object`.
  728. *
  729. * @private
  730. * @param {Object} object The object to query.
  731. * @param {string} key The key of the method to get.
  732. * @returns {*} Returns the function if it's native, else `undefined`.
  733. */
  734. function getNative(object, key) {
  735. var value = getValue(object, key);
  736. return baseIsNative(value) ? value : undefined;
  737. }
  738. /**
  739. * Checks if `value` is a valid array-like index.
  740. *
  741. * @private
  742. * @param {*} value The value to check.
  743. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  744. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  745. */
  746. function isIndex(value, length) {
  747. length = length == null ? MAX_SAFE_INTEGER : length;
  748. return !!length &&
  749. (typeof value == 'number' || reIsUint.test(value)) &&
  750. (value > -1 && value % 1 == 0 && value < length);
  751. }
  752. /**
  753. * Checks if `value` is a property name and not a property path.
  754. *
  755. * @private
  756. * @param {*} value The value to check.
  757. * @param {Object} [object] The object to query keys on.
  758. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  759. */
  760. function isKey(value, object) {
  761. if (isArray(value)) {
  762. return false;
  763. }
  764. var type = typeof value;
  765. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  766. value == null || isSymbol(value)) {
  767. return true;
  768. }
  769. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  770. (object != null && value in Object(object));
  771. }
  772. /**
  773. * Checks if `value` is suitable for use as unique object key.
  774. *
  775. * @private
  776. * @param {*} value The value to check.
  777. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  778. */
  779. function isKeyable(value) {
  780. var type = typeof value;
  781. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  782. ? (value !== '__proto__')
  783. : (value === null);
  784. }
  785. /**
  786. * Checks if `func` has its source masked.
  787. *
  788. * @private
  789. * @param {Function} func The function to check.
  790. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  791. */
  792. function isMasked(func) {
  793. return !!maskSrcKey && (maskSrcKey in func);
  794. }
  795. /**
  796. * Checks if `value` is likely a prototype object.
  797. *
  798. * @private
  799. * @param {*} value The value to check.
  800. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  801. */
  802. function isPrototype(value) {
  803. var Ctor = value && value.constructor,
  804. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  805. return value === proto;
  806. }
  807. /**
  808. * Gets the parent value at `path` of `object`.
  809. *
  810. * @private
  811. * @param {Object} object The object to query.
  812. * @param {Array} path The path to get the parent value of.
  813. * @returns {*} Returns the parent value.
  814. */
  815. function parent(object, path) {
  816. return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  817. }
  818. /**
  819. * Converts `string` to a property path array.
  820. *
  821. * @private
  822. * @param {string} string The string to convert.
  823. * @returns {Array} Returns the property path array.
  824. */
  825. var stringToPath = memoize(function(string) {
  826. string = toString(string);
  827. var result = [];
  828. if (reLeadingDot.test(string)) {
  829. result.push('');
  830. }
  831. string.replace(rePropName, function(match, number, quote, string) {
  832. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  833. });
  834. return result;
  835. });
  836. /**
  837. * Converts `value` to a string key if it's not a string or symbol.
  838. *
  839. * @private
  840. * @param {*} value The value to inspect.
  841. * @returns {string|symbol} Returns the key.
  842. */
  843. function toKey(value) {
  844. if (typeof value == 'string' || isSymbol(value)) {
  845. return value;
  846. }
  847. var result = (value + '');
  848. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  849. }
  850. /**
  851. * Converts `func` to its source code.
  852. *
  853. * @private
  854. * @param {Function} func The function to process.
  855. * @returns {string} Returns the source code.
  856. */
  857. function toSource(func) {
  858. if (func != null) {
  859. try {
  860. return funcToString.call(func);
  861. } catch (e) {}
  862. try {
  863. return (func + '');
  864. } catch (e) {}
  865. }
  866. return '';
  867. }
  868. /**
  869. * Gets the last element of `array`.
  870. *
  871. * @static
  872. * @memberOf _
  873. * @since 0.1.0
  874. * @category Array
  875. * @param {Array} array The array to query.
  876. * @returns {*} Returns the last element of `array`.
  877. * @example
  878. *
  879. * _.last([1, 2, 3]);
  880. * // => 3
  881. */
  882. function last(array) {
  883. var length = array ? array.length : 0;
  884. return length ? array[length - 1] : undefined;
  885. }
  886. /**
  887. * Invokes the method at `path` of each element in `collection`, returning
  888. * an array of the results of each invoked method. Any additional arguments
  889. * are provided to each invoked method. If `path` is a function, it's invoked
  890. * for, and `this` bound to, each element in `collection`.
  891. *
  892. * @static
  893. * @memberOf _
  894. * @since 4.0.0
  895. * @category Collection
  896. * @param {Array|Object} collection The collection to iterate over.
  897. * @param {Array|Function|string} path The path of the method to invoke or
  898. * the function invoked per iteration.
  899. * @param {...*} [args] The arguments to invoke each method with.
  900. * @returns {Array} Returns the array of results.
  901. * @example
  902. *
  903. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  904. * // => [[1, 5, 7], [1, 2, 3]]
  905. *
  906. * _.invokeMap([123, 456], String.prototype.split, '');
  907. * // => [['1', '2', '3'], ['4', '5', '6']]
  908. */
  909. var invokeMap = baseRest(function(collection, path, args) {
  910. var index = -1,
  911. isFunc = typeof path == 'function',
  912. isProp = isKey(path),
  913. result = isArrayLike(collection) ? Array(collection.length) : [];
  914. baseEach(collection, function(value) {
  915. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  916. result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
  917. });
  918. return result;
  919. });
  920. /**
  921. * Creates a function that memoizes the result of `func`. If `resolver` is
  922. * provided, it determines the cache key for storing the result based on the
  923. * arguments provided to the memoized function. By default, the first argument
  924. * provided to the memoized function is used as the map cache key. The `func`
  925. * is invoked with the `this` binding of the memoized function.
  926. *
  927. * **Note:** The cache is exposed as the `cache` property on the memoized
  928. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  929. * constructor with one whose instances implement the
  930. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  931. * method interface of `delete`, `get`, `has`, and `set`.
  932. *
  933. * @static
  934. * @memberOf _
  935. * @since 0.1.0
  936. * @category Function
  937. * @param {Function} func The function to have its output memoized.
  938. * @param {Function} [resolver] The function to resolve the cache key.
  939. * @returns {Function} Returns the new memoized function.
  940. * @example
  941. *
  942. * var object = { 'a': 1, 'b': 2 };
  943. * var other = { 'c': 3, 'd': 4 };
  944. *
  945. * var values = _.memoize(_.values);
  946. * values(object);
  947. * // => [1, 2]
  948. *
  949. * values(other);
  950. * // => [3, 4]
  951. *
  952. * object.a = 2;
  953. * values(object);
  954. * // => [1, 2]
  955. *
  956. * // Modify the result cache.
  957. * values.cache.set(object, ['a', 'b']);
  958. * values(object);
  959. * // => ['a', 'b']
  960. *
  961. * // Replace `_.memoize.Cache`.
  962. * _.memoize.Cache = WeakMap;
  963. */
  964. function memoize(func, resolver) {
  965. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  966. throw new TypeError(FUNC_ERROR_TEXT);
  967. }
  968. var memoized = function() {
  969. var args = arguments,
  970. key = resolver ? resolver.apply(this, args) : args[0],
  971. cache = memoized.cache;
  972. if (cache.has(key)) {
  973. return cache.get(key);
  974. }
  975. var result = func.apply(this, args);
  976. memoized.cache = cache.set(key, result);
  977. return result;
  978. };
  979. memoized.cache = new (memoize.Cache || MapCache);
  980. return memoized;
  981. }
  982. // Assign cache to `_.memoize`.
  983. memoize.Cache = MapCache;
  984. /**
  985. * Performs a
  986. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  987. * comparison between two values to determine if they are equivalent.
  988. *
  989. * @static
  990. * @memberOf _
  991. * @since 4.0.0
  992. * @category Lang
  993. * @param {*} value The value to compare.
  994. * @param {*} other The other value to compare.
  995. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  996. * @example
  997. *
  998. * var object = { 'a': 1 };
  999. * var other = { 'a': 1 };
  1000. *
  1001. * _.eq(object, object);
  1002. * // => true
  1003. *
  1004. * _.eq(object, other);
  1005. * // => false
  1006. *
  1007. * _.eq('a', 'a');
  1008. * // => true
  1009. *
  1010. * _.eq('a', Object('a'));
  1011. * // => false
  1012. *
  1013. * _.eq(NaN, NaN);
  1014. * // => true
  1015. */
  1016. function eq(value, other) {
  1017. return value === other || (value !== value && other !== other);
  1018. }
  1019. /**
  1020. * Checks if `value` is likely an `arguments` object.
  1021. *
  1022. * @static
  1023. * @memberOf _
  1024. * @since 0.1.0
  1025. * @category Lang
  1026. * @param {*} value The value to check.
  1027. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  1028. * else `false`.
  1029. * @example
  1030. *
  1031. * _.isArguments(function() { return arguments; }());
  1032. * // => true
  1033. *
  1034. * _.isArguments([1, 2, 3]);
  1035. * // => false
  1036. */
  1037. function isArguments(value) {
  1038. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  1039. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  1040. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  1041. }
  1042. /**
  1043. * Checks if `value` is classified as an `Array` object.
  1044. *
  1045. * @static
  1046. * @memberOf _
  1047. * @since 0.1.0
  1048. * @category Lang
  1049. * @param {*} value The value to check.
  1050. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  1051. * @example
  1052. *
  1053. * _.isArray([1, 2, 3]);
  1054. * // => true
  1055. *
  1056. * _.isArray(document.body.children);
  1057. * // => false
  1058. *
  1059. * _.isArray('abc');
  1060. * // => false
  1061. *
  1062. * _.isArray(_.noop);
  1063. * // => false
  1064. */
  1065. var isArray = Array.isArray;
  1066. /**
  1067. * Checks if `value` is array-like. A value is considered array-like if it's
  1068. * not a function and has a `value.length` that's an integer greater than or
  1069. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  1070. *
  1071. * @static
  1072. * @memberOf _
  1073. * @since 4.0.0
  1074. * @category Lang
  1075. * @param {*} value The value to check.
  1076. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  1077. * @example
  1078. *
  1079. * _.isArrayLike([1, 2, 3]);
  1080. * // => true
  1081. *
  1082. * _.isArrayLike(document.body.children);
  1083. * // => true
  1084. *
  1085. * _.isArrayLike('abc');
  1086. * // => true
  1087. *
  1088. * _.isArrayLike(_.noop);
  1089. * // => false
  1090. */
  1091. function isArrayLike(value) {
  1092. return value != null && isLength(value.length) && !isFunction(value);
  1093. }
  1094. /**
  1095. * This method is like `_.isArrayLike` except that it also checks if `value`
  1096. * is an object.
  1097. *
  1098. * @static
  1099. * @memberOf _
  1100. * @since 4.0.0
  1101. * @category Lang
  1102. * @param {*} value The value to check.
  1103. * @returns {boolean} Returns `true` if `value` is an array-like object,
  1104. * else `false`.
  1105. * @example
  1106. *
  1107. * _.isArrayLikeObject([1, 2, 3]);
  1108. * // => true
  1109. *
  1110. * _.isArrayLikeObject(document.body.children);
  1111. * // => true
  1112. *
  1113. * _.isArrayLikeObject('abc');
  1114. * // => false
  1115. *
  1116. * _.isArrayLikeObject(_.noop);
  1117. * // => false
  1118. */
  1119. function isArrayLikeObject(value) {
  1120. return isObjectLike(value) && isArrayLike(value);
  1121. }
  1122. /**
  1123. * Checks if `value` is classified as a `Function` object.
  1124. *
  1125. * @static
  1126. * @memberOf _
  1127. * @since 0.1.0
  1128. * @category Lang
  1129. * @param {*} value The value to check.
  1130. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  1131. * @example
  1132. *
  1133. * _.isFunction(_);
  1134. * // => true
  1135. *
  1136. * _.isFunction(/abc/);
  1137. * // => false
  1138. */
  1139. function isFunction(value) {
  1140. // The use of `Object#toString` avoids issues with the `typeof` operator
  1141. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  1142. var tag = isObject(value) ? objectToString.call(value) : '';
  1143. return tag == funcTag || tag == genTag;
  1144. }
  1145. /**
  1146. * Checks if `value` is a valid array-like length.
  1147. *
  1148. * **Note:** This method is loosely based on
  1149. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  1150. *
  1151. * @static
  1152. * @memberOf _
  1153. * @since 4.0.0
  1154. * @category Lang
  1155. * @param {*} value The value to check.
  1156. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  1157. * @example
  1158. *
  1159. * _.isLength(3);
  1160. * // => true
  1161. *
  1162. * _.isLength(Number.MIN_VALUE);
  1163. * // => false
  1164. *
  1165. * _.isLength(Infinity);
  1166. * // => false
  1167. *
  1168. * _.isLength('3');
  1169. * // => false
  1170. */
  1171. function isLength(value) {
  1172. return typeof value == 'number' &&
  1173. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  1174. }
  1175. /**
  1176. * Checks if `value` is the
  1177. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1178. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1179. *
  1180. * @static
  1181. * @memberOf _
  1182. * @since 0.1.0
  1183. * @category Lang
  1184. * @param {*} value The value to check.
  1185. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1186. * @example
  1187. *
  1188. * _.isObject({});
  1189. * // => true
  1190. *
  1191. * _.isObject([1, 2, 3]);
  1192. * // => true
  1193. *
  1194. * _.isObject(_.noop);
  1195. * // => true
  1196. *
  1197. * _.isObject(null);
  1198. * // => false
  1199. */
  1200. function isObject(value) {
  1201. var type = typeof value;
  1202. return !!value && (type == 'object' || type == 'function');
  1203. }
  1204. /**
  1205. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1206. * and has a `typeof` result of "object".
  1207. *
  1208. * @static
  1209. * @memberOf _
  1210. * @since 4.0.0
  1211. * @category Lang
  1212. * @param {*} value The value to check.
  1213. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1214. * @example
  1215. *
  1216. * _.isObjectLike({});
  1217. * // => true
  1218. *
  1219. * _.isObjectLike([1, 2, 3]);
  1220. * // => true
  1221. *
  1222. * _.isObjectLike(_.noop);
  1223. * // => false
  1224. *
  1225. * _.isObjectLike(null);
  1226. * // => false
  1227. */
  1228. function isObjectLike(value) {
  1229. return !!value && typeof value == 'object';
  1230. }
  1231. /**
  1232. * Checks if `value` is classified as a `Symbol` primitive or object.
  1233. *
  1234. * @static
  1235. * @memberOf _
  1236. * @since 4.0.0
  1237. * @category Lang
  1238. * @param {*} value The value to check.
  1239. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  1240. * @example
  1241. *
  1242. * _.isSymbol(Symbol.iterator);
  1243. * // => true
  1244. *
  1245. * _.isSymbol('abc');
  1246. * // => false
  1247. */
  1248. function isSymbol(value) {
  1249. return typeof value == 'symbol' ||
  1250. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  1251. }
  1252. /**
  1253. * Converts `value` to a string. An empty string is returned for `null`
  1254. * and `undefined` values. The sign of `-0` is preserved.
  1255. *
  1256. * @static
  1257. * @memberOf _
  1258. * @since 4.0.0
  1259. * @category Lang
  1260. * @param {*} value The value to process.
  1261. * @returns {string} Returns the string.
  1262. * @example
  1263. *
  1264. * _.toString(null);
  1265. * // => ''
  1266. *
  1267. * _.toString(-0);
  1268. * // => '-0'
  1269. *
  1270. * _.toString([1, 2, 3]);
  1271. * // => '1,2,3'
  1272. */
  1273. function toString(value) {
  1274. return value == null ? '' : baseToString(value);
  1275. }
  1276. /**
  1277. * Creates an array of the own enumerable property names of `object`.
  1278. *
  1279. * **Note:** Non-object values are coerced to objects. See the
  1280. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1281. * for more details.
  1282. *
  1283. * @static
  1284. * @since 0.1.0
  1285. * @memberOf _
  1286. * @category Object
  1287. * @param {Object} object The object to query.
  1288. * @returns {Array} Returns the array of property names.
  1289. * @example
  1290. *
  1291. * function Foo() {
  1292. * this.a = 1;
  1293. * this.b = 2;
  1294. * }
  1295. *
  1296. * Foo.prototype.c = 3;
  1297. *
  1298. * _.keys(new Foo);
  1299. * // => ['a', 'b'] (iteration order is not guaranteed)
  1300. *
  1301. * _.keys('hi');
  1302. * // => ['0', '1']
  1303. */
  1304. function keys(object) {
  1305. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  1306. }
  1307. module.exports = invokeMap;