Skip to content

Commit 39d4277

Browse files
authored
[add] Abort Signal support & polyfill (#9)
1 parent 0efd48f commit 39d4277

10 files changed

+3735
-3121
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
- uses: pnpm/action-setup@v2
1313
with:
14-
version: 8
14+
version: 9
1515
- uses: actions/setup-node@v3
1616
with:
1717
node-version: 18

ReadMe.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ npm install koajax
4444
<script src="https://polyfill.web-cell.dev/feature/Regenerator.js"></script>
4545
<script src="https://polyfill.web-cell.dev/feature/ECMAScript.js"></script>
4646
<script src="https://polyfill.web-cell.dev/feature/TextEncoder.js"></script>
47+
<script src="https://polyfill.web-cell.dev/feature/AbortController.js"></script>
4748
</head>
4849
```
4950

@@ -139,19 +140,22 @@ const bufferClient = new HTTPClient({ responseType: 'arraybuffer' });
139140

140141
document.querySelector('#download').onclick = async () => {
141142
const fileURL = 'https://your.server/with/Range/header/supported/file.zip';
142-
const suggestedName = fileURL.split('/').at(-1);
143+
const suggestedName = new URL(fileURL).pathname.split('/').pop();
143144

144145
const fileHandle = await showSaveFilePicker({ suggestedName });
145146
const writer = await fileHandle.createWritable(),
146147
stream = bufferClient.download(fileURL);
147148

148-
for await (const { total, loaded, percent, buffer } of stream) {
149-
writer.write(buffer);
149+
try {
150+
for await (const { total, loaded, percent, buffer } of stream) {
151+
await writer.write(buffer);
150152

151-
console.table({ total, loaded, percent });
153+
console.table({ total, loaded, percent });
154+
}
155+
window.alert(`File ${fileHandle.name} downloaded successfully!`);
156+
} finally {
157+
await writer.close();
152158
}
153-
writer.close();
154-
window.alert(`File ${fileHandle.name} downloaded successfully!`);
155159
};
156160
```
157161

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "koajax",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"license": "LGPL-3.0",
55
"author": "[email protected]",
66
"description": "HTTP Client based on Koa-like middlewares",
@@ -25,10 +25,10 @@
2525
"main": "dist/index.js",
2626
"module": "dist/index.esm.js",
2727
"dependencies": {
28-
"@swc/helpers": "^0.5.8",
28+
"@swc/helpers": "^0.5.11",
2929
"iterable-observer": "^1.0.1",
3030
"regenerator-runtime": "^0.14.1",
31-
"web-utility": "^4.3.0"
31+
"web-utility": "^4.4.0"
3232
},
3333
"peerDependencies": {
3434
"jsdom": ">=21"
@@ -39,8 +39,8 @@
3939
"@types/core-js": "^2.5.8",
4040
"@types/jest": "^29.5.12",
4141
"@types/jsdom": "^21.1.6",
42-
"@types/node": "^18.19.28",
43-
"core-js": "^3.36.1",
42+
"@types/node": "^18.19.33",
43+
"core-js": "^3.37.1",
4444
"cross-env": "^7.0.3",
4545
"husky": "^9.0.11",
4646
"jest": "^29.7.0",
@@ -51,9 +51,9 @@
5151
"parcel": "~2.12.0",
5252
"prettier": "^3.2.5",
5353
"ts-jest": "^29.1.2",
54-
"typedoc": "^0.25.12",
55-
"typedoc-plugin-mdn-links": "^3.1.18",
56-
"typescript": "~5.4.3"
54+
"typedoc": "^0.25.13",
55+
"typedoc-plugin-mdn-links": "^3.1.25",
56+
"typescript": "~5.5.0-beta"
5757
},
5858
"prettier": {
5959
"singleQuote": true,
@@ -77,7 +77,7 @@
7777
},
7878
"scripts": {
7979
"prepare": "husky",
80-
"test": "lint-staged && jest",
80+
"test": "lint-staged && cross-env NODE_OPTIONS=--unhandled-rejections=warn jest",
8181
"pack-dist": "rm -rf dist/ && tsc --emitDeclarationOnly && parcel build",
8282
"pack-docs": "rm -rf docs/ && typedoc source/",
8383
"build": "npm run pack-dist && npm run pack-docs",

0 commit comments

Comments
 (0)