json-reader.js 354 B

123456789101112131415
  1. const _fs = require('fs-magic');
  2. // parse json file and allow single line comments
  3. async function readJSONFile(filename){
  4. // load file
  5. let raw = await _fs.readFile(filename, 'utf8');
  6. // strip single line js comments
  7. raw = raw.replace(/^\s*\/\/.*$/gm, '');
  8. // parse text
  9. return JSON.parse(raw);
  10. }
  11. module.exports = readJSONFile;