From ee79742e583587f2876aab964604ecbd1b80088a Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Thu, 2 Apr 2020 23:33:59 +0200 Subject: [PATCH] prettier --write '**/*.{js,md}' --- README.md | 27 +++++++++++++-------------- lib/PngQuant.js | 26 +++++++++++++------------- test/PngQuant.js | 28 ++++++++++++++-------------- 3 files changed, 40 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index c7340fe..98cd20a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -node-pngquant -============= +# node-pngquant [![NPM version](https://badge.fury.io/js/pngquant.svg)](http://badge.fury.io/js/pngquant) [![Build Status](https://travis-ci.org/papandreou/node-pngquant.svg?branch=master)](https://travis-ci.org/papandreou/node-pngquant) @@ -13,7 +12,7 @@ the `pngquant` binary (defaults to `[256]`): ```javascript var PngQuant = require('pngquant'), - myPngQuanter = new PngQuant([192, '--quality', '60-80', '--nofs', '-']); + myPngQuanter = new PngQuant([192, '--quality', '60-80', '--nofs', '-']); sourceStream.pipe(myPngQuanter).pipe(destinationStream); ``` @@ -23,27 +22,27 @@ quantized to 128): ```javascript var PngQuant = require('pngquant'), - http = require('http'); + http = require('http'); -http.createServer(function (req, res) { +http + .createServer(function (req, res) { if (req.headers['content-type'] === 'image/png') { - res.writeHead(200, {'Content-Type': 'image/png'}); - req.pipe(new PngQuant([128])).pipe(res); + res.writeHead(200, { 'Content-Type': 'image/png' }); + req.pipe(new PngQuant([128])).pipe(res); } else { - res.writeHead(400); - res.end('Feed me a PNG!'); + res.writeHead(400); + res.end('Feed me a PNG!'); } -}).listen(1337); + }) + .listen(1337); ``` -Installation ------------- +## Installation Make sure you have node.js and npm installed, and that the `pngquant` binary is in your PATH, then run: npm install pngquant -License -------- +## License 3-clause BSD license -- see the `LICENSE` file for details. diff --git a/lib/PngQuant.js b/lib/PngQuant.js index ac3ff7a..f694b3e 100644 --- a/lib/PngQuant.js +++ b/lib/PngQuant.js @@ -22,7 +22,7 @@ function PngQuant(pngQuantArgs) { util.inherits(PngQuant, Stream); -PngQuant.getBinaryPath = memoizeAsync(cb => { +PngQuant.getBinaryPath = memoizeAsync((cb) => { if (PngQuant.binaryPath !== undefined) { setImmediate(() => { cb(null, PngQuant.binaryPath); @@ -46,11 +46,11 @@ PngQuant.getBinaryPath = memoizeAsync(cb => { }); }); -PngQuant.setBinaryPath = binaryPath => { +PngQuant.setBinaryPath = (binaryPath) => { PngQuant.binaryPath = binaryPath; }; -PngQuant.prototype._error = function(err) { +PngQuant.prototype._error = function (err) { if (!this.hasEnded) { this.hasEnded = true; this.cleanUp(); @@ -58,7 +58,7 @@ PngQuant.prototype._error = function(err) { } }; -PngQuant.prototype.cleanUp = function() { +PngQuant.prototype.cleanUp = function () { if (this.pngQuantProcess) { this.pngQuantProcess.kill(); this.pngQuantProcess = null; @@ -66,7 +66,7 @@ PngQuant.prototype.cleanUp = function() { this.bufferedChunks = null; }; -PngQuant.prototype.destroy = function() { +PngQuant.prototype.destroy = function () { if (!this.hasEnded) { this.hasEnded = true; this.cleanUp(); @@ -74,7 +74,7 @@ PngQuant.prototype.destroy = function() { } }; -PngQuant.prototype.write = function(chunk) { +PngQuant.prototype.write = function (chunk) { if (this.hasEnded) { return; } @@ -98,7 +98,7 @@ PngQuant.prototype.write = function(chunk) { this.pngQuantProcess.stdin.once('error', this._error.bind(this)); this.pngQuantProcess.stdout.once('error', this._error.bind(this)); - this.pngQuantProcess.stderr.on('data', data => { + this.pngQuantProcess.stderr.on('data', (data) => { if (!this.hasEnded) { this._error( new Error( @@ -109,7 +109,7 @@ PngQuant.prototype.write = function(chunk) { } }); - this.pngQuantProcess.once('exit', exitCode => { + this.pngQuantProcess.once('exit', (exitCode) => { if (this.hasEnded) { return; } @@ -124,7 +124,7 @@ PngQuant.prototype.write = function(chunk) { }); this.pngQuantProcess.stdout - .on('data', chunk => { + .on('data', (chunk) => { this.seenDataOnStdout = true; this.emit('data', chunk); }) @@ -147,7 +147,7 @@ PngQuant.prototype.write = function(chunk) { if (this.pauseStdoutOfPngQuantProcessAfterStartingIt) { this.pngQuantProcess.stdout.pause(); } - this.bufferedChunks.forEach(function(bufferedChunk) { + this.bufferedChunks.forEach(function (bufferedChunk) { // In node.js 12.6.0+ the error event be invoked syncronously, which means // that we might clean up between the chunks. Guard against dereferencing // 'stdin' of null in that case: @@ -169,7 +169,7 @@ PngQuant.prototype.write = function(chunk) { } }; -PngQuant.prototype.end = function(chunk) { +PngQuant.prototype.end = function (chunk) { if (this.hasEnded) { return; } @@ -186,7 +186,7 @@ PngQuant.prototype.end = function(chunk) { } }; -PngQuant.prototype.pause = function() { +PngQuant.prototype.pause = function () { if (this.pngQuantProcess) { this.pngQuantProcess.stdout.pause(); } else { @@ -194,7 +194,7 @@ PngQuant.prototype.pause = function() { } }; -PngQuant.prototype.resume = function() { +PngQuant.prototype.resume = function () { if (this.pngQuantProcess) { this.pngQuantProcess.stdout.resume(); } else { diff --git a/test/PngQuant.js b/test/PngQuant.js index bbe5ce6..11ca37d 100644 --- a/test/PngQuant.js +++ b/test/PngQuant.js @@ -8,7 +8,7 @@ const pathModule = require('path'); const fs = require('fs'); const semver = require('semver'); -it.skipIf = function(condition) { +it.skipIf = function (condition) { (condition ? it.skip : it).apply( it, Array.prototype.slice.call(arguments, 1) @@ -24,7 +24,7 @@ describe('PngQuant', () => { 'when piped through', new PngQuant([128, '--quality', '60-80', '--nofs']), 'to yield output satisfying', - expect.it(resultPngBuffer => { + expect.it((resultPngBuffer) => { expect(resultPngBuffer.length, 'to be within', 0, 8285); }) )); @@ -32,7 +32,7 @@ describe('PngQuant', () => { it.skipIf( semver.satisfies(process.version.replace(/^v/, ''), '>=0.12.0'), 'should not emit data events while paused', - done => { + (done) => { const pngQuant = new PngQuant(); function fail() { @@ -50,7 +50,7 @@ describe('PngQuant', () => { const chunks = []; pngQuant - .on('data', chunk => { + .on('data', (chunk) => { chunks.push(chunk); }) .on('end', () => { @@ -64,24 +64,24 @@ describe('PngQuant', () => { } ); - it('should emit an error if an invalid image is processed', done => { + it('should emit an error if an invalid image is processed', (done) => { const pngQuant = new PngQuant(); pngQuant .on('error', () => { done(); }) - .on('data', chunk => { + .on('data', (chunk) => { done(new Error('PngQuant emitted data when an error was expected')); }) - .on('end', chunk => { + .on('end', (chunk) => { done(new Error('PngQuant emitted end when an error was expected')); }); pngQuant.end(Buffer.from('qwvopeqwovkqvwiejvq', 'utf-8')); }); - it('should emit a single error if an invalid command line is specified', done => { + it('should emit a single error if an invalid command line is specified', (done) => { const pngQuant = new PngQuant(['--blabla']); let seenError = false; @@ -96,10 +96,10 @@ describe('PngQuant', () => { setTimeout(done, 100); } }) - .on('data', chunk => { + .on('data', (chunk) => { done(new Error('PngQuant emitted data when an error was expected')); }) - .on('end', chunk => { + .on('end', (chunk) => { done(new Error('PngQuant emitted end when an error was expected')); }); @@ -110,7 +110,7 @@ describe('PngQuant', () => { it('should kill the underlying child process', () => { const pngQuant = new PngQuant(['-grayscale']); - return expect.promise(run => { + return expect.promise((run) => { pngQuant.write('JFIF'); setTimeout( run(function waitForPngQuantProcess() { @@ -141,10 +141,10 @@ describe('PngQuant', () => { }); expect.addAssertion(' to error', (expect, subject) => - expect.promise(run => { + expect.promise((run) => { subject.once( 'error', - run(err => err) + run((err) => err) ); }) ); @@ -153,7 +153,7 @@ describe('PngQuant', () => { ' to error with ', (expect, subject, value) => { expect.errorMode = 'nested'; - return expect(subject, 'to error').then(err => + return expect(subject, 'to error').then((err) => expect(err, 'to satisfy', value) ); }