# reduce-css-calc

> Reduce CSS calc() function to the maximum

Latest version **2.1.8** (published 2021-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install reduce-css-calc
pnpm add reduce-css-calc
yarn add reduce-css-calc
bun add reduce-css-calc
```

## 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 | 2.1.8 |
| Published | 2021-01-08 |
| First published | 2014-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 140.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 56 |
| Author | Maxime Thirouin |
| Maintainers | beneb, moox, semigradsky |
| Keywords | css, calculation, calc |

## Links

- npm: https://www.npmjs.com/package/reduce-css-calc
- Repository: https://github.com/MoOx/reduce-css-calc
- Homepage: https://github.com/MoOx/reduce-css-calc#readme
- Issues: https://github.com/MoOx/reduce-css-calc/issues
- npm.io page: https://npm.io/package/reduce-css-calc

## Dependencies (2)

- [css-unit-converter](https://npm.io/package/css-unit-converter.md) ^1.1.1
- [postcss-value-parser](https://npm.io/package/postcss-value-parser.md) ^3.3.0

## 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

- 2.1.8 (latest) — 2021-01-08
- 2.1.7 — 2019-10-22
- 2.1.6 — 2019-01-11
- 2.1.5 — 2018-09-20
- 2.1.4 — 2018-01-22
- 2.1.3 — 2017-11-27
- 2.1.2 — 2017-11-26
- 2.1.1 — 2017-10-12
- 2.1.0 — 2017-10-10
- 2.0.5 — 2017-05-12
- 2.0.4 — 2017-05-09
- 2.0.3 — 2017-05-09
- 2.0.2 — 2017-05-08
- 2.0.1 — 2017-05-08
- 2.0.0 — 2017-05-08
- … 16 more at https://npm.io/package/reduce-css-calc/versions

## README

# reduce-css-calc

[![Build Status](https://travis-ci.org/MoOx/reduce-css-calc.svg)](https://travis-ci.org/MoOx/reduce-css-calc)

> Reduce CSS calc() function to the maximum.

Particularly useful for packages like [rework-calc](https://github.com/reworkcss/rework-calc) or [postcss-calc](https://github.com/postcss/postcss-calc).

## Installation

```console
npm install reduce-css-calc
```

## Usage

### `var reducedString = reduceCSSCalc(string, precision)`

```javascript
var reduceCSSCalc = require('reduce-css-calc')

reduceCSSCalc("calc(1 + 1)")
// 2

reduceCSSCalc("calc((6 / 2) - (4 * 2) + 1)")
// -4

reduceCSSCalc("calc(1/3)")
// 0.33333

reduceCSSCalc("calc(1/3)", 10)
// 0.3333333333

reduceCSSCalc("calc(3rem * 2 - 1rem)")
// 5rem

reduceCSSCalc("calc(2 * 50%)")
// 100%

reduceCSSCalc("calc(120% * 50%)")
// 60%

reduceCSSCalc("a calc(1 + 1) b calc(1 - 1) c")
// a 2 b 0 c

reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)")
// 0.125rem

reduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)")
// calc(1.125rem - 1px)

reduceCSSCalc("-moz-calc(100px / 2)")
// 50px

reduceCSSCalc("-moz-calc(50% - 2em)")
// -moz-calc(50% - 2em)
```

See [unit tests](src/__tests__/index.js) for others examples.

---

## Contributing

Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.

```console
git clone https://github.com/MoOx/reduce-css-calc.git
git checkout -b patch-1
npm install
npm test
```

## [Changelog](CHANGELOG.md)

## [License](LICENSE-MIT)

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