UNPKG

@stoplight/spectral

Version:

A flexible object linter with out of the box support for OpenAPI v2 and v3.

35 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const yaml_1 = require("@stoplight/yaml"); const fs_1 = require("fs"); const fetch = require("node-fetch"); function doRead(name, encoding) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (name.startsWith('http')) { const result = yield fetch(name); return yaml_1.parseWithPointers(yield result.text()); } else if (fs_1.existsSync(name)) { try { return yaml_1.parseWithPointers(fs_1.readFileSync(name, encoding)); } catch (ex) { throw new Error(`Could not read ${name}: ${ex.message}`); } } throw new Error(`${name} does not exist`); }); } function readParsable(name, encoding) { return tslib_1.__awaiter(this, void 0, void 0, function* () { try { return doRead(name, encoding); } catch (ex) { throw new Error(`Could not parse ${name}: ${ex.message}`); } }); } exports.readParsable = readParsable; //# sourceMappingURL=reader.js.map