From e6fcda735eca9e4b200ca473f589ef4da8dd6e79 Mon Sep 17 00:00:00 2001 From: Natan Lucena Date: Thu, 6 Feb 2025 15:26:49 -0300 Subject: [PATCH 1/2] :sparkles: feat: add Brazilian tax ID masking functions --- src/core/masks/brazilian-masks.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/core/masks/brazilian-masks.ts diff --git a/src/core/masks/brazilian-masks.ts b/src/core/masks/brazilian-masks.ts new file mode 100644 index 0000000..0457b8a --- /dev/null +++ b/src/core/masks/brazilian-masks.ts @@ -0,0 +1,25 @@ +export function numberMask(value: string): string { + return value.replace(/\D/g, ""); +} + +export function cpfTaxIdMask(value: string): string { + return value + .replace(/(\d{3})(\d)/, "$1.$2") + .replace(/(\d{3})(\d)/, "$1.$2") + .replace(/(\d{3})(\d{1,2})$/, "$1-$2"); +} + +export function cnpjTaxIdMask(value: string): string { + return value + .replace(/(\d{2})(\d)/, "$1.$2") + .replace(/(\d{3})(\d)/, "$1.$2") + .replace(/(\d{3})(\d)/, "$1/$2") + .replace(/(\d{4})(\d{1,2})$/, "$1-$2"); +} + +export function taxIdMask(value: string): string { + const valueWithoutSpecialCharacters = numberMask(value); + return valueWithoutSpecialCharacters.length > 11 + ? cnpjTaxIdMask(valueWithoutSpecialCharacters) + : cpfTaxIdMask(valueWithoutSpecialCharacters); +} From 588cf8a05998025d17de5fd61ae3ac825efd0e83 Mon Sep 17 00:00:00 2001 From: Natan Lucena Date: Thu, 6 Feb 2025 15:40:32 -0300 Subject: [PATCH 2/2] :recycle: refactor: remove local dependency on wave-tech-framework --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 8ff31b4..7659fdf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2656,4 +2656,4 @@ } } } -} +} \ No newline at end of file