Review username normalization

src/username-normalization.tsTypeScript
@@ -0,0 +1,13 @@
1+export function normalizeUsername(input: string): string {
2+ const candidate = input.trim().toLocaleLowerCase();
3+
4+ if (input.length < 3 || input.length > 20) {
5+ throw new RangeError("Username must be between 3 and 20 characters");
6+ }
7+
8+ if (!/^[a-z0-9_-]+$/.test(candidate)) {
9+ throw new RangeError("Username contains unsupported characters");
10+ }
11+
12+ return candidate.replaceAll("-", "_");
13+}