https://github.com/dipiash/enhanced-fetch-lib
Enhanced fetch library
https://github.com/dipiash/enhanced-fetch-lib
abortcontroller fetch polyfill
Last synced: 12 months ago
JSON representation
Enhanced fetch library
- Host: GitHub
- URL: https://github.com/dipiash/enhanced-fetch-lib
- Owner: dipiash
- License: mit
- Created: 2019-11-11T21:40:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T01:03:07.000Z (about 3 years ago)
- Last Synced: 2024-12-23T09:29:40.506Z (about 1 year ago)
- Topics: abortcontroller, fetch, polyfill
- Language: JavaScript
- Size: 1.83 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/js/enhanced-fetch-lib)
# enhanced-fetch-lib
Cross browser wrapper for fetch.
Polyfill is used under the hood:
- [promise-polyfill](https://www.npmjs.com/package/promise-polyfill)
- [whatwg-fetch](https://www.npmjs.com/package/whatwg-fetch)
- [abortcontroller-polyfill](https://www.npmjs.com/package/abortcontroller-polyfill)
## How to view example
Open `/example/index.html` in your browser.
## Before start
`npm i`
## How to start project for development with example app
1. `npm run development`, also you can use a production mode `npm run build`
2. Open `/example/index.html` in your browser for test
## How to build project for production
1. `npm run build`
## For usage: you can use script tag, import or require
```js
if (!window['enhancedFetch']) {
alert('"enhancedFetch" is not defined in window scope');
return;
}
var { requestByFetch } = window['enhancedFetch'];
var fetchInstance = requestByFetch.createInstance({baseUrl: 'https://poller.jeetiss.now.sh',});
var abortC = fetchInstance.abortController();
fetchInstance.fetch('/post', {
signal: abortC.signal,
method: 'POST',
mode: "cors",
}, 10000,)
.then(res => res.json())
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
});
abortC.abort()
```
or
```js
import enhancedFetch from 'enhanced-fetch-lib'
```
or
```js
const enhancedFetch = require('enhanced-fetch-lib').default
```
or
```js
const { enhancedFetch } = require('enhanced-fetch-lib')
```
## TODO
- [x] Add unit tests
- [ ] Improve example. Separate interface control from logic
- [x] Publish into npm
- [ ] Add CI
- [ ] Add auto generation CHANGELOG and version - https://github.com/conventional-changelog/standard-version
- [ ] Add ESLint rules
- [ ] Add Prettier
- [ ] Add husky and lint-staged
- [ ] Add typings (TS or Flow)