index.mjs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. const n = /[^\0-\x7E]/;
  2. const t = /[\x2E\u3002\uFF0E\uFF61]/g;
  3. const o = {
  4. overflow: "Overflow Error",
  5. "not-basic": "Illegal Input",
  6. "invalid-input": "Invalid Input"
  7. };
  8. const e = Math.floor;
  9. const r = String.fromCharCode;
  10. function s(n2) {
  11. throw new RangeError(o[n2]);
  12. }
  13. const c = function(n2, t2) {
  14. return n2 + 22 + 75 * (n2 < 26) - ((t2 != 0) << 5);
  15. };
  16. const u = function(n2, t2, o2) {
  17. let r2 = 0;
  18. for (n2 = o2 ? e(n2 / 700) : n2 >> 1, n2 += e(n2 / t2); n2 > 455; r2 += 36) {
  19. n2 = e(n2 / 35);
  20. }
  21. return e(r2 + 36 * n2 / (n2 + 38));
  22. };
  23. function toASCII(o2) {
  24. return function(n2, o3) {
  25. const e2 = n2.split("@");
  26. let r2 = "";
  27. e2.length > 1 && (r2 = e2[0] + "@", n2 = e2[1]);
  28. const s2 = function(n3, t2) {
  29. const o4 = [];
  30. let e3 = n3.length;
  31. for (; e3--; ) {
  32. o4[e3] = t2(n3[e3]);
  33. }
  34. return o4;
  35. }((n2 = n2.replace(t, ".")).split("."), o3).join(".");
  36. return r2 + s2;
  37. }(o2, function(t2) {
  38. return n.test(t2) ? "xn--" + function(n2) {
  39. const t3 = [];
  40. const o3 = (n2 = function(n3) {
  41. const t4 = [];
  42. let o4 = 0;
  43. const e2 = n3.length;
  44. for (; o4 < e2; ) {
  45. const r2 = n3.charCodeAt(o4++);
  46. if (r2 >= 55296 && r2 <= 56319 && o4 < e2) {
  47. const e3 = n3.charCodeAt(o4++);
  48. (64512 & e3) == 56320 ? t4.push(((1023 & r2) << 10) + (1023 & e3) + 65536) : (t4.push(r2), o4--);
  49. } else {
  50. t4.push(r2);
  51. }
  52. }
  53. return t4;
  54. }(n2)).length;
  55. let f = 128;
  56. let i = 0;
  57. let l = 72;
  58. for (const o4 of n2) {
  59. o4 < 128 && t3.push(r(o4));
  60. }
  61. const h = t3.length;
  62. let p = h;
  63. for (h && t3.push("-"); p < o3; ) {
  64. let o4 = 2147483647;
  65. for (const t4 of n2) {
  66. t4 >= f && t4 < o4 && (o4 = t4);
  67. }
  68. const a = p + 1;
  69. o4 - f > e((2147483647 - i) / a) && s("overflow"), i += (o4 - f) * a, f = o4;
  70. for (const o5 of n2) {
  71. if (o5 < f && ++i > 2147483647 && s("overflow"), o5 == f) {
  72. let n3 = i;
  73. for (let o6 = 36; ; o6 += 36) {
  74. const s2 = o6 <= l ? 1 : o6 >= l + 26 ? 26 : o6 - l;
  75. if (n3 < s2) {
  76. break;
  77. }
  78. const u2 = n3 - s2;
  79. const f2 = 36 - s2;
  80. t3.push(r(c(s2 + u2 % f2, 0))), n3 = e(u2 / f2);
  81. }
  82. t3.push(r(c(n3, 0))), l = u(i, a, p == h), i = 0, ++p;
  83. }
  84. }
  85. ++i, ++f;
  86. }
  87. return t3.join("");
  88. }(t2) : t2;
  89. });
  90. }
  91. const HASH_RE = /#/g;
  92. const AMPERSAND_RE = /&/g;
  93. const SLASH_RE = /\//g;
  94. const EQUAL_RE = /=/g;
  95. const IM_RE = /\?/g;
  96. const PLUS_RE = /\+/g;
  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, "|");
  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(input) {
  112. return encode(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
  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 {
  127. return "" + text;
  128. }
  129. }
  130. function decodePath(text) {
  131. return decode(text.replace(ENC_SLASH_RE, "%252F"));
  132. }
  133. function decodeQueryKey(text) {
  134. return decode(text.replace(PLUS_RE, " "));
  135. }
  136. function decodeQueryValue(text) {
  137. return decode(text.replace(PLUS_RE, " "));
  138. }
  139. function encodeHost(name = "") {
  140. return toASCII(name);
  141. }
  142. function parseQuery(parametersString = "") {
  143. const object = {};
  144. if (parametersString[0] === "?") {
  145. parametersString = parametersString.slice(1);
  146. }
  147. for (const parameter of parametersString.split("&")) {
  148. const s = parameter.match(/([^=]+)=?(.*)/) || [];
  149. if (s.length < 2) {
  150. continue;
  151. }
  152. const key = decodeQueryKey(s[1]);
  153. if (key === "__proto__" || key === "constructor") {
  154. continue;
  155. }
  156. const value = decodeQueryValue(s[2] || "");
  157. if (object[key] === void 0) {
  158. object[key] = value;
  159. } else if (Array.isArray(object[key])) {
  160. object[key].push(value);
  161. } else {
  162. object[key] = [object[key], value];
  163. }
  164. }
  165. return object;
  166. }
  167. function encodeQueryItem(key, value) {
  168. if (typeof value === "number" || typeof value === "boolean") {
  169. value = String(value);
  170. }
  171. if (!value) {
  172. return encodeQueryKey(key);
  173. }
  174. if (Array.isArray(value)) {
  175. return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
  176. }
  177. return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
  178. }
  179. function stringifyQuery(query) {
  180. return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
  181. }
  182. const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
  183. const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
  184. const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
  185. const PROTOCOL_SCRIPT_RE = /^[\s\0]*(blob|data|javascript|vbscript):$/i;
  186. const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
  187. const JOIN_LEADING_SLASH_RE = /^\.?\//;
  188. function isRelative(inputString) {
  189. return ["./", "../"].some((string_) => inputString.startsWith(string_));
  190. }
  191. function hasProtocol(inputString, opts = {}) {
  192. if (typeof opts === "boolean") {
  193. opts = { acceptRelative: opts };
  194. }
  195. if (opts.strict) {
  196. return PROTOCOL_STRICT_REGEX.test(inputString);
  197. }
  198. return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
  199. }
  200. function isScriptProtocol(protocol) {
  201. return !!protocol && PROTOCOL_SCRIPT_RE.test(protocol);
  202. }
  203. function hasTrailingSlash(input = "", respectQueryAndFragment) {
  204. if (!respectQueryAndFragment) {
  205. return input.endsWith("/");
  206. }
  207. return TRAILING_SLASH_RE.test(input);
  208. }
  209. function withoutTrailingSlash(input = "", respectQueryAndFragment) {
  210. if (!respectQueryAndFragment) {
  211. return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
  212. }
  213. if (!hasTrailingSlash(input, true)) {
  214. return input || "/";
  215. }
  216. let path = input;
  217. let fragment = "";
  218. const fragmentIndex = input.indexOf("#");
  219. if (fragmentIndex >= 0) {
  220. path = input.slice(0, fragmentIndex);
  221. fragment = input.slice(fragmentIndex);
  222. }
  223. const [s0, ...s] = path.split("?");
  224. const cleanPath = s0.endsWith("/") ? s0.slice(0, -1) : s0;
  225. return (cleanPath || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
  226. }
  227. function withTrailingSlash(input = "", respectQueryAndFragment) {
  228. if (!respectQueryAndFragment) {
  229. return input.endsWith("/") ? input : input + "/";
  230. }
  231. if (hasTrailingSlash(input, true)) {
  232. return input || "/";
  233. }
  234. let path = input;
  235. let fragment = "";
  236. const fragmentIndex = input.indexOf("#");
  237. if (fragmentIndex >= 0) {
  238. path = input.slice(0, fragmentIndex);
  239. fragment = input.slice(fragmentIndex);
  240. if (!path) {
  241. return fragment;
  242. }
  243. }
  244. const [s0, ...s] = path.split("?");
  245. return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
  246. }
  247. function hasLeadingSlash(input = "") {
  248. return input.startsWith("/");
  249. }
  250. function withoutLeadingSlash(input = "") {
  251. return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
  252. }
  253. function withLeadingSlash(input = "") {
  254. return hasLeadingSlash(input) ? input : "/" + input;
  255. }
  256. function cleanDoubleSlashes(input = "") {
  257. return input.split("://").map((string_) => string_.replace(/\/{2,}/g, "/")).join("://");
  258. }
  259. function withBase(input, base) {
  260. if (isEmptyURL(base) || hasProtocol(input)) {
  261. return input;
  262. }
  263. const _base = withoutTrailingSlash(base);
  264. if (input.startsWith(_base)) {
  265. return input;
  266. }
  267. return joinURL(_base, input);
  268. }
  269. function withoutBase(input, base) {
  270. if (isEmptyURL(base)) {
  271. return input;
  272. }
  273. const _base = withoutTrailingSlash(base);
  274. if (!input.startsWith(_base)) {
  275. return input;
  276. }
  277. const trimmed = input.slice(_base.length);
  278. return trimmed[0] === "/" ? trimmed : "/" + trimmed;
  279. }
  280. function withQuery(input, query) {
  281. const parsed = parseURL(input);
  282. const mergedQuery = { ...parseQuery(parsed.search), ...query };
  283. parsed.search = stringifyQuery(mergedQuery);
  284. return stringifyParsedURL(parsed);
  285. }
  286. function getQuery(input) {
  287. return parseQuery(parseURL(input).search);
  288. }
  289. function isEmptyURL(url) {
  290. return !url || url === "/";
  291. }
  292. function isNonEmptyURL(url) {
  293. return url && url !== "/";
  294. }
  295. function joinURL(base, ...input) {
  296. let url = base || "";
  297. for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
  298. if (url) {
  299. const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
  300. url = withTrailingSlash(url) + _segment;
  301. } else {
  302. url = segment;
  303. }
  304. }
  305. return url;
  306. }
  307. function joinRelativeURL(..._input) {
  308. const JOIN_SEGMENT_SPLIT_RE = /\/(?!\/)/;
  309. const input = _input.filter(Boolean);
  310. const segments = [];
  311. let segmentsDepth = 0;
  312. for (const i of input) {
  313. if (!i || i === "/") {
  314. continue;
  315. }
  316. for (const [sindex, s] of i.split(JOIN_SEGMENT_SPLIT_RE).entries()) {
  317. if (!s || s === ".") {
  318. continue;
  319. }
  320. if (s === "..") {
  321. if (segments.length === 1 && hasProtocol(segments[0])) {
  322. continue;
  323. }
  324. segments.pop();
  325. segmentsDepth--;
  326. continue;
  327. }
  328. if (sindex === 1 && segments[segments.length - 1]?.endsWith(":/")) {
  329. segments[segments.length - 1] += "/" + s;
  330. continue;
  331. }
  332. segments.push(s);
  333. segmentsDepth++;
  334. }
  335. }
  336. let url = segments.join("/");
  337. if (segmentsDepth >= 0) {
  338. if (input[0]?.startsWith("/") && !url.startsWith("/")) {
  339. url = "/" + url;
  340. } else if (input[0]?.startsWith("./") && !url.startsWith("./")) {
  341. url = "./" + url;
  342. }
  343. } else {
  344. url = "../".repeat(-1 * segmentsDepth) + url;
  345. }
  346. if (input[input.length - 1]?.endsWith("/") && !url.endsWith("/")) {
  347. url += "/";
  348. }
  349. return url;
  350. }
  351. function withHttp(input) {
  352. return withProtocol(input, "http://");
  353. }
  354. function withHttps(input) {
  355. return withProtocol(input, "https://");
  356. }
  357. function withoutProtocol(input) {
  358. return withProtocol(input, "");
  359. }
  360. function withProtocol(input, protocol) {
  361. let match = input.match(PROTOCOL_REGEX);
  362. if (!match) {
  363. match = input.match(/^\/{2,}/);
  364. }
  365. if (!match) {
  366. return protocol + input;
  367. }
  368. return protocol + input.slice(match[0].length);
  369. }
  370. function normalizeURL(input) {
  371. const parsed = parseURL(input);
  372. parsed.pathname = encodePath(decodePath(parsed.pathname));
  373. parsed.hash = encodeHash(decode(parsed.hash));
  374. parsed.host = encodeHost(decode(parsed.host));
  375. parsed.search = stringifyQuery(parseQuery(parsed.search));
  376. return stringifyParsedURL(parsed);
  377. }
  378. function resolveURL(base = "", ...inputs) {
  379. if (typeof base !== "string") {
  380. throw new TypeError(
  381. `URL input should be string received ${typeof base} (${base})`
  382. );
  383. }
  384. const filteredInputs = inputs.filter((input) => isNonEmptyURL(input));
  385. if (filteredInputs.length === 0) {
  386. return base;
  387. }
  388. const url = parseURL(base);
  389. for (const inputSegment of filteredInputs) {
  390. const urlSegment = parseURL(inputSegment);
  391. if (urlSegment.pathname) {
  392. url.pathname = withTrailingSlash(url.pathname) + withoutLeadingSlash(urlSegment.pathname);
  393. }
  394. if (urlSegment.hash && urlSegment.hash !== "#") {
  395. url.hash = urlSegment.hash;
  396. }
  397. if (urlSegment.search && urlSegment.search !== "?") {
  398. if (url.search && url.search !== "?") {
  399. const queryString = stringifyQuery({
  400. ...parseQuery(url.search),
  401. ...parseQuery(urlSegment.search)
  402. });
  403. url.search = queryString.length > 0 ? "?" + queryString : "";
  404. } else {
  405. url.search = urlSegment.search;
  406. }
  407. }
  408. }
  409. return stringifyParsedURL(url);
  410. }
  411. function isSamePath(p1, p2) {
  412. return decode(withoutTrailingSlash(p1)) === decode(withoutTrailingSlash(p2));
  413. }
  414. function isEqual(a, b, options = {}) {
  415. if (!options.trailingSlash) {
  416. a = withTrailingSlash(a);
  417. b = withTrailingSlash(b);
  418. }
  419. if (!options.leadingSlash) {
  420. a = withLeadingSlash(a);
  421. b = withLeadingSlash(b);
  422. }
  423. if (!options.encoding) {
  424. a = decode(a);
  425. b = decode(b);
  426. }
  427. return a === b;
  428. }
  429. function withFragment(input, hash) {
  430. if (!hash || hash === "#") {
  431. return input;
  432. }
  433. const parsed = parseURL(input);
  434. parsed.hash = hash === "" ? "" : "#" + encodeHash(hash);
  435. return stringifyParsedURL(parsed);
  436. }
  437. function withoutFragment(input) {
  438. return stringifyParsedURL({ ...parseURL(input), hash: "" });
  439. }
  440. function withoutHost(input) {
  441. const parsed = parseURL(input);
  442. return (parsed.pathname || "/") + parsed.search + parsed.hash;
  443. }
  444. const protocolRelative = Symbol.for("ufo:protocolRelative");
  445. function parseURL(input = "", defaultProto) {
  446. const _specialProtoMatch = input.match(
  447. /^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
  448. );
  449. if (_specialProtoMatch) {
  450. const [, _proto, _pathname = ""] = _specialProtoMatch;
  451. return {
  452. protocol: _proto.toLowerCase(),
  453. pathname: _pathname,
  454. href: _proto + _pathname,
  455. auth: "",
  456. host: "",
  457. search: "",
  458. hash: ""
  459. };
  460. }
  461. if (!hasProtocol(input, { acceptRelative: true })) {
  462. return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
  463. }
  464. const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
  465. let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
  466. if (protocol === "file:") {
  467. path = path.replace(/\/(?=[A-Za-z]:)/, "");
  468. }
  469. const { pathname, search, hash } = parsePath(path);
  470. return {
  471. protocol: protocol.toLowerCase(),
  472. auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
  473. host,
  474. pathname,
  475. search,
  476. hash,
  477. [protocolRelative]: !protocol
  478. };
  479. }
  480. function parsePath(input = "") {
  481. const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
  482. return {
  483. pathname,
  484. search,
  485. hash
  486. };
  487. }
  488. function parseAuth(input = "") {
  489. const [username, password] = input.split(":");
  490. return {
  491. username: decode(username),
  492. password: decode(password)
  493. };
  494. }
  495. function parseHost(input = "") {
  496. const [hostname, port] = (input.match(/([^/:]*):?(\d+)?/) || []).splice(1);
  497. return {
  498. hostname: decode(hostname),
  499. port
  500. };
  501. }
  502. function stringifyParsedURL(parsed) {
  503. const pathname = parsed.pathname || "";
  504. const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
  505. const hash = parsed.hash || "";
  506. const auth = parsed.auth ? parsed.auth + "@" : "";
  507. const host = parsed.host || "";
  508. const proto = parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "";
  509. return proto + auth + host + pathname + search + hash;
  510. }
  511. const FILENAME_STRICT_REGEX = /\/([^/]+\.[^/]+)$/;
  512. const FILENAME_REGEX = /\/([^/]+)$/;
  513. function parseFilename(input = "", { strict }) {
  514. const { pathname } = parseURL(input);
  515. const matches = strict ? pathname.match(FILENAME_STRICT_REGEX) : pathname.match(FILENAME_REGEX);
  516. return matches ? matches[1] : void 0;
  517. }
  518. var __defProp = Object.defineProperty;
  519. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  520. var __publicField = (obj, key, value) => {
  521. __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  522. return value;
  523. };
  524. class $URL {
  525. constructor(input = "") {
  526. __publicField(this, "protocol");
  527. __publicField(this, "host");
  528. __publicField(this, "auth");
  529. __publicField(this, "pathname");
  530. __publicField(this, "query", {});
  531. __publicField(this, "hash");
  532. if (typeof input !== "string") {
  533. throw new TypeError(
  534. `URL input should be string received ${typeof input} (${input})`
  535. );
  536. }
  537. const parsed = parseURL(input);
  538. this.protocol = decode(parsed.protocol);
  539. this.host = decode(parsed.host);
  540. this.auth = decode(parsed.auth);
  541. this.pathname = decodePath(parsed.pathname);
  542. this.query = parseQuery(parsed.search);
  543. this.hash = decode(parsed.hash);
  544. }
  545. get hostname() {
  546. return parseHost(this.host).hostname;
  547. }
  548. get port() {
  549. return parseHost(this.host).port || "";
  550. }
  551. get username() {
  552. return parseAuth(this.auth).username;
  553. }
  554. get password() {
  555. return parseAuth(this.auth).password || "";
  556. }
  557. get hasProtocol() {
  558. return this.protocol.length;
  559. }
  560. get isAbsolute() {
  561. return this.hasProtocol || this.pathname[0] === "/";
  562. }
  563. get search() {
  564. const q = stringifyQuery(this.query);
  565. return q.length > 0 ? "?" + q : "";
  566. }
  567. get searchParams() {
  568. const p = new URLSearchParams();
  569. for (const name in this.query) {
  570. const value = this.query[name];
  571. if (Array.isArray(value)) {
  572. for (const v of value) {
  573. p.append(name, v);
  574. }
  575. } else {
  576. p.append(
  577. name,
  578. typeof value === "string" ? value : JSON.stringify(value)
  579. );
  580. }
  581. }
  582. return p;
  583. }
  584. get origin() {
  585. return (this.protocol ? this.protocol + "//" : "") + encodeHost(this.host);
  586. }
  587. get fullpath() {
  588. return encodePath(this.pathname) + this.search + encodeHash(this.hash);
  589. }
  590. get encodedAuth() {
  591. if (!this.auth) {
  592. return "";
  593. }
  594. const { username, password } = parseAuth(this.auth);
  595. return encodeURIComponent(username) + (password ? ":" + encodeURIComponent(password) : "");
  596. }
  597. get href() {
  598. const auth = this.encodedAuth;
  599. const originWithAuth = (this.protocol ? this.protocol + "//" : "") + (auth ? auth + "@" : "") + encodeHost(this.host);
  600. return this.hasProtocol && this.isAbsolute ? originWithAuth + this.fullpath : this.fullpath;
  601. }
  602. append(url) {
  603. if (url.hasProtocol) {
  604. throw new Error("Cannot append a URL with protocol");
  605. }
  606. Object.assign(this.query, url.query);
  607. if (url.pathname) {
  608. this.pathname = withTrailingSlash(this.pathname) + withoutLeadingSlash(url.pathname);
  609. }
  610. if (url.hash) {
  611. this.hash = url.hash;
  612. }
  613. }
  614. toJSON() {
  615. return this.href;
  616. }
  617. toString() {
  618. return this.href;
  619. }
  620. }
  621. function createURL(input) {
  622. return new $URL(input);
  623. }
  624. export { $URL, cleanDoubleSlashes, createURL, decode, decodePath, decodeQueryKey, decodeQueryValue, encode, encodeHash, encodeHost, encodeParam, encodePath, encodeQueryItem, encodeQueryKey, encodeQueryValue, getQuery, hasLeadingSlash, hasProtocol, hasTrailingSlash, isEmptyURL, isEqual, isNonEmptyURL, isRelative, isSamePath, isScriptProtocol, joinRelativeURL, joinURL, normalizeURL, parseAuth, parseFilename, parseHost, parsePath, parseQuery, parseURL, resolveURL, stringifyParsedURL, stringifyQuery, withBase, withFragment, withHttp, withHttps, withLeadingSlash, withProtocol, withQuery, withTrailingSlash, withoutBase, withoutFragment, withoutHost, withoutLeadingSlash, withoutProtocol, withoutTrailingSlash };