Skip to content

Commit

Permalink
Add prettier, reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
GeKorm committed Sep 12, 2018
1 parent 4df0c6a commit 02864ae
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "none",
"singleQuote": true,
"printWidth": 80,
"arrowParens": "always"
}
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

var through2 = require('through2');
var through2 = require('through2');
var PluginError = require('plugin-error');
var bufferMode = require('./lib/buffer');
var streamMode = require('./lib/stream');
var bufferMode = require('./lib/buffer');
var streamMode = require('./lib/stream');
var defaults = require('defaults');
var bytes = require('bytes');

Expand All @@ -21,17 +21,16 @@ var PLUGIN_NAME = 'gulp-zopfli';
* @returns {Stream}
*/
module.exports = function(options) {

options = options || {};
defaults(options, {
format: 'gzip',
append: true,
threshold: false,
zopfliOptions: {}
});
if(options.threshold) {
if(typeof options.threshold != 'number') {
if(typeof options.threshold == 'string') {
if (options.threshold) {
if (typeof options.threshold != 'number') {
if (typeof options.threshold == 'string') {
options.threshold = bytes(options.threshold) || 150;
} else {
options.threshold = 150;
Expand All @@ -41,12 +40,12 @@ module.exports = function(options) {
}

var ext = '';
if(options.append) {
if(options.format === 'gzip') {
if (options.append) {
if (options.format === 'gzip') {
ext = '.gz';
} else if(options.format === 'deflate') {
} else if (options.format === 'deflate') {
ext = '.deflate';
} else if(options.format === 'zlib') {
} else if (options.format === 'zlib') {
ext = '.zz';
}
}
Expand All @@ -55,7 +54,6 @@ module.exports = function(options) {
stream.options = options;

function compress(file, enc, done) {

/*jshint validthis: true */
var self = this;

Expand Down Expand Up @@ -83,7 +81,7 @@ module.exports = function(options) {
};

// Check if file contents is a buffer or a stream
if(file.isBuffer()) {
if (file.isBuffer()) {
bufferMode(file.contents, options, finished);
} else {
streamMode(file.contents, options, finished);
Expand Down
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const through2 = require('through2');
const zopfli = require('@gfx/zopfli');
const Readable = require('stream').Readable;
const toArray = require('stream-to-array');
const toArray = require('stream-to-array');
const compress = require('./compress');

module.exports = function(contents, options, callback) {
Expand All @@ -29,7 +29,7 @@ module.exports = function(contents, options, callback) {
rs.pipe(compressStream);

// Turn gzip stream back into a buffer
toArray(compressStream, function (err, chunks) {
toArray(compressStream, function(err, chunks) {
if (err) {
callback(err, null, false);
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const zopfli = require('@gfx/zopfli');
const zopfli = require('@gfx/zopfli');
const through2 = require('through2');

const formats = ['gzip', 'deflate', 'zlib'];

module.exports = ({ format, zopfliOptions }, callback) => {
if (!formats.includes(format)) {
callback("incorrect format : " + format, null, false);
callback('incorrect format : ' + format, null, false);
return;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ const toArray = require('stream-to-array');
const compress = require('./compress');

module.exports = function(contents, options, callback) {

const compressStream = compress(options, callback);
if (!compressStream) return;

// Check if the threshold option is set
if (options.threshold) {
// Check if the stream contents is less than the threshold
toArray(contents, function (err, chunks) {
toArray(contents, function(err, chunks) {
if (err) {
callback(err, null, false);
return;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-zopfli-green",
"version": "3.0.0-beta.1",
"version": "3.0.0-beta.2",
"description": "Updated Zopfli compressor for gulp",
"keywords": [
"gulpplugin",
Expand Down Expand Up @@ -49,6 +49,7 @@
"jshint": "^2.9.6",
"mocha": "^5.2.0",
"nid": "^0.3.2",
"prettier": "^1.14.2",
"should": "^13.2.1"
},
"resolutions": {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=

prettier@^1.14.2:
version "1.14.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.2.tgz#0ac1c6e1a90baa22a62925f41963c841983282f9"
integrity sha512-McHPg0n1pIke+A/4VcaS2en+pTNjy4xF+Uuq86u/5dyDO59/TtFZtQ708QIRkEZ3qwKz3GVkVa6mpxK/CpB8Rg==

pretty-hrtime@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"
Expand Down

0 comments on commit 02864ae

Please sign in to comment.