Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

postcss-each-decl

jedmao113MIT1.0.2

PostCSS helper method to shallowly iterate over each declaration.

postcss, helpers, each, decl, declaration

readme

postcss-each-decl

NPM version npm license Travis Build Status AppVeyor Build Status

npm

PostCSS helper method to shallowly iterate over each declaration.

Introduction

Ever since PostCSS 5.0, a container method called walkDecls traverses the container's descendant nodes, calling a callback function for each declaration node found. Conversely, this project exposes a simple function that shallowly iterates over a container's direct child nodes, using no recursion.

const rule = postcss.parse(`
    a {
        foo: FOO;
        bar: BAR;
        b {
            baz: BAZ;
        }
        qux: QUX;
`).first;

eachDecl(rule, decl => {
    console.log(decl.prop, decl.value);
});

The above example outputs the following:

foo FOO
bar BAR
qux QUX

Installation

$ npm install postcss-each-decl

Usage

var postcss = require('postcss');
var eachDecl = require('postcss-each-decl');

var rule = postcss.parse('a{foo:bar}').first;
eachDecl(rule, function(decl) {
    console.log(decl.prop, decl.value); // foo bar
});

changelog

1.0.2

  • Fix Node 0.12.

1.0.1

  • Simplify build.

1.0.0

  • Initial release.
  • Supports PostCSS 5.x.