unit-to-px
v1.0.5
Published
Convert any CSS unit (pt, em, rem, pc, in, mm, cm, vw...) to px, in browser
Downloads
961
Readme
Unit To Px
Convert any CSS unit (pt, em, rem, pc, in, mm, cm, vw...) to px, in browser
Install
NPM
npm install -S unit-to-px
UNPKG
http://unpkg.com/unit-to-px
Usage
Only one top level API: fn (cssLength: string) -> px: Number
1. Caculate px per unit
const toPx = require('unit-to-px')
console.log(toPx('mm')) //3.779375
console.log(toPx('rem')) //16
console.log(toPx('em')) //14
console.log(toPx('in')) //96
console.log(toPx('vh')) //2.48
console.log(toPx('??')) //0 -> unknown unit always be 0!
2. Convert px of length
const toPx = require('unit-to-px')
console.log(toPx('210mm')) //793.6687499999999
console.log(toPx('- 210 m m')) //throw TypeError: Error parsing length