JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1505216
  • Score
    100M100P100Q180838F

Cross-browser type assertions (less broken typeof)

Package Exports

  • component-type

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (component-type) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.