This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 400,000 packages pre-installed, including
scale-number with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
Let's you map a number from a range to another.
Current status: Alpha, API might change until 1.0.0
Returns a scaling function from an input range to an output range.
Ranges are expressed with arrays.
var scaleNumber = require('scale-numbers') var scale = scaleNumber.createLinearScale([10, 20], [100, 200]) var number = scale(15) console.log(number) // 150
If the value is out of the entry range, it will be mapped to the lowest or greatest value. (this behaviour might be available as an option later)
var scale = scaleNumber.createLinearScale([10, 20], [100, 200]) var number = scale(5) console.log(number) // 100
This project gets its inspiration from d3 scale.
I needed this functionality as stand alone.