h7-validate-cnpj
Version:
A TypeScript library to validate Brazilian CNPJ. It ensures valid structure, verifies check digits, and handles known invalid patterns.
37 lines (36 loc) • 1.16 kB
TypeScript
/**
* @author
* @see https://github.com/herlandio
*
* Class to validate Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica).
*/
export declare class CNPJValidator {
private readonly cnpj;
/**
* Constructor to initialize the CNPJ value.
* @param cnpj - The CNPJ string to validate.
*/
constructor(cnpj: string);
/**
* Validates the CNPJ.
* @returns `true` if the CNPJ is valid; otherwise, `false`.
*/
isValid(): boolean;
/**
* Checks if the CNPJ has the correct length of 14 digits.
* @returns `true` if the length is valid; otherwise, `false`.
*/
private isValidLength;
/**
* Checks if the CNPJ matches known invalid patterns, such as repeated sequences.
* @returns `true` if the CNPJ is invalid; otherwise, `false`.
*/
private isKnownInvalid;
/**
* Calculates a single check digit for a CNPJ based on the provided weights.
* @param base - The numeric base string to validate against.
* @param weights - The weights used in the calculation.
* @returns The calculated check digit as a string.
*/
private calculateCheckDigit;
}