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.2.3 to 0.3.0

26

index.js

@@ -5,8 +5,12 @@ 'use strict';

function decomment(text) {
function decomment(text, options) {
if (typeof text !== 'string') {
throw new TypeError("A text string was expected.");
throw new TypeError("Parameter 'text' must be a string.");
}
if (options !== undefined && typeof(options) !== 'object') {
throw new TypeError("Parameter 'options' must be an object.");
}
var idx = 0, // current index;

@@ -45,2 +49,3 @@ s = '', // resulting text;

idx = lb + EOL.length - 1; // last symbol of the line break;
trim();
} else {

@@ -63,2 +68,3 @@ idx = lb - 1; // just before the line break;

idx = lb + EOL.length - 1; // last symbol of the line break;
trim();
}

@@ -83,2 +89,3 @@ }

idx = lb + EOL.length - 1; // last symbol of the line break;
trim();
}

@@ -138,2 +145,17 @@ }

function trim() {
if (options && options.trim) {
var startIdx, endIdx, i;
do {
startIdx = idx + 1;
endIdx = text.indexOf(EOL, startIdx);
i = startIdx;
while ((text[i] === ' ' || text[i] === '\t') && ++i < endIdx);
if (i === endIdx) {
idx = endIdx + EOL.length - 1;
}
} while (i === endIdx);
}
}
return s;

@@ -140,0 +162,0 @@ }

2

package.json
{
"name": "decomment",
"version": "0.2.3",
"version": "0.3.0",
"description": "Removes comments from JSON, JavaScript, CSS and HTML.",

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

@@ -31,7 +31,22 @@ decomment

var code = "var t; // comments";
var text = "var t; // comments";
console.log(decomment(code)); //=> var t;
decomment(text); //=> var t;
```
#### API
**decomment(text, [options]) ⇒ String**
Option `trim` is the only one currently supported:
* `false (default)` - use no trimming for comment blocks
* `true` - remove empty lines that follow full-line comments
Example:
```js
var text = "/* comment */\r\n\r\nvar test = 123;";
decomment(text, {trim: true}); //=> var test = 123;
```
## Features

@@ -38,0 +53,0 @@

@@ -13,6 +13,14 @@ 'use strict';

decomment();
}).toThrow(new TypeError("A text string was expected."));
}).toThrow(new TypeError("Parameter 'text' must be a string."));
});
});
describe("non-object options", function () {
it("must throw an error", function () {
expect(function () {
decomment("", 123);
}).toThrow(new TypeError("Parameter 'options' must be an object."));
});
});
describe("empty string input", function () {

@@ -19,0 +27,0 @@ it("must return empty string", function () {

@@ -120,2 +120,9 @@ 'use strict';

});
describe("multiple line breaks that follow", function () {
it("must be removed", function () {
expect(decomment("/*text*/" + LB + LB + "end", {trim: true})).toBe("end");
});
});
});

@@ -139,2 +139,9 @@ 'use strict';

});
describe("multiple line breaks that follow", function () {
it("must be removed", function () {
expect(decomment("//text" + LB + LB + "end", {trim: true})).toBe("end");
expect(decomment("//text" + LB + "\t" + LB + "end", {trim: true})).toBe("end");
});
});
});
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