UNPKG

web-atoms-core

Version:
94 lines 3.39 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "../web/core/AtomUI"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var AtomUI_1 = require("../web/core/AtomUI"); var AtomUri = /** @class */ (function () { /** * */ function AtomUri(url) { var path; var query = ""; var hash = ""; var 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] || ""; } // extract protocol and domain... var scheme = ""; var host = ""; var port = ""; var 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_1.AtomUI.parseUrl(query); this.hash = AtomUI_1.AtomUI.parseUrl(hash); } AtomUri.prototype.toString = function () { var q = []; var h = []; for (var key in this.query) { if (this.query.hasOwnProperty(key)) { var element = this.query[key]; if (element === undefined || element === null) { continue; } q.push(encodeURIComponent(key) + "=" + encodeURIComponent(element.toString())); } } for (var key in this.hash) { if (this.hash.hasOwnProperty(key)) { var element = this.hash[key]; if (element === undefined || element === null) { continue; } h.push(encodeURIComponent(key) + "=" + encodeURIComponent(element.toString())); } } var qstr = q.length ? "?" + q.join("&") : ""; var hash = h.length ? "#" + h.join("&") : ""; var port = this.port ? ":" + this.port : ""; var path = this.path || "/"; if (path.startsWith("/")) { path = path.substr(1); } return this.protocol + "//" + this.host + port + "/" + path + qstr + hash; }; return AtomUri; }()); exports.AtomUri = AtomUri; }); //# sourceMappingURL=AtomUri.js.map