1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var url = tslib_1.__importStar(require("url"));
|
5 | var SchemaId = (function () {
|
6 | function SchemaId(inputId, parentIds) {
|
7 | this.inputId = inputId;
|
8 | var absoluteId = 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.absoluteId = absoluteId;
|
23 | this.id = url.parse(absoluteId);
|
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 m[1];
|
46 | };
|
47 | SchemaId.empty = new SchemaId('');
|
48 | return SchemaId;
|
49 | }());
|
50 | exports.default = SchemaId;
|
51 |
|
\ | No newline at end of file |