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

decomment

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decomment - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

46

lib/parser.js

@@ -66,3 +66,2 @@ 'use strict';

}
if (code[idx + 1] === '*') {

@@ -85,5 +84,4 @@ if (checkRegEx && utils.indexInRegEx(idx, regEx)) {

}
var l = end - idx + 2; // entire comment length;
var comment = code.substr(idx, end - idx + 2);
idx = end + 1;
if (emptyLine) {

@@ -93,2 +91,8 @@ emptyLetters = '';

if (!keep) {
var parts = comment.split(EOL);
if (optSpace && parts.length > 1) {
for (var k = 0; k < parts.length - 1; k++) {
s += EOL;
}
}
var lb = code.indexOf(EOL, idx + 1);

@@ -105,5 +109,17 @@ if (lb > idx) {

if (optSpace) {
s += utils.getSpaces(l);
if (parts.length > 1) {
s += utils.getSpaces(parts[parts.length - 1].length);
} else {
s += utils.getSpaces(comment.length);
}
}
}
} else {
if (optSpace && parts.length > 1) {
var gapIdx = idx + 1;
while ((code[gapIdx] === ' ' || code[gapIdx] === '\t') && ++gapIdx < len);
if (gapIdx < len) {
s += utils.getSpaces(parts[parts.length - 1].length);
}
}
}

@@ -120,3 +136,3 @@ }

}
var l = end - idx + 3; // entire comment length;
var comment = code.substr(idx, end - idx + 3);
idx = end + 2;

@@ -126,2 +142,8 @@ if (emptyLine) {

}
var parts = comment.split(EOL);
if (optSpace && parts.length > 1) {
for (var k = 0; k < parts.length - 1; k++) {
s += EOL;
}
}
var lb = code.indexOf(EOL, idx + 1);

@@ -138,5 +160,17 @@ if (lb > idx) {

if (optSpace) {
s += utils.getSpaces(l);
if (parts.length > 1) {
s += utils.getSpaces(parts[parts.length - 1].length);
} else {
s += utils.getSpaces(comment.length);
}
}
}
} else {
if (optSpace && parts.length > 1) {
var gapIdx = idx + 1;
while ((code[gapIdx] === ' ' || code[gapIdx] === '\t') && ++gapIdx < len);
if (gapIdx < len) {
s += utils.getSpaces(parts[parts.length - 1].length);
}
}
}

@@ -143,0 +177,0 @@ continue;

2

package.json
{
"name": "decomment",
"version": "0.7.2",
"version": "0.7.3",
"description": "Removes comments from JSON, JavaScript, CSS, HTML, etc.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -99,2 +99,20 @@ 'use strict';

describe("across lines, with space=false", function () {
it("must delete all lines", function () {
expect(decomment("<!--start" + LB + "middle" + LB + "end-->")).toBe("");
expect(decomment("<!--start" + LB + "middle" + LB + "end-->text")).toBe("text");
expect(decomment.html("prefix-<!--start" + LB + "middle" + LB + "end-->suffix")).toBe("prefix-suffix");
});
});
describe("across lines, with space=true", function () {
it("must replace deleted lines with line break", function () {
expect(decomment("<!--start" + LB + "middle" + LB + "end-->text" + LB, {space: true})).toBe(LB + LB + " text" + LB);
expect(decomment("<!--start" + LB + "middle" + LB + "end-->\ttext", {space: true})).toBe(LB + LB + " \ttext");
expect(decomment("<!--start" + LB + "middle" + LB + "end-->", {space: true})).toBe(LB + LB);
expect(decomment("<!--start" + LB + "middle" + LB + "end-->text", {space: true})).toBe(LB + LB + " text");
expect(decomment.html("prefix<!--start" + LB + "middle" + LB + "end-->suffix", {space: true})).toBe("prefix" + LB + LB + " suffix");
});
});
});

@@ -189,2 +189,20 @@ 'use strict';

describe("across lines, with space=false", function () {
it("must delete all lines", function () {
expect(decomment("/*start" + LB + "middle" + LB + "end*/")).toBe("");
expect(decomment("/*start" + LB + "middle" + LB + "end*/text")).toBe("text");
expect(decomment("prefix-/*start" + LB + "middle" + LB + "end*/suffix")).toBe("prefix-suffix");
});
});
describe("across lines, with space=true", function () {
it("must replace deleted lines with line break", function () {
expect(decomment("/*start" + LB + "middle" + LB + "end*/text" + LB, {space: true})).toBe(LB + LB + " text" + LB);
expect(decomment("/*start" + LB + "middle" + LB + "end*/\ttext", {space: true})).toBe(LB + LB + " \ttext");
expect(decomment("/*start" + LB + "middle" + LB + "end*/", {space: true})).toBe(LB + LB);
expect(decomment("/*start" + LB + "middle" + LB + "end*/text", {space: true})).toBe(LB + LB + " text");
expect(decomment("prefix/*start" + LB + "middle" + LB + "end*/suffix", {space: true})).toBe("prefix" + LB + LB + " suffix");
});
});
});
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