Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/rate-map
Map a number in the range of 0-1 to a new value with a given range
https://github.com/shinnn/rate-map
javascript
Last synced: 27 days ago
JSON representation
Map a number in the range of 0-1 to a new value with a given range
- Host: GitHub
- URL: https://github.com/shinnn/rate-map
- Owner: shinnn
- License: isc
- Created: 2017-04-25T09:33:59.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T12:30:47.000Z (over 5 years ago)
- Last Synced: 2024-10-04T06:44:52.628Z (about 1 month ago)
- Topics: javascript
- Language: JavaScript
- Homepage: https://runkit.com/npm/rate-map
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rate-map
[![npm version](https://img.shields.io/npm/v/rate-map.svg)](https://www.npmjs.com/package/rate-map)
[![Build Status](https://travis-ci.org/shinnn/rate-map.svg?branch=master)](https://travis-ci.org/shinnn/rate-map)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/rate-map.svg)](https://coveralls.io/github/shinnn/rate-map)Map a number in the range of `0`-`1` to a new value with a given range
```javascript
import rateMap from 'rate-map';rateMap(0.5, 0, 100); //=> 50
rateMap(0.5, 100, 200); //=> 150
rateMap(0.5, -100, 100); //=> 0
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install rate-map
```## API
### rateMap(*value*, *start*, *end*)
*value*: `number` in the range of `0..1`
*start*: `number`
*end*: `number`
Return: `number````javascript
rateMap(0.1, 0, -1); //=> -0.1
rateMap(0.1, 1, -1); //=> -0.8
rateMap(0.1, -1, -2); //=> -1.1rateMap(0, 5, 5); //=> 5
rateMap(0.5, 5, 5); //=> 5
rateMap(1, 5, 5); //=> 5
```## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe