Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 30, 2019
1 parent 6ce8a90 commit 7049509
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ os:
- windows
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
79 changes: 40 additions & 39 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
export interface Options {
/**
* Speed `10` has 5% lower quality, but is about 8 times faster than the default. Speed `11` disables dithering and lowers compression level.
*
* Values: `1` (brute-force) to `11` (fastest)
*
* @default 3
*/
Speed `10` has 5% lower quality, but is about 8 times faster than the default. Speed `11` disables dithering and lowers compression level.
Values: `1` (brute-force) to `11` (fastest)
@default 3
*/
speed?: number;

/**
* Remove optional metadata.
*
* @default false
*/
Remove optional metadata.
@default false
*/
strip?: boolean;

/**
* Instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved.
* Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG.
*
* Values: `[0...1, 0...1]`
*
* @example [0.3, 0.5]
*/
Instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved.
Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG.
Values: `[0...1, 0...1]`
@example [0.3, 0.5]
*/
quality?: [number, number];

/**
* Set the dithering level using a fractional number between 0 (none) and 1 (full).
* Pass in `false` to disable dithering.
*
* Values: 0...1
*
* @default 1
*/
Set the dithering level using a fractional number between 0 (none) and 1 (full).
Pass in `false` to disable dithering.
Values: 0...1
@default 1
*/
dithering?: number | boolean;

/**
* Truncate number of least significant bits of color (per channel).
* Use this when image will be output on low-depth displays (e.g. 16-bit RGB). pngquant will make almost-opaque pixels fully opaque and will reduce amount of semi-transparent colors.
*/
Truncate number of least significant bits of color (per channel).
Use this when image will be output on low-depth displays (e.g. 16-bit RGB). pngquant will make almost-opaque pixels fully opaque and will reduce amount of semi-transparent colors.
*/
posterize?: number;

/**
* Print verbose status messages.
*
* @default false
*/
Print verbose status messages.
@default false
*/
verbose?: boolean;
}

/**
* Buffer or stream to optimize.
*
* @returns A `Promise` for a `Buffer`.
*/
Buffer or stream to optimize.
*/
export type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise<Buffer>

/**
* Imagemin plugin for pngquant.
*
* @returns An Imagemin plugin.
*/
Imagemin plugin for pngquant.
@returns An Imagemin plugin.
*/
export default function imageminPngquant(options?: Options): Plugin;
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ const imageminPngquant = (options = {}) => input => {
args.push('--verbose');
}

const cp = execa(pngquant, args, {
const subprocess = execa(pngquant, args, {
encoding: null,
maxBuffer: Infinity,
input
});

const promise = cp
.then(result => result.stdout)
const promise = subprocess
.then(result => result.stdout) // eslint-disable-line promise/prefer-await-to-then
.catch(error => {
if (error.code === 99) {
return input;
Expand All @@ -71,10 +71,10 @@ const imageminPngquant = (options = {}) => input => {
throw error;
});

cp.stdout.then = promise.then.bind(promise);
cp.stdout.catch = promise.catch.bind(promise);
subprocess.stdout.then = promise.then.bind(promise); // eslint-disable-line promise/prefer-await-to-then
subprocess.stdout.catch = promise.catch.bind(promise);

return cp.stdout;
return subprocess.stdout;
};

module.exports = imageminPngquant;
Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import {expectType} from 'tsd-check';
import {expectType} from 'tsd';
import imageminPngquant from '.';

const buffer = await fs.readFileSync(path.join(__dirname, 'fixture.png'));
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"license": "MIT",
"repository": "imagemin/imagemin-pngquant",
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -18,24 +18,23 @@
"compress",
"image",
"imageminplugin",
"img",
"minify",
"optimize",
"png",
"pngquant"
],
"dependencies": {
"execa": "^1.0.0",
"is-png": "^1.0.0",
"is-stream": "^1.1.0",
"ow": "^0.8.0",
"is-png": "^2.0.0",
"is-stream": "^2.0.0",
"ow": "^0.13.2",
"pngquant-bin": "^5.0.0"
},
"devDependencies": {
"@types/node": "^10.12.18",
"@types/node": "^12.0.3",
"ava": "^1.0.1",
"get-stream": "^4.1.0",
"tsd-check": "^0.3.0",
"xo": "^0.23.0"
"get-stream": "^5.1.0",
"tsd": "^0.7.3",
"xo": "^0.24.0"
}
}
15 changes: 5 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const imageminPngquant = require('imagemin-pngquant');

## API

### imageminPngquant([options])(input)
### imageminPngquant(options?)(input)

Returns a `Promise` for a `Buffer`.
Returns `Promise<Buffer>`.

#### options

Type: `Object`
Type: `object`

##### speed

Expand Down Expand Up @@ -67,7 +67,7 @@ Min and max are numbers in range 0 (worst) to 1 (perfect), similar to JPEG.

##### dithering

Type: `number` `boolean`<br>
Type: `number | boolean`<br>
Default: `1` (full)<br>
Values: `0...1`

Expand All @@ -90,11 +90,6 @@ Print verbose status messages.

#### input

Type: `Buffer` `Stream`
Type: `Buffer | Stream`

Buffer or stream to optimize.


## License

MIT © [Imagemin](https://github.com/imagemin)

0 comments on commit 7049509

Please sign in to comment.