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