Skip to content

PostCSS plugin to filter declarations by property names

License

Notifications You must be signed in to change notification settings

shinnn/postcss-filter-declarations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postcss-filter-declarations

npm version Build Status Coverage Status

A PostCSS plugin to filter declarations by property names

var fs = require('fs');

var postcss = require('postcss');
var filterDeclarations = require('postcss-filter-declarations');

postcss()
  .use(filterDeclarations({props: ['display', 'color']}))
  .process(fs.readFileSync('path/to/css/file'))
  .css;
.menubar {
  display: block;
  position: fixed;
  color: gray;
}

@media print {
  h1 {
    font-size: 16px;
  }

  a {
    color: blue;
  }
}

.menubar {
  display: block;
  color: gray;
}
@media print {
  h1 {
  }

  a {
    color: blue;
  }
}

Installation

Use npm.

npm install postcss-filter-declarations

API

var filterDeclarations = require('postcss-filter-declarations');

filterDeclarations([options])

options: Object
Return: Function

options.properties

(alias: options.props)

Type: Stirng or Array of String
Default: []

Removes all CSS declarations except for the proerties specified by this option.

postcss()
  .use(filterDeclarations({
    props: 'color'
  }))
  .process('a {color: red;} b {background: blue;}')
  .css; //=> 'a {color: red;} b {}'

options.exclude

Type: Boolean
Defult: false

true inverts the filtering result.

postcss()
  .use(filterDeclarations({
    props: 'color',
    exclude: true
  }))
  .process('a {color: red;} b {background: blue;}')
  .css; //=> 'a {} b {background: blue;}'

License

Copyright (c) 2014 - 2019 Shinnosuke Watanabe

Licensed under the MIT License.

About

PostCSS plugin to filter declarations by property names

Resources

License

Stars

Watchers

Forks

Packages

No packages published