From 99ee2c50d9d4edff75bdc47515950b866d01528e Mon Sep 17 00:00:00 2001 From: Borewit Date: Wed, 14 Aug 2024 13:37:15 +0200 Subject: [PATCH] Reuse strtok3 typing for different web stream types (#655) --- core.d.ts | 4 ++-- index.d.ts | 3 ++- package.json | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core.d.ts b/core.d.ts index a8c15319..16179ec9 100644 --- a/core.d.ts +++ b/core.d.ts @@ -3,7 +3,7 @@ Typings for primary entry point, Node.js specific typings can be found in index. */ import type {ReadableStream as WebReadableStream} from 'node:stream/web'; -import type {ITokenizer} from 'strtok3'; +import type {ITokenizer, AnyWebByteStream} from 'strtok3'; /** Either the Node.js ReadableStream or the `lib.dom.d.ts` ReadableStream. @@ -350,7 +350,7 @@ The file type is detected by checking the [magic number](https://en.wikipedia.or @param stream - A [web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) streaming a file to examine. @returns A `Promise` for an object with the detected file type, or `undefined` when there is no match. */ -export function fileTypeFromStream(stream: AnyWebReadableStream): Promise; +export function fileTypeFromStream(stream: AnyWebByteStream): Promise; /** Detect the file type from an [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer) source. diff --git a/index.d.ts b/index.d.ts index 49b1700d..3079ba9a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,6 +3,7 @@ Typings for Node.js specific entry point. */ import type {Readable as NodeReadableStream} from 'node:stream'; +import type {AnyWebByteStream} from 'strtok3'; import type {FileTypeResult, StreamOptions, AnyWebReadableStream, Detector, AnyWebReadableByteStreamWithFileType} from './core.js'; import {FileTypeParser} from './core.js'; @@ -85,6 +86,6 @@ if (stream2.fileType?.mime === 'image/jpeg') { ``` */ export function fileTypeStream(readableStream: NodeReadableStream, options?: StreamOptions): Promise; -export function fileTypeStream(webStream: AnyWebReadableStream, options?: StreamOptions): Promise; +export function fileTypeStream(webStream: AnyWebByteStream, options?: StreamOptions): Promise; export * from './core.js'; diff --git a/package.json b/package.json index 7533550b..8d8720b4 100644 --- a/package.json +++ b/package.json @@ -219,7 +219,7 @@ ], "dependencies": { "get-stream": "^9.0.1", - "strtok3": "^8.0.0", + "strtok3": "^8.1.0", "token-types": "^6.0.0", "uint8array-extras": "^1.3.0" },