mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-05 22:03:36 +00:00
25 lines
816 B
TypeScript
25 lines
816 B
TypeScript
/** Parses daemon runtime command output into normalized key-value maps. */
|
|
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
|
|
|
|
/** Parses command output key-value lines using a caller-supplied separator. */
|
|
export function parseKeyValueOutput(output: string, separator: string): Record<string, string> {
|
|
const entries: Record<string, string> = {};
|
|
for (const rawLine of output.split(/\r?\n/)) {
|
|
const line = rawLine.trim();
|
|
if (!line) {
|
|
continue;
|
|
}
|
|
const idx = line.indexOf(separator);
|
|
if (idx <= 0) {
|
|
continue;
|
|
}
|
|
const key = normalizeLowercaseStringOrEmpty(line.slice(0, idx));
|
|
if (!key) {
|
|
continue;
|
|
}
|
|
const value = line.slice(idx + separator.length).trim();
|
|
entries[key] = value;
|
|
}
|
|
return entries;
|
|
}
|