-
-
Notifications
You must be signed in to change notification settings - Fork 352
/
index.test-d.ts
66 lines (55 loc) · 1.85 KB
/
index.test-d.ts
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
import {createReadStream} from 'node:fs';
import {expectType} from 'tsd';
import {
type FileTypeResult as FileTypeResultBrowser,
} from './core.js';
import {
fileTypeFromBlob,
fileTypeFromBuffer,
fileTypeFromFile,
fileTypeFromStream,
fileTypeStream,
supportedExtensions,
supportedMimeTypes,
type FileTypeResult,
type ReadableStreamWithFileType,
type FileExtension,
type MimeType,
} from './index.js';
expectType<Promise<FileTypeResult | undefined>>(fileTypeFromBuffer(new Uint8Array([0xFF, 0xD8, 0xFF])));
expectType<Promise<FileTypeResult | undefined>>(fileTypeFromBuffer(new ArrayBuffer(42)));
(async () => {
const result = await fileTypeFromBuffer(new Uint8Array([0xFF, 0xD8, 0xFF]));
if (result !== undefined) {
expectType<FileExtension>(result.ext);
expectType<MimeType>(result.mime);
}
})();
(async () => {
expectType<FileTypeResult | undefined>(await fileTypeFromFile('myFile'));
const result = await fileTypeFromFile('myFile');
if (result !== undefined) {
expectType<FileExtension>(result.ext);
expectType<MimeType>(result.mime);
}
})();
(async () => {
const stream = createReadStream('myFile');
expectType<FileTypeResult | undefined>(await fileTypeFromStream(stream));
const result = await fileTypeFromStream(stream);
if (result !== undefined) {
expectType<FileExtension>(result.ext);
expectType<MimeType>(result.mime);
}
})();
expectType<ReadonlySet<FileExtension>>(supportedExtensions);
expectType<ReadonlySet<MimeType>>(supportedMimeTypes);
const readableStream = createReadStream('file.png');
const streamWithFileType = fileTypeStream(readableStream);
expectType<Promise<ReadableStreamWithFileType>>(streamWithFileType);
(async () => {
const {fileType} = await streamWithFileType;
expectType<FileTypeResult | undefined>(fileType);
})();
// Browser
expectType<Promise<FileTypeResultBrowser | undefined>>(fileTypeFromBlob(new Blob([])));