Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 11, 2019
1 parent da6a608 commit 2eff2e8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="node"/>
import {Readable as ReadableStream} from 'stream';

/**
* Convert a `string`/`Buffer`/`Uint8Array` to a [readable stream](https://nodejs.org/api/stream.html#stream_readable_streams).
*
* @param input - Value to convert to a stream.
*/
export default function toReadableStream(
input: string | Buffer | Uint8Array
): ReadableStream;
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';
const {Readable: ReadableStream} = require('stream');

module.exports = input => (
const toReadableStream = input => (
new ReadableStream({
read() {
this.push(input);
this.push(null);
}
})
);

module.exports = toReadableStream;
module.exports.default = toReadableStream;
7 changes: 7 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import toReadableStream from '.';

toReadableStream('🦄🌈').pipe(process.stdout);
toReadableStream(Buffer.from('🦄🌈')).pipe(process.stdout);
toReadableStream(new Uint8Array(Buffer.from('🦄🌈').buffer)).pipe(
process.stdout
);
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"stream",
Expand All @@ -33,8 +34,9 @@
"pull"
],
"devDependencies": {
"ava": "*",
"get-stream": "^3.0.0",
"xo": "*"
"ava": "^1.3.1",
"get-stream": "^4.1.0",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}

0 comments on commit 2eff2e8

Please sign in to comment.