@type-ddd/cnpj
Version:
Library that provides TypeScript type definitions for handling CNPJ (Cadastro Nacional da Pessoa Jurídica) in Domain-Driven Design contexts. It facilitates the validation and manipulation of CNPJ numbers, ensuring they adhere to the Brazilian legal standa
71 lines (70 loc) • 2.47 kB
TypeScript
import { Result, ValueObject } from 'rich-domain';
export declare class CNPJ extends ValueObject<string> {
protected static readonly REGEX: RegExp;
protected static readonly MESSAGE: string;
private constructor();
/**
* @description return a cnpj value (only numbers).
* @example example "22398345000188".
* @summary If you want cnpj as pattern use `formatToCnpjPattern` before get value.
*/
value(): string;
/**
* @description add hyphen and dot to cnpj value.
* @example before "22398345000188"
* @example after "22.398.345/0001-88"
*/
toPattern(): string;
/**
* @description add hyphen and dot to cnpj value.
* @example before "22398345000188"
* @example after "22.398.345/0001-88"
*/
static addMask(cnpj: string): string;
/**
* @description remove hyphen and dot from cnpj value.
* @example before "22.398.345/0001-88"
* @example after "22398345000188"
*/
static removeSpecialChars(cnpj: string): string;
/**
*
* @param cnpj value as string only number or pattern.
* @returns true if cnpj match with instance value and false if not.
* @example param "22398345000188"
* @example param "22.398.345/0001-88"
*/
compare(cnpj: string | CNPJ): boolean;
/**
* @description check if cnpj value is a valid pattern and has a valid digit sum.
* @param value cnpj as string
* @returns true if value is valid and false if not.
* @example "22.398.345/0001-88"
* @example "22398345000188"
*/
static isValidProps(value: string): boolean;
/**
* @description check if cnpj value is a valid pattern and has a valid digit sum.
* @param value cnpj as string
* @returns true if value is valid and false if not.
* @example "22.398.345/0001-88"
* @example "22398345000188"
*/
static isValid(value: string): boolean;
/**
*
* @param value value as string
* @returns instance of CNPJ or throw an error
*/
static init(value: string): CNPJ;
/**
* @description create a cnpj value object
* @param value cnpj numbers as string
* @returns instance of Result with cnpj value
* @example "22.398.345/0001-88"
* @example "22398345000188"
* @summary fails if provide an invalid pattern or a cnpj with invalid digit sum
*/
static create(value: string): Result<CNPJ | null>;
}
export default CNPJ;