const objectTypes = {
null: '[object Null]',
undefined: '[object Undefined]',
regExp: '[object RegExp]',
number: '[object Number]',
string: '[object String]',
function: '[object Function]',
symbol: '[object Symbol]',
object: '[object Object]',
date: '[object Date]',
math: '[object Math]',
window: '[object Window]',
};
/**
* 判断值是否为对象
* @param {object} value 值
*/
export const isObject = (value: any): boolean => {
if (value === undefined || value === null) return false;
if (Object.prototype.toString.apply(value) === objectTypes.object) {
return true;
}
return false;
};
export const isString = (value: any): boolean => {
if (value === undefined || value === null) return false;
if (Object.prototype.toString.apply(value) === objectTypes.string) return true;
return false;
};
网友评论