mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-01 03:13:22 +00:00
12 lines
361 B
JavaScript
12 lines
361 B
JavaScript
export function readPositiveIntEnv(name, fallback, env = process.env) {
|
|
const text = String(env[name] ?? fallback).trim();
|
|
if (!/^\d+$/u.test(text)) {
|
|
throw new Error(`invalid ${name}: ${text}`);
|
|
}
|
|
const value = Number(text);
|
|
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
throw new Error(`invalid ${name}: ${text}`);
|
|
}
|
|
return value;
|
|
}
|