https://github.com/ashleymarkfletcher/range-map
node module that scales a number from one range to another
https://github.com/ashleymarkfletcher/range-map
javascript npm-package range range-map scale
Last synced: 6 months ago
JSON representation
node module that scales a number from one range to another
- Host: GitHub
- URL: https://github.com/ashleymarkfletcher/range-map
- Owner: ashleymarkfletcher
- Created: 2017-06-20T21:42:46.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-08-20T04:39:22.000Z (over 2 years ago)
- Last Synced: 2025-09-06T16:55:40.490Z (7 months ago)
- Topics: javascript, npm-package, range, range-map, scale
- Language: JavaScript
- Homepage:
- Size: 50.8 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# range-map
inspired by the **[Map](https://processing.org/reference/map_.html)** function in **[Processing](https://processing.org/)**. This module scales a number from one range to another
[](https://nodei.co/npm/range-map/)
[](https://travis-ci.org/ashleymarkfletcher/range-map)
[](https://codecov.io/gh/ashleymarkfletcher/range-map)
## Installation
```bash
$ npm install range-map
```
## Example Usage
```js
var rangeMap = require("range-map");
var mapped = rangeMap(50, 0, 100, 0, 1000);
//mapped == 500
var clampMapped = rangeMap(500, 0, 100, 0, 1000, true);
//clampMapped == 1000
```
## API
`mapped(input, inputLowest, inputHighest, outputLowest, outputHighest, [clamped=false])`
returns a number that has been rounded with `Math.round()`
The ranges will also work with negative numbers.
If `clamped` is truthy then output value will be clamped to the minimum and maximum output values.