All files / lib utils.js

27.27% Statements 3/11
0% Branches 0/6
0% Functions 0/3
30% Lines 3/10

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  2x 2x                                                   2x          
'use strict'
const fs = require('fs')
const SLICE = Array.prototype.slice
 
/*
 * [writeToFile description]
 * @param  {[type]} data [数组数据列表]
 * @param  {[type]} path [写入的路径]
 */
// eslint-disable-next-line no-unused-vars
function writeToFile (data, path, calllback) {
  data = JSON.stringify(data, null, '\t')
  fs.writeFile(path, data, 'utf-8', function (err) {
    if (err) throw err
    calllback && calllback()
  })
}
 
/*
 * [readToFile 读取文件]
 * @param  {[type]} path [读取路径]
 */
function readToFile (path, calllback) {
  const data = fs.readFileSync(path, 'UTF-8')
  calllback && calllback()
  return data
}
 
module.exports = {
  writeToFile,
  readToFile,
  SLICE,
}