This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/cosmiconfig/dist/readFile.js

43 lines
916 B
JavaScript
Raw Permalink Normal View History

2019-08-11 18:48:02 +00:00
//
'use strict';
const fs = require('fs');
function readFile(filepath , options ) {
options = options || {};
const throwNotFound = options.throwNotFound || false;
return new Promise((resolve, reject) => {
fs.readFile(filepath, 'utf8', (err, content) => {
if (err && err.code === 'ENOENT' && !throwNotFound) {
return resolve(null);
}
if (err) return reject(err);
resolve(content);
});
});
}
readFile.sync = function readFileSync(
filepath ,
options
) {
options = options || {};
const throwNotFound = options.throwNotFound || false;
try {
return fs.readFileSync(filepath, 'utf8');
} catch (err) {
if (err.code === 'ENOENT' && !throwNotFound) {
return null;
}
throw err;
}
};
module.exports = readFile;