source: trip-planner-front/node_modules/lodash/toArray.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1var Symbol = require('./_Symbol'),
2 copyArray = require('./_copyArray'),
3 getTag = require('./_getTag'),
4 isArrayLike = require('./isArrayLike'),
5 isString = require('./isString'),
6 iteratorToArray = require('./_iteratorToArray'),
7 mapToArray = require('./_mapToArray'),
8 setToArray = require('./_setToArray'),
9 stringToArray = require('./_stringToArray'),
10 values = require('./values');
11
12/** `Object#toString` result references. */
13var mapTag = '[object Map]',
14 setTag = '[object Set]';
15
16/** Built-in value references. */
17var symIterator = Symbol ? Symbol.iterator : undefined;
18
19/**
20 * Converts `value` to an array.
21 *
22 * @static
23 * @since 0.1.0
24 * @memberOf _
25 * @category Lang
26 * @param {*} value The value to convert.
27 * @returns {Array} Returns the converted array.
28 * @example
29 *
30 * _.toArray({ 'a': 1, 'b': 2 });
31 * // => [1, 2]
32 *
33 * _.toArray('abc');
34 * // => ['a', 'b', 'c']
35 *
36 * _.toArray(1);
37 * // => []
38 *
39 * _.toArray(null);
40 * // => []
41 */
42function toArray(value) {
43 if (!value) {
44 return [];
45 }
46 if (isArrayLike(value)) {
47 return isString(value) ? stringToArray(value) : copyArray(value);
48 }
49 if (symIterator && value[symIterator]) {
50 return iteratorToArray(value[symIterator]());
51 }
52 var tag = getTag(value),
53 func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
54
55 return func(value);
56}
57
58module.exports = toArray;
Note: See TracBrowser for help on using the repository browser.