UNPKG

hd-types-check

Version:

hd-types-check 是一个校验实例类型的库,支持js的所有基本类型包括string、number、null、boolean、undefined,引用类型包括object、array、function、date。

44 lines (33 loc) 1.18 kB
# hd-types-check hd-types-check 是一个校验实例类型的库,支持js的所有基本类型包括string、number、nullboolean、undefined,引用类型包括objectarrayfunctiondate。 ## 使用过程 `npm install --save hd-types-checkyarn add hd-types-check ` ```js import Types from "hd-types-check" ``` ## 使用方法介绍 Types函数需要一个参数 @param {*} instance 任意一个实例 @returns 返回当前实例的类型,包括string、number、nullboolean、undefined、objectarrayfunctiondate ```js Types(123) // number Types("hello word") // string Types(null) // null Types(true) // boolean Types(undefined) // undefined Types({}) // object Types([]) // array Types(() => {}) // function Types(new Date()) // date ``` ## Types挂载的方法 ```js Types.isNumber(123) // true Types.isString("hello") // true Types.isNull(null) // true Types.isBoolean(false) // true Types.isObject({}) // true Types.isArray([]) // true Types.isFunction(() => {}) // true Types.isDate(new Date()) // true ```