Socket
Socket
Sign inDemoInstall

html-minifier

Package Overview
Dependencies
45
Maintainers
2
Versions
80
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.6 to 2.1.7

4

package.json
{
"name": "html-minifier",
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier.",
"version": "2.1.6",
"version": "2.1.7",
"keywords": [

@@ -69,3 +69,3 @@ "cli",

"grunt-contrib-uglify": "1.0.x",
"grunt-eslint": "18.1.x",
"grunt-eslint": "19.0.x",
"phantomjs-prebuilt": "2.1.x",

@@ -72,0 +72,0 @@ "qunitjs": "2.x"

@@ -15,3 +15,3 @@ # HTMLMinifier

Also see corresponding [Ruby wrapper](https://github.com/stereobooster/html_minifier), and for Node.js, [Grunt plugin](https://github.com/gruntjs/grunt-contrib-htmlmin), [Gulp module](https://github.com/jonschlinkert/gulp-htmlmin), and [Koa middleware wrapper](https://github.com/koajs/html-minifier).
Also see corresponding [Ruby wrapper](https://github.com/stereobooster/html_minifier), and for Node.js, [Grunt plugin](https://github.com/gruntjs/grunt-contrib-htmlmin), [Gulp module](https://github.com/jonschlinkert/gulp-htmlmin), [Koa middleware wrapper](https://github.com/koajs/html-minifier) and [Express middleware wrapper](https://github.com/melonmanchan/express-minify-html).

@@ -26,15 +26,15 @@ For lint-like capabilities take a look at [HTMLLint](https://github.com/kangax/html-lint).

| --------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
| [Google](https://www.google.com/) | 48 | **46** | 48 | 50 | 49 |
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 116 | **78** | 99 | 103 | 99 |
| [CNN](http://www.cnn.com/) | 121 | **111** | 117 | 119 | 115 |
| [BBC](http://www.bbc.co.uk/) | 193 | **157** | 187 | 192 | 182 |
| [New York Times](http://www.nytimes.com/) | 210 | **146** | 159 | 161 | 153 |
| [Stack Overflow](http://stackoverflow.com/) | 244 | **190** | 198 | 207 | 197 |
| [Google](https://www.google.com/) | 48 | **46** | 48 | 50 | 48 |
| [CNN](http://www.cnn.com/) | 115 | **105** | 111 | 113 | 109 |
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 117 | **79** | 99 | 103 | 99 |
| [BBC](http://www.bbc.co.uk/) | 179 | **147** | 172 | 177 | 168 |
| [New York Times](http://www.nytimes.com/) | 186 | **127** | 136 | 140 | 134 |
| [Stack Overflow](http://stackoverflow.com/) | 240 | **186** | 195 | 204 | 193 |
| [Bootstrap CSS](http://getbootstrap.com/css/) | 277 | **264** | 274 | 232 | 274 |
| [Amazon](http://www.amazon.co.uk/) | 456 | **403** | 436 | 450 | n/a |
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 479 | **435** | 462 | 478 | n/a |
| [NBC](http://www.nbc.com/) | 508 | **487** | 506 | 508 | n/a |
| [Amazon](http://www.amazon.co.uk/) | 431 | **377** | 412 | 424 | n/a |
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 481 | **437** | 464 | 479 | n/a |
| [NBC](http://www.nbc.com/) | 508 | **486** | 506 | 508 | n/a |
| [Eloquent Javascript](http://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a |
| [ES6 table](http://kangax.github.io/compat-table/es6/) | 3816 | **3207** | 3593 | 3771 | n/a |
| [ES6 draft](https://tc39.github.io/ecma262/) | 4796 | **4247** | 4376 | 4500 | n/a |
| [ES6 table](http://kangax.github.io/compat-table/es6/) | 3884 | **3272** | 3664 | 3839 | n/a |
| [ES6 draft](https://tc39.github.io/ecma262/) | 4797 | **4247** | 4377 | 4500 | n/a |

@@ -61,3 +61,3 @@ ## Options Quick Reference

| `maxLineLength` | Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points |
| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text, inline)`) |
| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text)`) |
| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `Object`, `Function(text, inline)`) |

@@ -64,0 +64,0 @@ | `minifyURLs` | Minify URLs in various attributes (uses [relateurl](https://github.com/stevenvachon/relateurl)) | `false` (could be `String`, `Object`, `Function(text)`) |

@@ -231,3 +231,3 @@ 'use strict';

function isCanonicalURL(tag, attrs) {
function isLinkType(tag, attrs, value) {
if (tag !== 'link') {

@@ -237,3 +237,3 @@ return false;

for (var i = 0, len = attrs.length; i < len; i++) {
if (attrs[i].name === 'rel' && attrs[i].value === 'canonical') {
if (attrs[i].name === 'rel' && attrs[i].value === value) {
return true;

@@ -244,2 +244,6 @@ }

function isMediaQuery(tag, attrs, attrName) {
return attrName === 'media' && (isLinkType(tag, attrs, 'stylesheet') || isStyleSheet(tag, attrs));
}
var srcsetTags = createMapFromString('img,source');

@@ -268,3 +272,3 @@

attrValue = trimWhitespace(attrValue);
return isCanonicalURL(tag, attrs) ? attrValue : options.minifyURLs(attrValue);
return isLinkType(tag, attrs, 'canonical') ? attrValue : options.minifyURLs(attrValue);
}

@@ -276,6 +280,9 @@ else if (isNumberTypeAttribute(attrName, tag)) {

attrValue = trimWhitespace(attrValue);
if (attrValue && /;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) {
attrValue = attrValue.replace(/\s*;$/, '');
if (attrValue) {
if (/;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) {
attrValue = attrValue.replace(/\s*;$/, '');
}
attrValue = unwrapInlineCSS(options.minifyCSS(wrapInlineCSS(attrValue)));
}
return options.minifyCSS(attrValue, true);
return attrValue;
}

@@ -313,2 +320,6 @@ else if (isSrcset(attrName, tag)) {

}
else if (isMediaQuery(tag, attrs, attrName)) {
attrValue = trimWhitespace(attrValue);
return unwrapMediaQuery(options.minifyCSS(wrapMediaQuery(attrValue)));
}
return attrValue;

@@ -330,14 +341,20 @@ }

// See https://github.com/jakubpawlowicz/clean-css/issues/418
function wrapCSS(text) {
function wrapInlineCSS(text) {
return '*{' + text + '}';
}
function unwrapCSS(text) {
var matches = text.match(/^\*\{([\s\S]*)\}$/m);
if (matches && matches[1]) {
return matches[1];
}
return text;
function unwrapInlineCSS(text) {
var matches = text.match(/^\*\{([\s\S]*)\}$/);
return matches ? matches[1] : text;
}
function wrapMediaQuery(text) {
return '@media ' + text + '{a{top:0}}';
}
function unwrapMediaQuery(text) {
var matches = text.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/);
return matches ? matches[1] : text;
}
function cleanConditionalComment(comment, options) {

@@ -695,3 +712,3 @@ return options.processConditionalComments ? comment.replace(/^(\[if\s[^\]]+\]>)([\s\S]*?)(<!\[endif\])$/, function(match, prefix, text, suffix) {

}
options.minifyCSS = function(text, inline) {
options.minifyCSS = function(text) {
text = text.replace(/(url\s*\(\s*)("|'|)(.*?)\2(\s*\))/ig, function(match, prefix, quote, url, suffix) {

@@ -703,7 +720,3 @@ return prefix + quote + options.minifyURLs(url) + quote + suffix;

try {
var cleanCSS = new CleanCSS(minifyCSS);
if (inline) {
return unwrapCSS(cleanCSS.minify(wrapCSS(style)).styles);
}
return cleanCSS.minify(style).styles;
return new CleanCSS(minifyCSS).minify(style).styles;
}

@@ -721,3 +734,3 @@ catch (err) {

do {
id = Math.random().toString(36).slice(2);
id = Math.random().toString(36).replace(/^0\.[0-9]*/, '');
} while (~value.indexOf(id));

@@ -835,3 +848,4 @@ return id;

uidIgnore,
uidAttr;
uidAttr,
uidPattern;

@@ -860,2 +874,20 @@ // temporarily replace ignored chunks with comments,

uidAttr = uniqueId(value);
uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g');
var minifyCSS = options.minifyCSS;
if (minifyCSS) {
options.minifyCSS = function(text) {
return minifyCSS(text).replace(uidPattern, function(match, prefix, index, suffix) {
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
});
};
}
var minifyJS = options.minifyJS;
if (minifyJS) {
var pattern = new RegExp('(\\\\t|)' + uidAttr + '([0-9]+)(\\\\t|)', 'g');
options.minifyJS = function(text, inline) {
return minifyJS(text, inline).replace(pattern, function(match, prefix, index, suffix) {
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
});
};
}
}

@@ -1218,4 +1250,4 @@ var token = uidAttr + ignoredCustomMarkupChunks.length;

if (uidAttr) {
str = str.replace(new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g'), function(match, prefix, index, suffix) {
if (uidPattern) {
str = str.replace(uidPattern, function(match, prefix, index, suffix) {
var chunk = ignoredCustomMarkupChunks[+index];

@@ -1222,0 +1254,0 @@ if (options.collapseWhitespace) {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc