Options
All
  • Public
  • Public/Protected
  • All
Menu

Module type/is

Index

Variables

Variables

Const is

1.0.2 provide
is: { array: any; bool: any; boolean: any; error: any; false: any; fun: any; function: any; number: any; object: any; true: any } = ...

Type declaration

  • array: function
    • array(value: any): value is []
    • 判断是不是数组类型

      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.array([])).toBe(true);
      expect(is.array({})).toBe(false);
      

      Parameters

      • value: any

      Returns value is []

  • bool: function
    • bool(value: any): value is boolean
    • 判断是不是bool类型

      remarks
      1. 只能判断是否是bool值,不能判断是否是true或者false
      2. 不针对类型进行转化,只判断是否boolean类型
      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.bool(false)).toBe(true)
      

      Parameters

      • value: any

      Returns value is boolean

  • boolean: function
    • boolean(value: any): value is boolean
    • 判断是不是bool类型

      remarks
      1. 只能判断是否是bool值,不能判断是否是true或者false
      2. 不针对类型进行转化,只判断是否boolean类型
      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.boolean(false)).toBe(true)
      

      Parameters

      • value: any

      Returns value is boolean

  • error: function
    • error(value: any): value is Error
    • 判断是不是error类型

      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.error(new Error())).toBe(true)
      

      Parameters

      • value: any

      Returns value is Error

  • false: function
    • false(value: any): value is boolean
    • 判断是不是bool类型,并且对应的值是false

      remarks
      1. 如果判断不是bool值,返回false
      2. 如果是bool,在判断是否是具体的false值
      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.false(false)).toBe(true)
      expect(is.false(true)).toBe(false)
      

      Parameters

      • value: any

      Returns value is boolean

  • fun: function
    • fun(value: any): value is Function
    • 判断是不是function类型

      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.fun(() => {})).toBe(true)
      

      Parameters

      • value: any

      Returns value is Function

  • function: function
    • function(value: any): value is Function
    • 判断是不是function类型

      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.function(() => {})).toBe(true)
      

      Parameters

      • value: any

      Returns value is Function

  • number: function
    • number(value: any): value is Number
    • 判断是不是number类型

      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.number(1)).toBe(true)
      

      Parameters

      • value: any

      Returns value is Number

  • object: function
    • object(value: any): value is object
    • 判断是不是对象类型

      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.object({})).toBe(true);
      expect(is.object([])).toBe(false);
      

      Parameters

      • value: any

      Returns value is object

  • true: function
    • true(value: any): value is boolean
    • 判断是不是bool类型,并且对应的值是false

      remarks
      1. 如果判断不是bool值,返回false
      2. 如果是bool,在判断是否是具体的true值
      example
      import { type } from 'onex-utils';
      
      const { is } = type;
      
      expect(is.true(false)).toBe(false)
      expect(is.true(true)).toBe(true)
      

      Parameters

      • value: any

      Returns value is boolean