house-middleware-sdk
Version:
58 hosue rn native sdk
79 lines (62 loc) • 1.42 kB
JavaScript
//TODO:这里应该更进一步
function isString(obj) {
return judgeType(obj, '[object String]');
}
function isObject(obj) {
return judgeType(obj, '[object Object]');
}
function isUndefined(obj) {
return judgeType(obj, '[object Undefined]');
}
function isNull(obj) {
return judgeType(obj, '[object Null]');
}
function isNumber(obj) {
return judgeType(obj, '[object Number]');
}
function isBoolean(obj) {
return judgeType(obj, '[object Boolean]');
}
function isFunction(obj) {
return judgeType(obj, '[object Function]');
}
function isArray(obj) {
return judgeType(obj, '[object Array]');
}
function isDate(obj) {
return judgeType(obj, '[object Date]');
}
function isRegExp(obj) {
return judgeType(obj, '[object RegExp]');
}
function judgeType(obj, type) {
return Object.prototype.toString.call(obj) === type;
}
function isEmpty(obj) {
if (isUndefined(obj) || isNull(obj)) {
return true;
}
const arr = Object.keys(obj);
return arr.length === 0;
}
function isEffectiveList(data) {
return data && data instanceof Array && data.length > 0;
}
function isEffectiveObject(data) {
return data && Object.keys(data).length > 0;
}
export {
isString,
isObject,
isUndefined,
isNull,
isNumber,
isBoolean,
isFunction,
isArray,
isDate,
isRegExp,
isEmpty,
isEffectiveList,
isEffectiveObject
};