1'use strict'; 2 3const { 4 SymbolAsyncIterator, 5 SymbolIterator, 6} = primordials; 7 8function isReadable(obj) { 9 return !!(obj && typeof obj.pipe === 'function' && 10 typeof obj.on === 'function'); 11} 12 13function isWritable(obj) { 14 return !!(obj && typeof obj.write === 'function' && 15 typeof obj.on === 'function'); 16} 17 18function isStream(obj) { 19 return isReadable(obj) || isWritable(obj); 20} 21 22function isIterable(obj, isAsync) { 23 if (!obj) return false; 24 if (isAsync === true) return typeof obj[SymbolAsyncIterator] === 'function'; 25 if (isAsync === false) return typeof obj[SymbolIterator] === 'function'; 26 return typeof obj[SymbolAsyncIterator] === 'function' || 27 typeof obj[SymbolIterator] === 'function'; 28} 29 30module.exports = { 31 isIterable, 32 isReadable, 33 isStream, 34}; 35