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

instof

v0.0.1

Published

Tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an value.

Downloads

13

Readme

instof

instof(<value>,<constructor>) => <boolean>
instof(<value>,<constructor_name>) => <boolean>

Tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an value. This is an alternative to instanceof that actually allows to check any value not just objects, even primitives, undefined and null. Also the big advantage in comparance with instanceof is that using instof you can do check without explicit import of constructor to the module by specifying string name of it.

Usage

const instof = require('instof')

//=> true:

instof(undefined, 'Undefined')
instof(null, 'Null')

instof(global, 'Global')
instof(global, Object)

instof(window, 'Global')
instof(window, 'Window')
instof(window, 'EventTarget')
instof(window, 'Object')

instof(NaN, 'NotNumber')
instof(NaN, Number)
instof(NaN, 'Object')

instof(1/0, 'InfiniteNumber')
instof(-Infinity, 'InfiniteNumber')
instof(Infinity, Number)

instof(Object.create(null), 'Dictionary')
instof({}, Object)

instof(42, Number)
instof(42, 'Object')
instof('str', String)
instof('str', Object)

instof(async function () {}, 'AsyncFunction')
instof(async function () {}, Function)
instof(async function () {}, 'Object')

instof([], Array)
instof([], Object)

instof(new BigInt64Array(), 'BigInt64Array')
instof(new BigInt64Array(), 'TypedArray')
instof(new BigInt64Array(), Object)

//=> false:

instof(null, Object)

instof(Object.create(null), Object)

instof(BigInt(Number.MAX_SAFE_INTEGER), Number)

instof('str', Symbol)

instof({}, 'Dictionary')

instof(new Object(), 'Null')

instof([], 'TypedArray')

instof(new Int8Array(), Array)

Reserved constructor names

Reserved constructor names make possible to distinguish type of some special values from values with the real type. Historically, accessing the global object has required different syntax in different JavaScript environments. On the web you can use window, self, frames, in Node.js you must instead use global and constructor of this global value is 'Object'. Also there are not straightforward situations with null, NaN and Infinity values. To determine the constructor of such values the instof function uses the following constructor names:

  • 'Undefined' for undefined
  • 'Null' for null
  • 'Global' for global, window, etc.
  • 'NotNumber' for NaN
  • 'InfiniteNumber' for Infinity or -Infinity
  • 'Dictionary' for object without prototype that was created by Object.create(null)

Install

Install on Node.JS with npm

npm install instof

License

MIT © Taras Panasyuk