提交 a5db3092 编写于 作者: 小刘28's avatar 小刘28 💬

feat:调整部分类型校验代码;

Signed-off-by: 小刘28's avatarxiaozuo28 <1032584581@qq.com>
上级 bdec63f3
/**
* @Author: xiaozuo28
* @Date: 2022年5月13日08:05:20
* @LastEditors: xiaozuo28
* @LastEditTime: 2022年7月19日23:47:40
* @Description: 数据类型处理
**/
export default {
/**
* @Description 校验是否是字符串
* @Date 2022年7月19日23:51:27
* @Param {Object} obejct 待校验对象
* @Return {Boolean} true:是,false:不是
**/
isString(obejct) {
return Object.prototype.toString.call(obejct).slice(8, -1) === 'String';
},
/**
* @Description 校验是否是数字
* @Date 2022年7月19日23:51:27
* @Param {Object} obejct 待校验对象
* @Return {Boolean} true:是,false:不是
**/
isNumber(obejct) {
return Object.prototype.toString.call(obejct).slice(8, -1) === 'Number';
},
/**
* @Description 校验是否是Boolean
* @Date 2022年7月19日23:51:27
* @Param {Object} obejct 待校验对象
* @Return {Boolean} true:是,false:不是
**/
isBoolean(obejct) {
return Object.prototype.toString.call(obejct).slice(8, -1) === 'Boolean';
},
/**
* @Description 校验是否是函数
* @Date 2022年7月19日23:51:27
* @Param {Object} obejct 待校验对象
* @Return {Boolean} true:是,false:不是
**/
isFunction(obejct) {
return Object.prototype.toString.call(obejct).slice(8, -1) === 'Function';
}
}
/**
* @description 是否是Null
* @param {Object} obj 待判断对象
* @example
* obj.ubIsNull(null);<br/>
* true
*/
function ubIsNull(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Null';
}
/**
* @description 是否是undefined
* @param {Object} obj 待判断对象
* @example
* obj.ubIsUndefined(undefined);<br/>
* true
*/
function ubIsUndefined(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Undefined';
}
/**
* @description 是否是对象
* @param {Object} obj 待判断对象
* @example
* obj.ubIsObject(new Object());<br/>
* true
*/
function ubIsObject(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Object';
}
/**
* @description 是否是数组
* @param {Object} obj 待判断对象
* @example
* obj.ubIsArray([1,2,3]);<br/>
* true
*/
function ubIsArray(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Array';
}
/**
* @description 是否是时间
* @param {Object} obj 待判断对象
* @example
* obj.ubIsDate(new Date());<br/>
* true
*/
function ubIsDate(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Date';
}
/**
* @description 是否是正则表达式
* @param {Object} obj 待判断对象
* @example
* obj.ubIsRegExp(/,/g);<br/>
* true
*/
function ubIsRegExp(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'RegExp';
}
/**
* @description 是否是错误对象
* @param {Object} obj 待判断对象
* @example
* obj.ubIsError(new Error());<br/>
* true
*/
function ubIsError(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Error';
}
/**
* @description 是否是Symbol函数
* @param {Object} obj 待判断对象
* @example
* obj.ubIsSymbol(Symbol());<br/>
*/
function ubIsSymbol(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Symbol';
}
/**
* @description 是否是Promise对象
* @param {Object} obj 待判断对象
* @example
* obj.ubIsPromise(new Promise(function(resolve, reject) {}));<br/>
* true
*/
function ubIsPromise(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Promise';
}
/**
* @description 是否是Set
* @param {Object} obj 待判断对象
* @example
* obj.ubIsSet(new Set());<br/>
* true
*/
function ubIsSet(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Set';
}
/**
* @description 是否是Map
* @param {Object} obj 待判断对象
* @example
* obj.ubIsMap(new Map());
* true
*/
function ubIsMap(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Map';
}
/**
* @description 是否是Math
* @param {Object} obj 待判断对象
* @example
* obj.ubIsMath(Math);<br/>
* true
*/
function ubIsMath(obj) {
return Object.prototype.toString.call(obj).slice(8, -1) === 'Math';
}
/**
* @description 是否是False
* @param {Object} obj
* @example
* obj.ubIsFalse(false);<br/>
* true
*/
function ubIsFalse (obj) {
if (!obj || obj === 'null' || obj === 'undefined' || obj === 'false' || obj === 'NaN'){
return true
}
return false;
}
/**
* @description 是否是True
* @param {Object} obj 待判断对象
* @example
* obj.ubIsTrue(true);<br/>
* true
*/
function ubIsTrue (obj) {
return !this.ubIsFalse(obj);
}
export default {
ubIsString,
ubIsNumber,
ubIsBoolean,
ubIsFunction,
ubIsNull,
ubIsUndefined,
ubIsObject,
ubIsArray,
ubIsDate,
ubIsRegExp,
ubIsError,
ubIsSymbol,
ubIsPromise,
ubIsSet,
ubIsMap,
ubIsMath,
ubIsFalse,
ubIsTrue
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册