@rg-dev/stdlib 1.0.32 → 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 +17 -0
- package/lib/common-env.d.cts +2 -1
- package/lib/common-env.d.ts +2 -1
- package/lib/common-env.js +17 -0
- package/package.json +1 -1
package/lib/common-env.cjs
CHANGED
|
@@ -24,6 +24,7 @@ __export(common_env_exports, {
|
|
|
24
24
|
catchInline: () => catchInline,
|
|
25
25
|
doSafe: () => doSafe,
|
|
26
26
|
fetchHelperJSON: () => fetchHelperJSON,
|
|
27
|
+
fetchHelperPost: () => fetchHelperPost,
|
|
27
28
|
fetchHelperText: () => fetchHelperText,
|
|
28
29
|
isNonEmptyString: () => isNonEmptyString,
|
|
29
30
|
isNumber: () => isNumber,
|
|
@@ -98,6 +99,22 @@ async function fetchHelperJSON(url, config) {
|
|
|
98
99
|
throwIfNotJSONResponse(res);
|
|
99
100
|
return await res.json();
|
|
100
101
|
}
|
|
102
|
+
async function fetchHelperPost(url, body, config) {
|
|
103
|
+
const isObject = typeof body == "object";
|
|
104
|
+
config = config || {};
|
|
105
|
+
config.method = "POST";
|
|
106
|
+
config.body = isObject ? JSON.stringify(body) : body;
|
|
107
|
+
config.headers = config.headers || {};
|
|
108
|
+
if (isObject) {
|
|
109
|
+
config.headers["Content-Type"] = "application/json";
|
|
110
|
+
}
|
|
111
|
+
const res = await fetch(url, config);
|
|
112
|
+
if (!res.ok) {
|
|
113
|
+
const text = await res.text();
|
|
114
|
+
throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
|
|
115
|
+
}
|
|
116
|
+
return res;
|
|
117
|
+
}
|
|
101
118
|
async function fetchHelperText(url, config) {
|
|
102
119
|
const res = await fetch(url, config);
|
|
103
120
|
if (!res.ok) {
|
package/lib/common-env.d.cts
CHANGED
|
@@ -42,6 +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 fetchHelperPost(url: string, body: any, config?: RequestInit): Promise<Response>;
|
|
45
46
|
declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
|
|
46
47
|
|
|
47
48
|
type MyFn<T extends Record<string, (...args: any[]) => any>> = {
|
|
@@ -73,4 +74,4 @@ declare function isRunningOnServer(): boolean;
|
|
|
73
74
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
74
75
|
declare function isNonEmptyString(str?: string): boolean;
|
|
75
76
|
|
|
76
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
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,6 +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 fetchHelperPost(url: string, body: any, config?: RequestInit): Promise<Response>;
|
|
45
46
|
declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
|
|
46
47
|
|
|
47
48
|
type MyFn<T extends Record<string, (...args: any[]) => any>> = {
|
|
@@ -73,4 +74,4 @@ declare function isRunningOnServer(): boolean;
|
|
|
73
74
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
74
75
|
declare function isNonEmptyString(str?: string): boolean;
|
|
75
76
|
|
|
76
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
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,6 +61,22 @@ async function fetchHelperJSON(url, config) {
|
|
|
61
61
|
throwIfNotJSONResponse(res);
|
|
62
62
|
return await res.json();
|
|
63
63
|
}
|
|
64
|
+
async function fetchHelperPost(url, body, config) {
|
|
65
|
+
const isObject = typeof body == "object";
|
|
66
|
+
config = config || {};
|
|
67
|
+
config.method = "POST";
|
|
68
|
+
config.body = isObject ? JSON.stringify(body) : body;
|
|
69
|
+
config.headers = config.headers || {};
|
|
70
|
+
if (isObject) {
|
|
71
|
+
config.headers["Content-Type"] = "application/json";
|
|
72
|
+
}
|
|
73
|
+
const res = await fetch(url, config);
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const text = await res.text();
|
|
76
|
+
throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
|
|
77
|
+
}
|
|
78
|
+
return res;
|
|
79
|
+
}
|
|
64
80
|
async function fetchHelperText(url, config) {
|
|
65
81
|
const res = await fetch(url, config);
|
|
66
82
|
if (!res.ok) {
|
|
@@ -188,6 +204,7 @@ export {
|
|
|
188
204
|
catchInline,
|
|
189
205
|
doSafe,
|
|
190
206
|
fetchHelperJSON,
|
|
207
|
+
fetchHelperPost,
|
|
191
208
|
fetchHelperText,
|
|
192
209
|
isNonEmptyString,
|
|
193
210
|
isNumber,
|