Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@anselan/maprange
Advanced tools
Inspired by the map function in the creative coding framework Processing.
Differs from the following similar JS packages:
remap (value, inputRange, targetRange, clamp, shouldRound)
...where the parameters are:
value
: a numberinputRange
, targetRange
: arrays of exactly 2 elements each, i.e [min,max]
clamp
(optional; default false
): whether to constrain the result within the given target rangeshouldRound
(optional; default false
): whether to round to nearest integer, i.e. only whole numbersProvide the range (inputMin
, inputMax
) that your value
is currently in, and specify a new range (outputMin
, outputMax
) and you'll get back a new value as per the target range.
npm install @anselan/remap
Then (depending on your environment):
import remap from 'remap`
...or:
const remap = require('remap`)
The value 0.5
in the range [0,1] should return as 50
in the range [0,100]:
const result = remap(0.5, [0,1], [0, 100]); // result === 50
Coordinates can often be normalised in the range [0,1]. Let's try convert to pixel values instead:
// These could be coordinates in [0,1] range:
const x = 0.5;
const y = 0.8967;
// Assume a display of 1920x1080 pixels:
const px = remap(0.5, [0,1], [0,1920]);
const py = remap(0.8967, [0,1], [0,1080]);
console.log(px, py); // "960, 968.436"
Often you want whole numbers for things like pixels. Optional rounding is included for convenience:
const py = remap(0.8967, [0,1], [0,1080], false, true);
console.log(py); // "968" (rounded from 968.436)
FAQs
Map values from one range to another
The npm package @anselan/maprange receives a total of 24 weekly downloads. As such, @anselan/maprange popularity was classified as not popular.
We found that @anselan/maprange demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.