(raw: string)
| 30 | * comments, and lines without a key are dropped; an empty value is kept |
| 31 | * (declaring a variable as empty is meaningful to a subprocess). */ |
| 32 | export function parseStdioEnv(raw: string): Record<string, string> { |
| 33 | const env: Record<string, string> = {}; |
| 34 | for (const line of raw.split("\n")) { |
| 35 | const trimmed = line.trim(); |
| 36 | if (trimmed === "" || trimmed.startsWith("#")) continue; |
| 37 | const separator = trimmed.indexOf("="); |
| 38 | if (separator <= 0) continue; |
| 39 | const key = trimmed.slice(0, separator).trim(); |
| 40 | if (key === "") continue; |
| 41 | env[key] = trimmed.slice(separator + 1).trim(); |
| 42 | } |
| 43 | return env; |
| 44 | } |
| 45 | |
| 46 | /** Render the stored env map back into the KEY=value block. */ |
| 47 | export function formatStdioEnv(env: Readonly<Record<string, string>> | undefined): string { |
no outgoing calls
no test coverage detected