UNPKG

@type-ddd/phone

Version:

Library that provides TypeScript type definitions for handling Phone Numbers in Domain-Driven Design contexts. It facilitates the validation and manipulation of Brazilian phone numbers.

63 lines (62 loc) 2.02 kB
import { Result, ValueObject } from 'rich-domain'; import { ddd } from './ddd.list'; /** * @description Brazilian Home Phone Number * @default (XX) XXXX-XXXX */ declare class HomePhone extends ValueObject<string> { protected static readonly REGEX: RegExp; protected static readonly MESSAGE: string; private constructor(); toPattern(): string; isMobile(): boolean; isHome(): boolean; static isValid(value: string): boolean; /** * * @param value Phone number (XX) XXXX-XXXX * @returns true if pattern match and false if not. */ static isValidProps(value: string): boolean; /** * @returns value XXXXXXXXXX as string */ value(): string; /** * * @returns only numbers without special chars. Includes 0 and DDD. * @example 01122502301 */ toCall(): string; number(): string; /** * * @returns only area code (DDD) as number * @example 11 */ code(): ddd; /** * * @returns only area code (DDD) as number * @example 11 */ static code(phone: string): ddd; uf(): "Distrito Federal" | "Goiás" | "Mato Grosso" | "Mato Grosso do Sul" | "Alagoas" | "Bahia" | "Ceará" | "Maranhão" | "Paraíba" | "Pernambuco" | "Piauí" | "Rio Grande do Norte" | "Acre" | "Amapá" | "Amazonas" | "Pará" | "Rondônia" | "Roraima" | "Tocantins" | "Paraná" | "Rio Grande do Sul" | "Santa Catarina" | "Espírito Santo" | "Minas Gerais" | "Rio de Janeiro" | "São Paulo"; static removeSpecialChars(cell: string): string; static addMask(cell: string): string; /** * * @param value value as string * @returns instance of HomePhone or throw an error */ static init(value: string): HomePhone; /** * * @param value Brazilian home phone number * @example (XX) XXXX-XXXX * @returns Result of HomePhoneValueObject */ static create(value: string): Result<HomePhone | null>; } export { HomePhone }; export default HomePhone;