@@ -4,16 +4,13 @@ declare namespace Intl {
4
4
* [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition.
5
5
*
6
6
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
7
- *
8
7
*/
9
8
type UnicodeBCP47LocaleIdentifier = string ;
10
9
11
10
/**
12
11
* Unit to use in the relative time internationalized message.
13
12
*
14
13
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format#Parameters).
15
- *
16
- * [Specification](https://tc39.es/ecma402/#sec-singularrelativetimeunit).
17
14
*/
18
15
type RelativeTimeFormatUnit =
19
16
| "year" | "years"
@@ -30,40 +27,42 @@ declare namespace Intl {
30
27
* The locale matching algorithm to use.
31
28
*
32
29
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
33
- *
34
- * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
35
30
*/
36
31
type RelativeTimeFormatLocaleMatcher = "lookup" | "best fit" ;
37
32
38
33
/**
39
34
* The format of output message.
40
35
*
41
36
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
42
- *
43
- * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
44
37
*/
45
38
type RelativeTimeFormatNumeric = "always" | "auto" ;
46
39
47
40
/**
48
41
* The length of the internationalized message.
49
42
*
50
43
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
51
- *
52
- * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
53
44
*/
54
45
type RelativeTimeFormatStyle = "long" | "short" | "narrow" ;
55
46
47
+ /**
48
+ * [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition.
49
+ *
50
+ * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
51
+ */
52
+ type BCP47LanguageTag = string ;
53
+
56
54
/**
57
55
* An object with some or all of properties of `options` parameter
58
56
* of `Intl.RelativeTimeFormat` constructor.
59
57
*
60
58
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters).
61
- *
62
- * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
63
59
*/
64
60
interface RelativeTimeFormatOptions {
61
+ /** The locale matching algorithm to use. For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). */
65
62
localeMatcher ?: RelativeTimeFormatLocaleMatcher ;
63
+ /** The format of output message. */
66
64
numeric ?: RelativeTimeFormatNumeric ;
65
+ /** The length of the internationalized message. */
67
66
style ?: RelativeTimeFormatStyle ;
68
67
}
69
68
@@ -73,8 +72,6 @@ declare namespace Intl {
73
72
* of the `Intel.RelativeTimeFormat` object
74
73
*
75
74
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description).
76
- *
77
- * [Specification](https://tc39.es/ecma402/#table-relativetimeformat-resolvedoptions-properties)
78
75
*/
79
76
interface ResolvedRelativeTimeFormatOptions {
80
77
locale : UnicodeBCP47LocaleIdentifier ;
@@ -88,8 +85,6 @@ declare namespace Intl {
88
85
* that can be used for custom locale-aware formatting.
89
86
*
90
87
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts#Using_formatToParts).
91
- *
92
- * [Specification](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts).
93
88
*/
94
89
interface RelativeTimeFormatPart {
95
90
type : string ;
@@ -106,75 +101,41 @@ declare namespace Intl {
106
101
*
107
102
* While this method automatically provides the correct plural forms,
108
103
* the grammatical form is otherwise as neutral as possible.
104
+ *
109
105
* It is the caller's responsibility to handle cut-off logic
110
106
* such as deciding between displaying "in 7 days" or "in 1 week".
111
107
* This API does not support relative dates involving compound units.
112
108
* e.g "in 5 days and 4 hours".
113
109
*
114
110
* @param value - Numeric value to use in the internationalized relative time message
115
111
*
116
- * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit)
117
- * to use in the relative time internationalized message.
118
- * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`,
119
- * `"day"`, `"hour"`, `"minute"`, `"second"`.
120
- * Plural forms are also permitted.
112
+ * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) to use in the relative time internationalized message.
121
113
*
122
114
* @throws `RangeError` if `unit` was given something other than `unit` possible values
123
115
*
124
- * @returns Internationalized relative time message as string
116
+ * @returns { string } Internationalized relative time message as string
125
117
*
126
118
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format).
127
- *
128
- * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.format).
129
119
*/
130
- format (
131
- value : number ,
132
- unit : RelativeTimeFormatUnit ,
133
- ) : string ;
120
+ format ( value : number , unit : RelativeTimeFormatUnit ) : string ;
134
121
135
122
/**
136
- * A version of the format method which it returns an array of objects
137
- * which represent "parts" of the object,
138
- * separating the formatted number into its constituent parts
139
- * and separating it from other surrounding text.
140
- * These objects have two properties:
141
- * `type` a NumberFormat formatToParts type, and `value`,
142
- * which is the String which is the component of the output.
143
- * If a "part" came from NumberFormat,
144
- * it will have a unit property which indicates the `unit` being formatted;
145
- * literals which are part of the larger frame will not have this property.
123
+ * Returns an array of objects representing the relative time format in parts that can be used for custom locale-aware formatting.
146
124
*
147
125
* @param value - Numeric value to use in the internationalized relative time message
148
126
*
149
- * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit)
150
- * to use in the relative time internationalized message.
151
- * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`,
152
- * `"day"`, `"hour"`, `"minute"`, `"second"`.
153
- * Plural forms are also permitted.
127
+ * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) to use in the relative time internationalized message.
154
128
*
155
129
* @throws `RangeError` if `unit` was given something other than `unit` possible values
156
130
*
157
- * @returns Array of [FormatRelativeTimeToParts](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts)
158
- *
159
131
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts).
160
- *
161
- * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.formatToParts).
162
132
*/
163
- formatToParts (
164
- value : number ,
165
- unit : RelativeTimeFormatUnit ,
166
- ) : RelativeTimeFormatPart [ ] ;
133
+ formatToParts ( value : number , unit : RelativeTimeFormatUnit ) : RelativeTimeFormatPart [ ] ;
167
134
168
135
/**
169
136
* Provides access to the locale and options computed during initialization of this `Intl.RelativeTimeFormat` object.
170
137
*
171
- * @returns A new object with properties reflecting the locale
172
- * and formatting options computed during initialization
173
- * of the `Intel.RelativeTimeFormat` object.
174
- *
175
138
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions).
176
- *
177
- * [Specification](https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions)
178
139
*/
179
140
resolvedOptions ( ) : ResolvedRelativeTimeFormatOptions ;
180
141
}
@@ -187,37 +148,21 @@ declare namespace Intl {
187
148
* namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm).
188
149
*
189
150
* [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#Browser_compatibility).
190
- *
191
- * [Polyfills](https://github.com/tc39/proposal-intl-relative-time#polyfills).
192
151
*/
193
152
const RelativeTimeFormat : {
194
153
/**
195
- * Constructor creates [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat)
196
- * objects
154
+ * Creates [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) objects
197
155
*
198
156
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
199
157
* For the general form and interpretation of the locales argument,
200
158
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
201
159
*
202
160
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
203
- * with some or all of options of the formatting.
204
- * An object with some or all of the following properties:
205
- * - `localeMatcher` - The locale matching algorithm to use.
206
- * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
207
- * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
208
- * - `numeric` - The format of output message.
209
- * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`).
210
- * The `"auto"` value allows to not always have to use numeric values in the output.
211
- * - `style` - The length of the internationalized message. Possible values are:
212
- * `"long"` (default, e.g., in 1 month),
213
- * `"short"` (e.g., in 1 mo.)
214
- * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales.
161
+ * with some or all of options of `RelativeTimeFormatOptions`.
215
162
*
216
163
* @returns [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) object.
217
164
*
218
165
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
219
- *
220
- * [Specification](https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor).
221
166
*/
222
167
new (
223
168
locales ?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier [ ] ,
@@ -235,25 +180,12 @@ declare namespace Intl {
235
180
*
236
181
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
237
182
* with some or all of options of the formatting.
238
- * An object with some or all of the following properties:
239
- * - `localeMatcher` - The locale matching algorithm to use.
240
- * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`.
241
- * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
242
- * - `numeric` - The format of output message.
243
- * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`).
244
- * The `"auto"` value allows to not always have to use numeric values in the output.
245
- * - `style` - The length of the internationalized message. Possible values are:
246
- * `"long"` (default, e.g., in 1 month),
247
- * `"short"` (e.g., in 1 mo.)
248
- * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales.
249
183
*
250
184
* @returns An array containing those of the provided locales
251
185
* that are supported in date and time formatting
252
186
* without having to fall back to the runtime's default locale.
253
187
*
254
188
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/supportedLocalesOf).
255
- *
256
- * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.supportedLocalesOf).
257
189
*/
258
190
supportedLocalesOf (
259
191
locales ?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier [ ] ,
@@ -262,19 +194,19 @@ declare namespace Intl {
262
194
} ;
263
195
264
196
interface NumberFormatOptions {
265
- compactDisplay ?: string ;
266
- notation ?: string ;
267
- signDisplay ?: string ;
268
- unit ?: string ;
269
- unitDisplay ?: string ;
197
+ compactDisplay ?: "short" | "long" ;
198
+ notation ?: "standard" | "scientific" | "engineering" | "compact" ;
199
+ signDisplay ?: "auto" | "never" | "always" ;
200
+ unit ?: NumberFormatUnit ;
201
+ unitDisplay ?: "short" | "long" | "narrow" ;
270
202
}
271
203
272
204
interface ResolvedNumberFormatOptions {
273
- compactDisplay ?: string ;
274
- notation ?: string ;
275
- signDisplay ?: string ;
276
- unit ?: string ;
277
- unitDisplay ?: string ;
205
+ compactDisplay ?: "short" | "long" ;
206
+ notation ?: "standard" | "scientific" | "engineering" | "compact" ;
207
+ signDisplay ?: "auto" | "never" | "always" ;
208
+ unit ?: NumberFormatUnit ;
209
+ unitDisplay ?: "short" | "long" | "narrow" ;
278
210
}
279
211
280
212
interface DateTimeFormatOptions {
@@ -286,4 +218,58 @@ declare namespace Intl {
286
218
hourCycle ?: "h11" | "h12" | "h23" | "h24" ;
287
219
fractionalSecondDigits ?: 0 | 1 | 2 | 3 ;
288
220
}
221
+
222
+ type LocaleHourCycleKey = "h12" | "h23" | "h11" | "h24" ;
223
+ type LocaleCollationCaseFirst = "upper" | "lower" | "false" ;
224
+
225
+ interface LocaleOptions {
226
+ /** A string containing the language, and the script and region if available. */
227
+ baseName ?: string ;
228
+ /** The part of the Locale that indicates the locale's calendar era. */
229
+ calendar ?: string ;
230
+ /** Flag that defines whether case is taken into account for the locale's collation rules. */
231
+ caseFirst ?: LocaleCollationCaseFirst ;
232
+ /** The collation type used for sorting */
233
+ collation ?: string ;
234
+ /** The time keeping format convention used by the locale. */
235
+ hourCycle ?: LocaleHourCycleKey ;
236
+ /** The primary language subtag associated with the locale. */
237
+ language ?: string ;
238
+ /** The numeral system used by the locale. */
239
+ numberingSystem ?: string ;
240
+ /** Flag that defines whether the locale has special collation handling for numeric characters. */
241
+ numeric ?: boolean ;
242
+ /** The region of the world (usually a country) associated with the locale. Possible values are region codes as defined by ISO 3166-1. */
243
+ region ?: string ;
244
+ /** The script used for writing the particular language used in the locale. Possible values are script codes as defined by ISO 15924. */
245
+ script ?: string ;
246
+ }
247
+
248
+ interface Locale extends LocaleOptions {
249
+ /** Gets the most likely values for the language, script, and region of the locale based on existing values. */
250
+ maximize ( ) : Locale ;
251
+ /** Attempts to remove information about the locale that would be added by calling `Locale.maximize()`. */
252
+ minimize ( ) : Locale ;
253
+ /** Returns the locale's full locale identifier string. */
254
+ toString ( ) : BCP47LanguageTag ;
255
+ }
256
+
257
+ /**
258
+ * Constructor creates [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
259
+ * objects
260
+ *
261
+ * @param tag - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646).
262
+ * For the general form and interpretation of the locales argument,
263
+ * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
264
+ *
265
+ * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale#Parameters)
266
+ * with some or all of options of the locale.
267
+ *
268
+ * @returns [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) object.
269
+ *
270
+ * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale).
271
+ */
272
+ const Locale : {
273
+ new ( tag ?: BCP47LanguageTag , options ?: LocaleOptions ) : Locale ;
274
+ } ;
289
275
}
0 commit comments