JSPM

postcss

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 80032996
  • Score
    100M100P100Q231066F
  • License MIT

Framework for CSS postprocessors

Package Exports

  • postcss
  • postcss/lib/at-rule
  • postcss/lib/container
  • postcss/lib/declaration
  • postcss/lib/list
  • postcss/lib/node
  • postcss/lib/parse
  • postcss/lib/postcss
  • postcss/lib/root
  • postcss/lib/rule
  • postcss/lib/vendor
  • postcss/package.json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (postcss) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PostCSS

PostCSS is a framework for CSS postprocessors. You get a custom JS function to modify CSS, and PostCSS parses CSS, gives you usable JS API to edit CSS node tree and then save modified node tree to new CSS.

For example, let's fix forgotten content propery in ::before and ::after:

var postcss = require('postcss');

var postprocessor = postcss(function (css) {
    css.eachRule(function (rule) {
        if ( rule.selector.match(/::(before|after)/) ) {

            var good = rule.some(function (i) {
                return i.prop == 'content';
            });
            if ( !good ) {
                rule.prepend({ prop: 'content', value: '""' });
            }

        }
    });
});

And then CSS with forgotten content:

a::before {
    width: 10px;
    height: 10px;
    background: black
}

will be fixed by our new postprocessor:

var fixed = postprocessor.process(css);

to:

a::before {
    content: "";
    width: 10px;
    height: 10px;
    background: black
}

Sponsored by Evil Martians.

Features

Preserves code formatting and indentations

PostCSS saves all spaces if you don’t change CSS node and try to copy your coding style if you modify it.

Parses everything

In addition to the unit tests, PostCSS has integration tests to check CSS parser on real-world sites. Right now parser is tested on GitHub, Twitter, Bootstrap and Habrahabr styles.

Also PostCSS parser is very flexible and, for example, can parse any custom or future at-rules, instead of built-in list.

High-level API

PostCSS is not only parser and stringifier. It contains useful tools, which can be used in most of postprocessor:

  1. Safe iterator, which allow to change list inside iteration.
  2. Module to split value list by spaces or commas.