Skip to content

Commit 009d9c0

Browse files
committed
fix: corrects sanitization to accept the entire alphabet in alphanumeric CNPJ
1 parent 723192c commit 009d9c0

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

src/format-cnpj/format-cnpj.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@ import { sanitizeToDigits } from "../_internals/sanitize-to-digits/sanitize-to-d
44
export type FormatCnpjOptions = Pick<FormatParams, "pad"> & { version?: 1 | 2 };
55

66
const sanitize = (
7-
value: string | number,
8-
version?: FormatCnpjOptions["version"],
7+
value: string | number,
8+
version?: FormatCnpjOptions["version"],
99
) => {
10-
if (version === 2) {
11-
const allowedChars = "0123456789ABCDFGHIJKLMNPQRSVWXYZ";
12-
const enhancedValue = value.toString();
13-
14-
let result = "";
15-
16-
for (let i = 0; i < enhancedValue.length; i++) {
17-
if (allowedChars.includes(enhancedValue[i].toUpperCase())) {
18-
result += enhancedValue[i].toUpperCase();
19-
}
20-
}
21-
22-
return result;
23-
}
10+
if (version === 2) {
11+
const enhancedValue = value.toString();
12+
return enhancedValue.replace(/[^A-Za-z0-9]/g, '').toUpperCase();
13+
}
2414

25-
return sanitizeToDigits(value);
15+
return sanitizeToDigits(value);
2616
};
2717

2818
/**

0 commit comments

Comments
 (0)