15 lines
512 B
JavaScript
15 lines
512 B
JavaScript
/**
|
|
* Converts a locale string from hyphen format (e.g., "en-US")
|
|
* to underscore format (e.g., "en_US").
|
|
*
|
|
* Useful for APIs or systems that expect locales with underscores.
|
|
*
|
|
* @param {string} locale - The locale string in BCP 47 format (e.g., "en-US").
|
|
* @returns {string} The normalized locale string using underscores (e.g., "en_US").
|
|
*
|
|
* @example
|
|
* normalizeLocaleUnderscore("en-US"); // "en_US"
|
|
*/
|
|
export const normalizeLocaleUnderscore = (locale) => {
|
|
return locale.split('-').join('_');
|
|
};
|