parse-css-dimension
Parse a CSS dimension (i.e., <number>
, <length>
, <percentage>
, <angle>
, <resolution>
, <frequency>
, <time>
) into a JavaScript object.
Installation
$ npm install parse-css-dimension [--save[-dev]]
Usage
var parseCssDimension = require('parse-css-dimension');
parseCssDimension('-3.4e-2');
parseCssDimension('42em');
parseCssDimension('42deg');
parseCssDimension('42dpi');
parseCssDimension('42Hz');
parseCssDimension('42ms');
parseCssDimension('42%');
The result is an instance of CssDimension
, which allows you to stringify it
back into its original form via .toString()
or perform math calculations.
var result = parseCssDimension('42%');
result instanceof parseCssDimension.CssDimension;
result.toString();
result + 3;
Testing
$ npm test
This will run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.