/** * Progressive as-you-type phone number formatter for the libphonenumber polyfill. */ import type { VegaCountryCode } from '../../types/flag.type'; /** * Format a possibly-incomplete phone number for display. * * Internally uses AsYouType to produce correct progressive formatting. * * @param {string} number - the raw phone number string to format * @param {VegaCountryCode} [country] - optional default country code * @returns {string} the formatted incomplete phone number * @example formatIncompletePhoneNumber('3023334444', 'US') // '(302) 333-4444' * @example formatIncompletePhoneNumber('+13023334444') // '+1 302 333 4444' */ export declare function formatIncompletePhoneNumber(number: string, country?: VegaCountryCode): string; /** * Progressive phone number formatter. * * Internally uses template-based formatting matching libphonenumber-js. */ export declare class AsYouType { private _country; private _allDigits; private _hasPlus; private _callingCode; private _nationalNumber; private _matchingFormats; private _chosenFormat; private _populatedTemplate; private _populatedPosition; /** * Stores a complex prefix (e.g. national prefix captured groups) that was * stripped from the national number. This prefix is re-prepended when * producing output. Mirrors `complexPrefixBeforeNationalSignificantNumber` * in the original library. */ private _complexPrefix; constructor(defaultCountry?: VegaCountryCode); /** * The currently detected country. * * @returns {VegaCountryCode | undefined} the detected country code or undefined */ get country(): VegaCountryCode | undefined; /** * Feed characters into the formatter. Returns the formatted number so far. * * The original library processes one digit at a time, running narrow-down * and format logic after each digit. This is critical because formats may * be eliminated at intermediate digit counts, triggering national-prefix * re-extraction that changes the output structure. We replicate that * behavior here by looping over each digit individually. * * @param {string} text - the raw input characters to process * @returns {string} the formatted phone number so far */ input(text: string): string; /** * Update internal state after a new digit is added. * Detects calling code and country for international numbers, * or keeps the full digit string as the national number in national mode. * * @returns {void} */ private updateState; /** * Initialize the list of candidate format rules for a given country. * Filters out formats that alter the number or do not suit the current mode. * * @param {VegaCountryCode} country - the country whose formats to load * @returns {void} */ private initFormats; /** * Narrow down matching formats based on the leading digits of the national number. * Removes formats that no longer match and resets the chosen format if it was eliminated. * * @returns {void} */ private narrowDownFormats; /** * Attempt to format the national number after a new digit is added. * Tries complete formatting first, then template-based, then chooses a new format. * * @param {string} newDigits - the newly added digit characters * @returns {string | undefined} the formatted national number or undefined if no format applies */ private formatDigit; /** * Try to format the national number as a complete number using the matching format rules. * Only attempts formatting when the number length is a possible length for the country. * * @returns {string | undefined} the formatted number if a complete match is found, or undefined */ private tryFormatComplete; /** * Choose a new format from the remaining candidates and apply it to the national number. * Builds a template for each candidate and returns the formatted result on first match. * * @returns {string | undefined} the formatted national number or undefined if no format matches */ private chooseFormatAndApply; /** * Insert digits into the current populated template one at a time. * Replaces placeholder characters with the actual digits. * * @param {string} digits - the digit characters to insert into the template * @returns {string | undefined} the partially formatted string or undefined if the template is exhausted */ private formatNextDigits; /** * Fill an entire template string with the given digits. * Used to synchronize the template state after a complete format match. * * @param {string} template - the format template containing digit placeholders * @param {string} digits - the digit characters to populate the template with * @returns {PopulatedTemplateResult | undefined} the filled template and last position, or undefined if the template ran out of placeholders */ private populateTemplateFull; /** * Reset the chosen format, populated template, and position to their initial values. * * @returns {void} */ private resetFormat; /** * Try to extract a national prefix from the current national number. * Uses the country's `nationalPrefixForParsing` pattern (metadata index [7]). * * Called proactively on every digit input, mirroring the original library's * `reExtractNationalSignificantNumber`. When extraction first succeeds * (or the extracted prefix changes), formats are re-initialized so that * only formats appropriate for the shorter national number remain. * * @returns {void} */ private tryReExtractNationalPrefix; /** * Build the full output string by prepending the calling code or complex prefix * to the formatted national number. * * @param {string} formattedNational - the formatted national number portion * @returns {string} the complete formatted phone number with prefix */ private getFullOutput; /** * Produce a fallback output when no format template matches. * Returns the raw digits with the plus sign or complex prefix if applicable. * * @returns {string} the non-formatted output string */ private getNonFormattedOutput; }