UNPKG

1.6 kBTypeScriptView Raw
1// Type definitions for from2 2.3
2// Project: https://github.com/hughsk/from2
3// Definitions by: BendingBender <https://github.com/BendingBender>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/// <reference types="node" />
7import * as stream from 'stream';
8
9export = from2;
10
11declare function from2(read: from2.ReadInput): NodeJS.ReadableStream;
12declare function from2(opts: from2.ObjectModeOptions, read: from2.ReadObjectInput): NodeJS.ReadableStream;
13declare function from2(opts: from2.Options, read: from2.ReadInput): NodeJS.ReadableStream;
14
15declare namespace from2 {
16 function obj(read: ReadObjectInput): NodeJS.ReadableStream;
17 function obj(opts: { objectMode?: true | undefined } & stream.ReadableOptions, read: ReadObjectInput): NodeJS.ReadableStream;
18
19 function ctor(opts?: Options): From2Ctor<ReadInput>;
20 function ctor(opts: ObjectModeOptions): From2Ctor<ReadObjectInput>;
21
22 type ObjectModeOptions = { objectMode: true } & stream.ReadableOptions;
23 type Options = { objectMode?: false | undefined } & stream.ReadableOptions;
24
25 type From2Ctor<R extends ReadInput | ReadObjectInput> = new(read: R) => NodeJS.ReadableStream;
26
27 type ReadObjectInput = ReadCallback<NextObjectCallback> | any[];
28 type ReadInput = ReadCallback<NextCallback> | Chunk[];
29 type ReadCallback<N extends NextCallback | NextObjectCallback> = (size: number, next: N) => void;
30 type NextCallback = (err: any | undefined, chunk: Chunk) => void;
31 type NextObjectCallback = (err: any | undefined, chunk: any) => void;
32 type Chunk = string | Buffer | Uint8Array | null;
33}