ixfx
    Preparing search index...

    Module @ixfx/numbers - v0.43.0

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

    Namespaces

    Bipolar
    Normalise

    Functions

    applyToValues

    Apples fn to every key of obj which is numeric.

    const o = {
    name: 'john',
    x: 10,
    y: 20
    };
    const o2 = applyToValues(o, (v) => v * 2
    average

    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.

    averageWeighted

    Computes an average of an array with a set of weights applied.

    clamp

    Clamps a value between min and max (both inclusive) Defaults to a 0-1 range, useful for percentages.

    clamper

    Returns a function that clamps values.

    clampIndex

    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.

    count

    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.

    differenceFromFixed

    Returns the difference from the initial value. Defaults to absolute difference.

    differenceFromLast

    Returns a function which yields difference compared to last value.

    dotProduct

    Returns the dot product of arbitrary-sized arrays. Assumed they are of the same length.

    filterIterable

    Filters an iterator of values, only yielding those that are valid numbers

    flip

    Flips a percentage-scale number: 1 - v.

    interpolate

    Interpolates between a and b by amount. Aka lerp.

    interpolateAngle

    Interpolate between angles a and b by amount. Angles are in radians.

    interpolatorStepped

    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 @ixfx/numbers.interpolatorInterval which steps on the basis of clock time.

    isApprox

    Checks if a value is within range of a base value

    isCloseToAny

    Yields a function that checks if a value is close to any target value

    isValid

    Returns true if possibleNumber is a number and not NaN

    linearSpace

    Generates a step-length series of values between start and end (inclusive). Each value will be equally spaced.

    max

    Returns the maximum number out of data. Undefined and non-numbers are silently ignored.

    maxAbs

    Returns the largest value, ignoring the sign of numbers

    maxFast

    Returns the maximum out of data without pre-filtering for speed.

    maxIndex

    Returns the index of the largest value.

    min

    Returns the minimum number out of data. Undefined and non-numbers are silently ignored.

    minFast

    Returns the maximum out of data without pre-filtering for speed.

    minIndex

    Returns the index of the smallest value.

    movingAverage

    Creates a moving average for a set number of samples. It returns a function which in turn yields an average value.

    movingAverageLight

    A moving average calculator (exponential weighted moving average) which does not keep track of previous samples. Less accurate, but uses less system resources.

    noiseFilter

    Noise filtering

    numberArrayCompute

    Calculate the min, max, total, average and count of input array data.

    numericPercent

    Yields numeric range between 0.0-1.0.

    numericRange

    Generates a range of numbers, with a given interval.

    numericRangeRaw

    Generates a range of numbers, starting from start and counting by interval. If end is provided, generator stops when reached.

    proportion

    Scales a percentage-scale number, ie: v * t.

    quantiseEvery

    Rounds v by every. Middle values are rounded up by default.

    rangeInclusive

    Returns a function that yields true if a number is at least min and no greater than max

    round

    Rounds a number.

    scale

    Scales v from an input range to an output range (aka map)

    scaleClamped

    As scale, but result is clamped to be within outMin and outMax.

    scalePercent

    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.

    scalePercentages

    Scales an input percentage to a new percentage range.

    scaler

    Returns a scaling function

    scalerNull

    Returns a 'null' scaler that does nothing - the input value is returned as output.

    scalerPercent

    Returns a function that scales an input percentage value to an output range

    scalerTwoWay

    Returns a two-way scaler

    // Input range 0..100, output range 0..1
    const s = scalerTwoWay(0,100,0,1
    softmax
    thresholdAtLeast

    Returns a function that yields true if a value is at least threshold

    total

    Returns the total of data. Undefined and non-numbers are silently ignored.

    totalFast

    Returns the total of data without pre-filtering for speed.

    validNumbers

    Returns an array of all valid numbers from data

    weight

    Applies a function fn to the elements of an array, weighting them based on their relative position.

    wrap

    Wraps floating point numbers to be within a range (default: 0..1). Use wrapInteger if you want to wrap integer values.

    wrapInteger

    Wraps an integer number within a specified range, defaulting to degrees (0-360). Use wrap for floating-point wrapping.

    wrapRange

    Performs a calculation within a wrapping number range. This is a lower-level function. See also: wrapInteger for simple wrapping within a range.

    Type Aliases

    BasicInterpolateOptions

    Interpolation options.

    BipolarWrapper

    Wrapper around a bipolar value. Immutable.

    DifferenceKind
    NumberScaler
    NumberScalerTwoWay
    NumbersComputeOptions
    NumbersComputeResult