diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 1b33162..77189ba 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,19 +1,15 @@ /** - * Formats a CPF string with masking (123.***.789-10) + * Formats a CPF string (might include masking) and masks it for display. * @param cpf - A CPF string (11 digits without punctuation) * @returns Formatted CPF with masking or the original input if invalid */ export function maskCpf(cpf: string): string { - // Clean input, keeping only digits - const cleanCpf = cpf.replace(/\D/g, ''); - // Validate if it's 11 digits - if (cleanCpf.length !== 11) { + if (cpf.length !== 11) { return cpf; } - - // Format with mask: 123.***.789-10 - return `${cleanCpf.slice(0, 3)}.***.${cleanCpf.slice(6, 9)}-${cleanCpf.slice(9)}`; + // Mask with standard punctuation: 123.456.789-10 + return `${cpf.slice(0, 3)}.${cpf.slice(3, 6)}.${cpf.slice(6, 9)}-${cpf.slice(9)}`; } /**