MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getRegion

Function getRegion

packages/@internationalized/date/src/queries.ts:268–290  ·  view source on GitHub ↗
(locale: string)

Source from the content-addressed store, hash-verified

266const cachedWeekInfo = new Map<string, {firstDay: number}>();
267
268function getRegion(locale: string): string | undefined {
269 // If the Intl.Locale API is available, use it to get the region for the locale.
270 // @ts-ignore
271 if (Intl.Locale) {
272 // Constructing an Intl.Locale is expensive, so cache the result.
273 let region = cachedRegions.get(locale);
274 if (!region) {
275 // @ts-ignore
276 region = new Intl.Locale(locale).maximize().region;
277 if (region) {
278 cachedRegions.set(locale, region);
279 }
280 }
281 return region;
282 }
283
284 // If not, just try splitting the string.
285 // If the second part of the locale string is 'u',
286 // then this is a unicode extension, so ignore it.
287 // Otherwise, it should be the region.
288 let part = locale.split('-')[1];
289 return part === 'u' ? undefined : part;
290}
291
292function getWeekStart(locale: string): number {
293 // TODO: use Intl.Locale for this once browsers support the weekInfo property

Callers 2

getWeekStartFunction · 0.85
isWeekendFunction · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected