Canonicalize setting values

Write codeMedium13 min

Your task

A dotfiles cleaner canonicalizes raw setting values. Input lines are "key=value"; split at the first "=", trim key and value, later duplicates win. Then rewrite each value by the FIRST rule that applies: (1) if it equals "true" or "false" ignoring case, use the lowercase word; (2) if it is an optional "-" followed only by digits (at least one), remove leading zeros, keep a single "0", and "-0", "-000" become "0"; (3) if it starts and ends with a double quote and is at least 2 characters, drop just those two quotes, keeping the inside verbatim; (4) otherwise keep it unchanged. Return the dict of rewritten values.

Examples

normalize_values(lines: list[str]) -> dict[str,str]
Example 1
Inputnormalize_values(["debug=TRUE", "port=0080", "name=\"my app\""])
Output{"debug": "true", "port": "80", "name": "my app"}