myfetchapi
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -0,7 +1,13 @@ | ||
import type * as nodefetch from "node-fetch"; | ||
/** | ||
* set maximum number of concurrent requests (requests made at thesame time) | ||
* @param max @default 500 | ||
*/ | ||
export declare const SET_MAX_CONCURRENT_REQUESTS: (max: number) => void; | ||
export type myFetchOptions = { | ||
useNodeFetch?: boolean; | ||
maxRetry?: number | null; | ||
retryCb?: (err: any, count: number, max: number) => any; | ||
retryCondition?: (res: Response) => boolean | Promise<boolean>; | ||
retryCondition?: (res: Response | nodefetch.Response) => boolean | Promise<boolean>; | ||
}; | ||
export declare function myFetch(input: RequestInfo, init?: RequestInit, options?: myFetchOptions): Promise<Response>; | ||
export declare function myFetch(input: RequestInfo | nodefetch.RequestInfo, init?: RequestInit | nodefetch.RequestInit, options?: myFetchOptions): Promise<Response>; |
@@ -20,3 +20,3 @@ "use strict"; | ||
// src/index.ts | ||
// index.ts | ||
var src_exports = {}; | ||
@@ -36,3 +36,4 @@ __export(src_exports, { | ||
try { | ||
const res = await fetch(input, init); | ||
const httpFunc = options?.useNodeFetch ? (await require("./nodeFetch.js")).fetch : fetch; | ||
const res = await httpFunc(input, init); | ||
const isOkay = options?.retryCondition ? await options.retryCondition(res) : res.ok; | ||
@@ -53,3 +54,3 @@ if (isOkay) | ||
try { | ||
return (await res.text()).substring(0, 250); | ||
return await res.text(); | ||
} catch (_) { | ||
@@ -59,3 +60,3 @@ return ""; | ||
} | ||
async function myFetch(input, init = {}, options) { | ||
async function myFetch(input, init, options) { | ||
const maxRetry = options?.maxRetry === void 0 ? 3 : options.maxRetry === null ? 0 : options.maxRetry < 0 ? 0 : options.maxRetry; | ||
@@ -62,0 +63,0 @@ return new Promise((resolve, reject) => { |
{ | ||
"name": "myfetchapi", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "mFetch is a JavaScript library that provides a utility function for making HTTP requests with queuing and retry functionality.", | ||
@@ -20,4 +20,6 @@ "type": "commonjs", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "tsc && esbuild src/index.ts --format=cjs --bundle --outfile=dist/index.js && esbuild src/index.ts --format=esm --bundle --outfile=dist/index.mjs" | ||
"test": "cd test && npm run dev", | ||
"build": "tsc && cd src && npm run cjs && npm run esm", | ||
"cjs": "esbuild nodeFetch.ts --format=cjs --bundle --platform=node --outfile=../dist/nodeFetch.js && esbuild index.ts --format=cjs --bundle --external:./nodeFetch.js --outfile=../dist/index.js", | ||
"esm": "esbuild nodeFetch.ts --format=esm --bundle --platform=node --outfile=../dist/nodeFetch.mjs && esbuild index.ts --format=esm --bundle --external:./nodeFetch.js --outfile=../dist/index.mjs" | ||
}, | ||
@@ -43,3 +45,9 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/ugo-studio/myfetch#readme" | ||
"homepage": "https://github.com/ugo-studio/myfetch#readme", | ||
"dependencies": { | ||
"node-fetch": "^3.3.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.9" | ||
} | ||
} |
@@ -12,3 +12,3 @@ { | ||
/* Language and Environment */ | ||
"target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
@@ -26,5 +26,5 @@ // "jsx": "preserve", /* Specify what JSX code is generated. */ | ||
/* Modules */ | ||
"module": "ES2020", /* Specify what module code is generated. */ | ||
"module": "ES2022", /* Specify what module code is generated. */ | ||
// "rootDir": "./", /* Specify the root folder within your source files. */ | ||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
"moduleResolution": "Bundler", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ | ||
@@ -31,0 +31,0 @@ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
537504
9
13061
0
1
1
6
8
+ Addednode-fetch@^3.3.2
+ Addeddata-uri-to-buffer@4.0.1(transitive)
+ Addedfetch-blob@3.2.0(transitive)
+ Addedformdata-polyfill@4.0.10(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addednode-fetch@3.3.2(transitive)
+ Addedweb-streams-polyfill@3.3.3(transitive)