07fd7bce64
* Import of Intl.Locale from #39664 * Handle updating es2020.intl and add es2021 for new DateTimeFormatOptions options - re: #39664 * Extends DateTimeFormatOptions for new Intl APIs - re: #45420 * Handle migrating Intl.NumberFormat.formatToParts to es2018 (keeping esnext.intl around) * Adds Intl.DisplayNames to es2020 - re: #44022 * Remove attributes added in es2021 from es2020 - re: #42944 * Add a reference to es2021 in the command line parser * Adds some docs about the lib files * Baselines * Allow undefined in Intl inputs to allow for ergonomic usage of exactOptionalPropertyTypes - see #45652 * Adds some tests covering the APIs * Apply suggestions from code review Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> * Handle PR feedback * More review improvements Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
210 lines
11 KiB
Plaintext
210 lines
11 KiB
Plaintext
=== tests/cases/conformance/es2020/es2020IntlAPIs.ts ===
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation
|
|
const count = 26254.39;
|
|
>count : 26254.39
|
|
>26254.39 : 26254.39
|
|
|
|
const date = new Date("2012-05-24");
|
|
>date : Date
|
|
>new Date("2012-05-24") : Date
|
|
>Date : DateConstructor
|
|
>"2012-05-24" : "2012-05-24"
|
|
|
|
function log(locale: string) {
|
|
>log : (locale: string) => void
|
|
>locale : string
|
|
|
|
console.log(
|
|
>console.log( `${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` ) : void
|
|
>console.log : (...data: any[]) => void
|
|
>console : Console
|
|
>log : (...data: any[]) => void
|
|
|
|
`${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}`
|
|
>`${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` : string
|
|
>new Intl.DateTimeFormat(locale).format(date) : string
|
|
>new Intl.DateTimeFormat(locale).format : (date?: number | Date) => string
|
|
>new Intl.DateTimeFormat(locale) : Intl.DateTimeFormat
|
|
>Intl.DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; }
|
|
>Intl : typeof Intl
|
|
>DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; }
|
|
>locale : string
|
|
>format : (date?: number | Date) => string
|
|
>date : Date
|
|
>new Intl.NumberFormat(locale).format(count) : string
|
|
>new Intl.NumberFormat(locale).format : { (value: number): string; (value: number | bigint): string; }
|
|
>new Intl.NumberFormat(locale) : Intl.NumberFormat
|
|
>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
|
|
>Intl : typeof Intl
|
|
>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; }
|
|
>locale : string
|
|
>format : { (value: number): string; (value: number | bigint): string; }
|
|
>count : 26254.39
|
|
|
|
);
|
|
}
|
|
|
|
log("en-US");
|
|
>log("en-US") : void
|
|
>log : (locale: string) => void
|
|
>"en-US" : "en-US"
|
|
|
|
// expected output: 5/24/2012 26,254.39
|
|
|
|
log("de-DE");
|
|
>log("de-DE") : void
|
|
>log : (locale: string) => void
|
|
>"de-DE" : "de-DE"
|
|
|
|
// expected output: 24.5.2012 26.254,39
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat
|
|
const rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' });
|
|
>rtf1 : Intl.RelativeTimeFormat
|
|
>new Intl.RelativeTimeFormat('en', { style: 'narrow' }) : Intl.RelativeTimeFormat
|
|
>Intl.RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; }
|
|
>Intl : typeof Intl
|
|
>RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; }
|
|
>'en' : "en"
|
|
>{ style: 'narrow' } : { style: "narrow"; }
|
|
>style : "narrow"
|
|
>'narrow' : "narrow"
|
|
|
|
console.log(rtf1.format(3, 'quarter'));
|
|
>console.log(rtf1.format(3, 'quarter')) : void
|
|
>console.log : (...data: any[]) => void
|
|
>console : Console
|
|
>log : (...data: any[]) => void
|
|
>rtf1.format(3, 'quarter') : string
|
|
>rtf1.format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string
|
|
>rtf1 : Intl.RelativeTimeFormat
|
|
>format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string
|
|
>3 : 3
|
|
>'quarter' : "quarter"
|
|
|
|
//expected output: "in 3 qtrs."
|
|
|
|
console.log(rtf1.format(-1, 'day'));
|
|
>console.log(rtf1.format(-1, 'day')) : void
|
|
>console.log : (...data: any[]) => void
|
|
>console : Console
|
|
>log : (...data: any[]) => void
|
|
>rtf1.format(-1, 'day') : string
|
|
>rtf1.format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string
|
|
>rtf1 : Intl.RelativeTimeFormat
|
|
>format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string
|
|
>-1 : -1
|
|
>1 : 1
|
|
>'day' : "day"
|
|
|
|
//expected output: "1 day ago"
|
|
|
|
const rtf2 = new Intl.RelativeTimeFormat('es', { numeric: 'auto' });
|
|
>rtf2 : Intl.RelativeTimeFormat
|
|
>new Intl.RelativeTimeFormat('es', { numeric: 'auto' }) : Intl.RelativeTimeFormat
|
|
>Intl.RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; }
|
|
>Intl : typeof Intl
|
|
>RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; }
|
|
>'es' : "es"
|
|
>{ numeric: 'auto' } : { numeric: "auto"; }
|
|
>numeric : "auto"
|
|
>'auto' : "auto"
|
|
|
|
console.log(rtf2.format(2, 'day'));
|
|
>console.log(rtf2.format(2, 'day')) : void
|
|
>console.log : (...data: any[]) => void
|
|
>console : Console
|
|
>log : (...data: any[]) => void
|
|
>rtf2.format(2, 'day') : string
|
|
>rtf2.format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string
|
|
>rtf2 : Intl.RelativeTimeFormat
|
|
>format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string
|
|
>2 : 2
|
|
>'day' : "day"
|
|
|
|
//expected output: "pasado mañana"
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames
|
|
const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' });
|
|
>regionNamesInEnglish : Intl.DisplayNames
|
|
>new Intl.DisplayNames(['en'], { type: 'region' }) : Intl.DisplayNames
|
|
>Intl.DisplayNames : { new (locales?: string | string[], options?: Partial<Intl.DisplayNamesOptions>): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; }
|
|
>Intl : typeof Intl
|
|
>DisplayNames : { new (locales?: string | string[], options?: Partial<Intl.DisplayNamesOptions>): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; }
|
|
>['en'] : string[]
|
|
>'en' : "en"
|
|
>{ type: 'region' } : { type: "region"; }
|
|
>type : "region"
|
|
>'region' : "region"
|
|
|
|
const regionNamesInTraditionalChinese = new Intl.DisplayNames(['zh-Hant'], { type: 'region' });
|
|
>regionNamesInTraditionalChinese : Intl.DisplayNames
|
|
>new Intl.DisplayNames(['zh-Hant'], { type: 'region' }) : Intl.DisplayNames
|
|
>Intl.DisplayNames : { new (locales?: string | string[], options?: Partial<Intl.DisplayNamesOptions>): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; }
|
|
>Intl : typeof Intl
|
|
>DisplayNames : { new (locales?: string | string[], options?: Partial<Intl.DisplayNamesOptions>): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; }
|
|
>['zh-Hant'] : string[]
|
|
>'zh-Hant' : "zh-Hant"
|
|
>{ type: 'region' } : { type: "region"; }
|
|
>type : "region"
|
|
>'region' : "region"
|
|
|
|
console.log(regionNamesInEnglish.of('US'));
|
|
>console.log(regionNamesInEnglish.of('US')) : void
|
|
>console.log : (...data: any[]) => void
|
|
>console : Console
|
|
>log : (...data: any[]) => void
|
|
>regionNamesInEnglish.of('US') : string
|
|
>regionNamesInEnglish.of : (code: string) => string
|
|
>regionNamesInEnglish : Intl.DisplayNames
|
|
>of : (code: string) => string
|
|
>'US' : "US"
|
|
|
|
// expected output: "United States"
|
|
|
|
console.log(regionNamesInTraditionalChinese.of('US'));
|
|
>console.log(regionNamesInTraditionalChinese.of('US')) : void
|
|
>console.log : (...data: any[]) => void
|
|
>console : Console
|
|
>log : (...data: any[]) => void
|
|
>regionNamesInTraditionalChinese.of('US') : string
|
|
>regionNamesInTraditionalChinese.of : (code: string) => string
|
|
>regionNamesInTraditionalChinese : Intl.DisplayNames
|
|
>of : (code: string) => string
|
|
>'US' : "US"
|
|
|
|
// expected output: "美國"
|
|
|
|
const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID'];
|
|
>locales1 : string[]
|
|
>['ban', 'id-u-co-pinyin', 'de-ID'] : string[]
|
|
>'ban' : "ban"
|
|
>'id-u-co-pinyin' : "id-u-co-pinyin"
|
|
>'de-ID' : "de-ID"
|
|
|
|
const options1 = { localeMatcher: 'lookup' } as const;
|
|
>options1 : { readonly localeMatcher: "lookup"; }
|
|
>{ localeMatcher: 'lookup' } as const : { readonly localeMatcher: "lookup"; }
|
|
>{ localeMatcher: 'lookup' } : { readonly localeMatcher: "lookup"; }
|
|
>localeMatcher : "lookup"
|
|
>'lookup' : "lookup"
|
|
|
|
console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', '));
|
|
>console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')) : void
|
|
>console.log : (...data: any[]) => void
|
|
>console : Console
|
|
>log : (...data: any[]) => void
|
|
>Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ') : string
|
|
>Intl.DisplayNames.supportedLocalesOf(locales1, options1).join : (separator?: string) => string
|
|
>Intl.DisplayNames.supportedLocalesOf(locales1, options1) : string[]
|
|
>Intl.DisplayNames.supportedLocalesOf : (locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }) => string[]
|
|
>Intl.DisplayNames : { new (locales?: string | string[], options?: Partial<Intl.DisplayNamesOptions>): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; }
|
|
>Intl : typeof Intl
|
|
>DisplayNames : { new (locales?: string | string[], options?: Partial<Intl.DisplayNamesOptions>): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; }
|
|
>supportedLocalesOf : (locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }) => string[]
|
|
>locales1 : string[]
|
|
>options1 : { readonly localeMatcher: "lookup"; }
|
|
>join : (separator?: string) => string
|
|
>', ' : ", "
|
|
|