A modern utility library for TypeScript and JavaScript

nuancejs

2024

What is it?

Nuance.js is a modern utility library for TypeScript and JavaScript. It is designed to be a lightweight alternative to popular libraries like lodash and underscore. The goal of the library is to provide a set of functions that are easy to use and read, and that aren't provided in the standard library. By using nuance, your code will be more easily readable by abstracting away complexity.

The library is available on npm, and the docs are available on nuancejs.org. Speaking of the docs, I created a custom built, fully self-contained search engine for the docs. Seriously, try it out. It's pretty cool! For example, type something like "library" and you'll get a filtered list of all the docs that contain the word "library".

Let's look at an example

Say you want to generate a random amount of particles. You can use JavaScript's

Math.random() function, but you don't want to generate 0 or 1 or 1.67457456 particles, instead, it would make more sense to generate an amount of particles that fall within a range of your choosing.

Well, JavaScript doesn't let you do that without writing some annoying code first.

Let's look at what you'd need to write in order to make a function that would let you generate a random number of particles within a range:

Math.floor(Math.random() * (20 - 10 + 1) + 10);

It's really not pretty, and if you want to change something down the line (like whether it be inclusive or exclusive) you have to go rework the formula directly.

With Nuance's randomInRange function, this becomes dead simple. Here's an example you can test out:

randomInRange({ min: 10, max: 20 })

// default inclusivity is true true