Skip to content

Commit 6171817

Browse files
committedSep 18, 2019
Require Node.js 10
1 parent 0773f8f commit 6171817

File tree

7 files changed

+32
-34
lines changed

7 files changed

+32
-34
lines changed
 

‎.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[.yml]
10+
[*.yml]
1111
indent_style = space
1212
indent_size = 2

‎.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

‎.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: node_js
22
node_js:
3-
- '8'
4-
- '6'
5-
- '4'
3+
- '12'
4+
- '10'

‎index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
2-
const PNG = require('pngjs').PNG;
2+
const {PNG} = require('pngjs');
33

4-
module.exports = (buf, opts) => {
5-
if (!Buffer.isBuffer(buf)) {
6-
return Promise.reject(new TypeError('Expected a buffer'));
4+
module.exports = async (buffer, opts) => {
5+
if (!Buffer.isBuffer(buffer)) {
6+
throw new TypeError(`Expected \`buffer\` to be of type \`Buffer\` but received type \`${typeof buffer}\``);
77
}
88

99
return new Promise((resolve, reject) => {
@@ -16,6 +16,6 @@ module.exports = (buf, opts) => {
1616
png.on('error', reject);
1717
png.on('parsed', () => resolve(png));
1818

19-
png.end(buf);
19+
png.end(buffer);
2020
});
2121
};

‎package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "github.com/kevva"
1111
},
1212
"engines": {
13-
"node": ">=4"
13+
"node": ">=10"
1414
},
1515
"scripts": {
1616
"test": "xo && ava"
@@ -27,10 +27,9 @@
2727
"pngjs": "^3.3.0"
2828
},
2929
"devDependencies": {
30-
"ava": "*",
30+
"ava": "^2.4.0",
3131
"file-type": "^7.2.0",
3232
"get-stream": "^3.0.0",
33-
"pify": "^3.0.0",
34-
"xo": "*"
33+
"xo": "^0.24.0"
3534
}
3635
}

‎readme.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ $ npm install parse-png
1616
const fs = require('fs');
1717
const parsePng = require('parse-png');
1818

19-
parsePng(fs.readFileSync('unicorn.png')).then(png => {
19+
(async () => {
20+
const png = await parsePng(fs.readFileSync('unicorn.png'));
21+
2022
console.log(png);
2123
/*
2224
{
@@ -35,15 +37,15 @@ parsePng(fs.readFileSync('unicorn.png')).then(png => {
3537

3638
png.adjustGamma();
3739
png.pack().pipe(fs.createWriteStream('unicorn-adjusted.png'));
38-
});
40+
})();
3941
```
4042

4143

4244
## API
4345

44-
### parsePng(buffer, [options])
46+
### parsePng(buffer, options?)
4547

46-
Returns a `Promise` for a PNG instance. See the [pngjs documentation](https://github.com/lukeapage/pngjs#async-api) for more information.
48+
Returns a `Promise<Object>` with a PNG instance. See the [pngjs documentation](https://github.com/lukeapage/pngjs#async-api) for more information.
4749

4850
#### buffer
4951

@@ -56,8 +58,3 @@ A PNG image buffer.
5658
Type: `Object`
5759

5860
See the [pngjs options](https://github.com/lukeapage/pngjs#options).
59-
60-
61-
## License
62-
63-
MIT © [Kevin Martensson](http://github.com/kevva)

‎test.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@ import fs from 'fs';
22
import fileType from 'file-type';
33
import getStream from 'get-stream';
44
import test from 'ava';
5-
import m from '.';
5+
import parsePng from '.';
66

77
test('parse', async t => {
8-
const data = await m(fs.readFileSync('./fixture.png'));
9-
t.is(data.width, 200);
10-
t.is(data.height, 133);
11-
t.is(data.depth, 8);
12-
t.true(Buffer.isBuffer(data.data));
8+
const png = await parsePng(fs.readFileSync('./fixture.png'));
9+
t.is(png.width, 200);
10+
t.is(png.height, 133);
11+
t.is(png.depth, 8);
12+
t.true(Buffer.isBuffer(png.data));
1313
});
1414

1515
test('pack', async t => {
16-
const png = await m(fs.readFileSync('./fixture.png'));
16+
const png = await parsePng(fs.readFileSync('./fixture.png'));
1717
t.deepEqual(fileType(await getStream.buffer(png.pack())), {ext: 'png', mime: 'image/png'});
1818
});
1919

2020
test('parse interlaced png', async t => {
21-
const data = await m(fs.readFileSync('./fixture-interlaced.png'));
22-
t.true(data.interlace);
21+
const png = await parsePng(fs.readFileSync('./fixture-interlaced.png'));
22+
t.true(png.interlace);
2323
});
2424

2525
test('pack interlaced png', async t => {
26-
const png = await m(fs.readFileSync('./fixture-interlaced.png'));
26+
const png = await parsePng(fs.readFileSync('./fixture-interlaced.png'));
2727
t.deepEqual(fileType(await getStream.buffer(png.pack())), {ext: 'png', mime: 'image/png'});
2828
});
29+
30+
test('accepts buffer', async t => {
31+
await t.throwsAsync(parsePng('foo'), 'Expected `buffer` to be of type `Buffer` but received type `string`');
32+
});

0 commit comments

Comments
 (0)
Please sign in to comment.