|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- var Symbol = require('./_Symbol'),
- copyArray = require('./_copyArray'),
- getTag = require('./_getTag'),
- isArrayLike = require('./isArrayLike'),
- isString = require('./isString'),
- iteratorToArray = require('./_iteratorToArray'),
- mapToArray = require('./_mapToArray'),
- setToArray = require('./_setToArray'),
- stringToArray = require('./_stringToArray'),
- values = require('./values');
-
-
- var mapTag = '[object Map]',
- setTag = '[object Set]';
-
-
- var symIterator = Symbol ? Symbol.iterator : undefined;
-
-
- function toArray(value) {
- if (!value) {
- return [];
- }
- if (isArrayLike(value)) {
- return isString(value) ? stringToArray(value) : copyArray(value);
- }
- if (symIterator && value[symIterator]) {
- return iteratorToArray(value[symIterator]());
- }
- var tag = getTag(value),
- func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
-
- return func(value);
- }
-
- module.exports = toArray;
|