UNPKG

@planjs/utils

Version:

🔧 Common tools collection

29 lines (25 loc) 668 B
import { MAX_ARRAY_INDEX } from '../constant'; import getType from './get-type'; /** * 是否为Array类型 * @param value * @category Is */ function isArray(value) { return Array.isArray ? Array.isArray(value) : getType(value) === 'Array'; } /** * 是否为一个类数组 * @param value */ export function isArrayLike(value) { var shallowProperty = function shallowProperty(key) { return function (obj) { return obj == null ? void 0 : obj[key]; }; }; var getLength = shallowProperty('length'); var length = getLength(value); return typeof length === 'number' && length >= 0 && length <= MAX_ARRAY_INDEX; } export default isArray;