一个安全的变量类型检查工具。
Use yarn:
yarn add type-tool
Use npm:
npm i type-tool
import { isArray } from 'type-tool'
const targetVariable = []
const isVariableArray = isArray(targetVariable)
console.log(isVariableArray) // true
import * as type from 'type-tool'
const targetVariable = []
const isVariableArray = type.isArray(targetVariable)
console.log(isVariableArray) // true
借助 Object.prototype.toString
来返回真实的变量类型。
// 看下面的例子
console.log(typeof []) // "object"
console.log(Object.prototype.toString.call([])) // "[Object Array]"
console.log(typeof null) // "object"
console.log(Object.prototype.toString.call(null)) // "[Object Null]"
getTypeString
getTypeString(o: any): string
Alias Object.prototype.toString.call
Return string like "[Object Null]" "[Object Array]".
isString isString(o: any): boolean
isNumber isNumber(o: any): boolean
isBoolean isBoolean(o: any): boolean
isSymbol isSymbol(o: any): boolean
isArray isArray(o: any): boolean
isObject isObject(o: any): boolean
isFunction isFunction(o: any): boolean
isError isError(o: any): boolean
isNull isNull(o: any): boolean
isUndefined isUndefined(o: any): boolean
isDate isDate(o: any): boolean
isMath isMath(o: any): boolean