Skip to content

Advanced

interpolate has a few different ways of being used

// Provide amount, A, B and options
const value = interpolate(amount, a, b, options);
// Get back interpolated result
// Provide an interpolation amount and optional options
const i = interpolate(amount, options)
// Get back a function which takes A & B values
i(from, to); // Yields interpolated value
// Provide A & B values, and options
const i = interpolate(a, b, options);
// Get back a function which takes interpolation amount
const i(amount); // Yields interpolated value

The options for the interpolate function can be left out. It has a single property, limits which determines how to behave if interpolation amount exceeds 0..1.

  • ‘clamp’: clamp returned value to within A & B (inclusive). This is the default.
  • ‘wrap’: value wraps from end to start
  • ‘ignore’: allow return values which exceed A & B.

For example:

import { interpolate } from 'https://unpkg.com/ixfx/dist/numbers.js';
interpolate(1.1, 100, 200, { limits: `clamp` }); // 200
interpolate(1.1, 100, 200, { limits: `wrap` }); // 110
interpolate(1.1, 100, 200, { limits: `ignore` }); // 210