-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
37 lines (33 loc) · 1.3 KB
/
index.js
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
export function isStream(stream, {checkOpen = true} = {}) {
return stream !== null
&& typeof stream === 'object'
&& (stream.writable || stream.readable || !checkOpen || (stream.writable === undefined && stream.readable === undefined))
&& typeof stream.pipe === 'function';
}
export function isWritableStream(stream, {checkOpen = true} = {}) {
return isStream(stream, {checkOpen})
&& (stream.writable || !checkOpen)
&& typeof stream.write === 'function'
&& typeof stream.end === 'function'
&& typeof stream.writable === 'boolean'
&& typeof stream.writableObjectMode === 'boolean'
&& typeof stream.destroy === 'function'
&& typeof stream.destroyed === 'boolean';
}
export function isReadableStream(stream, {checkOpen = true} = {}) {
return isStream(stream, {checkOpen})
&& (stream.readable || !checkOpen)
&& typeof stream.read === 'function'
&& typeof stream.readable === 'boolean'
&& typeof stream.readableObjectMode === 'boolean'
&& typeof stream.destroy === 'function'
&& typeof stream.destroyed === 'boolean';
}
export function isDuplexStream(stream, options) {
return isWritableStream(stream, options)
&& isReadableStream(stream, options);
}
export function isTransformStream(stream, options) {
return isDuplexStream(stream, options)
&& typeof stream._transform === 'function';
}