11declare namespace Intl {
2+
3+ /**
4+ * Value of the `unit` property in duration objects
5+ *
6+ * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration).
7+ */
8+ type DurationTimeFormatUnit = "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds"
9+
10+ type DurationFormatStyle = "long" | "short" | "narrow" | "digital"
11+
12+
13+ type DurationFormatUnitSingular =
14+ | "year"
15+ | "quarter"
16+ | "month"
17+ | "week"
18+ | "day"
19+ | "hour"
20+ | "minute"
21+ | "second" ;
22+
23+ /**
24+ * An object representing the relative time format in parts
25+ * that can be used for custom locale-aware formatting.
26+ *
27+ * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts#Using_formatToParts).
28+ */
29+ type DurationFormatPart =
30+ | {
31+ type : "literal" ;
32+ value : string ;
33+ }
34+ | {
35+ type : Exclude < NumberFormatPartTypes , "literal" > ;
36+ value : string ;
37+ unit : DurationFormatUnitSingular ;
38+ } ;
39+
40+ type ResolvedDurationFormatOptions = {
41+ locale : UnicodeBCP47LocaleIdentifier
42+ numberingSystem : DateTimeFormatOptions [ "numberingSystem" ]
43+ style : DurationFormatStyle
44+ years : "long" | "short" | "narrow" ;
45+ yearsDisplay :"always" | "auto" ;
46+ months :"long" | "short" | "narrow" ;
47+ monthsDisplay :"always" | "auto" ;
48+ weeks :"long" | "short" | "narrow" ;
49+ weeksDisplay :"always" | "auto" ;
50+ days :"long" | "short" | "narrow" ;
51+ daysDisplay :"always" | "auto" ;
52+ hours :"long" | "short" | "narrow" | "numeric" | "2-digit"
53+ hoursDisplay :"always" | "auto" ;
54+ minutes :"long" | "short" | "narrow" | "numeric" | "2-digit"
55+ minutesDisplay :"always" | "auto" ;
56+ seconds :"long" | "short" | "narrow" | "numeric" | "2-digit"
57+ secondsDisplay :"always" | "auto" ;
58+ milliseconds :"long" | "short" | "narrow" | "numeric" | "2-digit"
59+ millisecondsDisplay :"always" | "auto" ;
60+ microseconds :"long" | "short" | "narrow" | "numeric" | "2-digit"
61+ microsecondsDisplay :"always" | "auto" ;
62+ nanosecond :"long" | "short" | "narrow" | "numeric" | "2-digit"
63+ nanosecondDisplay :"always" | "auto" ;
64+ fractionalDigits :0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
65+ }
66+
67+ type DurationFormatOptions = {
68+ localeMatcher : LocaleMatcher
69+ numberingSystem : DateTimeFormatOptions [ "numberingSystem" ]
70+ style : DurationFormatStyle
71+ years : "long" | "short" | "narrow" ;
72+ yearsDisplay :"always" | "auto" ;
73+ months :"long" | "short" | "narrow" ;
74+ monthsDisplay :"always" | "auto" ;
75+ weeks :"long" | "short" | "narrow" ;
76+ weeksDisplay :"always" | "auto" ;
77+ days :"long" | "short" | "narrow" ;
78+ daysDisplay :"always" | "auto" ;
79+ hours :"long" | "short" | "narrow" | "numeric" | "2-digit"
80+ hoursDisplay :"always" | "auto" ;
81+ minutes :"long" | "short" | "narrow" | "numeric" | "2-digit"
82+ minutesDisplay :"always" | "auto" ;
83+ seconds :"long" | "short" | "narrow" | "numeric" | "2-digit"
84+ secondsDisplay :"always" | "auto" ;
85+ milliseconds :"long" | "short" | "narrow" | "numeric" | "2-digit"
86+ millisecondsDisplay :"always" | "auto" ;
87+ microseconds :"long" | "short" | "narrow" | "numeric" | "2-digit"
88+ microsecondsDisplay :"always" | "auto" ;
89+ nanosecond :"long" | "short" | "narrow" | "numeric" | "2-digit"
90+ nanosecondDisplay :"always" | "auto" ;
91+ fractionalDigits :0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
92+ }
93+
94+ /**
95+ * The duration object to be formatted
96+ *
97+ * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration).
98+ */
99+ type DurationType = Record < DurationTimeFormatUnit , number >
100+
2101 interface DurationFormat {
3102 /**
4103 * @param duration The duration object to be formatted. It should include some or all of the following properties: months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds.
5104 *
6105 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format).
7106 */
8- format ( duration : Record < "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds" , number > ) : string ;
107+ format ( duration : DurationType ) : string ;
9108 /**
10109 * @param duration The duration object to be formatted. It should include some or all of the following properties: months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds.
11110 *
12111 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts).
13112 */
14- formatToParts ( duration : Record < "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds" , number > ) : { type : "integer" | "literal" | "unit" , value : string , unit : "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "microseconds" | "nanoseconds" } [ ] ;
113+ formatToParts ( duration : DurationType ) : DurationFormatPart ;
15114 /**
16- * Returns a new object with properties reflecting the locale and style formatting options computed during the construction of the current
17- * [`Intl/DisplayNames`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
18- *
19- * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions).
115+ * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions).
20116 */
21- resolvedOptions ( ) : ResolvedDisplayNamesOptions ;
117+ resolvedOptions ( ) : ResolvedDurationFormatOptions ;
22118 }
23119
24120 const DurationFormat : {
@@ -29,11 +125,11 @@ declare namespace Intl {
29125 * For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation)
30126 * page.
31127 *
32- * @param options An object for setting up a display name .
128+ * @param options An object for setting up a duration format .
33129 *
34- * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames ).
130+ * [MDN](https://developer.mozilla.org/en-US/ docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat ).
35131 */
36- new ( locales : LocalesArgument , options : DisplayNamesOptions ) : DisplayNames ;
132+ new ( locales : LocalesArgument , options : DurationFormatOptions ) : DisplayNames ;
37133
38134 /**
39135 * Returns an array containing those of the provided locales that are supported in display names without having to fall back to the runtime's default locale.
@@ -46,8 +142,8 @@ declare namespace Intl {
46142 *
47143 * @returns An array of strings representing a subset of the given locale tags that are supported in display names without having to fall back to the runtime's default locale.
48144 *
49- * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames /supportedLocalesOf).
145+ * [MDN](https://developer.mozilla.org/en-US/ docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat /supportedLocalesOf).
50146 */
51- supportedLocalesOf ( locales ?: LocalesArgument , options ?: { localeMatcher ?: RelativeTimeFormatLocaleMatcher ; } ) : UnicodeBCP47LocaleIdentifier [ ] ;
147+ supportedLocalesOf ( locales ?: LocalesArgument , options ?: { localeMatcher ?: LocaleMatcher ; } ) : UnicodeBCP47LocaleIdentifier [ ] ;
52148 } ;
53149}
0 commit comments