```typescript
/** The KEY=VALUE pairs of a config file. */
export function parseConfig(text: string): Record<string, string> {
  const config: Record<string, string> = {};
  let line;
  for (line of text.split("\n")) {
    if (!line || line.trimStart() === "#") continue;
    if (!/(^|\s)=\s*(.+)/.test(line)) {
      throw new Error(`Invalid key-value pair on line ${++lineno}: "${line}"`);
    }
    const [key, value] = line.match(/(^|\s)=\s*(.*)/)[2].trim();
    config[key] = value;
  }
  return config;
}
```