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