Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 5, 2019
1 parent 1049256 commit ea52348
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
59 changes: 37 additions & 22 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
/// <reference types="node"/>
import {Readable as ReadableStream} from 'stream';

export type Input =
| Buffer
| NodeJS.TypedArray
| ArrayBuffer
| string
| Iterable<Buffer | string>;
declare namespace intoStream {
type Input =
| Buffer
| NodeJS.TypedArray
| ArrayBuffer
| string
| Iterable<Buffer | string>;

export type InputObject =
| {[key: string]: unknown}
| Iterable<{[key: string]: unknown}>;
type InputObject =
| {[key: string]: unknown}
| Iterable<{[key: string]: unknown}>;
}

declare const intoStream: {
/**
* Convert `input` into a stream. Adheres to the requested chunk size, except for `array` where each element will be a chunk.
*
* @param input - The input to convert to a stream.
* @returns A [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
*/
(input: Input | Promise<Input>): ReadableStream;
Convert `input` into a stream. Adheres to the requested chunk size, except for `array` where each element will be a chunk.
@param input - The input to convert to a stream.
@returns A [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
@example
```
import intoStream = require('into-stream');
intoStream('unicorn').pipe(process.stdout);
//=> 'unicorn'
```
*/
(input: intoStream.Input | Promise<intoStream.Input>): ReadableStream;

/**
* Convert object `input` into a stream.
*
* @param input - The object input to convert to a stream.
* @returns A [readable object stream](https://nodejs.org/api/stream.html#stream_object_mode).
*/
object(input: InputObject | Promise<InputObject>): ReadableStream;
Convert object `input` into a stream.
@param input - The object input to convert to a stream.
@returns A [readable object stream](https://nodejs.org/api/stream.html#stream_object_mode).
*/
object(
input: intoStream.InputObject | Promise<intoStream.InputObject>
): ReadableStream;

// TODO: Remove this for the next major release
default: typeof intoStream;
};

export default intoStream;
export = intoStream;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const intoStream = input => {
};

module.exports = intoStream;
// TODO: Remove this for the next major release
module.exports.default = intoStream;

module.exports.object = input => {
Expand Down
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 intoStream from '.';
import intoStream = require('.');

const unicornArray = 'unicorn'.split('');

Expand Down
10 changes: 5 additions & 5 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 @@ -40,14 +40,14 @@
"str"
],
"dependencies": {
"from2": "^2.1.1",
"from2": "^2.3.0",
"p-is-promise": "^2.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"ava": "^1.4.1",
"get-stream": "^5.0.0",
"p-event": "^3.0.0",
"tsd-check": "^0.3.0",
"p-event": "^4.1.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit ea52348

Please sign in to comment.