component-type
Cross-browser type assertions (less broken typeof)
Last updated 11 years ago by juliangruber .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install component-type 
SYNC missed versions from official npm registry.

component-type

Type assertions aka less-broken typeof

Install

npm install component-type

Usage

import type from 'component-type';

const date = new Date();

console.log(type(date));
//=> '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('Oh noes')) === 'error'
type(new Buffer) === 'buffer'

It makes no guarantees about the correctness when fed untrusted user-input.

Current Tags

  • 2.0.0                                ...           latest (2 years ago)

6 Versions

  • 2.0.0                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           10 years ago
  • 1.2.0                                ...           11 years ago
  • 1.1.0                                ...           11 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (0)
None
Dev Dependencies (0)
None

Copyright 2013 - present © cnpmjs.org | Home |