@@ -4,16 +4,13 @@ declare namespace Intl {
44 * [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition.
55 *
66 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
7- *
87 */
98 type UnicodeBCP47LocaleIdentifier = string ;
109
1110 /**
1211 * Unit to use in the relative time internationalized message.
1312 *
1413 * [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).
1714 */
1815 type RelativeTimeFormatUnit =
1916 | "year" | "years"
@@ -30,40 +27,42 @@ declare namespace Intl {
3027 * The locale matching algorithm to use.
3128 *
3229 * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation).
33- *
34- * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat).
3530 */
3631 type RelativeTimeFormatLocaleMatcher = "lookup" | "best fit" ;
3732
3833 /**
3934 * The format of output message.
4035 *
4136 * [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).
4437 */
4538 type RelativeTimeFormatNumeric = "always" | "auto" ;
4639
4740 /**
4841 * The length of the internationalized message.
4942 *
5043 * [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).
5344 */
5445 type RelativeTimeFormatStyle = "long" | "short" | "narrow" ;
5546
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+
5654 /**
5755 * An object with some or all of properties of `options` parameter
5856 * of `Intl.RelativeTimeFormat` constructor.
5957 *
6058 * [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).
6359 */
6460 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). */
6562 localeMatcher ?: RelativeTimeFormatLocaleMatcher ;
63+ /** The format of output message. */
6664 numeric ?: RelativeTimeFormatNumeric ;
65+ /** The length of the internationalized message. */
6766 style ?: RelativeTimeFormatStyle ;
6867 }
6968
@@ -73,8 +72,6 @@ declare namespace Intl {
7372 * of the `Intel.RelativeTimeFormat` object
7473 *
7574 * [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)
7875 */
7976 interface ResolvedRelativeTimeFormatOptions {
8077 locale : UnicodeBCP47LocaleIdentifier ;
@@ -88,8 +85,6 @@ declare namespace Intl {
8885 * that can be used for custom locale-aware formatting.
8986 *
9087 * [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).
9388 */
9489 interface RelativeTimeFormatPart {
9590 type : string ;
@@ -106,75 +101,41 @@ declare namespace Intl {
106101 *
107102 * While this method automatically provides the correct plural forms,
108103 * the grammatical form is otherwise as neutral as possible.
104+ *
109105 * It is the caller's responsibility to handle cut-off logic
110106 * such as deciding between displaying "in 7 days" or "in 1 week".
111107 * This API does not support relative dates involving compound units.
112108 * e.g "in 5 days and 4 hours".
113109 *
114110 * @param value - Numeric value to use in the internationalized relative time message
115111 *
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.
121113 *
122114 * @throws `RangeError` if `unit` was given something other than `unit` possible values
123115 *
124- * @returns Internationalized relative time message as string
116+ * @returns { string } Internationalized relative time message as string
125117 *
126118 * [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).
129119 */
130- format (
131- value : number ,
132- unit : RelativeTimeFormatUnit ,
133- ) : string ;
120+ format ( value : number , unit : RelativeTimeFormatUnit ) : string ;
134121
135122 /**
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.
146124 *
147125 * @param value - Numeric value to use in the internationalized relative time message
148126 *
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.
154128 *
155129 * @throws `RangeError` if `unit` was given something other than `unit` possible values
156130 *
157- * @returns Array of [FormatRelativeTimeToParts](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts)
158- *
159131 * [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).
162132 */
163- formatToParts (
164- value : number ,
165- unit : RelativeTimeFormatUnit ,
166- ) : RelativeTimeFormatPart [ ] ;
133+ formatToParts ( value : number , unit : RelativeTimeFormatUnit ) : RelativeTimeFormatPart [ ] ;
167134
168135 /**
169136 * Provides access to the locale and options computed during initialization of this `Intl.RelativeTimeFormat` object.
170137 *
171- * @returns A new object with properties reflecting the locale
172- * and formatting options computed during initialization
173- * of the `Intel.RelativeTimeFormat` object.
174- *
175138 * [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)
178139 */
179140 resolvedOptions ( ) : ResolvedRelativeTimeFormatOptions ;
180141 }
@@ -187,37 +148,21 @@ declare namespace Intl {
187148 * namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm).
188149 *
189150 * [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).
192151 */
193152 const RelativeTimeFormat : {
194153 /**
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
197155 *
198156 * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
199157 * For the general form and interpretation of the locales argument,
200158 * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
201159 *
202160 * @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`.
215162 *
216163 * @returns [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) object.
217164 *
218165 * [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).
221166 */
222167 new (
223168 locales ?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier [ ] ,
@@ -235,25 +180,12 @@ declare namespace Intl {
235180 *
236181 * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters)
237182 * 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.
249183 *
250184 * @returns An array containing those of the provided locales
251185 * that are supported in date and time formatting
252186 * without having to fall back to the runtime's default locale.
253187 *
254188 * [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).
257189 */
258190 supportedLocalesOf (
259191 locales ?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier [ ] ,
@@ -262,19 +194,19 @@ declare namespace Intl {
262194 } ;
263195
264196 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" ;
270202 }
271203
272204 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" ;
278210 }
279211
280212 interface DateTimeFormatOptions {
@@ -286,4 +218,58 @@ declare namespace Intl {
286218 hourCycle ?: "h11" | "h12" | "h23" | "h24" ;
287219 fractionalSecondDigits ?: 0 | 1 | 2 | 3 ;
288220 }
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+ } ;
289275}
0 commit comments