Skip to content

Scrum/postcss-attribute-selector-prefix

Repository files navigation

postcss-attribute-selector-prefix

PostCSS plugin adds a namespace/prefix to attribute selector.

Travis Build StatusAppVeyor Build Statustesten badgenodenpm versionDependency StatusXO code styleCoveralls status

npm downloadsnpmGreenkeeper badge

Why ?

Needs to escape from the third-party frameworks.

Install

$ npm install postcss-attribute-selector-prefix 

Note: This project is compatible with node v4+

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; 
}

LICENSE

MIT License (MIT)

Copyright (c) Ivan Demidov scrum@list.ru

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,