# parse-css-dimension

> Parse a CSS dimension (i.e., number, length, percentage) into a JavaScript object.

Latest version **1.1.0** (published 2016-08-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-css-dimension
pnpm add parse-css-dimension
yarn add parse-css-dimension
bun add parse-css-dimension
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-08-17 |
| First published | 2015-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jed Mao |
| Maintainers | jedmao |
| Keywords | parse, css, dimension, number, length, percentage, unit, object |

## Links

- npm: https://www.npmjs.com/package/parse-css-dimension
- Repository: https://github.com/jedmao/parse-css-dimension
- Homepage: https://github.com/jedmao/parse-css-dimension#readme
- Issues: https://github.com/jedmao/parse-css-dimension/issues
- npm.io page: https://npm.io/package/parse-css-dimension

## Dependencies (8)

- [lodash.fill](https://npm.io/package/lodash.fill.md) ^3.4.0
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.0
- [css-time-units](https://npm.io/package/css-time-units.md) ^1.0.1
- [css-angle-units](https://npm.io/package/css-angle-units.md) ^1.0.1
- [css-length-units](https://npm.io/package/css-length-units.md) ^1.0.0
- [lodash.zipobject](https://npm.io/package/lodash.zipobject.md) ^4.1.3
- [css-frequency-units](https://npm.io/package/css-frequency-units.md) ^1.0.1
- [css-resolution-units](https://npm.io/package/css-resolution-units.md) ^1.0.1

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2016-08-17
- 1.0.1 — 2015-10-06
- 1.0.0 — 2015-10-06

## README

# parse-css-dimension

[![NPM version](http://img.shields.io/npm/v/parse-css-dimension.svg?style=flat)](https://www.npmjs.org/package/parse-css-dimension)
[![npm license](http://img.shields.io/npm/l/parse-css-dimension.svg?style=flat-square)](https://www.npmjs.org/package/parse-css-dimension)
[![Travis Build Status](https://img.shields.io/travis/jedmao/parse-css-dimension.svg?label=unix)](https://travis-ci.org/jedmao/parse-css-dimension)

[![npm](https://nodei.co/npm/parse-css-dimension.svg?downloads=true)](https://nodei.co/npm/parse-css-dimension/)

Parse a CSS dimension (i.e., [`<number>`](https://developer.mozilla.org/en-US/docs/Web/CSS/number), [`<length>`](https://developer.mozilla.org/en-US/docs/Web/CSS/length), [`<percentage>`](https://developer.mozilla.org/en-US/docs/Web/CSS/percentage), [`<angle>`](https://developer.mozilla.org/en-US/docs/Web/CSS/angle), [`<resolution>`](https://developer.mozilla.org/en-US/docs/Web/CSS/resolution), [`<frequency>`](https://developer.mozilla.org/en-US/docs/Web/CSS/frequency), [`<time>`](https://developer.mozilla.org/en-US/docs/Web/CSS/time)) into a JavaScript object.

## Installation

```
$ npm install parse-css-dimension [--save[-dev]]
```

## Usage

```js
var parseCssDimension = require('parse-css-dimension');
parseCssDimension('-3.4e-2');  // { [Number: -0.034] type: 'number', value: -0.034 }
parseCssDimension('42em');     // { [Number: 42] type: 'length', value: 42, unit: 'em' }
parseCssDimension('42deg');    // { [Number: 42] type: 'angle', value: 42, unit: 'deg' }
parseCssDimension('42dpi');    // { [Number: 42] type: 'resolution', value: 42, unit: 'dpi' }
parseCssDimension('42Hz');     // { [Number: 42] type: 'frequency', value: 42, unit: 'Hz' }
parseCssDimension('42ms');     // { [Number: 42] type: 'time', value: 42, unit: 'ms' }
parseCssDimension('42%');      // { [Number: 42] type: 'percentage', value: 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.

```js
var result = parseCssDimension('42%');
result instanceof parseCssDimension.CssDimension; // true
result.toString(); // 42%
result + 3; // 45
```

## Testing

```
$ npm test
```

This will run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.

---
_Source: https://npm.io/package/parse-css-dimension · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
