Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/postcss-filter-declarations
PostCSS plugin to filter declarations by property names
https://github.com/shinnn/postcss-filter-declarations
Last synced: 27 days ago
JSON representation
PostCSS plugin to filter declarations by property names
- Host: GitHub
- URL: https://github.com/shinnn/postcss-filter-declarations
- Owner: shinnn
- License: mit
- Created: 2014-10-23T02:26:02.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-01-08T18:11:53.000Z (almost 6 years ago)
- Last Synced: 2024-10-04T00:47:37.618Z (about 1 month ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# postcss-filter-declarations
[![npm version](https://img.shields.io/npm/v/postcss-filter-declarations.svg)](https://www.npmjs.com/package/postcss-filter-declarations)
[![Build Status](https://travis-ci.com/shinnn/postcss-filter-declarations.svg?branch=master)](https://travis-ci.com/shinnn/postcss-filter-declarations)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/postcss-filter-declarations.svg)](https://coveralls.io/github/shinnn/postcss-filter-declarations)A [PostCSS](https://github.com/postcss/postcss) plugin to filter declarations by property names
```javascript
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;
``````css
.menubar {
display: block;
position: fixed;
color: gray;
}@media print {
h1 {
font-size: 16px;
}a {
color: blue;
}
}
```↓
```css
.menubar {
display: block;
color: gray;
}
@media print {
h1 {
}a {
color: blue;
}
}
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install postcss-filter-declarations
```## API
```javascript
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](https://github.com/postcss/postcss/blob/master/API.md#declaration-node) except for the proerties specified by this option.
```javascript
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.
```javascript
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](https://github.com/shinnn)
Licensed under [the MIT License](./LICENSE).