Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 5, 2019
1 parent eea277f commit c49dcd0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
32 changes: 24 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
/// <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;
declare const toReadableStream: {
/**
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.
@example
```
import toReadableStream = require('to-readable-stream');
toReadableStream('🦄🌈').pipe(process.stdout);
```
*/
(input: string | Buffer | Uint8Array): ReadableStream;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function toReadableStream(
// input: string | Buffer | Uint8Array
// ): ReadableStream;
// export = toReadableStream;
default: typeof toReadableStream;
};

export = toReadableStream;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const toReadableStream = input => (
);

module.exports = toReadableStream;
// TODO: Remove this for the next major release
module.exports.default = toReadableStream;
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import toReadableStream from '.';
import toReadableStream = require('.');

toReadableStream('🦄🌈').pipe(process.stdout);
toReadableStream(Buffer.from('🦄🌈')).pipe(process.stdout);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -34,9 +34,9 @@
"pull"
],
"devDependencies": {
"ava": "^1.3.1",
"get-stream": "^4.1.0",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"get-stream": "^5.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit c49dcd0

Please sign in to comment.