@temboplus/frontend-core
Version:
A JavaScript/TypeScript package providing common utilities and logic shared across front-end TemboPlus projects.
53 lines (52 loc) • 3.06 kB
TypeScript
import { MNOInfo } from "./mno/mno.types.js";
import { PhoneNumberParseOptions, PhoneNumberContract } from "./phone-number.types.js";
/**
* Factory class for creating phone number objects that conform to PhoneNumberContract.
* It attempts to use country-specific implementations (like TZMobileNumber, KEMobileNumber)
* when available and appropriate, otherwise falls back to the generic PhoneNumber class.
*
* Also provides validation methods related to specific use cases like payouts.
*/
export declare class PhoneNumberFactory {
/**
* Creates an appropriate phone number instance (generic or country-specific)
* based on the input string and options.
*
* @param {string} numberToParse The raw phone number string.
* @param {PhoneNumberParseOptions} [options] Optional parsing options (e.g., defaultCountry).
* @returns {PhoneNumberContract | undefined} An instance conforming to PhoneNumberContract
* if the input is valid, otherwise undefined.
*/
static create(numberToParse: string, options?: PhoneNumberParseOptions): PhoneNumberContract | undefined;
/**
* Convenience method to check if an input string can be constructed into
* ANY valid phone number object via the factory.
* @param {string | null | undefined} input The raw phone number string.
* @param {PhoneNumberParseOptions} [options] Optional parsing options.
* @returns {boolean} True if a valid phone number object can be created.
*/
static canCreate(input: string | null | undefined, options?: PhoneNumberParseOptions): boolean;
/**
* Checks if a phone number (provided as a string or a PhoneNumberContract object)
* represents a valid number that can be successfully processed by the specific
* country implementation (TZMobileNumber or KEMobileNumber) required for payouts,
* and is of type MOBILE.
*
* @param input The raw phone number string OR an existing PhoneNumberContract object.
* @returns True if the number is valid for payout, false otherwise.
*/
static checkPayoutEligibility(input: string | PhoneNumberContract): boolean;
/**
* Retrieves the Mobile Network Operator (MNO) information for a given phone number.
* This function first checks if the number is eligible for payout (i.e., a valid
* mobile number in a supported country). If it is, and the country is Tanzania (TZ),
* it attempts to parse the number using the Tanzania-specific number class
* (`TZMobileNumber`) to extract operator details. For other supported countries
* or if the parsing fails for Tanzania, it returns undefined.
*
* @param {string | PhoneNumberContract} input The raw phone number string OR an existing PhoneNumberContract object.
* @returns {MNOInfo | undefined} An object containing MNO information if the number
* is a valid Tanzanian mobile number and the operator can be identified; otherwise, undefined.
*/
static getMNO(input: string | PhoneNumberContract): MNOInfo | undefined;
}