postcss-attribute-selector-prefix
v0.1.1
Published
A attribute selector prefixer for postcss
Downloads
5
Maintainers
Readme
postcss-attribute-selector-prefix
PostCSS plugin adds a namespace/prefix to attribute selector.
Why ?
Needs to escape from the third-party frameworks.
Install
$ npm install postcss-attribute-selector-prefix
Note: This project is compatible with node v6+
Usage
// Dependencies
var fs = require('fs');
var postcss = require('postcss');
var attrSelectorPrefix = require('postcss-attribute-selector-prefix');
// CSS to be processed
var css = fs.readFileSync('css/input.css', 'utf8');
// Process css
var output = postcss()
.use(attrSelectorPrefix({prefix: 'test-'}))
.process(css)
.css;
console.log(output);
Example
/* input.css */
.class,
[type="text"],
[class*="lorem"] {
color:red;
}
/* Output example */
.class,
[type="text"],
[class*="test-lorem"] {
color:red;
}
Options
prefix
Type: string
Default: ``
Description: add prefix to attribute selector
filter
Type: Array
Default: []
Description: attribute selector to which we must add the prefix
Example: ['class', 'id']
/* input.css */
.class,
[type="text"],
[class*="lorem"],
[id^="myID"] {
color: red;
}
/* Output example */
.class,
[type="text"],
[class*="test-lorem"],
[id^="test-myID"] {
color: red;
}
ignore
Type: Array
Default: []
Description: ignored attribute selector
Example: ['type', 'alt']
/* input.css */
.class,
[type="text"],
[alt*="ALT"],
[class*="class"] {
color: red;
}
/* Output example */
.class,
[type="text"],
[alt*="ALT"],
[class*="test-class"] {
color: red;
}