Skip to content

Repository files navigation

reduce-css-calc

Build Status

Reduce CSS calc() function to the maximum.

Particularly useful for packages like rework-calc or postcss-calc.

Installation

npm install reduce-css-calc

Usage

var reducedString = reduceCSSCalc(string, precision)

varreduceCSSCalc=require("reduce-css-calc");reduceCSSCalc("calc(1 + 1)");// 2reduceCSSCalc("calc((6 / 2) - (4 * 2) + 1)");// -4reduceCSSCalc("calc(1/3)");// 0.33333reduceCSSCalc("calc(1/3)",10);// 0.3333333333reduceCSSCalc("calc(3rem * 2 - 1rem)");// 5remreduceCSSCalc("calc(2 * 50%)");// 100%reduceCSSCalc("calc(120% * 50%)");// 60%reduceCSSCalc("a calc(1 + 1) b calc(1 - 1) c");// a 2 b 0 creduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1rem)");// 0.125remreduceCSSCalc("calc(calc(calc(1rem * 0.75) * 1.5) - 1px)");// calc(1.125rem - 1px)reduceCSSCalc("-moz-calc(100px / 2)");// 50pxreduceCSSCalc("-moz-calc(50% - 2em)");// -moz-calc(50% - 2em)

See unit tests for others examples.


Contributing

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

git clone https://github.com/MoOx/reduce-css-calc.gitgit checkout -b patch-1npm installnpm test

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

About

Reduce CSS calc() function at the maximum

Resources

Code of conduct

Contributing

Stars

56 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages