New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

map-number

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-number

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

  • 1.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
608
decreased by-25.4%
Maintainers
1
Weekly downloads
 
Created
Source

map-number

CircleCI Greenkeeper badge npm dependencies Status devDependencies Status npm bundle size codecov Known Vulnerabilities GitHub

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

:warning: this map function has nothing to do with Array.prototype.map method.

Install

npm install map-number

CDN

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

more options on jsDelivr website

unpkg
<script src="https://unpkg.com/map-number/dist/map.umd.js"></script>

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, it may include number outside the given output range.

this is the core function and all other map function variants depend on this 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 truncated to the inmediate previous integer number, it may include number outside the given output range.

syntax
function floor(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, it may include number outside 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 bounded to the given output range.

syntax
function limit(num: number, inMin: number, inMax: 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 within the same range, see example

syntax
function create(func: MapFunction, inMin: number, inMax: number, outMin: number, outMax: number): (num: number) => number;
example
const myMap = create(map, -1, 1, 100, 0);
myMap(Math.sin(angle));
// ... is equivalent to...
map(Math.sin(angle), -1, 1, 100, 0);

wrap

an alias for create method

License

MIT © Manuel Fernández

Keywords

FAQs

Package last updated on 25 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc