# parse-unit

> parses number and unit, '20px' into [20, 'px']

Latest version **1.0.1** (published 2014-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-unit
pnpm add parse-unit
yarn add parse-unit
bun add parse-unit
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-09-22 |
| First published | 2014-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/parse-unit) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | parse, number, string, str, split, unit, in, m, px, %, pt, pc, em, deg, rad, css, value |

## Links

- npm: https://www.npmjs.com/package/parse-unit
- Repository: https://github.com/mattdesl/parse-unit
- Issues: https://github.com/mattdesl/parse-unit/issues
- npm.io page: https://npm.io/package/parse-unit

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2014-09-22
- 1.0.0 — 2014-09-22

## README

# parse-unit

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Parses a number and unit string, eg `"20px"` into `[20, "px"]`. 

```js
var unit = require('parse-unit')

//prints [50, "gold"]
console.log( unit("50 gold") ) 
```

## Usage

[![NPM](https://nodei.co/npm/parse-unit.png)](https://nodei.co/npm/parse-unit/)

#### `parse(str[, out])`

Parses the string and its unit, returning an array containing the number and unit, separated. 

```
"-20 foo" => [-20, "foo"]
"5.5%" => [5.5, "%"]
5 => [5, ""]
"5" => [5, ""]
```

This will create a new array unless you specify an array to `out`, which allows you to re-use arrays. 

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/parse-unit/blob/master/LICENSE.md) for details.

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