All files / lib/internal/streams utils.js

100% Statements 34/34
94.44% Branches 17/18
100% Functions 4/4
100% Lines 34/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 3520x 20x 20x 20x 20x 20x 20x 331x 331x 331x 331x 20x 57x 57x 57x 57x 20x 253x 253x 253x 20x 245x 245x 245x 245x 243x 245x 245x 20x 20x 20x 20x 20x 20x  
'use strict';
 
const {
  SymbolAsyncIterator,
  SymbolIterator,
} = primordials;
 
function isReadable(obj) {
  return !!(obj && typeof obj.pipe === 'function' &&
            typeof obj.on === 'function');
}
 
function isWritable(obj) {
  return !!(obj && typeof obj.write === 'function' &&
            typeof obj.on === 'function');
}
 
function isStream(obj) {
  return isReadable(obj) || isWritable(obj);
}
 
function isIterable(obj, isAsync) {
  if (obj == null) return false;
  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,
};