Skip to content

Commit 2f329fe

Browse files
BendingBendersindresorhus
authored andcommitted
Refactor TypeScript definition to CommonJS compatible export (#3)
1 parent 836678f commit 2f329fe

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

index.d.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
/// <reference types="node"/>
22
import {Readable as ReadableStream} from 'stream';
33

4-
export interface Options {
5-
/**
6-
* The total size to be produced by the stream in bytes.
7-
*
8-
* @default Infinity
9-
*/
10-
readonly size?: number;
4+
declare namespace randomBytesReadableStream {
5+
interface Options {
6+
/**
7+
The total size to be produced by the stream in bytes.
8+
9+
@default Infinity
10+
*/
11+
readonly size?: number;
12+
}
1113
}
1214

13-
/**
14-
* Creates a [readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) producing cryptographically strong pseudo-random data using [`crypto.randomBytes()`](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback).
15-
*
16-
* @returns By default, infinite data.
17-
*/
18-
export default function randomBytesReadableStream(options?: Options): ReadableStream;
15+
declare const randomBytesReadableStream: {
16+
/**
17+
Creates a [readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) producing cryptographically strong pseudo-random data using [`crypto.randomBytes()`](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback).
18+
19+
@returns By default, infinite data.
20+
21+
@example
22+
```
23+
import randomBytesReadableStream = require('random-bytes-readable-stream');
24+
25+
randomBytesReadableStream({size: 10}).pipe(process.stdout);
26+
```
27+
*/
28+
(options?: randomBytesReadableStream.Options): ReadableStream;
29+
30+
// TODO: Remove this for the next major release, refactor the whole definition to:
31+
// declare function randomBytesReadableStream(
32+
// options?: randomBytesReadableStream.Options
33+
// ): ReadableStream;
34+
// export = randomBytesReadableStream;
35+
default: typeof randomBytesReadableStream;
36+
};
37+
38+
export = randomBytesReadableStream;

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ const randomBytesReadableStream = (options = {}) => {
3232
};
3333

3434
module.exports = randomBytesReadableStream;
35+
// TODO: Remove this for the next major release
3536
module.exports.default = randomBytesReadableStream;

index.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import randomBytesReadableStream from '.';
1+
import randomBytesReadableStream = require('.');
22

33
randomBytesReadableStream().pipe(process.stdout);
44
randomBytesReadableStream({size: 50}).pipe(process.stdout);

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"node": ">=8"
1414
},
1515
"scripts": {
16-
"test": "xo && ava && tsd-check"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
1919
"index.js",
@@ -32,10 +32,10 @@
3232
"urandom"
3333
],
3434
"devDependencies": {
35-
"@types/node": "^11.10.5",
36-
"ava": "^1.3.1",
37-
"get-stream": "^4.1.0",
38-
"tsd-check": "^0.3.0",
35+
"@types/node": "^11.13.0",
36+
"ava": "^1.4.1",
37+
"get-stream": "^5.0.0",
38+
"tsd": "^0.7.2",
3939
"xo": "^0.24.0"
4040
}
4141
}

0 commit comments

Comments
 (0)