UNPKG

@hn3000/json-ref

Version:

simple resolver for json reference and json pointer

58 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JsonReference = void 0; var json_ptr_1 = require("./json-ptr"); var JsonReference = /** @class */ (function () { function JsonReference(ref) { var filename = JsonReference.getFilename(ref); var pointer = (ref && ref.substring(filename.length + 1)) || ""; this._pointer = new json_ptr_1.JsonPointer(decodeURIComponent(pointer)); this._filename = filename; } /** * Returns a JsonReference object from a string or JsonReference. * Used to allow clients to pass in either a string or a JsonReference without having * to deal with the difference. * * @param path string or JsonReference */ JsonReference.get = function (ref) { if ('string' === typeof ref) { return new JsonReference(ref); } return ref; }; JsonReference.getFilename = function (ref) { var filename = ""; if (ref != null) { var hashPos = ref.indexOf('#'); if (-1 != hashPos) { filename = ref.substring(0, hashPos); } else { filename = ref; } } return filename; }; Object.defineProperty(JsonReference.prototype, "filename", { get: function () { return this._filename; }, enumerable: false, configurable: true }); Object.defineProperty(JsonReference.prototype, "pointer", { get: function () { return this._pointer; }, enumerable: false, configurable: true }); JsonReference.prototype.toString = function () { return this._filename + '#' + this._pointer; }; return JsonReference; }()); exports.JsonReference = JsonReference; //# sourceMappingURL=json-ref.js.map