npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

builtin-type

v0.0.4

Published

What is the type of this builtin JS value?

Readme

Features

Install

[!NOTE]

Determining the builtin type in a way that works cross-realm and is resilient to spoofing is significantly slower than plain instanceof or Object.prototype.toString.call(...). If you don't need those guarantees, then just use these simpler options directly.

$ npm i builtin-type

Usage

import assert from 'node:assert'
import builtinType from 'builtin-type'

assert.equal(builtinType(undefined), `undefined`)
assert.equal(builtinType(null), `null`)
assert.equal(builtinType(false), `boolean`)
assert.equal(builtinType(42), `number`)
assert.equal(builtinType(42n), `bigint`)
assert.equal(builtinType(`foo`), `string`)
assert.equal(builtinType(Symbol()), `symbol`)
assert.equal(builtinType(new Boolean(false)), `Boolean`)
assert.equal(builtinType(new Number(42)), `Number`)
assert.equal(builtinType(Object(42n)), `BigInt`)
assert.equal(builtinType(new String(`foo`)), `String`)
assert.equal(builtinType(Object(Symbol())), `Symbol`)
assert.equal(builtinType([]), `Array`)
assert.equal(builtinType(new Map()), `Map`)
assert.equal(builtinType(new Set()), `Set`)
assert.equal(builtinType(new WeakMap()), `WeakMap`)
assert.equal(builtinType(new WeakSet()), `WeakSet`)
assert.equal(
  builtinType(() => {}),
  `Function`,
)
assert.equal(
  builtinType(function* () {}),
  `GeneratorFunction`,
)
assert.equal(
  builtinType(async () => {}),
  `AsyncFunction`,
)
assert.equal(
  builtinType(async function* () {}),
  `AsyncGeneratorFunction`,
)
assert.equal(builtinType(Promise.resolve()), `Promise`)
assert.equal(builtinType(new Date()), `Date`)
assert.equal(builtinType(/a/g), `RegExp`)
assert.equal(builtinType(new URL(`https://example.com/`)), `URL`)
assert.equal(builtinType(new URLSearchParams()), `URLSearchParams`)
assert.equal(builtinType(new WeakRef({})), `WeakRef`)
assert.equal(
  builtinType(new FinalizationRegistry(() => {})),
  `FinalizationRegistry`,
)
assert.equal(builtinType(new ArrayBuffer()), `ArrayBuffer`)
assert.equal(builtinType(new SharedArrayBuffer()), `SharedArrayBuffer`)
assert.equal(builtinType(Buffer.from([])), `Buffer`)
assert.equal(builtinType(new Int8Array()), `Int8Array`)
assert.equal(builtinType(new Uint8Array()), `Uint8Array`)
assert.equal(builtinType(new Uint8ClampedArray()), `Uint8ClampedArray`)
assert.equal(builtinType(new Int16Array()), `Int16Array`)
assert.equal(builtinType(new Uint16Array()), `Uint16Array`)
assert.equal(builtinType(new Int32Array()), `Int32Array`)
assert.equal(builtinType(new Uint32Array()), `Uint32Array`)
assert.equal(builtinType(new BigInt64Array()), `BigInt64Array`)
assert.equal(builtinType(new BigUint64Array()), `BigUint64Array`)
assert.equal(builtinType(new Float16Array()), `Float16Array`)
assert.equal(builtinType(new Float32Array()), `Float32Array`)
assert.equal(builtinType(new Float64Array()), `Float64Array`)
assert.equal(builtinType(new DataView(new ArrayBuffer())), `DataView`)
assert.equal(builtinType(new Temporal.Duration()), `Temporal.Duration`)
assert.equal(
  builtinType(Temporal.Instant.fromEpochMilliseconds(0)),
  `Temporal.Instant`,
)
assert.equal(
  builtinType(new Temporal.PlainDate(2024, 1, 15)),
  `Temporal.PlainDate`,
)
assert.equal(
  builtinType(new Temporal.PlainDateTime(2024, 1, 15, 12)),
  `Temporal.PlainDateTime`,
)
assert.equal(
  builtinType(new Temporal.PlainMonthDay(1, 15)),
  `Temporal.PlainMonthDay`,
)
assert.equal(builtinType(new Temporal.PlainTime(12)), `Temporal.PlainTime`)
assert.equal(
  builtinType(new Temporal.PlainYearMonth(2024, 1)),
  `Temporal.PlainYearMonth`,
)
assert.equal(
  builtinType(new Temporal.ZonedDateTime(0n, `UTC`)),
  `Temporal.ZonedDateTime`,
)
assert.equal(builtinType({}), `Object`)

Benchmarks

builtin-type is at least as fast as which-builtin-type. It may be slightly faster, but that could just be noise in the benchmarks.

Here's an example run of the benchmark:

 ✓ src/index.bench.ts 3333ms
     name                   hz      min      max     mean      p75      p99     p995     p999     rme  samples
   · whichBuiltinType  66.9824  14.6727  15.4056  14.9293  15.0297  15.4056  15.4056  15.4056  ±0.43%       34
   · builtinType       71.4251  13.7500  14.6090  14.0007  14.0046  14.6090  14.6090  14.6090  ±0.41%       36

  builtinType - src/index.bench.ts
    1.07x faster than whichBuiltinType

Contributing

Stars are always welcome!

For bugs and feature requests, please create an issue.

License

MIT © Tomer Aberbach