component-type
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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.

Package Sidebar

Install

npm i component-type

Weekly Downloads

1,265,602

Version

2.0.0

License

MIT

Unpacked Size

4.05 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus