ES6 Length Unit Converter – convert-length

Category: Javascript | August 10, 2018
Author:mattdesl
Views Total:307 views
Official Page:Go to website
Last Update:August 10, 2018
License:MIT

Preview:

ES6 Length Unit Converter – convert-length

Description:

convert-length is a fast length unit convert written in ES6 that makes it easy to convert between length units such as mm, cm, m, pc, pt, in, ft, px.

How to use it:

Install the convert-length with NPM.

# NPM
$ npm install convert-length --save

Import & initialize the convert-length.

const convert = require('convert-length');

The syntax to convert length unit to another:

result = convert(value, fromUnit, toUnit, options)

Available options with default values.

{
 
  // the number of pixels in one inch
  // used when converting to and from "px" units
  pixelsPerInch: 96,
  // precision: 3 will round to 0.001
  precision: null,
  //  If enabled, when converting to a "px" unit the return value will be rounded to a whole pixel. 
  // If disabled, the conversion will instead round to the specified Nth precision decimal (or no rounding if precision is not specified).
  roundPixel: false
}

You Might Be Interested In:


Leave a Reply