@ekb1zh/type
Version:
Simple tool for getting data type
21 lines (19 loc) • 358 B
text/typescript
export type Kind =
| 'null'
| 'undefined'
| 'boolean'
| 'number'
| 'string'
| 'symbol'
| 'bigint'
| 'function'
| 'array'
| 'object'
export const typeOf = (value: unknown): Kind => {
const type = typeof value
if (type === 'object') {
return !value ? 'null' : Array.isArray(value) ? 'array' : type
} else {
return type
}
}