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

@sebbes/identify

v1.0.0

Published

Upgraded version of: typeof in JavaScript, to better identify & separate similar results.

Downloads

4

Readme

identify()

An upgraded version of: typeof in JavaScript, to better identify & separate similar results.

You can send in ANY THING to the identify() function and it returns an object with 2 properties: .type & .subType that lets you identify whatever it was you sent in. eg: identify([]).subType returns: "array" instead of "object" that typeof would return. identify() returns an object containing 2 properties: .type & .subType.

.type is the same as typeof in case you need a more general matching, but .subType tries to be as specific as posible, you usually want to use .subType.

All output strings will always be turned to lowercase, for consistency & ease of writing.

When/Why should I use this?

This is great when working with larger projects &/or global variables, where the variable you get into a function might not be what you expec it to be, because some other function have changed the value, or someone sends the wrong data to your function. Eg: You get in: add("1", 2) & return "12" instead of 3.

Usage examples:

let foo = identify(null);
console.log(foo.type) // "object"
console.log(foo.subType) // "null"

if( foo.subType === "null" ) {
    foo = 5;
}

let bar = identify(3.14)
console.log( typeof foo )  // "object"
console.log( foo.type )    // "number"
console.log( foo.subType ) // "float"
/*
bar = {
    type: "number",
    subType: "float"
}
*/

let baz = new Date();
let qux = identify(baz);
/*
qux = {
    type: "object ",
    subType: "date"
}
*/
NOTE!

There is no (known?) way to diferentiate a "integer like" float number, eg: 3.00 or 123.0000 from a "true integer" eg: 3 or 123, not even on a binarry level. Therefore identify(3.00).subType will return "int" instead of "float". All other things should return their correct values.

Feedback requests:
  1. I am thinking of removing .type & only return .subType directly as a string, but I will wait to see what your feedback says about it.
  2. If you find anything that doesn't return what you think it should, it would be very usefull if you could report it.