UNPKG

1.67 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): from2.Stream;
12declare function from2(opts: from2.ObjectModeOptions, read: from2.ReadObjectInput): from2.Stream;
13declare function from2(opts: from2.Options, read: from2.ReadInput): from2.Stream;
14
15declare namespace from2 {
16 interface Stream extends NodeJS.ReadableStream {
17 readonly destroyed: boolean;
18 destroy: (err?: Error) => void;
19 }
20 function obj(read: ReadObjectInput): Stream;
21 function obj(opts: { objectMode?: true | undefined } & stream.ReadableOptions, read: ReadObjectInput): Stream;
22
23 function ctor(opts?: Options): From2Ctor<ReadInput>;
24 function ctor(opts: ObjectModeOptions): From2Ctor<ReadObjectInput>;
25
26 type ObjectModeOptions = { objectMode: true } & stream.ReadableOptions;
27 type Options = { objectMode?: false | undefined } & stream.ReadableOptions;
28
29 type From2Ctor<R extends ReadInput | ReadObjectInput> = new (read: R) => Stream;
30
31 type ReadObjectInput = ReadCallback<NextObjectCallback> | any[];
32 type ReadInput = ReadCallback<NextCallback> | Chunk[];
33 type ReadCallback<N extends NextCallback | NextObjectCallback> = (size: number, next: N) => void;
34 type NextCallback = (err: any | undefined, chunk: Chunk) => void;
35 type NextObjectCallback = (err: any | undefined, chunk: any) => void;
36 type Chunk = string | Buffer | Uint8Array | null;
37}