Passed
Push — master ( 0a8095...60f354 )
by hung
01:03
created

src/helper/input.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 24
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 6
c 1
b 0
f 0
nc 1
mnd 2
bc 7
fnc 3
dl 0
loc 24
rs 10
bpm 2.3333
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A input.js ➔ ??? 0 20 4
1
const fs = require('fs')
2
const { join } = require('path')
3
const { Readable } = require('stream')
4
5
module.exports = (input, callback) => {
6
  if (typeof input === 'string') {
7
    const path = join(__dirname, '../', input)
8
    if (!fs.existsSync(path)) {
9
      console.error(`Cannot read file ${path}`)
10
      return
11
    }
12
    const html = fs.readFileSync(path, 'utf8')
13
    callback(html)
14
  } else if (input instanceof Readable) {
15
    input.on('data', chunk => {
16
      callback(chunk.toString())
17
    })
18
    input.on('error', err => {
19
      console.error(err)
20
    })
21
  } else {
22
    console.error('Invalid Input')
23
  }
24
}
25