@carbon/ibm-products-web-components
Version:
Carbon for IBM Products Web Components
34 lines (32 loc) • 1.05 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/globals/js/utils/getSupportedLocale.ts
/**
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Ensures the requested `locale` is valid, else returns the default locale.
*
* Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#locales
*/
const getSupportedLocale = (locale, defaultLocale = "en-US") => {
let supportedLocale;
try {
Intl.NumberFormat.supportedLocalesOf(locale);
supportedLocale = locale;
} catch (error) {
supportedLocale = defaultLocale;
}
return supportedLocale;
};
//#endregion
exports.getSupportedLocale = getSupportedLocale;
//# sourceMappingURL=getSupportedLocale.js.map