Total Complexity | 7 |
Complexity/F | 2.33 |
Lines of Code | 31 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const fs = require('fs') |
||
2 | const { join } = require('path') |
||
3 | const { Writable } = require('stream') |
||
4 | |||
5 | module.exports = (output, data) => { |
||
6 | if (!data) { |
||
7 | return null |
||
8 | } |
||
9 | |||
10 | if (typeof output === 'string') { |
||
11 | // Output as file |
||
12 | const path = join(output) |
||
13 | fs.open(path, fs.W_OK, err => { |
||
14 | if (err) { |
||
15 | console.error(`Cannot write file to ${path}`) |
||
16 | return |
||
17 | } |
||
18 | fs.appendFileSync(path, data + '\r\n') |
||
19 | }) |
||
|
|||
20 | } else if (output instanceof Writable) { |
||
21 | // Output as stream |
||
22 | output.write(data + '\r\n') |
||
23 | output.on('error', err => { |
||
24 | console.error(err) |
||
25 | }) |
||
26 | } else { |
||
27 | // Output as console |
||
28 | console.log(data) |
||
29 | return |
||
30 | } |
||
31 | } |
||
32 |