1 | import {
|
2 | type Stream,
|
3 | type Writable as WritableStream,
|
4 | type Readable as ReadableStream,
|
5 | type Duplex as DuplexStream,
|
6 | type Transform as TransformStream,
|
7 | } from 'node:stream';
|
8 |
|
9 | export type Options = {
|
10 | /**
|
11 | When this option is `true`, the method returns `false` if the stream has already been closed.
|
12 |
|
13 | @default true
|
14 | */
|
15 | checkOpen?: boolean;
|
16 | };
|
17 |
|
18 | /**
|
19 | @returns Whether `stream` is a [`Stream`](https://nodejs.org/api/stream.html#stream_stream).
|
20 |
|
21 | @example
|
22 | ```
|
23 | import fs from 'node:fs';
|
24 | import {isStream} from 'is-stream';
|
25 |
|
26 | isStream(fs.createReadStream('unicorn.png'));
|
27 | //=> true
|
28 |
|
29 | isStream({});
|
30 | //=> false
|
31 | ```
|
32 | */
|
33 | export function isStream(stream: unknown, options?: Options): stream is Stream;
|
34 |
|
35 | /**
|
36 | @returns Whether `stream` is a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable), an [`http.OutgoingMessage`](https://nodejs.org/api/http.html#class-httpoutgoingmessage), an [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) or an [`http.ClientRequest`](https://nodejs.org/api/http.html#class-httpserverresponse).
|
37 |
|
38 | @example
|
39 | ```
|
40 | import fs from 'node:fs';
|
41 | import {isWritableStream} from 'is-stream';
|
42 |
|
43 | isWritableStream(fs.createWriteStrem('unicorn.txt'));
|
44 | //=> true
|
45 | ```
|
46 | */
|
47 | export function isWritableStream(stream: unknown, options?: Options): stream is WritableStream;
|
48 |
|
49 | /**
|
50 | @returns Whether `stream` is a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable) or an [`http.IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage).
|
51 |
|
52 | @example
|
53 | ```
|
54 | import fs from 'node:fs';
|
55 | import {isReadableStream} from 'is-stream';
|
56 |
|
57 | isReadableStream(fs.createReadStream('unicorn.png'));
|
58 | //=> true
|
59 | ```
|
60 | */
|
61 | export function isReadableStream(stream: unknown, options?: Options): stream is ReadableStream;
|
62 |
|
63 | /**
|
64 | @returns Whether `stream` is a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex).
|
65 |
|
66 | @example
|
67 | ```
|
68 | import {Duplex as DuplexStream} from 'node:stream';
|
69 | import {isDuplexStream} from 'is-stream';
|
70 |
|
71 | isDuplexStream(new DuplexStream());
|
72 | //=> true
|
73 | ```
|
74 | */
|
75 | export function isDuplexStream(stream: unknown, options?: Options): stream is DuplexStream;
|
76 |
|
77 | /**
|
78 | @returns Whether `stream` is a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform).
|
79 |
|
80 | @example
|
81 | ```
|
82 | import fs from 'node:fs';
|
83 | import StringifyStream from 'streaming-json-stringify';
|
84 | import {isTransformStream} from 'is-stream';
|
85 |
|
86 | isTransformStream(StringifyStream());
|
87 | //=> true
|
88 | ```
|
89 | */
|
90 | export function isTransformStream(stream: unknown, options?: Options): stream is TransformStream;
|