Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-stream

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-stream - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

33

index.d.ts
import {
Stream,
Writable as WritableStream,
Readable as ReadableStream,
Duplex as DuplexStream,
Transform as TransformStream,
type Stream,
type Writable as WritableStream,
type Readable as ReadableStream,
type Duplex as DuplexStream,
type Transform as TransformStream,
} from 'node:stream';
export type Options = {
/**
When this option is `true`, the method returns `false` if the stream has already been closed.
@default: `false` with `isStream()`, `true` with the other methods
*/
checkOpen?: boolean;
};
/**

@@ -24,6 +33,6 @@ @returns Whether `stream` is a [`Stream`](https://nodejs.org/api/stream.html#stream_stream).

*/
export function isStream(stream: unknown): stream is Stream;
export function isStream(stream: unknown, options?: Options): stream is Stream;
/**
@returns Whether `stream` is a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable).
@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).

@@ -39,6 +48,6 @@ @example

*/
export function isWritableStream(stream: unknown): stream is WritableStream;
export function isWritableStream(stream: unknown, options?: Options): stream is WritableStream;
/**
@returns Whether `stream` is a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable).
@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).

@@ -54,3 +63,3 @@ @example

*/
export function isReadableStream(stream: unknown): stream is ReadableStream;
export function isReadableStream(stream: unknown, options?: Options): stream is ReadableStream;

@@ -69,3 +78,3 @@ /**

*/
export function isDuplexStream(stream: unknown): stream is DuplexStream;
export function isDuplexStream(stream: unknown, options?: Options): stream is DuplexStream;

@@ -85,2 +94,2 @@ /**

*/
export function isTransformStream(stream: unknown): stream is TransformStream;
export function isTransformStream(stream: unknown, options?: Options): stream is TransformStream;

@@ -1,29 +0,37 @@

export function isStream(stream) {
export function isStream(stream, {checkOpen = true} = {}) {
return stream !== null
&& typeof stream === 'object'
&& (stream.writable || stream.readable || !checkOpen || (stream.writable === undefined && stream.readable === undefined))
&& typeof stream.pipe === 'function';
}
export function isWritableStream(stream) {
return isStream(stream)
&& stream.writable !== false
&& typeof stream._write === 'function'
&& typeof stream._writableState === 'object';
export function isWritableStream(stream, {checkOpen = true} = {}) {
return isStream(stream, {checkOpen})
&& (stream.writable || !checkOpen)
&& typeof stream.write === 'function'
&& typeof stream.end === 'function'
&& typeof stream.writable === 'boolean'
&& typeof stream.writableObjectMode === 'boolean'
&& typeof stream.destroy === 'function'
&& typeof stream.destroyed === 'boolean';
}
export function isReadableStream(stream) {
return isStream(stream)
&& stream.readable !== false
&& typeof stream._read === 'function'
&& typeof stream._readableState === 'object';
export function isReadableStream(stream, {checkOpen = true} = {}) {
return isStream(stream, {checkOpen})
&& (stream.readable || !checkOpen)
&& typeof stream.read === 'function'
&& typeof stream.readable === 'boolean'
&& typeof stream.readableObjectMode === 'boolean'
&& typeof stream.destroy === 'function'
&& typeof stream.destroyed === 'boolean';
}
export function isDuplexStream(stream) {
return isWritableStream(stream)
&& isReadableStream(stream);
export function isDuplexStream(stream, options) {
return isWritableStream(stream, options)
&& isReadableStream(stream, options);
}
export function isTransformStream(stream) {
return isDuplexStream(stream)
export function isTransformStream(stream, options) {
return isDuplexStream(stream, options)
&& typeof stream._transform === 'function';
}
{
"name": "is-stream",
"version": "3.0.0",
"version": "4.0.0",
"description": "Check if something is a Node.js stream",

@@ -14,5 +14,9 @@ "license": "MIT",

"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=18"
},

@@ -39,8 +43,8 @@ "scripts": {

"devDependencies": {
"@types/node": "^16.4.13",
"ava": "^3.15.0",
"tempy": "^1.0.1",
"tsd": "^0.17.0",
"xo": "^0.44.0"
"@types/node": "^20.11.19",
"ava": "^5.3.1",
"tempy": "^3.1.0",
"tsd": "^0.30.5",
"xo": "^0.57.0"
}
}

@@ -7,5 +7,5 @@ # is-stream

```sh
npm install is-stream
```
$ npm install is-stream
```

@@ -27,36 +27,33 @@ ## Usage

### isStream(stream)
### isStream(stream, options?)
Returns a `boolean` for whether it's a [`Stream`](https://nodejs.org/api/stream.html#stream_stream).
#### isWritableStream(stream)
### isWritableStream(stream, options?)
Returns a `boolean` for whether it's a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable).
Returns a `boolean` for whether it's 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).
#### isReadableStream(stream)
### isReadableStream(stream, options?)
Returns a `boolean` for whether it's a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable).
Returns a `boolean` for whether it's 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).
#### isDuplexStream(stream)
### isDuplexStream(stream, options?)
Returns a `boolean` for whether it's a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex).
#### isTransformStream(stream)
### isTransformStream(stream, options?)
Returns a `boolean` for whether it's a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform).
### Options
#### checkOpen
Type: `boolean`\
Default: `false` with [`isStream()`](#isstreamstream-options), `true` with the other methods
When this option is `true`, the method returns `false` if the stream has already been closed.
## Related
- [is-file-stream](https://github.com/jamestalmage/is-file-stream) - Detect if a stream is a file stream
---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-is-stream?utm_source=npm-is-stream&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc