0.0.1 • Published 5 years ago
type-tool v0.0.1
type-tool
一个安全的变量类型检查工具。
Install
Use yarn:
yarn add type-tool
Use npm:
npm i type-tool
Usage
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
Documentation
借助 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]"
API
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
0.0.1
5 years ago