@newdash/newdash
Version:
javascript/typescript utility library
46 lines (45 loc) • 1.72 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toArray = void 0;
const copyArray_1 = __importDefault(require("./.internal/copyArray"));
const getTag_1 = __importDefault(require("./.internal/getTag"));
const iteratorToArray_1 = __importDefault(require("./.internal/iteratorToArray"));
const mapToArray_1 = __importDefault(require("./.internal/mapToArray"));
const setToArray_1 = __importDefault(require("./.internal/setToArray"));
const stringToArray_1 = __importDefault(require("./.internal/stringToArray"));
const isArrayLike_1 = __importDefault(require("./isArrayLike"));
const isString_1 = __importDefault(require("./isString"));
const values_1 = __importDefault(require("./values"));
/** `Object#toString` result references.
* @ignore
*/
const mapTag = "[object Map]";
/**
* @ignore
*/
const setTag = "[object Set]";
/**
* Built-in value references.
* @ignore
*/
const symIterator = Symbol.iterator;
function toArray(value) {
if (!value) {
return [];
}
if ((0, isArrayLike_1.default)(value)) {
// TODO: potential error
return (0, isString_1.default)(value) ? (0, stringToArray_1.default)(value) : (0, copyArray_1.default)(value);
}
if (symIterator && value[symIterator]) {
return (0, iteratorToArray_1.default)(value[symIterator]());
}
const tag = (0, getTag_1.default)(value);
const func = tag == mapTag ? mapToArray_1.default : (tag == setTag ? setToArray_1.default : values_1.default);
return func(value);
}
exports.toArray = toArray;
exports.default = toArray;