formatToPhone utility formats a phone number string according to the country mask defined in
@arkyn/templates.ts
import { formatToPhone } from "@arkyn/shared";
libphonenumber-js to determine the country and national
number, then applies the corresponding country's mask (where _ is used as a digit placeholder) replacing
placeholders with actual digits.findCountryMask to pick the appropriate mask for the parsed number and returns a formatted
string ready for display in UI components or logs.phoneNumber (required): The phone number to format. Can include the country calling code
(e.g. +5511999999999) or be provided in a national format parsable by libphonenumber-js.string_ placeholders in the chosen mask are
replaced by digits from the parsed national number.stringError in cases such as:findCountryMask).ts
import { formatToPhone } from "@arkyn/shared";console.log(formatToPhone("+5534920524282")); // => "(34) 92052-4282"console.log(formatToPhone("+553420524282")); // => "(34) 2052-4282"console.log(formatToPhone("+12125550199")); // => "(212) 555-0199"
parsePhoneNumberWithError from libphonenumber-js to obtain the country iso and
national number.findCountryMask to inspect which mask will be applied for a given input before formatting.findCountryMask (utility that selects the mask): src/docs/shared/utilities/find-country-mask.mdlibphonenumber-js — parsing and validation library used for phone number analysis