2021-02-24 11:30:50 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const {
|
|
|
|
SymbolAsyncIterator,
|
|
|
|
SymbolIterator,
|
|
|
|
} = primordials;
|
|
|
|
|
|
|
|
function isReadable(obj) {
|
2021-03-13 16:44:48 +02:00
|
|
|
return !!(obj && typeof obj.pipe === 'function' &&
|
|
|
|
typeof obj.on === 'function');
|
2021-02-24 11:30:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function isWritable(obj) {
|
2021-03-13 16:44:48 +02:00
|
|
|
return !!(obj && typeof obj.write === 'function' &&
|
|
|
|
typeof obj.on === 'function');
|
2021-02-24 11:30:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function isStream(obj) {
|
|
|
|
return isReadable(obj) || isWritable(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isIterable(obj, isAsync) {
|
2021-05-18 23:30:13 +08:00
|
|
|
if (obj == null) return false;
|
2021-02-24 11:30:50 -08:00
|
|
|
if (isAsync === true) return typeof obj[SymbolAsyncIterator] === 'function';
|
|
|
|
if (isAsync === false) return typeof obj[SymbolIterator] === 'function';
|
|
|
|
return typeof obj[SymbolAsyncIterator] === 'function' ||
|
|
|
|
typeof obj[SymbolIterator] === 'function';
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
isIterable,
|
|
|
|
isReadable,
|
|
|
|
isStream,
|
|
|
|
};
|