The resolvedOptions()
method of Intl.PluralRules instances returns a new object with properties reflecting the locale and plural formatting options computed during initialization of this Intl.PluralRules
object.
Syntax
resolvedOptions()
Parameters
None.
Return value
A new object with properties reflecting the locale and plural formatting options computed during the initialization of the given Intl.PluralRules object.
The 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
.
- : 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
pluralCategories
- : An Array of plural categories used by the given locale, selected from the list
"zero"
,"one"
,"two"
,"few"
,"many"
and"other"
.
- : An Array of plural categories used by the given locale, selected from the list
type
- : The type used (
cardinal
orordinal
).
- : The type used (
roundingMode
- : The rounding mode.
This is the value provided for the
options.roundingMode
argument in the constructor, or the default value:halfExpand
.
- : The rounding mode.
This is the value provided for the
roundingPriority
- : The priority for resolving rounding conflicts if both "FractionDigits" and "SignificantDigits" are specified.
This is the value provided for the
options.roundingPriority
argument in the constructor, or the default value:auto
.
- : The priority for resolving rounding conflicts if both "FractionDigits" and "SignificantDigits" are specified.
This is the value provided for the
roundingIncrement
- : The rounding-increment precision (the increment used when rounding numbers).
This is the value specified in the
options.roundingIncrement
argument in the constructor.
- : The rounding-increment precision (the increment used when rounding numbers).
This is the value specified in the
trailingZeroDisplay
- : The strategy for displaying trailing zeros on whole numbers.
This is the value specified in the
options.trailingZeroDisplay
argument in the constructor, or the default value:"auto"
.
- : The strategy for displaying trailing zeros on whole numbers.
This is the value specified in the
Only one of the following two groups of properties is included:
minimumIntegerDigits
,minimumFractionDigits
,maximumFractionDigits
- : The values provided for these properties in the
options
argument or filled in as defaults. These properties are present only if neitherminimumSignificantDigits
normaximumSignificantDigits
was provided in theoptions
argument.
- : The values provided for these properties in the
minimumSignificantDigits
,maximumSignificantDigits
- : The values provided for these properties in the
options
argument or filled in as defaults. These properties are present only if at least one of them was provided in theoptions
argument.
- : The values provided for these properties in the
Examples
Using the resolvedOptions() method
The code below shows the construction of a PluralRules
object, followed by logging of each of the resolved options.
// Create a PluralRules instance
const de = new Intl.PluralRules("de-DE", {
maximumSignificantDigits: 2,
trailingZeroDisplay: "auto",
});
// Resolve the options
const usedOptions = de.resolvedOptions();
console.log(usedOptions.locale); // "de-DE"
console.log(usedOptions.pluralCategories); // Array ["one", "other"]
console.log(usedOptions.type); // "cardinal"
console.log(usedOptions.minimumIntegerDigits); // 1
console.log(usedOptions.minimumFractionDigits); // undefined (maximumSignificantDigits is set)
console.log(usedOptions.maximumFractionDigits); //undefined (maximumSignificantDigits is set)
console.log(usedOptions.minimumSignificantDigits); // 1
console.log(usedOptions.maximumSignificantDigits); //2
console.log(usedOptions.roundingIncrement); // 1
console.log(usedOptions.roundingMode); // "halfExpand"
console.log(usedOptions.roundingPriority); // "auto"
console.log(usedOptions.trailingZeroDisplay); // "auto"