interpolate-range

2.1.0 • Public • Published

Interpolate Range

Numeric range interpolation à la ReactNative's AnimatedValue.interpolate(). No dependencies, handy for animation or plotting points on a chart.

Props

Name Type Description
input [number, number] Input range (required)
output [number, number] Output range (required)
clamp boolean Restrict the returned value to the output range
fn (from, to, x) => number Alternative function to call on the value

Usage

import interpolate from 'interpolate-range';
 
function generateCurve({ floor, ceil, total }) {
  const data = [];
  const int = interpolate({
        inputRange: [floor, ceil],
        outputRange: [0, 1],
        clamp: true,
    });
 
  for (let k = 0; k < total; k++) {
    data.push({ x: k, y: int(k) });
  }
 
  return data;
}

Package Sidebar

Install

npm i interpolate-range

Weekly Downloads

747

Version

2.1.0

License

MIT

Last publish

Collaborators

  • jossmac