Skip to content

Commit

Permalink
FEAT: Add json read and write utility based on circular-json
Browse files Browse the repository at this point in the history
  • Loading branch information
nopnop committed Jul 28, 2016
1 parent cd7aeed commit c31081e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var fs = require( 'graceful-fs' );
var write = require( 'write' );
var circularJson = require( 'circular-json' )

module.exports = {

/**
* Read json file synchronously using circular-json
*
* @method readJSON
* @param {String} filePath Json filepath
* @returns {*} parse result
*/
readJSON: function ( filePath ) {
return circularJson.parse( fs.readFileSync( filePath ).toString().replace(/^\ufeff/g, '') );
},

/**
* Write json file synchronously using circular-json
*
* @method writeJSON
* @param {String} filePath Json filepath
* @param {*} data Object to serialize
*/
writeJSON: function (filePath, data ) {
write.sync( filePath, circularJson.stringify( data ) );
}

};

0 comments on commit c31081e

Please sign in to comment.