UNPKG

cosmiconfig

Version:

Find and load configuration from a package.json property, rc file, or CommonJS module

21 lines (15 loc) 467 B
'use strict'; const fs = require('graceful-fs'); module.exports = function (filepath, options) { options = options || {}; options.throwNotFound = options.throwNotFound || false; return new Promise((resolve, reject) => { fs.readFile(filepath, 'utf8', (err, content) => { if (err && err.code === 'ENOENT' && !options.throwNotFound) { return resolve(null); } if (err) return reject(err); resolve(content); }); }); };