initial commit
This commit is contained in:
21
node_modules/ufo/LICENSE
generated
vendored
Normal file
21
node_modules/ufo/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
234
node_modules/ufo/README.md
generated
vendored
Normal file
234
node_modules/ufo/README.md
generated
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
||||
[![Github Actions][github-actions-src]][github-actions-href]
|
||||
[![Codecov][codecov-src]][codecov-href]
|
||||
[![bundle][bundle-src]][bundle-href]
|
||||
|
||||

|
||||
|
||||
## Install
|
||||
|
||||
Install using npm or yarn:
|
||||
|
||||
```bash
|
||||
npm i ufo
|
||||
# or
|
||||
yarn add ufo
|
||||
```
|
||||
|
||||
Import:
|
||||
|
||||
```js
|
||||
// CommonJS
|
||||
const { normalizeURL, joinURL } = require('ufo')
|
||||
|
||||
// ESM
|
||||
import { normalizeURL, joinURL } from 'ufo'
|
||||
|
||||
// Deno
|
||||
import { parseURL } from 'https://unpkg.com/ufo/dist/index.mjs'
|
||||
```
|
||||
|
||||
**Notice:** You may need to transpile package and add URL polyfill for legacy environments
|
||||
|
||||
## Usage
|
||||
|
||||
### `normalizeURL`
|
||||
|
||||
- Ensures URL is properly encoded
|
||||
- Ensures pathname starts with slash
|
||||
- Preserves protocol/host if provided
|
||||
|
||||
```ts
|
||||
|
||||
// Result: test?query=123%20123#hash,%20test
|
||||
normalizeURL('test?query=123 123#hash, test')
|
||||
|
||||
// Result: http://localhost:3000/
|
||||
normalizeURL('http://localhost:3000')
|
||||
```
|
||||
|
||||
### `joinURL`
|
||||
|
||||
```ts
|
||||
// Result: a/b/c
|
||||
joinURL('a', '/b', '/c')
|
||||
```
|
||||
|
||||
### `resolveURL`
|
||||
|
||||
```ts
|
||||
// Result: http://foo.com/foo/bar/baz?test=123#token
|
||||
resolveURL('http://foo.com/foo?test=123#token', 'bar', 'baz')
|
||||
```
|
||||
|
||||
### `parseURL`
|
||||
|
||||
```ts
|
||||
// Result: { protocol: 'http:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }
|
||||
parseURL('http://foo.com/foo?test=123#token')
|
||||
|
||||
// Result: { pathname: 'foo.com/foo', search: '?test=123', hash: '#token' }
|
||||
parseURL('foo.com/foo?test=123#token')
|
||||
|
||||
// Result: { protocol: 'https:', auth: '', host: 'foo.com', pathname: '/foo', search: '?test=123', hash: '#token' }
|
||||
parseURL('foo.com/foo?test=123#token', 'https://')
|
||||
```
|
||||
|
||||
### `withQuery`
|
||||
|
||||
```ts
|
||||
// Result: /foo?page=a&token=secret
|
||||
withQuery('/foo?page=a', { token: 'secret' })
|
||||
```
|
||||
|
||||
### `getQuery`
|
||||
|
||||
```ts
|
||||
// Result: { test: '123', unicode: '好' }
|
||||
getQuery('http://foo.com/foo?test=123&unicode=%E5%A5%BD')
|
||||
```
|
||||
|
||||
### `$URL`
|
||||
|
||||
Implementing URL interface with some improvements:
|
||||
|
||||
- Supporting schemeless and hostless URLs
|
||||
- Supporting relative URLs
|
||||
- Preserving trailing-slash status
|
||||
- Decoded and mutable classs properties (`protocol`, `host`, `auth`, `pathname`, `query`, `hash`)
|
||||
- Consistent URL parser independent of environment
|
||||
- Consistent encoding independent of environment
|
||||
- Punycode support for host encoding
|
||||
|
||||
### `withTrailingSlash`
|
||||
|
||||
Ensures url ends with a trailing slash
|
||||
|
||||
```ts
|
||||
// Result: /foo/
|
||||
withTrailingSlash('/foo')
|
||||
```
|
||||
|
||||
```ts
|
||||
// Result: /path/?query=true
|
||||
withTrailingSlash('/path?query=true', true)
|
||||
```
|
||||
|
||||
### `withoutTrailingSlash`
|
||||
|
||||
Ensures url does not ends with a trailing slash
|
||||
|
||||
```ts
|
||||
// Result: /foo
|
||||
withoutTrailingSlash('/foo/')
|
||||
```
|
||||
|
||||
```ts
|
||||
// Result: /path?query=true
|
||||
withoutTrailingSlash('/path/?query=true', true)
|
||||
```
|
||||
|
||||
### `cleanDoubleSlashes`
|
||||
|
||||
Ensures url does not have double slash (except for protocol)
|
||||
|
||||
```ts
|
||||
// Result: /foo/bar/
|
||||
cleanDoubleSlashes('//foo//bar//')
|
||||
// Result: http://example.com/analyze/http://localhost:3000/
|
||||
cleanDoubleSlashes('http://example.com/analyze//http://localhost:3000//')
|
||||
```
|
||||
|
||||
### `isSamePath`
|
||||
|
||||
Check two paths are equal or not. Trailing slash and encoding are normalized before comparation.
|
||||
|
||||
```ts
|
||||
// Result: true
|
||||
isSamePath('/foo', '/foo/')
|
||||
```
|
||||
|
||||
### `isRelative`
|
||||
|
||||
Check if a path starts with `./` or `../`.
|
||||
|
||||
```ts
|
||||
// Result: true
|
||||
isRelative('./foo')
|
||||
```
|
||||
|
||||
### `withHttp`
|
||||
|
||||
Ensures url protocol is `http`
|
||||
|
||||
```ts
|
||||
// Result: http://example.com
|
||||
withHttp('https://example.com')
|
||||
```
|
||||
|
||||
### `withHttps`
|
||||
|
||||
Ensures url protocol is `https`
|
||||
|
||||
```ts
|
||||
// Result: https://example.com
|
||||
withHttps('http://example.com')
|
||||
```
|
||||
|
||||
### `withProtocol`
|
||||
|
||||
Changes url protocol passed as second argument
|
||||
|
||||
```ts
|
||||
// Result: ftp://example.com
|
||||
withProtocol('http://example.com', 'ftp://')
|
||||
```
|
||||
|
||||
### `withoutProtocol`
|
||||
|
||||
Removes url protocol
|
||||
|
||||
```ts
|
||||
// Result: example.com
|
||||
withoutProtocol('http://example.com')
|
||||
```
|
||||
|
||||
### `isEqual`
|
||||
|
||||
Compare two URLs regardless of their slash condition or encoding:
|
||||
|
||||
```ts
|
||||
// Result: true
|
||||
isEqual('/foo', 'foo')
|
||||
isEqual('foo/', 'foo')
|
||||
isEqual('/foo bar', '/foo%20bar')
|
||||
|
||||
// Strict compare
|
||||
// Result: false
|
||||
isEqual('/foo', 'foo', { leadingSlash: true })
|
||||
isEqual('foo/', 'foo', { trailingSlash: true })
|
||||
isEqual('/foo bar', '/foo%20bar', { encoding: true })
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE)
|
||||
|
||||
Special thanks to Eduardo San Martin Morote ([posva](https://github.com/posva)) for [encoding utlities](https://github.com/vuejs/vue-router-next/blob/v4.0.1/src/encoding.ts)
|
||||
|
||||
<!-- Badges -->
|
||||
[npm-version-src]: https://img.shields.io/npm/v/ufo?style=flat-square
|
||||
[npm-version-href]: https://npmjs.com/package/ufo
|
||||
|
||||
[npm-downloads-src]: https://img.shields.io/npm/dm/ufo?style=flat-square
|
||||
[npm-downloads-href]: https://npmjs.com/package/ufo
|
||||
|
||||
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ufo/ci/main?style=flat-square
|
||||
[github-actions-href]: https://github.com/unjs/ufo/actions?query=workflow%3Aci
|
||||
|
||||
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ufo/main?style=flat-square
|
||||
[codecov-href]: https://codecov.io/gh/unjs/ufo
|
||||
|
||||
[bundle-src]: https://img.shields.io/bundlephobia/minzip/ufo?style=flat-square
|
||||
[bundle-href]: https://bundlephobia.com/result?p=ufo
|
||||
499
node_modules/ufo/dist/index.cjs
generated
vendored
Normal file
499
node_modules/ufo/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,499 @@
|
||||
'use strict';
|
||||
|
||||
const n = /[^\0-\x7E]/;
|
||||
const t = /[\x2E\u3002\uFF0E\uFF61]/g;
|
||||
const o = { overflow: "Overflow Error", "not-basic": "Illegal Input", "invalid-input": "Invalid Input" };
|
||||
const e = Math.floor;
|
||||
const r = String.fromCharCode;
|
||||
function s(n2) {
|
||||
throw new RangeError(o[n2]);
|
||||
}
|
||||
const c = function(n2, t2) {
|
||||
return n2 + 22 + 75 * (n2 < 26) - ((t2 != 0) << 5);
|
||||
};
|
||||
const u = function(n2, t2, o2) {
|
||||
let r2 = 0;
|
||||
for (n2 = o2 ? e(n2 / 700) : n2 >> 1, n2 += e(n2 / t2); n2 > 455; r2 += 36) {
|
||||
n2 = e(n2 / 35);
|
||||
}
|
||||
return e(r2 + 36 * n2 / (n2 + 38));
|
||||
};
|
||||
function toASCII(o2) {
|
||||
return function(n2, o3) {
|
||||
const e2 = n2.split("@");
|
||||
let r2 = "";
|
||||
e2.length > 1 && (r2 = e2[0] + "@", n2 = e2[1]);
|
||||
const s2 = function(n3, t2) {
|
||||
const o4 = [];
|
||||
let e3 = n3.length;
|
||||
for (; e3--; ) {
|
||||
o4[e3] = t2(n3[e3]);
|
||||
}
|
||||
return o4;
|
||||
}((n2 = n2.replace(t, ".")).split("."), o3).join(".");
|
||||
return r2 + s2;
|
||||
}(o2, function(t2) {
|
||||
return n.test(t2) ? "xn--" + function(n2) {
|
||||
const t3 = [];
|
||||
const o3 = (n2 = function(n3) {
|
||||
const t4 = [];
|
||||
let o4 = 0;
|
||||
const e2 = n3.length;
|
||||
for (; o4 < e2; ) {
|
||||
const r2 = n3.charCodeAt(o4++);
|
||||
if (r2 >= 55296 && r2 <= 56319 && o4 < e2) {
|
||||
const e3 = n3.charCodeAt(o4++);
|
||||
(64512 & e3) == 56320 ? t4.push(((1023 & r2) << 10) + (1023 & e3) + 65536) : (t4.push(r2), o4--);
|
||||
} else {
|
||||
t4.push(r2);
|
||||
}
|
||||
}
|
||||
return t4;
|
||||
}(n2)).length;
|
||||
let f = 128;
|
||||
let i = 0;
|
||||
let l = 72;
|
||||
for (const o4 of n2) {
|
||||
o4 < 128 && t3.push(r(o4));
|
||||
}
|
||||
const h = t3.length;
|
||||
let p = h;
|
||||
for (h && t3.push("-"); p < o3; ) {
|
||||
let o4 = 2147483647;
|
||||
for (const t4 of n2) {
|
||||
t4 >= f && t4 < o4 && (o4 = t4);
|
||||
}
|
||||
const a = p + 1;
|
||||
o4 - f > e((2147483647 - i) / a) && s("overflow"), i += (o4 - f) * a, f = o4;
|
||||
for (const o5 of n2) {
|
||||
if (o5 < f && ++i > 2147483647 && s("overflow"), o5 == f) {
|
||||
let n3 = i;
|
||||
for (let o6 = 36; ; o6 += 36) {
|
||||
const s2 = o6 <= l ? 1 : o6 >= l + 26 ? 26 : o6 - l;
|
||||
if (n3 < s2) {
|
||||
break;
|
||||
}
|
||||
const u2 = n3 - s2;
|
||||
const f2 = 36 - s2;
|
||||
t3.push(r(c(s2 + u2 % f2, 0))), n3 = e(u2 / f2);
|
||||
}
|
||||
t3.push(r(c(n3, 0))), l = u(i, a, p == h), i = 0, ++p;
|
||||
}
|
||||
}
|
||||
++i, ++f;
|
||||
}
|
||||
return t3.join("");
|
||||
}(t2) : t2;
|
||||
});
|
||||
}
|
||||
|
||||
const HASH_RE = /#/g;
|
||||
const AMPERSAND_RE = /&/g;
|
||||
const SLASH_RE = /\//g;
|
||||
const EQUAL_RE = /=/g;
|
||||
const IM_RE = /\?/g;
|
||||
const PLUS_RE = /\+/g;
|
||||
const ENC_BRACKET_OPEN_RE = /%5b/gi;
|
||||
const ENC_BRACKET_CLOSE_RE = /%5d/gi;
|
||||
const ENC_CARET_RE = /%5e/gi;
|
||||
const ENC_BACKTICK_RE = /%60/gi;
|
||||
const ENC_CURLY_OPEN_RE = /%7b/gi;
|
||||
const ENC_PIPE_RE = /%7c/gi;
|
||||
const ENC_CURLY_CLOSE_RE = /%7d/gi;
|
||||
const ENC_SPACE_RE = /%20/gi;
|
||||
const ENC_SLASH_RE = /%2f/gi;
|
||||
const ENC_ENC_SLASH_RE = /%252f/gi;
|
||||
function encode(text) {
|
||||
return encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
|
||||
}
|
||||
function encodeHash(text) {
|
||||
return encode(text).replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
|
||||
}
|
||||
function encodeQueryValue(text) {
|
||||
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, "^");
|
||||
}
|
||||
function encodeQueryKey(text) {
|
||||
return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
|
||||
}
|
||||
function encodePath(text) {
|
||||
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");
|
||||
}
|
||||
function encodeParam(text) {
|
||||
return encodePath(text).replace(SLASH_RE, "%2F");
|
||||
}
|
||||
function decode(text = "") {
|
||||
try {
|
||||
return decodeURIComponent("" + text);
|
||||
} catch {
|
||||
return "" + text;
|
||||
}
|
||||
}
|
||||
function decodePath(text) {
|
||||
return decode(text.replace(ENC_SLASH_RE, "%252F"));
|
||||
}
|
||||
function decodeQueryValue(text) {
|
||||
return decode(text.replace(PLUS_RE, " "));
|
||||
}
|
||||
function encodeHost(name = "") {
|
||||
return toASCII(name);
|
||||
}
|
||||
|
||||
function parseQuery(parametersString = "") {
|
||||
const object = {};
|
||||
if (parametersString[0] === "?") {
|
||||
parametersString = parametersString.slice(1);
|
||||
}
|
||||
for (const parameter of parametersString.split("&")) {
|
||||
const s = parameter.match(/([^=]+)=?(.*)/) || [];
|
||||
if (s.length < 2) {
|
||||
continue;
|
||||
}
|
||||
const key = decode(s[1]);
|
||||
if (key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = decodeQueryValue(s[2] || "");
|
||||
if (typeof object[key] !== "undefined") {
|
||||
if (Array.isArray(object[key])) {
|
||||
object[key].push(value);
|
||||
} else {
|
||||
object[key] = [object[key], value];
|
||||
}
|
||||
} else {
|
||||
object[key] = value;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
function encodeQueryItem(key, value) {
|
||||
if (typeof value === "number" || typeof value === "boolean") {
|
||||
value = String(value);
|
||||
}
|
||||
if (!value) {
|
||||
return encodeQueryKey(key);
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
|
||||
}
|
||||
return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
|
||||
}
|
||||
function stringifyQuery(query) {
|
||||
return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).join("&");
|
||||
}
|
||||
|
||||
class $URL {
|
||||
constructor(input = "") {
|
||||
this.query = {};
|
||||
if (typeof input !== "string") {
|
||||
throw new TypeError(`URL input should be string received ${typeof input} (${input})`);
|
||||
}
|
||||
const parsed = parseURL(input);
|
||||
this.protocol = decode(parsed.protocol);
|
||||
this.host = decode(parsed.host);
|
||||
this.auth = decode(parsed.auth);
|
||||
this.pathname = decodePath(parsed.pathname);
|
||||
this.query = parseQuery(parsed.search);
|
||||
this.hash = decode(parsed.hash);
|
||||
}
|
||||
get hostname() {
|
||||
return parseHost(this.host).hostname;
|
||||
}
|
||||
get port() {
|
||||
return parseHost(this.host).port || "";
|
||||
}
|
||||
get username() {
|
||||
return parseAuth(this.auth).username;
|
||||
}
|
||||
get password() {
|
||||
return parseAuth(this.auth).password || "";
|
||||
}
|
||||
get hasProtocol() {
|
||||
return this.protocol.length;
|
||||
}
|
||||
get isAbsolute() {
|
||||
return this.hasProtocol || this.pathname[0] === "/";
|
||||
}
|
||||
get search() {
|
||||
const q = stringifyQuery(this.query);
|
||||
return q.length > 0 ? "?" + q : "";
|
||||
}
|
||||
get searchParams() {
|
||||
const p = new URLSearchParams();
|
||||
for (const name in this.query) {
|
||||
const value = this.query[name];
|
||||
if (Array.isArray(value)) {
|
||||
for (const v of value) {
|
||||
p.append(name, v);
|
||||
}
|
||||
} else {
|
||||
p.append(name, value || "");
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
get origin() {
|
||||
return (this.protocol ? this.protocol + "//" : "") + encodeHost(this.host);
|
||||
}
|
||||
get fullpath() {
|
||||
return encodePath(this.pathname) + this.search + encodeHash(this.hash);
|
||||
}
|
||||
get encodedAuth() {
|
||||
if (!this.auth) {
|
||||
return "";
|
||||
}
|
||||
const { username, password } = parseAuth(this.auth);
|
||||
return encodeURIComponent(username) + (password ? ":" + encodeURIComponent(password) : "");
|
||||
}
|
||||
get href() {
|
||||
const auth = this.encodedAuth;
|
||||
const originWithAuth = (this.protocol ? this.protocol + "//" : "") + (auth ? auth + "@" : "") + encodeHost(this.host);
|
||||
return this.hasProtocol && this.isAbsolute ? originWithAuth + this.fullpath : this.fullpath;
|
||||
}
|
||||
append(url) {
|
||||
if (url.hasProtocol) {
|
||||
throw new Error("Cannot append a URL with protocol");
|
||||
}
|
||||
Object.assign(this.query, url.query);
|
||||
if (url.pathname) {
|
||||
this.pathname = withTrailingSlash(this.pathname) + withoutLeadingSlash(url.pathname);
|
||||
}
|
||||
if (url.hash) {
|
||||
this.hash = url.hash;
|
||||
}
|
||||
}
|
||||
toJSON() {
|
||||
return this.href;
|
||||
}
|
||||
toString() {
|
||||
return this.href;
|
||||
}
|
||||
}
|
||||
|
||||
function isRelative(inputString) {
|
||||
return ["./", "../"].some((string_) => inputString.startsWith(string_));
|
||||
}
|
||||
const PROTOCOL_REGEX = /^\w{2,}:(\/\/)?/;
|
||||
const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
|
||||
function hasProtocol(inputString, acceptProtocolRelative = false) {
|
||||
return PROTOCOL_REGEX.test(inputString) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputString);
|
||||
}
|
||||
const TRAILING_SLASH_RE = /\/$|\/\?/;
|
||||
function hasTrailingSlash(input = "", queryParameters = false) {
|
||||
if (!queryParameters) {
|
||||
return input.endsWith("/");
|
||||
}
|
||||
return TRAILING_SLASH_RE.test(input);
|
||||
}
|
||||
function withoutTrailingSlash(input = "", queryParameters = false) {
|
||||
if (!queryParameters) {
|
||||
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
||||
}
|
||||
if (!hasTrailingSlash(input, true)) {
|
||||
return input || "/";
|
||||
}
|
||||
const [s0, ...s] = input.split("?");
|
||||
return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function withTrailingSlash(input = "", queryParameters = false) {
|
||||
if (!queryParameters) {
|
||||
return input.endsWith("/") ? input : input + "/";
|
||||
}
|
||||
if (hasTrailingSlash(input, true)) {
|
||||
return input || "/";
|
||||
}
|
||||
const [s0, ...s] = input.split("?");
|
||||
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function hasLeadingSlash(input = "") {
|
||||
return input.startsWith("/");
|
||||
}
|
||||
function withoutLeadingSlash(input = "") {
|
||||
return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
|
||||
}
|
||||
function withLeadingSlash(input = "") {
|
||||
return hasLeadingSlash(input) ? input : "/" + input;
|
||||
}
|
||||
function cleanDoubleSlashes(input = "") {
|
||||
return input.split("://").map((string_) => string_.replace(/\/{2,}/g, "/")).join("://");
|
||||
}
|
||||
function withBase(input, base) {
|
||||
if (isEmptyURL(base) || hasProtocol(input)) {
|
||||
return input;
|
||||
}
|
||||
const _base = withoutTrailingSlash(base);
|
||||
if (input.startsWith(_base)) {
|
||||
return input;
|
||||
}
|
||||
return joinURL(_base, input);
|
||||
}
|
||||
function withoutBase(input, base) {
|
||||
if (isEmptyURL(base)) {
|
||||
return input;
|
||||
}
|
||||
const _base = withoutTrailingSlash(base);
|
||||
if (!input.startsWith(_base)) {
|
||||
return input;
|
||||
}
|
||||
const trimmed = input.slice(_base.length);
|
||||
return trimmed[0] === "/" ? trimmed : "/" + trimmed;
|
||||
}
|
||||
function withQuery(input, query) {
|
||||
const parsed = parseURL(input);
|
||||
const mergedQuery = { ...parseQuery(parsed.search), ...query };
|
||||
parsed.search = stringifyQuery(mergedQuery);
|
||||
return stringifyParsedURL(parsed);
|
||||
}
|
||||
function getQuery(input) {
|
||||
return parseQuery(parseURL(input).search);
|
||||
}
|
||||
function isEmptyURL(url) {
|
||||
return !url || url === "/";
|
||||
}
|
||||
function isNonEmptyURL(url) {
|
||||
return url && url !== "/";
|
||||
}
|
||||
function joinURL(base, ...input) {
|
||||
let url = base || "";
|
||||
for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
|
||||
url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
function withHttp(input) {
|
||||
return withProtocol(input, "http://");
|
||||
}
|
||||
function withHttps(input) {
|
||||
return withProtocol(input, "https://");
|
||||
}
|
||||
function withoutProtocol(input) {
|
||||
return withProtocol(input, "");
|
||||
}
|
||||
function withProtocol(input, protocol) {
|
||||
const match = input.match(PROTOCOL_REGEX);
|
||||
if (!match) {
|
||||
return protocol + input;
|
||||
}
|
||||
return protocol + input.slice(match[0].length);
|
||||
}
|
||||
function createURL(input) {
|
||||
return new $URL(input);
|
||||
}
|
||||
function normalizeURL(input) {
|
||||
return createURL(input).toString();
|
||||
}
|
||||
function resolveURL(base, ...input) {
|
||||
const url = createURL(base);
|
||||
for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
|
||||
url.append(createURL(index));
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
function isSamePath(p1, p2) {
|
||||
return decode(withoutTrailingSlash(p1)) === decode(withoutTrailingSlash(p2));
|
||||
}
|
||||
function isEqual(a, b, options = {}) {
|
||||
if (!options.trailingSlash) {
|
||||
a = withTrailingSlash(a);
|
||||
b = withTrailingSlash(b);
|
||||
}
|
||||
if (!options.leadingSlash) {
|
||||
a = withLeadingSlash(a);
|
||||
b = withLeadingSlash(b);
|
||||
}
|
||||
if (!options.encoding) {
|
||||
a = decode(a);
|
||||
b = decode(b);
|
||||
}
|
||||
return a === b;
|
||||
}
|
||||
|
||||
function parseURL(input = "", defaultProto) {
|
||||
if (!hasProtocol(input, true)) {
|
||||
return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
|
||||
}
|
||||
const [protocol = "", auth, hostAndPath = ""] = (input.replace(/\\/g, "/").match(/([^/:]+:)?\/\/([^/@]+@)?(.*)/) || []).splice(1);
|
||||
const [host = "", path = ""] = (hostAndPath.match(/([^#/?]*)(.*)?/) || []).splice(1);
|
||||
const { pathname, search, hash } = parsePath(path.replace(/\/(?=[A-Za-z]:)/, ""));
|
||||
return {
|
||||
protocol,
|
||||
auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
|
||||
host,
|
||||
pathname,
|
||||
search,
|
||||
hash
|
||||
};
|
||||
}
|
||||
function parsePath(input = "") {
|
||||
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
|
||||
return {
|
||||
pathname,
|
||||
search,
|
||||
hash
|
||||
};
|
||||
}
|
||||
function parseAuth(input = "") {
|
||||
const [username, password] = input.split(":");
|
||||
return {
|
||||
username: decode(username),
|
||||
password: decode(password)
|
||||
};
|
||||
}
|
||||
function parseHost(input = "") {
|
||||
const [hostname, port] = (input.match(/([^/]*)(:0-9+)?/) || []).splice(1);
|
||||
return {
|
||||
hostname: decode(hostname),
|
||||
port
|
||||
};
|
||||
}
|
||||
function stringifyParsedURL(parsed) {
|
||||
const fullpath = parsed.pathname + (parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "") + parsed.hash;
|
||||
if (!parsed.protocol) {
|
||||
return fullpath;
|
||||
}
|
||||
return parsed.protocol + "//" + (parsed.auth ? parsed.auth + "@" : "") + parsed.host + fullpath;
|
||||
}
|
||||
|
||||
exports.$URL = $URL;
|
||||
exports.cleanDoubleSlashes = cleanDoubleSlashes;
|
||||
exports.createURL = createURL;
|
||||
exports.decode = decode;
|
||||
exports.decodePath = decodePath;
|
||||
exports.decodeQueryValue = decodeQueryValue;
|
||||
exports.encode = encode;
|
||||
exports.encodeHash = encodeHash;
|
||||
exports.encodeHost = encodeHost;
|
||||
exports.encodeParam = encodeParam;
|
||||
exports.encodePath = encodePath;
|
||||
exports.encodeQueryItem = encodeQueryItem;
|
||||
exports.encodeQueryKey = encodeQueryKey;
|
||||
exports.encodeQueryValue = encodeQueryValue;
|
||||
exports.getQuery = getQuery;
|
||||
exports.hasLeadingSlash = hasLeadingSlash;
|
||||
exports.hasProtocol = hasProtocol;
|
||||
exports.hasTrailingSlash = hasTrailingSlash;
|
||||
exports.isEmptyURL = isEmptyURL;
|
||||
exports.isEqual = isEqual;
|
||||
exports.isNonEmptyURL = isNonEmptyURL;
|
||||
exports.isRelative = isRelative;
|
||||
exports.isSamePath = isSamePath;
|
||||
exports.joinURL = joinURL;
|
||||
exports.normalizeURL = normalizeURL;
|
||||
exports.parseAuth = parseAuth;
|
||||
exports.parseHost = parseHost;
|
||||
exports.parsePath = parsePath;
|
||||
exports.parseQuery = parseQuery;
|
||||
exports.parseURL = parseURL;
|
||||
exports.resolveURL = resolveURL;
|
||||
exports.stringifyParsedURL = stringifyParsedURL;
|
||||
exports.stringifyQuery = stringifyQuery;
|
||||
exports.withBase = withBase;
|
||||
exports.withHttp = withHttp;
|
||||
exports.withHttps = withHttps;
|
||||
exports.withLeadingSlash = withLeadingSlash;
|
||||
exports.withProtocol = withProtocol;
|
||||
exports.withQuery = withQuery;
|
||||
exports.withTrailingSlash = withTrailingSlash;
|
||||
exports.withoutBase = withoutBase;
|
||||
exports.withoutLeadingSlash = withoutLeadingSlash;
|
||||
exports.withoutProtocol = withoutProtocol;
|
||||
exports.withoutTrailingSlash = withoutTrailingSlash;
|
||||
155
node_modules/ufo/dist/index.d.ts
generated
vendored
Normal file
155
node_modules/ufo/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* Encode characters that need to be encoded on the path, search and hash
|
||||
* sections of the URL.
|
||||
*
|
||||
* @internal
|
||||
* @param text - string to encode
|
||||
* @returns encoded string
|
||||
*/
|
||||
declare function encode(text: string | number): string;
|
||||
/**
|
||||
* Encode characters that need to be encoded on the hash section of the URL.
|
||||
*
|
||||
* @param text - string to encode
|
||||
* @returns encoded string
|
||||
*/
|
||||
declare function encodeHash(text: string): string;
|
||||
/**
|
||||
* Encode characters that need to be encoded query values on the query
|
||||
* section of the URL.
|
||||
*
|
||||
* @param text - string to encode
|
||||
* @returns encoded string
|
||||
*/
|
||||
declare function encodeQueryValue(text: string | number): string;
|
||||
/**
|
||||
* Like `encodeQueryValue` but also encodes the `=` character.
|
||||
*
|
||||
* @param text - string to encode
|
||||
*/
|
||||
declare function encodeQueryKey(text: string | number): string;
|
||||
/**
|
||||
* Encode characters that need to be encoded on the path section of the URL.
|
||||
*
|
||||
* @param text - string to encode
|
||||
* @returns encoded string
|
||||
*/
|
||||
declare function encodePath(text: string | number): string;
|
||||
/**
|
||||
* Encode characters that need to be encoded on the path section of the URL as a
|
||||
* param. This function encodes everything {@link encodePath} does plus the
|
||||
* slash (`/`) character.
|
||||
*
|
||||
* @param text - string to encode
|
||||
* @returns encoded string
|
||||
*/
|
||||
declare function encodeParam(text: string | number): string;
|
||||
/**
|
||||
* Decode text using `decodeURIComponent`. Returns the original text if it
|
||||
* fails.
|
||||
*
|
||||
* @param text - string to decode
|
||||
* @returns decoded string
|
||||
*/
|
||||
declare function decode(text?: string | number): string;
|
||||
/**
|
||||
* Decode path section of URL (consitant with encodePath for slash encoding).
|
||||
*
|
||||
* @param text - string to decode
|
||||
* @returns decoded string
|
||||
*/
|
||||
declare function decodePath(text: string): string;
|
||||
/**
|
||||
* Decode query value (consitant with encodeQueryValue for plus encoding).
|
||||
*
|
||||
* @param text - string to decode
|
||||
* @returns decoded string
|
||||
*/
|
||||
declare function decodeQueryValue(text: string): string;
|
||||
declare function encodeHost(name?: string): string;
|
||||
|
||||
interface ParsedURL {
|
||||
protocol?: string;
|
||||
host?: string;
|
||||
auth?: string;
|
||||
pathname: string;
|
||||
hash: string;
|
||||
search: string;
|
||||
}
|
||||
interface ParsedAuth {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
interface ParsedHost {
|
||||
hostname: string;
|
||||
port: string;
|
||||
}
|
||||
declare function parseURL(input?: string, defaultProto?: string): ParsedURL;
|
||||
declare function parsePath(input?: string): ParsedURL;
|
||||
declare function parseAuth(input?: string): ParsedAuth;
|
||||
declare function parseHost(input?: string): ParsedHost;
|
||||
declare function stringifyParsedURL(parsed: ParsedURL): string;
|
||||
|
||||
type QueryValue = string | undefined | null;
|
||||
type QueryObject = Record<string, QueryValue | QueryValue[]>;
|
||||
declare function parseQuery(parametersString?: string): QueryObject;
|
||||
declare function encodeQueryItem(key: string, value: QueryValue | QueryValue[]): string;
|
||||
declare function stringifyQuery(query: QueryObject): string;
|
||||
|
||||
declare class $URL implements URL {
|
||||
protocol: string;
|
||||
host: string;
|
||||
auth: string;
|
||||
pathname: string;
|
||||
query: QueryObject;
|
||||
hash: string;
|
||||
constructor(input?: string);
|
||||
get hostname(): string;
|
||||
get port(): string;
|
||||
get username(): string;
|
||||
get password(): string;
|
||||
get hasProtocol(): number;
|
||||
get isAbsolute(): number | boolean;
|
||||
get search(): string;
|
||||
get searchParams(): URLSearchParams;
|
||||
get origin(): string;
|
||||
get fullpath(): string;
|
||||
get encodedAuth(): string;
|
||||
get href(): string;
|
||||
append(url: $URL): void;
|
||||
toJSON(): string;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
declare function isRelative(inputString: string): boolean;
|
||||
declare function hasProtocol(inputString: string, acceptProtocolRelative?: boolean): boolean;
|
||||
declare function hasTrailingSlash(input?: string, queryParameters?: boolean): boolean;
|
||||
declare function withoutTrailingSlash(input?: string, queryParameters?: boolean): string;
|
||||
declare function withTrailingSlash(input?: string, queryParameters?: boolean): string;
|
||||
declare function hasLeadingSlash(input?: string): boolean;
|
||||
declare function withoutLeadingSlash(input?: string): string;
|
||||
declare function withLeadingSlash(input?: string): string;
|
||||
declare function cleanDoubleSlashes(input?: string): string;
|
||||
declare function withBase(input: string, base: string): string;
|
||||
declare function withoutBase(input: string, base: string): string;
|
||||
declare function withQuery(input: string, query: QueryObject): string;
|
||||
declare function getQuery(input: string): QueryObject;
|
||||
declare function isEmptyURL(url: string): boolean;
|
||||
declare function isNonEmptyURL(url: string): boolean;
|
||||
declare function joinURL(base: string, ...input: string[]): string;
|
||||
declare function withHttp(input: string): string;
|
||||
declare function withHttps(input: string): string;
|
||||
declare function withoutProtocol(input: string): string;
|
||||
declare function withProtocol(input: string, protocol: string): string;
|
||||
declare function createURL(input: string): $URL;
|
||||
declare function normalizeURL(input: string): string;
|
||||
declare function resolveURL(base: string, ...input: string[]): string;
|
||||
declare function isSamePath(p1: string, p2: string): boolean;
|
||||
interface CompareURLOptions {
|
||||
trailingSlash?: boolean;
|
||||
leadingSlash?: boolean;
|
||||
encoding?: boolean;
|
||||
}
|
||||
declare function isEqual(a: string, b: string, options?: CompareURLOptions): boolean;
|
||||
|
||||
export { $URL, ParsedAuth, ParsedHost, ParsedURL, QueryObject, QueryValue, cleanDoubleSlashes, createURL, decode, decodePath, decodeQueryValue, encode, encodeHash, encodeHost, encodeParam, encodePath, encodeQueryItem, encodeQueryKey, encodeQueryValue, getQuery, hasLeadingSlash, hasProtocol, hasTrailingSlash, isEmptyURL, isEqual, isNonEmptyURL, isRelative, isSamePath, joinURL, normalizeURL, parseAuth, parseHost, parsePath, parseQuery, parseURL, resolveURL, stringifyParsedURL, stringifyQuery, withBase, withHttp, withHttps, withLeadingSlash, withProtocol, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutProtocol, withoutTrailingSlash };
|
||||
454
node_modules/ufo/dist/index.mjs
generated
vendored
Normal file
454
node_modules/ufo/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,454 @@
|
||||
const n = /[^\0-\x7E]/;
|
||||
const t = /[\x2E\u3002\uFF0E\uFF61]/g;
|
||||
const o = { overflow: "Overflow Error", "not-basic": "Illegal Input", "invalid-input": "Invalid Input" };
|
||||
const e = Math.floor;
|
||||
const r = String.fromCharCode;
|
||||
function s(n2) {
|
||||
throw new RangeError(o[n2]);
|
||||
}
|
||||
const c = function(n2, t2) {
|
||||
return n2 + 22 + 75 * (n2 < 26) - ((t2 != 0) << 5);
|
||||
};
|
||||
const u = function(n2, t2, o2) {
|
||||
let r2 = 0;
|
||||
for (n2 = o2 ? e(n2 / 700) : n2 >> 1, n2 += e(n2 / t2); n2 > 455; r2 += 36) {
|
||||
n2 = e(n2 / 35);
|
||||
}
|
||||
return e(r2 + 36 * n2 / (n2 + 38));
|
||||
};
|
||||
function toASCII(o2) {
|
||||
return function(n2, o3) {
|
||||
const e2 = n2.split("@");
|
||||
let r2 = "";
|
||||
e2.length > 1 && (r2 = e2[0] + "@", n2 = e2[1]);
|
||||
const s2 = function(n3, t2) {
|
||||
const o4 = [];
|
||||
let e3 = n3.length;
|
||||
for (; e3--; ) {
|
||||
o4[e3] = t2(n3[e3]);
|
||||
}
|
||||
return o4;
|
||||
}((n2 = n2.replace(t, ".")).split("."), o3).join(".");
|
||||
return r2 + s2;
|
||||
}(o2, function(t2) {
|
||||
return n.test(t2) ? "xn--" + function(n2) {
|
||||
const t3 = [];
|
||||
const o3 = (n2 = function(n3) {
|
||||
const t4 = [];
|
||||
let o4 = 0;
|
||||
const e2 = n3.length;
|
||||
for (; o4 < e2; ) {
|
||||
const r2 = n3.charCodeAt(o4++);
|
||||
if (r2 >= 55296 && r2 <= 56319 && o4 < e2) {
|
||||
const e3 = n3.charCodeAt(o4++);
|
||||
(64512 & e3) == 56320 ? t4.push(((1023 & r2) << 10) + (1023 & e3) + 65536) : (t4.push(r2), o4--);
|
||||
} else {
|
||||
t4.push(r2);
|
||||
}
|
||||
}
|
||||
return t4;
|
||||
}(n2)).length;
|
||||
let f = 128;
|
||||
let i = 0;
|
||||
let l = 72;
|
||||
for (const o4 of n2) {
|
||||
o4 < 128 && t3.push(r(o4));
|
||||
}
|
||||
const h = t3.length;
|
||||
let p = h;
|
||||
for (h && t3.push("-"); p < o3; ) {
|
||||
let o4 = 2147483647;
|
||||
for (const t4 of n2) {
|
||||
t4 >= f && t4 < o4 && (o4 = t4);
|
||||
}
|
||||
const a = p + 1;
|
||||
o4 - f > e((2147483647 - i) / a) && s("overflow"), i += (o4 - f) * a, f = o4;
|
||||
for (const o5 of n2) {
|
||||
if (o5 < f && ++i > 2147483647 && s("overflow"), o5 == f) {
|
||||
let n3 = i;
|
||||
for (let o6 = 36; ; o6 += 36) {
|
||||
const s2 = o6 <= l ? 1 : o6 >= l + 26 ? 26 : o6 - l;
|
||||
if (n3 < s2) {
|
||||
break;
|
||||
}
|
||||
const u2 = n3 - s2;
|
||||
const f2 = 36 - s2;
|
||||
t3.push(r(c(s2 + u2 % f2, 0))), n3 = e(u2 / f2);
|
||||
}
|
||||
t3.push(r(c(n3, 0))), l = u(i, a, p == h), i = 0, ++p;
|
||||
}
|
||||
}
|
||||
++i, ++f;
|
||||
}
|
||||
return t3.join("");
|
||||
}(t2) : t2;
|
||||
});
|
||||
}
|
||||
|
||||
const HASH_RE = /#/g;
|
||||
const AMPERSAND_RE = /&/g;
|
||||
const SLASH_RE = /\//g;
|
||||
const EQUAL_RE = /=/g;
|
||||
const IM_RE = /\?/g;
|
||||
const PLUS_RE = /\+/g;
|
||||
const ENC_BRACKET_OPEN_RE = /%5b/gi;
|
||||
const ENC_BRACKET_CLOSE_RE = /%5d/gi;
|
||||
const ENC_CARET_RE = /%5e/gi;
|
||||
const ENC_BACKTICK_RE = /%60/gi;
|
||||
const ENC_CURLY_OPEN_RE = /%7b/gi;
|
||||
const ENC_PIPE_RE = /%7c/gi;
|
||||
const ENC_CURLY_CLOSE_RE = /%7d/gi;
|
||||
const ENC_SPACE_RE = /%20/gi;
|
||||
const ENC_SLASH_RE = /%2f/gi;
|
||||
const ENC_ENC_SLASH_RE = /%252f/gi;
|
||||
function encode(text) {
|
||||
return encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
|
||||
}
|
||||
function encodeHash(text) {
|
||||
return encode(text).replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
|
||||
}
|
||||
function encodeQueryValue(text) {
|
||||
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, "^");
|
||||
}
|
||||
function encodeQueryKey(text) {
|
||||
return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
|
||||
}
|
||||
function encodePath(text) {
|
||||
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");
|
||||
}
|
||||
function encodeParam(text) {
|
||||
return encodePath(text).replace(SLASH_RE, "%2F");
|
||||
}
|
||||
function decode(text = "") {
|
||||
try {
|
||||
return decodeURIComponent("" + text);
|
||||
} catch {
|
||||
return "" + text;
|
||||
}
|
||||
}
|
||||
function decodePath(text) {
|
||||
return decode(text.replace(ENC_SLASH_RE, "%252F"));
|
||||
}
|
||||
function decodeQueryValue(text) {
|
||||
return decode(text.replace(PLUS_RE, " "));
|
||||
}
|
||||
function encodeHost(name = "") {
|
||||
return toASCII(name);
|
||||
}
|
||||
|
||||
function parseQuery(parametersString = "") {
|
||||
const object = {};
|
||||
if (parametersString[0] === "?") {
|
||||
parametersString = parametersString.slice(1);
|
||||
}
|
||||
for (const parameter of parametersString.split("&")) {
|
||||
const s = parameter.match(/([^=]+)=?(.*)/) || [];
|
||||
if (s.length < 2) {
|
||||
continue;
|
||||
}
|
||||
const key = decode(s[1]);
|
||||
if (key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = decodeQueryValue(s[2] || "");
|
||||
if (typeof object[key] !== "undefined") {
|
||||
if (Array.isArray(object[key])) {
|
||||
object[key].push(value);
|
||||
} else {
|
||||
object[key] = [object[key], value];
|
||||
}
|
||||
} else {
|
||||
object[key] = value;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
function encodeQueryItem(key, value) {
|
||||
if (typeof value === "number" || typeof value === "boolean") {
|
||||
value = String(value);
|
||||
}
|
||||
if (!value) {
|
||||
return encodeQueryKey(key);
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
|
||||
}
|
||||
return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
|
||||
}
|
||||
function stringifyQuery(query) {
|
||||
return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).join("&");
|
||||
}
|
||||
|
||||
class $URL {
|
||||
constructor(input = "") {
|
||||
this.query = {};
|
||||
if (typeof input !== "string") {
|
||||
throw new TypeError(`URL input should be string received ${typeof input} (${input})`);
|
||||
}
|
||||
const parsed = parseURL(input);
|
||||
this.protocol = decode(parsed.protocol);
|
||||
this.host = decode(parsed.host);
|
||||
this.auth = decode(parsed.auth);
|
||||
this.pathname = decodePath(parsed.pathname);
|
||||
this.query = parseQuery(parsed.search);
|
||||
this.hash = decode(parsed.hash);
|
||||
}
|
||||
get hostname() {
|
||||
return parseHost(this.host).hostname;
|
||||
}
|
||||
get port() {
|
||||
return parseHost(this.host).port || "";
|
||||
}
|
||||
get username() {
|
||||
return parseAuth(this.auth).username;
|
||||
}
|
||||
get password() {
|
||||
return parseAuth(this.auth).password || "";
|
||||
}
|
||||
get hasProtocol() {
|
||||
return this.protocol.length;
|
||||
}
|
||||
get isAbsolute() {
|
||||
return this.hasProtocol || this.pathname[0] === "/";
|
||||
}
|
||||
get search() {
|
||||
const q = stringifyQuery(this.query);
|
||||
return q.length > 0 ? "?" + q : "";
|
||||
}
|
||||
get searchParams() {
|
||||
const p = new URLSearchParams();
|
||||
for (const name in this.query) {
|
||||
const value = this.query[name];
|
||||
if (Array.isArray(value)) {
|
||||
for (const v of value) {
|
||||
p.append(name, v);
|
||||
}
|
||||
} else {
|
||||
p.append(name, value || "");
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
get origin() {
|
||||
return (this.protocol ? this.protocol + "//" : "") + encodeHost(this.host);
|
||||
}
|
||||
get fullpath() {
|
||||
return encodePath(this.pathname) + this.search + encodeHash(this.hash);
|
||||
}
|
||||
get encodedAuth() {
|
||||
if (!this.auth) {
|
||||
return "";
|
||||
}
|
||||
const { username, password } = parseAuth(this.auth);
|
||||
return encodeURIComponent(username) + (password ? ":" + encodeURIComponent(password) : "");
|
||||
}
|
||||
get href() {
|
||||
const auth = this.encodedAuth;
|
||||
const originWithAuth = (this.protocol ? this.protocol + "//" : "") + (auth ? auth + "@" : "") + encodeHost(this.host);
|
||||
return this.hasProtocol && this.isAbsolute ? originWithAuth + this.fullpath : this.fullpath;
|
||||
}
|
||||
append(url) {
|
||||
if (url.hasProtocol) {
|
||||
throw new Error("Cannot append a URL with protocol");
|
||||
}
|
||||
Object.assign(this.query, url.query);
|
||||
if (url.pathname) {
|
||||
this.pathname = withTrailingSlash(this.pathname) + withoutLeadingSlash(url.pathname);
|
||||
}
|
||||
if (url.hash) {
|
||||
this.hash = url.hash;
|
||||
}
|
||||
}
|
||||
toJSON() {
|
||||
return this.href;
|
||||
}
|
||||
toString() {
|
||||
return this.href;
|
||||
}
|
||||
}
|
||||
|
||||
function isRelative(inputString) {
|
||||
return ["./", "../"].some((string_) => inputString.startsWith(string_));
|
||||
}
|
||||
const PROTOCOL_REGEX = /^\w{2,}:(\/\/)?/;
|
||||
const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
|
||||
function hasProtocol(inputString, acceptProtocolRelative = false) {
|
||||
return PROTOCOL_REGEX.test(inputString) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputString);
|
||||
}
|
||||
const TRAILING_SLASH_RE = /\/$|\/\?/;
|
||||
function hasTrailingSlash(input = "", queryParameters = false) {
|
||||
if (!queryParameters) {
|
||||
return input.endsWith("/");
|
||||
}
|
||||
return TRAILING_SLASH_RE.test(input);
|
||||
}
|
||||
function withoutTrailingSlash(input = "", queryParameters = false) {
|
||||
if (!queryParameters) {
|
||||
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
|
||||
}
|
||||
if (!hasTrailingSlash(input, true)) {
|
||||
return input || "/";
|
||||
}
|
||||
const [s0, ...s] = input.split("?");
|
||||
return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function withTrailingSlash(input = "", queryParameters = false) {
|
||||
if (!queryParameters) {
|
||||
return input.endsWith("/") ? input : input + "/";
|
||||
}
|
||||
if (hasTrailingSlash(input, true)) {
|
||||
return input || "/";
|
||||
}
|
||||
const [s0, ...s] = input.split("?");
|
||||
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function hasLeadingSlash(input = "") {
|
||||
return input.startsWith("/");
|
||||
}
|
||||
function withoutLeadingSlash(input = "") {
|
||||
return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
|
||||
}
|
||||
function withLeadingSlash(input = "") {
|
||||
return hasLeadingSlash(input) ? input : "/" + input;
|
||||
}
|
||||
function cleanDoubleSlashes(input = "") {
|
||||
return input.split("://").map((string_) => string_.replace(/\/{2,}/g, "/")).join("://");
|
||||
}
|
||||
function withBase(input, base) {
|
||||
if (isEmptyURL(base) || hasProtocol(input)) {
|
||||
return input;
|
||||
}
|
||||
const _base = withoutTrailingSlash(base);
|
||||
if (input.startsWith(_base)) {
|
||||
return input;
|
||||
}
|
||||
return joinURL(_base, input);
|
||||
}
|
||||
function withoutBase(input, base) {
|
||||
if (isEmptyURL(base)) {
|
||||
return input;
|
||||
}
|
||||
const _base = withoutTrailingSlash(base);
|
||||
if (!input.startsWith(_base)) {
|
||||
return input;
|
||||
}
|
||||
const trimmed = input.slice(_base.length);
|
||||
return trimmed[0] === "/" ? trimmed : "/" + trimmed;
|
||||
}
|
||||
function withQuery(input, query) {
|
||||
const parsed = parseURL(input);
|
||||
const mergedQuery = { ...parseQuery(parsed.search), ...query };
|
||||
parsed.search = stringifyQuery(mergedQuery);
|
||||
return stringifyParsedURL(parsed);
|
||||
}
|
||||
function getQuery(input) {
|
||||
return parseQuery(parseURL(input).search);
|
||||
}
|
||||
function isEmptyURL(url) {
|
||||
return !url || url === "/";
|
||||
}
|
||||
function isNonEmptyURL(url) {
|
||||
return url && url !== "/";
|
||||
}
|
||||
function joinURL(base, ...input) {
|
||||
let url = base || "";
|
||||
for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
|
||||
url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
function withHttp(input) {
|
||||
return withProtocol(input, "http://");
|
||||
}
|
||||
function withHttps(input) {
|
||||
return withProtocol(input, "https://");
|
||||
}
|
||||
function withoutProtocol(input) {
|
||||
return withProtocol(input, "");
|
||||
}
|
||||
function withProtocol(input, protocol) {
|
||||
const match = input.match(PROTOCOL_REGEX);
|
||||
if (!match) {
|
||||
return protocol + input;
|
||||
}
|
||||
return protocol + input.slice(match[0].length);
|
||||
}
|
||||
function createURL(input) {
|
||||
return new $URL(input);
|
||||
}
|
||||
function normalizeURL(input) {
|
||||
return createURL(input).toString();
|
||||
}
|
||||
function resolveURL(base, ...input) {
|
||||
const url = createURL(base);
|
||||
for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
|
||||
url.append(createURL(index));
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
function isSamePath(p1, p2) {
|
||||
return decode(withoutTrailingSlash(p1)) === decode(withoutTrailingSlash(p2));
|
||||
}
|
||||
function isEqual(a, b, options = {}) {
|
||||
if (!options.trailingSlash) {
|
||||
a = withTrailingSlash(a);
|
||||
b = withTrailingSlash(b);
|
||||
}
|
||||
if (!options.leadingSlash) {
|
||||
a = withLeadingSlash(a);
|
||||
b = withLeadingSlash(b);
|
||||
}
|
||||
if (!options.encoding) {
|
||||
a = decode(a);
|
||||
b = decode(b);
|
||||
}
|
||||
return a === b;
|
||||
}
|
||||
|
||||
function parseURL(input = "", defaultProto) {
|
||||
if (!hasProtocol(input, true)) {
|
||||
return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
|
||||
}
|
||||
const [protocol = "", auth, hostAndPath = ""] = (input.replace(/\\/g, "/").match(/([^/:]+:)?\/\/([^/@]+@)?(.*)/) || []).splice(1);
|
||||
const [host = "", path = ""] = (hostAndPath.match(/([^#/?]*)(.*)?/) || []).splice(1);
|
||||
const { pathname, search, hash } = parsePath(path.replace(/\/(?=[A-Za-z]:)/, ""));
|
||||
return {
|
||||
protocol,
|
||||
auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
|
||||
host,
|
||||
pathname,
|
||||
search,
|
||||
hash
|
||||
};
|
||||
}
|
||||
function parsePath(input = "") {
|
||||
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
|
||||
return {
|
||||
pathname,
|
||||
search,
|
||||
hash
|
||||
};
|
||||
}
|
||||
function parseAuth(input = "") {
|
||||
const [username, password] = input.split(":");
|
||||
return {
|
||||
username: decode(username),
|
||||
password: decode(password)
|
||||
};
|
||||
}
|
||||
function parseHost(input = "") {
|
||||
const [hostname, port] = (input.match(/([^/]*)(:0-9+)?/) || []).splice(1);
|
||||
return {
|
||||
hostname: decode(hostname),
|
||||
port
|
||||
};
|
||||
}
|
||||
function stringifyParsedURL(parsed) {
|
||||
const fullpath = parsed.pathname + (parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "") + parsed.hash;
|
||||
if (!parsed.protocol) {
|
||||
return fullpath;
|
||||
}
|
||||
return parsed.protocol + "//" + (parsed.auth ? parsed.auth + "@" : "") + parsed.host + fullpath;
|
||||
}
|
||||
|
||||
export { $URL, cleanDoubleSlashes, createURL, decode, decodePath, decodeQueryValue, encode, encodeHash, encodeHost, encodeParam, encodePath, encodeQueryItem, encodeQueryKey, encodeQueryValue, getQuery, hasLeadingSlash, hasProtocol, hasTrailingSlash, isEmptyURL, isEqual, isNonEmptyURL, isRelative, isSamePath, joinURL, normalizeURL, parseAuth, parseHost, parsePath, parseQuery, parseURL, resolveURL, stringifyParsedURL, stringifyQuery, withBase, withHttp, withHttps, withLeadingSlash, withProtocol, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutProtocol, withoutTrailingSlash };
|
||||
39
node_modules/ufo/package.json
generated
vendored
Normal file
39
node_modules/ufo/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "ufo",
|
||||
"version": "1.0.1",
|
||||
"description": "URL utils for humans",
|
||||
"repository": "unjs/ufo",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./dist/index.cjs",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"./*": "./*"
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.9",
|
||||
"@vitest/coverage-c8": "^0.25.3",
|
||||
"eslint": "^8.28.0",
|
||||
"eslint-config-unjs": "^0.0.2",
|
||||
"standard-version": "^9.5.0",
|
||||
"typescript": "^4.9.3",
|
||||
"unbuild": "^1.0.1",
|
||||
"vitest": "^0.25.3"
|
||||
},
|
||||
"packageManager": "pnpm@7.17.1",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest",
|
||||
"lint": "eslint --ext .ts .",
|
||||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
|
||||
"test": "pnpm lint && vitest run"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user