pax_global_header00006660000000000000000000000064141044551200014506gustar00rootroot0000000000000052 comment=6913e344ab2dd63041bb7c03095876ce5a7e0a8b is-stream-3.0.0/000077500000000000000000000000001410445512000134125ustar00rootroot00000000000000is-stream-3.0.0/.editorconfig000066400000000000000000000002571410445512000160730ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 is-stream-3.0.0/.gitattributes000066400000000000000000000000231410445512000163000ustar00rootroot00000000000000* text=auto eol=lf is-stream-3.0.0/.github/000077500000000000000000000000001410445512000147525ustar00rootroot00000000000000is-stream-3.0.0/.github/funding.yml000066400000000000000000000001631410445512000171270ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/is-stream custom: https://sindresorhus.com/donate is-stream-3.0.0/.github/security.md000066400000000000000000000002631410445512000171440ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. is-stream-3.0.0/.github/workflows/000077500000000000000000000000001410445512000170075ustar00rootroot00000000000000is-stream-3.0.0/.github/workflows/main.yml000066400000000000000000000006261410445512000204620ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 16 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test is-stream-3.0.0/.gitignore000066400000000000000000000000271410445512000154010ustar00rootroot00000000000000node_modules yarn.lock is-stream-3.0.0/.npmrc000066400000000000000000000000231410445512000145250ustar00rootroot00000000000000package-lock=false is-stream-3.0.0/index.d.ts000066400000000000000000000036261410445512000153220ustar00rootroot00000000000000import { Stream, Writable as WritableStream, Readable as ReadableStream, Duplex as DuplexStream, Transform as TransformStream, } from 'node:stream'; /** @returns Whether `stream` is a [`Stream`](https://nodejs.org/api/stream.html#stream_stream). @example ``` import fs from 'node:fs'; import {isStream} from 'is-stream'; isStream(fs.createReadStream('unicorn.png')); //=> true isStream({}); //=> false ``` */ export function isStream(stream: unknown): stream is Stream; /** @returns Whether `stream` is a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable). @example ``` import fs from 'node:fs'; import {isWritableStream} from 'is-stream'; isWritableStream(fs.createWriteStrem('unicorn.txt')); //=> true ``` */ export function isWritableStream(stream: unknown): stream is WritableStream; /** @returns Whether `stream` is a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable). @example ``` import fs from 'node:fs'; import {isReadableStream} from 'is-stream'; isReadableStream(fs.createReadStream('unicorn.png')); //=> true ``` */ export function isReadableStream(stream: unknown): stream is ReadableStream; /** @returns Whether `stream` is a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex). @example ``` import {Duplex as DuplexStream} from 'node:stream'; import {isDuplexStream} from 'is-stream'; isDuplexStream(new DuplexStream()); //=> true ``` */ export function isDuplexStream(stream: unknown): stream is DuplexStream; /** @returns Whether `stream` is a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform). @example ``` import fs from 'node:fs'; import StringifyStream from 'streaming-json-stringify'; import {isTransformStream} from 'is-stream'; isTransformStream(StringifyStream()); //=> true ``` */ export function isTransformStream(stream: unknown): stream is TransformStream; is-stream-3.0.0/index.js000066400000000000000000000013521410445512000150600ustar00rootroot00000000000000export function isStream(stream) { return stream !== null && typeof stream === 'object' && typeof stream.pipe === 'function'; } export function isWritableStream(stream) { return isStream(stream) && stream.writable !== false && typeof stream._write === 'function' && typeof stream._writableState === 'object'; } export function isReadableStream(stream) { return isStream(stream) && stream.readable !== false && typeof stream._read === 'function' && typeof stream._readableState === 'object'; } export function isDuplexStream(stream) { return isWritableStream(stream) && isReadableStream(stream); } export function isTransformStream(stream) { return isDuplexStream(stream) && typeof stream._transform === 'function'; } is-stream-3.0.0/index.test-d.ts000066400000000000000000000012521410445512000162700ustar00rootroot00000000000000import { Stream, Writable as WritableStream, Readable as ReadableStream, Duplex as DuplexStream, Transform as TransformStream, } from 'node:stream'; import {expectAssignable} from 'tsd'; import { isStream, isWritableStream, isReadableStream, isDuplexStream, isTransformStream, } from './index.js'; const foo = ''; if (isStream(foo)) { expectAssignable(foo); } if (isWritableStream(foo)) { expectAssignable(foo); } if (isReadableStream(foo)) { expectAssignable(foo); } if (isDuplexStream(foo)) { expectAssignable(new DuplexStream()); } if (isTransformStream(foo)) { expectAssignable(foo); } is-stream-3.0.0/license000066400000000000000000000021351410445512000147600ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-stream-3.0.0/package.json000066400000000000000000000014521410445512000157020ustar00rootroot00000000000000{ "name": "is-stream", "version": "3.0.0", "description": "Check if something is a Node.js stream", "license": "MIT", "repository": "sindresorhus/is-stream", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "stream", "type", "streams", "writable", "readable", "duplex", "transform", "check", "detect", "is" ], "devDependencies": { "@types/node": "^16.4.13", "ava": "^3.15.0", "tempy": "^1.0.1", "tsd": "^0.17.0", "xo": "^0.44.0" } } is-stream-3.0.0/readme.md000066400000000000000000000031161410445512000151720ustar00rootroot00000000000000# is-stream > Check if something is a [Node.js stream](https://nodejs.org/api/stream.html) ## Install ``` $ npm install is-stream ``` ## Usage ```js import fs from 'node:fs'; import {isStream} from 'is-stream'; isStream(fs.createReadStream('unicorn.png')); //=> true isStream({}); //=> false ``` ## API ### isStream(stream) Returns a `boolean` for whether it's a [`Stream`](https://nodejs.org/api/stream.html#stream_stream). #### isWritableStream(stream) Returns a `boolean` for whether it's a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable). #### isReadableStream(stream) Returns a `boolean` for whether it's a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable). #### isDuplexStream(stream) Returns a `boolean` for whether it's a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex). #### isTransformStream(stream) Returns a `boolean` for whether it's a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform). ## Related - [is-file-stream](https://github.com/jamestalmage/is-file-stream) - Detect if a stream is a file stream ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
is-stream-3.0.0/test.js000066400000000000000000000052501410445512000147310ustar00rootroot00000000000000import fs from 'node:fs'; import Stream from 'node:stream'; import net from 'node:net'; import test from 'ava'; import tempy from 'tempy'; import { isStream, isWritableStream, isReadableStream, isDuplexStream, isTransformStream, } from './index.js'; test('isStream()', t => { t.true(isStream(new Stream.Stream())); t.true(isStream(new Stream.Readable())); t.true(isStream(new Stream.Writable())); t.true(isStream(new Stream.Duplex())); t.true(isStream(new Stream.Transform())); t.true(isStream(new Stream.PassThrough())); t.true(isStream(fs.createReadStream('test.js'))); t.true(isStream(fs.createWriteStream(tempy.file()))); t.true(isStream(new net.Socket())); t.false(isStream({})); t.false(isStream(null)); t.false(isStream(undefined)); t.false(isStream('')); }); test('isWritableStream()', t => { t.true(isWritableStream(new Stream.Writable())); t.true(isWritableStream(new Stream.Duplex())); t.true(isWritableStream(new Stream.Transform())); t.true(isWritableStream(new Stream.PassThrough())); t.true(isWritableStream(fs.createWriteStream(tempy.file()))); t.true(isWritableStream(new net.Socket())); t.false(isWritableStream(new Stream.Stream())); t.false(isWritableStream(new Stream.Readable())); t.false(isWritableStream(fs.createReadStream('test.js'))); }); test('isReadableStream()', t => { t.true(isReadableStream(new Stream.Readable())); t.true(isReadableStream(new Stream.Duplex())); t.true(isReadableStream(new Stream.Transform())); t.true(isReadableStream(new Stream.PassThrough())); t.true(isReadableStream(fs.createReadStream('test.js'))); t.true(isReadableStream(new net.Socket())); t.false(isReadableStream(new Stream.Stream())); t.false(isReadableStream(new Stream.Writable())); t.false(isReadableStream(fs.createWriteStream(tempy.file()))); }); test('isDuplexStream()', t => { t.true(isDuplexStream(new Stream.Duplex())); t.true(isDuplexStream(new Stream.Transform())); t.true(isDuplexStream(new Stream.PassThrough())); t.false(isDuplexStream(new Stream.Stream())); t.false(isDuplexStream(new Stream.Readable())); t.false(isDuplexStream(new Stream.Writable())); t.false(isDuplexStream(fs.createReadStream('test.js'))); t.false(isDuplexStream(fs.createWriteStream(tempy.file()))); }); test('isTransformStream()', t => { t.true(isTransformStream(new Stream.Transform())); t.true(isTransformStream(new Stream.PassThrough())); t.false(isTransformStream(new Stream.Duplex())); t.false(isTransformStream(new Stream.Stream())); t.false(isTransformStream(new Stream.Readable())); t.false(isTransformStream(new Stream.Writable())); t.false(isTransformStream(fs.createReadStream('test.js'))); t.false(isTransformStream(fs.createWriteStream(tempy.file()))); });