mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-19 15:34:59 +03:00
17 lines
417 B
JavaScript
17 lines
417 B
JavaScript
import { match } from '@formatjs/intl-localematcher';
|
|
import mem from 'mem';
|
|
|
|
function _localeMatch(...args) {
|
|
// Wrap in try/catch because localeMatcher throws on invalid locales
|
|
try {
|
|
return match(...args);
|
|
} catch (e) {
|
|
const defaultLocale = args[2];
|
|
return defaultLocale || false;
|
|
}
|
|
}
|
|
const localeMatch = mem(_localeMatch, {
|
|
cacheKey: (args) => args.join(),
|
|
});
|
|
|
|
export default localeMatch;
|