@rg-dev/stdlib
Advanced tools
+13
-0
@@ -27,2 +27,3 @@ var __defProp = Object.defineProperty; | ||
| fetchHelperJSON: () => fetchHelperJSON, | ||
| fetchHelperPostJSON: () => fetchHelperPostJSON, | ||
| fetchHelperText: () => fetchHelperText, | ||
@@ -102,2 +103,14 @@ isNonEmptyString: () => isNonEmptyString, | ||
| } | ||
| async function fetchHelperPostJSON(url, body, config) { | ||
| config = config || {}; | ||
| config.method = "POST"; | ||
| config.body = typeof body == "string" ? body : JSON.stringify(body); | ||
| config.headers["Content-Type"] = "application/json"; | ||
| const res = await fetch(url, config); | ||
| if (!res.ok) { | ||
| const text = await res.text(); | ||
| throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`); | ||
| } | ||
| return res; | ||
| } | ||
| async function fetchHelperText(url, config) { | ||
@@ -104,0 +117,0 @@ const res = await fetch(url, config); |
@@ -45,2 +45,3 @@ type Options = { | ||
| declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>; | ||
| declare function fetchHelperPostJSON(url: string, body: any, config?: RequestInit): Promise<Response>; | ||
| declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>; | ||
@@ -77,2 +78,2 @@ | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPostJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; |
@@ -45,2 +45,3 @@ type Options = { | ||
| declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>; | ||
| declare function fetchHelperPostJSON(url: string, body: any, config?: RequestInit): Promise<Response>; | ||
| declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>; | ||
@@ -77,2 +78,2 @@ | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPostJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; |
+13
-0
@@ -64,2 +64,14 @@ // src/promise-retry.ts | ||
| } | ||
| async function fetchHelperPostJSON(url, body, config) { | ||
| config = config || {}; | ||
| config.method = "POST"; | ||
| config.body = typeof body == "string" ? body : JSON.stringify(body); | ||
| config.headers["Content-Type"] = "application/json"; | ||
| const res = await fetch(url, config); | ||
| if (!res.ok) { | ||
| const text = await res.text(); | ||
| throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`); | ||
| } | ||
| return res; | ||
| } | ||
| async function fetchHelperText(url, config) { | ||
@@ -192,2 +204,3 @@ const res = await fetch(url, config); | ||
| fetchHelperJSON, | ||
| fetchHelperPostJSON, | ||
| fetchHelperText, | ||
@@ -194,0 +207,0 @@ isNonEmptyString, |
+1
-1
| { | ||
| "name": "@rg-dev/stdlib", | ||
| "version": "1.0.32", | ||
| "version": "1.0.33", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
539910
0.22%13480
0.2%22
10%