Consuming the package:
import { interpolate } from "https://unpkg.com/@ixfx/numbers/bundle";
Or: import { interpolate } from "@ixfx/numbers";
// Returns the value 50% between 1024 and 2310 (ie. 1667)
interpolate(0.5, 1024, 2310);
Or to import the whole package:
import * as Numbers from "https://unpkg.com/@ixfx/numbers/bundle";
Or: import * Numbers from "@ixfx/numbers";
// Returns the value 50% between 1024 and 2310 (ie. 1667)
Numbers.interpolate(0.5, 1024, 2310);
Calculates the average of all numbers in an array. Array items which aren't a valid number are ignored and do not factor into averaging.
Computes an average of an array with a set of weights applied.
Clamps a value between min and max (both inclusive) Defaults to a 0-1 range, useful for percentages.
Returns a function that clamps values.
Clamps integer v between 0 (inclusive) and array length or length (exclusive).
Returns value then will always be at least zero, and a valid array index.
Yields amount integers, counting by one from zero. If a negative amount is used,
count decreases. If offset is provided, this is added to the return result.
Returns the difference from the initial value. Defaults to absolute difference.
Returns a function which yields difference compared to last value.
Returns the dot product of arbitrary-sized arrays. Assumed they are of the same length.
Filters an iterator of values, only yielding those that are valid numbers
Flips a percentage-scale number: 1 - v.
Interpolates between a and b by amount. Aka lerp.
Interpolate between angles a and b by amount. Angles are in radians.
Returns a function that interpolates from A to B.
It steps through the interpolation with each call to the returned function.
This means that the incrementAmount will hinge on the rate
at which the function is called. Alternatively, consider https://api.ixfx.fun/_ixfx/modulation/interpolatorInterval/
which steps on the basis of clock time.
Checks if a value is within range of a base value
Yields a function that checks if a value is close to any target value
Returns true if possibleNumber is a number and not NaN
Generates a step-length series of values between start and end (inclusive).
Each value will be equally spaced.
Returns the maximum number out of data.
Undefined and non-numbers are silently ignored.
Returns the largest value, ignoring the sign of numbers
Returns the maximum out of data without pre-filtering for speed.
Returns the index of the largest value.
Returns the minimum number out of data.
Undefined and non-numbers are silently ignored.
Returns the maximum out of data without pre-filtering for speed.
Returns the index of the smallest value.
Creates a moving average for a set number of samples.
It returns a function which in turn yields an average value.
A moving average calculator (exponential weighted moving average) which does not keep track of previous samples. Less accurate, but uses less system resources.
Noise filtering
Calculate the min, max, total, average and count of input array data.
Yields numeric range between 0.0-1.0.
Generates a range of numbers, with a given interval.
Generates a range of numbers, starting from start and counting by interval.
If end is provided, generator stops when reached.
Scales a percentage-scale number, ie: v * t.
Rounds v by every. Middle values are rounded up by default.
Iterates over values finding the min/max.
By default non-numbers, as well as NaN and infinite values are skipped.
Returns a function that yields true if a number is at least min and no greater than max
Returns an empty range:
Returns true if ranges a and b have identical min/max values.
Returns false if not, or if either/both values are undefined
Returns true if range 'a' is within or same as range 'b'. Returns false if not or if either/both ranges are undefined
Expands a range to encompass a new range.
Returns existingRange if newRange is within it.
Computes min/max based on a new value and previous range. Returns existing object reference if value is within existing range.
Returns a function that scales values in a range, by default on 0..1 scale.
Keeps track of min/max values.
Rounds a number.
Scales v from an input range to an output range (aka map)
As scale, but result is clamped to be
within outMin and outMax.
Scales an input percentage value to an output range
If you have an input percentage (0-1), scalePercent maps it to an output range of outMin-outMax.
Scales an input percentage to a new percentage range.
Returns a scaling function
Returns a 'null' scaler that does nothing - the input value is returned as output.
Returns a function that scales an input percentage value to an output range
Returns a two-way scaler
// Input range 0..100, output range 0..1
const s = scalerTwoWay(0,100,0,1
Returns a function that yields true if a value
is at least threshold
Returns the total of data.
Undefined and non-numbers are silently ignored.
Returns the total of data without pre-filtering for speed.
Returns an array of all valid numbers from data
Applies a function fn to the elements of an array, weighting them based on their relative position.
Wraps floating point numbers to be within a range (default: 0..1). Use wrapInteger if you want to wrap integer values.
Wraps an integer number within a specified range, defaulting to degrees (0-360). Use wrap for floating-point wrapping.
Performs a calculation within a wrapping number range. This is a lower-level function. See also: wrapInteger for simple wrapping within a range.
Interpolation options.
Wrapper around a bipolar value. Immutable.
Apples
fnto every key ofobjwhich is numeric.