File tree 4 files changed +50
-4
lines changed
4 files changed +50
-4
lines changed Original file line number Diff line number Diff line change
1
+ /// <reference types="node"/>
2
+ import { Metadata , PNG , PNGOptions } from 'pngjs' ;
3
+
4
+ /**
5
+ Parse a PNG.
6
+
7
+ @param buffer - A PNG image buffer.
8
+ @param options - See the [pngjs options](https://github.com/lukeapage/pngjs#options).
9
+ @returns The parsed PNG image.
10
+
11
+ @example
12
+ ```
13
+ import * as fs from 'fs';
14
+ import parsePng = require('parse-png');
15
+
16
+ (async () => {
17
+ const png = await parsePng(fs.readFileSync('unicorn.png'));
18
+
19
+ png.adjustGamma();
20
+ png.pack().pipe(fs.createWriteStream('unicorn-adjusted.png'));
21
+ })();
22
+ ```
23
+ */
24
+ declare function parsePng (
25
+ buffer : Buffer ,
26
+ options ?: PNGOptions
27
+ ) : Promise < PNG & Metadata > ;
28
+
29
+ export = parsePng ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
const { PNG } = require ( 'pngjs' ) ;
3
3
4
- module . exports = async ( buffer , opts ) => {
4
+ module . exports = async ( buffer , options ) => {
5
5
if ( ! Buffer . isBuffer ( buffer ) ) {
6
6
throw new TypeError ( `Expected \`buffer\` to be of type \`Buffer\` but received type \`${ typeof buffer } \`` ) ;
7
7
}
8
8
9
9
return new Promise ( ( resolve , reject ) => {
10
- let png = new PNG ( opts ) ;
10
+ let png = new PNG ( options ) ;
11
11
12
12
png . on ( 'metadata' , data => {
13
13
png = Object . assign ( png , data ) ;
Original file line number Diff line number Diff line change
1
+ /// <reference types="node"/>
2
+ import { expectError , expectType } from 'tsd' ;
3
+ import { Metadata , PNG , PNGOptions } from 'pngjs' ;
4
+ import parsePng = require( '.' ) ;
5
+
6
+ expectType < Promise < PNG & Metadata > > ( parsePng ( Buffer . from ( 'foo' ) ) ) ;
7
+ expectType < Promise < PNG & Metadata > > (
8
+ parsePng ( Buffer . from ( 'foo' ) , {
9
+ width : 0 ,
10
+ bgColor : { red : 0 , green : 0 , blue : 0 }
11
+ } )
12
+ ) ;
13
+ expectError ( parsePng ( Buffer . from ( 'foo' ) , { foo : 'bar' } ) ) ;
Original file line number Diff line number Diff line change 13
13
"node" : " >=10"
14
14
},
15
15
"scripts" : {
16
- "test" : " xo && ava"
16
+ "test" : " xo && ava && tsd "
17
17
},
18
18
"files" : [
19
- " index.js"
19
+ " index.js" ,
20
+ " index.d.ts"
20
21
],
21
22
"keywords" : [
22
23
" parse" ,
27
28
"pngjs" : " ^3.3.0"
28
29
},
29
30
"devDependencies" : {
31
+ "@types/node" : " ^12.7.5" ,
32
+ "@types/pngjs" : " ^3.3.2" ,
30
33
"ava" : " ^2.4.0" ,
31
34
"file-type" : " ^7.2.0" ,
32
35
"get-stream" : " ^3.0.0" ,
36
+ "tsd" : " ^0.7.4" ,
33
37
"xo" : " ^0.24.0"
34
38
}
35
39
}
You can’t perform that action at this time.
0 commit comments