CSS Convert Units is a library for convert css unit to another unit.
Use the npm
or yarn
to install dependencies.
$ npm i css-convert-units
or
$ yarn add css-convert-units
Here is a description of an imaginary function convertUnit :
convertUnit(convertFrom, [convertTo], [dpi])
- density independen pixel (dp)
- pixel (px)
- scale independen pixel (sp)
- millimeter (mm)
- inch (in)
- point (pt)
- remme (rem)
convertTo
& dpi
are optional parameters, convertTo
will be filled by default with rem and
dpi
will be default with mdpi.
check ./index.js
file:
let convertUnit = require('css-convert-units')
Code Examples:
convertUnit('1pt', 'px', 'mdpi') // output : 2.22px
convertUnit('1pt', 'px') // output : 2.22px
convertUnit('1px', 'rem', 'mdpi') // output : 0.0625rem
convertUnit('1px', 'rem') // output : 0.0625rem (mdpi is default dpi)
convertUnit('1px') // output : 0.0625rem (rem is default unit)
Dwi Agustianto - @agusID
See also the list of contributors who participated in this project.