index.cjs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. const n = /[^\0-\x7E]/;
  4. const t = /[\x2E\u3002\uFF0E\uFF61]/g;
  5. const o = { overflow: "Overflow Error", "not-basic": "Illegal Input", "invalid-input": "Invalid Input" };
  6. const e = Math.floor;
  7. const r = String.fromCharCode;
  8. function s(n2) {
  9. throw new RangeError(o[n2]);
  10. }
  11. const c = function(n2, t2) {
  12. return n2 + 22 + 75 * (n2 < 26) - ((t2 != 0) << 5);
  13. };
  14. const u = function(n2, t2, o2) {
  15. let r2 = 0;
  16. for (n2 = o2 ? e(n2 / 700) : n2 >> 1, n2 += e(n2 / t2); n2 > 455; r2 += 36) {
  17. n2 = e(n2 / 35);
  18. }
  19. return e(r2 + 36 * n2 / (n2 + 38));
  20. };
  21. function toASCII(o2) {
  22. return function(n2, o3) {
  23. const e2 = n2.split("@");
  24. let r2 = "";
  25. e2.length > 1 && (r2 = e2[0] + "@", n2 = e2[1]);
  26. const s2 = function(n3, t2) {
  27. const o4 = [];
  28. let e3 = n3.length;
  29. for (; e3--; ) {
  30. o4[e3] = t2(n3[e3]);
  31. }
  32. return o4;
  33. }((n2 = n2.replace(t, ".")).split("."), o3).join(".");
  34. return r2 + s2;
  35. }(o2, function(t2) {
  36. return n.test(t2) ? "xn--" + function(n2) {
  37. const t3 = [];
  38. const o3 = (n2 = function(n3) {
  39. const t4 = [];
  40. let o4 = 0;
  41. const e2 = n3.length;
  42. for (; o4 < e2; ) {
  43. const r2 = n3.charCodeAt(o4++);
  44. if (r2 >= 55296 && r2 <= 56319 && o4 < e2) {
  45. const e3 = n3.charCodeAt(o4++);
  46. (64512 & e3) == 56320 ? t4.push(((1023 & r2) << 10) + (1023 & e3) + 65536) : (t4.push(r2), o4--);
  47. } else {
  48. t4.push(r2);
  49. }
  50. }
  51. return t4;
  52. }(n2)).length;
  53. let f = 128;
  54. let i = 0;
  55. let l = 72;
  56. for (const o4 of n2) {
  57. o4 < 128 && t3.push(r(o4));
  58. }
  59. const h = t3.length;
  60. let p = h;
  61. for (h && t3.push("-"); p < o3; ) {
  62. let o4 = 2147483647;
  63. for (const t4 of n2) {
  64. t4 >= f && t4 < o4 && (o4 = t4);
  65. }
  66. const a = p + 1;
  67. o4 - f > e((2147483647 - i) / a) && s("overflow"), i += (o4 - f) * a, f = o4;
  68. for (const o5 of n2) {
  69. if (o5 < f && ++i > 2147483647 && s("overflow"), o5 == f) {
  70. let n3 = i;
  71. for (let o6 = 36; ; o6 += 36) {
  72. const s2 = o6 <= l ? 1 : o6 >= l + 26 ? 26 : o6 - l;
  73. if (n3 < s2) {
  74. break;
  75. }
  76. const u2 = n3 - s2;
  77. const f2 = 36 - s2;
  78. t3.push(r(c(s2 + u2 % f2, 0))), n3 = e(u2 / f2);
  79. }
  80. t3.push(r(c(n3, 0))), l = u(i, a, p == h), i = 0, ++p;
  81. }
  82. }
  83. ++i, ++f;
  84. }
  85. return t3.join("");
  86. }(t2) : t2;
  87. });
  88. }
  89. const HASH_RE = /#/g;
  90. const AMPERSAND_RE = /&/g;
  91. const SLASH_RE = /\//g;
  92. const EQUAL_RE = /=/g;
  93. const IM_RE = /\?/g;
  94. const PLUS_RE = /\+/g;
  95. const ENC_BRACKET_OPEN_RE = /%5B/gi;
  96. const ENC_BRACKET_CLOSE_RE = /%5D/gi;
  97. const ENC_CARET_RE = /%5E/gi;
  98. const ENC_BACKTICK_RE = /%60/gi;
  99. const ENC_CURLY_OPEN_RE = /%7B/gi;
  100. const ENC_PIPE_RE = /%7C/gi;
  101. const ENC_CURLY_CLOSE_RE = /%7D/gi;
  102. const ENC_SPACE_RE = /%20/gi;
  103. const ENC_SLASH_RE = /%2F/gi;
  104. const ENC_ENC_SLASH_RE = /%252F/gi;
  105. function encode(text) {
  106. return encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
  107. }
  108. function encodeHash(text) {
  109. return encode(text).replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
  110. }
  111. function encodeQueryValue(text) {
  112. return encode(text).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
  113. }
  114. function encodeQueryKey(text) {
  115. return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
  116. }
  117. function encodePath(text) {
  118. return encode(text).replace(HASH_RE, "%23").replace(IM_RE, "%3F").replace(ENC_ENC_SLASH_RE, "%2F").replace(AMPERSAND_RE, "%26").replace(PLUS_RE, "%2B");
  119. }
  120. function encodeParam(text) {
  121. return encodePath(text).replace(SLASH_RE, "%2F");
  122. }
  123. function decode(text = "") {
  124. try {
  125. return decodeURIComponent("" + text);
  126. } catch (_err) {
  127. return "" + text;
  128. }
  129. }
  130. function decodePath(text) {
  131. return decode(text.replace(ENC_SLASH_RE, "%252F"));
  132. }
  133. function decodeQueryValue(text) {
  134. return decode(text.replace(PLUS_RE, " "));
  135. }
  136. function encodeHost(name = "") {
  137. return toASCII(name);
  138. }
  139. function parseQuery(paramsStr = "") {
  140. const obj = {};
  141. if (paramsStr[0] === "?") {
  142. paramsStr = paramsStr.substr(1);
  143. }
  144. for (const param of paramsStr.split("&")) {
  145. const s = param.match(/([^=]+)=?(.*)/) || [];
  146. if (s.length < 2) {
  147. continue;
  148. }
  149. const key = decode(s[1]);
  150. if (key === "__proto__" || key === "constructor") {
  151. continue;
  152. }
  153. const value = decodeQueryValue(s[2] || "");
  154. if (obj[key]) {
  155. if (Array.isArray(obj[key])) {
  156. obj[key].push(value);
  157. } else {
  158. obj[key] = [obj[key], value];
  159. }
  160. } else {
  161. obj[key] = value;
  162. }
  163. }
  164. return obj;
  165. }
  166. function encodeQueryItem(key, val) {
  167. if (!val) {
  168. return encodeQueryKey(key);
  169. }
  170. if (Array.isArray(val)) {
  171. return val.map((_val) => `${encodeQueryKey(key)}=${encodeQueryValue(_val)}`).join("&");
  172. }
  173. return `${encodeQueryKey(key)}=${encodeQueryValue(val)}`;
  174. }
  175. function stringifyQuery(query) {
  176. return Object.keys(query).map((k) => encodeQueryItem(k, query[k])).join("&");
  177. }
  178. class $URL {
  179. constructor(input = "") {
  180. this.query = {};
  181. if (typeof input !== "string") {
  182. throw new TypeError(`URL input should be string received ${typeof input} (${input})`);
  183. }
  184. const parsed = parseURL(input);
  185. this.protocol = decode(parsed.protocol);
  186. this.host = decode(parsed.host);
  187. this.auth = decode(parsed.auth);
  188. this.pathname = decodePath(parsed.pathname);
  189. this.query = parseQuery(parsed.search);
  190. this.hash = decode(parsed.hash);
  191. }
  192. get hostname() {
  193. return parseHost(this.host).hostname;
  194. }
  195. get port() {
  196. return parseHost(this.host).port || "";
  197. }
  198. get username() {
  199. return parseAuth(this.auth).username;
  200. }
  201. get password() {
  202. return parseAuth(this.auth).password || "";
  203. }
  204. get hasProtocol() {
  205. return this.protocol.length;
  206. }
  207. get isAbsolute() {
  208. return this.hasProtocol || this.pathname[0] === "/";
  209. }
  210. get search() {
  211. const q = stringifyQuery(this.query);
  212. return q.length ? "?" + q : "";
  213. }
  214. get searchParams() {
  215. const p = new URLSearchParams();
  216. for (const name in this.query) {
  217. const value = this.query[name];
  218. if (Array.isArray(value)) {
  219. value.forEach((v) => p.append(name, v));
  220. } else {
  221. p.append(name, value || "");
  222. }
  223. }
  224. return p;
  225. }
  226. get origin() {
  227. return (this.protocol ? this.protocol + "//" : "") + encodeHost(this.host);
  228. }
  229. get fullpath() {
  230. return encodePath(this.pathname) + this.search + encodeHash(this.hash);
  231. }
  232. get encodedAuth() {
  233. if (!this.auth) {
  234. return "";
  235. }
  236. const { username, password } = parseAuth(this.auth);
  237. return encodeURIComponent(username) + (password ? ":" + encodeURIComponent(password) : "");
  238. }
  239. get href() {
  240. const auth = this.encodedAuth;
  241. const originWithAuth = (this.protocol ? this.protocol + "//" : "") + (auth ? auth + "@" : "") + encodeHost(this.host);
  242. return this.hasProtocol && this.isAbsolute ? originWithAuth + this.fullpath : this.fullpath;
  243. }
  244. append(url) {
  245. if (url.hasProtocol) {
  246. throw new Error("Cannot append a URL with protocol");
  247. }
  248. Object.assign(this.query, url.query);
  249. if (url.pathname) {
  250. this.pathname = withTrailingSlash(this.pathname) + withoutLeadingSlash(url.pathname);
  251. }
  252. if (url.hash) {
  253. this.hash = url.hash;
  254. }
  255. }
  256. toJSON() {
  257. return this.href;
  258. }
  259. toString() {
  260. return this.href;
  261. }
  262. }
  263. function isRelative(inputStr) {
  264. return ["./", "../"].some((str) => inputStr.startsWith(str));
  265. }
  266. function hasProtocol(inputStr, acceptProtocolRelative = false) {
  267. return /^\w+:\/\/.+/.test(inputStr) || acceptProtocolRelative && /^\/\/[^/]+/.test(inputStr);
  268. }
  269. const TRAILING_SLASH_RE = /\/$|\/\?/;
  270. function hasTrailingSlash(input = "", queryParams = false) {
  271. if (!queryParams) {
  272. return input.endsWith("/");
  273. }
  274. return TRAILING_SLASH_RE.test(input);
  275. }
  276. function withoutTrailingSlash(input = "", queryParams = false) {
  277. if (!queryParams) {
  278. return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
  279. }
  280. if (!hasTrailingSlash(input, true)) {
  281. return input || "/";
  282. }
  283. const [s0, ...s] = input.split("?");
  284. return (s0.slice(0, -1) || "/") + (s.length ? `?${s.join("?")}` : "");
  285. }
  286. function withTrailingSlash(input = "", queryParams = false) {
  287. if (!queryParams) {
  288. return input.endsWith("/") ? input : input + "/";
  289. }
  290. if (hasTrailingSlash(input, true)) {
  291. return input || "/";
  292. }
  293. const [s0, ...s] = input.split("?");
  294. return s0 + "/" + (s.length ? `?${s.join("?")}` : "");
  295. }
  296. function hasLeadingSlash(input = "") {
  297. return input.startsWith("/");
  298. }
  299. function withoutLeadingSlash(input = "") {
  300. return (hasLeadingSlash(input) ? input.substr(1) : input) || "/";
  301. }
  302. function withLeadingSlash(input = "") {
  303. return hasLeadingSlash(input) ? input : "/" + input;
  304. }
  305. function cleanDoubleSlashes(input = "") {
  306. return input.split("://").map((str) => str.replace(/\/{2,}/g, "/")).join("://");
  307. }
  308. function withBase(input, base) {
  309. if (isEmptyURL(base)) {
  310. return input;
  311. }
  312. const _base = withoutTrailingSlash(base);
  313. if (input.startsWith(_base)) {
  314. return input;
  315. }
  316. return joinURL(_base, input);
  317. }
  318. function withoutBase(input, base) {
  319. if (isEmptyURL(base)) {
  320. return input;
  321. }
  322. const _base = withoutTrailingSlash(base);
  323. if (input.startsWith(_base)) {
  324. return input.substr(_base.length) || "/";
  325. }
  326. return input;
  327. }
  328. function withQuery(input, query) {
  329. const parsed = parseURL(input);
  330. const mergedQuery = { ...parseQuery(parsed.search), ...query };
  331. parsed.search = stringifyQuery(mergedQuery);
  332. return stringifyParsedURL(parsed);
  333. }
  334. function getQuery(input) {
  335. return parseQuery(parseURL(input).search);
  336. }
  337. function isEmptyURL(url) {
  338. return !url || url === "/";
  339. }
  340. function isNonEmptyURL(url) {
  341. return url && url !== "/";
  342. }
  343. function joinURL(base, ...input) {
  344. let url = base || "";
  345. for (const i of input.filter(isNonEmptyURL)) {
  346. url = url ? withTrailingSlash(url) + withoutLeadingSlash(i) : i;
  347. }
  348. return url;
  349. }
  350. function createURL(input) {
  351. return new $URL(input);
  352. }
  353. function normalizeURL(input) {
  354. return createURL(input).toString();
  355. }
  356. function resolveURL(base, ...input) {
  357. const url = createURL(base);
  358. for (const i of input.filter(isNonEmptyURL)) {
  359. url.append(createURL(i));
  360. }
  361. return url.toString();
  362. }
  363. function isSamePath(p1, p2) {
  364. return decode(withoutTrailingSlash(p1)) === decode(withoutTrailingSlash(p2));
  365. }
  366. function parseURL(input = "", defaultProto) {
  367. if (!hasProtocol(input, true)) {
  368. return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
  369. }
  370. const [protocol = "", auth, hostAndPath] = (input.replace(/\\/g, "/").match(/([^:/]+:)?\/\/([^/@]+@)?(.*)/) || []).splice(1);
  371. const [host = "", path = ""] = (hostAndPath.match(/([^/?#]*)(.*)?/) || []).splice(1);
  372. const { pathname, search, hash } = parsePath(path);
  373. return {
  374. protocol,
  375. auth: auth ? auth.substr(0, auth.length - 1) : "",
  376. host,
  377. pathname,
  378. search,
  379. hash
  380. };
  381. }
  382. function parsePath(input = "") {
  383. const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
  384. return {
  385. pathname,
  386. search,
  387. hash
  388. };
  389. }
  390. function parseAuth(input = "") {
  391. const [username, password] = input.split(":");
  392. return {
  393. username: decode(username),
  394. password: decode(password)
  395. };
  396. }
  397. function parseHost(input = "") {
  398. const [hostname, port] = (input.match(/([^/]*)(:0-9+)?/) || []).splice(1);
  399. return {
  400. hostname: decode(hostname),
  401. port
  402. };
  403. }
  404. function stringifyParsedURL(parsed) {
  405. const fullpath = parsed.pathname + (parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "") + parsed.hash;
  406. if (!parsed.protocol) {
  407. return fullpath;
  408. }
  409. return parsed.protocol + "//" + (parsed.auth ? parsed.auth + "@" : "") + parsed.host + fullpath;
  410. }
  411. exports.$URL = $URL;
  412. exports.cleanDoubleSlashes = cleanDoubleSlashes;
  413. exports.createURL = createURL;
  414. exports.decode = decode;
  415. exports.decodePath = decodePath;
  416. exports.decodeQueryValue = decodeQueryValue;
  417. exports.encode = encode;
  418. exports.encodeHash = encodeHash;
  419. exports.encodeHost = encodeHost;
  420. exports.encodeParam = encodeParam;
  421. exports.encodePath = encodePath;
  422. exports.encodeQueryItem = encodeQueryItem;
  423. exports.encodeQueryKey = encodeQueryKey;
  424. exports.encodeQueryValue = encodeQueryValue;
  425. exports.getQuery = getQuery;
  426. exports.hasLeadingSlash = hasLeadingSlash;
  427. exports.hasProtocol = hasProtocol;
  428. exports.hasTrailingSlash = hasTrailingSlash;
  429. exports.isEmptyURL = isEmptyURL;
  430. exports.isNonEmptyURL = isNonEmptyURL;
  431. exports.isRelative = isRelative;
  432. exports.isSamePath = isSamePath;
  433. exports.joinURL = joinURL;
  434. exports.normalizeURL = normalizeURL;
  435. exports.parseAuth = parseAuth;
  436. exports.parseHost = parseHost;
  437. exports.parsePath = parsePath;
  438. exports.parseQuery = parseQuery;
  439. exports.parseURL = parseURL;
  440. exports.resolveURL = resolveURL;
  441. exports.stringifyParsedURL = stringifyParsedURL;
  442. exports.stringifyQuery = stringifyQuery;
  443. exports.withBase = withBase;
  444. exports.withLeadingSlash = withLeadingSlash;
  445. exports.withQuery = withQuery;
  446. exports.withTrailingSlash = withTrailingSlash;
  447. exports.withoutBase = withoutBase;
  448. exports.withoutLeadingSlash = withoutLeadingSlash;
  449. exports.withoutTrailingSlash = withoutTrailingSlash;