0.0.1 • Published 5 years ago

type-tool v0.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

type-tool

Build Status codecov code style: prettier

一个安全的变量类型检查工具。

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