@jossmac/lil-libs
    Preparing search index...

    Function remap

    • Maps a numeric value from one range to another via linear interpolation.

      Clamps to the output range by default. Supports negative and floating-point ranges. Pass { clamp: false } to allow extrapolation. Degenerate input ranges (from === to) map predictably.

      • value: number

        Input value to map from inputRange.

      • inputRange: [number, number]

        Two-element source range [from, to].

      • outputRange: [number, number]

        Two-element destination range mapped via linear interpolation.

      • options: { clamp?: boolean } = {}

        Optional settings; clamp defaults to true, constraining the result to outputRange.

      The linearly mapped value in outputRange; extrapolates when clamp is false.

      remap(5, [0, 10], [0, 100]); // 50
      remap(-5, [-10, 0], [0, 100]); // 50
      remap(7.5, [0, 10], [-20, -10]); // -12.5
      remap(-5, [0, 10], [0, 100]); // 0 (clamped)
      remap(15, [0, 10], [0, 100]); // 100 (clamped)
      remap(15, [0, 10], [0, 100], { clamp: false }); // 150