kind-of-modern
v0.1.0
Published
Tiny zero-dependency utility that returns the lowercase type of any JavaScript value.
Downloads
84
Maintainers
Readme
kind-of-modern
Tiny, zero-dependency utility that returns the lowercase type of any JavaScript value. Modern, cross‑realm safe, and Node + browser compatible.
Install
npm i kind-of-modernUsage
import kindOf from 'kind-of-modern'
kindOf('hello') // 'string'
kindOf(123) // 'number'
kindOf(true) // 'boolean'
kindOf(Symbol('x')) // 'symbol'
kindOf(1n) // 'bigint'
kindOf(() => {}) // 'function'
kindOf([]) // 'array'
kindOf(new Date()) // 'date'
kindOf(/re/) // 'regexp'
kindOf(new Error('oops')) // 'error'
kindOf(new Map()) // 'map'
kindOf(new Set()) // 'set'
kindOf(new WeakMap()) // 'weakmap'
kindOf(new WeakSet()) // 'weakset'
kindOf(null) // 'null'
kindOf(undefined) // 'undefined'
kindOf(Promise.resolve()) // 'promise'
kindOf(new Uint8Array()) // 'typedarray'
kindOf(Buffer.from('x')) // 'buffer' (Node)
kindOf({}) // 'object'Named export is also available:
import { kindOf } from 'kind-of-modern'Why modern?
- Uses
Object.prototype.toString(respectsSymbol.toStringTag) for accurate, cross‑realm detection. - Detects Node
Bufferand groups all TypedArray variants undertypedarray. - Strict TypeScript types and ESM + CJS builds with auto
.d.ts.
API
type Kind =
| 'string'
| 'number'
| 'boolean'
| 'symbol'
| 'bigint'
| 'function'
| 'array'
| 'date'
| 'regexp'
| 'error'
| 'map'
| 'set'
| 'weakmap'
| 'weakset'
| 'null'
| 'undefined'
| 'promise'
| 'typedarray'
| 'buffer'
| 'object'Benchmarks
npm run benchThis will build the package and run a micro‑benchmark comparing against the legacy kind-of package.
Publishing
- ESM + CJS:
exports,main, andmoduleare set. - Types:
.d.tsis emitted automatically. - Size: minified build stays under 2KB.
