index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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 references for various `Number` constants. */
  10. var MAX_SAFE_INTEGER = 9007199254740991;
  11. /** `Object#toString` result references. */
  12. var argsTag = '[object Arguments]',
  13. funcTag = '[object Function]',
  14. genTag = '[object GeneratorFunction]',
  15. mapTag = '[object Map]',
  16. objectTag = '[object Object]',
  17. promiseTag = '[object Promise]',
  18. setTag = '[object Set]',
  19. stringTag = '[object String]',
  20. weakMapTag = '[object WeakMap]';
  21. var dataViewTag = '[object DataView]';
  22. /**
  23. * Used to match `RegExp`
  24. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  25. */
  26. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  27. /** Used to detect host constructors (Safari). */
  28. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  29. /** Used to detect unsigned integer values. */
  30. var reIsUint = /^(?:0|[1-9]\d*)$/;
  31. /** Used to compose unicode character classes. */
  32. var rsAstralRange = '\\ud800-\\udfff',
  33. rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
  34. rsComboSymbolsRange = '\\u20d0-\\u20f0',
  35. rsVarRange = '\\ufe0e\\ufe0f';
  36. /** Used to compose unicode capture groups. */
  37. var rsAstral = '[' + rsAstralRange + ']',
  38. rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
  39. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  40. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  41. rsNonAstral = '[^' + rsAstralRange + ']',
  42. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  43. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  44. rsZWJ = '\\u200d';
  45. /** Used to compose unicode regexes. */
  46. var reOptMod = rsModifier + '?',
  47. rsOptVar = '[' + rsVarRange + ']?',
  48. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  49. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  50. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  51. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  52. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  53. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  54. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
  55. /** Detect free variable `global` from Node.js. */
  56. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  57. /** Detect free variable `self`. */
  58. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  59. /** Used as a reference to the global object. */
  60. var root = freeGlobal || freeSelf || Function('return this')();
  61. /**
  62. * A specialized version of `_.map` for arrays without support for iteratee
  63. * shorthands.
  64. *
  65. * @private
  66. * @param {Array} [array] The array to iterate over.
  67. * @param {Function} iteratee The function invoked per iteration.
  68. * @returns {Array} Returns the new mapped array.
  69. */
  70. function arrayMap(array, iteratee) {
  71. var index = -1,
  72. length = array ? array.length : 0,
  73. result = Array(length);
  74. while (++index < length) {
  75. result[index] = iteratee(array[index], index, array);
  76. }
  77. return result;
  78. }
  79. /**
  80. * Converts an ASCII `string` to an array.
  81. *
  82. * @private
  83. * @param {string} string The string to convert.
  84. * @returns {Array} Returns the converted array.
  85. */
  86. function asciiToArray(string) {
  87. return string.split('');
  88. }
  89. /**
  90. * The base implementation of `_.times` without support for iteratee shorthands
  91. * or max array length checks.
  92. *
  93. * @private
  94. * @param {number} n The number of times to invoke `iteratee`.
  95. * @param {Function} iteratee The function invoked per iteration.
  96. * @returns {Array} Returns the array of results.
  97. */
  98. function baseTimes(n, iteratee) {
  99. var index = -1,
  100. result = Array(n);
  101. while (++index < n) {
  102. result[index] = iteratee(index);
  103. }
  104. return result;
  105. }
  106. /**
  107. * The base implementation of `_.values` and `_.valuesIn` which creates an
  108. * array of `object` property values corresponding to the property names
  109. * of `props`.
  110. *
  111. * @private
  112. * @param {Object} object The object to query.
  113. * @param {Array} props The property names to get values for.
  114. * @returns {Object} Returns the array of property values.
  115. */
  116. function baseValues(object, props) {
  117. return arrayMap(props, function(key) {
  118. return object[key];
  119. });
  120. }
  121. /**
  122. * Gets the value at `key` of `object`.
  123. *
  124. * @private
  125. * @param {Object} [object] The object to query.
  126. * @param {string} key The key of the property to get.
  127. * @returns {*} Returns the property value.
  128. */
  129. function getValue(object, key) {
  130. return object == null ? undefined : object[key];
  131. }
  132. /**
  133. * Checks if `string` contains Unicode symbols.
  134. *
  135. * @private
  136. * @param {string} string The string to inspect.
  137. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  138. */
  139. function hasUnicode(string) {
  140. return reHasUnicode.test(string);
  141. }
  142. /**
  143. * Checks if `value` is a host object in IE < 9.
  144. *
  145. * @private
  146. * @param {*} value The value to check.
  147. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  148. */
  149. function isHostObject(value) {
  150. // Many host objects are `Object` objects that can coerce to strings
  151. // despite having improperly defined `toString` methods.
  152. var result = false;
  153. if (value != null && typeof value.toString != 'function') {
  154. try {
  155. result = !!(value + '');
  156. } catch (e) {}
  157. }
  158. return result;
  159. }
  160. /**
  161. * Converts `iterator` to an array.
  162. *
  163. * @private
  164. * @param {Object} iterator The iterator to convert.
  165. * @returns {Array} Returns the converted array.
  166. */
  167. function iteratorToArray(iterator) {
  168. var data,
  169. result = [];
  170. while (!(data = iterator.next()).done) {
  171. result.push(data.value);
  172. }
  173. return result;
  174. }
  175. /**
  176. * Converts `map` to its key-value pairs.
  177. *
  178. * @private
  179. * @param {Object} map The map to convert.
  180. * @returns {Array} Returns the key-value pairs.
  181. */
  182. function mapToArray(map) {
  183. var index = -1,
  184. result = Array(map.size);
  185. map.forEach(function(value, key) {
  186. result[++index] = [key, value];
  187. });
  188. return result;
  189. }
  190. /**
  191. * Creates a unary function that invokes `func` with its argument transformed.
  192. *
  193. * @private
  194. * @param {Function} func The function to wrap.
  195. * @param {Function} transform The argument transform.
  196. * @returns {Function} Returns the new function.
  197. */
  198. function overArg(func, transform) {
  199. return function(arg) {
  200. return func(transform(arg));
  201. };
  202. }
  203. /**
  204. * Converts `set` to an array of its values.
  205. *
  206. * @private
  207. * @param {Object} set The set to convert.
  208. * @returns {Array} Returns the values.
  209. */
  210. function setToArray(set) {
  211. var index = -1,
  212. result = Array(set.size);
  213. set.forEach(function(value) {
  214. result[++index] = value;
  215. });
  216. return result;
  217. }
  218. /**
  219. * Converts `string` to an array.
  220. *
  221. * @private
  222. * @param {string} string The string to convert.
  223. * @returns {Array} Returns the converted array.
  224. */
  225. function stringToArray(string) {
  226. return hasUnicode(string)
  227. ? unicodeToArray(string)
  228. : asciiToArray(string);
  229. }
  230. /**
  231. * Converts a Unicode `string` to an array.
  232. *
  233. * @private
  234. * @param {string} string The string to convert.
  235. * @returns {Array} Returns the converted array.
  236. */
  237. function unicodeToArray(string) {
  238. return string.match(reUnicode) || [];
  239. }
  240. /** Used for built-in method references. */
  241. var funcProto = Function.prototype,
  242. objectProto = Object.prototype;
  243. /** Used to detect overreaching core-js shims. */
  244. var coreJsData = root['__core-js_shared__'];
  245. /** Used to detect methods masquerading as native. */
  246. var maskSrcKey = (function() {
  247. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  248. return uid ? ('Symbol(src)_1.' + uid) : '';
  249. }());
  250. /** Used to resolve the decompiled source of functions. */
  251. var funcToString = funcProto.toString;
  252. /** Used to check objects for own properties. */
  253. var hasOwnProperty = objectProto.hasOwnProperty;
  254. /**
  255. * Used to resolve the
  256. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  257. * of values.
  258. */
  259. var objectToString = objectProto.toString;
  260. /** Used to detect if a method is native. */
  261. var reIsNative = RegExp('^' +
  262. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  263. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  264. );
  265. /** Built-in value references. */
  266. var Symbol = root.Symbol,
  267. iteratorSymbol = Symbol ? Symbol.iterator : undefined,
  268. propertyIsEnumerable = objectProto.propertyIsEnumerable;
  269. /* Built-in method references for those with the same name as other `lodash` methods. */
  270. var nativeKeys = overArg(Object.keys, Object);
  271. /* Built-in method references that are verified to be native. */
  272. var DataView = getNative(root, 'DataView'),
  273. Map = getNative(root, 'Map'),
  274. Promise = getNative(root, 'Promise'),
  275. Set = getNative(root, 'Set'),
  276. WeakMap = getNative(root, 'WeakMap');
  277. /** Used to detect maps, sets, and weakmaps. */
  278. var dataViewCtorString = toSource(DataView),
  279. mapCtorString = toSource(Map),
  280. promiseCtorString = toSource(Promise),
  281. setCtorString = toSource(Set),
  282. weakMapCtorString = toSource(WeakMap);
  283. /**
  284. * Creates an array of the enumerable property names of the array-like `value`.
  285. *
  286. * @private
  287. * @param {*} value The value to query.
  288. * @param {boolean} inherited Specify returning inherited property names.
  289. * @returns {Array} Returns the array of property names.
  290. */
  291. function arrayLikeKeys(value, inherited) {
  292. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  293. // Safari 9 makes `arguments.length` enumerable in strict mode.
  294. var result = (isArray(value) || isArguments(value))
  295. ? baseTimes(value.length, String)
  296. : [];
  297. var length = result.length,
  298. skipIndexes = !!length;
  299. for (var key in value) {
  300. if ((inherited || hasOwnProperty.call(value, key)) &&
  301. !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  302. result.push(key);
  303. }
  304. }
  305. return result;
  306. }
  307. /**
  308. * The base implementation of `getTag`.
  309. *
  310. * @private
  311. * @param {*} value The value to query.
  312. * @returns {string} Returns the `toStringTag`.
  313. */
  314. function baseGetTag(value) {
  315. return objectToString.call(value);
  316. }
  317. /**
  318. * The base implementation of `_.isNative` without bad shim checks.
  319. *
  320. * @private
  321. * @param {*} value The value to check.
  322. * @returns {boolean} Returns `true` if `value` is a native function,
  323. * else `false`.
  324. */
  325. function baseIsNative(value) {
  326. if (!isObject(value) || isMasked(value)) {
  327. return false;
  328. }
  329. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  330. return pattern.test(toSource(value));
  331. }
  332. /**
  333. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  334. *
  335. * @private
  336. * @param {Object} object The object to query.
  337. * @returns {Array} Returns the array of property names.
  338. */
  339. function baseKeys(object) {
  340. if (!isPrototype(object)) {
  341. return nativeKeys(object);
  342. }
  343. var result = [];
  344. for (var key in Object(object)) {
  345. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  346. result.push(key);
  347. }
  348. }
  349. return result;
  350. }
  351. /**
  352. * Copies the values of `source` to `array`.
  353. *
  354. * @private
  355. * @param {Array} source The array to copy values from.
  356. * @param {Array} [array=[]] The array to copy values to.
  357. * @returns {Array} Returns `array`.
  358. */
  359. function copyArray(source, array) {
  360. var index = -1,
  361. length = source.length;
  362. array || (array = Array(length));
  363. while (++index < length) {
  364. array[index] = source[index];
  365. }
  366. return array;
  367. }
  368. /**
  369. * Gets the native function at `key` of `object`.
  370. *
  371. * @private
  372. * @param {Object} object The object to query.
  373. * @param {string} key The key of the method to get.
  374. * @returns {*} Returns the function if it's native, else `undefined`.
  375. */
  376. function getNative(object, key) {
  377. var value = getValue(object, key);
  378. return baseIsNative(value) ? value : undefined;
  379. }
  380. /**
  381. * Gets the `toStringTag` of `value`.
  382. *
  383. * @private
  384. * @param {*} value The value to query.
  385. * @returns {string} Returns the `toStringTag`.
  386. */
  387. var getTag = baseGetTag;
  388. // Fallback for data views, maps, sets, and weak maps in IE 11,
  389. // for data views in Edge < 14, and promises in Node.js.
  390. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  391. (Map && getTag(new Map) != mapTag) ||
  392. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  393. (Set && getTag(new Set) != setTag) ||
  394. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  395. getTag = function(value) {
  396. var result = objectToString.call(value),
  397. Ctor = result == objectTag ? value.constructor : undefined,
  398. ctorString = Ctor ? toSource(Ctor) : undefined;
  399. if (ctorString) {
  400. switch (ctorString) {
  401. case dataViewCtorString: return dataViewTag;
  402. case mapCtorString: return mapTag;
  403. case promiseCtorString: return promiseTag;
  404. case setCtorString: return setTag;
  405. case weakMapCtorString: return weakMapTag;
  406. }
  407. }
  408. return result;
  409. };
  410. }
  411. /**
  412. * Checks if `value` is a valid array-like index.
  413. *
  414. * @private
  415. * @param {*} value The value to check.
  416. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  417. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  418. */
  419. function isIndex(value, length) {
  420. length = length == null ? MAX_SAFE_INTEGER : length;
  421. return !!length &&
  422. (typeof value == 'number' || reIsUint.test(value)) &&
  423. (value > -1 && value % 1 == 0 && value < length);
  424. }
  425. /**
  426. * Checks if `func` has its source masked.
  427. *
  428. * @private
  429. * @param {Function} func The function to check.
  430. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  431. */
  432. function isMasked(func) {
  433. return !!maskSrcKey && (maskSrcKey in func);
  434. }
  435. /**
  436. * Checks if `value` is likely a prototype object.
  437. *
  438. * @private
  439. * @param {*} value The value to check.
  440. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  441. */
  442. function isPrototype(value) {
  443. var Ctor = value && value.constructor,
  444. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  445. return value === proto;
  446. }
  447. /**
  448. * Converts `func` to its source code.
  449. *
  450. * @private
  451. * @param {Function} func The function to process.
  452. * @returns {string} Returns the source code.
  453. */
  454. function toSource(func) {
  455. if (func != null) {
  456. try {
  457. return funcToString.call(func);
  458. } catch (e) {}
  459. try {
  460. return (func + '');
  461. } catch (e) {}
  462. }
  463. return '';
  464. }
  465. /**
  466. * Checks if `value` is likely an `arguments` object.
  467. *
  468. * @static
  469. * @memberOf _
  470. * @since 0.1.0
  471. * @category Lang
  472. * @param {*} value The value to check.
  473. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  474. * else `false`.
  475. * @example
  476. *
  477. * _.isArguments(function() { return arguments; }());
  478. * // => true
  479. *
  480. * _.isArguments([1, 2, 3]);
  481. * // => false
  482. */
  483. function isArguments(value) {
  484. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  485. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  486. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  487. }
  488. /**
  489. * Checks if `value` is classified as an `Array` object.
  490. *
  491. * @static
  492. * @memberOf _
  493. * @since 0.1.0
  494. * @category Lang
  495. * @param {*} value The value to check.
  496. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  497. * @example
  498. *
  499. * _.isArray([1, 2, 3]);
  500. * // => true
  501. *
  502. * _.isArray(document.body.children);
  503. * // => false
  504. *
  505. * _.isArray('abc');
  506. * // => false
  507. *
  508. * _.isArray(_.noop);
  509. * // => false
  510. */
  511. var isArray = Array.isArray;
  512. /**
  513. * Checks if `value` is array-like. A value is considered array-like if it's
  514. * not a function and has a `value.length` that's an integer greater than or
  515. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  516. *
  517. * @static
  518. * @memberOf _
  519. * @since 4.0.0
  520. * @category Lang
  521. * @param {*} value The value to check.
  522. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  523. * @example
  524. *
  525. * _.isArrayLike([1, 2, 3]);
  526. * // => true
  527. *
  528. * _.isArrayLike(document.body.children);
  529. * // => true
  530. *
  531. * _.isArrayLike('abc');
  532. * // => true
  533. *
  534. * _.isArrayLike(_.noop);
  535. * // => false
  536. */
  537. function isArrayLike(value) {
  538. return value != null && isLength(value.length) && !isFunction(value);
  539. }
  540. /**
  541. * This method is like `_.isArrayLike` except that it also checks if `value`
  542. * is an object.
  543. *
  544. * @static
  545. * @memberOf _
  546. * @since 4.0.0
  547. * @category Lang
  548. * @param {*} value The value to check.
  549. * @returns {boolean} Returns `true` if `value` is an array-like object,
  550. * else `false`.
  551. * @example
  552. *
  553. * _.isArrayLikeObject([1, 2, 3]);
  554. * // => true
  555. *
  556. * _.isArrayLikeObject(document.body.children);
  557. * // => true
  558. *
  559. * _.isArrayLikeObject('abc');
  560. * // => false
  561. *
  562. * _.isArrayLikeObject(_.noop);
  563. * // => false
  564. */
  565. function isArrayLikeObject(value) {
  566. return isObjectLike(value) && isArrayLike(value);
  567. }
  568. /**
  569. * Checks if `value` is classified as a `Function` object.
  570. *
  571. * @static
  572. * @memberOf _
  573. * @since 0.1.0
  574. * @category Lang
  575. * @param {*} value The value to check.
  576. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  577. * @example
  578. *
  579. * _.isFunction(_);
  580. * // => true
  581. *
  582. * _.isFunction(/abc/);
  583. * // => false
  584. */
  585. function isFunction(value) {
  586. // The use of `Object#toString` avoids issues with the `typeof` operator
  587. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  588. var tag = isObject(value) ? objectToString.call(value) : '';
  589. return tag == funcTag || tag == genTag;
  590. }
  591. /**
  592. * Checks if `value` is a valid array-like length.
  593. *
  594. * **Note:** This method is loosely based on
  595. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  596. *
  597. * @static
  598. * @memberOf _
  599. * @since 4.0.0
  600. * @category Lang
  601. * @param {*} value The value to check.
  602. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  603. * @example
  604. *
  605. * _.isLength(3);
  606. * // => true
  607. *
  608. * _.isLength(Number.MIN_VALUE);
  609. * // => false
  610. *
  611. * _.isLength(Infinity);
  612. * // => false
  613. *
  614. * _.isLength('3');
  615. * // => false
  616. */
  617. function isLength(value) {
  618. return typeof value == 'number' &&
  619. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  620. }
  621. /**
  622. * Checks if `value` is the
  623. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  624. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  625. *
  626. * @static
  627. * @memberOf _
  628. * @since 0.1.0
  629. * @category Lang
  630. * @param {*} value The value to check.
  631. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  632. * @example
  633. *
  634. * _.isObject({});
  635. * // => true
  636. *
  637. * _.isObject([1, 2, 3]);
  638. * // => true
  639. *
  640. * _.isObject(_.noop);
  641. * // => true
  642. *
  643. * _.isObject(null);
  644. * // => false
  645. */
  646. function isObject(value) {
  647. var type = typeof value;
  648. return !!value && (type == 'object' || type == 'function');
  649. }
  650. /**
  651. * Checks if `value` is object-like. A value is object-like if it's not `null`
  652. * and has a `typeof` result of "object".
  653. *
  654. * @static
  655. * @memberOf _
  656. * @since 4.0.0
  657. * @category Lang
  658. * @param {*} value The value to check.
  659. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  660. * @example
  661. *
  662. * _.isObjectLike({});
  663. * // => true
  664. *
  665. * _.isObjectLike([1, 2, 3]);
  666. * // => true
  667. *
  668. * _.isObjectLike(_.noop);
  669. * // => false
  670. *
  671. * _.isObjectLike(null);
  672. * // => false
  673. */
  674. function isObjectLike(value) {
  675. return !!value && typeof value == 'object';
  676. }
  677. /**
  678. * Checks if `value` is classified as a `String` primitive or object.
  679. *
  680. * @static
  681. * @since 0.1.0
  682. * @memberOf _
  683. * @category Lang
  684. * @param {*} value The value to check.
  685. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  686. * @example
  687. *
  688. * _.isString('abc');
  689. * // => true
  690. *
  691. * _.isString(1);
  692. * // => false
  693. */
  694. function isString(value) {
  695. return typeof value == 'string' ||
  696. (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
  697. }
  698. /**
  699. * Converts `value` to an array.
  700. *
  701. * @static
  702. * @since 0.1.0
  703. * @memberOf _
  704. * @category Lang
  705. * @param {*} value The value to convert.
  706. * @returns {Array} Returns the converted array.
  707. * @example
  708. *
  709. * _.toArray({ 'a': 1, 'b': 2 });
  710. * // => [1, 2]
  711. *
  712. * _.toArray('abc');
  713. * // => ['a', 'b', 'c']
  714. *
  715. * _.toArray(1);
  716. * // => []
  717. *
  718. * _.toArray(null);
  719. * // => []
  720. */
  721. function toArray(value) {
  722. if (!value) {
  723. return [];
  724. }
  725. if (isArrayLike(value)) {
  726. return isString(value) ? stringToArray(value) : copyArray(value);
  727. }
  728. if (iteratorSymbol && value[iteratorSymbol]) {
  729. return iteratorToArray(value[iteratorSymbol]());
  730. }
  731. var tag = getTag(value),
  732. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  733. return func(value);
  734. }
  735. /**
  736. * Creates an array of the own enumerable property names of `object`.
  737. *
  738. * **Note:** Non-object values are coerced to objects. See the
  739. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  740. * for more details.
  741. *
  742. * @static
  743. * @since 0.1.0
  744. * @memberOf _
  745. * @category Object
  746. * @param {Object} object The object to query.
  747. * @returns {Array} Returns the array of property names.
  748. * @example
  749. *
  750. * function Foo() {
  751. * this.a = 1;
  752. * this.b = 2;
  753. * }
  754. *
  755. * Foo.prototype.c = 3;
  756. *
  757. * _.keys(new Foo);
  758. * // => ['a', 'b'] (iteration order is not guaranteed)
  759. *
  760. * _.keys('hi');
  761. * // => ['0', '1']
  762. */
  763. function keys(object) {
  764. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  765. }
  766. /**
  767. * Creates an array of the own enumerable string keyed property values of `object`.
  768. *
  769. * **Note:** Non-object values are coerced to objects.
  770. *
  771. * @static
  772. * @since 0.1.0
  773. * @memberOf _
  774. * @category Object
  775. * @param {Object} object The object to query.
  776. * @returns {Array} Returns the array of property values.
  777. * @example
  778. *
  779. * function Foo() {
  780. * this.a = 1;
  781. * this.b = 2;
  782. * }
  783. *
  784. * Foo.prototype.c = 3;
  785. *
  786. * _.values(new Foo);
  787. * // => [1, 2] (iteration order is not guaranteed)
  788. *
  789. * _.values('hi');
  790. * // => ['h', 'i']
  791. */
  792. function values(object) {
  793. return object ? baseValues(object, keys(object)) : [];
  794. }
  795. module.exports = toArray;