Variable testUtilsConst

testUtils: {
    isArray(obj): boolean;
    isBankCard(value): boolean;
    isCarNo(value): boolean;
    isChinese(value): boolean;
    isCode(value, len?): boolean;
    isDate(value): boolean;
    isDateISO(value): boolean;
    isDeepEqual(obj1, obj2): boolean;
    isEmail(value): boolean;
    isEmpty(...values): boolean;
    isFloat(obj, decimalPlaces?): boolean;
    isFunction(obj): boolean;
    isGif(value): boolean;
    isIdCard(value): boolean;
    isImage(value): boolean;
    isInLength(value, param): boolean;
    isInRange(value, param): boolean;
    isInteger(obj): boolean;
    isJsonString(value): boolean;
    isLandline(value): boolean;
    isLetter(value): boolean;
    isLetterOrNum(value): boolean;
    isMobile(value): boolean;
    isNonNegInt(value): boolean;
    isNotEmpty(...values): boolean;
    isNull(obj): boolean;
    isNullOrUndefined(obj): boolean;
    isNum(value): boolean;
    isObjAllFieldEmpty(Obj): boolean;
    isPlainObject(obj): boolean;
    isPromise(value): boolean;
    isSingleEmpty(value): boolean;
    isUndefined(obj): boolean;
    isUrl(value): boolean;
    isVersion(value): boolean;
    isVideo(value): boolean;
    isZero(value): boolean;
} = ...

逻辑判断相关方法

Type declaration

  • isArray:function
    • 是否为数组

      Parameters

      • obj: any

        对象

      Returns boolean

      Example

      testUtils.isArray([]); // true
      testUtils.isArray({}) // false
  • isBankCard:function
    • 判断是否为银行卡号

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isBankCard('1234561651'); // false
      testUtils.isBankCard('6222010300100044001') // true
      testUtils.isBankCard('62220103001000440011112356') // false
  • isCarNo:function
    • 判断是否为车牌号

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isCarNo('1234561651'); // false
      testUtils.isCarNo('粤B12345') // true
  • isChinese:function
    • 判断是否为中文

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isChinese('aasdas'); // false
      testUtils.isChinese('aasdasd123') // false
      testUtils.isChinese('哈哈') // true
  • isCode:function
    • 判断是否为短信验证码,或指定位数的纯数字

      Parameters

      • value: any

        传入数据

      • len: number = 6

        数字的预期长度, 默认6

      Returns boolean

      Example

      testUtils.isCode('123'); // false
      testUtils.isCode('123456') // true
      testUtils.isCode('123哈哈哈') // false
  • isDate:function
    • 判断是否为日期格式

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isDate('2020-01-01'); // true
      testUtils.isDate('2020-01-01 12:00:00') // true
      testUtils.isDate('2020-13-01 12:00:00.000') // false
      testUtils.isDate('1711013650') // true 时间戳
  • isDateISO:function
    • 判断是否为ios日期格式

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isDateISO('2020-01-01'); // true
      testUtils.isDateISO('2024/03/21') // true
  • isDeepEqual:function
    • 深度比较2个对象是否相等

      Parameters

      • obj1: any

        {Object} obj 对象

      • obj2: any

        {Object} obj 对象

      Returns boolean

      Example

      testUtils.isDeepEqual({ test1: 1, test2: 2 }, { test2: 2, test1: 1 }) // true
      testUtils.isDeepEqual([1, 2], [1, 2]) // true
      testUtils.isDeepEqual([2, 1], [1, 2]) // false
  • isEmail:function
    • 判断是否为电子邮箱格式

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isEmail('123'); // false
      testUtils.isEmail('123456') // false
      testUtils.isEmail('123asd@qq.com') // true
  • isEmpty:function
    • 判断一个或多个值是否全部为空 0, false 均为有值, 返回 false "" 为无值,返回 true

      Parameters

      • Rest ...values: any[]

        传入多个数据

      Returns boolean

      是否为空

      Example

      testUtils.isEmpty("") // true
      testUtils.isEmpty(0) // false
      testUtils.isEmpty(false) // false
      testUtils.isEmpty([1], {}); // false
      testUtils.isEmpty([], {}) // true
  • isFloat:function
    • 判断是否小数以及多少位的小数

      Parameters

      • obj: string | number

        传入数据

      • Optional decimalPlaces: number

        几位小数

      Returns boolean

      是否小数

      Example

      testUtils.isFloat("12.01") // true
      testUtils.isFloat(12.0) // false 会转化成12
      testUtils.isFloat(12.00,2) // false 会转化成12,整数直接返回了false
      testUtils.isFloat(12.11,2) // true
  • isFunction:function
    • 是否为方法

      Parameters

      • obj: any

        对象

      Returns boolean

      Example

      testUtils.isFunction(() => 1); // true
      testUtils.isFunction({}) // false
  • isGif:function
    • 判断是否为gif格式

      Parameters

      • value: string

      Returns boolean

      Example

      testUtils.isImage('123.png') // false
      testUtils.isImage('123.gif?a=1&b=2) // true
  • isIdCard:function
    • 判断是否为身份证号

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isIdCard('1234561651'); // false
      testUtils.isIdCard('533001199912112325') // true
  • isImage:function
    • 判断是否为图片格式

      Parameters

      • value: string

        传入数据

      Returns boolean

      Example

      testUtils.isImage('123'); // false
      testUtils.isImage('123.png') // true
      testUtils.isImage('123.gif?a=1&b=2) // true
  • isInLength:function
    • 判断长度是否在范围内

      Parameters

      • value: string | any[]

        传入数据

      • param: number[]

        范围参数, [min, max]

      Returns boolean

      Example

      testUtils.isInLength('123', [1, 3]); // true
      testUtils.isInLength('123qwe', [1, 3]) // false
      testUtils.isInLength('[1, 2, 3, 4, 5], [1, 5]) // true
  • isInRange:function
    • 判断是否在范围内

      Parameters

      • value: string | number

        传入数据

      • param: number[]

        范围参数, [min, max]

      Returns boolean

      Example

      testUtils.isInRange(1, [1, 2]); // true
      testUtils.isInRange(1, [2, 1]) // false
      testUtils.isInRange('5', [1, 3]) // false
  • isInteger:function
    • 判断是否整数

      Parameters

      • obj: string | number

        传入数据

      Returns boolean

      是否整数

      Example

      testUtils.isInteger(2.1); // false
      
  • isJsonString:function
    • 判断是否为JSON字符串

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isJsonString('123'); // false
      testUtils.isJsonString('{"a":1}') // true
  • isLandline:function
    • 判断是否为座机号

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isLandline('1234561651'); // false
      testUtils.isLandline('020-1234535') // true
  • isLetter:function
    • 判断是否全为字母

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isLetter('aasdas'); // true
      testUtils.isLetter('aasdasd123') // false
  • isLetterOrNum:function
    • 判断是否为字母、数字 或 字母数字组合

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isLetterOrNum('aasdas'); // true
      testUtils.isLetterOrNum('aasdasd123') // true
      testUtils.isLetterOrNum('aas哈哈asd') // false
  • isMobile:function
    • 判断是否为手机或座机格式 全部是数字,或者数字之间至多包含一个 - ,因为座机号包含 -

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isMobile('1234561651'); // true
      testUtils.isMobile('1234-561651') // true
      testUtils.isMobile('12345哈23@qq.com') // false
  • isNonNegInt:function
    • 判断是否为非负的整数

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isNonNegInt(1.1); // false
      testUtils.isNonNegInt(0) // true
      testUtils.isNonNegInt('0') // true
      testUtils.isNonNegInt('12.12') // false
      testUtils.isNonNegInt('-12.12') // false
  • isNotEmpty:function
    • 判断一个或多个值是否全部不为空

      Parameters

      • Rest ...values: any[]

        传入多个数据

      Returns boolean

      是否不为空

      Example

      testUtils.isNotEmpty([1], {}); // false
      testUtils.isNotEmpty({ a: 1 }, ['1']) // true
      testUtils.isNotEmpty(false) // false
      testUtils.isNotEmpty(0) // false
  • isNull:function
    • 是否为 null 或者 undefined

      Parameters

      • obj: any

        对象

      Returns boolean

      Example

      testUtils.isNull(null); // true
      testUtils.isNull(undefined) // false
  • isNullOrUndefined:function
    • 是否为 null 或者 undefined

      Parameters

      • obj: any

        对象

      Returns boolean

      Example

      testUtils.isNullOrUndefined(null); // true
      testUtils.isNullOrUndefined(undefined) // true
      testUtils.isNullOrUndefined('') // false
  • isNum:function
    • 判断是否为数字

      Parameters

      • value: any

        传入数据

      Returns boolean

      是否为数字

      Example

      testUtils.isNum(1); // true
      testUtils.isNum(-1.1) // true
      testUtils.isNum('0') // true
      testUtils.isNum('12.a2') // false
  • isObjAllFieldEmpty:function
    • 判断一个对象中的所有字段是否全为空 非对象类型返回false

      Parameters

      • Obj: {
            [key: string]: any;
        }

        传入对象

        • [key: string]: any

      Returns boolean

      是否为空

      Example

      testUtils.isObjAllFieldEmpty('{}') // false
      testUtils.isObjAllFieldEmpty({}) // true
      testUtils.isObjAllFieldEmpty({a: ''}) // true
      testUtils.isObjAllFieldEmpty({a: undefined}) // true
      testUtils.isObjAllFieldEmpty({a: null}) // true
      testUtils.isObjAllFieldEmpty({a: undefined}) // true
      testUtils.isObjAllFieldEmpty({ a: '12', b: 1 }) // false
  • isPlainObject:function
    • 是否为普通对象 即 通过对象字面量 {} 或者 new Object() 创建的

      Parameters

      • obj: any

        传入数据

      Returns boolean

      是否为普通对象

  • isPromise:function
    • 判断是否为Promise对象

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isPromise(Promise.resolve()); // true
      testUtils.isPromise(new Promise(() => {})) // true
      testUtils.isPromise(function fun() {}) // false
  • isSingleEmpty:function
    • 判断单个值是否为空

      Parameters

      • value: any

        传入数据

      Returns boolean

      是否为空

      Example

      testUtils.isSingleEmpty({}); // true
      testUtils.isSingleEmpty({ a: 1 }) // false
      testUtils.isSingleEmpty(12.01) // false
      testUtils.isSingleEmpty(null) // true
      testUtils.isSingleEmpty(undefined) // true
      testUtils.isSingleEmpty(NaN) // true
      testUtils.isSingleEmpty(false) // false
  • isUndefined:function
    • 是否为 null 或者 undefined

      Parameters

      • obj: any

        对象

      Returns boolean

      Example

      testUtils.isUndefined(null); // false
      testUtils.isUndefined(undefined) // true
  • isUrl:function
    • 判断是否为URL格式

      Parameters

      • value: any

        传入数据

      Returns boolean

      Example

      testUtils.isUrl('http://baidu.com'); // true
      testUtils.isUrl('https://baidu.com/123?a=1&b=2&c=哈哈') // true
      testUtils.isUrl('www.baidu.com') // false
  • isVersion:function
    • 是否版本号

      Parameters

      • value: string

        传入数据

      Returns boolean

      Example

      testUtils.isVersion('1234561651'); // false
      testUtils.isVersion(''0.0.1') // true
  • isVideo:function
    • 判断是否为视频格式

      Parameters

      • value: string

        传入数据

      Returns boolean

      Example

      testUtils.isVideo('123'); // false
      testUtils.isVideo('123.mp4') // true
      testUtils.isVideo('123.mpg?a=1&b=2') // true
  • isZero:function
    • 判断是否为0

      Parameters

      • value: any

        传入数据

      Returns boolean

      是否为0

      Example

      testUtils.isZero(1); // false
      testUtils.isZero(0) // true
      testUtils.isZero('0') // true
      testUtils.isZero(null) // false

Generated using TypeDoc