# to-px

> Convert any CSS unit to logical pixels ("px")

Latest version **1.1.0** (published 2018-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-px
pnpm add to-px
yarn add to-px
bun add to-px
```

## 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.1.0 |
| Published | 2018-11-19 |
| First published | 2015-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/to-px) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko |
| Keywords | css, px, em, ex, line, height, ch, rem, vh, vw, vmin, vmax, unit, conversion, scale, factor |

## Links

- npm: https://www.npmjs.com/package/to-px
- Repository: https://github.com/mikolalysenko/to-px
- Issues: https://github.com/mikolalysenko/to-px/issues
- npm.io page: https://npm.io/package/to-px

## Dependencies (1)

- [parse-unit](https://npm.io/package/parse-unit.md) ^1.0.1

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-11-19
- 1.0.1 — 2015-02-17
- 1.0.0 — 2015-02-17

## README

to-px
=====
Get the scale factor to convert any CSS unit to `px` (logical pixel units).

[![testling badge](https://ci.testling.com/mikolalysenko/to-px.png)](https://ci.testling.com/mikolalysenko/to-px)

# Example

```javascript
var toPX = require('to-px')

console.log(toPX('1em'))
console.log(toPX('.23vh'))
console.log(toPX('in'))
```

# Install

Note that this module only works within the DOM.

```
npm i to-px
```

# API

#### `var scaleFactor = require('to-px')(unit[, element])`

Computes the number of pixels in the `unit` string.

* `unit` is a CSS unit type or a number followed by CSS unit, eg `vh` or `2in`
* `element` is an optional element in which the unit is computed (default is `document.body`)

**Returns** The number of pixels in the `unit`

**Note** Conversions for `%` are not supported since they are context dependent.

# License
(c) 2015 Mikola Lysenko. MIT License

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