
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
postcss-calc
Advanced tools

A PostCSS plugin to reduce calc() usage.
Particularly useful with the postcss-custom-properties
npm install postcss-calc
var postcss = require("postcss")
var calc = require("postcss-calc")
var css = postcss()
.use(calc())
.process(cssString)
.css
This reduce calc() references whenever it's possible.
This can be particularly useful with the postcss-custom-properties plugin.
Note: When multiple units are mixed together in the same expression, the calc() statement is left as is, to fallback to the w3c calc() feature.
Example (with postcss-custom-properties enabled as well):
// dependencies
var fs = require("fs")
var postcss = require("postcss")
var customProperties = require("postcss-custom-properties")
var calc = require("postcss-calc")
// css to be processed
var css = fs.readFileSync("style.css", "utf8")
var output = postcss()
.use(customProperties())
.use(calc())
.process(css)
.css
:root {
--main-font-size: 16px;
}
body {
font-size: var(--main-font-size);
}
h1 {
font-size: calc(var(--main-font-size) * 2);
height: calc(100px - 2em);
}
yields:
body {
font-size: 16px
}
h1 {
font-size: 32px;
height: calc(100px - 2em)
}
See unit tests for a better example.
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/postcss/postcss-calc.git
git checkout -b patch-1
npm install
npm test
cssnano is a modular CSS minifier that includes functionalities similar to postcss-calc as part of its optimizations. It uses PostCSS to analyze and rewrite CSS files, reducing their size. While cssnano includes a broader range of optimizations, postcss-calc focuses specifically on the optimization of calc() functions.
postcss-custom-properties is another PostCSS plugin that allows you to use CSS custom properties (variables) in your stylesheets. It can transform these properties into static values, similar to how postcss-calc simplifies calc() expressions. However, it focuses on variables rather than calculations.
FAQs
PostCSS plugin to reduce calc()
The npm package postcss-calc receives a total of 5,620,889 weekly downloads. As such, postcss-calc popularity was classified as popular.
We found that postcss-calc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.