Blame view

node_modules/cosmiconfig/lib/readFile.js 468 Bytes
ce4c83ff   wxy   初始提交
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);
      });
    });
  };