index.d.ts
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/// <reference types="node"/>
declare namespace imageType {
type ImageType =
| 'jpg'
| 'png'
| 'gif'
| 'webp'
| 'flif'
| 'cr2'
| 'tif'
| 'bmp'
| 'jxr'
| 'psd'
| 'ico'
| 'bpg'
| 'jp2'
| 'jpm'
| 'jpx'
| 'heic'
| 'cur'
| 'dcm';
interface ImageTypeResult {
/**
One of the supported [file types](https://github.com/sindresorhus/image-type#supported-file-types).
*/
ext: ImageType;
/**
The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type).
*/
mime: string;
}
}
declare const imageType: {
/**
Detect the image type of a `Buffer`/`Uint8Array`.
@param input - Input to examine to determine the file type. It only needs the first `.minimumBytes` bytes.
@example
```
import readChunk = require('read-chunk');
import imageType = require('image-type');
const buffer = readChunk.sync('unicorn.png', 0, 12);
imageType(buffer);
//=> {ext: 'png', mime: 'image/png'}
// Or from a remote location:
import * as http from 'http';
const url = 'https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif';
http.get(url, response => {
response.on('readable', () => {
const chunk = response.read(imageType.minimumBytes);
response.destroy();
console.log(imageType(chunk));
//=> {ext: 'gif', mime: 'image/gif'}
});
});
```
*/
(input: Buffer | Uint8Array): imageType.ImageTypeResult | null;
/**
The minimum amount of bytes needed to detect a file type. Currently, it's 4100 bytes, but it can change, so don't hard-code it.
*/
readonly minimumBytes: number;
// TODO: Remove this for the next major release
default: typeof imageType;
};
export = imageType;