Package Exports
- map-number
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (map-number) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
map-number
processing/p5.js map like function, including floating point numbers
⚠️ this
map
function has nothing to do withArray.prototype.map
method.
Install
npm
npm install map-number
jsDelivr
<script src="https://cdn.jsdelivr.net/npm/map-number/dist/map.umd.min.js"></script>
API
map
maps a number in a range to a different range, returning a floting point number, including number outside the given output range.
function map(num: number, min: number, max: number, outMin: number, outMax: number): number;
floor
maps a number in a range to a different range, returning a number truncated to the inmediate previous integer number, including number outside the given output range.
function floor(num: number, min: number, max: number, outMin: number, outMax: number): number;
round
maps a number in a range to a different range, returning a number rounded to the closest integer number, including number outside the given output range.
function round(num: number, min: number, max: number, outMin: number, outMax: number): number;
limit
maps a number in a range to a different range, returning a floting point number, limiting the result to the given output range.
function limit(num: number, min: number, max: number, outMin: number, outMax: number): number;
create
creates a single argument function implementing the given map
, floor
, round
or limit
function, useful when you need to map values multiple times with the same arguments, see example
function create(func: MapFunction, min: number, max: number, outMin: number, outMax: number): (num: number) => number;
example
const myMap = create(map, -1, 1, 0, 10);
myMap(0.5);
// ... is equivalent to...
map(0.5, -1, 1, 0, 10);