index.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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. /** `Object#toString` result references. */
  16. var funcTag = '[object Function]',
  17. genTag = '[object GeneratorFunction]',
  18. symbolTag = '[object Symbol]';
  19. /** Used to match property names within property paths. */
  20. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  21. reIsPlainProp = /^\w*$/,
  22. reLeadingDot = /^\./,
  23. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  24. /**
  25. * Used to match `RegExp`
  26. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  27. */
  28. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  29. /** Used to match backslashes in property paths. */
  30. var reEscapeChar = /\\(\\)?/g;
  31. /** Used to detect host constructors (Safari). */
  32. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  33. /** Detect free variable `global` from Node.js. */
  34. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  35. /** Detect free variable `self`. */
  36. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  37. /** Used as a reference to the global object. */
  38. var root = freeGlobal || freeSelf || Function('return this')();
  39. /**
  40. * Gets the value at `key` of `object`.
  41. *
  42. * @private
  43. * @param {Object} [object] The object to query.
  44. * @param {string} key The key of the property to get.
  45. * @returns {*} Returns the property value.
  46. */
  47. function getValue(object, key) {
  48. return object == null ? undefined : object[key];
  49. }
  50. /**
  51. * Checks if `value` is a host object in IE < 9.
  52. *
  53. * @private
  54. * @param {*} value The value to check.
  55. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  56. */
  57. function isHostObject(value) {
  58. // Many host objects are `Object` objects that can coerce to strings
  59. // despite having improperly defined `toString` methods.
  60. var result = false;
  61. if (value != null && typeof value.toString != 'function') {
  62. try {
  63. result = !!(value + '');
  64. } catch (e) {}
  65. }
  66. return result;
  67. }
  68. /** Used for built-in method references. */
  69. var arrayProto = Array.prototype,
  70. funcProto = Function.prototype,
  71. objectProto = Object.prototype;
  72. /** Used to detect overreaching core-js shims. */
  73. var coreJsData = root['__core-js_shared__'];
  74. /** Used to detect methods masquerading as native. */
  75. var maskSrcKey = (function() {
  76. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  77. return uid ? ('Symbol(src)_1.' + uid) : '';
  78. }());
  79. /** Used to resolve the decompiled source of functions. */
  80. var funcToString = funcProto.toString;
  81. /** Used to check objects for own properties. */
  82. var hasOwnProperty = objectProto.hasOwnProperty;
  83. /**
  84. * Used to resolve the
  85. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  86. * of values.
  87. */
  88. var objectToString = objectProto.toString;
  89. /** Used to detect if a method is native. */
  90. var reIsNative = RegExp('^' +
  91. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  92. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  93. );
  94. /** Built-in value references. */
  95. var Symbol = root.Symbol,
  96. splice = arrayProto.splice;
  97. /* Built-in method references that are verified to be native. */
  98. var Map = getNative(root, 'Map'),
  99. nativeCreate = getNative(Object, 'create');
  100. /** Used to convert symbols to primitives and strings. */
  101. var symbolProto = Symbol ? Symbol.prototype : undefined,
  102. symbolToString = symbolProto ? symbolProto.toString : undefined;
  103. /**
  104. * Creates a hash object.
  105. *
  106. * @private
  107. * @constructor
  108. * @param {Array} [entries] The key-value pairs to cache.
  109. */
  110. function Hash(entries) {
  111. var index = -1,
  112. length = entries ? entries.length : 0;
  113. this.clear();
  114. while (++index < length) {
  115. var entry = entries[index];
  116. this.set(entry[0], entry[1]);
  117. }
  118. }
  119. /**
  120. * Removes all key-value entries from the hash.
  121. *
  122. * @private
  123. * @name clear
  124. * @memberOf Hash
  125. */
  126. function hashClear() {
  127. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  128. }
  129. /**
  130. * Removes `key` and its value from the hash.
  131. *
  132. * @private
  133. * @name delete
  134. * @memberOf Hash
  135. * @param {Object} hash The hash to modify.
  136. * @param {string} key The key of the value to remove.
  137. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  138. */
  139. function hashDelete(key) {
  140. return this.has(key) && delete this.__data__[key];
  141. }
  142. /**
  143. * Gets the hash value for `key`.
  144. *
  145. * @private
  146. * @name get
  147. * @memberOf Hash
  148. * @param {string} key The key of the value to get.
  149. * @returns {*} Returns the entry value.
  150. */
  151. function hashGet(key) {
  152. var data = this.__data__;
  153. if (nativeCreate) {
  154. var result = data[key];
  155. return result === HASH_UNDEFINED ? undefined : result;
  156. }
  157. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  158. }
  159. /**
  160. * Checks if a hash value for `key` exists.
  161. *
  162. * @private
  163. * @name has
  164. * @memberOf Hash
  165. * @param {string} key The key of the entry to check.
  166. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  167. */
  168. function hashHas(key) {
  169. var data = this.__data__;
  170. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  171. }
  172. /**
  173. * Sets the hash `key` to `value`.
  174. *
  175. * @private
  176. * @name set
  177. * @memberOf Hash
  178. * @param {string} key The key of the value to set.
  179. * @param {*} value The value to set.
  180. * @returns {Object} Returns the hash instance.
  181. */
  182. function hashSet(key, value) {
  183. var data = this.__data__;
  184. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  185. return this;
  186. }
  187. // Add methods to `Hash`.
  188. Hash.prototype.clear = hashClear;
  189. Hash.prototype['delete'] = hashDelete;
  190. Hash.prototype.get = hashGet;
  191. Hash.prototype.has = hashHas;
  192. Hash.prototype.set = hashSet;
  193. /**
  194. * Creates an list cache object.
  195. *
  196. * @private
  197. * @constructor
  198. * @param {Array} [entries] The key-value pairs to cache.
  199. */
  200. function ListCache(entries) {
  201. var index = -1,
  202. length = entries ? entries.length : 0;
  203. this.clear();
  204. while (++index < length) {
  205. var entry = entries[index];
  206. this.set(entry[0], entry[1]);
  207. }
  208. }
  209. /**
  210. * Removes all key-value entries from the list cache.
  211. *
  212. * @private
  213. * @name clear
  214. * @memberOf ListCache
  215. */
  216. function listCacheClear() {
  217. this.__data__ = [];
  218. }
  219. /**
  220. * Removes `key` and its value from the list cache.
  221. *
  222. * @private
  223. * @name delete
  224. * @memberOf ListCache
  225. * @param {string} key The key of the value to remove.
  226. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  227. */
  228. function listCacheDelete(key) {
  229. var data = this.__data__,
  230. index = assocIndexOf(data, key);
  231. if (index < 0) {
  232. return false;
  233. }
  234. var lastIndex = data.length - 1;
  235. if (index == lastIndex) {
  236. data.pop();
  237. } else {
  238. splice.call(data, index, 1);
  239. }
  240. return true;
  241. }
  242. /**
  243. * Gets the list cache value for `key`.
  244. *
  245. * @private
  246. * @name get
  247. * @memberOf ListCache
  248. * @param {string} key The key of the value to get.
  249. * @returns {*} Returns the entry value.
  250. */
  251. function listCacheGet(key) {
  252. var data = this.__data__,
  253. index = assocIndexOf(data, key);
  254. return index < 0 ? undefined : data[index][1];
  255. }
  256. /**
  257. * Checks if a list cache value for `key` exists.
  258. *
  259. * @private
  260. * @name has
  261. * @memberOf ListCache
  262. * @param {string} key The key of the entry to check.
  263. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  264. */
  265. function listCacheHas(key) {
  266. return assocIndexOf(this.__data__, key) > -1;
  267. }
  268. /**
  269. * Sets the list cache `key` to `value`.
  270. *
  271. * @private
  272. * @name set
  273. * @memberOf ListCache
  274. * @param {string} key The key of the value to set.
  275. * @param {*} value The value to set.
  276. * @returns {Object} Returns the list cache instance.
  277. */
  278. function listCacheSet(key, value) {
  279. var data = this.__data__,
  280. index = assocIndexOf(data, key);
  281. if (index < 0) {
  282. data.push([key, value]);
  283. } else {
  284. data[index][1] = value;
  285. }
  286. return this;
  287. }
  288. // Add methods to `ListCache`.
  289. ListCache.prototype.clear = listCacheClear;
  290. ListCache.prototype['delete'] = listCacheDelete;
  291. ListCache.prototype.get = listCacheGet;
  292. ListCache.prototype.has = listCacheHas;
  293. ListCache.prototype.set = listCacheSet;
  294. /**
  295. * Creates a map cache object to store key-value pairs.
  296. *
  297. * @private
  298. * @constructor
  299. * @param {Array} [entries] The key-value pairs to cache.
  300. */
  301. function MapCache(entries) {
  302. var index = -1,
  303. length = entries ? entries.length : 0;
  304. this.clear();
  305. while (++index < length) {
  306. var entry = entries[index];
  307. this.set(entry[0], entry[1]);
  308. }
  309. }
  310. /**
  311. * Removes all key-value entries from the map.
  312. *
  313. * @private
  314. * @name clear
  315. * @memberOf MapCache
  316. */
  317. function mapCacheClear() {
  318. this.__data__ = {
  319. 'hash': new Hash,
  320. 'map': new (Map || ListCache),
  321. 'string': new Hash
  322. };
  323. }
  324. /**
  325. * Removes `key` and its value from the map.
  326. *
  327. * @private
  328. * @name delete
  329. * @memberOf MapCache
  330. * @param {string} key The key of the value to remove.
  331. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  332. */
  333. function mapCacheDelete(key) {
  334. return getMapData(this, key)['delete'](key);
  335. }
  336. /**
  337. * Gets the map value for `key`.
  338. *
  339. * @private
  340. * @name get
  341. * @memberOf MapCache
  342. * @param {string} key The key of the value to get.
  343. * @returns {*} Returns the entry value.
  344. */
  345. function mapCacheGet(key) {
  346. return getMapData(this, key).get(key);
  347. }
  348. /**
  349. * Checks if a map value for `key` exists.
  350. *
  351. * @private
  352. * @name has
  353. * @memberOf MapCache
  354. * @param {string} key The key of the entry to check.
  355. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  356. */
  357. function mapCacheHas(key) {
  358. return getMapData(this, key).has(key);
  359. }
  360. /**
  361. * Sets the map `key` to `value`.
  362. *
  363. * @private
  364. * @name set
  365. * @memberOf MapCache
  366. * @param {string} key The key of the value to set.
  367. * @param {*} value The value to set.
  368. * @returns {Object} Returns the map cache instance.
  369. */
  370. function mapCacheSet(key, value) {
  371. getMapData(this, key).set(key, value);
  372. return this;
  373. }
  374. // Add methods to `MapCache`.
  375. MapCache.prototype.clear = mapCacheClear;
  376. MapCache.prototype['delete'] = mapCacheDelete;
  377. MapCache.prototype.get = mapCacheGet;
  378. MapCache.prototype.has = mapCacheHas;
  379. MapCache.prototype.set = mapCacheSet;
  380. /**
  381. * Gets the index at which the `key` is found in `array` of key-value pairs.
  382. *
  383. * @private
  384. * @param {Array} array The array to inspect.
  385. * @param {*} key The key to search for.
  386. * @returns {number} Returns the index of the matched value, else `-1`.
  387. */
  388. function assocIndexOf(array, key) {
  389. var length = array.length;
  390. while (length--) {
  391. if (eq(array[length][0], key)) {
  392. return length;
  393. }
  394. }
  395. return -1;
  396. }
  397. /**
  398. * The base implementation of `_.get` without support for default values.
  399. *
  400. * @private
  401. * @param {Object} object The object to query.
  402. * @param {Array|string} path The path of the property to get.
  403. * @returns {*} Returns the resolved value.
  404. */
  405. function baseGet(object, path) {
  406. path = isKey(path, object) ? [path] : castPath(path);
  407. var index = 0,
  408. length = path.length;
  409. while (object != null && index < length) {
  410. object = object[toKey(path[index++])];
  411. }
  412. return (index && index == length) ? object : undefined;
  413. }
  414. /**
  415. * The base implementation of `_.isNative` without bad shim checks.
  416. *
  417. * @private
  418. * @param {*} value The value to check.
  419. * @returns {boolean} Returns `true` if `value` is a native function,
  420. * else `false`.
  421. */
  422. function baseIsNative(value) {
  423. if (!isObject(value) || isMasked(value)) {
  424. return false;
  425. }
  426. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  427. return pattern.test(toSource(value));
  428. }
  429. /**
  430. * The base implementation of `_.toString` which doesn't convert nullish
  431. * values to empty strings.
  432. *
  433. * @private
  434. * @param {*} value The value to process.
  435. * @returns {string} Returns the string.
  436. */
  437. function baseToString(value) {
  438. // Exit early for strings to avoid a performance hit in some environments.
  439. if (typeof value == 'string') {
  440. return value;
  441. }
  442. if (isSymbol(value)) {
  443. return symbolToString ? symbolToString.call(value) : '';
  444. }
  445. var result = (value + '');
  446. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  447. }
  448. /**
  449. * Casts `value` to a path array if it's not one.
  450. *
  451. * @private
  452. * @param {*} value The value to inspect.
  453. * @returns {Array} Returns the cast property path array.
  454. */
  455. function castPath(value) {
  456. return isArray(value) ? value : stringToPath(value);
  457. }
  458. /**
  459. * Gets the data for `map`.
  460. *
  461. * @private
  462. * @param {Object} map The map to query.
  463. * @param {string} key The reference key.
  464. * @returns {*} Returns the map data.
  465. */
  466. function getMapData(map, key) {
  467. var data = map.__data__;
  468. return isKeyable(key)
  469. ? data[typeof key == 'string' ? 'string' : 'hash']
  470. : data.map;
  471. }
  472. /**
  473. * Gets the native function at `key` of `object`.
  474. *
  475. * @private
  476. * @param {Object} object The object to query.
  477. * @param {string} key The key of the method to get.
  478. * @returns {*} Returns the function if it's native, else `undefined`.
  479. */
  480. function getNative(object, key) {
  481. var value = getValue(object, key);
  482. return baseIsNative(value) ? value : undefined;
  483. }
  484. /**
  485. * Checks if `value` is a property name and not a property path.
  486. *
  487. * @private
  488. * @param {*} value The value to check.
  489. * @param {Object} [object] The object to query keys on.
  490. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  491. */
  492. function isKey(value, object) {
  493. if (isArray(value)) {
  494. return false;
  495. }
  496. var type = typeof value;
  497. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  498. value == null || isSymbol(value)) {
  499. return true;
  500. }
  501. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  502. (object != null && value in Object(object));
  503. }
  504. /**
  505. * Checks if `value` is suitable for use as unique object key.
  506. *
  507. * @private
  508. * @param {*} value The value to check.
  509. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  510. */
  511. function isKeyable(value) {
  512. var type = typeof value;
  513. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  514. ? (value !== '__proto__')
  515. : (value === null);
  516. }
  517. /**
  518. * Checks if `func` has its source masked.
  519. *
  520. * @private
  521. * @param {Function} func The function to check.
  522. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  523. */
  524. function isMasked(func) {
  525. return !!maskSrcKey && (maskSrcKey in func);
  526. }
  527. /**
  528. * Converts `string` to a property path array.
  529. *
  530. * @private
  531. * @param {string} string The string to convert.
  532. * @returns {Array} Returns the property path array.
  533. */
  534. var stringToPath = memoize(function(string) {
  535. string = toString(string);
  536. var result = [];
  537. if (reLeadingDot.test(string)) {
  538. result.push('');
  539. }
  540. string.replace(rePropName, function(match, number, quote, string) {
  541. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  542. });
  543. return result;
  544. });
  545. /**
  546. * Converts `value` to a string key if it's not a string or symbol.
  547. *
  548. * @private
  549. * @param {*} value The value to inspect.
  550. * @returns {string|symbol} Returns the key.
  551. */
  552. function toKey(value) {
  553. if (typeof value == 'string' || isSymbol(value)) {
  554. return value;
  555. }
  556. var result = (value + '');
  557. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  558. }
  559. /**
  560. * Converts `func` to its source code.
  561. *
  562. * @private
  563. * @param {Function} func The function to process.
  564. * @returns {string} Returns the source code.
  565. */
  566. function toSource(func) {
  567. if (func != null) {
  568. try {
  569. return funcToString.call(func);
  570. } catch (e) {}
  571. try {
  572. return (func + '');
  573. } catch (e) {}
  574. }
  575. return '';
  576. }
  577. /**
  578. * Creates a function that memoizes the result of `func`. If `resolver` is
  579. * provided, it determines the cache key for storing the result based on the
  580. * arguments provided to the memoized function. By default, the first argument
  581. * provided to the memoized function is used as the map cache key. The `func`
  582. * is invoked with the `this` binding of the memoized function.
  583. *
  584. * **Note:** The cache is exposed as the `cache` property on the memoized
  585. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  586. * constructor with one whose instances implement the
  587. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  588. * method interface of `delete`, `get`, `has`, and `set`.
  589. *
  590. * @static
  591. * @memberOf _
  592. * @since 0.1.0
  593. * @category Function
  594. * @param {Function} func The function to have its output memoized.
  595. * @param {Function} [resolver] The function to resolve the cache key.
  596. * @returns {Function} Returns the new memoized function.
  597. * @example
  598. *
  599. * var object = { 'a': 1, 'b': 2 };
  600. * var other = { 'c': 3, 'd': 4 };
  601. *
  602. * var values = _.memoize(_.values);
  603. * values(object);
  604. * // => [1, 2]
  605. *
  606. * values(other);
  607. * // => [3, 4]
  608. *
  609. * object.a = 2;
  610. * values(object);
  611. * // => [1, 2]
  612. *
  613. * // Modify the result cache.
  614. * values.cache.set(object, ['a', 'b']);
  615. * values(object);
  616. * // => ['a', 'b']
  617. *
  618. * // Replace `_.memoize.Cache`.
  619. * _.memoize.Cache = WeakMap;
  620. */
  621. function memoize(func, resolver) {
  622. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  623. throw new TypeError(FUNC_ERROR_TEXT);
  624. }
  625. var memoized = function() {
  626. var args = arguments,
  627. key = resolver ? resolver.apply(this, args) : args[0],
  628. cache = memoized.cache;
  629. if (cache.has(key)) {
  630. return cache.get(key);
  631. }
  632. var result = func.apply(this, args);
  633. memoized.cache = cache.set(key, result);
  634. return result;
  635. };
  636. memoized.cache = new (memoize.Cache || MapCache);
  637. return memoized;
  638. }
  639. // Assign cache to `_.memoize`.
  640. memoize.Cache = MapCache;
  641. /**
  642. * Performs a
  643. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  644. * comparison between two values to determine if they are equivalent.
  645. *
  646. * @static
  647. * @memberOf _
  648. * @since 4.0.0
  649. * @category Lang
  650. * @param {*} value The value to compare.
  651. * @param {*} other The other value to compare.
  652. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  653. * @example
  654. *
  655. * var object = { 'a': 1 };
  656. * var other = { 'a': 1 };
  657. *
  658. * _.eq(object, object);
  659. * // => true
  660. *
  661. * _.eq(object, other);
  662. * // => false
  663. *
  664. * _.eq('a', 'a');
  665. * // => true
  666. *
  667. * _.eq('a', Object('a'));
  668. * // => false
  669. *
  670. * _.eq(NaN, NaN);
  671. * // => true
  672. */
  673. function eq(value, other) {
  674. return value === other || (value !== value && other !== other);
  675. }
  676. /**
  677. * Checks if `value` is classified as an `Array` object.
  678. *
  679. * @static
  680. * @memberOf _
  681. * @since 0.1.0
  682. * @category Lang
  683. * @param {*} value The value to check.
  684. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  685. * @example
  686. *
  687. * _.isArray([1, 2, 3]);
  688. * // => true
  689. *
  690. * _.isArray(document.body.children);
  691. * // => false
  692. *
  693. * _.isArray('abc');
  694. * // => false
  695. *
  696. * _.isArray(_.noop);
  697. * // => false
  698. */
  699. var isArray = Array.isArray;
  700. /**
  701. * Checks if `value` is classified as a `Function` object.
  702. *
  703. * @static
  704. * @memberOf _
  705. * @since 0.1.0
  706. * @category Lang
  707. * @param {*} value The value to check.
  708. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  709. * @example
  710. *
  711. * _.isFunction(_);
  712. * // => true
  713. *
  714. * _.isFunction(/abc/);
  715. * // => false
  716. */
  717. function isFunction(value) {
  718. // The use of `Object#toString` avoids issues with the `typeof` operator
  719. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  720. var tag = isObject(value) ? objectToString.call(value) : '';
  721. return tag == funcTag || tag == genTag;
  722. }
  723. /**
  724. * Checks if `value` is the
  725. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  726. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  727. *
  728. * @static
  729. * @memberOf _
  730. * @since 0.1.0
  731. * @category Lang
  732. * @param {*} value The value to check.
  733. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  734. * @example
  735. *
  736. * _.isObject({});
  737. * // => true
  738. *
  739. * _.isObject([1, 2, 3]);
  740. * // => true
  741. *
  742. * _.isObject(_.noop);
  743. * // => true
  744. *
  745. * _.isObject(null);
  746. * // => false
  747. */
  748. function isObject(value) {
  749. var type = typeof value;
  750. return !!value && (type == 'object' || type == 'function');
  751. }
  752. /**
  753. * Checks if `value` is object-like. A value is object-like if it's not `null`
  754. * and has a `typeof` result of "object".
  755. *
  756. * @static
  757. * @memberOf _
  758. * @since 4.0.0
  759. * @category Lang
  760. * @param {*} value The value to check.
  761. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  762. * @example
  763. *
  764. * _.isObjectLike({});
  765. * // => true
  766. *
  767. * _.isObjectLike([1, 2, 3]);
  768. * // => true
  769. *
  770. * _.isObjectLike(_.noop);
  771. * // => false
  772. *
  773. * _.isObjectLike(null);
  774. * // => false
  775. */
  776. function isObjectLike(value) {
  777. return !!value && typeof value == 'object';
  778. }
  779. /**
  780. * Checks if `value` is classified as a `Symbol` primitive or object.
  781. *
  782. * @static
  783. * @memberOf _
  784. * @since 4.0.0
  785. * @category Lang
  786. * @param {*} value The value to check.
  787. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  788. * @example
  789. *
  790. * _.isSymbol(Symbol.iterator);
  791. * // => true
  792. *
  793. * _.isSymbol('abc');
  794. * // => false
  795. */
  796. function isSymbol(value) {
  797. return typeof value == 'symbol' ||
  798. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  799. }
  800. /**
  801. * Converts `value` to a string. An empty string is returned for `null`
  802. * and `undefined` values. The sign of `-0` is preserved.
  803. *
  804. * @static
  805. * @memberOf _
  806. * @since 4.0.0
  807. * @category Lang
  808. * @param {*} value The value to process.
  809. * @returns {string} Returns the string.
  810. * @example
  811. *
  812. * _.toString(null);
  813. * // => ''
  814. *
  815. * _.toString(-0);
  816. * // => '-0'
  817. *
  818. * _.toString([1, 2, 3]);
  819. * // => '1,2,3'
  820. */
  821. function toString(value) {
  822. return value == null ? '' : baseToString(value);
  823. }
  824. /**
  825. * Gets the value at `path` of `object`. If the resolved value is
  826. * `undefined`, the `defaultValue` is returned in its place.
  827. *
  828. * @static
  829. * @memberOf _
  830. * @since 3.7.0
  831. * @category Object
  832. * @param {Object} object The object to query.
  833. * @param {Array|string} path The path of the property to get.
  834. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  835. * @returns {*} Returns the resolved value.
  836. * @example
  837. *
  838. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  839. *
  840. * _.get(object, 'a[0].b.c');
  841. * // => 3
  842. *
  843. * _.get(object, ['a', '0', 'b', 'c']);
  844. * // => 3
  845. *
  846. * _.get(object, 'a.b.c', 'default');
  847. * // => 'default'
  848. */
  849. function get(object, path, defaultValue) {
  850. var result = object == null ? undefined : baseGet(object, path);
  851. return result === undefined ? defaultValue : result;
  852. }
  853. module.exports = get;