recursal/MDN huggingface dataset:
Intl.RelativeTimeFormat.prototype.resolvedOptions()
===================================================

The **`resolvedOptions()`** method of `Intl.RelativeTimeFormat` instances returns a new object with properties reflecting the locale and relative time formatting options computed during initialization of this `Intl.RelativeTimeFormat` object.

Try it
------

Syntax
------


```js
resolvedOptions()
```

### Parameters

None.

### Return value

A new object with properties reflecting the locale and number formatting options computed during the initialization of the given `Intl.RelativeTimeFormat` object.

Description
-----------

The resulting object has the following properties:

`locale`

The BCP 47 language tag for the locale actually used. If any Unicode extension values were requested in the input BCP 47 language tag that led to this locale, the key-value pairs that were requested and are supported for this locale are included in `locale`.

`style`

The length of the internationalized message. Possible values are:

* `"long"` (default, e.g., `in 1 month`)
* `"short"` (e.g., `in 1 mo.`),
* or `"narrow"` (e.g., `in 1 mo.`). The narrow style could be similar to the short style for some locales.

`numeric`

The format of output message. Possible values are:

* `"always"` (default, e.g., `1 day ago`),
* or `"auto"` (e.g., `yesterday`). The `"auto"` value allows to not always have to use numeric values in the output.

`numberingSystem`

The value requested using the Unicode extension key `"nu"` or filled in as a default.

Examples
--------

### Using the resolvedOptions() method


```js
const de = new Intl.RelativeTimeFormat("de-DE");
const usedOptions = de.resolvedOptions();

usedOptions.locale; // "de-DE"
usedOptions.style; // "long"
usedOptions.numeric; // "always"
usedOptions.numberingSystem; // "latn"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.relativetimeformat.prototype.resolvedoptions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.RelativeTimeFormat`
Intl.RelativeTimeFormat.prototype.format()
==========================================

The **`format()`** method of `Intl.RelativeTimeFormat` instances formats a `value` and `unit` according to the locale and formatting options of this `Intl.RelativeTimeFormat` object.

Try it
------

Syntax
------


```js
format(value, unit)
```

### Parameters

`value`

Numeric value to use in the internationalized relative time message.

`unit`

Unit to use in the relative time internationalized message. Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`, `"day"`, `"hour"`, `"minute"`, `"second"`. Plural forms are also permitted.

### Return value

A string representing the given `value` and `unit` formatted according to the locale and formatting options of this `Intl.RelativeTimeFormat` object.

Examples
--------

### Basic format usage

The following example shows how to create a relative time formatter using the English language.


```js
// Create a relative time formatter in your locale
// with default values explicitly passed in.
const rtf = new Intl.RelativeTimeFormat("en", {
  localeMatcher: "best fit", // other values: "lookup"
  numeric: "always", // other values: "auto"
  style: "long", // other values: "short" or "narrow"
});

// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "1 day ago"

// Format relative time using positive value (1).
rtf.format(1, "day"); // "in 1 day"
```

### Using the auto option

If `numeric:auto` option is passed, it will produce the string `yesterday`, `today`, or `tomorrow` instead of `1 day ago`, `in 0 days`, or `in 1 day`. This allows to not always have to use numeric values in the output.


```js
// Create a relative time formatter in your locale
// with numeric: "auto" option value passed in.
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "yesterday"

rtf.format(0, "day"); // "today"

// Format relative time using positive day unit (1).
rtf.format(1, "day"); // "tomorrow"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.RelativeTimeFormat.prototype.format |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.RelativeTimeFormat`
Intl.DisplayNames.supportedLocalesOf()
======================================

The **`Intl.DisplayNames.supportedLocalesOf()`** static method 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.

Syntax
------


```js
Intl.DisplayNames.supportedLocalesOf(locales)
Intl.DisplayNames.supportedLocalesOf(locales, options)
```

### Parameters

`locales`

A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

`options` Optional

An object that may have the following property:

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see the Intl page.


### Return value

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.

Examples
--------

### Using supportedLocalesOf()

Assuming a runtime that supports Indonesian and German but not Balinese in display names, `supportedLocalesOf` returns the Indonesian and German language tags unchanged, even though `pinyin` collation is neither relevant to display names nor used with Indonesian, and a specialized German for Indonesia is unlikely to be supported. Note the specification of the `"lookup"` algorithm here — a `"best fit"` matcher might decide that Indonesian is an adequate match for Balinese since most Balinese speakers also understand Indonesian, and therefore return the Balinese language tag as well.


```js
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.DisplayNames.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.DisplayNames.supportedLocalesOf |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.DisplayNames`
Intl.DisplayNames.prototype.resolvedOptions()
=============================================

 The **`resolvedOptions()`** method of `Intl.DisplayNames` instances
 returns a new object with properties reflecting the locale and style formatting
 options computed during the construction of this `Intl.DisplayNames`
 object.

Syntax
------


```js
resolvedOptions()
```

### Parameters

None.

### Return value

 An object with properties reflecting the locale and formatting options computed during
 the construction of the given `Intl.DisplayNames` object.

Description
-----------

The object returned by `resolvedOptions()` has the following properties:

`locale`

 The BCP 47 language tag for the locale actually used. If any Unicode extension
 values were requested in the input BCP 47 language tag that led to this locale,
 the key-value pairs that were requested and are supported for this locale are
 included in `locale`.


`style`

 The value provided for this property in the `options` argument of the
 constructor or the default value (`"long"`). Its value is either
 `"long"`, `"short"`, or `"narrow"`.


`type`

 The value provided for this property in the `options` argument of the
 constructor or the default value (`"language"`). Its value is either
 `"language"`, `"region"`, `"script"`, or
 `"currency"`.


`fallback`

 The value provided for this property in the options argument of the constructor or
 the default value (`"code"`). Its value is either `"code"`
 or `"none"`.


Examples
--------

### Using resolvedOptions


```js
const displayNames = new Intl.DisplayNames(["de-DE"], { type: "region" });

const usedOptions = displayNames.resolvedOptions();
console.log(usedOptions.locale); // "de-DE"
console.log(usedOptions.style); // "long"
console.log(usedOptions.type); // "region"
console.log(usedOptions.fallback); // "code"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.DisplayNames.prototype.resolvedOptions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.DisplayNames`
Intl.Segmenter() constructor
============================

The **`Intl.Segmenter()`** constructor creates `Intl.Segmenter` objects.

Try it
------

Syntax
------


```js
new Intl.Segmenter()
new Intl.Segmenter(locales)
new Intl.Segmenter(locales, options)
```


**Note:** `Intl.Segmenter()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`locales` Optional

A string with a BCP 47 language tag or an `Intl.Locale` instance, or an array of such locale identifiers. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

`options` Optional

An object containing the following properties, in the order they are retrieved (all of them are optional):

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see Locale identification and negotiation.

`granularity`

How granularly should the input be split. Possible values are:

`"grapheme"` (default)

Split the input into segments at grapheme cluster (user-perceived character) boundaries, as determined by the locale.

`"word"`

Split the input into segments at word boundaries, as determined by the locale.

`"sentence"`

Split the input into segments at sentence boundaries, as determined by the locale.


### Return value

A new `Intl.Segmenter` instance.

### Exceptions

`RangeError`

Thrown if `locales` or `options` contain invalid values.

Examples
--------

### Basic usage

The following example shows how to count words in a string using the Japanese language (where splitting the string using `String` methods would have given an incorrect result).


```js
const text = "吾輩は猫である。名前はたぬき。";
const japaneseSegmenter = new Intl.Segmenter("ja-JP", { granularity: "word" });
console.log(
  [...japaneseSegmenter.segment(text)].filter((segment) => segment.isWordLike)
    .length,
);
// 8, as the text is segmented as '吾輩'|'は'|'猫'|'で'|'ある'|'。'|'名前'|'は'|'たぬき'|'。'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl-segmenter-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
Intl.Segmenter.prototype.segment()
==================================

The **`segment()`** method of `Intl.Segmenter` instances segments a string according to the locale and granularity of this `Intl.Segmenter` object.

Try it
------

Syntax
------


```js
segment(input)
```

### Parameters

`input`

The text to be segmented as a string.

### Return value

A new iterable `Segments` object containing the segments of the input string, using the segmenter's locale and granularity.

Examples
--------


```js
// Create a locale-specific word segmenter
const segmenter = new Intl.Segmenter("fr", { granularity: "word" });

// Use it to get an iterator over the segments of a string
const input = "Moi ? N'est-ce pas ?";
const segments = segmenter.segment(input);

// Use that for segmentation
for (const { segment, index, isWordLike } of segments) {
  console.log(
    "segment at code units [%d, %d]: «%s»%s",
    index,
    index + segment.length,
    segment,
    isWordLike ? " (word-like)" : "",
  );
}
// segment at code units [0, 3]: «Moi» (word-like)
// segment at code units [3, 4]: « »
// segment at code units [4, 5]: «?»
// segment at code units [5, 6]: « »
// segment at code units [6, 11]: «N'est» (word-like)
// segment at code units [11, 12]: «-»
// segment at code units [12, 14]: «ce» (word-like)
// segment at code units [14, 15]: « »
// segment at code units [15, 18]: «pas» (word-like)
// segment at code units [18, 19]: « »
// segment at code units [19, 20]: «?»
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.segmenter.prototype.segment |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
Intl.Segmenter.prototype.resolvedOptions()
==========================================

The **`resolvedOptions()`** method of `Intl.Segmenter` instances returns a new object with properties reflecting the locale and granularity options computed during the initialization of this `Intl.Segmenter` object.

Try it
------

Syntax
------


```js
resolvedOptions()
```

### Parameters

None.

### Return value

 A new object with properties reflecting the locale and collation options computed
 during the initialization of the given `Intl.Segmenter` object.

Description
-----------

The resulting object has the following properties:

`locale`

 The BCP 47 language tag for the locale actually used. If any Unicode extension
 values were requested in the input BCP 47 language tag that led to this locale,
 the key-value pairs that were requested and are supported for this locale are
 included in `locale`.


`granularity`

 The value provided for this property in the `options` argument or filled
 in as the default.


Examples
--------

### Basic usage


```js
const spanishSegmenter = new Intl.Segmenter("es", { granularity: "sentence" });
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "sentence"
```

### Default granularity


```js
const spanishSegmenter = new Intl.Segmenter("es");
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "grapheme"
```

### Fallback locale


```js
const banSegmenter = new Intl.Segmenter("ban");
const options = banSegmenter.resolvedOptions();
console.log(options.locale);
// "fr" on a runtime where the Balinese locale
// is not supported and French is the default locale
console.log(options.granularity); // "grapheme"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.segmenter.prototype.resolvedoptions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
Intl.Segmenter.supportedLocalesOf()
===================================

The **`Intl.Segmenter.supportedLocalesOf()`** static method returns an array containing those of the provided locales that are supported in segmentation without having to fall back to the runtime's default locale.

Try it
------

Syntax
------


```js
Intl.Segmenter.supportedLocalesOf(locales)
Intl.Segmenter.supportedLocalesOf(locales, options)
```

### Parameters

`locales`

A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

`options` Optional

An object that may have the following property:

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see the Intl page.


### Return value

An array of strings representing a subset of the given locale tags that are supported in segmentation without having to fall back to the runtime's default locale.

Examples
--------

### Using supportedLocalesOf()

Assuming a runtime that supports Indonesian and German but not Balinese in segmentation, `supportedLocalesOf` returns the Indonesian and German language tags unchanged, even though `pinyin` collation is neither relevant to segmentation nor used with Indonesian, and a specialized German for Indonesia is unlikely to be supported. Note the specification of the `"lookup"` algorithm here — a `"best fit"` matcher might decide that Indonesian is an adequate match for Balinese since most Balinese speakers also understand Indonesian, and therefore return the Balinese language tag as well.


```js
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.Segmenter.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.segmenter.supportedlocalesof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Segmenter`
Segments
========

A **`Segments`** object is an iterable collection of the segments of a text string. It is returned by a call to the `segment()` method of an `Intl.Segmenter` object.

Try it
------

Instance methods
----------------

`Segments.prototype.containing()`

Returns an object describing the segment in the original string that includes the code unit at a specified index.

`Segments.prototype[@@iterator]()`

Returns an iterator to iterate over the segments.

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-segments-objects |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Segmenter`
* `Intl.Segmenter.prototype.segment()`
Segments.prototype.containing()
===============================

The **`containing()`** method of `Segments` instances returns an object describing the segment in the string that includes the code unit at the specified index.

Try it
------

Syntax
------


```js
containing(codeUnitIndex)
```

### Parameters

`codeUnitIndex` Optional

A number specifying the index of the code unit in the original input string. If the value is omitted, it defaults to `0`.

### Return value

An object describing the segment of the original string with the following properties, or `undefined` if the supplied index value is out of bounds.

`segment`

A string containing the segment extracted from the original input string.

`index`

The code unit index in the original input string at which the segment begins.

`input`

The complete input string that was segmented.

`isWordLike`

A boolean value only if `granularity` is `"word"`; otherwise, `undefined`. If `granularity` is `"word"`, then `isWordLike` is `true` when the segment is word-like (i.e., consists of letters/numbers/ideographs/etc.); otherwise, `false`.

Examples
--------


```js
// ┃0 1 2 3 4 5┃6┃7┃8┃9 ← code unit index
// ┃A l l o n s┃-┃y┃!┃ ← code unit
const input = "Allons-y!";

const segmenter = new Intl.Segmenter("fr", { granularity: "word" });
const segments = segmenter.segment(input);

let current = segments.containing();
// { index: 0, segment: "Allons", isWordLike: true }

current = segments.containing(4);
// { index: 0, segment: "Allons", isWordLike: true }

current = segments.containing(6);
// { index: 6, segment: "-", isWordLike: false }

current = segments.containing(current.index + current.segment.length);
// { index: 7, segment: "y", isWordLike: true }

current = segments.containing(current.index + current.segment.length);
// { index: 8, segment: "!", isWordLike: false }

current = segments.containing(current.index + current.segment.length);
// undefined
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-%segmentsprototype%.containing |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Segmenter`
* `Intl.Segmenter.prototype.segment()`
Intl.ListFormat.prototype.formatToParts()
=========================================

 The **`formatToParts()`** method of `Intl.ListFormat` instances
 returns an `Array` of objects representing the different components that
 can be used to format a list of values in a locale-aware fashion.

Try it
------

Syntax
------


```js
formatToParts(list)
```

### Parameters

`list`

An iterable object, such as an `Array`, to be formatted according to a locale.

### Return value

An `Array` of components which contains the formatted parts from the list.

Description
-----------

 Whereas `Intl.ListFormat.prototype.format()` returns a string being the formatted version
 of the list (according to the given locale and style options),
 `formatToParts()` returns an array of the different components of the
 formatted string.

 Each element of the resulting array has two properties: `type` and
 `value`. The `type` property may be either
 `"element"`, which refers to a value from the list, or
 `"literal"` which refers to a linguistic construct. The `value`
 property gives the content, as a string, of the token.

 The locale and style options used for formatting are given when constructing the
 `Intl.ListFormat` instance.

Examples
--------

### Using formatToParts


```js
const fruits = ["Apple", "Orange", "Pineapple"];
const myListFormat = new Intl.ListFormat("en-GB", {
  style: "long",
  type: "conjunction",
});

console.table(myListFormat.formatToParts(fruits));
// [
// { "type": "element", "value": "Apple" },
// { "type": "literal", "value": ", " },
// { "type": "element", "value": "Orange" },
// { "type": "literal", "value": ", and " },
// { "type": "element", "value": "Pineapple" }
// ]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.ListFormat.prototype.formatToParts |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.ListFormat`
* `Intl.ListFormat.prototype.format()`
* `Intl.RelativeTimeFormat.prototype.formatToParts()`
* `Intl.NumberFormat.prototype.formatToParts()`
* `Intl.DateTimeFormat.prototype.formatToParts()`