1 var fs = require('fs');
2 var path = require('path');
3 var flatted = require('flatted');
6 tryParse: function (filePath, defaultValue) {
9 result = this.readJSON(filePath);
11 result = defaultValue;
17 * Read json file synchronously using flatted
20 * @param {String} filePath Json filepath
21 * @returns {*} parse result
23 readJSON: function (filePath) {
25 fs.readFileSync(filePath, {
32 * Write json file synchronously using circular-json
35 * @param {String} filePath Json filepath
36 * @param {*} data Object to serialize
38 writeJSON: function (filePath, data) {
39 fs.mkdirSync(path.dirname(filePath), {
42 fs.writeFileSync(filePath, flatted.stringify(data));