Comparing version 0.8.2 to 0.8.3
@@ -25,3 +25,3 @@ 'use strict'; | ||
isHtml, // set when the input is recognized as HTML; | ||
regEx; // regular expression details; | ||
regEx = []; // regular expression details; | ||
@@ -41,2 +41,37 @@ if (!len) { | ||
if (options && options.ignore) { | ||
var ignore = options.ignore; | ||
if (ignore instanceof RegExp) { | ||
ignore = [ignore]; | ||
} else { | ||
if (ignore instanceof Array) { | ||
ignore = ignore.filter(function (f) { | ||
return f instanceof RegExp; | ||
}); | ||
if (!ignore.length) { | ||
ignore = null; | ||
} | ||
} else { | ||
ignore = null; | ||
} | ||
} | ||
if (ignore) { | ||
for (var i = 0; i < ignore.length; i++) { | ||
var match, reg = ignore[i]; | ||
do { | ||
match = reg.exec(code); | ||
if (match) { | ||
regEx.push({ | ||
start: match.index, | ||
end: match.index + match[0].length - 1 | ||
}); | ||
} | ||
} while (match && reg.global); | ||
} | ||
regEx = regEx.sort(function (a, b) { | ||
return a.start > b.start; | ||
}); | ||
} | ||
} | ||
do { | ||
@@ -124,2 +159,6 @@ if (!isHtml && code[idx] === '/' && idx < len - 1 && (!idx || code[idx - 1] !== '\\')) { | ||
if (isHtml && code[idx] === '<' && idx < len - 3 && code.substr(idx + 1, 3) === '!--') { | ||
if (inRegEx()) { | ||
s += '<'; | ||
continue; | ||
} | ||
var end = code.indexOf('-->', idx + 4); | ||
@@ -220,3 +259,3 @@ var keep = optSafe && code.substr(idx + 4, 3) === '[if'; | ||
function inRegEx() { | ||
if (regEx && regEx.length) { | ||
if (regEx.length) { | ||
return utils.indexInRegEx(idx, regEx); | ||
@@ -223,0 +262,0 @@ } |
{ | ||
"name": "decomment", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "Removes comments from JSON, JavaScript, CSS, HTML, etc.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -86,2 +86,17 @@ decomment | ||
##### options.ignore ⇒ RegExp | [RegExp,...] | ||
Takes either a single or an array of regular expressions to match against. | ||
All matching blocks are ignored, as well as any comment-like content inside them. | ||
For example, CSS may contain Base64-encoded strings with comment-like symbols: | ||
```css | ||
src: url(data:font/woff;base64,d09GRg//ABAAAAAAZ) | ||
``` | ||
And you can isolate all `url(*)` blocks by using: | ||
```js | ||
{ignore: /url\([\w\s:\/=\-\+;,]*\)/g} | ||
``` | ||
##### options.space ⇒ Boolean | ||
@@ -88,0 +103,0 @@ |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
55126
13
1066
168
2