.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / flat-cache / utils.js
1 var fs = require( 'graceful-fs' );
2 var write = require( 'write' );
3 var circularJson = require( 'circular-json' );
4
5 module.exports = {
6
7   tryParse: function ( filePath, defaultValue ) {
8     var result;
9     try {
10       result = this.readJSON( filePath );
11     } catch (ex) {
12       result = defaultValue;
13     }
14     return result;
15   },
16
17   /**
18    * Read json file synchronously using circular-json
19    *
20    * @method readJSON
21    * @param  {String} filePath Json filepath
22    * @returns {*} parse result
23    */
24   readJSON: function ( filePath ) {
25     return circularJson.parse( fs.readFileSync( filePath ).toString() );
26   },
27
28   /**
29    * Write json file synchronously using circular-json
30    *
31    * @method writeJSON
32    * @param  {String} filePath Json filepath
33    * @param  {*} data Object to serialize
34    */
35   writeJSON: function ( filePath, data ) {
36     write.sync( filePath, circularJson.stringify( data ) );
37   }
38
39 };