1 | // Type definitions for event-stream v4.0
|
2 | // Project: https://github.com/dominictarr/event-stream
|
3 | // Definitions by: David Gardiner <https://github.com/flcdrg>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 |
|
6 | /// <reference types="node" />
|
7 |
|
8 | import * as stream from 'stream';
|
9 |
|
10 | export interface MapStream extends stream.Stream {
|
11 | writable: boolean;
|
12 | readable: boolean;
|
13 |
|
14 | destroy: () => void;
|
15 | end: any;
|
16 | pause: () => void;
|
17 | resume: () => void;
|
18 | write: any;
|
19 | }
|
20 |
|
21 | /**
|
22 | * Create a stream from a series of MapStreams
|
23 | */
|
24 | export declare function pipeline(...streams: MapStream[]): MapStream;
|
25 |
|
26 | /**
|
27 | * Create a through stream from an asynchronous function
|
28 | *
|
29 | * @param asyncFunction
|
30 | */
|
31 | export declare function map(asyncFunction: Function): MapStream;
|
32 |
|
33 | /**
|
34 | * Same as map, but the callback is called synchronously. Based on es.through
|
35 | * @param syncFunction
|
36 | */
|
37 | export declare function mapSync(syncFunction: Function): MapStream;
|
38 |
|
39 | /**
|
40 | * Filter elements of the stream.
|
41 | * @param syncFunction
|
42 | */
|
43 | export declare function filterSync(syncFunction: (value: any) => boolean): MapStream;
|
44 |
|
45 | /**
|
46 | * Break up a stream and reassemble it so that each line is a chunk. matcher may be a String, or a RegExp
|
47 | *
|
48 | * @param matcher
|
49 | */
|
50 | export declare function split(matcher?: string | RegExp): MapStream;
|
51 |
|
52 | /**
|
53 | * Create a through stream that emits separator between each chunk, just like Array#join
|
54 | *
|
55 | * @param separator
|
56 | */
|
57 | export declare function join(separator: string): MapStream;
|
58 |
|
59 | /**
|
60 | * Merges streams into one and returns it. Incoming data will be emitted as soon it comes into - no ordering will be applied
|
61 | * (for example: data1 data1 data2 data1 data2 - where data1 and data2 is data from two streams).
|
62 | * Counts how many streams were passed to it and emits end only when all streams emitted end.
|
63 | *
|
64 | * @param stream
|
65 | */
|
66 | export declare function concat(...stream: MapStream[]): MapStream;
|
67 |
|
68 | /**
|
69 | * Merges streams into one and returns it. Incoming data will be emitted as soon it comes into - no ordering will be applied
|
70 | * (for example: data1 data1 data2 data1 data2 - where data1 and data2 is data from two streams).
|
71 | * Counts how many streams were passed to it and emits end only when all streams emitted end.
|
72 | *
|
73 | * @param stream
|
74 | */
|
75 | export declare function concat(streamArray: MapStream[]): MapStream;
|
76 |
|
77 | /**
|
78 | * Merges streams into one and returns it. Incoming data will be emitted as soon it comes into - no ordering will be applied
|
79 | * (for example: data1 data1 data2 data1 data2 - where data1 and data2 is data from two streams).
|
80 | * Counts how many streams were passed to it and emits end only when all streams emitted end.
|
81 | *
|
82 | * @param stream
|
83 | */
|
84 | export declare function merge(...stream: MapStream[]): MapStream;
|
85 |
|
86 | /**
|
87 | * Merges streams into one and returns it. Incoming data will be emitted as soon it comes into - no ordering will be applied
|
88 | * (for example: data1 data1 data2 data1 data2 - where data1 and data2 is data from two streams).
|
89 | * Counts how many streams were passed to it and emits end only when all streams emitted end.
|
90 | *
|
91 | * @param stream
|
92 | */
|
93 | export declare function merge(streamArray: MapStream[]): MapStream;
|
94 |
|
95 | /**
|
96 | * Replace all occurrences of from with to
|
97 | * @param from
|
98 | * @param to
|
99 | */
|
100 | export declare function replace(from: string | RegExp, to: string | RegExp): MapStream;
|
101 |
|
102 | /**
|
103 | * Convenience function for parsing JSON chunks. For newline separated JSON, use with es.split.
|
104 | * By default it logs parsing errors by console.error; for another behaviour, transforms created by es.parse({error: true})
|
105 | * will emit error events for exceptions thrown from JSON.parse, unmodified.
|
106 | */
|
107 | export declare function parse(): any;
|
108 |
|
109 | /**
|
110 | * convert javascript objects into lines of text. The text will have whitespace escaped and have a \n appended, so it will be compatible with es.parse
|
111 | */
|
112 | export declare function stringify(): MapStream;
|
113 |
|
114 | /**
|
115 | * create a readable stream (that respects pause) from an async function.
|
116 | *
|
117 | * @param asyncFunction
|
118 | */
|
119 | export declare function readable(asyncFunction: Function): MapStream;
|
120 |
|
121 | /**
|
122 | * Create a readable stream from an Array.
|
123 | *
|
124 | * @param array
|
125 | */
|
126 | export declare function readArray(array: any[]): MapStream;
|
127 |
|
128 | /**
|
129 | * create a writeable stream from a callback
|
130 | *
|
131 | * @param callback
|
132 | */
|
133 | export declare function writeArray(callback: Function): MapStream;
|
134 |
|
135 | /**
|
136 | * A stream that buffers all chunks when paused
|
137 | */
|
138 | export declare function pause(): MapStream | void;
|
139 |
|
140 | /**
|
141 | * Takes a writable stream and a readable stream and makes them appear as a readable writable stream.
|
142 | *
|
143 | * @param writeStream
|
144 | * @param readStream
|
145 | */
|
146 | export declare function duplex(writeStream: stream.Writable, readStream: stream.Readable): MapStream;
|
147 |
|
148 | /**
|
149 | * Create a through stream from a child process
|
150 | *
|
151 | * @param child_process
|
152 | */
|
153 | export declare function child(child_process: any): MapStream;
|
154 |
|
155 | /**
|
156 | * waits for stream to emit 'end'. joins chunks of a stream into a single string or buffer.
|
157 | * Takes an optional callback, which will be passed the complete string/buffer when it receives the 'end' event.
|
158 | *
|
159 | * @param callback
|
160 | */
|
161 | export declare function wait(callback: Function): MapStream;
|