UNPKG

@ekb1zh/type

Version:

Simple tool for getting data type

52 lines (38 loc) 838 B
## Simple tool for getting data type ### Install ```sh 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`. ```ts typeof null // => 'object' typeof [] // => 'object' typeof {} // => 'object' ``` This little library solves this problem quickly and efficiently. ```tsx import { typeOf } from '@ekb1zh/type' typeOf(null) // => 'null' typeOf([]) // => 'array' typeOf({}) // => 'object' ``` Also you can use type `Kind` for type checking. ```tsx 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 ```