range-mapper

1.0.0 • Public • Published

range-mapper

provides simple range-mapping functions for linear-interpolation.

installation

npm install range-mapper

usage

var rangeMapper = require('range-mapper');
var interpolate;


// convert [0..1] to [0..255]
interpolate = rangeMapper(0, 1, 0, 255);

interpolate(0); // > 0
interpolate(1); // > 255
interpolate(0.5); // > 127.5

// no clamping:
interpolate(-1); // > -255


// convert relative coordinates
interpolate = rangeMapper.clamped(0, elementWidth, -1, 1);

// could be used to get relative coordinates for mouse-events
interpolate(ev.pageX - elementLeft);

Package Sidebar

Install

npm i range-mapper

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • usefulthink