UNPKG

1.73 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var url = tslib_1.__importStar(require("url"));
5var SchemaId = (function () {
6 function SchemaId(inputId, parentIds) {
7 this.inputId = inputId;
8 var absoluteId = url.resolve('', inputId);
9 if (parentIds) {
10 parentIds.forEach(function (parent) {
11 if (parent) {
12 absoluteId = url.resolve(parent, absoluteId);
13 }
14 });
15 }
16 if (absoluteId.indexOf('#') < 0) {
17 absoluteId += '#';
18 }
19 if (absoluteId.indexOf('://') < 0 && absoluteId[0] !== '/' && absoluteId[0] !== '#') {
20 absoluteId = '/' + absoluteId;
21 }
22 this.id = url.parse(absoluteId);
23 this.absoluteId = this.id.href;
24 }
25 SchemaId.prototype.getAbsoluteId = function () {
26 return this.absoluteId;
27 };
28 SchemaId.prototype.isEmpty = function () {
29 return !!this.absoluteId;
30 };
31 SchemaId.prototype.isFetchable = function () {
32 return /https?\:\/\//.test(this.absoluteId);
33 };
34 SchemaId.prototype.getFileId = function () {
35 return this.absoluteId.replace(/#.*$/, '#');
36 };
37 SchemaId.prototype.existsJsonPointerHash = function () {
38 return this.absoluteId === '#' || /#\//.test(this.absoluteId);
39 };
40 SchemaId.prototype.getJsonPointerHash = function () {
41 var m = /(#\/.*)$/.exec(this.absoluteId);
42 if (m == null) {
43 return '#';
44 }
45 return decodeURIComponent(m[1]);
46 };
47 SchemaId.empty = new SchemaId('');
48 return SchemaId;
49}());
50exports.default = SchemaId;
51//# sourceMappingURL=schemaId.js.map
\No newline at end of file