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

tisnthings

v1.6.22

Published

Smallish set of things I often use. Favors brevity.

Downloads

1

Readme

tisnthings.js

Smallish set of things I often use. Favors brevity.

Example: type checking with tis(a,b) (as in "type is"):

tis(x,"")//is x a string?
tis(x,[])//is x an array?
tis(x,aFxn)//is x a function?
tis(x,aPromise)//is x a promise?
tis(x,/ /)//is x regex?
tis(x,new CustomThing)//is x a CustomThing?

tis works by constructor comparisons, with some quick checks first, so:

tis(NaN,1)//false
tis(NaN,NaN)//true!

type(x) will give you a string of x a bit more distinctly than typeof. ([] is 'array'!)

Or a quick ways to guess random numbers:

g()//plain Math.random()
g(1)// 50 / 50 chance truthy
g(100)//randomly pick an integer between 0 & 100
g(50,60)//randomly pick an integer between 50 & 60
g(50,60,true)//pick a floaty decimal between 50 & 60
g([2,3,6,9])//randomly return a value from the array

array2obj(), or shorthand a2o(array[,justBeTruthy[,specificValueKey]]), allowing easy preprocessing of []s into O(1)-accessible {} properties instead of using [].indexOf:

a2o([1,2,3,4],"just be truthy")//{1: 1, 2: 1, 3: 1, 4: 1} //values all a truthy 1
a2o([1,2,3,4])                 //{1: 0, 2: 1, 3: 2, 4: 3} //values ascending
a2o([{k:1},{k:5},{z:12}],0,'k') //{1:{k:1},5:{k:5},undefined:{z:12}} //key by k, if value has it

and for symmetry's sake (albeit less used), obj2array(), or o2a(object[,callKey]):

o2a({f:3,k:9,e:{Z:"Q"}})     //[{val:3,key:"f"},{val:9,key:"k"},{val:{Z:"Q"},key:"e"}]
o2a({f:3,k:9,e:{Z:"Q"}},"W") //[{val:3,W:"f"},{val:9,W:"k"},{val:{Z:"Q"},W:"e"}]

Some string functions:

//what a human might like seeing:
"query_select ColumnName".pretty()//"Query Select Column Name"
//machine a string to something simpler:
"a Goofy nglés sentence!!(#&---".machine()//"a_goofy_ngl_s_sentence"

code2str(55356,57194,9786)//cookie + smiley face characters
"doc brown".toProperCase()//"Doc Brown"
"Something Else".decapitalize()//"something Else"
"convert into method name".toMethodName()//"convertIntoMethodName"
"somethingCamelCased".camelSplit()//["something", "Camel", "Cased"]
"pass".replaceAt(0,"b")//"bass"
x.in("a b c")//true if x=='a' || x=='b' || x=='c' (case insensitive)

Some constants & simple functions for easy reading:

var aDay=24*3600*1000
  ,aPromise=new Promise(function(){})
  ,aFxn=function(){}
  ,noop=function(){}
  ,asc =function(a,b){return a<b?1:-1}
  ,desc=function(a,b){return a>b?1:-1}
  ,lexicalAsc=function(a,b){return a>b?1:a==b?0:-1}

Sometimes it's worth insisting you have an array:

//x might not be an array
insistArray(x)//but it definitely is now
    .map(x=>x*x)

Give a function some inputs, but don't execute just yet:

var gp=g.pass(1,10)
//...later
gp()//g(1,10)

And all Math.* functions are brought into the global scope.

max(1,10)
sin(PI)
tan(PI/2)
///etc