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

whatsit

v2.1.1

Published

A small util class.

Downloads

1

Readme

WhatsIt

A small util class.

The plugin is only available for Node.JS currently.

##Install package

npm install whatsit --save

TF stands for Team First

##Include package

var W = require('whatsit');

##Functions available

####type:

Also checks for email, url, phone number(uses libphonenumber library), NaN, Float, Int and Infinity types

W.type("hello world"); //'String'
W.type(123); //'Int'
W.type(123.23); //'Float'
W.type(NaN); //'NaN'
W.type(Infinity); //'Number'
W.type(-Infinity); //'Number'
W.type({}); //'Object'
W.type(undefined); //'Undefined'
W.type([]); //'Array'
W.type(true); //'Boolean'
W.type(new Date()); //'Date'
W.type(null); //'Null'
W.type("[email protected]"); //'Email'
W.type("http://www.google.com/?q=testing"); //'Url'
W.type("+44 7700 900804"); //'Phone'

####trueType:

Just check for type and returns true javascript type for an object 1

W.type("hello world"); //'String'
W.type(123); //'Number'
W.type(123.23); //'Number'
W.type(NaN); //'Number'
W.type(Infinity); //'Number'
W.type(-Infinity); //'Number'
W.type({}); //'Object'
W.type(undefined); //'Undefined'
W.type([]); //'Array'
W.type(true); //'Boolean'
W.type(new Date()); //'Date'
W.type(null); //'Null'
W.type("[email protected]"); //'String'
W.type("http://www.google.com/?q=testing"); //'String'
W.type("+44 7700 900804"); //'String'

####isNaN:

W.isNaN(NaN); //true
W.isNaN(1312); //false

####isFalsey:

Even checks for empty object and array.

W.isFalsey(false); //true
W.isFalsey(null); //true
W.isFalsey(0); //true
W.isFalsey(""); //true
W.isFalsey("   "); //true
W.isFalsey({}); //true
W.isFalsey([]); //true
W.isFalsey(undefined); //true
W.isFalsey(NaN); //true
W.isFalsey(["", null, 0, NaN, undefined, , false]); //true

####isEmpty:

Same as isFalsey but it returns false for false and 0. This helps to check required fields

W.isEmpty(false); //false
W.isEmpty(null); //true
W.isEmpty(0); //false
W.isEmpty(""); //true
W.isEmpty("   "); //true
W.isEmpty({}); //true
W.isEmpty([]); //true
W.isEmpty(undefined); //true
W.isEmpty(NaN); //true
W.isEmpty(["", null, 0, NaN, undefined, , false]); //false

####trim:

W.trim("          "); //""
W.trim("    hello   "); //"hello"
W.trim(["", null, 0, NaN, undefined, false, , "hello"]); //["hello"]

####prefixInArray:

W.prefixInArray(["Hello", "Hola", "Welcome"], "H"); //["Hello", "Hola"]
W.prefixInArray(["Hello", "Hola", "Welcome", null, undefined, 0, false, NaN], "H"); //["Hello", "Hola"]);
W.prefixInArray(["Wello", "Wola", "Welcome", null, undefined, 0, false, NaN], "H"); //[]
W.prefixInArray(["Hello", "Hola", "Welcome"], undefined); //["Hello", "Hola", "Welcome"]
W.prefixInArray(null, undefined); //null
W.prefixInArray(["Hello", "Hola", "Welcome"], ""); //["Hello", "Hola", "Welcome"]
W.prefixInArray(["Hello", "Hola", "Welcome",["Hello"]], "H"); //["Hello", "Hola"]

####sufixInArray:

W.sufixInArray(["Hello", "Hole", "Welcome"], "e"); //["Hole", "Welcome"]
W.sufixInArray(["Hello", "Hole", "Welcome", null, undefined, 0, false, NaN], "e"); //["Hole", "Welcome"]
W.sufixInArray(["Wello", "Wola", "Welcome", null, undefined, 0, false, NaN], "H"); //[]
W.sufixInArray(["Hello", "Hola", "Welcome"], undefined); //["Hello", "Hola", "Welcome"]
W.sufixInArray(null, undefined); //null
W.sufixInArray(["Hello", "Hola", "Welcome"], ""); //["Hello", "Hola", "Welcome"]

####findInArray:

W.findInArray(["Hello", "Hola", "Welcome"], "el"); //["Hello", "Welcome"]
W.findInArray(["Hello", "Hola", "Welcome", null, undefined, 0, false, NaN], "el"); //["Hello", "Welcome"]);
W.findInArray(["Wello", "Wola", "Welcome", null, undefined, 0, false, NaN], "z"); //[]
W.findInArray(["Hello", "Hola", "Welcome"], undefined); //["Hello", "Hola", "Welcome"]
W.findInArray(null, undefined); //null
W.findInArray(["Hello", "Hola", "Welcome"], ""); //["Hello", "Hola", "Welcome"]

####for

does for in loop and checks for hasOwnProperty for both objects and arrays in one line.

W.for([1, 2, 3, 4], function(index, item, items) {
  //do something
});
W.for({"key": "value"}, function(index, item, items) {
  //do something
});
W.for(undefined, function(index, item, items) {
  //do something
}); //throws an error 'Unexpected type'
W.for(undefined, undefined) // returns undefined

##LICENSE

The MIT License (MIT)

Back to Top