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

niims

v1.0.3

Published

Nonlinear Interpolation of Integers Made Simple

Downloads

20

Readme

niims

Nonlinear Integer Interpolation Made Simple

Parabolic Interpolation
Graph Visualizations powered by desmos.com

USING niims

const niims = require("niims");

HOW IT WORKS

This package nonlinearly (or linearly if you so choose) interpolates between two numbers. No matter the method of interpolation, three arguments are needed.

[0] linearProgress // A number between min and max that represents where to interpolate the output number. For example, assuming min and max are 0 and 1, 0.5 would transform into 0.25 when using parabolic interpolation, and 0.75 would transform into 0.56.
[1] min // The lowest number that can be interpolated between.
[2] max // The largest number that can be interpolated between.

Here are some examples:

niims.load("parabolic")
niims.parabolic(0.5, 0, 1) // 0.25
niims.parabolic(50, 0, 100) // 25
niims.parabolic(0.5, 0, 1, {power: 3}) // 0.125
niims.parabolic(0.95, 0, 1, {power: 3}) // 0.86

If you need help visualizing this, then refer to the graphical "INTERNAL MODULES" section.

USING STATIC MODULES

These are internal functions that shouldn't be normally used by the end user unless they want to express a range between two large values as a range between 0 and 1, and the reverse. They can be found here, and require no niims.load() call.

niims.rebase(int <0-1>, min, max) // Converts a number from 0-1 to min-max.
niims.debase(int <min-max>, min, max) // Converts a number from min-max to 0-1.

USING INTERNAL MODULES

The base niims module comes pre-packaged with an ever-expanding list of internal modules. The entire list can be found below, in the "INTERNAL MODULES" section. A quick and dirty way to get all modules is with a ".load()" command with no arguments.

niims.load();

niims.linear(...)
niims.parabolic(...)

This is wasteful and may be unreliable, so using a load function while supplying only the modules that you want to load is much better.

niims.load("linear");
niims.load("parabolic");

niims.linear(...);
niims.parabolic(...);

USING EXTERNAL MODULES

An external module is a group of smaller modules that are contained in a seperate NPM package. This will happen when a certain set of niims functions are very specialized and can be grouped together into an external module. You can find these by searching for "@niims/". As of now, none exist, but here is how it would be used.

niims.require("@niims/MyExternalModuleNameHere")

// OR

var externalModule = require("@niims/externalModule")
niims.require(externalModule.load())

INTERNAL MODULES

Remember, the default min and max values are always 0 and 1!

LINEAR

Linear Interpolation

Mostly just a test function for rebase/debase. Will always return the same number as the first argument.

PARABOLIC

Parabolic Interpolation

The first form of "accelerative" interpolation. Due to the nature of parabolas, the frequency cannot be controlled and will always consistently rise from min to max. Options include the power, which is 2 by default. Powers equal to 1 will make the interpolation linear, powers less than one will provide "negative acceleration" (never decreases, increases at an ever-lower rate), while powers greater than one will provide "positive acceleration".

f(i, min, max, {power: 2})

SINE

Sine Interpolation

The second form of "accelerative" interpolation. The frequency (times that the maximum value can be reached) can be controlled, which is also the rate of change. By default, it is 0.5. A frequency of 1 would, for example, change a number that is the mean of the minimum and maximum value to the maximum value itself, while numbers closer to the minimum and maximum values are the least, meaning that it would interpolate "upwards", then "downwards" half-way through. This can be desirable in certain situations.

f(i, min, max, {frequency: 0.5})

REFLECTIVE

Reflective Interpolation

A form of interpolation that is linear, but the rate of change "bounces" a specified number of times. Options include the frequency (bounce count), which is 2 by default.

f(i, min, max, {frequency: 2})

SAWTOOTH

Sawtooth Interpolation

A form of interpolation that is linear, but transforms directly from max to min a specified number of times. Options include the frequency (wrap count), which is 2 by default.

f(i, min, max, {frequency: 2})

SQUARE

Square Interpolation

A form of interpolation that will start at either 0 or 1 (polarity), and switch between 0 and 1 a certain amount of times (frequency) in an equally-spaced way. A frequency of two will make any value before 0.5 equal to (0 or 1), and any value that is or is after 0.5 equal to (1 or 0). 

f(i, min, max, {frequency: 2, polarity: 0})

HERMITE

Hermite Interpolation

Basic "hermite" interpolation. Good choice for preserving linearity while also introducing curvature.

f(i, min, max)