feat: add region handling for currency and locale formatting, including comprehensive tests
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import type { BillingType, PaymentDto, WeekDay } from '@gruperly/shared'
|
||||
|
||||
import { countryOf, currencyForRegion, localeForRegion } from './region'
|
||||
|
||||
export const WEEK_DAY_FULL_LABELS: Record<WeekDay, string> = {
|
||||
MONDAY: 'Lunes',
|
||||
TUESDAY: 'Martes',
|
||||
@@ -49,70 +51,163 @@ export function formatSchedule(days: readonly WeekDay[], time: string | null): s
|
||||
return time ? `${dayNames.join(', ')} · ${time}` : dayNames.join(', ')
|
||||
}
|
||||
|
||||
/* Moneda por defecto de la app (Argentina). Solo define cómo se pinta: el
|
||||
valor persistido no cambia. La firma acepta la moneda para que el paso a
|
||||
multi-moneda no obligue a tocar los call sites. */
|
||||
export const DEFAULT_CURRENCY = 'ARS'
|
||||
/* Un importe se escribe con el país de la persona: su moneda y su regional
|
||||
(separadores, posición del símbolo), sin conversión — el importe lo fija
|
||||
quien creó el grupo y no se toca. El país sale de la zona horaria del
|
||||
sistema y, si no se conoce, del idioma del browser (ver countryOf). Sin
|
||||
país conocido se pinta con el símbolo $ genérico, nunca con un código
|
||||
inventado. La firma acepta moneda y locale para forzarlas (tests, print)
|
||||
sin tocar los call sites. */
|
||||
|
||||
export function formatPrice(price: number | null, currency: string = DEFAULT_CURRENCY): string {
|
||||
/* La configuración regional del browser manda en cómo se pintan los datos.
|
||||
Se lee en cada llamada (es un accessor barato) para que un cambio de idioma
|
||||
del sistema se refleje sin recargar; lo caro es construir el formatter, así
|
||||
que esos se memorizan por locale/moneda. */
|
||||
type BrowserNavigator = { language?: string; languages?: readonly string[] }
|
||||
|
||||
function browserLocale(): string | undefined {
|
||||
const nav = (globalThis as { navigator?: BrowserNavigator }).navigator
|
||||
return nav?.language || nav?.languages?.[0] || undefined
|
||||
}
|
||||
|
||||
const priceFormatters = new Map<string, Intl.NumberFormat>()
|
||||
|
||||
export function formatPrice(
|
||||
price: number | null,
|
||||
currency?: string,
|
||||
locale?: string,
|
||||
): string {
|
||||
if (price == null) return '—'
|
||||
// Importes enteros sin decimales ($50.000); con centavos se respetan.
|
||||
const hasCents = !Number.isInteger(price)
|
||||
return new Intl.NumberFormat('es-AR', {
|
||||
style: 'currency',
|
||||
currency,
|
||||
minimumFractionDigits: hasCents ? 2 : 0,
|
||||
maximumFractionDigits: 2,
|
||||
})
|
||||
.format(price)
|
||||
// es-AR separa el símbolo con un espacio duro (U+00A0): preferimos "$50.000".
|
||||
.replace(/\u00A0/g, '')
|
||||
const browser = locale ?? browserLocale()
|
||||
const country = countryOf(browser)
|
||||
const resolvedCurrency = currency ?? currencyForRegion(country)
|
||||
// Los separadores y la posición del símbolo siguen al país: un browser en
|
||||
// inglés en Argentina tiene que ver $50.000, no ARS 50,000. Con la locale
|
||||
// pasada explícita no se toca nada (tests, print).
|
||||
const resolved = locale === undefined ? (localeForRegion(country) ?? browser) : browser
|
||||
const key = `${resolved ?? ''}|${resolvedCurrency ?? '$'}|${hasCents ? 'c' : 'i'}`
|
||||
|
||||
let formatter = priceFormatters.get(key)
|
||||
if (!formatter) {
|
||||
formatter = new Intl.NumberFormat(resolved, {
|
||||
style: 'currency',
|
||||
currency: resolvedCurrency ?? 'USD',
|
||||
currencyDisplay: resolvedCurrency ? 'symbol' : 'narrowSymbol',
|
||||
minimumFractionDigits: hasCents ? 2 : 0,
|
||||
maximumFractionDigits: 2,
|
||||
})
|
||||
priceFormatters.set(key, formatter)
|
||||
}
|
||||
return tidyCurrencySpacing(formatter.format(price))
|
||||
}
|
||||
|
||||
/* Presentación de teléfonos (Argentina). Nunca altera el valor persistido:
|
||||
es maquillaje de salida, y los links wa.me siguen usando los dígitos crudos.
|
||||
/* Intl separa el símbolo de la moneda con un espacio duro: "$ 50.000" se lee
|
||||
como dos tokens sueltos. Lo quitamos solo cuando separa símbolo de número;
|
||||
entre dígitos y código ("50.000 ARS") el no-break space evita el corte. */
|
||||
const SYMBOL_GAP = /([^\p{L}\p{N}])\u00A0/gu
|
||||
|
||||
Estrategia: se normalizan los prefijos conocidos (0054 / 54 / 0 nacional y
|
||||
el 9 de móvil argentino). Si el resultado no parece un número plausible
|
||||
(6 a 10 dígitos nacionales) se devuelve el valor original tal cual: es
|
||||
preferible un número sin maquillar a uno inventado. */
|
||||
export function formatPhoneDisplay(value: string | null | undefined): string | null {
|
||||
function tidyCurrencySpacing(value: string): string {
|
||||
return value.replace(SYMBOL_GAP, '$1')
|
||||
}
|
||||
|
||||
/* ── Teléfonos ──────────────────────────────────────────────────────────────
|
||||
|
||||
Presentación, nunca persistencia: los links wa.me siguen usando los dígitos
|
||||
crudos. El formato sale de la región del propio número cuando su prefijo de
|
||||
país es reconocible; si el número es nacional, manda la región del browser
|
||||
(y si esa región no la conocemos, la de la app: AR). Si nada encaja se cae
|
||||
a E.164 (+331234567890) o al valor original, siempre preferible a un número
|
||||
inventado. */
|
||||
|
||||
type PhoneRegion = 'AR' | 'US' | 'ES' | 'MX'
|
||||
|
||||
/** Prefijos de país que sabemos agrupar. */
|
||||
const COUNTRY_CALLING_CODES: { region: PhoneRegion; code: string }[] = [
|
||||
{ region: 'AR', code: '54' },
|
||||
{ region: 'ES', code: '34' },
|
||||
{ region: 'MX', code: '52' },
|
||||
{ region: 'US', code: '1' },
|
||||
]
|
||||
|
||||
export function formatPhoneDisplay(
|
||||
value: string | null | undefined,
|
||||
locale?: string,
|
||||
): string | null {
|
||||
if (value == null) return null
|
||||
const raw = value.trim()
|
||||
if (!raw) return null
|
||||
|
||||
const hasPlus = raw.startsWith('+')
|
||||
let digits = raw.replace(/\D/g, '')
|
||||
// "0054…" es el mismo indicio internacional que "+54…".
|
||||
const hasDoubleZero = !hasPlus && raw.startsWith('00')
|
||||
if (hasDoubleZero) digits = digits.slice(2)
|
||||
if (digits.length < 6) return raw
|
||||
|
||||
let isAr = false
|
||||
const withCallingCode = formatWithCallingCode(digits)
|
||||
if (withCallingCode) return withCallingCode
|
||||
if (hasPlus || hasDoubleZero) return `+${digits}`
|
||||
|
||||
return formatNational(digits, appRegion(countryOf(locale ?? browserLocale())), false) ?? raw
|
||||
}
|
||||
|
||||
/** Prueba el prefijo de país solo si lo que sigue encaja en sus reglas. */
|
||||
function formatWithCallingCode(digits: string): string | null {
|
||||
for (const { region, code } of COUNTRY_CALLING_CODES) {
|
||||
if (!digits.startsWith(code)) continue
|
||||
const formatted = formatNational(digits.slice(code.length), region, true)
|
||||
if (formatted) return formatted
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** Región ISO → región con reglas propias. CA comparte NANP con US. */
|
||||
function appRegion(region: string | undefined): PhoneRegion {
|
||||
if (region === 'US' || region === 'CA') return 'US'
|
||||
if (region === 'ES') return 'ES'
|
||||
if (region === 'MX') return 'MX'
|
||||
// Sin región reconocible seguimos siendo una app de Argentina.
|
||||
return 'AR'
|
||||
}
|
||||
|
||||
function formatNational(
|
||||
digits: string,
|
||||
region: PhoneRegion,
|
||||
hasCallingCode: boolean,
|
||||
): string | null {
|
||||
switch (region) {
|
||||
case 'AR':
|
||||
return formatArNational(digits, hasCallingCode)
|
||||
case 'US':
|
||||
return formatUsNational(digits)
|
||||
case 'ES':
|
||||
return formatEsNational(digits, hasCallingCode)
|
||||
case 'MX':
|
||||
return formatMxNational(digits, hasCallingCode)
|
||||
}
|
||||
}
|
||||
|
||||
function formatArNational(digits: string, withCountry: boolean): string | null {
|
||||
let national = digits
|
||||
let isMobile = false
|
||||
|
||||
if (digits.startsWith('0054')) {
|
||||
digits = digits.slice(4)
|
||||
isAr = true
|
||||
} else if (digits.startsWith('54') && digits.length >= 12) {
|
||||
digits = digits.slice(2)
|
||||
isAr = true
|
||||
}
|
||||
|
||||
// Móvil argentino: 9 + 10 dígitos nacionales.
|
||||
if (digits.length === 11 && digits.startsWith('9')) {
|
||||
digits = digits.slice(1)
|
||||
if (national.length === 11 && national.startsWith('9')) {
|
||||
national = national.slice(1)
|
||||
isMobile = true
|
||||
isAr = true
|
||||
}
|
||||
|
||||
// 0 de trunk nacional (0 + 10 dígitos; o 0 + 9 tras el 9 de móvil).
|
||||
if (digits.startsWith('0') && digits.length >= 9) {
|
||||
digits = digits.slice(1)
|
||||
isAr = true
|
||||
// 0 de trunk nacional: además implica que el número es argentino.
|
||||
if (national.startsWith('0') && national.length >= 9) {
|
||||
national = national.slice(1)
|
||||
withCountry = true
|
||||
}
|
||||
if (national.length < 6 || national.length > 10) return null
|
||||
|
||||
if (digits.length < 6 || digits.length > 10) return raw
|
||||
|
||||
const local = groupArNational(digits)
|
||||
if (!isAr) return local
|
||||
return isMobile ? `+54 9 ${local}` : `+54 ${local}`
|
||||
const local = groupArNational(national)
|
||||
const body = isMobile ? `9 ${local}` : local
|
||||
return withCountry ? `+54 ${body}` : body
|
||||
}
|
||||
|
||||
function groupArNational(digits: string): string {
|
||||
@@ -128,6 +223,29 @@ function groupArNational(digits: string): string {
|
||||
return digits
|
||||
}
|
||||
|
||||
/** NANP (US/CA): 10 dígitos con área e intercambio que arrancan en 2–9. */
|
||||
function formatUsNational(digits: string): string | null {
|
||||
if (digits.length === 11 && digits.startsWith('1')) digits = digits.slice(1)
|
||||
if (digits.length !== 10) return null
|
||||
if (digits[0] === '0' || digits[0] === '1' || digits[3] === '0' || digits[3] === '1') return null
|
||||
// Convención doméstica: el "1" del país no se escribe.
|
||||
return `(${digits.slice(0, 3)}) ${digits.slice(3, 6)}-${digits.slice(6)}`
|
||||
}
|
||||
|
||||
/** España: 9 dígitos (móvil 6/7, fijo 8/9) agrupados 3-2-2-2. */
|
||||
function formatEsNational(digits: string, withCountry: boolean): string | null {
|
||||
if (digits.length !== 9 || !'6789'.includes(digits[0])) return null
|
||||
const local = `${digits.slice(0, 3)} ${digits.slice(3, 5)} ${digits.slice(5, 7)} ${digits.slice(7)}`
|
||||
return withCountry ? `+34 ${local}` : local
|
||||
}
|
||||
|
||||
/** México: 10 dígitos agrupados 2-4-4. */
|
||||
function formatMxNational(digits: string, withCountry: boolean): string | null {
|
||||
if (digits.length !== 10 || digits[0] === '0' || digits[0] === '1') return null
|
||||
const local = `${digits.slice(0, 2)} ${digits.slice(2, 6)} ${digits.slice(6)}`
|
||||
return withCountry ? `+52 ${local}` : local
|
||||
}
|
||||
|
||||
// El vencimiento se cuenta como frase ("Vence el día 10 de cada mes") en vez
|
||||
// de "Vence día 10": se lee como una promesa, no como un dato suelto.
|
||||
export function formatBillingMeta(
|
||||
@@ -139,4 +257,4 @@ export function formatBillingMeta(
|
||||
return dueDay ? `Vence el día ${dueDay} de cada mes` : BILLING_LABELS.MONTHLY
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
271
apps/web/src/lib/region.ts
Normal file
271
apps/web/src/lib/region.ts
Normal file
@@ -0,0 +1,271 @@
|
||||
/* De dónde es la persona y cómo se le escriben los números.
|
||||
|
||||
El idioma del browser dice en qué idioma se está, no en qué país se está:
|
||||
con "en-US" a alguien en Argentina lo trata como estadounidense, y con
|
||||
"es-419" no dice ningún país. La zona horaria —que sí expone el sistema—
|
||||
es la señal del país real; el idioma solo define cuando la zona no se
|
||||
conoce. Con el país resuelto salen la moneda (REGION_CURRENCY) y la
|
||||
regional con la que se formatea (REGION_LOCALE), para que un browser en
|
||||
inglés en Argentina vea $50.000 y no ARS 50,000.
|
||||
|
||||
Estos mapas son dato a mano (Intl no expone región → moneda ni región →
|
||||
locale). Solo definen cómo se PINTA un importe: el valor persistido no
|
||||
cambia ni se convierte. Si el país no está en ninguno, formatPrice cae al
|
||||
símbolo $ genérico. */
|
||||
|
||||
export const REGION_CURRENCY: Record<string, string> = {
|
||||
// Norteamérica
|
||||
CA: 'CAD',
|
||||
US: 'USD',
|
||||
|
||||
// Latinoamérica y Caribe
|
||||
AR: 'ARS',
|
||||
BO: 'BOB',
|
||||
BR: 'BRL',
|
||||
CL: 'CLP',
|
||||
CO: 'COP',
|
||||
CR: 'CRC',
|
||||
CU: 'CUP',
|
||||
DO: 'DOP',
|
||||
EC: 'USD',
|
||||
GT: 'GTQ',
|
||||
HN: 'HNL',
|
||||
MX: 'MXN',
|
||||
NI: 'NIO',
|
||||
PA: 'USD',
|
||||
PE: 'PEN',
|
||||
PR: 'USD',
|
||||
PY: 'PYG',
|
||||
SV: 'USD',
|
||||
UY: 'UYU',
|
||||
VE: 'VES',
|
||||
|
||||
// Zona euro
|
||||
AT: 'EUR',
|
||||
BE: 'EUR',
|
||||
HR: 'EUR',
|
||||
CY: 'EUR',
|
||||
EE: 'EUR',
|
||||
FI: 'EUR',
|
||||
FR: 'EUR',
|
||||
DE: 'EUR',
|
||||
GR: 'EUR',
|
||||
IE: 'EUR',
|
||||
IT: 'EUR',
|
||||
LV: 'EUR',
|
||||
LT: 'EUR',
|
||||
LU: 'EUR',
|
||||
MT: 'EUR',
|
||||
NL: 'EUR',
|
||||
PT: 'EUR',
|
||||
SK: 'EUR',
|
||||
SI: 'EUR',
|
||||
ES: 'EUR',
|
||||
|
||||
// Fuera de la zona euro
|
||||
CH: 'CHF',
|
||||
GB: 'GBP',
|
||||
CZ: 'CZK',
|
||||
DK: 'DKK',
|
||||
NO: 'NOK',
|
||||
PL: 'PLN',
|
||||
RU: 'RUB',
|
||||
SE: 'SEK',
|
||||
TR: 'TRY',
|
||||
UA: 'UAH',
|
||||
}
|
||||
|
||||
/** Regional con la que se formatea para cada país. México y Argentina usan
|
||||
separadores distintos (1,234.56 vs 1.234,56), así que el locale va con el
|
||||
país y no solo con el idioma. */
|
||||
export const REGION_LOCALE: Record<string, string> = {
|
||||
// Norteamérica
|
||||
CA: 'en-CA',
|
||||
US: 'en-US',
|
||||
|
||||
// Latinoamérica y Caribe
|
||||
AR: 'es-AR',
|
||||
BO: 'es-BO',
|
||||
BR: 'pt-BR',
|
||||
CL: 'es-CL',
|
||||
CO: 'es-CO',
|
||||
CR: 'es-CR',
|
||||
CU: 'es-CU',
|
||||
DO: 'es-DO',
|
||||
EC: 'es-EC',
|
||||
GT: 'es-GT',
|
||||
HN: 'es-HN',
|
||||
MX: 'es-MX',
|
||||
NI: 'es-NI',
|
||||
PA: 'es-PA',
|
||||
PE: 'es-PE',
|
||||
PR: 'es-PR',
|
||||
PY: 'es-PY',
|
||||
SV: 'es-SV',
|
||||
UY: 'es-UY',
|
||||
VE: 'es-VE',
|
||||
|
||||
// Zona euro
|
||||
AT: 'de-AT',
|
||||
BE: 'nl-BE',
|
||||
HR: 'hr-HR',
|
||||
CY: 'el-CY',
|
||||
EE: 'et-EE',
|
||||
FI: 'fi-FI',
|
||||
FR: 'fr-FR',
|
||||
DE: 'de-DE',
|
||||
GR: 'el-GR',
|
||||
IE: 'en-IE',
|
||||
IT: 'it-IT',
|
||||
LV: 'lv-LV',
|
||||
LT: 'lt-LT',
|
||||
LU: 'fr-LU',
|
||||
MT: 'mt-MT',
|
||||
NL: 'nl-NL',
|
||||
PT: 'pt-PT',
|
||||
SK: 'sk-SK',
|
||||
SI: 'sl-SI',
|
||||
ES: 'es-ES',
|
||||
|
||||
// Fuera de la zona euro
|
||||
CH: 'de-CH',
|
||||
GB: 'en-GB',
|
||||
CZ: 'cs-CZ',
|
||||
DK: 'da-DK',
|
||||
NO: 'nb-NO',
|
||||
PL: 'pl-PL',
|
||||
RU: 'ru-RU',
|
||||
SE: 'sv-SE',
|
||||
TR: 'tr-TR',
|
||||
UA: 'uk-UA',
|
||||
}
|
||||
|
||||
/* Zona horaria IANA → región ISO 3166-1 alpha-2.
|
||||
|
||||
Cobertura: las zonas de los países de arriba, agrupadas por prefijo
|
||||
(America/Argentina/*) o por la ciudad en la zona (Sao_Paulo). Cubre las
|
||||
zonas principales; una zona desconocida cae al país del idioma. */
|
||||
export const TIMEZONE_REGION: Record<string, string> = {
|
||||
// ── Latinoamérica ─────────────────────────────────────────────────────────
|
||||
'America/Argentina/': 'AR',
|
||||
// Chromium/ICU reporta en la forma legacy (sin el prefijo "Argentina/") las
|
||||
// zonas argentinas más comunes: America/Argentina/Buenos_Aires → America/Buenos_Aires.
|
||||
'America/Buenos_Aires': 'AR',
|
||||
'America/Catamarca': 'AR',
|
||||
'America/Cordoba': 'AR',
|
||||
'America/Jujuy': 'AR',
|
||||
'America/Mendoza': 'AR',
|
||||
'America/La_Paz': 'BO',
|
||||
'America/Sao_Paulo': 'BR',
|
||||
'America/Fortaleza': 'BR',
|
||||
'America/Recife': 'BR',
|
||||
'America/Bahia': 'BR',
|
||||
'America/Manaus': 'BR',
|
||||
'America/Cuiaba': 'BR',
|
||||
'America/Porto_Velho': 'BR',
|
||||
'America/Noronha': 'BR',
|
||||
'America/Campo_Grande': 'BR',
|
||||
'America/Santiago': 'CL',
|
||||
'America/Bogota': 'CO',
|
||||
'America/Lima': 'PE',
|
||||
'America/Asuncion': 'PY',
|
||||
'America/Montevideo': 'UY',
|
||||
'America/Caracas': 'VE',
|
||||
'America/Guayaquil': 'EC',
|
||||
'America/Panama': 'PA',
|
||||
'America/Managua': 'NI',
|
||||
'America/Tegucigalpa': 'HN',
|
||||
'America/El_Salvador': 'SV',
|
||||
'America/Guatemala': 'GT',
|
||||
'America/Costa_Rica': 'CR',
|
||||
'America/Havana': 'CU',
|
||||
'America/Santo_Domingo': 'DO',
|
||||
'America/Puerto_Rico': 'PR',
|
||||
|
||||
// ── Norteamérica ─────────────────────────────────────────────────────────
|
||||
'America/New_York': 'US',
|
||||
'America/Detroit': 'US',
|
||||
'America/Chicago': 'US',
|
||||
'America/Denver': 'US',
|
||||
'America/Phoenix': 'US',
|
||||
'America/Los_Angeles': 'US',
|
||||
'America/Anchorage': 'US',
|
||||
'Pacific/Honolulu': 'US',
|
||||
'America/Toronto': 'CA',
|
||||
'America/Vancouver': 'CA',
|
||||
'America/Winnipeg': 'CA',
|
||||
'America/Edmonton': 'CA',
|
||||
'America/Halifax': 'CA',
|
||||
'America/Regina': 'CA',
|
||||
'America/St_Johns': 'CA',
|
||||
|
||||
// ── Europa ───────────────────────────────────────────────────────────────
|
||||
'Europe/Madrid': 'ES',
|
||||
'Atlantic/Canary': 'ES',
|
||||
'Atlantic/Faeroe': 'ES',
|
||||
'Europe/Lisbon': 'PT',
|
||||
'Europe/Rome': 'IT',
|
||||
'Europe/Paris': 'FR',
|
||||
'Europe/Berlin': 'DE',
|
||||
'Europe/Vienna': 'AT',
|
||||
'Europe/Brussels': 'BE',
|
||||
'Europe/Amsterdam': 'NL',
|
||||
'Europe/Dublin': 'IE',
|
||||
'Europe/Zurich': 'CH',
|
||||
'Europe/London': 'GB',
|
||||
'Europe/Copenhagen': 'DK',
|
||||
'Europe/Oslo': 'NO',
|
||||
'Europe/Stockholm': 'SE',
|
||||
'Europe/Warsaw': 'PL',
|
||||
'Europe/Prague': 'CZ',
|
||||
'Europe/Helsinki': 'FI',
|
||||
'Europe/Athens': 'GR',
|
||||
'Europe/Kyiv': 'UA',
|
||||
'Europe/Kiev': 'UA',
|
||||
'Europe/Moscow': 'RU',
|
||||
'Europe/Istanbul': 'TR',
|
||||
}
|
||||
|
||||
const ZONE_PREFIXES = Object.keys(TIMEZONE_REGION).filter((zone) => zone.endsWith('/'))
|
||||
|
||||
export function browserTimezone(): string | undefined {
|
||||
try {
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export function regionForTimezone(timezone: string | undefined): string | undefined {
|
||||
if (!timezone) return undefined
|
||||
const exact = TIMEZONE_REGION[timezone]
|
||||
if (exact) return exact
|
||||
const prefix = ZONE_PREFIXES.find((zone) => timezone.startsWith(zone))
|
||||
return prefix ? TIMEZONE_REGION[prefix] : undefined
|
||||
}
|
||||
|
||||
/** Región del locale (es-MX → MX). Un locale sin país se maximiza, pero solo
|
||||
como último recurso: countryOf prefiere la zona horaria. */
|
||||
export function regionOf(locale: string | undefined): string | undefined {
|
||||
if (!locale || typeof Intl.Locale === 'undefined') return undefined
|
||||
try {
|
||||
return new Intl.Locale(locale).maximize().region
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** País de la persona: el de la zona horaria, y si no se conoce, el del
|
||||
idioma. `en` sin país no se maximiza a US a propósito: un usuario en
|
||||
México con el browser en inglés caería en dólares. */
|
||||
export function countryOf(locale: string | undefined): string | undefined {
|
||||
return regionForTimezone(browserTimezone()) ?? regionOf(locale)
|
||||
}
|
||||
|
||||
export function currencyForRegion(region: string | undefined): string | undefined {
|
||||
return region ? REGION_CURRENCY[region] : undefined
|
||||
}
|
||||
|
||||
export function localeForRegion(region: string | undefined): string | undefined {
|
||||
return region ? REGION_LOCALE[region] : undefined
|
||||
}
|
||||
Reference in New Issue
Block a user