UNPKG

2.51 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { PassThrough } from "stream";
4
5/**
6 * @summary This function takes an arbitrary number of streams and returns a
7 * Merge2Stream.
8 *
9 * @description If a DuplexOption is specified, it has to be specified last in the
10 * argument list
11 *
12 * @see { @link https://github.com/teambition/merge2#api }
13 *
14 * @param args StreamTypes
15 * @param opts Optional DuplexOption to be specified last
16 *
17 * @return A merged duplex stream
18 */
19declare function merge2(options?: merge2.Options): merge2.Merge2Stream;
20declare function merge2(a: Streams, options?: merge2.Options): merge2.Merge2Stream;
21declare function merge2(a: Streams, b: Streams, options?: merge2.Options): merge2.Merge2Stream;
22declare function merge2(a: Streams, b: Streams, c: Streams, options?: merge2.Options): merge2.Merge2Stream;
23declare function merge2(a: Streams, b: Streams, c: Streams, d: Streams, options?: merge2.Options): merge2.Merge2Stream;
24declare function merge2(
25 a: Streams,
26 b: Streams,
27 c: Streams,
28 d: Streams,
29 e: Streams,
30 options?: merge2.Options,
31): merge2.Merge2Stream;
32declare function merge2(...args: Streams[]): merge2.Merge2Stream;
33
34type Streams = merge2.StreamType | merge2.StreamType[];
35
36declare namespace merge2 {
37 type StreamType = NodeJS.ReadableStream | Merge2Stream;
38
39 interface Options {
40 end?: boolean | undefined;
41 pipeError?: boolean | undefined;
42 objectMode?: boolean | undefined;
43 }
44
45 interface Merge2Stream extends PassThrough {
46 /**
47 * @summary Add more streams to an existing merged stream
48 *
49 * @param args streams to add
50 *
51 * @return The merged stream
52 */
53 add(...args: Streams[]): Merge2Stream;
54
55 /**
56 * @summary It will emit 'queueDrain' when all streams merged.
57 * If you set end === false in options, this event give you a notice that
58 * you should add more streams to merge, or end the mergedStream.
59 *
60 * @param event The 'queueDrain' event
61 *
62 * @return This stream
63 */
64 on(event: "queueDrain", listener: () => void): this;
65 on(event: string, listener: (...args: any[]) => void): this;
66
67 once(event: "queueDrain", listener: () => void): this;
68 once(event: string, listener: (...args: any[]) => void): this;
69 }
70}
71
72export = merge2;