salve-annos
Version:
A fork with support for documentation of Salve, a Javascript library which implements a validator able to validate an XML document on the basis of a subset of RelaxNG.
50 lines • 2.06 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FetchResourceLoader = exports.FetchResource = void 0;
// tslint:disable-next-line:no-typeof-undefined
if (typeof fetch === "undefined") {
throw new Error("trying to load the fetch loader when fetch is absent");
}
class FetchResource {
constructor(url, response) {
this.url = url;
this.response = response;
}
getText() {
return __awaiter(this, void 0, void 0, function* () {
return this.response.text();
});
}
}
exports.FetchResource = FetchResource;
/**
* A resource loader that loads resources using ``fetch``. It can only be used
* in an environment where ``fetch`` is native or provided by a polyfill.
*
* This loader does not allow loading from ``file://``.
*/
class FetchResourceLoader {
load(url) {
return __awaiter(this, void 0, void 0, function* () {
if (url.protocol === "file:") {
throw new Error("this loader cannot load from the file system");
}
const response = yield fetch(url.toString());
if (!response.ok) {
throw new Error(`unable to fetch ${url}`);
}
return new FetchResource(url, response);
});
}
}
exports.FetchResourceLoader = FetchResourceLoader;
//# sourceMappingURL=fetch.js.map