All files / lib/Io read.js

100% Statements 16/16
70% Branches 7/10
80% Functions 4/5
100% Lines 14/14

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        4x 4x   4x 6x     4x 1x 1x       4x 10x 2x     8x 7x 1x     1x  
/**
 * Including available read/input methods
 */
 
const fs = require('fs');
const { htmlTo$ } = require('../utils');
 
const readFromFile = (path, cb) => {
  return cb(htmlTo$(fs.readFileSync(path)));
}
 
const readFromStream = (stream, cb) => {
  stream.on('data', (html) => {
    cb(htmlTo$(html.toString()))
  })
}
 
module.exports = function(input = '', cb = () => {}) {
  if (typeof input === 'string') {
    return cb(htmlTo$(input));
  }
 
  if (input instanceof Object) {
    if (input.file) return readFromFile(input.file, cb);
    Eif (input.stream) return readFromStream(input.stream, cb);
  }
 
  return cb(htmlTo$('<body></body>'));
}