-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathindex.ts
49 lines (45 loc) · 1.19 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { setOptions, setErrorType, setPolyfills } from "./config.js"
import { core } from "./core.js"
import { WretchError } from "./resolver.js"
import type { Wretch } from "./types.js"
export type {
Wretch,
Config,
ConfiguredMiddleware,
FetchLike,
Middleware,
WretchResponseChain,
WretchOptions,
WretchError,
WretchErrorCallback,
WretchResponse,
WretchDeferredCallback,
WretchAddon
} from "./types.js"
/**
* Creates a new wretch instance with a base url and base
* [fetch options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch).
*
* ```ts
* import wretch from "wretch"
*
* // Reusable instance
* const w = wretch("https://domain.com", { mode: "cors" })
* ```
*
* @param _url The base url
* @param _options The base fetch options
* @returns A fresh wretch instance
*/
function factory(_url = "", _options = {}): Wretch {
return { ...core, _url, _options }
}
factory["default"] = factory
/** {@inheritDoc setOptions} */
factory.options = setOptions
/** {@inheritDoc setErrorType} */
factory.errorType = setErrorType
/** {@inheritDoc setPolyfills} */
factory.polyfills = setPolyfills
factory.WretchError = WretchError
export default factory