initial commit
This commit is contained in:
21
node_modules/ohmyfetch/LICENSE
generated
vendored
Normal file
21
node_modules/ohmyfetch/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 - UnJS
|
||||
|
||||
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.
|
||||
285
node_modules/ohmyfetch/README.md
generated
vendored
Normal file
285
node_modules/ohmyfetch/README.md
generated
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
|
||||
[![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]
|
||||
|
||||

|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
Install:
|
||||
|
||||
```bash
|
||||
# npm
|
||||
npm i ohmyfetch
|
||||
|
||||
# yarn
|
||||
yarn add ohmyfetch
|
||||
```
|
||||
|
||||
Import:
|
||||
|
||||
```js
|
||||
// ESM / Typescript
|
||||
import { $fetch } from 'ohmyfetch'
|
||||
|
||||
// CommonJS
|
||||
const { $fetch } = require('ohmyfetch')
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Spoiler</summary>
|
||||
<img src="https://media.giphy.com/media/Dn1QRA9hqMcoMz9zVZ/giphy.gif">
|
||||
</details>
|
||||
|
||||
## ✔️ Works with Node.js
|
||||
|
||||
We use [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports) to detect Node.js
|
||||
and automatically use [unjs/node-fetch-native](https://github.com/unjs/node-fetch-native). If `globalThis.fetch` is available, will be used instead. To leverage Node.js 17.5.0 experimental native fetch API use [`--experimental-fetch` flag](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch).
|
||||
|
||||
### `undici` support
|
||||
|
||||
In order to use experimental fetch implementation from [nodejs/undici](https://github.com/nodejs/undici), You can import from `ohmyfetch/undici`.
|
||||
|
||||
```js
|
||||
import { $fetch } from 'ohmyfetch/undici'
|
||||
```
|
||||
|
||||
On Node.js versions older than `16.5`, node-fetch will be used as the fallback.
|
||||
|
||||
### `keepAlive` support
|
||||
|
||||
By setting the `FETCH_KEEP_ALIVE` environment variable to `true`, an http/https agent will be registered that keeps sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a TCP connection.
|
||||
|
||||
**Note:** This option can potentially introduce memory leaks. Please check [node-fetch/node-fetch#1325](https://github.com/node-fetch/node-fetch/pull/1325).
|
||||
|
||||
## ✔️ Parsing Response
|
||||
|
||||
`$fetch` will smartly parse JSON and native values using [destr](https://github.com/unjs/destr), falling back to text if it fails to parse.
|
||||
|
||||
```js
|
||||
const { users } = await $fetch('/api/users')
|
||||
```
|
||||
|
||||
For binary content types, `$fetch` will instead return a `Blob` object.
|
||||
|
||||
You can optionally provide a different parser than destr, or specify `blob`, `arrayBuffer` or `text` to force parsing the body with the respective `FetchResponse` method.
|
||||
|
||||
```js
|
||||
// Use JSON.parse
|
||||
await $fetch('/movie?lang=en', { parseResponse: JSON.parse })
|
||||
|
||||
// Return text as is
|
||||
await $fetch('/movie?lang=en', { parseResponse: txt => txt })
|
||||
|
||||
// Get the blob version of the response
|
||||
await $fetch('/api/generate-image', { responseType: 'blob' })
|
||||
```
|
||||
|
||||
## ✔️ JSON Body
|
||||
|
||||
`$fetch` automatically stringifies request body (if an object is passed) and adds JSON `Content-Type` and `Accept` headers (for `put`, `patch` and `post` requests).
|
||||
|
||||
```js
|
||||
const { users } = await $fetch('/api/users', { method: 'POST', body: { some: 'json' } })
|
||||
```
|
||||
|
||||
## ✔️ Handling Errors
|
||||
|
||||
`$fetch` Automatically throw errors when `response.ok` is `false` with a friendly error message and compact stack (hiding internals).
|
||||
|
||||
Parsed error body is available with `error.data`. You may also use `FetchError` type.
|
||||
|
||||
```ts
|
||||
await $fetch('http://google.com/404')
|
||||
// FetchError: 404 Not Found (http://google.com/404)
|
||||
// at async main (/project/playground.ts:4:3)
|
||||
```
|
||||
|
||||
In order to bypass errors as response you can use `error.data`:
|
||||
|
||||
```ts
|
||||
await $fetch(...).catch((error) => error.data)
|
||||
```
|
||||
|
||||
## ✔️ Auto Retry
|
||||
|
||||
`$fetch` Automatically retries the request if an error happens. Default is `1` (except for `POST`, `PUT` and `PATCH` methods that is `0`)
|
||||
|
||||
```ts
|
||||
await $fetch('http://google.com/404', {
|
||||
retry: 3
|
||||
})
|
||||
```
|
||||
|
||||
## ✔️ Type Friendly
|
||||
|
||||
Response can be type assisted:
|
||||
|
||||
```ts
|
||||
const article = await $fetch<Article>(`/api/article/${id}`)
|
||||
// Auto complete working with article.id
|
||||
```
|
||||
|
||||
## ✔️ Adding `baseURL`
|
||||
|
||||
By using `baseURL` option, `$fetch` prepends it with respecting to trailing/leading slashes and query search params for baseURL using [ufo](https://github.com/unjs/ufo):
|
||||
|
||||
```js
|
||||
await $fetch('/config', { baseURL })
|
||||
```
|
||||
|
||||
## ✔️ Adding Query Search Params
|
||||
|
||||
By using `query` option (or `params` as alias), `$fetch` adds query search params to URL by preserving query in request itself using [ufo](https://github.com/unjs/ufo):
|
||||
|
||||
```js
|
||||
await $fetch('/movie?lang=en', { query: { id: 123 } })
|
||||
```
|
||||
|
||||
## ✔️ Interceptors
|
||||
|
||||
It is possible to provide async interceptors to hook into lifecycle events of `$fetch` call.
|
||||
|
||||
You might want to use `$fetch.create` to set set shared interceptors.
|
||||
|
||||
### `onRequest({ request, options })`
|
||||
|
||||
`onRequest` is called as soon as `$fetch` is being called, allowing to modify options or just do simple logging.
|
||||
|
||||
```js
|
||||
await $fetch('/api', {
|
||||
async onRequest({ request, options }) {
|
||||
// Log request
|
||||
console.log('[fetch request]', request, options)
|
||||
|
||||
// Add `?t=1640125211170` to query search params
|
||||
options.query = options.query || {}
|
||||
options.query.t = new Date()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### `onRequestError({ request, options, error })`
|
||||
|
||||
`onRequestError` will be called when fetch request fails.
|
||||
|
||||
```js
|
||||
await $fetch('/api', {
|
||||
async onRequestError({ request, options, error }) {
|
||||
// Log error
|
||||
console.log('[fetch request error]', request, error)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### `onResponse({ request, options, response })`
|
||||
|
||||
`onResponse` will be called after `fetch` call and parsing body.
|
||||
|
||||
```js
|
||||
await $fetch('/api', {
|
||||
async onResponse({ request, response, options }) {
|
||||
// Log response
|
||||
console.log('[fetch response]', request, response.status, response.body)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### `onResponseError({ request, options, response })`
|
||||
|
||||
`onResponseError` is same as `onResponse` but will be called when fetch happens but `response.ok` is not `true`.
|
||||
|
||||
```js
|
||||
await $fetch('/api', {
|
||||
async onResponseError({ request, response, options }) {
|
||||
// Log error
|
||||
console.log('[fetch response error]', request, response.status, response.body)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## ✔️ Create fetch with default options
|
||||
|
||||
This utility is useful if you need to use common options across serveral fetch calls.
|
||||
|
||||
**Note:** Defaults will be cloned at one level and inherrited. Be careful about nested options like `headers`.
|
||||
|
||||
```js
|
||||
const apiFetch = $fetch.create({ baseURL: '/api' })
|
||||
|
||||
apiFetch('/test') // Same as $fetch('/test', { baseURL: '/api' })
|
||||
```
|
||||
|
||||
## 💡 Adding headers
|
||||
|
||||
By using `headers` option, `$fetch` adds extra headers in addition to the request default headers:
|
||||
|
||||
```js
|
||||
await $fetch('/movies', {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 🍣 Access to Raw Response
|
||||
|
||||
If you need to access raw response (for headers, etc), can use `$fetch.raw`:
|
||||
|
||||
```js
|
||||
const response = await $fetch.raw('/sushi')
|
||||
|
||||
// response.data
|
||||
// response.headers
|
||||
// ...
|
||||
```
|
||||
|
||||
## 📦 Bundler Notes
|
||||
|
||||
- All targets are exported with Module and CommonJS format and named exports
|
||||
- No export is transpiled for sake of modern syntax
|
||||
- You probably need to transpile `ohmyfetch`, `destr` and `ufo` packages with babel for ES5 support
|
||||
- You need to polyfill `fetch` global for supporting legacy browsers like using [unfetch](https://github.com/developit/unfetch)
|
||||
|
||||
## ❓ FAQ
|
||||
|
||||
**Why export is called `$fetch` instead of `fetch`?**
|
||||
|
||||
Using the same name of `fetch` can be confusing since API is different but still it is a fetch so using closest possible alternative. You can however, import `{ fetch }` from `ohmyfetch` which is auto polyfilled for Node.js and using native otherwise.
|
||||
|
||||
**Why not having default export?**
|
||||
|
||||
Default exports are always risky to be mixed with CommonJS exports.
|
||||
|
||||
This also guarantees we can introduce more utils without breaking the package and also encourage using `$fetch` name.
|
||||
|
||||
**Why not transpiled?**
|
||||
|
||||
By keep transpiling libraries we push web backward with legacy code which is unneeded for most of the users.
|
||||
|
||||
If you need to support legacy users, you can optionally transpile the library in your build pipeline.
|
||||
|
||||
## License
|
||||
|
||||
MIT. Made with 💖
|
||||
|
||||
<!-- Badges -->
|
||||
[npm-version-src]: https://img.shields.io/npm/v/ohmyfetch?style=flat-square
|
||||
[npm-version-href]: https://npmjs.com/package/ohmyfetch
|
||||
|
||||
[npm-downloads-src]: https://img.shields.io/npm/dm/ohmyfetch?style=flat-square
|
||||
[npm-downloads-href]: https://npmjs.com/package/ohmyfetch
|
||||
|
||||
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ohmyfetch/ci/main?style=flat-square
|
||||
[github-actions-href]: https://github.com/unjs/ohmyfetch/actions?query=workflow%3Aci
|
||||
|
||||
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ohmyfetch/main?style=flat-square
|
||||
[codecov-href]: https://codecov.io/gh/unjs/ohmyfetch
|
||||
|
||||
[bundle-src]: https://img.shields.io/bundlephobia/minzip/ohmyfetch?style=flat-square
|
||||
[bundle-href]: https://bundlephobia.com/result?p=ohmyfetch
|
||||
6
node_modules/ohmyfetch/cjs/index.cjs
generated
vendored
Normal file
6
node_modules/ohmyfetch/cjs/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
const getExport = name => import('../dist/index.mjs').then(r => r[name])
|
||||
const createCaller = name => (input, init) => getExport(name).then(fn => fn(input, init))
|
||||
|
||||
exports.fetch = createCaller('fetch')
|
||||
exports.$fetch = createCaller('$fetch')
|
||||
exports.$fetch.raw = (input, init) => getExport('$fetch').then($fetch => $fetch.raw(input, init))
|
||||
6
node_modules/ohmyfetch/cjs/node.cjs
generated
vendored
Normal file
6
node_modules/ohmyfetch/cjs/node.cjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
const getExport = name => import('../dist/node.mjs').then(r => r[name])
|
||||
const createCaller = name => (input, init) => getExport(name).then(fn => fn(input, init))
|
||||
|
||||
exports.fetch = createCaller('fetch')
|
||||
exports.$fetch = createCaller('$fetch')
|
||||
exports.$fetch.raw = (input, init) => getExport('$fetch').then($fetch => $fetch.raw(input, init))
|
||||
6
node_modules/ohmyfetch/cjs/undici.cjs
generated
vendored
Normal file
6
node_modules/ohmyfetch/cjs/undici.cjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
const getExport = name => import('../dist/undici.mjs').then(r => r[name])
|
||||
const createCaller = name => (input, init) => getExport(name).then(fn => fn(input, init))
|
||||
|
||||
exports.fetch = createCaller('fetch')
|
||||
exports.$fetch = createCaller('$fetch')
|
||||
exports.$fetch.raw = (input, init) => getExport('$fetch').then($fetch => $fetch.raw(input, init))
|
||||
72
node_modules/ohmyfetch/dist/error-65d5de49.d.ts
generated
vendored
Normal file
72
node_modules/ohmyfetch/dist/error-65d5de49.d.ts
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
declare type Fetch = typeof globalThis.fetch;
|
||||
declare type RequestInfo = globalThis.RequestInfo;
|
||||
declare type RequestInit = globalThis.RequestInit;
|
||||
declare type Response = globalThis.Response;
|
||||
|
||||
interface ResponseMap {
|
||||
blob: Blob;
|
||||
text: string;
|
||||
arrayBuffer: ArrayBuffer;
|
||||
stream: ReadableStream<Uint8Array>;
|
||||
}
|
||||
declare type ResponseType = keyof ResponseMap | 'json';
|
||||
declare type MappedType<R extends ResponseType, JsonType = any> = R extends keyof ResponseMap ? ResponseMap[R] : JsonType;
|
||||
|
||||
interface CreateFetchOptions {
|
||||
defaults?: FetchOptions;
|
||||
fetch: Fetch;
|
||||
Headers: typeof Headers;
|
||||
}
|
||||
declare type FetchRequest = RequestInfo;
|
||||
interface FetchResponse<T> extends Response {
|
||||
_data?: T;
|
||||
}
|
||||
interface SearchParams {
|
||||
[key: string]: any;
|
||||
}
|
||||
interface FetchContext<T = any, R extends ResponseType = ResponseType> {
|
||||
request: FetchRequest;
|
||||
options: FetchOptions<R>;
|
||||
response?: FetchResponse<T>;
|
||||
error?: Error;
|
||||
}
|
||||
interface FetchOptions<R extends ResponseType = ResponseType> extends Omit<RequestInit, 'body'> {
|
||||
baseURL?: string;
|
||||
body?: RequestInit['body'] | Record<string, any>;
|
||||
params?: SearchParams;
|
||||
query?: SearchParams;
|
||||
parseResponse?: (responseText: string) => any;
|
||||
responseType?: R;
|
||||
response?: boolean;
|
||||
retry?: number | false;
|
||||
onRequest?(ctx: FetchContext): Promise<void> | void;
|
||||
onRequestError?(ctx: FetchContext & {
|
||||
error: Error;
|
||||
}): Promise<void> | void;
|
||||
onResponse?(ctx: FetchContext & {
|
||||
response: FetchResponse<R>;
|
||||
}): Promise<void> | void;
|
||||
onResponseError?(ctx: FetchContext & {
|
||||
response: FetchResponse<R>;
|
||||
}): Promise<void> | void;
|
||||
}
|
||||
interface $Fetch {
|
||||
<T = any, R extends ResponseType = 'json'>(request: FetchRequest, opts?: FetchOptions<R>): Promise<MappedType<R, T>>;
|
||||
raw<T = any, R extends ResponseType = 'json'>(request: FetchRequest, opts?: FetchOptions<R>): Promise<FetchResponse<MappedType<R, T>>>;
|
||||
create(defaults: FetchOptions): $Fetch;
|
||||
}
|
||||
declare function createFetch(globalOptions: CreateFetchOptions): $Fetch;
|
||||
|
||||
declare class FetchError<T = any> extends Error {
|
||||
name: 'FetchError';
|
||||
request?: FetchRequest;
|
||||
response?: FetchResponse<T>;
|
||||
data?: T;
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
statusCode?: number;
|
||||
statusMessage?: string;
|
||||
}
|
||||
declare function createFetchError<T = any>(request: FetchRequest, error?: Error, response?: FetchResponse<T>): FetchError<T>;
|
||||
|
||||
export { $Fetch as $, CreateFetchOptions as C, FetchRequest as F, SearchParams as S, FetchResponse as a, FetchContext as b, FetchOptions as c, createFetch as d, FetchError as e, createFetchError as f };
|
||||
11
node_modules/ohmyfetch/dist/index.d.ts
generated
vendored
Normal file
11
node_modules/ohmyfetch/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { $ as $Fetch } from './error-65d5de49.js';
|
||||
export { $ as $Fetch, C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParams, d as createFetch, f as createFetchError } from './error-65d5de49.js';
|
||||
|
||||
declare const fetch: typeof globalThis.fetch;
|
||||
declare const Headers: {
|
||||
new (init?: HeadersInit | undefined): Headers;
|
||||
prototype: Headers;
|
||||
};
|
||||
declare const $fetch: $Fetch;
|
||||
|
||||
export { $fetch, Headers, fetch };
|
||||
25
node_modules/ohmyfetch/dist/index.mjs
generated
vendored
Normal file
25
node_modules/ohmyfetch/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { c as createFetch } from './shared/ohmyfetch.d1948a88.mjs';
|
||||
export { F as FetchError, c as createFetch, a as createFetchError } from './shared/ohmyfetch.d1948a88.mjs';
|
||||
import 'destr';
|
||||
import 'ufo';
|
||||
|
||||
const _globalThis = function() {
|
||||
if (typeof globalThis !== "undefined") {
|
||||
return globalThis;
|
||||
}
|
||||
if (typeof self !== "undefined") {
|
||||
return self;
|
||||
}
|
||||
if (typeof window !== "undefined") {
|
||||
return window;
|
||||
}
|
||||
if (typeof global !== "undefined") {
|
||||
return global;
|
||||
}
|
||||
throw new Error("unable to locate global object");
|
||||
}();
|
||||
const fetch = _globalThis.fetch || (() => Promise.reject(new Error("[ohmyfetch] global.fetch is not supported!")));
|
||||
const Headers = _globalThis.Headers;
|
||||
const $fetch = createFetch({ fetch, Headers });
|
||||
|
||||
export { $fetch, Headers, fetch };
|
||||
12
node_modules/ohmyfetch/dist/node.d.ts
generated
vendored
Normal file
12
node_modules/ohmyfetch/dist/node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { $ as $Fetch } from './error-65d5de49.js';
|
||||
export { $ as $Fetch, C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParams, d as createFetch, f as createFetchError } from './error-65d5de49.js';
|
||||
|
||||
declare function createNodeFetch(): (input: RequestInfo, init?: RequestInit) => any;
|
||||
declare const fetch: typeof globalThis.fetch;
|
||||
declare const Headers: {
|
||||
new (init?: HeadersInit | undefined): Headers;
|
||||
prototype: Headers;
|
||||
};
|
||||
declare const $fetch: $Fetch;
|
||||
|
||||
export { $fetch, Headers, createNodeFetch, fetch };
|
||||
30
node_modules/ohmyfetch/dist/node.mjs
generated
vendored
Normal file
30
node_modules/ohmyfetch/dist/node.mjs
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import nodeFetch, { Headers as Headers$1 } from 'node-fetch-native';
|
||||
import { c as createFetch } from './shared/ohmyfetch.d1948a88.mjs';
|
||||
export { F as FetchError, c as createFetch, a as createFetchError } from './shared/ohmyfetch.d1948a88.mjs';
|
||||
import 'destr';
|
||||
import 'ufo';
|
||||
|
||||
function createNodeFetch() {
|
||||
const useKeepAlive = JSON.parse(process.env.FETCH_KEEP_ALIVE || "false");
|
||||
if (!useKeepAlive) {
|
||||
return nodeFetch;
|
||||
}
|
||||
const agentOpts = { keepAlive: true };
|
||||
const httpAgent = new http.Agent(agentOpts);
|
||||
const httpsAgent = new https.Agent(agentOpts);
|
||||
const nodeFetchOptions = {
|
||||
agent(parsedURL) {
|
||||
return parsedURL.protocol === "http:" ? httpAgent : httpsAgent;
|
||||
}
|
||||
};
|
||||
return function nodeFetchWithKeepAlive(input, init) {
|
||||
return nodeFetch(input, { ...nodeFetchOptions, ...init });
|
||||
};
|
||||
}
|
||||
const fetch = globalThis.fetch || createNodeFetch();
|
||||
const Headers = globalThis.Headers || Headers$1;
|
||||
const $fetch = createFetch({ fetch, Headers });
|
||||
|
||||
export { $fetch, Headers, createNodeFetch, fetch };
|
||||
186
node_modules/ohmyfetch/dist/shared/ohmyfetch.d1948a88.mjs
generated
vendored
Normal file
186
node_modules/ohmyfetch/dist/shared/ohmyfetch.d1948a88.mjs
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
import destr from 'destr';
|
||||
import { withBase, withQuery } from 'ufo';
|
||||
|
||||
class FetchError extends Error {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.name = "FetchError";
|
||||
}
|
||||
}
|
||||
function createFetchError(request, error, response) {
|
||||
let message = "";
|
||||
if (request && response) {
|
||||
message = `${response.status} ${response.statusText} (${request.toString()})`;
|
||||
}
|
||||
if (error) {
|
||||
message = `${error.message} (${message})`;
|
||||
}
|
||||
const fetchError = new FetchError(message);
|
||||
Object.defineProperty(fetchError, "request", { get() {
|
||||
return request;
|
||||
} });
|
||||
Object.defineProperty(fetchError, "response", { get() {
|
||||
return response;
|
||||
} });
|
||||
Object.defineProperty(fetchError, "data", { get() {
|
||||
return response && response._data;
|
||||
} });
|
||||
Object.defineProperty(fetchError, "status", { get() {
|
||||
return response && response.status;
|
||||
} });
|
||||
Object.defineProperty(fetchError, "statusText", { get() {
|
||||
return response && response.statusText;
|
||||
} });
|
||||
Object.defineProperty(fetchError, "statusCode", { get() {
|
||||
return response && response.status;
|
||||
} });
|
||||
Object.defineProperty(fetchError, "statusMessage", { get() {
|
||||
return response && response.statusText;
|
||||
} });
|
||||
return fetchError;
|
||||
}
|
||||
|
||||
const payloadMethods = new Set(Object.freeze(["PATCH", "POST", "PUT", "DELETE"]));
|
||||
function isPayloadMethod(method = "GET") {
|
||||
return payloadMethods.has(method.toUpperCase());
|
||||
}
|
||||
function isJSONSerializable(val) {
|
||||
if (val === void 0) {
|
||||
return false;
|
||||
}
|
||||
const t = typeof val;
|
||||
if (t === "string" || t === "number" || t === "boolean" || t === null) {
|
||||
return true;
|
||||
}
|
||||
if (t !== "object") {
|
||||
return false;
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
return true;
|
||||
}
|
||||
return val.constructor && val.constructor.name === "Object" || typeof val.toJSON === "function";
|
||||
}
|
||||
const textTypes = /* @__PURE__ */ new Set([
|
||||
"image/svg",
|
||||
"application/xml",
|
||||
"application/xhtml",
|
||||
"application/html"
|
||||
]);
|
||||
const JSON_RE = /^application\/(?:[\w!#$%&*`\-.^~]*\+)?json(;.+)?$/i;
|
||||
function detectResponseType(_contentType = "") {
|
||||
if (!_contentType) {
|
||||
return "json";
|
||||
}
|
||||
const contentType = _contentType.split(";").shift();
|
||||
if (JSON_RE.test(contentType)) {
|
||||
return "json";
|
||||
}
|
||||
if (textTypes.has(contentType) || contentType.startsWith("text/")) {
|
||||
return "text";
|
||||
}
|
||||
return "blob";
|
||||
}
|
||||
|
||||
const retryStatusCodes = /* @__PURE__ */ new Set([
|
||||
408,
|
||||
409,
|
||||
425,
|
||||
429,
|
||||
500,
|
||||
502,
|
||||
503,
|
||||
504
|
||||
]);
|
||||
function createFetch(globalOptions) {
|
||||
const { fetch, Headers } = globalOptions;
|
||||
function onError(ctx) {
|
||||
const isAbort = ctx.error && ctx.error.name === "AbortError" || false;
|
||||
if (ctx.options.retry !== false && !isAbort) {
|
||||
const retries = typeof ctx.options.retry === "number" ? ctx.options.retry : isPayloadMethod(ctx.options.method) ? 0 : 1;
|
||||
const responseCode = ctx.response && ctx.response.status || 500;
|
||||
if (retries > 0 && retryStatusCodes.has(responseCode)) {
|
||||
return $fetchRaw(ctx.request, {
|
||||
...ctx.options,
|
||||
retry: retries - 1
|
||||
});
|
||||
}
|
||||
}
|
||||
const err = createFetchError(ctx.request, ctx.error, ctx.response);
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(err, $fetchRaw);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
const $fetchRaw = async function $fetchRaw2(_request, _opts = {}) {
|
||||
const ctx = {
|
||||
request: _request,
|
||||
options: { ...globalOptions.defaults, ..._opts },
|
||||
response: void 0,
|
||||
error: void 0
|
||||
};
|
||||
if (ctx.options.onRequest) {
|
||||
await ctx.options.onRequest(ctx);
|
||||
}
|
||||
if (typeof ctx.request === "string") {
|
||||
if (ctx.options.baseURL) {
|
||||
ctx.request = withBase(ctx.request, ctx.options.baseURL);
|
||||
}
|
||||
if (ctx.options.query || ctx.options.params) {
|
||||
ctx.request = withQuery(ctx.request, { ...ctx.options.params, ...ctx.options.query });
|
||||
}
|
||||
if (ctx.options.body && isPayloadMethod(ctx.options.method)) {
|
||||
if (isJSONSerializable(ctx.options.body)) {
|
||||
ctx.options.body = typeof ctx.options.body === "string" ? ctx.options.body : JSON.stringify(ctx.options.body);
|
||||
ctx.options.headers = new Headers(ctx.options.headers);
|
||||
if (!ctx.options.headers.has("content-type")) {
|
||||
ctx.options.headers.set("content-type", "application/json");
|
||||
}
|
||||
if (!ctx.options.headers.has("accept")) {
|
||||
ctx.options.headers.set("accept", "application/json");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.response = await fetch(ctx.request, ctx.options).catch(async (error) => {
|
||||
ctx.error = error;
|
||||
if (ctx.options.onRequestError) {
|
||||
await ctx.options.onRequestError(ctx);
|
||||
}
|
||||
return onError(ctx);
|
||||
});
|
||||
const responseType = (ctx.options.parseResponse ? "json" : ctx.options.responseType) || detectResponseType(ctx.response.headers.get("content-type") || "");
|
||||
if (responseType === "json") {
|
||||
const data = await ctx.response.text();
|
||||
const parseFn = ctx.options.parseResponse || destr;
|
||||
ctx.response._data = parseFn(data);
|
||||
} else if (responseType === "stream") {
|
||||
ctx.response._data = ctx.response.body;
|
||||
} else {
|
||||
ctx.response._data = await ctx.response[responseType]();
|
||||
}
|
||||
if (ctx.options.onResponse) {
|
||||
await ctx.options.onResponse(ctx);
|
||||
}
|
||||
if (ctx.response.status >= 400 && ctx.response.status < 600) {
|
||||
if (ctx.options.onResponseError) {
|
||||
await ctx.options.onResponseError(ctx);
|
||||
}
|
||||
return onError(ctx);
|
||||
}
|
||||
return ctx.response;
|
||||
};
|
||||
const $fetch = function $fetch2(request, opts) {
|
||||
return $fetchRaw(request, opts).then((r) => r._data);
|
||||
};
|
||||
$fetch.raw = $fetchRaw;
|
||||
$fetch.create = (defaultOptions = {}) => createFetch({
|
||||
...globalOptions,
|
||||
defaults: {
|
||||
...globalOptions.defaults,
|
||||
...defaultOptions
|
||||
}
|
||||
});
|
||||
return $fetch;
|
||||
}
|
||||
|
||||
export { FetchError as F, createFetchError as a, createFetch as c };
|
||||
9
node_modules/ohmyfetch/dist/undici.d.ts
generated
vendored
Normal file
9
node_modules/ohmyfetch/dist/undici.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { $ as $Fetch } from './error-65d5de49.js';
|
||||
export { $ as $Fetch, C as CreateFetchOptions, b as FetchContext, e as FetchError, c as FetchOptions, F as FetchRequest, a as FetchResponse, S as SearchParams, d as createFetch, f as createFetchError } from './error-65d5de49.js';
|
||||
export { Headers } from './node.js';
|
||||
|
||||
declare const fetch: typeof globalThis.fetch;
|
||||
|
||||
declare const $fetch: $Fetch;
|
||||
|
||||
export { $fetch, fetch };
|
||||
15
node_modules/ohmyfetch/dist/undici.mjs
generated
vendored
Normal file
15
node_modules/ohmyfetch/dist/undici.mjs
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { fetch as fetch$1 } from 'undici';
|
||||
import { createNodeFetch, Headers } from './node.mjs';
|
||||
export { Headers } from './node.mjs';
|
||||
import { c as createFetch } from './shared/ohmyfetch.d1948a88.mjs';
|
||||
export { F as FetchError, c as createFetch, a as createFetchError } from './shared/ohmyfetch.d1948a88.mjs';
|
||||
import 'http';
|
||||
import 'https';
|
||||
import 'node-fetch-native';
|
||||
import 'destr';
|
||||
import 'ufo';
|
||||
|
||||
const fetch = globalThis.fetch || fetch$1 || createNodeFetch();
|
||||
const $fetch = createFetch({ fetch, Headers });
|
||||
|
||||
export { $fetch, fetch };
|
||||
1
node_modules/ohmyfetch/node.d.ts
generated
vendored
Normal file
1
node_modules/ohmyfetch/node.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './dist/node'
|
||||
21
node_modules/ohmyfetch/node_modules/node-fetch-native/LICENSE
generated
vendored
Normal file
21
node_modules/ohmyfetch/node_modules/node-fetch-native/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 - UnJS
|
||||
|
||||
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.
|
||||
147
node_modules/ohmyfetch/node_modules/node-fetch-native/README.md
generated
vendored
Normal file
147
node_modules/ohmyfetch/node_modules/node-fetch-native/README.md
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
# node-fetch-native
|
||||
|
||||
[![][npm-version-src]][npm-version-href]
|
||||
[![][github-actions-src]][github-actions-href]
|
||||
[![][packagephobia-src]][packagephobia-href]
|
||||
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
||||
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
||||
|
||||
A redistribution of [node-fetch v3](https://github.com/node-fetch/node-fetch) for better backward and forward compatibility.
|
||||
|
||||
**Why this package?**
|
||||
|
||||
- We can no longer `require('node-fetch')` with latest version. This stopped popular libraries from upgrading and dependency conflicts between `node-fetch@2` and `node-fetch@3`.
|
||||
- With upcoming versions of Node.js, native `fetch` is being supported. We are prepared for native fetch support using this package yet keep supporting older Node versions.
|
||||
|
||||
**Features:**
|
||||
|
||||
✅ Prefer to **native globals** when available (See Node.js [experimental fetch](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch))
|
||||
|
||||
✅ Compact build and less install size with **zero dependencies** [![][packagephobia-s-src]][packagephobia-s-href] <sup>vs</sup> [![][packagephobia-s-alt-src]][packagephobia-s-alt-href]
|
||||
|
||||
✅ Support both **CommonJS** (`require`) and **ESM** (`import`) usage
|
||||
|
||||
✅ Use native version if imported without `node` condition using [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports) with **zero bundle overhead**
|
||||
|
||||
✅ Polyfill support for Node.js
|
||||
|
||||
## Usage
|
||||
|
||||
Install `node-fetch-native` dependency:
|
||||
|
||||
```sh
|
||||
# npm
|
||||
npm i node-fetch-native
|
||||
|
||||
# yarn
|
||||
yarn add node-fetch-native
|
||||
|
||||
# pnpm
|
||||
pnpm i node-fetch-native
|
||||
```
|
||||
|
||||
You can now either import or require the dependency:
|
||||
|
||||
```js
|
||||
// ESM
|
||||
import fetch from 'node-fetch-native'
|
||||
|
||||
// CommonJS
|
||||
const fetch = require('node-fetch-native')
|
||||
```
|
||||
|
||||
More named exports:
|
||||
|
||||
```js
|
||||
// ESM
|
||||
import { fetch, Blob, FormData, Headers, Request, Response, AbortController } from 'node-fetch-native'
|
||||
|
||||
// CommonJS
|
||||
const { fetch, Blob, FormData, Headers, Request, Response, AbortController } = require('node-fetch-native')
|
||||
```
|
||||
|
||||
## Polyfill support
|
||||
|
||||
Using the polyfill method, we can once ensure global fetch is available in the environment and all files. Natives are always preferred.
|
||||
|
||||
**Note:** I don't recommand this if you are authoring a library! Please prefer explicit methods.
|
||||
|
||||
```js
|
||||
// ESM
|
||||
import 'node-fetch-native/polyfill'
|
||||
|
||||
// CJS
|
||||
require('node-fetch-native/polyfill')
|
||||
|
||||
// You can now use fetch() without any import!
|
||||
```
|
||||
|
||||
## Alias to `node-fetch`
|
||||
|
||||
Using this method, you can ensure all project dependencies and usages of `node-fetch` can benefit from improved `node-fetch-native` and won't conflict between `node-fetch@2` and `node-fetch@3`.
|
||||
|
||||
### npm
|
||||
|
||||
Using npm [overrides](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides):
|
||||
|
||||
```jsonc
|
||||
// package.json
|
||||
{
|
||||
"overrides": {
|
||||
"node-fetch": "npm:node-fetch-native@latest"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### yarn
|
||||
|
||||
Using yarn [selective dependency resolutions](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/):
|
||||
|
||||
```jsonc
|
||||
// package.json
|
||||
{
|
||||
"resolutions": {
|
||||
"node-fetch": "npm:node-fetch-native@latest"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### pnpm
|
||||
|
||||
Using [pnpm.overrides](https://pnpm.io/package_json#pnpmoverrides):
|
||||
|
||||
```jsonc
|
||||
// package.json
|
||||
{
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"node-fetch": "npm:node-fetch-native@latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Made with 💛
|
||||
|
||||
[node-fetch is published under the MIT license](https://github.com/node-fetch/node-fetch/blob/main/LICENSE.md)
|
||||
|
||||
<!-- Badges -->
|
||||
[npm-version-src]: https://flat.badgen.net/npm/v/node-fetch-native
|
||||
[npm-version-href]: https://npmjs.com/package/node-fetch-native
|
||||
|
||||
[npm-downloads-src]: https://flat.badgen.net/npm/dm/node-fetch-native
|
||||
[npm-downloads-href]: https://npmjs.com/package/node-fetch-native
|
||||
|
||||
[github-actions-src]: https://flat.badgen.net/github/checks/unjs/node-fetch-native
|
||||
[github-actions-href]: https://github.com/unjs/node-fetch-native/actions?query=workflow%3Aci
|
||||
|
||||
[packagephobia-src]: https://flat.badgen.net/packagephobia/install/node-fetch-native
|
||||
[packagephobia-href]: https://packagephobia.com/result?p=node-fetch-native
|
||||
|
||||
[packagephobia-s-src]: https://flat.badgen.net/packagephobia/install/node-fetch-native?label=node-fetch-native&scale=.9
|
||||
[packagephobia-s-href]: https://packagephobia.com/result?p=node-fetch-native
|
||||
|
||||
[packagephobia-s-alt-src]: https://flat.badgen.net/packagephobia/install/node-fetch?label=node-fetch&scale=.9
|
||||
[packagephobia-s-alt-href]: https://packagephobia.com/result?p=node-fetch
|
||||
445
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs
generated
vendored
Normal file
445
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs
generated
vendored
Normal file
@@ -0,0 +1,445 @@
|
||||
'use strict';
|
||||
|
||||
require('node:fs');
|
||||
require('node:path');
|
||||
const abortController = require('../shared/node-fetch-native.bd0cd7ae.cjs');
|
||||
require('node:http');
|
||||
require('node:https');
|
||||
require('node:zlib');
|
||||
require('node:stream');
|
||||
require('node:buffer');
|
||||
require('node:util');
|
||||
require('node:url');
|
||||
require('node:net');
|
||||
|
||||
let s = 0;
|
||||
const S = {
|
||||
START_BOUNDARY: s++,
|
||||
HEADER_FIELD_START: s++,
|
||||
HEADER_FIELD: s++,
|
||||
HEADER_VALUE_START: s++,
|
||||
HEADER_VALUE: s++,
|
||||
HEADER_VALUE_ALMOST_DONE: s++,
|
||||
HEADERS_ALMOST_DONE: s++,
|
||||
PART_DATA_START: s++,
|
||||
PART_DATA: s++,
|
||||
END: s++
|
||||
};
|
||||
|
||||
let f = 1;
|
||||
const F = {
|
||||
PART_BOUNDARY: f,
|
||||
LAST_BOUNDARY: f *= 2
|
||||
};
|
||||
|
||||
const LF = 10;
|
||||
const CR = 13;
|
||||
const SPACE = 32;
|
||||
const HYPHEN = 45;
|
||||
const COLON = 58;
|
||||
const A = 97;
|
||||
const Z = 122;
|
||||
|
||||
const lower = c => c | 0x20;
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
class MultipartParser {
|
||||
/**
|
||||
* @param {string} boundary
|
||||
*/
|
||||
constructor(boundary) {
|
||||
this.index = 0;
|
||||
this.flags = 0;
|
||||
|
||||
this.onHeaderEnd = noop;
|
||||
this.onHeaderField = noop;
|
||||
this.onHeadersEnd = noop;
|
||||
this.onHeaderValue = noop;
|
||||
this.onPartBegin = noop;
|
||||
this.onPartData = noop;
|
||||
this.onPartEnd = noop;
|
||||
|
||||
this.boundaryChars = {};
|
||||
|
||||
boundary = '\r\n--' + boundary;
|
||||
const ui8a = new Uint8Array(boundary.length);
|
||||
for (let i = 0; i < boundary.length; i++) {
|
||||
ui8a[i] = boundary.charCodeAt(i);
|
||||
this.boundaryChars[ui8a[i]] = true;
|
||||
}
|
||||
|
||||
this.boundary = ui8a;
|
||||
this.lookbehind = new Uint8Array(this.boundary.length + 8);
|
||||
this.state = S.START_BOUNDARY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} data
|
||||
*/
|
||||
write(data) {
|
||||
let i = 0;
|
||||
const length_ = data.length;
|
||||
let previousIndex = this.index;
|
||||
let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
|
||||
const boundaryLength = this.boundary.length;
|
||||
const boundaryEnd = boundaryLength - 1;
|
||||
const bufferLength = data.length;
|
||||
let c;
|
||||
let cl;
|
||||
|
||||
const mark = name => {
|
||||
this[name + 'Mark'] = i;
|
||||
};
|
||||
|
||||
const clear = name => {
|
||||
delete this[name + 'Mark'];
|
||||
};
|
||||
|
||||
const callback = (callbackSymbol, start, end, ui8a) => {
|
||||
if (start === undefined || start !== end) {
|
||||
this[callbackSymbol](ui8a && ui8a.subarray(start, end));
|
||||
}
|
||||
};
|
||||
|
||||
const dataCallback = (name, clear) => {
|
||||
const markSymbol = name + 'Mark';
|
||||
if (!(markSymbol in this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (clear) {
|
||||
callback(name, this[markSymbol], i, data);
|
||||
delete this[markSymbol];
|
||||
} else {
|
||||
callback(name, this[markSymbol], data.length, data);
|
||||
this[markSymbol] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
for (i = 0; i < length_; i++) {
|
||||
c = data[i];
|
||||
|
||||
switch (state) {
|
||||
case S.START_BOUNDARY:
|
||||
if (index === boundary.length - 2) {
|
||||
if (c === HYPHEN) {
|
||||
flags |= F.LAST_BOUNDARY;
|
||||
} else if (c !== CR) {
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
break;
|
||||
} else if (index - 1 === boundary.length - 2) {
|
||||
if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
|
||||
state = S.END;
|
||||
flags = 0;
|
||||
} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
|
||||
index = 0;
|
||||
callback('onPartBegin');
|
||||
state = S.HEADER_FIELD_START;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (c !== boundary[index + 2]) {
|
||||
index = -2;
|
||||
}
|
||||
|
||||
if (c === boundary[index + 2]) {
|
||||
index++;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.HEADER_FIELD_START:
|
||||
state = S.HEADER_FIELD;
|
||||
mark('onHeaderField');
|
||||
index = 0;
|
||||
// falls through
|
||||
case S.HEADER_FIELD:
|
||||
if (c === CR) {
|
||||
clear('onHeaderField');
|
||||
state = S.HEADERS_ALMOST_DONE;
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
if (c === HYPHEN) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c === COLON) {
|
||||
if (index === 1) {
|
||||
// empty header field
|
||||
return;
|
||||
}
|
||||
|
||||
dataCallback('onHeaderField', true);
|
||||
state = S.HEADER_VALUE_START;
|
||||
break;
|
||||
}
|
||||
|
||||
cl = lower(c);
|
||||
if (cl < A || cl > Z) {
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.HEADER_VALUE_START:
|
||||
if (c === SPACE) {
|
||||
break;
|
||||
}
|
||||
|
||||
mark('onHeaderValue');
|
||||
state = S.HEADER_VALUE;
|
||||
// falls through
|
||||
case S.HEADER_VALUE:
|
||||
if (c === CR) {
|
||||
dataCallback('onHeaderValue', true);
|
||||
callback('onHeaderEnd');
|
||||
state = S.HEADER_VALUE_ALMOST_DONE;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.HEADER_VALUE_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
return;
|
||||
}
|
||||
|
||||
state = S.HEADER_FIELD_START;
|
||||
break;
|
||||
case S.HEADERS_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback('onHeadersEnd');
|
||||
state = S.PART_DATA_START;
|
||||
break;
|
||||
case S.PART_DATA_START:
|
||||
state = S.PART_DATA;
|
||||
mark('onPartData');
|
||||
// falls through
|
||||
case S.PART_DATA:
|
||||
previousIndex = index;
|
||||
|
||||
if (index === 0) {
|
||||
// boyer-moore derrived algorithm to safely skip non-boundary data
|
||||
i += boundaryEnd;
|
||||
while (i < bufferLength && !(data[i] in boundaryChars)) {
|
||||
i += boundaryLength;
|
||||
}
|
||||
|
||||
i -= boundaryEnd;
|
||||
c = data[i];
|
||||
}
|
||||
|
||||
if (index < boundary.length) {
|
||||
if (boundary[index] === c) {
|
||||
if (index === 0) {
|
||||
dataCallback('onPartData', true);
|
||||
}
|
||||
|
||||
index++;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index === boundary.length) {
|
||||
index++;
|
||||
if (c === CR) {
|
||||
// CR = part boundary
|
||||
flags |= F.PART_BOUNDARY;
|
||||
} else if (c === HYPHEN) {
|
||||
// HYPHEN = end boundary
|
||||
flags |= F.LAST_BOUNDARY;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index - 1 === boundary.length) {
|
||||
if (flags & F.PART_BOUNDARY) {
|
||||
index = 0;
|
||||
if (c === LF) {
|
||||
// unset the PART_BOUNDARY flag
|
||||
flags &= ~F.PART_BOUNDARY;
|
||||
callback('onPartEnd');
|
||||
callback('onPartBegin');
|
||||
state = S.HEADER_FIELD_START;
|
||||
break;
|
||||
}
|
||||
} else if (flags & F.LAST_BOUNDARY) {
|
||||
if (c === HYPHEN) {
|
||||
callback('onPartEnd');
|
||||
state = S.END;
|
||||
flags = 0;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (index > 0) {
|
||||
// when matching a possible boundary, keep a lookbehind reference
|
||||
// in case it turns out to be a false lead
|
||||
lookbehind[index - 1] = c;
|
||||
} else if (previousIndex > 0) {
|
||||
// if our boundary turned out to be rubbish, the captured lookbehind
|
||||
// belongs to partData
|
||||
const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
|
||||
callback('onPartData', 0, previousIndex, _lookbehind);
|
||||
previousIndex = 0;
|
||||
mark('onPartData');
|
||||
|
||||
// reconsider the current character even so it interrupted the sequence
|
||||
// it could be the beginning of a new sequence
|
||||
i--;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.END:
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected state entered: ${state}`);
|
||||
}
|
||||
}
|
||||
|
||||
dataCallback('onHeaderField');
|
||||
dataCallback('onHeaderValue');
|
||||
dataCallback('onPartData');
|
||||
|
||||
// Update properties for the next call
|
||||
this.index = index;
|
||||
this.state = state;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
end() {
|
||||
if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
|
||||
(this.state === S.PART_DATA && this.index === this.boundary.length)) {
|
||||
this.onPartEnd();
|
||||
} else if (this.state !== S.END) {
|
||||
throw new Error('MultipartParser.end(): stream ended unexpectedly');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _fileName(headerValue) {
|
||||
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
||||
const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
|
||||
if (!m) {
|
||||
return;
|
||||
}
|
||||
|
||||
const match = m[2] || m[3] || '';
|
||||
let filename = match.slice(match.lastIndexOf('\\') + 1);
|
||||
filename = filename.replace(/%22/g, '"');
|
||||
filename = filename.replace(/&#(\d{4});/g, (m, code) => {
|
||||
return String.fromCharCode(code);
|
||||
});
|
||||
return filename;
|
||||
}
|
||||
|
||||
async function toFormData(Body, ct) {
|
||||
if (!/multipart/i.test(ct)) {
|
||||
throw new TypeError('Failed to fetch');
|
||||
}
|
||||
|
||||
const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
||||
|
||||
if (!m) {
|
||||
throw new TypeError('no or bad content-type header, no multipart boundary');
|
||||
}
|
||||
|
||||
const parser = new MultipartParser(m[1] || m[2]);
|
||||
|
||||
let headerField;
|
||||
let headerValue;
|
||||
let entryValue;
|
||||
let entryName;
|
||||
let contentType;
|
||||
let filename;
|
||||
const entryChunks = [];
|
||||
const formData = new abortController.FormData();
|
||||
|
||||
const onPartData = ui8a => {
|
||||
entryValue += decoder.decode(ui8a, {stream: true});
|
||||
};
|
||||
|
||||
const appendToFile = ui8a => {
|
||||
entryChunks.push(ui8a);
|
||||
};
|
||||
|
||||
const appendFileToFormData = () => {
|
||||
const file = new abortController.File(entryChunks, filename, {type: contentType});
|
||||
formData.append(entryName, file);
|
||||
};
|
||||
|
||||
const appendEntryToFormData = () => {
|
||||
formData.append(entryName, entryValue);
|
||||
};
|
||||
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
decoder.decode();
|
||||
|
||||
parser.onPartBegin = function () {
|
||||
parser.onPartData = onPartData;
|
||||
parser.onPartEnd = appendEntryToFormData;
|
||||
|
||||
headerField = '';
|
||||
headerValue = '';
|
||||
entryValue = '';
|
||||
entryName = '';
|
||||
contentType = '';
|
||||
filename = null;
|
||||
entryChunks.length = 0;
|
||||
};
|
||||
|
||||
parser.onHeaderField = function (ui8a) {
|
||||
headerField += decoder.decode(ui8a, {stream: true});
|
||||
};
|
||||
|
||||
parser.onHeaderValue = function (ui8a) {
|
||||
headerValue += decoder.decode(ui8a, {stream: true});
|
||||
};
|
||||
|
||||
parser.onHeaderEnd = function () {
|
||||
headerValue += decoder.decode();
|
||||
headerField = headerField.toLowerCase();
|
||||
|
||||
if (headerField === 'content-disposition') {
|
||||
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
||||
const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
|
||||
|
||||
if (m) {
|
||||
entryName = m[2] || m[3] || '';
|
||||
}
|
||||
|
||||
filename = _fileName(headerValue);
|
||||
|
||||
if (filename) {
|
||||
parser.onPartData = appendToFile;
|
||||
parser.onPartEnd = appendFileToFormData;
|
||||
}
|
||||
} else if (headerField === 'content-type') {
|
||||
contentType = headerValue;
|
||||
}
|
||||
|
||||
headerValue = '';
|
||||
headerField = '';
|
||||
};
|
||||
|
||||
for await (const chunk of Body) {
|
||||
parser.write(chunk);
|
||||
}
|
||||
|
||||
parser.end();
|
||||
|
||||
return formData;
|
||||
}
|
||||
|
||||
exports.toFormData = toFormData;
|
||||
443
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs
generated
vendored
Normal file
443
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs
generated
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import { a as FormData, F as File } from '../shared/node-fetch-native.b703cef9.mjs';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:zlib';
|
||||
import 'node:stream';
|
||||
import 'node:buffer';
|
||||
import 'node:util';
|
||||
import 'node:url';
|
||||
import 'node:net';
|
||||
|
||||
let s = 0;
|
||||
const S = {
|
||||
START_BOUNDARY: s++,
|
||||
HEADER_FIELD_START: s++,
|
||||
HEADER_FIELD: s++,
|
||||
HEADER_VALUE_START: s++,
|
||||
HEADER_VALUE: s++,
|
||||
HEADER_VALUE_ALMOST_DONE: s++,
|
||||
HEADERS_ALMOST_DONE: s++,
|
||||
PART_DATA_START: s++,
|
||||
PART_DATA: s++,
|
||||
END: s++
|
||||
};
|
||||
|
||||
let f = 1;
|
||||
const F = {
|
||||
PART_BOUNDARY: f,
|
||||
LAST_BOUNDARY: f *= 2
|
||||
};
|
||||
|
||||
const LF = 10;
|
||||
const CR = 13;
|
||||
const SPACE = 32;
|
||||
const HYPHEN = 45;
|
||||
const COLON = 58;
|
||||
const A = 97;
|
||||
const Z = 122;
|
||||
|
||||
const lower = c => c | 0x20;
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
class MultipartParser {
|
||||
/**
|
||||
* @param {string} boundary
|
||||
*/
|
||||
constructor(boundary) {
|
||||
this.index = 0;
|
||||
this.flags = 0;
|
||||
|
||||
this.onHeaderEnd = noop;
|
||||
this.onHeaderField = noop;
|
||||
this.onHeadersEnd = noop;
|
||||
this.onHeaderValue = noop;
|
||||
this.onPartBegin = noop;
|
||||
this.onPartData = noop;
|
||||
this.onPartEnd = noop;
|
||||
|
||||
this.boundaryChars = {};
|
||||
|
||||
boundary = '\r\n--' + boundary;
|
||||
const ui8a = new Uint8Array(boundary.length);
|
||||
for (let i = 0; i < boundary.length; i++) {
|
||||
ui8a[i] = boundary.charCodeAt(i);
|
||||
this.boundaryChars[ui8a[i]] = true;
|
||||
}
|
||||
|
||||
this.boundary = ui8a;
|
||||
this.lookbehind = new Uint8Array(this.boundary.length + 8);
|
||||
this.state = S.START_BOUNDARY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} data
|
||||
*/
|
||||
write(data) {
|
||||
let i = 0;
|
||||
const length_ = data.length;
|
||||
let previousIndex = this.index;
|
||||
let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
|
||||
const boundaryLength = this.boundary.length;
|
||||
const boundaryEnd = boundaryLength - 1;
|
||||
const bufferLength = data.length;
|
||||
let c;
|
||||
let cl;
|
||||
|
||||
const mark = name => {
|
||||
this[name + 'Mark'] = i;
|
||||
};
|
||||
|
||||
const clear = name => {
|
||||
delete this[name + 'Mark'];
|
||||
};
|
||||
|
||||
const callback = (callbackSymbol, start, end, ui8a) => {
|
||||
if (start === undefined || start !== end) {
|
||||
this[callbackSymbol](ui8a && ui8a.subarray(start, end));
|
||||
}
|
||||
};
|
||||
|
||||
const dataCallback = (name, clear) => {
|
||||
const markSymbol = name + 'Mark';
|
||||
if (!(markSymbol in this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (clear) {
|
||||
callback(name, this[markSymbol], i, data);
|
||||
delete this[markSymbol];
|
||||
} else {
|
||||
callback(name, this[markSymbol], data.length, data);
|
||||
this[markSymbol] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
for (i = 0; i < length_; i++) {
|
||||
c = data[i];
|
||||
|
||||
switch (state) {
|
||||
case S.START_BOUNDARY:
|
||||
if (index === boundary.length - 2) {
|
||||
if (c === HYPHEN) {
|
||||
flags |= F.LAST_BOUNDARY;
|
||||
} else if (c !== CR) {
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
break;
|
||||
} else if (index - 1 === boundary.length - 2) {
|
||||
if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
|
||||
state = S.END;
|
||||
flags = 0;
|
||||
} else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
|
||||
index = 0;
|
||||
callback('onPartBegin');
|
||||
state = S.HEADER_FIELD_START;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (c !== boundary[index + 2]) {
|
||||
index = -2;
|
||||
}
|
||||
|
||||
if (c === boundary[index + 2]) {
|
||||
index++;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.HEADER_FIELD_START:
|
||||
state = S.HEADER_FIELD;
|
||||
mark('onHeaderField');
|
||||
index = 0;
|
||||
// falls through
|
||||
case S.HEADER_FIELD:
|
||||
if (c === CR) {
|
||||
clear('onHeaderField');
|
||||
state = S.HEADERS_ALMOST_DONE;
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
if (c === HYPHEN) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c === COLON) {
|
||||
if (index === 1) {
|
||||
// empty header field
|
||||
return;
|
||||
}
|
||||
|
||||
dataCallback('onHeaderField', true);
|
||||
state = S.HEADER_VALUE_START;
|
||||
break;
|
||||
}
|
||||
|
||||
cl = lower(c);
|
||||
if (cl < A || cl > Z) {
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.HEADER_VALUE_START:
|
||||
if (c === SPACE) {
|
||||
break;
|
||||
}
|
||||
|
||||
mark('onHeaderValue');
|
||||
state = S.HEADER_VALUE;
|
||||
// falls through
|
||||
case S.HEADER_VALUE:
|
||||
if (c === CR) {
|
||||
dataCallback('onHeaderValue', true);
|
||||
callback('onHeaderEnd');
|
||||
state = S.HEADER_VALUE_ALMOST_DONE;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.HEADER_VALUE_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
return;
|
||||
}
|
||||
|
||||
state = S.HEADER_FIELD_START;
|
||||
break;
|
||||
case S.HEADERS_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback('onHeadersEnd');
|
||||
state = S.PART_DATA_START;
|
||||
break;
|
||||
case S.PART_DATA_START:
|
||||
state = S.PART_DATA;
|
||||
mark('onPartData');
|
||||
// falls through
|
||||
case S.PART_DATA:
|
||||
previousIndex = index;
|
||||
|
||||
if (index === 0) {
|
||||
// boyer-moore derrived algorithm to safely skip non-boundary data
|
||||
i += boundaryEnd;
|
||||
while (i < bufferLength && !(data[i] in boundaryChars)) {
|
||||
i += boundaryLength;
|
||||
}
|
||||
|
||||
i -= boundaryEnd;
|
||||
c = data[i];
|
||||
}
|
||||
|
||||
if (index < boundary.length) {
|
||||
if (boundary[index] === c) {
|
||||
if (index === 0) {
|
||||
dataCallback('onPartData', true);
|
||||
}
|
||||
|
||||
index++;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index === boundary.length) {
|
||||
index++;
|
||||
if (c === CR) {
|
||||
// CR = part boundary
|
||||
flags |= F.PART_BOUNDARY;
|
||||
} else if (c === HYPHEN) {
|
||||
// HYPHEN = end boundary
|
||||
flags |= F.LAST_BOUNDARY;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index - 1 === boundary.length) {
|
||||
if (flags & F.PART_BOUNDARY) {
|
||||
index = 0;
|
||||
if (c === LF) {
|
||||
// unset the PART_BOUNDARY flag
|
||||
flags &= ~F.PART_BOUNDARY;
|
||||
callback('onPartEnd');
|
||||
callback('onPartBegin');
|
||||
state = S.HEADER_FIELD_START;
|
||||
break;
|
||||
}
|
||||
} else if (flags & F.LAST_BOUNDARY) {
|
||||
if (c === HYPHEN) {
|
||||
callback('onPartEnd');
|
||||
state = S.END;
|
||||
flags = 0;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (index > 0) {
|
||||
// when matching a possible boundary, keep a lookbehind reference
|
||||
// in case it turns out to be a false lead
|
||||
lookbehind[index - 1] = c;
|
||||
} else if (previousIndex > 0) {
|
||||
// if our boundary turned out to be rubbish, the captured lookbehind
|
||||
// belongs to partData
|
||||
const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
|
||||
callback('onPartData', 0, previousIndex, _lookbehind);
|
||||
previousIndex = 0;
|
||||
mark('onPartData');
|
||||
|
||||
// reconsider the current character even so it interrupted the sequence
|
||||
// it could be the beginning of a new sequence
|
||||
i--;
|
||||
}
|
||||
|
||||
break;
|
||||
case S.END:
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected state entered: ${state}`);
|
||||
}
|
||||
}
|
||||
|
||||
dataCallback('onHeaderField');
|
||||
dataCallback('onHeaderValue');
|
||||
dataCallback('onPartData');
|
||||
|
||||
// Update properties for the next call
|
||||
this.index = index;
|
||||
this.state = state;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
end() {
|
||||
if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
|
||||
(this.state === S.PART_DATA && this.index === this.boundary.length)) {
|
||||
this.onPartEnd();
|
||||
} else if (this.state !== S.END) {
|
||||
throw new Error('MultipartParser.end(): stream ended unexpectedly');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _fileName(headerValue) {
|
||||
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
||||
const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
|
||||
if (!m) {
|
||||
return;
|
||||
}
|
||||
|
||||
const match = m[2] || m[3] || '';
|
||||
let filename = match.slice(match.lastIndexOf('\\') + 1);
|
||||
filename = filename.replace(/%22/g, '"');
|
||||
filename = filename.replace(/&#(\d{4});/g, (m, code) => {
|
||||
return String.fromCharCode(code);
|
||||
});
|
||||
return filename;
|
||||
}
|
||||
|
||||
async function toFormData(Body, ct) {
|
||||
if (!/multipart/i.test(ct)) {
|
||||
throw new TypeError('Failed to fetch');
|
||||
}
|
||||
|
||||
const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
||||
|
||||
if (!m) {
|
||||
throw new TypeError('no or bad content-type header, no multipart boundary');
|
||||
}
|
||||
|
||||
const parser = new MultipartParser(m[1] || m[2]);
|
||||
|
||||
let headerField;
|
||||
let headerValue;
|
||||
let entryValue;
|
||||
let entryName;
|
||||
let contentType;
|
||||
let filename;
|
||||
const entryChunks = [];
|
||||
const formData = new FormData();
|
||||
|
||||
const onPartData = ui8a => {
|
||||
entryValue += decoder.decode(ui8a, {stream: true});
|
||||
};
|
||||
|
||||
const appendToFile = ui8a => {
|
||||
entryChunks.push(ui8a);
|
||||
};
|
||||
|
||||
const appendFileToFormData = () => {
|
||||
const file = new File(entryChunks, filename, {type: contentType});
|
||||
formData.append(entryName, file);
|
||||
};
|
||||
|
||||
const appendEntryToFormData = () => {
|
||||
formData.append(entryName, entryValue);
|
||||
};
|
||||
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
decoder.decode();
|
||||
|
||||
parser.onPartBegin = function () {
|
||||
parser.onPartData = onPartData;
|
||||
parser.onPartEnd = appendEntryToFormData;
|
||||
|
||||
headerField = '';
|
||||
headerValue = '';
|
||||
entryValue = '';
|
||||
entryName = '';
|
||||
contentType = '';
|
||||
filename = null;
|
||||
entryChunks.length = 0;
|
||||
};
|
||||
|
||||
parser.onHeaderField = function (ui8a) {
|
||||
headerField += decoder.decode(ui8a, {stream: true});
|
||||
};
|
||||
|
||||
parser.onHeaderValue = function (ui8a) {
|
||||
headerValue += decoder.decode(ui8a, {stream: true});
|
||||
};
|
||||
|
||||
parser.onHeaderEnd = function () {
|
||||
headerValue += decoder.decode();
|
||||
headerField = headerField.toLowerCase();
|
||||
|
||||
if (headerField === 'content-disposition') {
|
||||
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
||||
const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
|
||||
|
||||
if (m) {
|
||||
entryName = m[2] || m[3] || '';
|
||||
}
|
||||
|
||||
filename = _fileName(headerValue);
|
||||
|
||||
if (filename) {
|
||||
parser.onPartData = appendToFile;
|
||||
parser.onPartEnd = appendFileToFormData;
|
||||
}
|
||||
} else if (headerField === 'content-type') {
|
||||
contentType = headerValue;
|
||||
}
|
||||
|
||||
headerValue = '';
|
||||
headerField = '';
|
||||
};
|
||||
|
||||
for await (const chunk of Body) {
|
||||
parser.write(chunk);
|
||||
}
|
||||
|
||||
parser.end();
|
||||
|
||||
return formData;
|
||||
}
|
||||
|
||||
export { toFormData };
|
||||
138
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/index.cjs
generated
vendored
Normal file
138
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const abortController = require('./shared/node-fetch-native.bd0cd7ae.cjs');
|
||||
const node_fs = require('node:fs');
|
||||
const node_path = require('node:path');
|
||||
require('node:http');
|
||||
require('node:https');
|
||||
require('node:zlib');
|
||||
require('node:stream');
|
||||
require('node:buffer');
|
||||
require('node:util');
|
||||
require('node:url');
|
||||
require('node:net');
|
||||
|
||||
const { stat } = node_fs.promises;
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
*/
|
||||
const blobFromSync = (path, type) => fromBlob(node_fs.statSync(path), path, type);
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
* @returns {Promise<Blob>}
|
||||
*/
|
||||
const blobFrom = (path, type) => stat(path).then(stat => fromBlob(stat, path, type));
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
* @returns {Promise<File>}
|
||||
*/
|
||||
const fileFrom = (path, type) => stat(path).then(stat => fromFile(stat, path, type));
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
*/
|
||||
const fileFromSync = (path, type) => fromFile(node_fs.statSync(path), path, type);
|
||||
|
||||
// @ts-ignore
|
||||
const fromBlob = (stat, path, type = '') => new abortController._Blob([new BlobDataItem({
|
||||
path,
|
||||
size: stat.size,
|
||||
lastModified: stat.mtimeMs,
|
||||
start: 0
|
||||
})], { type });
|
||||
|
||||
// @ts-ignore
|
||||
const fromFile = (stat, path, type = '') => new abortController.File([new BlobDataItem({
|
||||
path,
|
||||
size: stat.size,
|
||||
lastModified: stat.mtimeMs,
|
||||
start: 0
|
||||
})], node_path.basename(path), { type, lastModified: stat.mtimeMs });
|
||||
|
||||
/**
|
||||
* This is a blob backed up by a file on the disk
|
||||
* with minium requirement. Its wrapped around a Blob as a blobPart
|
||||
* so you have no direct access to this.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class BlobDataItem {
|
||||
#path
|
||||
#start
|
||||
|
||||
constructor (options) {
|
||||
this.#path = options.path;
|
||||
this.#start = options.start;
|
||||
this.size = options.size;
|
||||
this.lastModified = options.lastModified;
|
||||
this.originalSize = options.originalSize === undefined
|
||||
? options.size
|
||||
: options.originalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Slicing arguments is first validated and formatted
|
||||
* to not be out of range by Blob.prototype.slice
|
||||
*/
|
||||
slice (start, end) {
|
||||
return new BlobDataItem({
|
||||
path: this.#path,
|
||||
lastModified: this.lastModified,
|
||||
originalSize: this.originalSize,
|
||||
size: end - start,
|
||||
start: this.#start + start
|
||||
})
|
||||
}
|
||||
|
||||
async * stream () {
|
||||
const { mtimeMs, size } = await stat(this.#path);
|
||||
|
||||
if (mtimeMs > this.lastModified || this.originalSize !== size) {
|
||||
throw new abortController.nodeDomexception('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError')
|
||||
}
|
||||
|
||||
yield * node_fs.createReadStream(this.#path, {
|
||||
start: this.#start,
|
||||
end: this.#start + this.size - 1
|
||||
});
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag] () {
|
||||
return 'Blob'
|
||||
}
|
||||
}
|
||||
|
||||
const fetch = globalThis.fetch || abortController.fetch;
|
||||
const Blob = globalThis.Blob || abortController._Blob;
|
||||
const File = globalThis.File || abortController.File;
|
||||
const FormData = globalThis.FormData || abortController.FormData;
|
||||
const Headers = globalThis.Headers || abortController.Headers;
|
||||
const Request = globalThis.Request || abortController.Request;
|
||||
const Response = globalThis.Response || abortController.Response;
|
||||
const AbortController = globalThis.AbortController || abortController.AbortController;
|
||||
|
||||
exports.AbortError = abortController.AbortError;
|
||||
exports.FetchError = abortController.FetchError;
|
||||
exports.isRedirect = abortController.isRedirect;
|
||||
exports.AbortController = AbortController;
|
||||
exports.Blob = Blob;
|
||||
exports.File = File;
|
||||
exports.FormData = FormData;
|
||||
exports.Headers = Headers;
|
||||
exports.Request = Request;
|
||||
exports.Response = Response;
|
||||
exports.blobFrom = blobFrom;
|
||||
exports.blobFromSync = blobFromSync;
|
||||
exports.default = fetch;
|
||||
exports.fetch = fetch;
|
||||
exports.fileFrom = fileFrom;
|
||||
exports.fileFromSync = fileFromSync;
|
||||
120
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/index.mjs
generated
vendored
Normal file
120
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
import { _ as _Blob, F as File$1, n as nodeDomexception, a as FormData$1, f as fetch$1, H as Headers$1, R as Request$1, b as Response$1, A as AbortController$1 } from './shared/node-fetch-native.b703cef9.mjs';
|
||||
export { c as AbortError, d as FetchError, i as isRedirect } from './shared/node-fetch-native.b703cef9.mjs';
|
||||
import { statSync, createReadStream, promises } from 'node:fs';
|
||||
import { basename } from 'node:path';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:zlib';
|
||||
import 'node:stream';
|
||||
import 'node:buffer';
|
||||
import 'node:util';
|
||||
import 'node:url';
|
||||
import 'node:net';
|
||||
|
||||
const { stat } = promises;
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
*/
|
||||
const blobFromSync = (path, type) => fromBlob(statSync(path), path, type);
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
* @returns {Promise<Blob>}
|
||||
*/
|
||||
const blobFrom = (path, type) => stat(path).then(stat => fromBlob(stat, path, type));
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
* @returns {Promise<File>}
|
||||
*/
|
||||
const fileFrom = (path, type) => stat(path).then(stat => fromFile(stat, path, type));
|
||||
|
||||
/**
|
||||
* @param {string} path filepath on the disk
|
||||
* @param {string} [type] mimetype to use
|
||||
*/
|
||||
const fileFromSync = (path, type) => fromFile(statSync(path), path, type);
|
||||
|
||||
// @ts-ignore
|
||||
const fromBlob = (stat, path, type = '') => new _Blob([new BlobDataItem({
|
||||
path,
|
||||
size: stat.size,
|
||||
lastModified: stat.mtimeMs,
|
||||
start: 0
|
||||
})], { type });
|
||||
|
||||
// @ts-ignore
|
||||
const fromFile = (stat, path, type = '') => new File$1([new BlobDataItem({
|
||||
path,
|
||||
size: stat.size,
|
||||
lastModified: stat.mtimeMs,
|
||||
start: 0
|
||||
})], basename(path), { type, lastModified: stat.mtimeMs });
|
||||
|
||||
/**
|
||||
* This is a blob backed up by a file on the disk
|
||||
* with minium requirement. Its wrapped around a Blob as a blobPart
|
||||
* so you have no direct access to this.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
class BlobDataItem {
|
||||
#path
|
||||
#start
|
||||
|
||||
constructor (options) {
|
||||
this.#path = options.path;
|
||||
this.#start = options.start;
|
||||
this.size = options.size;
|
||||
this.lastModified = options.lastModified;
|
||||
this.originalSize = options.originalSize === undefined
|
||||
? options.size
|
||||
: options.originalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Slicing arguments is first validated and formatted
|
||||
* to not be out of range by Blob.prototype.slice
|
||||
*/
|
||||
slice (start, end) {
|
||||
return new BlobDataItem({
|
||||
path: this.#path,
|
||||
lastModified: this.lastModified,
|
||||
originalSize: this.originalSize,
|
||||
size: end - start,
|
||||
start: this.#start + start
|
||||
})
|
||||
}
|
||||
|
||||
async * stream () {
|
||||
const { mtimeMs, size } = await stat(this.#path);
|
||||
|
||||
if (mtimeMs > this.lastModified || this.originalSize !== size) {
|
||||
throw new nodeDomexception('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError')
|
||||
}
|
||||
|
||||
yield * createReadStream(this.#path, {
|
||||
start: this.#start,
|
||||
end: this.#start + this.size - 1
|
||||
});
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag] () {
|
||||
return 'Blob'
|
||||
}
|
||||
}
|
||||
|
||||
const fetch = globalThis.fetch || fetch$1;
|
||||
const Blob = globalThis.Blob || _Blob;
|
||||
const File = globalThis.File || File$1;
|
||||
const FormData = globalThis.FormData || FormData$1;
|
||||
const Headers = globalThis.Headers || Headers$1;
|
||||
const Request = globalThis.Request || Request$1;
|
||||
const Response = globalThis.Response || Response$1;
|
||||
const AbortController = globalThis.AbortController || AbortController$1;
|
||||
|
||||
export { AbortController, Blob, File, FormData, Headers, Request, Response, blobFrom, blobFromSync, fetch as default, fetch, fileFrom, fileFromSync };
|
||||
24
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/native.cjs
generated
vendored
Normal file
24
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/native.cjs
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const Blob = globalThis.Blob;
|
||||
const File = globalThis.File;
|
||||
const FormData = globalThis.FormData;
|
||||
const Headers = globalThis.Headers;
|
||||
const Request = globalThis.Request;
|
||||
const Response = globalThis.Response;
|
||||
const AbortController = globalThis.AbortController;
|
||||
const fetch = globalThis.fetch || (() => {
|
||||
throw new Error("global fetch is not available!");
|
||||
});
|
||||
|
||||
exports.AbortController = AbortController;
|
||||
exports.Blob = Blob;
|
||||
exports.File = File;
|
||||
exports.FormData = FormData;
|
||||
exports.Headers = Headers;
|
||||
exports.Request = Request;
|
||||
exports.Response = Response;
|
||||
exports.default = fetch;
|
||||
exports.fetch = fetch;
|
||||
12
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/native.mjs
generated
vendored
Normal file
12
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/native.mjs
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
const Blob = globalThis.Blob;
|
||||
const File = globalThis.File;
|
||||
const FormData = globalThis.FormData;
|
||||
const Headers = globalThis.Headers;
|
||||
const Request = globalThis.Request;
|
||||
const Response = globalThis.Response;
|
||||
const AbortController = globalThis.AbortController;
|
||||
const fetch = globalThis.fetch || (() => {
|
||||
throw new Error("global fetch is not available!");
|
||||
});
|
||||
|
||||
export { AbortController, Blob, File, FormData, Headers, Request, Response, fetch as default, fetch };
|
||||
22
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/polyfill.cjs
generated
vendored
Normal file
22
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/polyfill.cjs
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
const abortController = require('./shared/node-fetch-native.bd0cd7ae.cjs');
|
||||
require('node:fs');
|
||||
require('node:path');
|
||||
require('node:http');
|
||||
require('node:https');
|
||||
require('node:zlib');
|
||||
require('node:stream');
|
||||
require('node:buffer');
|
||||
require('node:util');
|
||||
require('node:url');
|
||||
require('node:net');
|
||||
|
||||
globalThis.fetch = globalThis.fetch || abortController.fetch;
|
||||
globalThis.Blob = globalThis.Blob || abortController._Blob;
|
||||
globalThis.File = globalThis.File || abortController.File;
|
||||
globalThis.FormData = globalThis.FormData || abortController.FormData;
|
||||
globalThis.Headers = globalThis.Headers || abortController.Headers;
|
||||
globalThis.Request = globalThis.Request || abortController.Request;
|
||||
globalThis.Response = globalThis.Response || abortController.Response;
|
||||
globalThis.AbortController = globalThis.AbortController || abortController.AbortController;
|
||||
20
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/polyfill.mjs
generated
vendored
Normal file
20
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/polyfill.mjs
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { f as fetch, _ as _Blob, F as File, a as FormData, H as Headers, R as Request, b as Response, A as AbortController } from './shared/node-fetch-native.b703cef9.mjs';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:zlib';
|
||||
import 'node:stream';
|
||||
import 'node:buffer';
|
||||
import 'node:util';
|
||||
import 'node:url';
|
||||
import 'node:net';
|
||||
|
||||
globalThis.fetch = globalThis.fetch || fetch;
|
||||
globalThis.Blob = globalThis.Blob || _Blob;
|
||||
globalThis.File = globalThis.File || File;
|
||||
globalThis.FormData = globalThis.FormData || FormData;
|
||||
globalThis.Headers = globalThis.Headers || Headers;
|
||||
globalThis.Request = globalThis.Request || Request;
|
||||
globalThis.Response = globalThis.Response || Response;
|
||||
globalThis.AbortController = globalThis.AbortController || AbortController;
|
||||
7636
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/shared/node-fetch-native.b703cef9.mjs
generated
vendored
Normal file
7636
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/shared/node-fetch-native.b703cef9.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7649
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/shared/node-fetch-native.bd0cd7ae.cjs
generated
vendored
Normal file
7649
node_modules/ohmyfetch/node_modules/node-fetch-native/dist/shared/node-fetch-native.bd0cd7ae.cjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
0
node_modules/ohmyfetch/node_modules/node-fetch-native/lib/empty.mjs
generated
vendored
Normal file
0
node_modules/ohmyfetch/node_modules/node-fetch-native/lib/empty.mjs
generated
vendored
Normal file
11
node_modules/ohmyfetch/node_modules/node-fetch-native/lib/index.cjs
generated
vendored
Normal file
11
node_modules/ohmyfetch/node_modules/node-fetch-native/lib/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
const nodeFetch = require('../dist/index.cjs')
|
||||
|
||||
function fetch (input, options) {
|
||||
return nodeFetch.fetch(input, options)
|
||||
}
|
||||
|
||||
for (const key in nodeFetch) {
|
||||
fetch[key] = nodeFetch[key]
|
||||
}
|
||||
|
||||
module.exports = fetch
|
||||
10
node_modules/ohmyfetch/node_modules/node-fetch-native/lib/index.d.ts
generated
vendored
Normal file
10
node_modules/ohmyfetch/node_modules/node-fetch-native/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export declare const fetch: typeof globalThis.fetch
|
||||
export declare const Blob: typeof globalThis.Blob
|
||||
export declare const File: typeof globalThis.File
|
||||
export declare const FormData: typeof globalThis.FormData
|
||||
export declare const Headers: typeof globalThis.Headers
|
||||
export declare const Request: typeof globalThis.Request
|
||||
export declare const Response: typeof globalThis.Response
|
||||
export declare const AbortController: typeof globalThis.AbortController
|
||||
|
||||
export default fetch
|
||||
52
node_modules/ohmyfetch/node_modules/node-fetch-native/package.json
generated
vendored
Normal file
52
node_modules/ohmyfetch/node_modules/node-fetch-native/package.json
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "node-fetch-native",
|
||||
"version": "0.1.8",
|
||||
"description": "A better redistribution of `node-fetch`",
|
||||
"repository": "unjs/node-fetch-native",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"node": {
|
||||
"require": "./lib/index.cjs",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"import": "./dist/native.mjs"
|
||||
},
|
||||
"./polyfill": {
|
||||
"node": {
|
||||
"require": "./dist/polyfill.cjs",
|
||||
"import": "./dist/polyfill.mjs"
|
||||
},
|
||||
"import": "./lib/empty.mjs"
|
||||
},
|
||||
"./src/index.js": {
|
||||
"import": "./dist/index.mjs"
|
||||
}
|
||||
},
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./lib/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"lib"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@nuxtjs/eslint-config-typescript": "^11.0.0",
|
||||
"@vitest/coverage-c8": "^0.24.3",
|
||||
"abort-controller": "^3.0.0",
|
||||
"eslint": "^8.25.0",
|
||||
"node-fetch": "^3.2.10",
|
||||
"standard-version": "^9.5.0",
|
||||
"typescript": "^4.8.4",
|
||||
"unbuild": "^0.9.4",
|
||||
"vitest": "^0.24.3"
|
||||
},
|
||||
"packageManager": "pnpm@7.13.4",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"lint": "eslint --ext .ts,.js,.mjs,.cjs .",
|
||||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
|
||||
"test": "pnpm lint && pnpm build && vitest run --coverage"
|
||||
}
|
||||
}
|
||||
21
node_modules/ohmyfetch/node_modules/ufo/LICENSE
generated
vendored
Normal file
21
node_modules/ohmyfetch/node_modules/ufo/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Nuxt Contrib
|
||||
|
||||
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/ohmyfetch/node_modules/ufo/README.md
generated
vendored
Normal file
234
node_modules/ohmyfetch/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
|
||||
497
node_modules/ohmyfetch/node_modules/ufo/dist/index.cjs
generated
vendored
Normal file
497
node_modules/ohmyfetch/node_modules/ufo/dist/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,497 @@
|
||||
'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 (_err) {
|
||||
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(paramsStr = "") {
|
||||
const obj = {};
|
||||
if (paramsStr[0] === "?") {
|
||||
paramsStr = paramsStr.substr(1);
|
||||
}
|
||||
for (const param of paramsStr.split("&")) {
|
||||
const s = param.match(/([^=]+)=?(.*)/) || [];
|
||||
if (s.length < 2) {
|
||||
continue;
|
||||
}
|
||||
const key = decode(s[1]);
|
||||
if (key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = decodeQueryValue(s[2] || "");
|
||||
if (obj[key]) {
|
||||
if (Array.isArray(obj[key])) {
|
||||
obj[key].push(value);
|
||||
} else {
|
||||
obj[key] = [obj[key], value];
|
||||
}
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
function encodeQueryItem(key, val) {
|
||||
if (typeof val === "number" || typeof val === "boolean") {
|
||||
val = String(val);
|
||||
}
|
||||
if (!val) {
|
||||
return encodeQueryKey(key);
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
return val.map((_val) => `${encodeQueryKey(key)}=${encodeQueryValue(_val)}`).join("&");
|
||||
}
|
||||
return `${encodeQueryKey(key)}=${encodeQueryValue(val)}`;
|
||||
}
|
||||
function stringifyQuery(query) {
|
||||
return Object.keys(query).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 ? "?" + q : "";
|
||||
}
|
||||
get searchParams() {
|
||||
const p = new URLSearchParams();
|
||||
for (const name in this.query) {
|
||||
const value = this.query[name];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((v) => 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(inputStr) {
|
||||
return ["./", "../"].some((str) => inputStr.startsWith(str));
|
||||
}
|
||||
const PROTOCOL_REGEX = /^\w+:(\/\/)?/;
|
||||
const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
|
||||
function hasProtocol(inputStr, acceptProtocolRelative = false) {
|
||||
return PROTOCOL_REGEX.test(inputStr) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputStr);
|
||||
}
|
||||
const TRAILING_SLASH_RE = /\/$|\/\?/;
|
||||
function hasTrailingSlash(input = "", queryParams = false) {
|
||||
if (!queryParams) {
|
||||
return input.endsWith("/");
|
||||
}
|
||||
return TRAILING_SLASH_RE.test(input);
|
||||
}
|
||||
function withoutTrailingSlash(input = "", queryParams = false) {
|
||||
if (!queryParams) {
|
||||
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 ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function withTrailingSlash(input = "", queryParams = false) {
|
||||
if (!queryParams) {
|
||||
return input.endsWith("/") ? input : input + "/";
|
||||
}
|
||||
if (hasTrailingSlash(input, true)) {
|
||||
return input || "/";
|
||||
}
|
||||
const [s0, ...s] = input.split("?");
|
||||
return s0 + "/" + (s.length ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function hasLeadingSlash(input = "") {
|
||||
return input.startsWith("/");
|
||||
}
|
||||
function withoutLeadingSlash(input = "") {
|
||||
return (hasLeadingSlash(input) ? input.substr(1) : input) || "/";
|
||||
}
|
||||
function withLeadingSlash(input = "") {
|
||||
return hasLeadingSlash(input) ? input : "/" + input;
|
||||
}
|
||||
function cleanDoubleSlashes(input = "") {
|
||||
return input.split("://").map((str) => str.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.substring(_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 i of input.filter(isNonEmptyURL)) {
|
||||
url = url ? withTrailingSlash(url) + withoutLeadingSlash(i) : i;
|
||||
}
|
||||
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.substring(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 i of input.filter(isNonEmptyURL)) {
|
||||
url.append(createURL(i));
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
function isSamePath(p1, p2) {
|
||||
return decode(withoutTrailingSlash(p1)) === decode(withoutTrailingSlash(p2));
|
||||
}
|
||||
function isEqual(a, b, opts = {}) {
|
||||
if (!opts.trailingSlash) {
|
||||
a = withTrailingSlash(a);
|
||||
b = withTrailingSlash(b);
|
||||
}
|
||||
if (!opts.leadingSlash) {
|
||||
a = withLeadingSlash(a);
|
||||
b = withLeadingSlash(b);
|
||||
}
|
||||
if (!opts.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);
|
||||
return {
|
||||
protocol,
|
||||
auth: auth ? auth.substr(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/ohmyfetch/node_modules/ufo/dist/index.d.ts
generated
vendored
Normal file
155
node_modules/ohmyfetch/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;
|
||||
|
||||
declare type QueryValue = string | string[] | undefined;
|
||||
declare type QueryObject = Record<string, QueryValue>;
|
||||
declare function parseQuery(paramsStr?: string): QueryObject;
|
||||
declare function encodeQueryItem(key: string, val: 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(inputStr: string): boolean;
|
||||
declare function hasProtocol(inputStr: string, acceptProtocolRelative?: boolean): boolean;
|
||||
declare function hasTrailingSlash(input?: string, queryParams?: boolean): boolean;
|
||||
declare function withoutTrailingSlash(input?: string, queryParams?: boolean): string;
|
||||
declare function withTrailingSlash(input?: string, queryParams?: 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, opts?: 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 };
|
||||
452
node_modules/ohmyfetch/node_modules/ufo/dist/index.mjs
generated
vendored
Normal file
452
node_modules/ohmyfetch/node_modules/ufo/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,452 @@
|
||||
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 (_err) {
|
||||
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(paramsStr = "") {
|
||||
const obj = {};
|
||||
if (paramsStr[0] === "?") {
|
||||
paramsStr = paramsStr.substr(1);
|
||||
}
|
||||
for (const param of paramsStr.split("&")) {
|
||||
const s = param.match(/([^=]+)=?(.*)/) || [];
|
||||
if (s.length < 2) {
|
||||
continue;
|
||||
}
|
||||
const key = decode(s[1]);
|
||||
if (key === "__proto__" || key === "constructor") {
|
||||
continue;
|
||||
}
|
||||
const value = decodeQueryValue(s[2] || "");
|
||||
if (obj[key]) {
|
||||
if (Array.isArray(obj[key])) {
|
||||
obj[key].push(value);
|
||||
} else {
|
||||
obj[key] = [obj[key], value];
|
||||
}
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
function encodeQueryItem(key, val) {
|
||||
if (typeof val === "number" || typeof val === "boolean") {
|
||||
val = String(val);
|
||||
}
|
||||
if (!val) {
|
||||
return encodeQueryKey(key);
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
return val.map((_val) => `${encodeQueryKey(key)}=${encodeQueryValue(_val)}`).join("&");
|
||||
}
|
||||
return `${encodeQueryKey(key)}=${encodeQueryValue(val)}`;
|
||||
}
|
||||
function stringifyQuery(query) {
|
||||
return Object.keys(query).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 ? "?" + q : "";
|
||||
}
|
||||
get searchParams() {
|
||||
const p = new URLSearchParams();
|
||||
for (const name in this.query) {
|
||||
const value = this.query[name];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((v) => 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(inputStr) {
|
||||
return ["./", "../"].some((str) => inputStr.startsWith(str));
|
||||
}
|
||||
const PROTOCOL_REGEX = /^\w+:(\/\/)?/;
|
||||
const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
|
||||
function hasProtocol(inputStr, acceptProtocolRelative = false) {
|
||||
return PROTOCOL_REGEX.test(inputStr) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputStr);
|
||||
}
|
||||
const TRAILING_SLASH_RE = /\/$|\/\?/;
|
||||
function hasTrailingSlash(input = "", queryParams = false) {
|
||||
if (!queryParams) {
|
||||
return input.endsWith("/");
|
||||
}
|
||||
return TRAILING_SLASH_RE.test(input);
|
||||
}
|
||||
function withoutTrailingSlash(input = "", queryParams = false) {
|
||||
if (!queryParams) {
|
||||
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 ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function withTrailingSlash(input = "", queryParams = false) {
|
||||
if (!queryParams) {
|
||||
return input.endsWith("/") ? input : input + "/";
|
||||
}
|
||||
if (hasTrailingSlash(input, true)) {
|
||||
return input || "/";
|
||||
}
|
||||
const [s0, ...s] = input.split("?");
|
||||
return s0 + "/" + (s.length ? `?${s.join("?")}` : "");
|
||||
}
|
||||
function hasLeadingSlash(input = "") {
|
||||
return input.startsWith("/");
|
||||
}
|
||||
function withoutLeadingSlash(input = "") {
|
||||
return (hasLeadingSlash(input) ? input.substr(1) : input) || "/";
|
||||
}
|
||||
function withLeadingSlash(input = "") {
|
||||
return hasLeadingSlash(input) ? input : "/" + input;
|
||||
}
|
||||
function cleanDoubleSlashes(input = "") {
|
||||
return input.split("://").map((str) => str.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.substring(_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 i of input.filter(isNonEmptyURL)) {
|
||||
url = url ? withTrailingSlash(url) + withoutLeadingSlash(i) : i;
|
||||
}
|
||||
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.substring(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 i of input.filter(isNonEmptyURL)) {
|
||||
url.append(createURL(i));
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
function isSamePath(p1, p2) {
|
||||
return decode(withoutTrailingSlash(p1)) === decode(withoutTrailingSlash(p2));
|
||||
}
|
||||
function isEqual(a, b, opts = {}) {
|
||||
if (!opts.trailingSlash) {
|
||||
a = withTrailingSlash(a);
|
||||
b = withTrailingSlash(b);
|
||||
}
|
||||
if (!opts.leadingSlash) {
|
||||
a = withLeadingSlash(a);
|
||||
b = withLeadingSlash(b);
|
||||
}
|
||||
if (!opts.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);
|
||||
return {
|
||||
protocol,
|
||||
auth: auth ? auth.substr(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/ohmyfetch/node_modules/ufo/package.json
generated
vendored
Normal file
39
node_modules/ohmyfetch/node_modules/ufo/package.json
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "ufo",
|
||||
"version": "0.8.6",
|
||||
"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": {
|
||||
"@nuxtjs/eslint-config-typescript": "^11.0.0",
|
||||
"@types/node": "^18.11.0",
|
||||
"c8": "^7.12.0",
|
||||
"eslint": "^8.25.0",
|
||||
"standard-version": "^9.5.0",
|
||||
"typescript": "^4.8.4",
|
||||
"unbuild": "^0.9.2",
|
||||
"vitest": "^0.24.3"
|
||||
},
|
||||
"packageManager": "pnpm@7.13.4",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
72
node_modules/ohmyfetch/package.json
generated
vendored
Normal file
72
node_modules/ohmyfetch/package.json
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "ohmyfetch",
|
||||
"version": "0.4.21",
|
||||
"description": "oh-my-fetch",
|
||||
"repository": "unjs/ohmyfetch",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"node": {
|
||||
"types": "./dist/node.d.ts",
|
||||
"import": "./dist/node.mjs",
|
||||
"require": "./cjs/node.cjs"
|
||||
},
|
||||
"default": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./cjs/index.cjs"
|
||||
}
|
||||
},
|
||||
"./node": {
|
||||
"types": "./dist/node.d.ts",
|
||||
"import": "./dist/node.mjs",
|
||||
"require": "./cjs/node.cjs"
|
||||
},
|
||||
"./undici": {
|
||||
"types": "./dist/undici.d.ts",
|
||||
"import": "./dist/undici.mjs",
|
||||
"require": "./cjs/undici.cjs"
|
||||
}
|
||||
},
|
||||
"main": "./cjs/node.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"node.d.ts",
|
||||
"undici.d.ts",
|
||||
"cjs"
|
||||
],
|
||||
"dependencies": {
|
||||
"destr": "^1.2.0",
|
||||
"node-fetch-native": "^0.1.8",
|
||||
"ufo": "^0.8.6",
|
||||
"undici": "^5.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nuxtjs/eslint-config-typescript": "^11.0.0",
|
||||
"@types/node": "^18.11.9",
|
||||
"@vitest/coverage-c8": "^0.24.5",
|
||||
"eslint": "^8.26.0",
|
||||
"fetch-blob": "^3.2.0",
|
||||
"formdata-polyfill": "^4.0.10",
|
||||
"h3": "^0.8.6",
|
||||
"jiti": "^1.16.0",
|
||||
"listhen": "^0.3.5",
|
||||
"standard-version": "^9.5.0",
|
||||
"typescript": "^4.8.4",
|
||||
"unbuild": "^0.9.4",
|
||||
"vitest": "^0.24.5"
|
||||
},
|
||||
"packageManager": "pnpm@7.14.2",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "vitest",
|
||||
"lint": "eslint --ext .ts .",
|
||||
"play": "jiti playground/index.ts",
|
||||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
|
||||
"test": "pnpm lint && vitest run --coverage"
|
||||
}
|
||||
}
|
||||
1
node_modules/ohmyfetch/undici.d.ts
generated
vendored
Normal file
1
node_modules/ohmyfetch/undici.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './dist/undici'
|
||||
Reference in New Issue
Block a user