UNPKG

1.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const yaml_1 = require("@stoplight/yaml");
5const fs_1 = require("fs");
6const fetch = require("node-fetch");
7function doRead(name, encoding) {
8 return tslib_1.__awaiter(this, void 0, void 0, function* () {
9 if (name.startsWith('http')) {
10 const result = yield fetch(name);
11 return yaml_1.parseWithPointers(yield result.text());
12 }
13 else if (fs_1.existsSync(name)) {
14 try {
15 return yaml_1.parseWithPointers(fs_1.readFileSync(name, encoding));
16 }
17 catch (ex) {
18 throw new Error(`Could not read ${name}: ${ex.message}`);
19 }
20 }
21 throw new Error(`${name} does not exist`);
22 });
23}
24function readParsable(name, encoding) {
25 return tslib_1.__awaiter(this, void 0, void 0, function* () {
26 try {
27 return doRead(name, encoding);
28 }
29 catch (ex) {
30 throw new Error(`Could not parse ${name}: ${ex.message}`);
31 }
32 });
33}
34exports.readParsable = readParsable;
35//# sourceMappingURL=reader.js.map
\No newline at end of file