UNPKG

@ledgerhq/live-common

Version:
22 lines 834 B
"use strict"; /** * Locale utility functions for parsing and extracting information from BCP 47 locale strings. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getCountryCodeFromLocale = getCountryCodeFromLocale; /** * Extracts the ISO 3166-1 alpha-2 country code from a BCP 47 locale string. * * @param locale - A BCP 47 locale string (e.g., "fr-FR", "en-US", "de-DE") * @returns The lowercase country code (e.g., "fr", "us", "de") or undefined if not present * * @example * getCountryCodeFromLocale("fr-FR") // "fr" * getCountryCodeFromLocale("en-US") // "us" * getCountryCodeFromLocale("en") // undefined */ function getCountryCodeFromLocale(locale) { const parts = locale.split("-"); return parts.length > 1 ? parts[1].toLowerCase() : undefined; } //# sourceMappingURL=index.js.map