@type-ddd/cpf
Version:
This package provides TypeScript type definitions for handling CPF (Cadastro de Pessoa Física) in Domain-Driven Design contexts
71 lines (70 loc) • 2.41 kB
TypeScript
import { Result, ValueObject } from "rich-domain";
export declare class CPF extends ValueObject<string> {
protected static readonly REGEX: RegExp;
protected static readonly MESSAGE: string;
private constructor();
/**
* @description return a cpf value (only numbers).
* @example example "52734865211".
* @summary If you want cpf as pattern use `formatToCpfPattern` before get value.
*/
value(): string;
/**
* @description add hyphen and dot to cpf value.
* @example before "52734865211"
* @example after "527.348.652-11"
*/
toPattern(): string;
/**
* @description add hyphen and dot to cpf value.
* @example before "52734865211"
* @example after "527.348.652-11"
*/
static addMask(cpf: string): string;
/**
* @description remove hyphen and dot from cpf value.
* @example before "527.348.652-11"
* @example after "52734865211"
*/
static removeSpecialChars(cpf: string): string;
/**
*
* @param cpf value as string only number or pattern Or instance of CPF.
* @returns true if cpf match with instance value and false if not.
* @example param "52734865211"
* @example param "527.348.652-11"
*/
compare(cpf: string | CPF): boolean;
/**
* @description check if cpf value is a valid pattern and has a valid digit sum.
* @param value cpf as string
* @returns true if value is valid and false if not.
* @example "527.348.652-11"
* @example "72725477824"
*/
static isValidProps(value: string): boolean;
/**
* @description check if cpf value is a valid pattern and has a valid digit sum.
* @param value cpf as string
* @returns true if value is valid and false if not.
* @example "527.348.652-11"
* @example "72725477824"
*/
static isValid(value: string): boolean;
/**
*
* @param value value as string
* @returns instance of CPF or throw an error
*/
static init(value: string): CPF;
/**
* @description create a cpf value object
* @param value cpf numbers as string
* @returns instance of Result with cpf value
* @example "527.348.652-11"
* @example "72725477824"
* @summary fails if provide an invalid pattern or a cpf with invalid digit sum
*/
static create(value: string): Result<CPF | null>;
}
export default CPF;