source: trip-planner-front/node_modules/cosmiconfig/dist/readFile.js@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.readFile = readFile;
7exports.readFileSync = readFileSync;
8
9var _fs = _interopRequireDefault(require("fs"));
10
11function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13async function fsReadFileAsync(pathname, encoding) {
14 return new Promise((resolve, reject) => {
15 _fs.default.readFile(pathname, encoding, (error, contents) => {
16 if (error) {
17 reject(error);
18 return;
19 }
20
21 resolve(contents);
22 });
23 });
24}
25
26async function readFile(filepath, options = {}) {
27 const throwNotFound = options.throwNotFound === true;
28
29 try {
30 const content = await fsReadFileAsync(filepath, 'utf8');
31 return content;
32 } catch (error) {
33 if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
34 return null;
35 }
36
37 throw error;
38 }
39}
40
41function readFileSync(filepath, options = {}) {
42 const throwNotFound = options.throwNotFound === true;
43
44 try {
45 const content = _fs.default.readFileSync(filepath, 'utf8');
46
47 return content;
48 } catch (error) {
49 if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
50 return null;
51 }
52
53 throw error;
54 }
55}
56//# sourceMappingURL=readFile.js.map
Note: See TracBrowser for help on using the repository browser.