formatUnitAbbr()function
formatUnitAbbr(unit: string, options?: UnitFormatOptions): string
| Param | Type | |
|---|---|---|
unit | string | Unit reference, e.g. "minute" or "product". required |
options | UnitFormatOptions | Options for quantity formatting. |
.one | string | String for one of this thing, e.g. product or item or sheep- Used for unitDisplay: "long" formatting.- Defaults to unit reference, e.g. "minute" readonly |
.many | string | String for several of this thing, e.g. products or items or sheep- Used for unitDisplay: "long" formatting.- Defaults to one + "s" readonly |
.abbr | string | Abbreviation for this thing, e.g. products or items or sheep (defaults to one + "s").- Used for unitDisplay: "narrow" formatting.- Defaults to unit reference, e.g. "minute" readonly |
| Return | |
|---|---|
string | The short name of the unit, e.g. "min". |
Format the short name of a unit on its own, e.g. "km" or "min", with no number.
- Uses the
Intl.NumberFormatshort name when the browser supports the unit, so the name is translated (e.g."Std."forhourin German). - Falls back to
options.abbr, then to the unit reference itself, when the browser does not support the unit. - Gives the name for an amount of one, so some units in some locales differ from their plural form (e.g.
"day"not"days").
Examples
formatUnitAbbr("kilometer") // "km"formatUnitAbbr("dog", { abbr: "🐶" }) // "🐶"