Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 20, 2019
1 parent 0342990 commit c918e37
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sudo: false
language: node_js
node_js:
- '6'
- '4'
- '10'
- '8'
80 changes: 80 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/// <reference types="node"/>
import * as stream from 'stream';

declare const isStream: {
/**
@returns Whether `stream` is a [`Stream`](https://nodejs.org/api/stream.html#stream_stream).
@example
```
import * as fs from 'fs';
import isStream = require('is-stream');
isStream(fs.createReadStream('unicorn.png'));
//=> true
isStream({});
//=> false
```
*/
(stream: unknown): stream is stream.Stream;

/**
@returns Whether `stream` is a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable).
@example
```
import * as fs from 'fs';
import isStream = require('is-stream');
isStream.writable(fs.createWriteStrem('unicorn.txt'));
//=> true
```
*/
writable(stream: unknown): stream is stream.Writable;

/**
@returns Whether `stream` is a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable).
@example
```
import * as fs from 'fs';
import isStream = require('is-stream');
isStream.readable(fs.createReadStream('unicorn.png'));
//=> true
```
*/
readable(stream: unknown): stream is stream.Readable;

/**
@returns Whether `stream` is a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex).
@example
```
import {Duplex} from 'stream';
import isStream = require('is-stream');
isStream.duplex(new Duplex());
//=> true
```
*/
duplex(stream: unknown): stream is stream.Duplex;

/**
@returns Whether `stream` is a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform).
@example
```
import * as fs from 'fs';
import Stringify = require('streaming-json-stringify');
import isStream = require('is-stream');
isStream.transform(Stringify());
//=> true
```
*/
transform(input: unknown): input is stream.Transform;
};

export = isStream;
25 changes: 25 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {expectType} from 'tsd';
import * as stream from 'stream';
import isStream = require('.');

const foo = '';

if (isStream(foo)) {
expectType<stream.Stream>(foo);
}

if (isStream.writable(foo)) {
expectType<stream.Writable>(foo);
}

if (isStream.readable(foo)) {
expectType<stream.Readable>(foo);
}

if (isStream.duplex(foo)) {
expectType<stream.Duplex>(new stream.Duplex());
}

if (isStream.transform(foo)) {
expectType<stream.Transform>(foo);
}
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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:
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 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.
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.
75 changes: 39 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
{
"name": "is-stream",
"version": "1.1.0",
"description": "Check if something is a Node.js stream",
"license": "MIT",
"repository": "sindresorhus/is-stream",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"stream",
"type",
"streams",
"writable",
"readable",
"duplex",
"transform",
"check",
"detect",
"is"
],
"devDependencies": {
"ava": "*",
"tempy": "^0.1.0",
"xo": "*"
}
"name": "is-stream",
"version": "1.1.0",
"description": "Check if something is a Node.js stream",
"license": "MIT",
"repository": "sindresorhus/is-stream",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"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": "^11.13.6",
"ava": "^1.4.1",
"tempy": "^0.3.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Install

```
$ npm install --save is-stream
$ npm install is-stream
```


Expand Down
96 changes: 48 additions & 48 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,66 @@ import Stream from 'stream';
import net from 'net';
import test from 'ava';
import tempy from 'tempy';
import m from '.';
import isStream from '.';

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(tempy.file())));
t.true(m(new net.Socket()));
t.false(m({}));
t.false(m(null));
t.false(m(undefined));
t.false(m(''));
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('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(tempy.file())));
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()));
t.true(isStream.writable(new Stream.Writable()));
t.true(isStream.writable(new Stream.Duplex()));
t.true(isStream.writable(new Stream.Transform()));
t.true(isStream.writable(new Stream.PassThrough()));
t.true(isStream.writable(fs.createWriteStream(tempy.file())));
t.false(isStream.writable(new Stream.Stream()));
t.false(isStream.writable(new Stream.Readable()));
t.false(isStream.writable(fs.createReadStream('test.js')));
t.false(isStream.writable(new net.Socket()));
});

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(tempy.file())));
t.false(m.readable(new net.Socket()));
t.true(isStream.readable(new Stream.Readable()));
t.true(isStream.readable(new Stream.Duplex()));
t.true(isStream.readable(new Stream.Transform()));
t.true(isStream.readable(new Stream.PassThrough()));
t.true(isStream.readable(fs.createReadStream('test.js')));
t.false(isStream.readable(new Stream.Stream()));
t.false(isStream.readable(new Stream.Writable()));
t.false(isStream.readable(fs.createWriteStream(tempy.file())));
t.false(isStream.readable(new net.Socket()));
});

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(tempy.file())));
t.true(isStream.duplex(new Stream.Duplex()));
t.true(isStream.duplex(new Stream.Transform()));
t.true(isStream.duplex(new Stream.PassThrough()));
t.false(isStream.duplex(new Stream.Stream()));
t.false(isStream.duplex(new Stream.Readable()));
t.false(isStream.duplex(new Stream.Writable()));
t.false(isStream.duplex(fs.createReadStream('test.js')));
t.false(isStream.duplex(fs.createWriteStream(tempy.file())));
});

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(tempy.file())));
t.true(isStream.transform(new Stream.Transform()));
t.true(isStream.transform(new Stream.PassThrough()));
t.false(isStream.transform(new Stream.Duplex()));
t.false(isStream.transform(new Stream.Stream()));
t.false(isStream.transform(new Stream.Readable()));
t.false(isStream.transform(new Stream.Writable()));
t.false(isStream.transform(fs.createReadStream('test.js')));
t.false(isStream.transform(fs.createWriteStream(tempy.file())));
});

0 comments on commit c918e37

Please sign in to comment.