Skip to content

stewdio/shoes-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shoes for JavaScript

Walking never felt so easy.


A need for shoes

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 Shoes, then? Shoes 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), Shoes 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 Shoes can no longer afford this approach. But the individual logic bits are still so useful—so cozy—that once you try them, you won’t want to give them up. And this toolkit is so lightweight; it’s just the goodies.


Sanity checks

The world can be a stabby, insane place. Put on your shoes, and keep your sanity with these type helpers.

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

clamp, round, normalize, normalize01, lerp, mapRange,

average, circularAverage,

random, randomBetween, randomInteger, randomIntegerBetween,

ratioToQuotient, copySign, signedPower,

Geometry

degreesToRadians, radiansToDegrees, radiansToPointsArray, wrapToRange, normalizeAngle, polarToCartesian, rotateCartesian, findMidpoint, distance2D,

Color

floatToHex, hslToRgb,

Misc

compareArraysByElementProperty, timeAgo, numberToFullWidthChars, toSentenceCase, toCamelCase

About

Walking never felt so comfy.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published