aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cosmiconfig/lib/readFile.js
blob: 95e1e2e238ebc4e52d595da69f6d29452a23e907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';

var fs = require('fs');

module.exports = function (filepath, options) {
  options = options || {};
  options.throwNotFound = options.throwNotFound || false;

  return new Promise(function (resolve, reject) {
    fs.readFile(filepath, 'utf8', function (err, content) {
      if (err && err.code === 'ENOENT' && !options.throwNotFound) {
        return resolve(null);
      }

      if (err) return reject(err);

      resolve(content);
    });
  });
};