@rg-dev/stdlib 1.0.33 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common-env.cjs +8 -4
- package/lib/common-env.d.cts +2 -2
- package/lib/common-env.d.ts +2 -2
- package/lib/common-env.js +8 -4
- package/package.json +1 -1
package/lib/common-env.cjs
CHANGED
|
@@ -24,7 +24,7 @@ __export(common_env_exports, {
|
|
|
24
24
|
catchInline: () => catchInline,
|
|
25
25
|
doSafe: () => doSafe,
|
|
26
26
|
fetchHelperJSON: () => fetchHelperJSON,
|
|
27
|
-
|
|
27
|
+
fetchHelperPost: () => fetchHelperPost,
|
|
28
28
|
fetchHelperText: () => fetchHelperText,
|
|
29
29
|
isNonEmptyString: () => isNonEmptyString,
|
|
30
30
|
isNumber: () => isNumber,
|
|
@@ -99,11 +99,15 @@ async function fetchHelperJSON(url, config) {
|
|
|
99
99
|
throwIfNotJSONResponse(res);
|
|
100
100
|
return await res.json();
|
|
101
101
|
}
|
|
102
|
-
async function
|
|
102
|
+
async function fetchHelperPost(url, body, config) {
|
|
103
|
+
const isObject = typeof body == "object";
|
|
103
104
|
config = config || {};
|
|
104
105
|
config.method = "POST";
|
|
105
|
-
config.body =
|
|
106
|
-
config.headers
|
|
106
|
+
config.body = isObject ? JSON.stringify(body) : body;
|
|
107
|
+
config.headers = config.headers || {};
|
|
108
|
+
if (isObject) {
|
|
109
|
+
config.headers["Content-Type"] = "application/json";
|
|
110
|
+
}
|
|
107
111
|
const res = await fetch(url, config);
|
|
108
112
|
if (!res.ok) {
|
|
109
113
|
const text = await res.text();
|
package/lib/common-env.d.cts
CHANGED
|
@@ -42,7 +42,7 @@ declare class StringBuilder implements IStringBuilder {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>;
|
|
45
|
-
declare function
|
|
45
|
+
declare function fetchHelperPost(url: string, body: any, config?: RequestInit): Promise<Response>;
|
|
46
46
|
declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
|
|
47
47
|
|
|
48
48
|
type MyFn<T extends Record<string, (...args: any[]) => any>> = {
|
|
@@ -74,4 +74,4 @@ declare function isRunningOnServer(): boolean;
|
|
|
74
74
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
75
75
|
declare function isNonEmptyString(str?: string): boolean;
|
|
76
76
|
|
|
77
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON,
|
|
77
|
+
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ declare class StringBuilder implements IStringBuilder {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>;
|
|
45
|
-
declare function
|
|
45
|
+
declare function fetchHelperPost(url: string, body: any, config?: RequestInit): Promise<Response>;
|
|
46
46
|
declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
|
|
47
47
|
|
|
48
48
|
type MyFn<T extends Record<string, (...args: any[]) => any>> = {
|
|
@@ -74,4 +74,4 @@ declare function isRunningOnServer(): boolean;
|
|
|
74
74
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
75
75
|
declare function isNonEmptyString(str?: string): boolean;
|
|
76
76
|
|
|
77
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON,
|
|
77
|
+
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.js
CHANGED
|
@@ -61,11 +61,15 @@ async function fetchHelperJSON(url, config) {
|
|
|
61
61
|
throwIfNotJSONResponse(res);
|
|
62
62
|
return await res.json();
|
|
63
63
|
}
|
|
64
|
-
async function
|
|
64
|
+
async function fetchHelperPost(url, body, config) {
|
|
65
|
+
const isObject = typeof body == "object";
|
|
65
66
|
config = config || {};
|
|
66
67
|
config.method = "POST";
|
|
67
|
-
config.body =
|
|
68
|
-
config.headers
|
|
68
|
+
config.body = isObject ? JSON.stringify(body) : body;
|
|
69
|
+
config.headers = config.headers || {};
|
|
70
|
+
if (isObject) {
|
|
71
|
+
config.headers["Content-Type"] = "application/json";
|
|
72
|
+
}
|
|
69
73
|
const res = await fetch(url, config);
|
|
70
74
|
if (!res.ok) {
|
|
71
75
|
const text = await res.text();
|
|
@@ -200,7 +204,7 @@ export {
|
|
|
200
204
|
catchInline,
|
|
201
205
|
doSafe,
|
|
202
206
|
fetchHelperJSON,
|
|
203
|
-
|
|
207
|
+
fetchHelperPost,
|
|
204
208
|
fetchHelperText,
|
|
205
209
|
isNonEmptyString,
|
|
206
210
|
isNumber,
|