import { TypeTag } from '@/common/utils/index.ts' import { isString } from '@/common/utils/types.ts' /** * 检查是否为普通对象 * @param obj 待检查对象 */ export function isSimpleObject(obj: any) { if (Object.prototype.toString.call(obj) !== TypeTag.OBJECT) { return false } let firstProto = Object.getPrototypeOf(obj) if (firstProto == null) { return true } let proto = firstProto let pt = null while ((pt = Object.getPrototypeOf(proto)) != null) { proto = pt } return firstProto === proto } /** * 检查是否为类数组 * @param obj 待检查对象 */ export function isArrayLike(obj: any) { return obj != null && typeof obj !== 'function' && (typeof obj.length === 'number' && obj.length > -1 && obj.length % 1 === 0 && obj.length <= Number.MAX_SAFE_INTEGER) } /** * 检查是否为纯数字字符串 * @param obj 待检查对象 */ export function isNumStr(obj: any) { return isString(obj) && !isNaN(Number(obj)) } export default { isSimpleObject, isArrayLike, isNumStr, }