recursal/MDN huggingface dataset:
WeakSet.prototype.add()
=======================

The **`add()`** method of `WeakSet` instances appends a new object to the end of this `WeakSet`.

Try it
------

Syntax
------


```js
add(value)
```

### Parameters

`value`

Must be either an object or a non-registered symbol. The value to add to the `WeakSet` collection.

### Return value

The `WeakSet` object.

### Exceptions

`TypeError`

Thrown if `value` is not an object or a non-registered symbol.

Examples
--------

### Using add


```js
const ws = new WeakSet();

ws.add(window); // add the window object to the WeakSet

ws.has(window); // true

// WeakSet only takes objects as arguments
ws.add(1);
// results in "TypeError: Invalid value used in weak set" in Chrome
// and "TypeError: 1 is not a non-null object" in Firefox
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-weakset.prototype.add |

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

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

See also
--------

* `WeakSet`
* `WeakSet.prototype.delete()`
* `WeakSet.prototype.has()`
WeakSet.prototype.has()
=======================

 The **`has()`** method of `WeakSet` instances returns a boolean indicating whether an
 object exists in this `WeakSet` or not.

Try it
------

Syntax
------


```js
has(value)
```

### Parameters

`value`

The value to test for presence in the `WeakSet`.

### Return value

Returns `true` if an element with the specified value exists in the `WeakSet` object; otherwise `false`. Always returns `false` if `value` is not an object or a non-registered symbol.

Examples
--------

### Using the `has()` method


```js
const ws = new WeakSet();
const obj = {};
ws.add(window);

ws.has(window); // returns true
ws.has(obj); // returns false

// Storing a non-registered symbol
const sym = Symbol("foo");
ws.add(sym);
ws.add(Symbol.iterator);
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-weakset.prototype.has |

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

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

See also
--------

* `WeakSet`
* `WeakSet.prototype.add()`
* `WeakSet.prototype.delete()`
BigUint64Array() constructor
============================

The **`BigUint64Array()`** constructor creates `BigUint64Array` objects. The contents are initialized to `0n`.

Syntax
------


```js
new BigUint64Array()
new BigUint64Array(length)
new BigUint64Array(typedArray)
new BigUint64Array(object)

new BigUint64Array(buffer)
new BigUint64Array(buffer, byteOffset)
new BigUint64Array(buffer, byteOffset, length)
```


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

### Parameters

See `TypedArray`.

### Exceptions

See `TypedArray`.

Examples
--------

### Different ways to create a BigUint64Array


```js
// From a length
const biguint64 = new BigUint64Array(2);
biguint64[0] = 42n;
console.log(biguint64[0]); // 42n
console.log(biguint64.length); // 2
console.log(biguint64.BYTES\_PER\_ELEMENT); // 8

// From an array
const x = new BigUint64Array([21n, 31n]);
console.log(x[1]); // 31n

// From another TypedArray
const y = new BigUint64Array(x);
console.log(y[0]); // 21n

// From an ArrayBuffer
const buffer = new ArrayBuffer(64);
const z = new BigUint64Array(buffer, 8, 4);
console.log(z.byteOffset); // 8

// From an iterable
const iterable = (function\* () {
  yield\* [1n, 2n, 3n];
})();
const biguint64FromIterable = new BigUint64Array(iterable);
console.log(biguint64FromIterable);
// BigUint64Array [1n, 2n, 3n]
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-typedarray-constructors |

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

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

See also
--------

* JavaScript typed arrays guide
* `TypedArray`
* `ArrayBuffer`
* `DataView`
Float32Array() constructor
==========================

The **`Float32Array()`** constructor creates `Float32Array` objects. The contents are initialized to `0`.

Syntax
------


```js
new Float32Array()
new Float32Array(length)
new Float32Array(typedArray)
new Float32Array(object)

new Float32Array(buffer)
new Float32Array(buffer, byteOffset)
new Float32Array(buffer, byteOffset, length)
```


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

### Parameters

See `TypedArray`.

### Exceptions

See `TypedArray`.

Examples
--------

### Different ways to create a Float32Array


```js
// From a length
const float32 = new Float32Array(2);
float32[0] = 42;
console.log(float32[0]); // 42
console.log(float32.length); // 2
console.log(float32.BYTES\_PER\_ELEMENT); // 4

// From an array
const x = new Float32Array([21, 31]);
console.log(x[1]); // 31

// From another TypedArray
const y = new Float32Array(x);
console.log(y[0]); // 21

// From an ArrayBuffer
const buffer = new ArrayBuffer(32);
const z = new Float32Array(buffer, 4, 4);
console.log(z.byteOffset); // 4

// From an iterable
const iterable = (function\* () {
  yield\* [1, 2, 3];
})();
const float32FromIterable = new Float32Array(iterable);
console.log(float32FromIterable);
// Float32Array [1, 2, 3]
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-typedarray-constructors |

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

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

See also
--------

* Polyfill of `Float32Array` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `ArrayBuffer`
* `DataView`
Intl.DurationFormat
===================

**Experimental:** **This is an experimental technology**  
Check the Browser compatibility table carefully before using this in production.

The **`Intl.DurationFormat`** object enables language-sensitive duration formatting.

Constructor
-----------

`Intl.DurationFormat()` 
Experimental

Creates a new `Intl.DurationFormat` object.

Static methods
--------------

`Intl.DurationFormat.supportedLocalesOf()` 
Experimental

Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance properties
-------------------

These properties are defined on `Intl.DurationFormat.prototype` and shared by all `Intl.DurationFormat` instances.

`Intl.DurationFormat.prototype.constructor`

The constructor function that created the instance object. For `Intl.DurationFormat` instances, the initial value is the `Intl.DurationFormat` constructor.

`Intl.DurationFormat.prototype[@@toStringTag]`

The initial value of the `@@toStringTag` property is the string `"Intl.DurationFormat"`. This property is used in `Object.prototype.toString()`.

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

`Intl.DurationFormat.prototype.format()` 
Experimental

Getter function that formats a duration according to the locale and formatting options of this `DurationFormat` object.

`Intl.DurationFormat.prototype.formatToParts()` 
Experimental

Returns an `Array` of objects representing the formatted duration in parts.

`Intl.DurationFormat.prototype.resolvedOptions()` 
Experimental

Returns a new object with properties reflecting the locale and formatting options computed during initialization of the object.

Examples
--------

### Using Intl.DurationFormat

The examples below show how to use the `Intl.DurationFormat` object to format a duration object with various locales and styles.


```js
const duration = {
  hours: 1,
  minutes: 46,
  seconds: 40,
};

// With style set to "long" and locale "fr-FR"
new Intl.DurationFormat("fr-FR", { style: "long" }).format(duration);
// "1 heure, 46 minutes et 40 secondes"

// With style set to "short" and locale "en"
new Intl.DurationFormat("en", { style: "short" }).format(duration);
// "1 hr, 46 min and 40 sec"

// With style set to "short" and locale "pt"
new Intl.DurationFormat("pt", { style: "narrow" }).format(duration);
// "1h 46min 40s"
```

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

| Specification |
| --- |
| Intl.DurationFormat # durationformat-objects |

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

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

See also
--------

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

The **`Intl.Segmenter`** object enables locale-sensitive text segmentation, enabling you to get meaningful items (graphemes, words or sentences) from a string.

Try it
------

Constructor
-----------

`Intl.Segmenter()`

Creates a new `Intl.Segmenter` object.

Static methods
--------------

`Intl.Segmenter.supportedLocalesOf()`

Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance properties
-------------------

These properties are defined on `Intl.Segmenter.prototype` and shared by all `Intl.Segmenter` instances.

`Intl.Segmenter.prototype.constructor`

The constructor function that created the instance object. For `Intl.Segmenter` instances, the initial value is the `Intl.Segmenter` constructor.

`Intl.Segmenter.prototype[@@toStringTag]`

The initial value of the `@@toStringTag` property is the string `"Intl.Segmenter"`. This property is used in `Object.prototype.toString()`.

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

`Intl.Segmenter.prototype.resolvedOptions()`

Returns a new object with properties reflecting the locale and granularity options computed during initialization of this `Intl.Segmenter` object.

`Intl.Segmenter.prototype.segment()`

Returns a new iterable `Segments` instance representing the segments of a string according to the locale and granularity of this `Intl.Segmenter` instance.

Examples
--------

### Basic usage and difference from String.prototype.split()

If we were to use `String.prototype.split(" ")` to segment a text in words, we would not get the correct result if the locale of the text does not use whitespaces between words (which is the case for Japanese, Chinese, Thai, Lao, Khmer, Myanmar, etc.).


```js
const str = "吾輩は猫である。名前はたぬき。";
console.table(str.split(" "));
// ['吾輩は猫である。名前はたぬき。']
// The two sentences are not correctly segmented.
```



```js
const str = "吾輩は猫である。名前はたぬき。";
const segmenterJa = new Intl.Segmenter("ja-JP", { granularity: "word" });

const segments = segmenterJa.segment(str);
console.table(Array.from(segments));
// [{segment: '吾輩', index: 0, input: '吾輩は猫である。名前はたぬき。', isWordLike: true},
// etc.
// ]
```

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

| Specification |
| --- |
| ECMAScript Internationalization API Specification # segmenter-objects |

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

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

 The **`Intl.getCanonicalLocales()`** static method returns an array
 containing the canonical locale names. Duplicates will be omitted and elements will be
 validated as structurally valid language tags.

Try it
------

Syntax
------


```js
Intl.getCanonicalLocales(locales)
```

### Parameters

`locales`

A list of `String` values for which to get the canonical locale names.

### Return value

An array containing the canonical locale names.

Examples
--------

### Using getCanonicalLocales


```js
Intl.getCanonicalLocales("EN-US"); // ["en-US"]
Intl.getCanonicalLocales(["EN-US", "Fr"]); // ["en-US", "fr"]

Intl.getCanonicalLocales("EN\_US");
// RangeError:'EN\_US' is not a structurally valid language tag
```

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

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.getcanonicallocales |

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

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

See also
--------

* Polyfill of `Intl.getCanonicalLocales` in FormatJS
* `Intl.NumberFormat.supportedLocalesOf()`
* `Intl.DateTimeFormat.supportedLocalesOf()`
* `Intl.Collator.supportedLocalesOf()`
Intl.RelativeTimeFormat
=======================

The **`Intl.RelativeTimeFormat`** object enables language-sensitive relative time formatting.

Try it
------

Constructor
-----------

`Intl.RelativeTimeFormat()`

Creates a new `Intl.RelativeTimeFormat` object.

Static methods
--------------

`Intl.RelativeTimeFormat.supportedLocalesOf()`

Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance properties
-------------------

These properties are defined on `Intl.RelativeTimeFormat.prototype` and shared by all `Intl.RelativeTimeFormat` instances.

`Intl.RelativeTimeFormat.prototype.constructor`

The constructor function that created the instance object. For `Intl.RelativeTimeFormat` instances, the initial value is the `Intl.RelativeTimeFormat` constructor.

`Intl.RelativeTimeFormat.prototype[@@toStringTag]`

The initial value of the `@@toStringTag` property is the string `"Intl.RelativeTimeFormat"`. This property is used in `Object.prototype.toString()`.

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

`Intl.RelativeTimeFormat.prototype.format()`

Formats a `value` and a `unit` according to the locale and formatting options of the given `Intl.RelativeTimeFormat` object.

`Intl.RelativeTimeFormat.prototype.formatToParts()`

Returns an `Array` of objects representing the relative time format in parts that can be used for custom locale-aware formatting.

`Intl.RelativeTimeFormat.prototype.resolvedOptions()`

Returns a new object with properties reflecting the locale and formatting options computed during initialization of the object.

Examples
--------

### Basic format usage

The following example shows how to use a relative time formatter for 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 formatToParts

The following example shows how to create a relative time formatter returning formatted parts.


```js
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

// Format relative time using the day unit.
rtf.formatToParts(-1, "day");
// [{ type: "literal", value: "yesterday"}]

rtf.formatToParts(100, "day");
// [
// { type: "literal", value: "in " },
// { type: "integer", value: "100", unit: "day" },
// { type: "literal", value: " days" }
// ]
```

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

| Specification |
| --- |
| ECMAScript Internationalization API Specification # relativetimeformat-objects |

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

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

See also
--------

* Polyfill of `Intl.RelativeTimeFormat` in FormatJS
* `Intl`
* `Intl.RelativeTimeFormat` on v8.dev (2018)
Intl.supportedValuesOf()
========================

The **`Intl.supportedValuesOf()`** static method returns an array containing the supported calendar, collation, currency, numbering systems, or unit values supported by the implementation.

Duplicates are omitted and the array is sorted in ascending lexicographical order (or more precisely, using `Array.prototype.sort()` with an `undefined` compare function).

 The method can be used to feature-test whether values are supported in a particular implementation and download a polyfill only if necessary.
 It can also be used to build UIs that allow users to select their preferred localized values, for example when the UI is created from WebGL or server-side.

Try it
------

Syntax
------


```js
Intl.supportedValuesOf(key)
```

### Parameters

`key`

A key string indicating the category of values to be returned. This is one of: `"calendar"`, `"collation"`, `"currency"`, `"numberingSystem"`, `"timeZone"`, `"unit"`.

### Return value

A sorted array of unique string values indicating the values supported by the implementation for the given key.

### Exceptions

`RangeError`

Thrown if an unsupported key was passed as a parameter.

Examples
--------

### Feature testing

You can check that the method is supported by comparing to `undefined`:


```js
if (typeof Intl.supportedValuesOf !== "undefined") {
  // method is supported
}
```

### Get all values for key

 To get the supported values for calendar you call the method with the key `"calendar"`.
 You can then iterate through the returned array as shown below:


```js
Intl.supportedValuesOf("calendar").forEach((calendar) => {
  // "buddhist", "chinese", "coptic", "dangi", etc.
});
```


**Note:** The array returned for calendar values will always include the value "gregory" (gregorian).

The other values are all obtained in the same way:


```js
Intl.supportedValuesOf("collation").forEach((collation) => {
  // "compat", "dict", "emoji", etc.
});

Intl.supportedValuesOf("currency").forEach((currency) => {
  // "ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", etc.
});

Intl.supportedValuesOf("numberingSystem").forEach((numberingSystem) => {
  // "adlm", "ahom", "arab", "arabext", "bali", etc.
});

Intl.supportedValuesOf("timeZone").forEach((timeZone) => {
  // "Africa/Abidjan", "Africa/Accra", "Africa/Addis\_Ababa", "Africa/Algiers", etc.
});

Intl.supportedValuesOf("unit").forEach((unit) => {
  // "acre", "bit", "byte", "celsius", "centimeter", etc.
});
```

### Invalid key throws RangeError


```js
try {
  Intl.supportedValuesOf("someInvalidKey");
} catch (err) {
  //Error: RangeError: invalid key: "someInvalidKey"
}
```

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

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.supportedvaluesof |

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

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

See also
--------

* Polyfill of `Intl.supportedValuesOf` in FormatJS
* `Intl`
Intl.ListFormat
===============

The **`Intl.ListFormat`** object enables language-sensitive list formatting.

Try it
------

Constructor
-----------

`Intl.ListFormat()`

Creates a new `Intl.ListFormat` object.

Static methods
--------------

`Intl.ListFormat.supportedLocalesOf()`

Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance properties
-------------------

These properties are defined on `Intl.ListFormat.prototype` and shared by all `Intl.ListFormat` instances.

`Intl.ListFormat.prototype.constructor`

The constructor function that created the instance object. For `Intl.ListFormat` instances, the initial value is the `Intl.ListFormat` constructor.

`Intl.ListFormat.prototype[@@toStringTag]`

The initial value of the `@@toStringTag` property is the string `"Intl.ListFormat"`. This property is used in `Object.prototype.toString()`.

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

`Intl.ListFormat.prototype.format()`

Returns a language-specific formatted string representing the elements of the list.

`Intl.ListFormat.prototype.formatToParts()`

Returns an array of objects representing the different components that can be used to format a list of values in a locale-aware fashion.

`Intl.ListFormat.prototype.resolvedOptions()`

Returns a new object with properties reflecting the locale and style formatting options computed during the construction of the current `Intl.ListFormat` object.

Examples
--------

### Using format

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


```js
const list = ["Motorcycle", "Bus", "Car"];

console.log(
  new Intl.ListFormat("en-GB", { style: "long", type: "conjunction" }).format(
    list,
  ),
);
// Motorcycle, Bus and Car

console.log(
  new Intl.ListFormat("en-GB", { style: "short", type: "disjunction" }).format(
    list,
  ),
);
// Motorcycle, Bus or Car

console.log(
  new Intl.ListFormat("en-GB", { style: "narrow", type: "unit" }).format(list),
);
// Motorcycle Bus Car
```

### Using formatToParts

The following example shows how to create a List formatter returning formatted parts


```js
const list = ["Motorcycle", "Bus", "Car"];
console.log(
  new Intl.ListFormat("en-GB", {
    style: "long",
    type: "conjunction",
  }).formatToParts(list),
);

// [ { "type": "element", "value": "Motorcycle" },
// { "type": "literal", "value": ", " },
// { "type": "element", "value": "Bus" },
// { "type": "literal", "value": ", and " },
// { "type": "element", "value": "Car" } ];
```

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

| Specification |
| --- |
| ECMAScript Internationalization API Specification # listformat-objects |

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

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

See also
--------

* Polyfill of `Intl.ListFormat` in FormatJS
* `Intl`
Intl.Collator.prototype.compare()
=================================

 The **`compare()`** method of `Intl.Collator` instances compares two
 strings according to the sort order of this collator object.

Try it
------

Syntax
------


```js
compare(string1, string2)
```

### Parameters

`string1`, `string2`

The strings to compare against each other.

### Return value

A number indicating how `string1` and `string2` compare to each other according to the sort order of this `Intl.Collator` object:

* A negative value if `string1` comes before `string2`;
* A positive value if `string1` comes after `string2`;
* 0 if they are considered equal.
Examples
--------

### Using compare for array sort

 Use the `compare` function for sorting arrays. Note that the function
 is bound to the collator from which it was obtained, so it can be passed directly to
 `Array.prototype.sort()`.


```js
const a = ["Offenbach", "Österreich", "Odenwald"];
const collator = new Intl.Collator("de-u-co-phonebk");
a.sort(collator.compare);
console.log(a.join(", ")); // "Odenwald, Österreich, Offenbach"
```

### Using compare for array search

Use the `compare` function for finding matching strings in arrays:


```js
const a = ["Congrès", "congres", "Assemblée", "poisson"];
const collator = new Intl.Collator("fr", {
  usage: "search",
  sensitivity: "base",
});
const s = "congres";
const matches = a.filter((v) => collator.compare(v, s) === 0);
console.log(matches.join(", ")); // "Congrès, congres"
```

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

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.collator.prototype.compare |

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

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

See also
--------

* `Intl.Collator`
* `String.prototype.localeCompare()`