@gajae-code/utils 0.12.5 → 0.12.6
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/dist/types/env.d.ts +1 -1
- package/package.json +2 -2
- package/src/env.ts +12 -10
- package/src/fetch-retry.ts +1 -0
package/dist/types/env.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare function $credentialEnv(name: string): string | undefined;
|
|
|
31
31
|
export declare function $pickCredentialEnv(...keys: string[]): string | undefined;
|
|
32
32
|
/**
|
|
33
33
|
* Parses a positive decimal integer from `$env[name]`.
|
|
34
|
-
* Empty, invalid,
|
|
34
|
+
* Empty, invalid, unsafe, zero, or negative values return `defaultValue`.
|
|
35
35
|
*/
|
|
36
36
|
export declare function $envpos(name: string, defaultValue: number): number;
|
|
37
37
|
/** True when `BUN_ENV` or `NODE_ENV` is the string `test`. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@gajae-code/utils",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.6",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://gajae-code.com",
|
|
7
7
|
"author": "Yeachan-Heo",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"fmt": "biome format --write ."
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@gajae-code/natives": "0.12.
|
|
34
|
+
"@gajae-code/natives": "0.12.6",
|
|
35
35
|
"beautiful-mermaid": "^1.1.3",
|
|
36
36
|
"handlebars": "^4.7.9",
|
|
37
37
|
"winston": "^3.19.0",
|
package/src/env.ts
CHANGED
|
@@ -147,16 +147,20 @@ export function $pickCredentialEnv(...keys: string[]): string | undefined {
|
|
|
147
147
|
return undefined;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
function parsePositiveInteger(raw: string | undefined): number | undefined {
|
|
151
|
+
const value = raw?.trim();
|
|
152
|
+
if (!value || !/^\d+$/.test(value)) return undefined;
|
|
153
|
+
const parsed = Number(value);
|
|
154
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
150
157
|
/**
|
|
151
158
|
* Parses a positive decimal integer from `$env[name]`.
|
|
152
|
-
* Empty, invalid,
|
|
159
|
+
* Empty, invalid, unsafe, zero, or negative values return `defaultValue`.
|
|
153
160
|
*/
|
|
154
161
|
export function $envpos(name: string, defaultValue: number): number {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const parsed = Number.parseInt(raw, 10);
|
|
158
|
-
if (Number.isNaN(parsed) || parsed <= 0) return defaultValue;
|
|
159
|
-
return parsed;
|
|
162
|
+
const parsed = parsePositiveInteger($env[name]);
|
|
163
|
+
return parsed ?? defaultValue;
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
/** True when `BUN_ENV` or `NODE_ENV` is the string `test`. */
|
|
@@ -200,10 +204,8 @@ export function $pickflag(...keys: string[]): boolean {
|
|
|
200
204
|
/** Resolve the first positive integer among keys, else defaultValue (GJC-first). Set-but-invalid keys are skipped. */
|
|
201
205
|
export function $pickenvpos(keys: string[], defaultValue: number): number {
|
|
202
206
|
for (const key of keys) {
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
const parsed = Number.parseInt(raw, 10);
|
|
206
|
-
if (!Number.isNaN(parsed) && parsed > 0) return parsed;
|
|
207
|
+
const parsed = parsePositiveInteger($env[key]);
|
|
208
|
+
if (parsed !== undefined) return parsed;
|
|
207
209
|
}
|
|
208
210
|
return defaultValue;
|
|
209
211
|
}
|
package/src/fetch-retry.ts
CHANGED
|
@@ -153,6 +153,7 @@ export async function fetchWithRetry(
|
|
|
153
153
|
if (hint !== undefined && hint > maxDelayMs) return response;
|
|
154
154
|
|
|
155
155
|
const delayMs = Math.min(hint ?? resolveDefaultDelay(defaultDelayMs, attempt, maxDelayMs), maxDelayMs);
|
|
156
|
+
void response.body?.cancel().catch(() => undefined);
|
|
156
157
|
await scheduler.wait(delayMs, { signal });
|
|
157
158
|
}
|
|
158
159
|
}
|