Socket
Book a DemoInstallSign in
Socket

postcss-calc

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-calc

Reduce calc() plugin for PostCSS

Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
6.3M
-38.27%
Maintainers
1
Weekly downloads
 
Created
Source

postcss-calc Build Status

A PostCSS plugin to reduce calc() usage.

Particularly useful with the postcss-custom-properties

Installation

npm install postcss-calc

Usage

var postcss = require("postcss")
var calc = require("postcss-calc")

var css = postcss()
  .use(calc())
  .process(cssString)
  .css

Supported feature

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.

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/postcss/postcss-calc.git
git checkout -b patch-1
npm install
npm test

Changelog

License

Keywords

css

FAQs

Package last updated on 06 Aug 2014

Did you know?

Socket

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.

Install

Related posts