Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/is-stream
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 424a6904c768f5f446fbc36c03a31be8b1209ca6
Choose a base ref
...
head repository: sindresorhus/is-stream
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e21d73f1028c189d16150cea52641059b0936310
Choose a head ref
  • 7 commits
  • 7 files changed
  • 2 contributors

Commits on Feb 8, 2015

  1. Update .travis.yml

    sindresorhus committed Feb 8, 2015
    Copy the full SHA
    9aba305 View commit details

Commits on Sep 8, 2015

  1. add XO

    sindresorhus committed Sep 8, 2015

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e88f948 View commit details
  2. bump AVA

    sindresorhus committed Sep 8, 2015

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    cddca0d View commit details

Commits on Dec 31, 2015

  1. Copy the full SHA
    838082d View commit details

Commits on Apr 12, 2016

  1. Add support for detecting transform streams (#4)

    Fixes #3.
    kevva authored and sindresorhus committed Apr 12, 2016
    Copy the full SHA
    892107f View commit details
  2. minor tweaks

    sindresorhus committed Apr 12, 2016
    Copy the full SHA
    0a3afe5 View commit details
  3. 1.1.0

    sindresorhus committed Apr 12, 2016
    Copy the full SHA
    e21d73f View commit details
Showing with 84 additions and 83 deletions.
  1. +1 −4 .editorconfig
  2. +0 −13 .jshintrc
  3. +4 −0 .travis.yml
  4. +6 −2 index.js
  5. +8 −6 package.json
  6. +5 −4 readme.md
  7. +60 −54 test.js
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
13 changes: 0 additions & 13 deletions .jshintrc

This file was deleted.

4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
sudo: false
language: node_js
node_js:
- '5'
- '4'
- '0.12'
- '0.10'
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -5,13 +5,17 @@ var isStream = module.exports = function (stream) {
};

isStream.writable = function (stream) {
return isStream(stream) && stream.writable !== false && typeof stream._write == 'function' && typeof stream._writableState == 'object';
return isStream(stream) && stream.writable !== false && typeof stream._write === 'function' && typeof stream._writableState === 'object';
};

isStream.readable = function (stream) {
return isStream(stream) && stream.readable !== false && typeof stream._read == 'function' && typeof stream._readableState == 'object';
return isStream(stream) && stream.readable !== false && typeof stream._read === 'function' && typeof stream._readableState === 'object';
};

isStream.duplex = function (stream) {
return isStream.writable(stream) && isStream.readable(stream);
};

isStream.transform = function (stream) {
return isStream.duplex(stream) && typeof stream._transform === 'function' && typeof stream._transformState === 'object';
};
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "is-stream",
"version": "1.0.1",
"version": "1.1.0",
"description": "Check if something is a Node.js stream",
"license": "MIT",
"repository": "sindresorhus/is-stream",
@@ -13,24 +13,26 @@
"node": ">=0.10.0"
},
"scripts": {
"test": "node test.js"
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"stream",
"type",
"streams",
"writable",
"readable",
"duplex",
"transform",
"check",
"detect",
"is",
"type"
"is"
],
"devDependencies": {
"ava": "0.0.4",
"tempfile": "^1.1.0"
"ava": "*",
"tempfile": "^1.1.0",
"xo": "*"
}
}
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# is-stream [![Build Status](https://travis-ci.org/sindresorhus/is-stream.svg?branch=master)](https://travis-ci.org/sindresorhus/is-stream)

> Check if something is a [Node.js stream](http://nodejs.org/api/stream.html)
> Check if something is a [Node.js stream](https://nodejs.org/api/stream.html)

## Install
@@ -13,8 +13,8 @@ $ npm install --save is-stream
## Usage

```js
var fs = require('fs');
var isStream = require('is-stream');
const fs = require('fs');
const isStream = require('is-stream');

isStream(fs.createReadStream('unicorn.png'));
//=> true
@@ -34,8 +34,9 @@ isStream({});

#### isStream.duplex(stream)

#### isStream.transform(stream)


## License

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
114 changes: 60 additions & 54 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,68 @@
'use strict';
var fs = require('fs');
var Stream = require('stream');
var net = require('net');
var test = require('ava');
var tempfile = require('tempfile');
var isStream = require('./');
import fs from 'fs';
import Stream from 'stream';
import net from 'net';
import test from 'ava';
import tempfile from 'tempfile';
import m from './';

test('isStream()', function (t) {
t.assert(isStream(new Stream.Stream()));
t.assert(isStream(new Stream.Readable()));
t.assert(isStream(new Stream.Writable()));
t.assert(isStream(new Stream.Duplex()));
t.assert(isStream(new Stream.Transform()));
t.assert(isStream(new Stream.PassThrough()));
t.assert(isStream(fs.createReadStream('test.js')));
t.assert(isStream(fs.createWriteStream(tempfile())));
t.assert(!isStream({}));
t.assert(!isStream(null));
t.assert(!isStream(undefined));
t.assert(!isStream(''));
t.assert(isStream(new net.Socket()));
t.end();
test('isStream()', t => {
t.true(m(new Stream.Stream()));
t.true(m(new Stream.Readable()));
t.true(m(new Stream.Writable()));
t.true(m(new Stream.Duplex()));
t.true(m(new Stream.Transform()));
t.true(m(new Stream.PassThrough()));
t.true(m(fs.createReadStream('test.js')));
t.true(m(fs.createWriteStream(tempfile())));
t.true(m(new net.Socket()));
t.false(m({}));
t.false(m(null));
t.false(m(undefined));
t.false(m(''));
});

test('isStream.writable()', function (t) {
t.assert(!isStream.writable(new Stream.Stream()));
t.assert(!isStream.writable(new Stream.Readable()));
t.assert(isStream.writable(new Stream.Writable()));
t.assert(isStream.writable(new Stream.Duplex()));
t.assert(isStream.writable(new Stream.Transform()));
t.assert(isStream.writable(new Stream.PassThrough()));
t.assert(!isStream.writable(fs.createReadStream('test.js')));
t.assert(isStream.writable(fs.createWriteStream(tempfile())));
t.assert(!isStream.writable(new net.Socket()));
t.end();
test('isStream.writable()', t => {
t.true(m.writable(new Stream.Writable()));
t.true(m.writable(new Stream.Duplex()));
t.true(m.writable(new Stream.Transform()));
t.true(m.writable(new Stream.PassThrough()));
t.true(m.writable(fs.createWriteStream(tempfile())));
t.false(m.writable(new Stream.Stream()));
t.false(m.writable(new Stream.Readable()));
t.false(m.writable(fs.createReadStream('test.js')));
t.false(m.writable(new net.Socket()));
});

test('isStream.readable()', function (t) {
t.assert(!isStream.readable(new Stream.Stream()));
t.assert(isStream.readable(new Stream.Readable()));
t.assert(!isStream.readable(new Stream.Writable()));
t.assert(isStream.readable(new Stream.Duplex()));
t.assert(isStream.readable(new Stream.Transform()));
t.assert(isStream.readable(new Stream.PassThrough()));
t.assert(isStream.readable(fs.createReadStream('test.js')));
t.assert(!isStream.readable(fs.createWriteStream(tempfile())));
t.assert(!isStream.readable(new net.Socket()));
t.end();
test('isStream.readable()', t => {
t.true(m.readable(new Stream.Readable()));
t.true(m.readable(new Stream.Duplex()));
t.true(m.readable(new Stream.Transform()));
t.true(m.readable(new Stream.PassThrough()));
t.true(m.readable(fs.createReadStream('test.js')));
t.false(m.readable(new Stream.Stream()));
t.false(m.readable(new Stream.Writable()));
t.false(m.readable(fs.createWriteStream(tempfile())));
t.false(m.readable(new net.Socket()));
});

test('isStream.duplex()', function (t) {
t.assert(!isStream.duplex(new Stream.Stream()));
t.assert(!isStream.duplex(new Stream.Readable()));
t.assert(!isStream.duplex(new Stream.Writable()));
t.assert(isStream.duplex(new Stream.Duplex()));
t.assert(isStream.duplex(new Stream.Transform()));
t.assert(isStream.duplex(new Stream.PassThrough()));
t.assert(!isStream.duplex(fs.createReadStream('test.js')));
t.assert(!isStream.duplex(fs.createWriteStream(tempfile())));
t.end();
test('isStream.duplex()', t => {
t.true(m.duplex(new Stream.Duplex()));
t.true(m.duplex(new Stream.Transform()));
t.true(m.duplex(new Stream.PassThrough()));
t.false(m.duplex(new Stream.Stream()));
t.false(m.duplex(new Stream.Readable()));
t.false(m.duplex(new Stream.Writable()));
t.false(m.duplex(fs.createReadStream('test.js')));
t.false(m.duplex(fs.createWriteStream(tempfile())));
});

test('isStream.transform()', t => {
t.true(m.transform(new Stream.Transform()));
t.true(m.transform(new Stream.PassThrough()));
t.false(m.transform(new Stream.Duplex()));
t.false(m.transform(new Stream.Stream()));
t.false(m.transform(new Stream.Readable()));
t.false(m.transform(new Stream.Writable()));
t.false(m.transform(fs.createReadStream('test.js')));
t.false(m.transform(fs.createWriteStream(tempfile())));
});