JSPM

  • Created
  • Published
  • Downloads 225
  • Score
    100M100P100Q61583F
  • License MIT

Linear converter

Package Exports

  • linear-converter

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 (linear-converter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

linear-converter

Build Status Coverage Status Code Climate

Flexible linear converter with built in conversions for common units

Install

npm i linear-converter

Basic usage

var lc = require('linear-converter');

lc.convert(25, lc.PRESETS.temperature.celsiusToFahrenheit); // => 77

Custom conversions

Custom conversions are easily achieved by passing an array with 2 scales, each of those an array with 2 values. For example, [[0, 1], [0, 2]] means that 0 and 1 in the first scale map to 0 and 2 in the second scale respectively; in short, it multiplies by 2. Any linear function can be described that way:

// f(x) = ax + b
lc.convert(x, [[0, 1], [b, a + b]]); // => ax + b
lc.convert(x, [[Math.sqrt(a), -b/a], [b, 0]]); // => ax + b

More examples:

// degrees to radians
lc.convert(240, [[0, 180], [0, Math.Pi]]); // => 4 * Math.PI / 3

// f(x) = 3x
lc.convert(5, [[0, 1/3], [0, 1]]); // => 15

// f(x) = -2x - 46
lc.convert(-23, [[0, 1], [-46, -48]]); // => 0

See more