component-type

    1.2.1 • Public • Published

    type

    Type assertions aka less-broken typeof.

    Example

    var type = require('type');
     
    var obj = new Date;
    if (type(obj) == 'date') ...

    API

    type(new Date) == 'date'
    type({}) == 'object'
    type(null) == 'null'
    type(undefined) == 'undefined'
    type("hey") == 'string'
    type(true) == 'boolean'
    type(false) == 'boolean'
    type(12) == 'number'
    type(type) == 'function'
    type(/asdf/) == 'regexp'
    type((function(){ return arguments })()) == 'arguments'
    type([]) == 'array'
    type(document.createElement('div')) == 'element'
    type(NaN) == 'nan'
    type(new Error('Ups! Something wrong...')) == 'error'
    type(new Buffer) == 'buffer'

    License

    MIT

    Install

    npm i component-type

    DownloadsWeekly Downloads

    627,757

    Version

    1.2.1

    License

    MIT

    Last publish

    Collaborators

    • dfcreative
    • maxogden
    • jongleberry
    • dominicbarnes
    • tootallnate
    • tjholowaychuk
    • juliangruber
    • ianstormtaylor
    • timoxley
    • mattmueller
    • jonathanong
    • queckezz
    • yields
    • anthonyshort
    • nami-doc
    • clintwood
    • thehydroimpulse
    • stephenmathieson
    • trevorgerhardt
    • timaschew