# fela-plugin-unit

> Fela plugin to automatically add units if required

Latest version **12.2.1** (published 2022-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install fela-plugin-unit
pnpm add fela-plugin-unit
yarn add fela-plugin-unit
bun add fela-plugin-unit
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 12.2.1 |
| Published | 2022-11-16 |
| First published | 2016-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2281 |
| Author | Robin Weser |
| Maintainers | rofrischmann, txhawks |
| Keywords | fela, fela-plugin, cssinjs |

## Links

- npm: https://www.npmjs.com/package/fela-plugin-unit
- Repository: https://github.com/robinweser/fela
- Homepage: https://github.com/robinweser/fela#readme
- Issues: https://github.com/robinweser/fela/issues
- npm.io page: https://npm.io/package/fela-plugin-unit

## Dependencies (2)

- [isobject](https://npm.io/package/isobject.md) ^4.0.0
- [css-in-js-utils](https://npm.io/package/css-in-js-utils.md) ^3.0.0

## Recent versions

- 12.2.1 (latest) — 2022-11-16
- 12.0.0-rc.3.0 (next) — 2022-02-22
- 12.2.0 — 2022-07-06
- 12.1.2 — 2022-05-04
- 12.1.1 — 2022-04-07
- 12.1.0 — 2022-04-06
- 12.0.2 — 2022-02-23
- 12.0.1 — 2022-02-23
- 12.0.0 — 2022-02-23
- 12.0.0-y.0 — 2022-02-22
- 12.0.0-rc.2 — 2022-02-21
- 12.0.0-rc.1 — 2022-02-18
- 12.0.0-rc.0 — 2022-02-16
- 11.7.0 — 2021-09-24
- 11.6.1 — 2021-03-25
- … 96 more at https://npm.io/package/fela-plugin-unit/versions

## README

# fela-plugin-unit

<img alt="npm version" src="https://badge.fury.io/js/fela-plugin-unit.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/fela-plugin-unit.svg"> <a href="https://bundlephobia.com/result?p=fela-plugin-unit@latest"><img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/fela-plugin-unit.svg"></a>

Always writing length values as string with a value applied seems not like the JavaScript way to do it. You can also use mathematics to process number values. <br>
It is aware of unitless properties such as `lineHeight`, zero-values and also adds units to multiple values inside an array.

## Installation

```sh
yarn add fela-plugin-unit
```

You may alternatively use `npm i --save fela-plugin-unit`.

## Usage

Make sure to read the documentation on [how to use plugins](https://fela.js.org/docs/latest/advanced/plugins#using-plugins).

```javascript
import { createRenderer } from 'fela'
import unit from 'fela-plugin-unit'

const renderer = createRenderer({
  plugins: [unit()],
})
```

### Configuration

##### Parameters

|  Parameter         | Value                                                                                            | Default                                                                                                    | Description                                   |
| ------------------ | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| unit               | `ch`, `em`, `ex`, `rem`, `vh`, `vw`, `vmin`, `vmax`, `px`, `cm`, `mm`, `in`, `pc`, `pt`, `mozmm` |  `px`                                                                                                      | unit which gets applied                       |
| unitPerProperty    |  *(Object)*                                                                                      | `{}`                                                                                                       |  Default units per property                   |
| isUnitlessProperty | _(Function)_                                                                                     | [`util function`](https://github.com/robinweser/css-in-js-utils/blob/master/modules/isUnitlessProperty.js) | check whether property should remain unitless |

##### Example

```javascript
import { createRenderer } from 'fela'
import unit from 'fela-plugin-unit'

const unitPlugin = unit('em', {
  margin: '%',
  fontSize: 'pt',
})

const renderer = createRenderer({
  plugins: [unitPlugin],
})
```

## Example

Using the above example code:

#### Input

```javascript
{
  marginTop: 0,
  width: 25,
  lineHeight: 1.4,
  height: '53',
  fontSize: 15,
  margin: 10
}
```

#### Output

```javascript
{
  marginTop: 0,
  width: '25em',
  lineHeight: 1.4,
  height: '53em',
  fontSize: '15pt',
  margin: '10%'
}
```

## License

Fela is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br>
Documentation is licensed under [Creative Commons License](http://creativecommons.org/licenses/by/4.0/).<br>
Created with ♥ by [@robinweser](http://weser.io) and all the great contributors.

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