Simple tool for getting data type
Install
npm i @ekb1zh/type
Reason
You can't just find out the type of the null
, array
and object
values in runtime. For these three values, the type is always object
.
typeof null // => 'object'
typeof [] // => 'object'
typeof {} // => 'object'
This little library solves this problem quickly and efficiently.
import { typeOf } from '@ekb1zh/type'
typeOf(null) // => 'null'
typeOf([]) // => 'array'
typeOf({}) // => 'object'
Also you can use type Kind
for type checking.
import { Kind } from '@ekb1zh/type'
const validValue: Kind = 'null' // ok
const invalidValue: Kind = 'bla-bla-bla' // error
The complete list of types that this library defines
null
undefined
boolean
number
string
symbol
bigint
function
array
object