-
Notifications
You must be signed in to change notification settings - Fork 12.8k
intl.d.ts: cleanup, add missing features, fix library discrepancies #58084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4cce807
a6b7bad
5265cbc
fea424d
c676adf
2d8de76
8f78556
3166c84
1961da6
aaf1758
27bbc61
50d6708
f5204b9
d8363b4
2cb5dee
d68c136
4c84f0e
0ff12bd
7354ab0
7871f1e
19d70ce
fda90ca
ff38aff
cb957d1
b1cf424
daa14b8
165b31c
8cf8f28
a7f690b
ae033d3
e5c29dd
9624605
1209aee
ab7cfc1
b3dd379
edf8ae6
dd2e100
62be4e9
ffe0b99
3459af2
3d631ca
7827f33
9d2741c
d7dc3e2
4e06b5e
ac84ff5
30bc011
5c8b793
0c035e3
1ddd414
cb3a856
b6acf0f
897fc6d
0cd1814
31d8a82
9e37c30
6fa9cf2
193ea18
c08b13c
86d0f1a
596edb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
declare namespace Intl { | ||
/** | ||
* The `Intl.getCanonicalLocales()` method returns an array containing | ||
* the canonical locale names. Duplicates will be omitted and elements | ||
* will be validated as structurally valid language tags. | ||
* | ||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales) | ||
* | ||
* @param locale A list of String values for which to get the canonical locale names | ||
* @returns An array containing the canonical and validated locale names. | ||
* Takes a list of locale identifiers, and returns a deduplicated list of their canonical names. | ||
* Structurally invalid identifiers will cause an error to be thrown. | ||
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers. | ||
*/ | ||
function getCanonicalLocales(locale?: string | readonly string[]): string[]; | ||
function getCanonicalLocales(locales?: string | readonly string[]): string[]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
declare namespace Intl { | ||
interface DateTimeFormatPartTypesRegistry { | ||
day: any; | ||
dayPeriod: any; | ||
era: any; | ||
hour: any; | ||
literal: any; | ||
minute: any; | ||
month: any; | ||
second: any; | ||
timeZoneName: any; | ||
weekday: any; | ||
year: any; | ||
day: "day"; | ||
dayPeriod: "dayPeriod"; | ||
era: "era"; | ||
hour: "hour"; | ||
literal: "literal"; | ||
minute: "minute"; | ||
month: "month"; | ||
second: "second"; | ||
timeZoneName: "timeZoneName"; | ||
weekday: "weekday"; | ||
year: "year"; | ||
} | ||
|
||
type DateTimeFormatPartTypes = keyof DateTimeFormatPartTypesRegistry; | ||
type DateTimeFormatPartTypes = DateTimeFormatPartTypesRegistry[keyof DateTimeFormatPartTypesRegistry]; | ||
|
||
interface DateTimeFormatPart { | ||
type: DateTimeFormatPartTypes; | ||
value: string; | ||
} | ||
|
||
interface DateTimeFormat { | ||
/** | ||
* Formats a date as a string, according to the selected locale and formatting options, | ||
* and returns the result as a list of locale-specific string tokens. | ||
* @param date A `Date` object or timestamp. If undefined, defaults to the value of `Date.now()`. | ||
*/ | ||
formatToParts(date?: Date | number): DateTimeFormatPart[]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
declare namespace Intl { | ||
// http://cldr.unicode.org/index/cldr-spec/plural-rules#TOC-Determining-Plural-Categories | ||
type LDMLPluralRule = "zero" | "one" | "two" | "few" | "many" | "other"; | ||
type PluralRuleType = "cardinal" | "ordinal"; | ||
|
||
interface PluralRulesOptions { | ||
localeMatcher?: "lookup" | "best fit" | undefined; | ||
localeMatcher?: LocaleMatcherAlgorithm | undefined; | ||
type?: PluralRuleType | undefined; | ||
minimumIntegerDigits?: number | undefined; | ||
minimumFractionDigits?: number | undefined; | ||
|
@@ -18,48 +17,75 @@ declare namespace Intl { | |
pluralCategories: LDMLPluralRule[]; | ||
type: PluralRuleType; | ||
minimumIntegerDigits: number; | ||
minimumFractionDigits: number; | ||
maximumFractionDigits: number; | ||
minimumFractionDigits?: number; | ||
maximumFractionDigits?: number; | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentionally optional. |
||
minimumSignificantDigits?: number; | ||
maximumSignificantDigits?: number; | ||
} | ||
|
||
interface PluralRules { | ||
resolvedOptions(): ResolvedPluralRulesOptions; | ||
/** | ||
* Returns the plural rule identifier for the given number, according to the selected locale and parsing options. | ||
* @param n The number to parse. | ||
*/ | ||
select(n: number): LDMLPluralRule; | ||
|
||
/** Returns the locale and options computed during initialization of this `PluralRules` instance. */ | ||
resolvedOptions(): ResolvedPluralRulesOptions; | ||
} | ||
|
||
interface PluralRulesConstructor { | ||
new (locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules; | ||
(locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot be invoked without |
||
supportedLocalesOf(locales: string | readonly string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[]; | ||
readonly prototype: PluralRules; | ||
|
||
/** | ||
* Takes a list of locale identifiers, and returns the subset of identifiers that are supported by the current implementation of `PluralRules`. | ||
* If none of the provided locales are supported, an empty array is returned. | ||
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers. | ||
* @param options Options for the locale matching algorithm. | ||
*/ | ||
supportedLocalesOf(locales?: string | readonly string[], options?: SupportedLocalesOptions): string[]; | ||
} | ||
|
||
const PluralRules: PluralRulesConstructor; | ||
var PluralRules: PluralRulesConstructor; | ||
|
||
interface NumberFormatPartTypeRegistry { | ||
literal: never; | ||
nan: never; | ||
infinity: never; | ||
percent: never; | ||
integer: never; | ||
group: never; | ||
decimal: never; | ||
fraction: never; | ||
plusSign: never; | ||
minusSign: never; | ||
percentSign: never; | ||
currency: never; | ||
literal: "literal"; | ||
nan: "nan"; | ||
infinity: "infinity"; | ||
percent: "percent"; | ||
integer: "integer"; | ||
group: "group"; | ||
decimal: "decimal"; | ||
fraction: "fraction"; | ||
plusSign: "plusSign"; | ||
minusSign: "minusSign"; | ||
percentSign: "percentSign"; | ||
currency: "currency"; | ||
} | ||
|
||
type NumberFormatPartTypes = keyof NumberFormatPartTypeRegistry; | ||
type NumberFormatPartTypes = NumberFormatPartTypeRegistry[keyof NumberFormatPartTypeRegistry]; | ||
|
||
interface NumberFormatPart { | ||
type: NumberFormatPartTypes; | ||
value: string; | ||
} | ||
|
||
interface NumberFormat { | ||
formatToParts(number?: number | bigint): NumberFormatPart[]; | ||
/** | ||
* Formats a number as a string, according to the selected locale and formatting options, | ||
* and returns the result as a list of locale-specific string tokens. | ||
* @param value The value to be formatted. | ||
*/ | ||
formatToParts(value?: number): NumberFormatPart[]; | ||
} | ||
|
||
type DateTimeFormatOptionsHourCycle = "h11" | "h12" | "h23" | "h24"; | ||
|
||
interface DateTimeFormatOptions { | ||
hourCycle?: DateTimeFormatOptionsHourCycle | undefined; | ||
} | ||
|
||
interface ResolvedDateTimeFormatOptions { | ||
hourCycle?: DateTimeFormatOptionsHourCycle; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentionally optional. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
declare namespace Intl { | ||
interface DateTimeFormatPartTypesRegistry { | ||
unknown: never; | ||
unknown: "unknown"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See notes towards the bottom of the PR description for discussion regarding the type of
options
here.I'm ambivalent towards the change, but thought it would be worth proposing.