lakutata
Version:
An IoC-based universal application framework.
442 lines (395 loc) • 11.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
const e = require("../../../vendor/Package.5.cjs");
"use strict";
var t = function e(t, s) {
s = s.split(":")[0];
t = +t;
if (!t) return false;
switch (s) {
case "http":
case "ws":
return t !== 80;
case "https":
case "wss":
return t !== 443;
case "ftp":
return t !== 21;
case "gopher":
return t !== 70;
case "file":
return false;
}
return t !== 0;
};
const s = e.getDefaultExportFromCjs(t);
var o = {};
"use strict";
var r = Object.prototype.hasOwnProperty, n;
function i(e) {
try {
return decodeURIComponent(e.replace(/\+/g, " "));
} catch (e) {
return null;
}
}
function a(e) {
try {
return encodeURIComponent(e);
} catch (e) {
return null;
}
}
function h(e) {
var t = /([^=?#&]+)=?([^&]*)/g, s = {}, o;
while (o = t.exec(e)) {
var r = i(o[1]), n = i(o[2]);
if (r === null || n === null || r in s) continue;
s[r] = n;
}
return s;
}
function l(e, t) {
t = t || "";
var s = [], o, i;
if ("string" !== typeof t) t = "?";
for (i in e) {
if (r.call(e, i)) {
o = e[i];
if (!o && (o === null || o === n || isNaN(o))) {
o = "";
}
i = a(i);
o = a(o);
if (i === null || o === null) continue;
s.push(i + "=" + o);
}
}
return s.length ? t + s.join("&") : "";
}
var c = o.stringify = l;
var u = o.parse = h;
"use strict";
var f = t, p = o, d = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/, m = /[\n\r\t]/g, g = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//, w = /:\d+$/, y = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i, b = /^[a-zA-Z]:/;
function v(e) {
return (e ? e : "").toString().replace(d, "");
}
var j = [ [ "#", "hash" ], [ "?", "query" ], function e(t, s) {
return R(s.protocol) ? t.replace(/\\/g, "/") : t;
}, [ "/", "pathname" ], [ "@", "auth", 1 ], [ NaN, "host", undefined, 1, 1 ], [ /:(\d*)$/, "port", undefined, 1 ], [ NaN, "hostname", undefined, 1, 1 ] ];
var O = {
hash: 1,
query: 1
};
function C(t) {
var s;
if (typeof window !== "undefined") s = window; else if (typeof e.commonjsGlobal !== "undefined") s = e.commonjsGlobal; else if (typeof self !== "undefined") s = self; else s = {};
var o = s.location || {};
t = t || o;
var r = {}, n = typeof t, i;
if ("blob:" === t.protocol) {
r = new q(unescape(t.pathname), {});
} else if ("string" === n) {
r = new q(t, {});
for (i in O) delete r[i];
} else if ("object" === n) {
for (i in t) {
if (i in O) continue;
r[i] = t[i];
}
if (r.slashes === undefined) {
r.slashes = g.test(t.href);
}
}
return r;
}
function R(e) {
return e === "file:" || e === "ftp:" || e === "http:" || e === "https:" || e === "ws:" || e === "wss:";
}
function U(e, t) {
e = v(e);
e = e.replace(m, "");
t = t || {};
var s = y.exec(e);
var o = s[1] ? s[1].toLowerCase() : "";
var r = !!s[2];
var n = !!s[3];
var i = 0;
var a;
if (r) {
if (n) {
a = s[2] + s[3] + s[4];
i = s[2].length + s[3].length;
} else {
a = s[2] + s[4];
i = s[2].length;
}
} else {
if (n) {
a = s[3] + s[4];
i = s[3].length;
} else {
a = s[4];
}
}
if (o === "file:") {
if (i >= 2) {
a = a.slice(2);
}
} else if (R(o)) {
a = s[4];
} else if (o) {
if (r) {
a = a.slice(2);
}
} else if (i >= 2 && R(t.protocol)) {
a = s[4];
}
return {
protocol: o,
slashes: r || R(o),
slashesCount: i,
rest: a
};
}
function I(e, t) {
if (e === "") return t;
var s = (t || "/").split("/").slice(0, -1).concat(e.split("/")), o = s.length, r = s[o - 1], n = false, i = 0;
while (o--) {
if (s[o] === ".") {
s.splice(o, 1);
} else if (s[o] === "..") {
s.splice(o, 1);
i++;
} else if (i) {
if (o === 0) n = true;
s.splice(o, 1);
i--;
}
}
if (n) s.unshift("");
if (r === "." || r === "..") s.push("");
return s.join("/");
}
function q(e, t, s) {
e = v(e);
e = e.replace(m, "");
if (!(this instanceof q)) {
return new q(e, t, s);
}
var o, r, n, i, a, h, l = j.slice(), c = typeof t, u = this, d = 0;
if ("object" !== c && "string" !== c) {
s = t;
t = null;
}
if (s && "function" !== typeof s) s = p.parse;
t = C(t);
r = U(e || "", t);
o = !r.protocol && !r.slashes;
u.slashes = r.slashes || o && t.slashes;
u.protocol = r.protocol || t.protocol || "";
e = r.rest;
if (r.protocol === "file:" && (r.slashesCount !== 2 || b.test(e)) || !r.slashes && (r.protocol || r.slashesCount < 2 || !R(u.protocol))) {
l[3] = [ /(.*)/, "pathname" ];
}
for (;d < l.length; d++) {
i = l[d];
if (typeof i === "function") {
e = i(e, u);
continue;
}
n = i[0];
h = i[1];
if (n !== n) {
u[h] = e;
} else if ("string" === typeof n) {
a = n === "@" ? e.lastIndexOf(n) : e.indexOf(n);
if (~a) {
if ("number" === typeof i[2]) {
u[h] = e.slice(0, a);
e = e.slice(a + i[2]);
} else {
u[h] = e.slice(a);
e = e.slice(0, a);
}
}
} else if (a = n.exec(e)) {
u[h] = a[1];
e = e.slice(0, a.index);
}
u[h] = u[h] || (o && i[3] ? t[h] || "" : "");
if (i[4]) u[h] = u[h].toLowerCase();
}
if (s) u.query = s(u.query);
if (o && t.slashes && u.pathname.charAt(0) !== "/" && (u.pathname !== "" || t.pathname !== "")) {
u.pathname = I(u.pathname, t.pathname);
}
if (u.pathname.charAt(0) !== "/" && R(u.protocol)) {
u.pathname = "/" + u.pathname;
}
if (!f(u.port, u.protocol)) {
u.host = u.hostname;
u.port = "";
}
u.username = u.password = "";
if (u.auth) {
a = u.auth.indexOf(":");
if (~a) {
u.username = u.auth.slice(0, a);
u.username = encodeURIComponent(decodeURIComponent(u.username));
u.password = u.auth.slice(a + 1);
u.password = encodeURIComponent(decodeURIComponent(u.password));
} else {
u.username = encodeURIComponent(decodeURIComponent(u.auth));
}
u.auth = u.password ? u.username + ":" + u.password : u.username;
}
u.origin = u.protocol !== "file:" && R(u.protocol) && u.host ? u.protocol + "//" + u.host : "null";
u.href = u.toString();
}
function x(e, t, s) {
var o = this;
switch (e) {
case "query":
if ("string" === typeof t && t.length) {
t = (s || p.parse)(t);
}
o[e] = t;
break;
case "port":
o[e] = t;
if (!f(t, o.protocol)) {
o.host = o.hostname;
o[e] = "";
} else if (t) {
o.host = o.hostname + ":" + t;
}
break;
case "hostname":
o[e] = t;
if (o.port) t += ":" + o.port;
o.host = t;
break;
case "host":
o[e] = t;
if (w.test(t)) {
t = t.split(":");
o.port = t.pop();
o.hostname = t.join(":");
} else {
o.hostname = t;
o.port = "";
}
break;
case "protocol":
o.protocol = t.toLowerCase();
o.slashes = !s;
break;
case "pathname":
case "hash":
if (t) {
var r = e === "pathname" ? "/" : "#";
o[e] = t.charAt(0) !== r ? r + t : t;
} else {
o[e] = t;
}
break;
case "username":
case "password":
o[e] = encodeURIComponent(t);
break;
case "auth":
var n = t.indexOf(":");
if (~n) {
o.username = t.slice(0, n);
o.username = encodeURIComponent(decodeURIComponent(o.username));
o.password = t.slice(n + 1);
o.password = encodeURIComponent(decodeURIComponent(o.password));
} else {
o.username = encodeURIComponent(decodeURIComponent(t));
}
}
for (var i = 0; i < j.length; i++) {
var a = j[i];
if (a[4]) o[a[1]] = o[a[1]].toLowerCase();
}
o.auth = o.password ? o.username + ":" + o.password : o.username;
o.origin = o.protocol !== "file:" && R(o.protocol) && o.host ? o.protocol + "//" + o.host : "null";
o.href = o.toString();
return o;
}
function S(e) {
if (!e || "function" !== typeof e) e = p.stringify;
var t, s = this, o = s.host, r = s.protocol;
if (r && r.charAt(r.length - 1) !== ":") r += ":";
var n = r + (s.protocol && s.slashes || R(s.protocol) ? "//" : "");
if (s.username) {
n += s.username;
if (s.password) n += ":" + s.password;
n += "@";
} else if (s.password) {
n += ":" + s.password;
n += "@";
} else if (s.protocol !== "file:" && R(s.protocol) && !o && s.pathname !== "/") {
n += "@";
}
if (o[o.length - 1] === ":" || w.test(s.hostname) && !s.port) {
o += ":";
}
n += o + s.pathname;
t = "object" === typeof s.query ? e(s.query) : s.query;
if (t) n += "?" !== t.charAt(0) ? "?" + t : t;
if (s.hash) n += s.hash;
return n;
}
q.prototype = {
set: x,
toString: S
};
q.extractProtocol = U;
q.location = C;
q.trimLeft = v;
q.qs = p;
var L = q;
const k = e.getDefaultExportFromCjs(L);
class URLBuilder {
static parse(e) {
return new URLBuilder(JSON.parse(JSON.stringify(k(e, true))));
}
#e;
constructor(e = {}) {
this.#e = k("");
this.auth = e.auth;
this.hash = e.hash;
this.host = e.host;
this.hostname = e.hostname;
this.href = e.href;
this.origin = e.origin;
this.password = e.password;
this.pathname = e.pathname;
this.port = e.port;
this.protocol = e.protocol;
this.query = e.query;
this.slashes = e.slashes;
this.username = e.username;
}
toString() {
if (this.auth) this.#e.set("auth", this.auth);
if (this.hash) this.#e.set("hash", this.hash);
if (this.host) this.#e.set("host", this.host);
if (this.hostname) this.#e.set("hostname", this.hostname);
if (this.href) this.#e.set("href", this.href);
if (this.origin !== undefined) this.#e.set("origin", this.origin.toString());
if (this.password) this.#e.set("password", this.password);
if (this.pathname) this.#e.set("pathname", this.pathname);
if (this.port !== undefined) this.#e.set("port", this.port);
if (this.protocol) this.#e.set("protocol", this.protocol);
if (this.query) this.#e.set("query", this.query);
if (this.slashes !== undefined) this.#e.set("slashes", this.slashes);
if (this.username) this.#e.set("username", this.username);
return this.#e.toString();
}
}
exports.URLBuilder = URLBuilder;