node.js数据类型检查

node.js数据类型检查

export function isString(arg) {
return arg && typeof(arg) == "string";
}

export function isNumber(arg) {
return arg && typeof(arg) == "number" && !isNaN(arg);
}

export function isBoolean(arg) {
return arg === !!arg;
}

export function isArray(arg) {
return Object.prototype.toString.call(arg) == '[object Array]';
}

export function isObject(arg) {
return Object.prototype.toString.call(arg) == '[object Object]';
}

export function isFunction(arg) {
return Object.prototype.toString.call(arg) == '[object Function]';
}

export function isEmpty(arg) {
return Object.keys(arg).length === 0;
}

你可能感兴趣的:(node.js)