-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor TypeScript definition to CommonJS compatible export (#12)
- Loading branch information
1 parent
1049256
commit ea52348
Showing
4 changed files
with
44 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import intoStream from '.'; | ||
import intoStream = require('.'); | ||
|
||
const unicornArray = 'unicorn'.split(''); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters