@superutils/fetch 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/dist/browser/index.min.js +1 -1123
- package/dist/browser/index.min.js.map +1 -1
- package/dist/index.cjs +51 -31
- package/dist/index.d.cts +147 -138
- package/dist/index.d.ts +147 -138
- package/dist/index.js +51 -28
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ For full API reference check out the [docs page](https://alien45.github.io/super
|
|
|
14
14
|
|
|
15
15
|
- [Features](#features)
|
|
16
16
|
- [Installation](#installation)
|
|
17
|
+
- [NPM](#npm)
|
|
18
|
+
- [CDN / Browser](#cdn--browser)
|
|
17
19
|
- [Usage](#usage)
|
|
18
20
|
- [`fetch()`](#fetch): drop-in replacement for built-in `fetch()`
|
|
19
21
|
- [`PromisE Features`](#promise-features): status, early finalization etc
|
|
@@ -39,10 +41,57 @@ For full API reference check out the [docs page](https://alien45.github.io/super
|
|
|
39
41
|
|
|
40
42
|
## Installation
|
|
41
43
|
|
|
44
|
+
### NPM
|
|
45
|
+
|
|
46
|
+
Install using your favorite package manager (e.g., `npm`, `yarn`, `pnpm`, `bun`, etc.):
|
|
47
|
+
|
|
42
48
|
```bash
|
|
43
49
|
npm install @superutils/fetch
|
|
44
50
|
```
|
|
45
51
|
|
|
52
|
+
Dependency: `@superutils/core` and `@superutils/promise` will be automatically installed by package manager
|
|
53
|
+
|
|
54
|
+
### CDN / Browser
|
|
55
|
+
|
|
56
|
+
If you are not using a bundler, you can include the browser build directly:
|
|
57
|
+
|
|
58
|
+
```xml
|
|
59
|
+
<script src="https://cdn.jsdelivr.net/npm/@superutils/fetch/dist/browser/index.min.js"></script>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
OR,
|
|
63
|
+
|
|
64
|
+
```xml
|
|
65
|
+
<script src="https://cdn.jsdelivr.net/npm/@superutils/fetch@latest/dist/browser/index.min.js"></script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This will expose a global namespace with the following:
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
// Namespace: default export (function) from '@superutils/fetch' and all the exports as properties
|
|
72
|
+
superutils.fetch
|
|
73
|
+
// Namespace: default export (class) from '@superutils/promise' and all the exports as properties
|
|
74
|
+
superutils.PromisE
|
|
75
|
+
|
|
76
|
+
const { fetch, PromisE } = superutils
|
|
77
|
+
|
|
78
|
+
// Fetch usage
|
|
79
|
+
fetch('url', { method: 'get', timeout: 10_000 })
|
|
80
|
+
fetch.get()
|
|
81
|
+
fetch.createClient({ method: 'post', timeout: 30_000 }, {}, { delay: 500 })
|
|
82
|
+
|
|
83
|
+
// PromisE usage
|
|
84
|
+
new PromisE()
|
|
85
|
+
await PromisE.delay(1000)
|
|
86
|
+
const handleChange = PromisE.deferredCallback(
|
|
87
|
+
event => console.log({ value: event.target.value }),
|
|
88
|
+
{ delay: 300 },
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `@superutils/fetch` browser build includes `PromisE` most (if not all) of it is used internally.
|
|
93
|
+
Loading `@superutils/promise` separately will take precedence and override it.
|
|
94
|
+
|
|
46
95
|
## Usage
|
|
47
96
|
|
|
48
97
|
<div id="fetch"></div>
|