@regionorebrolan/extensions
Version:
Library with JavaScript additions and extensions.
189 lines • 6.57 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var urijs_1 = __importDefault(require("urijs"));
var UriWrapper_1 = __importDefault(require("./UriWrapper"));
var Utility_1 = __importDefault(require("./Utility"));
var UriBuilder = /** @class */ (function () {
// Constructors
function UriBuilder(queryCollectionFactory, uri) {
this._modified = false;
this._uri = null;
this._validationInstance = new urijs_1.default();
if (Utility_1.default.isNullOrUndefined(queryCollectionFactory))
throw new Error("The query-collection-factory can not be null or undefined.");
if (Utility_1.default.isNullOrUndefined(uri))
uri = new UriWrapper_1.default(new urijs_1.default());
else if (typeof uri === "string")
uri = new UriWrapper_1.default(new urijs_1.default(uri));
else
uri = uri;
this._fragment = uri.fragment;
this._host = uri.host;
this._password = uri.password;
this._path = uri.path;
this._port = uri.port;
this._query = queryCollectionFactory.create(this.onQueryChanged, uri.query);
this._scheme = uri.scheme;
this._userName = uri.userName;
}
Object.defineProperty(UriBuilder.prototype, "fragment", {
// Properties
get: function () {
return this._fragment;
},
set: function (value) {
if (this._fragment === value)
return;
this.validationInstance.fragment(value);
this._fragment = this.validationInstance.fragment();
this.modified = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "host", {
get: function () {
return this._host;
},
set: function (value) {
if (this._host === value)
return;
this.validationInstance.hostname(value);
this._host = this.validationInstance.hostname();
this.modified = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "modified", {
get: function () {
return this._modified;
},
set: function (value) {
this._modified = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "password", {
get: function () {
return this._password;
},
set: function (value) {
if (this._password === value)
return;
this.validationInstance.password(value);
this._password = this.validationInstance.password();
this.modified = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "path", {
get: function () {
return this._path;
},
set: function (value) {
if (this._path === value)
return;
this.validationInstance.path(value);
this._path = this.validationInstance.path();
this.modified = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "port", {
get: function () {
return this._port;
},
set: function (value) {
if (this._port === value)
return;
var port = value === null ? null : isNaN(value) ? null : value;
this.validationInstance.port(port === null ? "" : port.toString());
this._port = port;
this.modified = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "query", {
get: function () {
return this._query;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "scheme", {
get: function () {
return this._scheme;
},
set: function (value) {
if (this._scheme === value)
return;
this.validationInstance.scheme(value);
this._scheme = this.validationInstance.scheme();
this.modified = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "uri", {
get: function () {
if (this._uri === null || this.modified) {
this._uri = this.createUri();
this.modified = false;
}
return this._uri;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "userName", {
get: function () {
return this._userName;
},
set: function (value) {
if (this._userName === value)
return;
this.validationInstance.username(value);
this._userName = this.validationInstance.username();
this.modified = true;
},
enumerable: false,
configurable: true
});
Object.defineProperty(UriBuilder.prototype, "validationInstance", {
get: function () {
return this._validationInstance;
},
enumerable: false,
configurable: true
});
// Methods
UriBuilder.prototype.createUri = function () {
var uri = new urijs_1.default();
uri.fragment(this.fragment);
uri.hostname(this.host);
uri.path(this.path);
uri.password(this.password);
uri.port((this.port || "").toString());
uri.query(this.query.toString());
uri.scheme(this.scheme);
uri.username(this.userName);
return new UriWrapper_1.default(uri);
};
UriBuilder.prototype.onQueryChanged = function () {
this.modified = true;
};
UriBuilder.prototype.toString = function () {
return this.uri.toString();
};
return UriBuilder;
}());
exports.default = UriBuilder;
//# sourceMappingURL=UriBuilder.js.map