# strip-css-comments

> Strip comments from CSS

Latest version **5.0.0** (published 2021-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install strip-css-comments
pnpm add strip-css-comments
yarn add strip-css-comments
bun add strip-css-comments
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2021-08-21 |
| First published | 2014-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 1 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 122 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | css, style, stylesheet, strip, remove, delete, trim, comments, preprocess, transform, string |

## Links

- npm: https://www.npmjs.com/package/strip-css-comments
- Repository: https://github.com/sindresorhus/strip-css-comments
- Homepage: https://github.com/sindresorhus/strip-css-comments#readme
- Issues: https://github.com/sindresorhus/strip-css-comments/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/strip-css-comments

## Dependencies (1)

- [is-regexp](https://npm.io/package/is-regexp.md) ^3.0.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

- 5.0.0 (latest) — 2021-08-21
- 4.1.0 — 2019-11-17
- 4.0.0 — 2019-04-30
- 3.0.0 — 2015-08-10
- 2.1.0 — 2015-08-10
- 2.0.2 — 2015-03-14
- 2.0.1 — 2015-02-16
- 2.0.0 — 2015-01-12
- 1.0.1 — 2014-10-24
- 1.0.0 — 2014-10-22

## README

# strip-css-comments

> Strip comments from CSS

Also available as a [Gulp](https://github.com/sindresorhus/gulp-strip-css-comments)/[Grunt](https://github.com/sindresorhus/grunt-strip-css-comments)/[Broccoli](https://github.com/sindresorhus/broccoli-strip-css-comments) plugin.

## Usage

```
$ npm install strip-css-comments
```

## Usage

```js
import stripCssComments from 'strip-css-comments';

// By default important comments `/*!` are preserved
stripCssComments('/*! <copyright> */ body { /* unicorns */color: hotpink; }');
//=> '/*! <copyright> */ body { color: hotpink; }'

// `preserve: false` will strip all comments including `/*!`
stripCssComments(
	'/*! <copyright> */ body { /* unicorns */color: hotpink; }',
	{preserve: false}
);
//=> 'body { color: hotpink; }'

// Preserve comments based on a regex
stripCssComments(
	'/*# preserved */ body { /* unicorns */color: hotpink; }',
	{preserve: /^#/}
);
//=> '/*# preserved */ body { color: hotpink; }'

// Preserve comments based on the return value of the supplied function
stripCssComments(
	'/*# preserved */ body { /* unicorns */color: hotpink; }',
	{
		preserve: comment => comment.charAt(0) === '#'
	}
);
//=> '/*# preserved */ body { color: hotpink; }'
```

## API

### stripCssComments(cssString, options?)

## cssString

Type: `string`

String with CSS.

## options

Type: `object`

### preserve

Type: `boolean | RegExp | Function`\
Default: `true`

- `true` - Preserve important comments `/*! */`.
- `false` - Strip all comments.
- `RegExp` - Preserve comments where the comment body matches a regular expression.
- `Function` - Preserve comments for which a function returns `true`. The function is called on each comment, gets the comment body as the first argument, and is expected to return a boolean of whether to preserve the comment.

### whitespace

Type: `boolean`\
Default: `true`

Replace comments with whitespace instead of stripping them entirely.

## Benchmark

```
$ npm run bench
```

## Related

- [strip-css-comments-cli](https://github.com/sindresorhus/strip-css-comments-cli) - CLI for this module
- [strip-json-comments](https://github.com/sindresorhus/strip-json-comments) - Strip comments from JSON

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