mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-25 08:52:12 +00:00
21 lines
664 B
TypeScript
21 lines
664 B
TypeScript
import fs from "node:fs";
|
|
|
|
export function loadPatternListFile(filePath: string, label: string): string[] {
|
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8")) as unknown;
|
|
if (!Array.isArray(parsed)) {
|
|
throw new TypeError(`${label} must point to a JSON array: ${filePath}`);
|
|
}
|
|
return parsed.filter((value): value is string => typeof value === "string" && value.length > 0);
|
|
}
|
|
|
|
export function loadPatternListFromEnv(
|
|
envKey: string,
|
|
env: Record<string, string | undefined> = process.env,
|
|
): string[] | null {
|
|
const filePath = env[envKey]?.trim();
|
|
if (!filePath) {
|
|
return null;
|
|
}
|
|
return loadPatternListFile(filePath, envKey);
|
|
}
|