read-json.js 317 B

12345678910111213
  1. 'use strict';
  2. module.exports = function (filepath, defaults) {
  3. if (this.exists(filepath)) {
  4. try {
  5. return JSON.parse(this.read(filepath));
  6. } catch (error) {
  7. throw new Error('Could not parse JSON in file: ' + filepath + '. Detail: ' + error.message);
  8. }
  9. } else {
  10. return defaults;
  11. }
  12. };