Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

jo-fetch

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jo-fetch

JoFetch is a JavaScript tool that provides enhanced fetch functionality.

npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

JoFetch · License NPM CI

JoFetch is a JavaScript tool that provides enhanced fetch functionality.

There are a lot of functions in this tool, such as simple or integration version. Of course, all functions are successfully tested by Jest. By the way, hope this fetch function return any data jo(just) like how we call it.

Usage

import joFetch from 'jo-fetch'
let doc = await joFetch(
	'https://www.google.com',
	{
		method: 'GET',
		loadingTime: 10000,
		retryTimes: 5,
		retryDelay: 1000,
		typeTo: 'document',
	}
)
import { fetchDocument } from 'jo-fetch'
let doc = await fetchDocument(
	'https://www.google.com',
	{ method: 'GET' }
)

Installation

npm install jo-fetch

API

Integration function (joFetch)

joFetch(url, param)
The following are the additional attributes in the parameter "param".

AttributeTypeDescription
loadingTimenumberDefine the loading time for this fetch. If the fetch time exceeds this value, this fetch fails and an error is thrown.
retryTimesnumberDefine the number of times to retry to fetch it again when this fetch fails.
retryDelaynumberDefine the delay before each retry.
typeFromstringSpecify the type of data to be retrieved.
typeTostringSpecify the type of returned data.
isBadResponseErrorbooleanDefine whether to throw an error when the result isn't ok status.
onErrorfunctionDefine the hook to trigger it when an error is caught.

Simple function

The parameters, url and param, are same as window.fetch.

FunctionReturn TypeDescription
fetchText(url, param)PromiseReturn the result as text after fetching.
fetchJSON(url, param)PromiseReturn the result in json form after fetching.
fetchBlob(url, param)PromiseReturn the result as a blob after fetching.
fetchDocument(url, param)PromiseReturn the result as a document after fetching.
fetchGZip(url, param)PromiseReturn the decompressed result after fetching. It only works on browser.
fetchOnlyResponseOk(url, param)PromiseReturn the result with ok status. If not, this fetch fails and an error is thrown.
fetchInTime(url, param, time: number)PromiseReturn the result within a limit time. If not, this fetch fails and an error is thrown.
fetchAutoRetry(url, param, times: number, delay: number)PromiseReturn the successful result. If not, it retries to fetch within a limited number of times.
combineSignals(signals: Array<AbortSignal>)AbortSignalReturn the combined signal for each signal input.

License

JoFetch is MIT licensed.

Keywords

fetch

FAQs

Package last updated on 15 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts