Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/castastrophe/postcss-transform-selectors

A postcss plugin to remap and transform selectors.
https://github.com/castastrophe/postcss-transform-selectors

Last synced: about 1 month ago
JSON representation

A postcss plugin to remap and transform selectors.

Awesome Lists containing this project

README

        

# postcss-transformselectors
> Re-map and transform selectors

## Installation

```sh
npm install postcss-transformselectors
```

## Usage

In your `postcss.config.js`, pass `options` to the plugin:

```js
module.exports = {
plugins: [
require('postcss-transformselectors')({
replace: [
// replace all instaces of .button in a selector with .btn (will catch .button:hover)
// when search is a string, replaces are automatically made global
{ search: '.button', replace: '.btn' },
// replace all double dashes in classnames with an underscore
// note the g flag (global) is used to ensure every instance in a selector is replaced
{ search: /\.(.*?)--([^ ]*?)/g, replace: '.$1_$2' },
],
// lowercase all classnames
// you can use the PostCSS Rule object to determine the new selector (i.e. based off rule.parent)
transform: (selector, rule) => selector.toLowerCase()
}),
],
};
````

### `options.replace`

An array of objects with `{ search: RegExp | string, replace: string }`.

### `options.transform`

A function that takes `(selector, rule)` and returns a new selector.