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

kindjs

v2.1.0

Published

Precise type-checker for JavaScript

Downloads

1

Readme

Kind

A more precise version of JavaScript's typeof

npm package Build Status Downloads Issues Code Coverage Semantic Release

Description

kind() returns a useful name for a variable's type. It breaks down objects into more precise terms: array, null, element, etc.

Examples:

| Input | typeof | kind | |:---------------|:--------|:------------| | [1, 2, 3] | "object" | "array" | | null | "object" | "null" | | new Promise(() => null) | "object" | "promise" | | document.getElementById('id') | "object" | "element" | | document.getElementsByTagName('div') | "object" | "nodelist" | | document.createTextNode('') | "object" | "node" | | new Date() | "object" | "date" | | {} | "object" | "object" (if no special type was detected — see full list below) |

Install

yarn: yarn add kindjs

npm: npm install kindjs

Usage

import kind from 'kindjs';

kind(['hello', 'world']);
//=> 'array'

Basic

// Objects that aren't *really* objects
kind(null);       // "null"
kind([1, 2, 3]);  // "array"
kind(arguments);  // "arraylike"
kind(new Date()); // "date"
kind(document.getElementById('id'));        // "element"
kind(document.getElementsByTagName('div')); // "nodelist"

// This one's actually just an object
kind({});         // "object"

// Also works on standard types
kind("text");     // "string"
kind(2);          // "number"
kind(alert);      // "function"

"Deep" option

You may add a second, boolean parameter to tell kind to perform a deeper test for some types. For example, instead of "number" it could return "integer" or "float".

kind(1);          // "number"
kind(1, true);    // "integer"

kind(1.21);       // "number"
kind(1.21, true); // "float"

kind(evt);        // "event"
kind(evt, true);  // "mouseevent" (i.e. if the event was a click)

A complete list is noted below

Supported types

  • All standard types normally returned by typeof:
    • function, undefined, boolean, symbol
    • string
      • Deep option returns either string or emptystring
    • number
      • Deep option returns either integer or float
  • array
  • arraylike
    • A non-array object with a .length property
  • null
  • element
  • node
    • Deep options from this list (e.g. text, comment)
  • nodelist
  • event
    • Deep options from this list (e.g. mouseevent, keyboardevent)
  • regexp
  • date
  • error
  • errorevent
  • math
  • promise
  • set
  • url (i.e. an instance of the URL() constructor)
  • urlsearchparams
  • map

Features

  • Works with any type, not just objects
  • Always returns a simple lowercase string, just like the native typeof
  • Handles undefined or undeclared variables
  • Optimized to check for the most common types first
  • Excellent browser support, including many very old browsers
    • IE 6+ (and maybe older)
    • Chrome
    • Firefox
    • Safari
    • Android 1+
    • Opera (pre-Blink)
    • Netscape 4 (in theory!)
    • Probably anything that runs JavaScript and supports regular expressions