31 lines
938 B
TypeScript
31 lines
938 B
TypeScript
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function validarCPFLocal(cpf: string): boolean {
|
|
if (!cpf) return false;
|
|
cpf = cpf.replace(/[^\d]+/g, "");
|
|
if (cpf.length !== 11) return false;
|
|
if (/^(\d)\1{10}$/.test(cpf)) return false;
|
|
|
|
let soma = 0,
|
|
resto = 0;
|
|
for (let index = 1; index <= 9; index++)
|
|
soma += parseInt(cpf.substring(index - 1, index)) * (11 - index);
|
|
resto = (soma * 10) % 11;
|
|
if (resto === 10 || resto === 11) resto = 0;
|
|
if (resto !== parseInt(cpf.substring(9, 10))) return false;
|
|
|
|
soma = 0;
|
|
for (let index = 1; index <= 10; index++)
|
|
soma += parseInt(cpf.substring(index - 1, index)) * (12 - index);
|
|
resto = (soma * 10) % 11;
|
|
if (resto === 10 || resto === 11) resto = 0;
|
|
if (resto !== parseInt(cpf.substring(10, 11))) return false;
|
|
|
|
return true;
|
|
}
|