map-range
v0.1.2
Published
Simple function domain/range conversion
Downloads
769
Readme
map-range
Convert a function that has a domain and range of 0..1 to one with an arbitrary domain and range through application of a linear mapping.
That's a complicated way of saying this:
Installation
$ npm install map-rangeUsage
var map = require('map-range');
function linear(x) {
return x;
}
var mapped = map(linear, 0, 1, 1000, 1100);
mapped(0.5); // => 1050API
map(fn, inStart, inEnd, outStart, outEnd)
fn should be a single-arg function that expects values in the range 0..1 and returns a corresponding value in the same range. map will wrap this function to accept arguments in the domain inStart..inEnd and map, linearly, its output to the range outStart..outEnd.
map(fn, outStart, outEnd)
As above but with implied values of 0 and 1 for inStart, inEnd.
