component-type

Type assertions aka less-broken `typeof`

MIT 6 个版本
安装
npm install component-type
yarn add component-type
pnpm add component-type
bun add component-type
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.

版本列表
2.0.0 2023-11-16
1.2.2 2023-11-16
1.2.1 2016-03-15
1.2.0 2015-09-16
1.1.0 2014-12-08
1.0.0 2014-01-06