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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ibnlanre/typeof

v0.1.0

Published

A utility for retrieving the type of a JS value

Downloads

4

Readme

typeOf

A utility for retrieving the type of a JS value.

Install

npm i @ibnlanre/typeof

Import

// ES6 Import
import typeOf from "@ibnlanre/typeof"

// NodeJS Require
const typeOf = require("@ibnlanre/typeof");

Usage

typeOf([1, "two", 3]) // array
typeOf(JSON, { quirksMode: true }) // object
typeOf(async() => {}) // function
typeOf(new Set([0])[Symbol.iterator]()) // setiterator

Browser

You can also use typeOf within the browser, but only as a module.

<script src="http://unpkg.com/@ibnlanre/typeof" type="module">
  // CDN Service
</script>

<script src="./node_modules/@ibnlanre/typeof" type="module">
  // PKG manager
  console.log(typeOf(null)) // null
</script>

Reference

Some JavaScript Standard Built-ins compared with { quirkMode: true } results.

  • Primitives

    typeOf(NaN) // number
    typeOf(-Infinity) // number
    typeOf(0) // number
    typeOf(new Number(1)) // number
    typeOf(2n) // bigint
    typeOf(BigInt(3)) // bigint
    typeOf("type") // string
    typeOf(new String("of")) // string
    typeOf(false) // boolean
    typeOf(new Boolean(true)) // boolean
    typeOf(new Object(1 > 2)) // boolean
    typeOf(Symbol("bar")) // symbol
    typeOf(undefined) // undefined
    typeOf(null) // null
  • Functions

    typeOf(Object) // function
    typeOf(new Function()) // function
    typeOf((function () { return arguments })()) // arguments
    typeOf(() => { }) // function
  • Control Abstractions

    typeOf(function*() {}) // generatorfunction
    typeOf((function*(x) { yield x })(0)) // generator
    typeOf(new Set([0, 9, 8])[Symbol.iterator]()) // setiterator
    typeOf(async() => { await 0 }) // asyncfunction
  • Objects

    typeOf({ a: "apple", b: "ball" }) // object
    typeOf(new Object()) // object
    typeOf(new (class Library {})(), { quirksMode: true }) // library
    typeOf(new (class Library {})()) // object
    typeOf(/regEx/m) // regexp
    typeOf(new RegExp(/u/, "ig")) // regexp
    typeOf(new Date()) // date
  • Global Properties

    typeOf(globalThis) // global
    typeOf(globalThis, { quirksMode: true }) // object
    
    // NodeJS
    typeOf(global, { quirksMode: true }) // object
    typeOf(global), // global
  • Math

    typeOf(Math) // math
    typeOf(Math, { quirksMode: true }) // object
  • JSON

    typeOf(JSON, { quirksMode: true }) // object
    typeOf(JSON) // json
  • Error Objects

    typeOf(new Error()) // error
    typeOf(new SyntaxError()) // error
    typeOf(new SyntaxError(), { quirksMode: true }) // syntaxerror
  • Array

    typeOf([1, "two"]) // array
    typeOf(new Array()) // array
  • Structured Data

    typeOf(new ArrayBuffer()) // arraybuffer
    typeOf(new DataView(new ArrayBuffer())) // dataview
  • Keyed Collections

    typeOf(new Map()) // map
    typeOf(new WeakMap()) // weakmap
    typeOf(new Set()) // set
    typeOf(new WeakSet()) // weakset
  • Typed DataViews

    typeOf(new Int8Array()) //  int8array
    typeOf(new Uint8Array()) // uint8array
    typeOf(new Uint8ClampedArray()) // uint8clampedarray
    typeOf(new Int16Array()) // int16array
    typeOf(new Uint16Array()) // uint16array
    typeOf(new Int32Array()) // int32array
    typeOf(new Uint32Array()) // uint32array
    typeOf(new Float32Array()) // float32array
    typeOf(new Float64Array()) // float64array
    typeOf(new BigInt64Array()) // bigint64array
    typeOf(new BigUint64Array()) // biguint64array
  • Buffer

    // NodeJS
    typeOf(Buffer.from("abc"), { quirksMode: true }) // buffer
    typeOf(Buffer.from("abc")) // uint8array

Custom Type

You may also use Symbol.toStringTag to change an object's return value

const testObject = {};
testObject[Symbol.toStringTag] = "customType";
typeOf(testObject, { quirksMode: true }) // object
typeOf(testObject) // customtype