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.04 kB
import { Result, ValueObject } from 'rich-domain'; import { ddd } from './ddd.list'; /** * @description Brazilian Mobile Phone Number * @default (XX) 9XXXX-XXXX */ declare class MobilePhone extends ValueObject<string> { protected static readonly REGEX: RegExp; protected static readonly MESSAGE: string; private constructor(); toPattern(): string; /** * * @param value Phone number (XX) 9XXXX-XXXX * @returns true if pattern match and false if not. */ static isValidProps(value: string): boolean; static isValid(value: string): boolean; isMobile(): boolean; isHome(): boolean; /** * @returns value XX9XXXXXXXX as string */ value(): string; /** * * @returns only numbers without special chars. Includes 0 and DDD. * @example 01199502301 */ 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 MobilePhone or throw an error */ static init(value: string): MobilePhone; /** * * @param value Brazilian Mobile phone number * @example (XX) 9XXXX-XXXX * @returns Result of MobilePhoneValueObject */ static create(value: string): Result<MobilePhone | null>; } export { MobilePhone }; export default MobilePhone;