(locale: string)
| 266 | const cachedWeekInfo = new Map<string, {firstDay: number}>(); |
| 267 | |
| 268 | function 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 | |
| 292 | function getWeekStart(locale: string): number { |
| 293 | // TODO: use Intl.Locale for this once browsers support the weekInfo property |
no test coverage detected