JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 252
  • Score
    100M100P100Q81849F
  • License MIT

processing/p5.js map like function, including floating point numbers support

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

CircleCI Greenkeeper badge npm jsdelivr dependencies Status devDependencies Status install size npm bundle size npm type definitions codecov Known Vulnerabilities GitHub

processing / p5.js map like function, including floating point numbers support.

⚠️ this map function has nothing to do with Array.prototype.map method.

Install

npm i map-number

CDN

jsDelivr

www.jsdelivr.com

<script src="https://cdn.jsdelivr.net/npm/map-number@latest/dist/map.umd.js"></script>
for production
<script src="https://cdn.jsdelivr.net/npm/map-number@latest/dist/map.umd.min.js"></script>

more options...

unpkg

unpkg.com

<script src="https://unpkg.com/map-number@latest/dist/map.umd.js"></script>
for production
<script src="https://unpkg.com/map-number@latest/dist/map.umd.min.js"></script>

more options...

Usage

Node.js

const mapNum = require("map-number");
const y = mapNum.map(Math.sin(angle), -1, 1, 100, 0);

Browser

After the script tag has been added, mapNum will be available globally.

const y = mapNum.map(Math.sin(angle), -1, 1, 100, 0);

API

map

Maps a number in a range to a different range, returning a floting point number. The result is not limited to the the given output range.

This is the core function and all other map function variants depend on it.

syntax
function map(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number;

floor

Maps a number in a range to a different range, returning a number rounded down to the previous integer number. The result is not limited to the the given output range.

syntax
function floor(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number;

ceil

Maps a number in a range to a different range, returning a number rounded up to the next integer number. The result is not blimitedto the the given output range.

syntax
function ceil(num: number, inMin: number, inMax: 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. The result is not blimitedto the the given output range.

syntax
function round(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number;

limit

Maps a number in a range to a different range, returning a floting point number. The result will be bounded to the given output range.

syntax
function limit(num: number, inMin: number, inMax: number, outMin: number, outMax: number): number;

wrap

Creates a single argument function implementing the given map, floor, ceil, round or limit function. Useful when you need to map values multiple times within the same range, see example.

syntax
function wrap(func: MapFunction, inMin: number, inMax: number, outMin: number, outMax: number): (num: number) => number;
example
import { map, wrap } from "map-number";

const myMap = wrap(map, -1, 1, 100, 0);

myMap(-0.2);
myMap(0.33);

// ... is equivalent to...

map(-0.2, -1, 1, 100, 0);
map(0.33, -1, 1, 100, 0);

create

An alias for wrap method, deprecated in version 1.2.0, use wrap instead.

License

MIT © Manuel Fernández