Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-discard-comments

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-discard-comments - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

lib/commentParser.js

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# 2.0.1
* Replaces a dependency on node-balanced with internal comments parser.
# 2.0.0

@@ -2,0 +6,0 @@

49

index.js
'use strict';
var balanced = require('node-balanced');
var CommentRemover = require('./lib/commentRemover');
var commentParser = require('./lib/commentParser');
var postcss = require('postcss');

@@ -9,23 +9,28 @@ var space = postcss.list.space;

module.exports = postcss.plugin('postcss-discard-comments', function (options) {
return function (css) {
var remover = new CommentRemover(options || {});
var remover = new CommentRemover(options || {});
function replaceComments (source) {
if (!source) {
return;
function matchesComments (source) {
return commentParser(source).filter(function (node) {
return node.type === 'comment';
});
}
function replaceComments (source) {
if (!source) {
return;
}
var parsed = commentParser(source).reduce(function (value, node) {
if (node.type !== 'comment') {
return value + node.value;
}
var b = balanced.replacements({
source: source,
open: '/*',
close: '*/',
replace: function (comment, head, tail) {
if (remover.canRemove(comment)) {
return ' ';
}
return head + comment + tail;
}
});
return space(b).join(' ');
}
if (remover.canRemove(node.value)) {
return value + ' ';
}
return value + '/*' + node.value + '*/';
}, '');
return space(parsed).join(' ');
}
return function (css) {
css.walk(function (node) {

@@ -47,7 +52,3 @@ if (node.type === 'comment' && remover.canRemove(node.text)) {

node.raws.important = replaceComments(node.raws.important);
var b = balanced.matches({
source: node.raws.important,
open: '/*',
close: '*/'
});
var b = matchesComments(node.raws.important);
node.raws.important = b.length ? node.raws.important : '!important';

@@ -54,0 +55,0 @@ }

'use strict';
function CommentRemover (options) {
if (!(this instanceof CommentRemover)) {
return new CommentRemover(options);
}
this.options = options;

@@ -8,0 +5,0 @@ }

{
"name": "postcss-discard-comments",
"version": "2.0.0",
"version": "2.0.1",
"description": "Discard comments in your CSS files with PostCSS.",
"main": "index.js",
"files": [
"lib",
"index.js",
"LICENSE-MIT"
],
"scripts": {

@@ -17,4 +22,5 @@ "test": "tape test.js | tap-spec"

"devDependencies": {
"postcss-scss": "^0.1.2",
"tap-spec": "^4.1.0",
"tape": "^4.2.0"
"tape": "^4.2.1"
},

@@ -27,10 +33,6 @@ "homepage": "https://github.com/ben-eb/postcss-discard-comments",

},
"repository": {
"type": "git",
"url": "git://github.com/ben-eb/postcss-discard-comments.git"
},
"repository": "ben-eb/postcss-discard-comments",
"dependencies": {
"node-balanced": "0.0.14",
"postcss": "^5.0.4"
"postcss": "^5.0.8"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc