Code Monkey home page Code Monkey logo

type-tool's Introduction

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

type-tool's People

Contributors

hifizz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.