mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
PR-URL: https://github.com/nodejs/node/pull/7999 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
30 lines
711 B
JavaScript
30 lines
711 B
JavaScript
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() );
|
|
},
|
|
|
|
/**
|
|
* 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 ) );
|
|
}
|
|
|
|
};
|