Utilities
mapRange

mapRange

Maps a value from one range to another.

Installation

npm install @madeinhaus/utils

Import

import { mapRange } from '@madeinhaus/utils';

Parameters

  • value (number): The value to map.
  • inMin (number): The minimum value of the input range.
  • inMax (number): The maximum value of the input range.
  • outMin (number): The minimum value of the output range.
  • outMax (number): The maximum value of the output range.

Returns

  • (number): The mapped value.

Usage

import { mapRange } from '@madeinhaus/utils';
 
const value = 50;
const inMin = 0;
const inMax = 100;
const outMin = 0;
const outMax = 1;
const mappedValue = mapRange(value, inMin, inMax, outMin, outMax); // 0.5

In this example, we import the mapRange function from the @madeinhaus/utils package and use it to map a value from one range to another.