diff --git a/browser.d.ts b/browser.d.ts index 638656b2..eecfd80c 100644 --- a/browser.d.ts +++ b/browser.d.ts @@ -22,7 +22,7 @@ const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg'; })(); ``` */ -export declare function fromStream(stream: ReadableStream): Promise; +export declare function fromStream(stream: ReadableStream): Promise; /** Determine file type from a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob). @@ -41,7 +41,7 @@ import FileType = require('file-type/browser'); })(); ``` */ -export declare function fromBlob(blob: Blob): Promise; +export declare function fromBlob(blob: Blob): Promise; export { fromBuffer, diff --git a/core.d.ts b/core.d.ts index f52526d4..ab4ec89b 100644 --- a/core.d.ts +++ b/core.d.ts @@ -245,12 +245,12 @@ declare namespace core { /** One of the supported [file types](https://github.com/sindresorhus/file-type#supported-file-types). */ - ext: FileExtension; + readonly ext: FileExtension; /** The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type). */ - mime: MimeType; + readonly mime: MimeType; } type ReadableStreamWithFileType = ReadableStream & { @@ -306,7 +306,7 @@ declare namespace core { @param tokenizer - File source implementing the tokenizer interface. @returns The detected file type and MIME type, or `undefined` when there is no match. */ - function fromTokenizer(tokenizer: ITokenizer): Promise; + function fromTokenizer(tokenizer: ITokenizer): Promise; /** Deprecated: 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. diff --git a/index.test-d.ts b/index.test-d.ts index b3cc3930..9ecd9437 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,7 +1,9 @@ import * as fs from 'fs'; import {expectType} from 'tsd'; import FileType = require('.'); -import {FileTypeResult, ReadableStreamWithFileType, FileExtension} from '.'; +import {FileTypeResult, ReadableStreamWithFileType, FileExtension, MimeType} from '.'; +import FileTypeBrowser = require('./browser'); +import {FileTypeResult as FileTypeResultBrowser} from './browser'; expectType>(FileType.fromBuffer(new Buffer([0xff, 0xd8, 0xff]))); expectType>(FileType.fromBuffer(new Uint8Array([0xff, 0xd8, 0xff]))); @@ -11,17 +13,17 @@ expectType>(FileType.fromBuffer(new ArrayBuf const result = await FileType.fromBuffer(new Buffer([0xff, 0xd8, 0xff])); if (result !== undefined) { expectType(result.ext); - expectType(result.mime); + expectType(result.mime); } })(); (async () => { expectType(await FileType.fromFile('myFile')); - const fileRes = await FileType.fromFile('myFile'); - if (fileRes !== undefined) { - expectType(fileRes.ext); - expectType(fileRes.mime); + const result = await FileType.fromFile('myFile'); + if (result !== undefined) { + expectType(result.ext); + expectType(result.mime); } })(); @@ -30,10 +32,10 @@ expectType>(FileType.fromBuffer(new ArrayBuf expectType(await FileType.fromStream(stream)); - const fileRes = await FileType.fromStream(stream); - if (fileRes !== undefined) { - expectType(fileRes.ext); - expectType(fileRes.mime); + const result = await FileType.fromStream(stream); + if (result !== undefined) { + expectType(result.ext); + expectType(result.mime); } })(); @@ -50,3 +52,6 @@ expectType>(streamWithFileType); (async () => { expectType((await streamWithFileType).fileType); })(); + +// Browser +expectType>(FileTypeBrowser.fromBlob(new Blob())); diff --git a/package.json b/package.json index 05e1631e..ac8e5387 100644 --- a/package.json +++ b/package.json @@ -173,7 +173,7 @@ "noop-stream": "^0.1.0", "pify": "^4.0.1", "read-chunk": "^3.2.0", - "tsd": "^0.7.0", + "tsd": "^0.11.0", "xo": "^0.25.3" }, "dependencies": {