@arco-plugins/utils
Version:
utils for arco design plugins
28 lines (27 loc) • 613 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrify = void 0;
function isIterator(val) {
return typeof val[Symbol.iterator] === 'function';
}
/**
* 将传入的内容转化为数组
* @param {any} value
* @returns {array<any>}
*/
function arrify(value) {
if (value === null || value === undefined) {
return [];
}
if (Array.isArray(value)) {
return value;
}
if (typeof value === 'string') {
return [value];
}
if (isIterator(value)) {
return [...value];
}
return [value];
}
exports.arrify = arrify;