UNPKG

@libj/make-uri

Version:
80 lines 3.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MakeUriBaseUri = void 0; var UriPart_1 = require("./UriPart"); var MakeUriError_1 = require("./MakeUriError"); var Regex = { Scheme: new RegExp("^[\\w+-.]+".concat(UriPart_1.UriPart.COLON)), Authority: /^[^/?#\s]+(?:[/?#]|[^:\s]$)/, Path: /(?:^|[^/])\/(?:[^/]|$)/, }; var InvalidParts = [ UriPart_1.UriPart.SLASH, UriPart_1.UriPart.QM, UriPart_1.UriPart.HASH, ].map(function (p) { return "".concat(UriPart_1.UriPart.DSLASH).concat(p); }); var MakeUriBaseUri = /** @class */ (function () { function MakeUriBaseUri(value) { this.value = value.trim(); this.validate(); } Object.defineProperty(MakeUriBaseUri.prototype, "hasScheme", { /*** Public ***/ get: function () { return Regex.Scheme.test(this.value); }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "schemeOnly", { get: function () { return new RegExp("".concat(Regex.Scheme.source, "$")).test(this.value); }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "hasAuthority", { get: function () { return Regex.Authority.test(this.value); }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "hasNoAuthority", { get: function () { return !this.hasAuthority; }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "hasPath", { get: function () { return Regex.Path.test(this.value); }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "hasQuery", { get: function () { return this.value.indexOf(UriPart_1.UriPart.QM) > -1; }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "hasFragment", { get: function () { return this.value.indexOf(UriPart_1.UriPart.HASH) > -1; }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "empty", { get: function () { return !this.value; }, enumerable: false, configurable: true }); Object.defineProperty(MakeUriBaseUri.prototype, "notEmpty", { get: function () { return !this.empty; }, enumerable: false, configurable: true }); MakeUriBaseUri.prototype.toString = function () { return this.value; }; MakeUriBaseUri.prototype.validate = function () { var _this = this; var err = new MakeUriError_1.MakeUriError("Invalid base uri given: ".concat(this.value)); if (InvalidParts.find(function (p) { return _this.value.indexOf(p) > -1; })) { throw err; } }; return MakeUriBaseUri; }()); exports.MakeUriBaseUri = MakeUriBaseUri; //# sourceMappingURL=MakeUriBaseUri.js.map