Socket
Socket
Sign inDemoInstall

minimize

Package Overview
Dependencies
2
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.12 to 0.5.13

16

lib/helpers.js

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

var flow = /<\/[^>]+>$|\w+$/
, conditional = /\[if.+IE[\s\d]*\]>.+<\!\[endif\]/g
, inline = [

@@ -45,7 +46,8 @@ 'a', 'abbr', 'b', 'bdo', 'br', 'cite',

var config = {
empty: false, // remove(false) or retain(true) empty attributes
cdata: false, // remove(false) or retain(true) CDATA from scripts
comments: false, // remove(false) or retain(true) comments
spare: false, // remove(false) or retain(true) redundant attributes
quotes: false // remove(false) or retain(true) quotes if not required
empty: false, // remove(false) or retain(true) empty attributes
cdata: false, // remove(false) or retain(true) CDATA from scripts
comments: false, // remove(false) or retain(true) comments
conditionals: false, // remove(false) or retain(true) ie conditional comments
spare: false, // remove(false) or retain(true) redundant attributes
quotes: false // remove(false) or retain(true) quotes if not required
};

@@ -228,2 +230,6 @@

Helpers.prototype.comment = function comment (element) {
if (this.config.conditionals && conditional.test(element.data)) {
return '<!--' + element.data + '-->';
}
return !this.config.comments ? '' : '<!--' + element.data + '-->';

@@ -230,0 +236,0 @@ };

{
"name": "minimize",
"version": "0.5.12",
"version": "0.5.13",
"description": "Minimize HTML",

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

@@ -18,8 +18,12 @@ [![Build Status][status]](https://travis-ci.org/Moveo/minimize)

Upcoming in release 1.0
- fast and stable html minification
- highly configurable
- can distinguish conditional IE comments
- build on the foundations of htmlparser2
## Upcoming in release 1.0
- command line usage support
- increased configurability (element replacement, etc.)
Upcoming in release 2.0
## Upcoming in release 2.0

@@ -36,8 +40,9 @@ - minification of inline javascript by [square](https://github.com/observing/square)

var Minimize = require('minimize')
minimize = new Minimize({
empty: true // DO NOT remove empty attributes
, cdata: true // DO NOT strip CDATA from scripts
, comments: true // DO NOT remove comments
, spare: true // DO NOT remove redundant attributes
, quotes: true // DO NOT remove arbitrary quotes
, minimize = new Minimize({
empty: true, // DO NOT remove empty attributes
cdata: true, // DO NOT strip CDATA from scripts
comments: true, // DO NOT remove comments
conditionals: true, // DO NOT remove conditional internet explorer comments
spare: true, // DO NOT remove redundant attributes
quotes: true // DO NOT remove arbitrary quotes
});

@@ -60,9 +65,9 @@

var Minimize = require('minimize')
minimize = new Minimize({ empty: true });
, minimize = new Minimize({ empty: true });
minimize.parse(
'<h1 id=""></h1>'
, function (error, data) {
// data output: <h1 id=""></h1>
}
'<h1 id=""></h1>',
function (error, data) {
// data output: <h1 id=""></h1>
}
);

@@ -79,9 +84,9 @@ ```

var Minimize = require('minimize')
minimize = new Minimize({ cdata: true });
, minimize = new Minimize({ cdata: true });
minimize.parse(
'<script type="text/javascript">\n//<![CDATA[\n...code...\n//]]>\n</script>'
, function (error, data) {
// data output: <script type=text/javascript>//<![CDATA[\n...code...\n//]]></script>
}
'<script type="text/javascript">\n//<![CDATA[\n...code...\n//]]>\n</script>',
function (error, data) {
// data output: <script type=text/javascript>//<![CDATA[\n...code...\n//]]></script>
}
);

@@ -99,12 +104,32 @@ ```

var Minimize = require('minimize')
minimize = new Minimize({ comments: true });
, minimize = new Minimize({ comments: true });
minimize.parse(
'<!-- some HTML comment -->\n <div class="slide nodejs">'
, function (error, data) {
// data output: <!-- some HTML comment --><div class="slide nodejs">
}
'<!-- some HTML comment -->\n <div class="slide nodejs">',
function (error, data) {
// data output: <!-- some HTML comment --><div class="slide nodejs">
}
);
```
**Conditionals**
Conditional comments only work in IE, and are thus excellently suited to give
special instructions meant only for IE. Minimize can be configured to retain
these comments. But since the comments are only working until IE9 (inclusive)
the default is to remove the conditionals.
```javascript
var Minimize = require('minimize')
, minimize = new Minimize({ conditionals: true });
minimize.parse(
"<!--[if ie6]>Cover microsofts' ass<![endif]-->\n<br>",
function (error, data) {
// data output: <!--[if ie6]>Cover microsofts' ass<![endif]-->\n<br>
}
);
```
**Spare**

@@ -117,9 +142,9 @@

var Minimize = require('minimize')
minimize = new Minimize({ spare: true });
, minimize = new Minimize({ spare: true });
minimize.parse(
'<input type="text" disabled="disabled"></h1>'
, function (error, data) {
// data output: <input type=text disabled=disabled></h1>
}
'<input type="text" disabled="disabled"></h1>',
function (error, data) {
// data output: <input type=text disabled=disabled></h1>
}
);

@@ -136,9 +161,9 @@ ```

var Minimize = require('minimize')
minimize = new Minimize({ quotes: true });
, minimize = new Minimize({ quotes: true });
minimize.parse(
'<p class="paragraph" id="title">\n Some content\n </p>'
, function (error, data) {
// data output: <p class="paragraph" id="title">Some content</p>
}
'<p class="paragraph" id="title">\n Some content\n </p>',
function (error, data) {
// data output: <p class="paragraph" id="title">Some content</p>
}
);

@@ -145,0 +170,0 @@ ```

{
"content": "<div class=\"slide nodejs\">\n <h3>100% Node.js</h3>\n <p>\n We are Node.js experts and the first hosting platform to build\n our full stack in node. We understand your node application\n better than anyone.\n </p>\n </div>\n\n ",
"comment": "<!-- some HTML comment -->\n <div class=\"slide nodejs\">\n <h3>100% Node.js</h3>\n <p>\n We are Node.js experts and the first hosting platform to build\n our full stack in node. We understand your node application\n better than anyone.\n </p>\n </div>\n\n ",
"ie": "<!--[if IE 6]>Special instructions for IE 6 here<![endif]-->\n <div class=\"slide nodejs\">\n <h3>100% Node.js</h3>\n </div>",
"interpunction": "<h3>Become a partner</h3>\n <p>\n Interested in being part of the solution?\n <a href=\"/company/contact\">Contact Nodejitsu to discuss</a>.\n </p>",

@@ -5,0 +6,0 @@ "code": "<code class=\"copy\">\n<span>var http = require('http');\nhttp.createServer(function (req, res) {\n res.writeHead(200, {'Content-Type': 'text/plain'});\n res.end('hello, i know nodejitsu');\n})listen(8080);</span><a href=\"#\"><s class=\"ss-layers\" role=\"presentation\"></s> copy</a></code>",

@@ -85,2 +85,10 @@ 'use strict';

it('should be configurable to retain conditional internet explorer comments', function (done) {
var commentable = new Minimize({ conditionals: true });
commentable.parse(html.ie, function (error, result) {
expect(result).to.equal('<!--[if IE 6]>Special instructions for IE 6 here<![endif]--><div class=\"slide nodejs\"><h3>100% Node.js</h3></div>');
done();
});
});
it('should be configurable to retain empty attributes', function (done) {

@@ -87,0 +95,0 @@ var empty = new Minimize({ empty: true });

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