@rg-dev/stdlib
Advanced tools
@@ -27,3 +27,3 @@ var __defProp = Object.defineProperty; | ||
| fetchHelperJSON: () => fetchHelperJSON, | ||
| fetchHelperPostJSON: () => fetchHelperPostJSON, | ||
| fetchHelperPost: () => fetchHelperPost, | ||
| fetchHelperText: () => fetchHelperText, | ||
@@ -103,7 +103,11 @@ isNonEmptyString: () => isNonEmptyString, | ||
| } | ||
| async function fetchHelperPostJSON(url, body, config) { | ||
| async function fetchHelperPost(url, body, config) { | ||
| const isObject = typeof body == "object"; | ||
| config = config || {}; | ||
| config.method = "POST"; | ||
| config.body = typeof body == "string" ? body : JSON.stringify(body); | ||
| config.headers["Content-Type"] = "application/json"; | ||
| config.body = isObject ? JSON.stringify(body) : body; | ||
| config.headers = config.headers || {}; | ||
| if (isObject) { | ||
| config.headers["Content-Type"] = "application/json"; | ||
| } | ||
| const res = await fetch(url, config); | ||
@@ -110,0 +114,0 @@ if (!res.ok) { |
@@ -45,3 +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 fetchHelperPost(url: string, body: any, config?: RequestInit): Promise<Response>; | ||
| declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>; | ||
@@ -78,2 +78,2 @@ | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPostJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; |
@@ -45,3 +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 fetchHelperPost(url: string, body: any, config?: RequestInit): Promise<Response>; | ||
| declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>; | ||
@@ -78,2 +78,2 @@ | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPostJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; | ||
| export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer }; |
@@ -64,7 +64,11 @@ // src/promise-retry.ts | ||
| } | ||
| async function fetchHelperPostJSON(url, body, config) { | ||
| async function fetchHelperPost(url, body, config) { | ||
| const isObject = typeof body == "object"; | ||
| config = config || {}; | ||
| config.method = "POST"; | ||
| config.body = typeof body == "string" ? body : JSON.stringify(body); | ||
| config.headers["Content-Type"] = "application/json"; | ||
| config.body = isObject ? JSON.stringify(body) : body; | ||
| config.headers = config.headers || {}; | ||
| if (isObject) { | ||
| config.headers["Content-Type"] = "application/json"; | ||
| } | ||
| const res = await fetch(url, config); | ||
@@ -204,3 +208,3 @@ if (!res.ok) { | ||
| fetchHelperJSON, | ||
| fetchHelperPostJSON, | ||
| fetchHelperPost, | ||
| fetchHelperText, | ||
@@ -207,0 +211,0 @@ isNonEmptyString, |
+1
-1
| { | ||
| "name": "@rg-dev/stdlib", | ||
| "version": "1.0.33", | ||
| "version": "1.0.34", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
540062
0.03%13488
0.06%