source: imaps-frontend/node_modules/lodash-es/toArray.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import Symbol from './_Symbol.js';
2import copyArray from './_copyArray.js';
3import getTag from './_getTag.js';
4import isArrayLike from './isArrayLike.js';
5import isString from './isString.js';
6import iteratorToArray from './_iteratorToArray.js';
7import mapToArray from './_mapToArray.js';
8import setToArray from './_setToArray.js';
9import stringToArray from './_stringToArray.js';
10import values from './values.js';
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
58export default toArray;
Note: See TracBrowser for help on using the repository browser.