@rg-dev/stdlib 1.0.29 → 1.0.31
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 +27 -0
- package/lib/common-env.d.cts +4 -1
- package/lib/common-env.d.ts +4 -1
- package/lib/common-env.js +27 -0
- package/package.json +1 -1
package/lib/common-env.cjs
CHANGED
|
@@ -23,6 +23,8 @@ __export(common_env_exports, {
|
|
|
23
23
|
StringBuilder: () => StringBuilder,
|
|
24
24
|
catchInline: () => catchInline,
|
|
25
25
|
doSafe: () => doSafe,
|
|
26
|
+
fetchHelperJSON: () => fetchHelperJSON,
|
|
27
|
+
fetchHelperText: () => fetchHelperText,
|
|
26
28
|
isNonEmptyString: () => isNonEmptyString,
|
|
27
29
|
isNumber: () => isNumber,
|
|
28
30
|
isRunningOnServer: () => isRunningOnServer,
|
|
@@ -86,6 +88,31 @@ var StringBuilder = class {
|
|
|
86
88
|
}
|
|
87
89
|
};
|
|
88
90
|
|
|
91
|
+
// src/fetchHelper.ts
|
|
92
|
+
async function fetchHelperJSON(url, config) {
|
|
93
|
+
const res = await fetch(url, config);
|
|
94
|
+
if (!res.ok) {
|
|
95
|
+
const text = await res.text();
|
|
96
|
+
throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
|
|
97
|
+
}
|
|
98
|
+
throwIfNotJSONResponse(res);
|
|
99
|
+
return await res.json();
|
|
100
|
+
}
|
|
101
|
+
async function fetchHelperText(url, config) {
|
|
102
|
+
const res = await fetch(url, config);
|
|
103
|
+
if (!res.ok) {
|
|
104
|
+
const text = await res.text();
|
|
105
|
+
throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
|
|
106
|
+
}
|
|
107
|
+
return await res.text();
|
|
108
|
+
}
|
|
109
|
+
function throwIfNotJSONResponse(res) {
|
|
110
|
+
const contentType = res.headers["content-type"] || "";
|
|
111
|
+
if (!(contentType == null ? void 0 : contentType.toLowerCase().includes("application/json"))) {
|
|
112
|
+
throw new Error(`Response is not JSON (content-type: ${contentType}, URL: ${res.url})`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
89
116
|
// src/common-env.ts
|
|
90
117
|
var Optional = class _Optional {
|
|
91
118
|
value;
|
package/lib/common-env.d.cts
CHANGED
|
@@ -41,6 +41,9 @@ declare class StringBuilder implements IStringBuilder {
|
|
|
41
41
|
toString(): string;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>;
|
|
45
|
+
declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
|
|
46
|
+
|
|
44
47
|
type MyFn<T extends Record<string, (...args: any[]) => any>> = {
|
|
45
48
|
[K in keyof T]: (...args: Parameters<T[K]>) => void;
|
|
46
49
|
};
|
|
@@ -70,4 +73,4 @@ declare function isRunningOnServer(): boolean;
|
|
|
70
73
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
71
74
|
declare function isNonEmptyString(str?: string): boolean;
|
|
72
75
|
|
|
73
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
76
|
+
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.d.ts
CHANGED
|
@@ -41,6 +41,9 @@ declare class StringBuilder implements IStringBuilder {
|
|
|
41
41
|
toString(): string;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>;
|
|
45
|
+
declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
|
|
46
|
+
|
|
44
47
|
type MyFn<T extends Record<string, (...args: any[]) => any>> = {
|
|
45
48
|
[K in keyof T]: (...args: Parameters<T[K]>) => void;
|
|
46
49
|
};
|
|
@@ -70,4 +73,4 @@ declare function isRunningOnServer(): boolean;
|
|
|
70
73
|
declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
|
|
71
74
|
declare function isNonEmptyString(str?: string): boolean;
|
|
72
75
|
|
|
73
|
-
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
|
76
|
+
export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
|
package/lib/common-env.js
CHANGED
|
@@ -51,6 +51,31 @@ var StringBuilder = class {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
// src/fetchHelper.ts
|
|
55
|
+
async function fetchHelperJSON(url, config) {
|
|
56
|
+
const res = await fetch(url, config);
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
const text = await res.text();
|
|
59
|
+
throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
|
|
60
|
+
}
|
|
61
|
+
throwIfNotJSONResponse(res);
|
|
62
|
+
return await res.json();
|
|
63
|
+
}
|
|
64
|
+
async function fetchHelperText(url, config) {
|
|
65
|
+
const res = await fetch(url, config);
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
const text = await res.text();
|
|
68
|
+
throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
|
|
69
|
+
}
|
|
70
|
+
return await res.text();
|
|
71
|
+
}
|
|
72
|
+
function throwIfNotJSONResponse(res) {
|
|
73
|
+
const contentType = res.headers["content-type"] || "";
|
|
74
|
+
if (!(contentType == null ? void 0 : contentType.toLowerCase().includes("application/json"))) {
|
|
75
|
+
throw new Error(`Response is not JSON (content-type: ${contentType}, URL: ${res.url})`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
54
79
|
// src/common-env.ts
|
|
55
80
|
var Optional = class _Optional {
|
|
56
81
|
value;
|
|
@@ -162,6 +187,8 @@ export {
|
|
|
162
187
|
StringBuilder,
|
|
163
188
|
catchInline,
|
|
164
189
|
doSafe,
|
|
190
|
+
fetchHelperJSON,
|
|
191
|
+
fetchHelperText,
|
|
165
192
|
isNonEmptyString,
|
|
166
193
|
isNumber,
|
|
167
194
|
isRunningOnServer,
|