Gathering detailed insights and metrics for exfetch
Gathering detailed insights and metrics for exfetch
Gathering detailed insights and metrics for exfetch
Gathering detailed insights and metrics for exfetch
npm install exfetch
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
4 Commits
2 Watching
2 Branches
1 Contributors
Updated on 10 Jun 2020
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
27.7%
180
Compared to previous day
Last week
26.7%
859
Compared to previous week
Last month
-18.5%
3,333
Compared to previous month
Last year
23.6%
27,586
Compared to previous year
50
Enhanced unfetch
API.
Features:
AbortController
,
following abortable Fetch approach1npm install exfetch --save
1import exfetch from 'exfetch'; 2 3(async () => { 4 const { request, abort, isAborted, onEvent } = exfetch('https://becky.com'); 5 let downloaded = 0; 6 let uploaded = 0; 7 8 onEvent('download', (e) => { 9 if (e.lengthComputable) { 10 downloaded = e.loaded / e.total; 11 } 12 }); 13 14 onEvent('upload', (e) => { 15 if (e.lengthComputable) { 16 uploaded = e.loaded / e.total; 17 } 18 }); 19 20 setTimeout(() => { 21 // Will abort request after 2 seconds 22 abort(); 23 }, 2000); 24 25 const response = await request(); 26 27 if (isAborted()) { 28 // Request aborted! 29 return; 30 } 31 32 // Parse response as JSON 33 const data = await response.json(); 34})();
Using abort
and isAborted
export properties will throw error which instructs
to use
AbortController.abort()
method and
AbortSignal.aborted
property respectively.
1import exfetch from 'exfetch'; 2 3(async () => { 4 const controller = new AbortController(); 5 const signal = controller.signal; 6 const { request, onEvent } = exfetch('https://becky.com', { signal }); 7 let downloaded = 0; 8 let uploaded = 0; 9 10 onEvent('download', (e) => { 11 if (e.lengthComputable) { 12 downloaded = e.loaded / e.total; 13 } 14 }); 15 16 onEvent('upload', (e) => { 17 if (e.lengthComputable) { 18 uploaded = e.loaded / e.total; 19 } 20 }); 21 22 setTimeout(() => { 23 // Will abort request after 2 seconds 24 controller.abort(); 25 }, 2000); 26 27 try { 28 const response = await request(); 29 // Parse response as JSON 30 const data = await response.json(); 31 } catch (error) { 32 if (error.name === 'AbortError') { 33 // Request aborted! 34 return; 35 } 36 } 37})();
Returns: Object
See
unfetch
API documentation
for arguments.
Returns API object with following properties:
Type: Function
Returns: Promise
Returns request Promise
.
Type: Function
Returns: Function
Wrapper around progress event.
Event name | Original handler |
---|---|
download | xhr.onprogress |
upload | xhr.upload.onprogress |
Handler receives one argument which is original Event
.
Returns function for unlistening event.
Type: Function
Returns: undefined
Aborts request.
This has effect only with custom abort implementation. If you use this method
with "abortable Fetch" approach, it will throw error telling
you to use AbortController.abort()
instead.
Type: Function
Returns: boolean
Check if current request is aborted.
This has effect only with custom abort implementation. If you use this method
with "abortable Fetch" approach, it will throw error telling
you to use AbortSignal.aborted
instead.
Original GitHub issue on aborting Fetch
is rather long and it culminated with generic AbortController
approach not
connected only with Fetch, which is great for any kind of abortable operations.
But XHR already has simple solution for aborting requests and it would be shame not to use that.
I wanted to support both approaches, but they have differences in how they are resolved.
For "abortable Fetch" approach, request Promise is rejected
with AbortError
following standard implementation.
For custom abort approach, request Promise is resolved/fulfilled to response
object following
XHR abort operation sequence
with ok
set to false and status set to 0
.
Tested in IE11+ and all modern browsers, assuming Promise
is available
(polyfill).
If you want to use "abortable Fetch" approach, you also need
to have AbortController
available
(polyfill).
For automated tests, run npm run test:automated
(append :watch
for watcher
support).
MIT © Ivan Nikolić
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More