UNPKG

@carbon/ibm-products-web-components

Version:
33 lines (31 loc) 964 B
/** * 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. */ //#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 export { getSupportedLocale }; //# sourceMappingURL=getSupportedLocale.js.map