判断数据类型
export function isArray (ar) {
return Array.isArray(ar);
}
export function isBoolean (arg) {
return typeof arg === 'boolean';
}
export function isDef (value) {
return value !== undefined && value !== null
}
export function isNull (arg) {
return arg === null;
}
export function isNullOrUndefined (arg) {
return arg == null;
}
export function isNumber (arg) {
return typeof arg === 'number';
}
export function isString (arg) {
return typeof arg === 'string';
}
export function isSymbol (arg) {
return typeof arg === 'symbol';
}
export function isUndefined (arg) {
return arg === void 0;
}
export function isRegExp (re) {
return isObject(re) && objectToString(re) === '[object RegExp]';
}
export function isObject (arg) {
return typeof arg === 'object' && objectToString(arg) === '[object Object]';
}
export function isEmptyObject (obj) {
if (isObject(obj)) {
if (JSON.stringify(obj) === '{}') {
return false
}
}
return true
}
export function isDate (d) {
return isObject(d) && objectToString(d) === '[object Date]';
}
export function isError (e) {
return isObject(e) &&
(objectToString(e) === '[object Error]' || e instanceof Error);
}
export function isFunction (arg) {
return typeof arg === 'function';
}
export function isPrimitive (arg) {
return arg === null ||
typeof arg === 'boolean' ||
typeof arg === 'number' ||
typeof arg === 'string' ||
typeof arg === 'symbol' ||
typeof arg === 'undefined';
}
function objectToString (o) {
return Object.prototype.toString.call(o);
}
export function isHasOwnProperty (obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
const isUtil = {
isArray,
isBoolean,
isDef,
isNull,
isNullOrUndefined,
isNumber,
isString,
isSymbol,
isUndefined,
isRegExp,
isObject,
isEmptyObject,
isDate,
isError,
isFunction,
isPrimitive,
isHasOwnProperty
}
export default isUtil;