You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

strip-css-comments

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strip-css-comments

Strip comments from CSS

Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
63K
7.78%
Maintainers
1
Weekly downloads
 
Created
Source

strip-css-comments Build Status

Strip comments from CSS

Also available as a gulp/grunt/broccoli plugin.

Usage

$ npm install --save strip-css-comments
var stripCssComments = require('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: function (comment) {
			return comment.charAt(0) === '#';
		}
	}
);
//=> '/*# preserved */ body { color: hotpink; }'

API

stripCssComments(input, [options])

input

Required
Type: string

String with CSS.

options

preserve

Type: boolean, RegExp, function
Default: true

  • true - Preserve comments that use the /*! */ syntax
  • 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.

CLI

$ npm install --global strip-css-comments
$ strip-css-comments --help

  Usage
    $ strip-css-comments <input-file> > <output-file>
    $ strip-css-comments < <input-string>

  Option
    -a, --all  Strip all comments including `/*!`

  Example
    $ strip-css-comments src/app.css > dist/app.css
    $ strip-css-comments < src/app.css --all

Benchmark

$ npm run bench

License

MIT © Sindre Sorhus

Keywords

cli-app

FAQs

Package last updated on 10 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts