Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
1.1 KiB
Text
31 lines
1.1 KiB
Text
import { UNICODE_EXTENSION_SEQUENCE_REGEX, findBestMatch } from './utils';
|
|
/**
|
|
* https://tc39.es/ecma402/#sec-bestfitmatcher
|
|
* @param availableLocales
|
|
* @param requestedLocales
|
|
* @param getDefaultLocale
|
|
*/
|
|
export function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) {
|
|
var foundLocale;
|
|
var extension;
|
|
var noExtensionLocales = [];
|
|
var noExtensionLocaleMap = requestedLocales.reduce(function (all, l) {
|
|
var noExtensionLocale = l.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, '');
|
|
noExtensionLocales.push(noExtensionLocale);
|
|
all[noExtensionLocale] = l;
|
|
return all;
|
|
}, {});
|
|
var result = findBestMatch(noExtensionLocales, availableLocales);
|
|
if (result.matchedSupportedLocale && result.matchedDesiredLocale) {
|
|
foundLocale = result.matchedSupportedLocale;
|
|
extension =
|
|
noExtensionLocaleMap[result.matchedDesiredLocale].slice(result.matchedDesiredLocale.length) || undefined;
|
|
}
|
|
if (!foundLocale) {
|
|
return { locale: getDefaultLocale() };
|
|
}
|
|
return {
|
|
locale: foundLocale,
|
|
extension: extension,
|
|
};
|
|
}
|