@web-atoms/core
Version:
90 lines (89 loc) • 2.83 kB
JavaScript
System.register(["../web/core/AtomUI"], function (_export, _context) {
"use strict";
var AtomUI, AtomUri;
_export("AtomUri", void 0);
return {
setters: [function (_webCoreAtomUI) {
AtomUI = _webCoreAtomUI.AtomUI;
}],
execute: function () {
_export("AtomUri", AtomUri = class AtomUri {
get pathAndQuery() {
const q = [];
const h = [];
for (const key in this.query) {
if (this.query.hasOwnProperty(key)) {
const element = this.query[key];
if (element === undefined || element === null) {
continue;
}
q.push(`${encodeURIComponent(key)}=${encodeURIComponent(element.toString())}`);
}
}
for (const key in this.hash) {
if (this.hash.hasOwnProperty(key)) {
const element = this.hash[key];
if (element === undefined || element === null) {
continue;
}
h.push(`${encodeURIComponent(key)}=${encodeURIComponent(element.toString())}`);
}
}
const query = q.length ? "?" + q.join("&") : "";
const hash = h.length ? "#" + h.join("&") : "";
let path = this.path || "/";
if (path.startsWith("/")) {
path = path.substr(1);
}
return `${path}${query}${hash}`;
}
constructor(url) {
let path;
let query = "";
let hash = "";
let t = url.split("?");
path = t[0];
if (t.length === 2) {
query = t[1] || "";
t = query.split("#");
query = t[0];
hash = t[1] || "";
} else {
t = path.split("#");
path = t[0];
hash = t[1] || "";
}
let scheme = "";
let host = "";
let port = "";
let i = path.indexOf("//");
if (i !== -1) {
scheme = path.substr(0, i);
path = path.substr(i + 2);
i = path.indexOf("/");
if (i !== -1) {
host = path.substr(0, i);
path = path.substr(i + 1);
t = host.split(":");
if (t.length > 1) {
host = t[0];
port = t[1];
}
}
}
this.host = host;
this.protocol = scheme;
this.port = port;
this.path = path;
this.query = AtomUI.parseUrl(query);
this.hash = AtomUI.parseUrl(hash);
}
toString() {
const port = this.port ? ":" + this.port : "";
return `${this.protocol}//${this.host}${port}/${this.pathAndQuery}`;
}
});
}
};
});
//# sourceMappingURL=AtomUri.js.map