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

html-minifier

Package Overview
Dependencies
Maintainers
2
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-minifier - npm Package Compare versions

Comparing version 3.5.14 to 3.5.15

4

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

@@ -67,3 +67,3 @@ "cli",

"grunt": "1.0.x",
"grunt-browserify": "5.2.x",
"grunt-browserify": "5.3.x",
"grunt-contrib-uglify": "3.3.x",

@@ -70,0 +70,0 @@ "gruntify-eslint": "4.0.x",

@@ -25,14 +25,14 @@ # HTMLMinifier

| ---------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
| [Google](https://www.google.com/) | 45 | **42** | 45 | 46 | 45 |
| [Twitter](https://twitter.com/) | 122 | **89** | 114 | 132 | 114 |
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 141 | **110** | 118 | 123 | 118 |
| [New York Times](https://www.nytimes.com/) | 214 | **147** | 165 | 161 | 150 |
| [Stack Overflow](https://stackoverflow.com/) | 245 | **192** | 200 | 209 | 198 |
| [Google](https://www.google.com/) | 45 | **42** | 45 | 47 | 45 |
| [Twitter](https://twitter.com/) | 122 | **89** | 115 | 134 | 115 |
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 142 | **110** | 119 | 123 | 118 |
| [New York Times](https://www.nytimes.com/) | 221 | **152** | 172 | 168 | 156 |
| [Stack Overflow](https://stackoverflow.com/) | 247 | **193** | 202 | 210 | 200 |
| [Bootstrap CSS](https://getbootstrap.com/docs/3.3/css/) | 272 | **260** | 269 | 229 | 269 |
| [BBC](https://www.bbc.co.uk/) | 299 | **241** | 291 | 294 | 277 |
| [Amazon](https://www.amazon.co.uk/) | 369 | **315** | 356 | 367 | n/a |
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 473 | **441** | 458 | 473 | 457 |
| [NBC](https://www.nbc.com/) | 689 | **648** | 685 | 688 | n/a |
| [BBC](https://www.bbc.co.uk/) | 283 | **228** | 275 | 278 | 262 |
| [Amazon](https://www.amazon.co.uk/) | 370 | **315** | 356 | 367 | n/a |
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 474 | **442** | 458 | 473 | 457 |
| [NBC](https://www.nbc.com/) | 666 | **627** | 663 | 665 | n/a |
| [Eloquent Javascript](https://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a |
| [ES6 table](https://kangax.github.io/compat-table/es6/) | 4808 | **4095** | 4548 | n/a | n/a |
| [ES6 table](https://kangax.github.io/compat-table/es6/) | 4916 | **4189** | 4652 | n/a | n/a |
| [ES6 draft](https://tc39.github.io/ecma262/) | 6099 | **5435** | 5597 | n/a | n/a |

@@ -62,3 +62,3 @@

| `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)`) |
| `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, type)`) |
| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `Object`, `Function(text, inline)`) |

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

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

}
attrValue = unwrapInlineCSS(options.minifyCSS(wrapInlineCSS(attrValue)));
attrValue = options.minifyCSS(attrValue, 'inline');
}

@@ -326,3 +326,3 @@ return attrValue;

attrValue = trimWhitespace(attrValue);
return unwrapMediaQuery(options.minifyCSS(wrapMediaQuery(attrValue)));
return options.minifyCSS(attrValue, 'media');
}

@@ -618,96 +618,103 @@ return attrValue;

function processOptions(options) {
['html5', 'includeAutoGeneratedTags'].forEach(function(key) {
if (!(key in options)) {
options[key] = true;
}
});
if (typeof options.log !== 'function') {
options.log = identity;
}
if (!options.canCollapseWhitespace) {
options.canCollapseWhitespace = canCollapseWhitespace;
}
if (!options.canTrimWhitespace) {
options.canTrimWhitespace = canTrimWhitespace;
}
if (!('ignoreCustomComments' in options)) {
options.ignoreCustomComments = [/^!/];
}
if (!('ignoreCustomFragments' in options)) {
options.ignoreCustomFragments = [
function processOptions(values) {
var options = {
canCollapseWhitespace: canCollapseWhitespace,
canTrimWhitespace: canTrimWhitespace,
html5: true,
ignoreCustomComments: [/^!/],
ignoreCustomFragments: [
/<%[\s\S]*?%>/,
/<\?[\s\S]*?\?>/
];
}
if (!options.minifyURLs) {
options.minifyURLs = identity;
}
if (typeof options.minifyURLs !== 'function') {
var minifyURLs = options.minifyURLs;
if (typeof minifyURLs === 'string') {
minifyURLs = { site: minifyURLs };
],
includeAutoGeneratedTags: true,
log: identity,
minifyCSS: identity,
minifyJS: identity,
minifyURLs: identity
};
Object.keys(values).forEach(function(key) {
var value = values[key];
if (key === 'log') {
if (typeof value === 'function') {
options.log = value;
}
}
else if (typeof minifyURLs !== 'object') {
minifyURLs = {};
}
options.minifyURLs = function(text) {
try {
return RelateUrl.relate(text, minifyURLs);
else if (key === 'minifyCSS' && typeof value !== 'function') {
if (!value) {
return;
}
catch (err) {
options.log(err);
return text;
if (typeof value !== 'object') {
value = {};
}
};
}
if (!options.minifyJS) {
options.minifyJS = identity;
}
if (typeof options.minifyJS !== 'function') {
var minifyJS = options.minifyJS;
if (typeof minifyJS !== 'object') {
minifyJS = {};
options.minifyCSS = function(text, type) {
text = text.replace(/(url\s*\(\s*)("|'|)(.*?)\2(\s*\))/ig, function(match, prefix, quote, url, suffix) {
return prefix + quote + options.minifyURLs(url) + quote + suffix;
});
try {
if (type === 'inline') {
text = wrapInlineCSS(text);
}
else if (type === 'media') {
text = wrapMediaQuery(text);
}
text = new CleanCSS(value).minify(text).styles;
if (type === 'inline') {
text = unwrapInlineCSS(text);
}
else if (type === 'media') {
text = unwrapMediaQuery(text);
}
return text;
}
catch (err) {
options.log(err);
return text;
}
};
}
(minifyJS.parse || (minifyJS.parse = {})).bare_returns = false;
options.minifyJS = function(text, inline) {
var start = text.match(/^\s*<!--.*/);
var code = start ? text.slice(start[0].length).replace(/\n\s*-->\s*$/, '') : text;
minifyJS.parse.bare_returns = inline;
var result = UglifyJS.minify(code, minifyJS);
if (result.error) {
options.log(result.error);
return text;
else if (key === 'minifyJS' && typeof value !== 'function') {
if (!value) {
return;
}
return result.code.replace(/;$/, '');
};
}
if (!options.minifyCSS) {
options.minifyCSS = identity;
}
if (typeof options.minifyCSS !== 'function') {
var minifyCSS = options.minifyCSS;
if (typeof minifyCSS !== 'object') {
minifyCSS = {};
if (typeof value !== 'object') {
value = {};
}
(value.parse || (value.parse = {})).bare_returns = false;
options.minifyJS = function(text, inline) {
var start = text.match(/^\s*<!--.*/);
var code = start ? text.slice(start[0].length).replace(/\n\s*-->\s*$/, '') : text;
value.parse.bare_returns = inline;
var result = UglifyJS.minify(code, value);
if (result.error) {
options.log(result.error);
return text;
}
return result.code.replace(/;$/, '');
};
}
options.minifyCSS = function(text) {
text = text.replace(/(url\s*\(\s*)("|'|)(.*?)\2(\s*\))/ig, function(match, prefix, quote, url, suffix) {
return prefix + quote + options.minifyURLs(url) + quote + suffix;
});
try {
return new CleanCSS(minifyCSS).minify(text).styles;
else if (key === 'minifyURLs' && typeof value !== 'function') {
if (!value) {
return;
}
catch (err) {
options.log(err);
return text;
if (typeof value === 'string') {
value = { site: value };
}
};
}
else if (typeof value !== 'object') {
value = {};
}
options.minifyURLs = function(text) {
try {
return RelateUrl.relate(text, value);
}
catch (err) {
options.log(err);
return text;
}
};
}
else {
options[key] = value;
}
});
return options;
}

@@ -777,3 +784,3 @@

var log = options.log;
options.log = null;
options.log = identity;
options.sortAttributes = false;

@@ -811,5 +818,2 @@ options.sortClassName = false;

function minify(value, options, partialMarkup) {
options = options || {};
var optionsStack = [];
processOptions(options);
if (options.collapseWhitespace) {

@@ -829,3 +833,2 @@ value = collapseWhitespace(value, options, true, true);

optionalEndTag = '',
t = Date.now(),
ignoredMarkupChunks = [],

@@ -846,7 +849,8 @@ ignoredCustomMarkupChunks = [],

if (options.ignoreCustomComments) {
options.ignoreCustomComments.push(pattern);
options.ignoreCustomComments = options.ignoreCustomComments.slice();
}
else {
options.ignoreCustomComments = [pattern];
options.ignoreCustomComments = [];
}
options.ignoreCustomComments.push(pattern);
}

@@ -858,7 +862,9 @@ var token = '<!--' + uidIgnore + ignoredMarkupChunks.length + '-->';

function escapeFragments(text) {
return text.replace(uidPattern, function(match, prefix, index) {
var chunks = ignoredCustomMarkupChunks[+index];
return chunks[1] + uidAttr + index + chunks[2];
});
function escapeFragments(fn) {
return function(text, type) {
return fn(text.replace(uidPattern, function(match, prefix, index) {
var chunks = ignoredCustomMarkupChunks[+index];
return chunks[1] + uidAttr + index + chunks[2];
}), type);
};
}

@@ -876,13 +882,7 @@

uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g');
var minifyCSS = options.minifyCSS;
if (minifyCSS) {
options.minifyCSS = function(text) {
return minifyCSS(escapeFragments(text));
};
if (options.minifyCSS) {
options.minifyCSS = escapeFragments(options.minifyCSS);
}
var minifyJS = options.minifyJS;
if (minifyJS) {
options.minifyJS = function(text, inline) {
return minifyJS(escapeFragments(text), inline);
};
if (options.minifyJS) {
options.minifyJS = escapeFragments(options.minifyJS);
}

@@ -961,10 +961,5 @@ }

if (lowerTag === 'svg') {
optionsStack.push(options);
var nextOptions = {};
for (var key in options) {
nextOptions[key] = options[key];
}
nextOptions.keepClosingSlash = true;
nextOptions.caseSensitive = true;
options = nextOptions;
options = Object.create(options);
options.keepClosingSlash = true;
options.caseSensitive = true;
}

@@ -1055,3 +1050,3 @@

if (lowerTag === 'svg') {
options = optionsStack.pop();
options = Object.getPrototypeOf(options);
}

@@ -1283,3 +1278,2 @@ tag = options.caseSensitive ? tag : lowerTag;

options.log('minified in: ' + (Date.now() - t) + 'ms');
return str;

@@ -1316,3 +1310,7 @@ }

exports.minify = function(value, options) {
return minify(value, options);
var start = Date.now();
options = processOptions(options || {});
var result = minify(value, options);
options.log('minified in: ' + (Date.now() - start) + 'ms');
return result;
};
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