Comparing version 0.5.11 to 0.5.12
'use strict'; | ||
/** | ||
* Required modules. | ||
*/ | ||
// | ||
// Required modules. | ||
// | ||
var util = require('utile'); | ||
/** | ||
* Some predefined elements and regular expressions. | ||
*/ | ||
// | ||
// Some predefined elements and regular expressions. | ||
// | ||
var flow = /<\/[^>]+>$|\w+$/ | ||
, inline = [ | ||
'a', 'abbr', 'b', 'bdo', 'br', 'cite' | ||
, 'code', 'dfn', 'em', 'i', 'img', 'kbd' | ||
, 'q', 'samp', 'small', 'span', 'strong' | ||
, 'sub', 'sup', 'textarea', 'var' | ||
'a', 'abbr', 'b', 'bdo', 'br', 'cite', | ||
'code', 'dfn', 'em', 'i', 'img', 'kbd', | ||
'q', 'samp', 'small', 'span', 'strong', | ||
'sub', 'sup', 'textarea', 'var', | ||
] | ||
, singular = [ | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr' | ||
, 'img', 'input', 'link', 'meta', 'param', 'source' | ||
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', | ||
'img', 'input', 'link', 'meta', 'param', 'source', | ||
] | ||
, redundant = [ | ||
'autofocus', 'disabled', 'multiple', 'required', 'readonly', 'hidden' | ||
, 'async', 'defer', 'formnovalidate', 'checked', 'scoped', 'reversed' | ||
, 'selected', 'autoplay', 'controls', 'loop', 'muted', 'seamless' | ||
, 'default', 'ismap', 'novalidate', 'open', 'typemustmatch', 'truespeed' | ||
, 'itemscope' | ||
'autofocus', 'disabled', 'multiple', 'required', 'readonly', 'hidden', | ||
'async', 'defer', 'formnovalidate', 'checked', 'scoped', 'reversed', | ||
'selected', 'autoplay', 'controls', 'loop', 'muted', 'seamless', | ||
'default', 'ismap', 'novalidate', 'open', 'typemustmatch', 'truespeed', | ||
'itemscope' | ||
] | ||
, node = [ 'tag', 'script' ] | ||
, node = [ 'tag', 'script', 'style' ] | ||
, structural = [ 'pre', 'textarea', 'code' ] | ||
, retain = /data|itemscope/ | ||
, cdata = { | ||
start: /\/*<!\[CDATA\[/g | ||
, end: /\/*\]\]>/g | ||
start: /\/*<!\[CDATA\[/g, | ||
end: /\/*\]\]>/g | ||
} | ||
@@ -40,11 +40,11 @@ , interpunction = '.,!%;:?$' | ||
/** | ||
* Predefined parsing options. | ||
*/ | ||
// | ||
// Predefined parsing options. | ||
// | ||
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 | ||
spare: false, // remove(false) or retain(true) redundant attributes | ||
quotes: false // remove(false) or retain(true) quotes if not required | ||
}; | ||
@@ -166,4 +166,15 @@ | ||
/** | ||
* Check if the element is of type style. | ||
* | ||
* @param {Object} element | ||
* @return {Boolean} | ||
* @api public | ||
*/ | ||
Helpers.prototype.isStyle = function isStyle(element) { | ||
return element.type === 'style'; | ||
}; | ||
/** | ||
* Check if an element needs to retain its internal structure, e.g. this goes | ||
* for elements like script, textarea or pre. | ||
* for elements like script, style, textarea or pre. | ||
* | ||
@@ -176,3 +187,3 @@ * @param {Object} element | ||
return element.type !== 'text' | ||
? !!~structural.indexOf(element.name) || this.isJS(element) | ||
? !!~structural.indexOf(element.name) || this.isJS(element) || this.isStyle(element) | ||
: false; | ||
@@ -232,10 +243,11 @@ }; | ||
/** | ||
* Define some proxies for easy external reference. | ||
*/ | ||
// | ||
// Define some proxies for easy external reference. | ||
// | ||
Helpers.prototype.script = Helpers.prototype.tag; | ||
Helpers.prototype.style = Helpers.prototype.tag; | ||
/** | ||
* Expose some additional members while testing. | ||
*/ | ||
// | ||
// Expose some additional members while testing. | ||
// | ||
if (process.env.NODE_ENV === 'test') { | ||
@@ -255,5 +267,5 @@ Helpers.prototype.flow = flow; | ||
/** | ||
* Create public proxies. | ||
*/ | ||
// | ||
// Create public proxies. | ||
// | ||
module.exports = Helpers; |
'use strict'; | ||
// | ||
// Required modules. | ||
// | ||
var parser = require('htmlparser2') | ||
@@ -24,2 +27,5 @@ , EventEmitter = require('events').EventEmitter | ||
// | ||
// Add EventEmitter prototype. | ||
// | ||
Minimize.prototype.__proto__ = EventEmitter.prototype; | ||
@@ -86,6 +92,5 @@ | ||
/** | ||
* Expose the minimize function by default. | ||
*/ | ||
// | ||
// Expose the minimize function by default. | ||
// | ||
module.exports = Minimize; |
{ | ||
"name": "minimize", | ||
"version": "0.5.11", | ||
"version": "0.5.12", | ||
"description": "Minimize HTML", | ||
@@ -5,0 +5,0 @@ "main": "./lib/minimize", |
{ | ||
"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 " | ||
, "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>" | ||
, "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>" | ||
, "newlines": "<li>We're <a href=\"http://nodejitsu.com\">Nodejitsu</a>, and we can give you scalable,\nfault-tolerant cloud hosting for your Node.js apps - and we're the best you'll\nfind.</li>" | ||
, "spacing": "<strong>npm</strong>. You don't have to worry\n about installing npm since it comes bundled with Node.js.\n\n <pre class=\"copy\">$ <span>npm install jitsu -g</span><a href=\"#\"><s class=\"ss-layers\" role=\"presentation\"></s> copy</a></pre>\n" | ||
, "full": "<!doctype html>\n<html class=\"no-js\">\n<head>\n</head>\n<body class=\"container\">\n<section class=\"navigation\" id=\"navigation\">\n <nav class=\"row\">\n <h1>\n <a href=\"/\" class=\"logo\" title=\"Back to the homepage\">Nodejitsu</a>\n </h1>\n <a href=\"#navigation\" class=\"mobile btn ss-rows\"></a>\n\n\n\n <a href=\"/paas\" >\n Cloud\n </a>\n\n <a href=\"/enterprise/private-cloud\" >\n Enterprise\n </a>\n </section>\n <input type=\"text\" name=\"temp\">\n</body>\n </html>" | ||
, "cdata": "<script type=\"text/javascript\">\n//<![CDATA[\n...code...\n//]]>\n</script>" | ||
, "noscript": "<script type=\"imno/script\" id=plates-forgot><h3>\n Forgot your password?\n <a href=\"#\" class=\"close ss-delete\"></a>\n </h3>\n\n <p>Tell us your username and we will reset it for you.</p>\n\n <p class=\"error alert\"></p>\n <p class=\"success alert\"></p></script>" | ||
, "empty": "<h1 class=\"slide nodejs\">a</h1><h2 name=\"\">b</h2><h3 id=\"lol\">c</h3><h4 disabled=\"disabled\">d</h4><h5 autofocus=true>e</h5><h6 itemscope>f</h6>" | ||
, "scripts": "<script type=text/javascript src=//use.typekit.net/gmp8svh.js></script> <script type=text/javascript>" | ||
, "doctype": { | ||
"data": "!doctype html" | ||
, "type": "directive" | ||
, "name": "!doctype" | ||
} | ||
, "block": { | ||
"type": "tag" | ||
, "name": "section" | ||
, "attribs": null | ||
, "children": null | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
} | ||
, "inline": { | ||
"type": "tag" | ||
, "name": "strong" | ||
, "children": null | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
} | ||
, "singular": { | ||
"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 ", | ||
"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>", | ||
"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>", | ||
"newlines": "<li>We're <a href=\"http://nodejitsu.com\">Nodejitsu</a>, and we can give you scalable,\nfault-tolerant cloud hosting for your Node.js apps - and we're the best you'll\nfind.</li>", | ||
"spacing": "<strong>npm</strong>. You don't have to worry\n about installing npm since it comes bundled with Node.js.\n\n <pre class=\"copy\">$ <span>npm install jitsu -g</span><a href=\"#\"><s class=\"ss-layers\" role=\"presentation\"></s> copy</a></pre>\n", | ||
"full": "<!doctype html>\n<html class=\"no-js\">\n<head>\n</head>\n<body class=\"container\">\n<section class=\"navigation\" id=\"navigation\">\n <nav class=\"row\">\n <h1>\n <a href=\"/\" class=\"logo\" title=\"Back to the homepage\">Nodejitsu</a>\n </h1>\n <a href=\"#navigation\" class=\"mobile btn ss-rows\"></a>\n\n\n\n <a href=\"/paas\" >\n Cloud\n </a>\n\n <a href=\"/enterprise/private-cloud\" >\n Enterprise\n </a>\n </section>\n <input type=\"text\" name=\"temp\">\n</body>\n </html>", | ||
"cdata": "<script type=\"text/javascript\">\n//<![CDATA[\n...code...\n//]]>\n</script>", | ||
"noscript": "<script type=\"imno/script\" id=plates-forgot><h3>\n Forgot your password?\n <a href=\"#\" class=\"close ss-delete\"></a>\n </h3>\n\n <p>Tell us your username and we will reset it for you.</p>\n\n <p class=\"error alert\"></p>\n <p class=\"success alert\"></p></script>", | ||
"empty": "<h1 class=\"slide nodejs\">a</h1><h2 name=\"\">b</h2><h3 id=\"lol\">c</h3><h4 disabled=\"disabled\">d</h4><h5 autofocus=true>e</h5><h6 itemscope>f</h6>", | ||
"scripts": "<script type=text/javascript src=//use.typekit.net/gmp8svh.js></script> <script type=text/javascript>", | ||
"styles": "<style> .test { color: #FFF }</style><style>.test { color: black }</style>", | ||
"doctype": { | ||
"data": "!doctype html", | ||
"type": "directive", | ||
"name": "!doctype" | ||
}, | ||
"block": { | ||
"type": "tag", | ||
"name": "section", | ||
"attribs": null, | ||
"children": null, | ||
"prev": null, | ||
"next": null, | ||
"parent": null | ||
}, | ||
"inline": { | ||
"type": "tag", | ||
"name": "strong", | ||
"children": null, | ||
"prev": null, | ||
"next": null, | ||
"parent": null | ||
}, | ||
"style": { | ||
"type": "style", | ||
"name": "style", | ||
"children": [{ "data": ".test { color: white }", "type": "text"}] | ||
}, | ||
"singular": { | ||
"attribs": { | ||
"type": "text", | ||
"name": "temp" | ||
}, | ||
"type": "tag", | ||
"name": "input", | ||
"children": [], | ||
"prev": null, | ||
"next": null, | ||
"parent": null | ||
}, | ||
"attribs": { | ||
"type": "text", | ||
"name": "temp-name", | ||
"class": "some classes with spaces", | ||
"href": "http://without.params.com", | ||
"hrefparam": "http://with.params.com?test=test" | ||
}, | ||
"script": { | ||
"type": "script", | ||
"name": "script", | ||
"attribs": { "type": "text/javascript" }, | ||
"children": null, | ||
"prev": null, | ||
"next": null, | ||
"parent": null | ||
}, | ||
"structure": { | ||
"type": "tag", | ||
"name": "textarea", | ||
"children": null, | ||
"prev": null, | ||
"next": null, | ||
"parent": null | ||
}, | ||
"text": { | ||
"data": "some random text", | ||
"type": "text" | ||
}, | ||
"multiline": { | ||
"data": "some additional lines.\n\n some random text, and alot of spaces", | ||
"type": "text" | ||
}, | ||
"element": { | ||
"type": "tag", | ||
"name": "html", | ||
"attribs": { | ||
"class": "no-js" | ||
}, | ||
"prev": null, | ||
"next": null, | ||
"parent": null, | ||
"children": [ | ||
{ | ||
"type": "tag", | ||
"name": "head", | ||
"attribs": {}, | ||
"children": [], | ||
"prev": null, | ||
"next": null, | ||
"parent": null | ||
}, | ||
{ | ||
"type": "tag", | ||
"name": "body", | ||
"attribs": { | ||
"type": "text" | ||
, "name": "temp" | ||
} | ||
, "type": "tag" | ||
, "name": "input" | ||
, "children": [] | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
} | ||
, "attribs": { | ||
"type": "text" | ||
, "name": "temp-name" | ||
, "class": "some classes with spaces" | ||
, "href": "http://without.params.com" | ||
, "hrefparam": "http://with.params.com?test=test" | ||
} | ||
, "script": { | ||
"type": "script" | ||
, "name": "script" | ||
, "attribs": { "type": "text/javascript" } | ||
, "children": null | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
} | ||
, "structure": { | ||
"type": "tag" | ||
, "name": "textarea" | ||
, "children": null | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
} | ||
, "text": { | ||
"data": "some random text" | ||
, "type": "text" | ||
} | ||
, "multiline": { | ||
"data": "some additional lines.\n\n some random text, and alot of spaces" | ||
, "type": "text" | ||
} | ||
, "element": { | ||
"type": "tag" | ||
, "name": "html" | ||
, "attribs": { | ||
"class": "no-js" | ||
} | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
, "children": [ | ||
{ | ||
"type": "tag" | ||
, "name": "head" | ||
, "attribs": {} | ||
, "children": [] | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
} | ||
, { | ||
"type": "tag" | ||
, "name": "body" | ||
, "attribs": { | ||
"class": "container" | ||
} | ||
, "children": [] | ||
, "prev": null | ||
, "next": null | ||
, "parent": null | ||
} | ||
] | ||
} | ||
"class": "container" | ||
}, | ||
"children": [], | ||
"prev": null, | ||
"next": null, | ||
"parent": null | ||
} | ||
] | ||
} | ||
} |
@@ -37,2 +37,7 @@ /*global beforeEach, afterEach*/ | ||
it('which has a function isStyle', function () { | ||
expect(helpers).to.have.property('isStyle'); | ||
expect(helpers.isStyle).to.be.a('function'); | ||
}); | ||
it('which has a function structure', function () { | ||
@@ -305,2 +310,8 @@ expect(helpers).to.have.property('structure'); | ||
describe('function isStyle', function () { | ||
it('returns true if an element is of type style', function () { | ||
expect(helpers.isStyle(html.style)).to.be.true; | ||
}); | ||
}); | ||
describe('function isJS', function () { | ||
@@ -454,5 +465,6 @@ afterEach(function () { | ||
describe('node collection', function () { | ||
it('matches tag or script', function () { | ||
it('matches tag, style or script', function () { | ||
expect(!!~helpers.node.indexOf('tag')).to.be.true; | ||
expect(!!~helpers.node.indexOf('script')).to.be.true; | ||
expect(!!~helpers.node.indexOf('style')).to.be.true; | ||
}); | ||
@@ -459,0 +471,0 @@ }); |
@@ -108,2 +108,9 @@ 'use strict'; | ||
it('should leave style element content intact', function (done) { | ||
minimize.parse(html.styles, function (error, result) { | ||
expect(result).to.equal("<style>.test { color: #FFF }</style><style>.test { color: black }</style>"); | ||
done(); | ||
}); | ||
}); | ||
it('should minify script content that is not real text/javascript as much as possible', function (done) { | ||
@@ -110,0 +117,0 @@ minimize.parse(html.noscript, function (error, result) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50143
1087