Socket
Socket
Sign inDemoInstall

html-preflight

Package Overview
Dependencies
82
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.4 to 0.3.5

.jshintrc

2

index.js
'use strict';
module.exports = require('./lib/preflight');
var plugins = require('./lib/plugins');
for (var key in plugins) {

@@ -7,0 +7,0 @@ if (plugins.hasOwnProperty(key)) {

@@ -5,11 +5,12 @@ 'use strict';

function MinifierPlugin(opts) {
this.opts = opts || {};
function MinifierPlugin(options) {
this.options = options || {};
return this;
}
MinifierPlugin.prototype.run = function(html, cb) {
MinifierPlugin.prototype.run = function(html, callback) {
try {
return cb(null, minify(html, this.opts));
return callback(null, minify(html, this.options));
} catch(e) {
return cb(e);
return callback(e);
}

@@ -16,0 +17,0 @@ };

@@ -5,15 +5,15 @@ 'use strict';

function PrefixPlugin(opts) {
this.opts = opts;
function PrefixPlugin(options) {
this.options = options || {};
return this;
}
PrefixPlugin.prototype.run = function(html, cb){
PrefixPlugin.prototype.run = function(html, callback) {
try {
return cb(null, htmlAutoprefixer.process(html, this.opts));
} catch(e) {
return cb(e);
return callback(null, htmlAutoprefixer.process(html, this.options));
} catch (e) {
return callback(e);
}
};
module.exports = PrefixPlugin;
'use strict';
var HtmlUglify = require('html-uglify');
var HTMLUglify = require('html-uglify');
function UglifierPlugin(opts) {
this.uglifier = new HtmlUglify(opts);
function UglifierPlugin(options) {
this.options = options || {};
this.uglifier = new HTMLUglify(this.options);
return this;
}
UglifierPlugin.prototype.run = function(html, cb) {
UglifierPlugin.prototype.run = function(html, callback) {
try {
return cb(null, this.uglifier.process(html));
return callback(null, this.uglifier.process(html));
} catch (e) {
return cb(e);
return callback(e);
}

@@ -15,0 +17,0 @@ };

@@ -5,38 +5,40 @@ 'use strict';

var bytes = require('bytes');
var colors = require('colors');
var packageJson = require('./../package.json');
var colors = require('colors/safe');
var generateStats = function (start, end) {
var startbyte = Buffer.byteLength(start.toString(), 'utf8');
var endbyte = Buffer.byteLength(end.toString(), 'utf8');
var delta = ((startbyte-endbyte)/startbyte) *100;
console.log('Starting Filesize: ', colors.inverse(bytes(startbyte)));
console.log('Ending Filesize: ', colors.inverse(bytes(endbyte)));
var VERSION = require('../package.json').version;
function generateStats(originalDoc, doc) {
var initialSize = Buffer.byteLength(originalDoc.toString(), 'utf8');
var finalSize = Buffer.byteLength(doc.toString(), 'utf8');
var delta = ((initialSize - finalSize) / initialSize) * 100;
console.log('Starting Filesize: ', colors.inverse(bytes(initialSize)));
console.log('Ending Filesize: ', colors.inverse(bytes(finalSize)));
console.log('Percent Savings: ', colors.inverse.bold(delta.toFixed(2) + '%'));
console.log('==================');
if (endbyte <= 102400) {
return console.log('The file is under 100kb and will work everywhere!!!'.bold.yellow.bgBlack);
if (finalSize <= 102400) {
console.log(colors.bold.yellow.bgBlack('The file is under 100KiB and will work everywhere.'));
} else {
return console.log('The file is NOT under 100kb and will NOT work everywhere!!!'.bold.red.bgBlack);
console.log(colors.bold.red.bgBlack('The file is NOT under 100KiB and will NOT work everywhere!!!'));
}
};
}
function HTMLPreflight(plugins) {
this.version = VERSION;
this.plugins = plugins || [];
this.version = packageJson.version;
return this;
}
HTMLPreflight.prototype.run = function(doc, options, cb) {
var that = this;
HTMLPreflight.prototype.run = function(originalDoc, options, callback) {
if (arguments.length < 3) {
cb = options;
callback = options;
options = {};
}
if (options.stats) var originalDoc = doc;
that.plugins[0] = async.apply(that.plugins[0], doc);
async.waterfall(that.plugins, function(err, doc) {
var tasks = [async.constant(originalDoc)].concat(this.plugins);
async.waterfall(tasks, function(err, doc) {
if (err) return callback(err, doc);
if (options.stats) generateStats(originalDoc, doc);
return cb(err, doc);
return callback(err, doc);
});

@@ -43,0 +45,0 @@ };

{
"name": "html-preflight",
"version": "0.3.4",
"version": "0.3.5",
"description": "The HTML email preflight process, maximing compression without distortion",
"main": "index.js",
"scripts": {
"coverage": "istanbul cover _mocha test/**/**.test.js -- -R spec",
"test": "mocha test/**/**.test.js"
"test": "istanbul test _mocha -- --recursive"
},

@@ -27,5 +26,5 @@ "keywords": [

"dependencies": {
"async": "^1.0.0",
"async": "^1.4.0",
"bytes": "^2.1.0",
"colors": "^1.1.0",
"colors": "^1.1.2",
"html-autoprefixer": "^0.3.7",

@@ -36,5 +35,6 @@ "html-minifier": "^0.7.2",

"devDependencies": {
"chai": "^2.3.0",
"chai": "^3.2.0",
"istanbul": "^0.3.17",
"mocha": "^2.2.5"
}
}

@@ -16,7 +16,5 @@ # html-preflight

preflight.run(htmlString, {stats: true}, function(err, finalHtml) {
preflight.run(htmlString, { stats: true }, function(err, finalHtml) {
console.log(arguments);
});
```

@@ -27,5 +25,6 @@

### `HTMLPreflight(plugins)`
Takes in an array of functions. This functions will run in the order they were
provided. Each will pass the resulting HTML string to the next function.
Always keep in mind that if your provided function must have access to its
Takes in an array of functions. This functions will run in the order they were
provided. Each will pass the resulting HTML string to the next function.
Always keep in mind that if your provided function must have access to its
scope, you will probably have to bind it to it.

@@ -32,0 +31,0 @@

@@ -5,18 +5,22 @@ 'use strict';

var Minifier = require('./../../lib/plugins').MinifierPlugin;
var Minifier = require('../../lib/plugins').MinifierPlugin;
describe('MinifierPlugin', function() {
describe('#constructor', function() {
it('should not return nil', function() {
it('should not return null', function() {
expect(new Minifier()).to.exist;
});
it('should store opts', function() {
expect(new Minifier(true).opts).to.exist;
it('should store options', function() {
expect(new Minifier(true).options).to.exist;
});
});
describe('#run', function() {
var minifier;
before(function() {
minifier = new Minifier();
});
it('should return err if invalid input', function(done) {

@@ -28,2 +32,3 @@ minifier.run('<htm', function(err) {

});
it('should return result if valid input', function(done) {

@@ -30,0 +35,0 @@ minifier.run('<html></html>', function(err, html) {

@@ -5,18 +5,22 @@ 'use strict';

var Prefixer = require('./../../lib/plugins').PrefixerPlugin;
var Prefixer = require('../../lib/plugins').PrefixerPlugin;
describe('PrefixerPlugin', function() {
describe('#constructor', function() {
it('should not return nil', function() {
it('should not return null', function() {
expect(new Prefixer()).to.exist;
});
it('should store opts', function() {
expect(new Prefixer(true).opts).to.exist;
it('should store options', function() {
expect(new Prefixer(true).options).to.exist;
});
});
describe('#run', function() {
var prefixer;
before(function() {
prefixer = new Prefixer();
});
it('should return err if invalid input', function(done) {

@@ -27,4 +31,4 @@ prefixer.run('<htm', function(err) {

});
});
});
it('should return result if valid input', function(done) {

@@ -31,0 +35,0 @@ prefixer.run('<html></html>', function(err, html) {

@@ -5,18 +5,22 @@ 'use strict';

var Uglifier = require('./../../lib/plugins').UglifierPlugin;
var Uglifier = require('../../lib/plugins').UglifierPlugin;
describe('UglifierPlugin', function() {
describe('#constructor', function() {
it('should not return nil', function() {
it('should not return null', function() {
expect(new Uglifier()).to.exist;
});
it('should create an uglifier with opts', function() {
it('should create an uglifier with options', function() {
expect(new Uglifier(true).uglifier).to.exist;
});
});
describe('#run', function() {
var uglifier;
before(function() {
uglifier = new Uglifier();
});
it('should return err if invalid input', function(done) {

@@ -27,4 +31,4 @@ uglifier.run('<htm', function(err) {

});
});
});
it('should return result if valid input', function(done) {

@@ -31,0 +35,0 @@ uglifier.run('<html></html>', function(err, html) {

'use strict';
var expect = require('chai').expect;
var HTMLPreflight = require('./../lib/preflight');
var HTMLPreflight = require('../lib/preflight');
describe('HTMLPreflight', function() {

@@ -21,5 +22,7 @@ describe('#constructor', function() {

var preflight;
before(function() {
preflight = new HTMLPreflight();
});
it('should return an error if a plugin failed', function(done) {

@@ -36,2 +39,3 @@ var stub = function(html, cb) {

});
it('should return a valid html if plugins succeeded', function(done) {

@@ -41,2 +45,3 @@ var stub = function(html, cb) {

};
preflight.plugins = [stub];

@@ -48,6 +53,4 @@ preflight.run('test', function(err, html) {

});
});
});
});
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