Sha256: f6201ed2cee6ade19de32d4af41eb037f84e315ebb600bae2d2b030549ca6c9f

Contents?: true

Size: 909 Bytes

Versions: 43

Compression:

Stored size: 909 Bytes

Contents

var fs = require( 'graceful-fs' );
var write = require( 'write' );
var circularJson = require( 'circular-json' );

module.exports = {

  tryParse: function ( filePath, defaultValue ) {
    var result;
    try {
      result = this.readJSON( filePath );
    } catch (ex) {
      result = defaultValue;
    }
    return result;
  },

  /**
   * 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 ) );
  }

};

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.21.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.20.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.19.1 node_modules/flat-cache/utils.js
govuk_publishing_components-17.19.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.18.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.17.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.16.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.15.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.14.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.13.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.12.2 node_modules/flat-cache/utils.js
govuk_publishing_components-17.12.1 node_modules/flat-cache/utils.js
govuk_publishing_components-17.12.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.11.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.10.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.9.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.8.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.7.0 node_modules/flat-cache/utils.js
govuk_publishing_components-17.6.1 node_modules/flat-cache/utils.js