interpolate-all
v1.0.1
Published
Interpolate between Numbers, Arrays or Objects
Downloads
447
Maintainers
Readme
Installation
$ npm install --save interpolate-all
Import
import interpolate from "interpolate-all"
Syntax
interpolate(
a: number | number[] | object,
b: number | number[] | object,
alpha: number,
type: string = "linear"
): number | number[] | object
Examples
//Number and Number
interpolate(0, 10, 0.6) // 6
//Array and Number
interpolate([0, 10], 100, 0.5) // [50, 55]
//Array and Array
interpolate([0, 10], [10, -2], 0.5) // [5, 4]
//Object and Number
interpolate({foo: 0, bar: 200}, 100, 0.5) // {foo: 50, bar: 150}
//Object and Object
interpolate({foo: 0, baz: 33, bar: 200}, {foo: 100, bar: 300}, 0.5) // {foo: 50, baz: 33, bar: 250}
interpolate({foo: 0, bar: 200}, {foo: 100, baz: 33, bar: 300}, 0.5) // {foo: 50, bar: 250}
Custom types
interpolate(0,10,0.7,"easeInOutExpo") // 9.6875