//#region src/format-phone/format-phone.d.ts /** The masks `formatPhone` can apply. */ export type PhoneMask = "auto" | "e164" | "international" | "service" | "sn" | "nanp"; /** Options of `formatPhone`. */ export type FormatPhoneOptions = { /** Which mask to apply, or `"auto"` to pick one from the value (default: `"sn"`). */ mask?: PhoneMask; }; /** * Formats a phone number according to Brazilian phone number patterns. * * `options.mask` accepts: * - `"sn"` (default): Brazilian subscriber number only, e.g. `"98765-4321"` (9 digits, no DDD). * With a DDD present in `value`, `"sn"` **truncates** it, e.g. `formatPhone("11987654321")` * (with `mask` omitted) returns `"11987-6543"`, silently dropping the last digit, because * only the first 9 digits are used and the DDD's 2 digits are consumed as if they were part * of the subscriber number. * - `"nanp"`: DDD + subscriber number, `"(00) 00000-0000"` for the 11 digits of a mobile and * `"(00) 0000-0000"` for the 10 digits of a landline. Any other length keeps the 11 digit * grouping, so a value still being typed reads as a partial mobile. * - `"auto"`: picks a mask from `value`. A leading Brazilian country code (`+55`, `0055` or a * bare `55` followed by 10 or 11 digits) selects `"international"`; a service number selects * `"service"`; otherwise the digit count decides, `"nanp"` when `value` has more digits than * a bare subscriber number (9) and `"sn"` when it does not. * - `"e164"`: the ITU-T E.164 form, `"+5511987654321"`, no separators. * - `"international"`: the way a Brazilian number is printed for foreign callers, * `"+55 11 98765-4321"` (or `"+55 11 3000-0000"` for a landline). * - `"service"`: service numbers, `"0800 123 4567"` for the Códigos Não Geográficos (`0300`, * `0303`, `0500`, `0800`, `0900`) and `"4004-1234"` for the abbreviated `300X`/`400X` ones. * Anatel specifies no display format for either, so these are the conventional groupings. * * `"e164"` and `"international"` drop the country code from `value` first, under the rule * documented in `parsePhone`. A service number has no E.164 form, it is not reachable from * abroad, so both international masks fall back to the `"service"` presentation for it, which * is how such numbers are printed in Brazil. The service-number check itself reads `value` * under the same rule, so `"5508001234567"` is the `0800` number, not a `+55 08` one. * * If `value` includes a DDD (area code), pass `{ mask: "auto" }` (or `"nanp"`) explicitly, * do not rely on the default, since the default `"sn"` mask assumes no DDD is present. A `mask` * outside the union falls back to the default `"sn"` instead of throwing. * * @param {string|number} value - The phone number to format, either as a string or a number. * @param {FormatPhoneOptions} [options] - Optional formatting options. * @param {"auto"|"sn"|"nanp"|"e164"|"international"|"service"} options.mask - The mask to apply for formatting the phone number (default: `"sn"`). * @returns {string} The formatted phone number as a string. * * @example * ```typescript * formatPhone("987654321"); // "98765-4321" (default "sn", no DDD) * formatPhone("11987654321", { mask: "auto" }); // "(11) 98765-4321" * formatPhone("1130000000", { mask: "auto" }); // "(11) 3000-0000" (10 digit landline) * formatPhone("5511987654321", { mask: "auto" }); // "+55 11 98765-4321" * formatPhone("08001234567", { mask: "auto" }); // "0800 123 4567" * formatPhone("5508001234567", { mask: "auto" }); // "0800 123 4567" * formatPhone("11987654321", { mask: "e164" }); // "+5511987654321" * formatPhone("11987654321", { mask: "international" }); // "+55 11 98765-4321" * formatPhone("40041234", { mask: "service" }); // "4004-1234" * formatPhone("11987654321"); // "11987-6543" (BEWARE: default "sn" truncates a DDD-prefixed number) * ``` * * @see Official: https://www.itu.int/rec/T-REC-E.164 * @see Official: https://informacoes.anatel.gov.br/legislacao/resolucoes/2022/1641-resolucao-749 */ export declare const formatPhone: (value: string | number, options?: FormatPhoneOptions) => string; //#endregion