UNPKG

@temboplus/frontend-core

Version:

A JavaScript/TypeScript package providing common utilities and logic shared across front-end TemboPlus projects.

37 lines (36 loc) 1.64 kB
import { type NumberType, type PhoneNumber as LibPhoneNumber } from "libphonenumber-js/max"; import { PhoneNumberFormat } from "./phone-number.types.js"; import { ISO2CountryCode } from "@models/country/country.types.js"; export interface ParsedPhoneNumber { libInstance: LibPhoneNumber; countryCode: ISO2CountryCode | undefined; compactNumber: string; e164Format: string; isValid: boolean; numberType: NumberType | undefined; } export declare class PhoneNumberService { private static instance; private constructor(); static getInstance(): PhoneNumberService; /** * Parses a phone number string using libphonenumber-js. * @param numberToParse The raw phone number string. * @param defaultCountry Optional default country code. * @returns A ParsedPhoneNumber object if successful, otherwise undefined. */ parse(numberToParse: string, defaultCountry?: ISO2CountryCode): ParsedPhoneNumber | undefined; /** * Validates a previously parsed LibPhoneNumber instance. * @param libInstance The LibPhoneNumber instance from libphonenumber-js. * @returns True if the number is considered valid by the library. */ isValid(libInstance: LibPhoneNumber | undefined): boolean; /** * Formats a previously parsed LibPhoneNumber instance. * @param libInstance The LibPhoneNumber instance from libphonenumber-js. * @param formatType Our local PhoneNumberFormat enum value. * @returns The formatted string, or the E.164 format as fallback. */ format(libInstance: LibPhoneNumber | undefined, formatType: PhoneNumberFormat): string; }