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 🙏

© 2026 – Pkg Stats / Ryan Hefner

snacks-js

v1.0.4

Published

Let’s have some snacks!

Downloads

168

Readme

JavaScript snacks

Relax and have a tasty snack.

The need for snacks

I love JavaScript. It’s an often misunderstood language, full of beauty and flexibility. “Minutes to learn, lifetime to master.” Just about everything in JavaScript is an Object. In fact, JavaScript is more object-oriented than most so-called “OO” programming languages. But for some reason its dynamic typing and superior prototypal inheritance confuses those crusty-compiler naysayers, who only believe in strongly-typed, classically-inherited cruft. Dinosaurs. Inspired by Lisp and Scheme, “LiveScript” (One of JavaScript’s early monikers) had first-class functions and lambdas from the start. Given how speedily it was crafted, and all the ways the Web has careened right off the rails… It’s a better language than we perhaps deserve.

So why Snacks, then? Snacks is a small collection of constants, methods, and conveniences that I have needed with such frequency over the past two decades (Yes—I’ve been doing this a long time), that it made sense to bundle this grab-bag of logic together into something more modularly useful. In its first incarnations (before modules and Node even existed), Snacks just blissfully augmented built-in language prototypes which made for incredibly pleasant function-chaining like so:

( 2 + 3 )
.multiply( 4.5 )
.round()
.toString()
.prepend( 'Our magic number:' )
.print()

Sadly, augmenting the built-in prototypes has become so frowned upon (and no one has bothered to sandbox / scope it yet), that Snacks can no longer afford this approach. But the individual logic bits are still so useful—so tasty—that once you pop, you can’t stop. And this toolkit is so lightweight; it’s just the goodies. No heavy meals.

Sanity checks

The world can be a stabby, insane place. These sanity checks keep your snacks safe.

Booleans

isUsefulBoolean( b ). Not null or undefined or NaN or anything else. Strictly true or false. Note that instance of Boolean and typeof b === 'boolean' would not do the trick here. (See the code comments for details.) This is the simplest sanity check and already JavaScript has gotchas.
isNotUsefulBoolean( b ). Inverts the above logic.

Numbers

isUsefulNumber( n ). Returns true if n is a numeric, finite number. It’s just a hair trickier than you’d expect. But we’ve got you covered.
isNotUsefulNumber( n ). Inverts the above logic.
isUsefulInteger( n ). Adds integer-checking to isUsefulNumber.
isNotUsefulInteger( n ). Inverts the above logic.

Strings

isString( s ). Is it? (Does not include Template literals.)
isEmptyString( s ). Is it a String with a length of exactly zero?
isNonEmptyString( s ). Looking for isString and a length greater than zero.
isUsefulString( s ). Currently this is pegged to isNonEmptyString, though I could see arguments for otherwise.
isNotUsefulString( s ). Inverts the above logic.

Arrays

isArray( a ).
isNotArray( a ).
isEmptyArray( a ).
isNotEmptyArray( a ).
isUsefulArray( a ).
arrayCount. What’s the difference between your grandma’s Array.prototype.length and arrayCount? We only count the defined entries—very useful for determining how many elements are actually in a sparse Array.

Unitless goodies

Operators

How about some higher order logic that feels a bit like Lisp / Scheme? Bonus: These functions allow you to juggle relative numeric values in addition to your normal, every day, absolutely-defined values.

OPERATORS. Object containing operator methods (and their common symbols / names) for the usual suspects like addition, subtraction, and so on.
operate( operatorObject, ...args ).
parseRelativeNumber( a ).
applyRelativeNumber( a ).

Randomness

random
randomBetween
randomInteger
randomIntegerBetween

Misc unitless

clamp
round
normalize
normalize01
lerp
mapRange
average
circularAverage
ratioToQuotient
copySign
signedPower

Geometry (and trigonometry)

PI. Alias for Math.PI.
TAU. Math.PI × 2.
degreesToRadians
radiansToDegrees
radiansToPointsArray
wrapToRange
normalizeAngle
polarToCartesian
rotateCartesian
findMidpoint
distance2D

Color

floatToHex
hslToRgb

Metric system

QUETTA
RONNA
YOTTA
ZETTA
EXA
PETA
TERA
GIGA
MEGA
KILO
HECTO
DEKA
UNIT
DECI
CENTA
MILLI
MICRO
NANO
PICO
FEMTO
ATTO
ZEPTO
YOCTO
RONTO
QUECTO
convertMetric

Misc

compareArraysByElementProperty
timeAgo
numberToFullWidthChars
toSentenceCase
toCamelCase
css