# map-range

> Simple function domain/range conversion

Latest version **0.1.2** (published 2014-04-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install map-range
pnpm add map-range
yarn add map-range
bun add map-range
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2014-04-18 |
| First published | 2014-04-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Jason Frame |
| Maintainers | jaz303 |
| Keywords | math, function, domain, range, map |

## Links

- npm: https://www.npmjs.com/package/map-range
- Repository: https://github.com/jaz303/map-range
- Issues: https://github.com/jaz303/map-range/issues
- npm.io page: https://npm.io/package/map-range

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2014-04-18
- 0.1.1 — 2014-04-18
- 0.1.0 — 2014-04-18

## README

# map-range

Convert a function that has a domain and range of `0..1` to one with an arbitrary domain and range through application of a linear mapping.

That's a complicated way of saying this:

<table>
	<thead>
    <tr>
      <th><code>x</code></th>
      <th><code>fn(x)</code></th>
      <th><code>map(fn, 0, 1, 200, 300)(x)</code></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0</td>
      <td>0</td>
      <td>200</td>
    </tr>
    <tr>
      <td>0.25</td>
      <td>0.25</td>
      <td>225</td>
    </tr>
    <tr>
      <td>0.5</td>
      <td>0.5</td>
      <td>250</td>
    </tr>
    <tr>
      <td>0.75</td>
      <td>0.75</td>
      <td>275</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>300</td>
    </tr>
  </tbody>
</table>

## Installation

    $ npm install map-range

## Usage

```javascript
var map = require('map-range');

function linear(x) {
  return x;
}

var mapped = map(linear, 0, 1, 1000, 1100);

mapped(0.5); // => 1050
```

## API

#### `map(fn, inStart, inEnd, outStart, outEnd)`

`fn` should be a single-arg function that expects values in the range 0..1 and returns a corresponding value in the same range. `map` will wrap this function to accept arguments in the domain `inStart..inEnd` and map, linearly, its output to the range `outStart..outEnd`.

#### `map(fn, outStart, outEnd)`

As above but with implied values of 0 and 1 for `inStart`, `inEnd`.

---
_Source: https://npm.io/package/map-range · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
