@ssports_fe/ssutils
Version:
24 lines (22 loc) • 653 B
JavaScript
/**
* @desc 获取对象类型
* @param {object} 需要检查的对象
* @return {String} 对象的字符串类型
*/
const typeOf = (obj) => {
const toString = Object.prototype.toString;
const map = {
'[object Boolean]': 'boolean',
'[object Number]': 'number',
'[object String]': 'string',
'[object Function]': 'function',
'[object Array]': 'array',
'[object Date]': 'date',
'[object RegExp]': 'regExp',
'[object Undefined]': 'undefined',
'[object Null]': 'null',
'[object Object]': 'object'
};
return map[toString.call(obj)];
};
module.exports = typeOf;