index.d.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. export type Options = {
  9. /**
  10. When this option is `true`, the method returns `false` if the stream has already been closed.
  11. @default true
  12. */
  13. checkOpen?: boolean;
  14. };
  15. /**
  16. @returns Whether `stream` is a [`Stream`](https://nodejs.org/api/stream.html#stream_stream).
  17. @example
  18. ```
  19. import fs from 'node:fs';
  20. import {isStream} from 'is-stream';
  21. isStream(fs.createReadStream('unicorn.png'));
  22. //=> true
  23. isStream({});
  24. //=> false
  25. ```
  26. */
  27. export function isStream(stream: unknown, options?: Options): stream is Stream;
  28. /**
  29. @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).
  30. @example
  31. ```
  32. import fs from 'node:fs';
  33. import {isWritableStream} from 'is-stream';
  34. isWritableStream(fs.createWriteStrem('unicorn.txt'));
  35. //=> true
  36. ```
  37. */
  38. export function isWritableStream(stream: unknown, options?: Options): stream is WritableStream;
  39. /**
  40. @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).
  41. @example
  42. ```
  43. import fs from 'node:fs';
  44. import {isReadableStream} from 'is-stream';
  45. isReadableStream(fs.createReadStream('unicorn.png'));
  46. //=> true
  47. ```
  48. */
  49. export function isReadableStream(stream: unknown, options?: Options): stream is ReadableStream;
  50. /**
  51. @returns Whether `stream` is a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex).
  52. @example
  53. ```
  54. import {Duplex as DuplexStream} from 'node:stream';
  55. import {isDuplexStream} from 'is-stream';
  56. isDuplexStream(new DuplexStream());
  57. //=> true
  58. ```
  59. */
  60. export function isDuplexStream(stream: unknown, options?: Options): stream is DuplexStream;
  61. /**
  62. @returns Whether `stream` is a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform).
  63. @example
  64. ```
  65. import fs from 'node:fs';
  66. import StringifyStream from 'streaming-json-stringify';
  67. import {isTransformStream} from 'is-stream';
  68. isTransformStream(StringifyStream());
  69. //=> true
  70. ```
  71. */
  72. export function isTransformStream(stream: unknown, options?: Options): stream is TransformStream;