# postcss-sanitize

> PostCSS plugin that removes properties and values based on options (think like a CSS sanitizer)

Latest version **0.0.9** (published 2021-08-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install postcss-sanitize
pnpm add postcss-sanitize
yarn add postcss-sanitize
bun add postcss-sanitize
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2021-08-14 |
| First published | 2016-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Damien Erambert |
| Maintainers | eramdam |
| Keywords | postcss, css, postcss-plugin, sanitizer |

## Links

- npm: https://www.npmjs.com/package/postcss-sanitize
- Repository: https://github.com/eramdam/postcss-sanitize
- Issues: https://github.com/eramdam/postcss-sanitize/issues
- npm.io page: https://npm.io/package/postcss-sanitize

## Dependencies (2)

- [lodash.isregexp](https://npm.io/package/lodash.isregexp.md) ^4.0.1
- [postcss-value-parser](https://npm.io/package/postcss-value-parser.md) ^4.1.0

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2021-08-14
- 0.0.7 — 2017-02-09
- 0.0.6 — 2016-05-19
- 0.0.5 — 2016-04-24
- 0.0.4 — 2016-04-24

## README

# PostCSS Sanitize [![Build Status][ci-img]][ci] [![David](https://img.shields.io/david/eramdam/postcss-sanitize.svg)]()

[![npm](https://img.shields.io/npm/v/postcss-sanitize.svg)](https://www.npmjs.com/package/postcss-sanitize)
[![npm](https://img.shields.io/npm/l/postcss-sanitize.svg)](https://www.npmjs.com/package/postcss-sanitize)

[PostCSS] plugin that removes properties and values based on options (think like a CSS sanitizer).


## Installation

```bash
npm install postcss-sanitize
```

## Usage

Let's say you want to do the following things:
+ Remove Comic Sans as a font from your CSS
+ Disallow `position: absolute` or `position: relative`

Options:
```js
removeEmpty: true,
allowedSchemes: ['http', 'https']
rules: [{
  prop: /font/gi,
  value: /Comic Sans/gi
}, {
  prop: 'position',
  value: /relative|absolute/
}]
```

Input:
```css
@import(ssh://foobar.host);

.skeleton--Sans {
  color: blue;
  position: absolute;
  font-family: "Comic Sans MS";
}

.the-real-slim-shady-element {
  background-image: url(javascript:alert(42));
}
```

Output:
```css
.skeleton--Sans {
  color: blue;
}

.the-real-slim-shady-element {
  background-image: url();
}
```

## Options

+ `removeEmpty (boolean) (Default: false)`: Decide if you want to CSS rules made empty by the changes
+ `allowedSchemes`: An array of URL schemes you want to allow in your CSS.
+ `rules (array)`: rules
  - `prop (RegExp/string)`: the pattern or the **exact** string you want to match in properties
  - `value (RegExp/string)`: the pattern or the **exact** string you want to match in values
  - **Important** When using both, a property/value couple have to match both the property and the value pattern to be matched and removed.

See [PostCSS] docs for examples for your environment.

## Contribute

You will need at least Node 5.x.

- Fork
- Install the dependencies
- Hack around
- Make sure tests are passing or add some if needed
- Open a pull request :tada:

## License

This project is using the MIT License (see `LICENSE` file for more infos)


[PostCSS]: https://github.com/postcss/postcss
[ci-img]:  https://travis-ci.org/eramdam/postcss-sanitize.svg
[ci]:      https://travis-ci.org/eramdam/postcss-sanitize

---
_Source: https://npm.io/package/postcss-sanitize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
