interpolate-range

Super simple numeric range interpolation

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
interpolate-range
1202.1.05 years ago5 years agoMinified + gzip package size for interpolate-range in KB

Readme

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;
}