Coder Social home page Coder Social logo

postcss-filter-plugins's Introduction

postcss-filter-plugins Build Status

Exclude/warn on duplicated PostCSS plugins.

Install

With npm do:

$ npm install postcss-filter-plugins --save

Example

Note that this plugin does not actually transform your CSS; instead, it ensures that plugins in the PostCSS instance are not duplicated. It is intended to be used by plugin packs such as cssnano or cssnext.

var counter = postcss.plugin('counter', function () {
    return function (css) {
        css.eachDecl('foo', function (decl) {
            let value = parseInt(decl.value, 10);
            value += 1;
            decl.value = String(value);
        });
    }
});

var css = 'h1 { foo: 1 }';
var out = postcss([
    filter(),
    counter(),
    counter()
]).process(css).css;

console.log(out);
// => h1 { foo: 2 }
// Note that you will get a PostCSS warning in the message registry

API

filterPlugins([options])

options

direction

Type: string
Default: 'both'

Pass 'forward', 'backward', or 'both' to customise the direction in which the plugin will look in the plugins array. See the tests for examples on how this works.

postcss([ filter({
    direction: 'forward'
}) ]).process(css).css);
exclude

Type: array
Default: [] (empty)

Plugins that should be excluded from the filter. Pass an array of plugin names.

postcss([ filter({
    exclude: ['postcss-cssstats']
}) ]).process(css).css);
silent

Type: boolean
Default: false

Set this to true to disable the plugin from emitting any PostCSS warnings.

postcss([ filter({
    silent: true
}) ]).process(css).css);
template

Type: function
Default: format function

This function will be passed each PostCSS plugin object. You are expected to return a string from each call, which is then used to warn the user about her duplicated plugins.

postcss([ filter({
    template: function (plugin) {
        return 'Duplicate plugin found: ' + plugin.postcssPlugin;
    }
}) ]).process(css).css);

Usage

See the PostCSS documentation for examples for your environment.

Contributors

Thanks goes to these wonderful people (emoji key):


Ben Briggs

๐Ÿ’ป ๐Ÿ“– ๐Ÿ‘€ โš ๏ธ

Maxime Thirouin

๐Ÿ“–

Andreas Lind

๐Ÿ’ป

Ryan Zimmerman

๐Ÿ’ป

James Hunt

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT ยฉ Ben Briggs

postcss-filter-plugins's People

Contributors

ben-eb avatar greenkeeperio-bot avatar jamescodes avatar moox avatar papandreou avatar ryanzim avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.