From c347d5ce24460f002328cf151486713e96d20820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Henrique?= Date: Thu, 19 Jun 2025 19:55:35 -0300 Subject: [PATCH] cpf masking --- src/utils/utils.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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)}`; } /**