Standard built-ins
Intl.RelativeTimeFormat.prototype.formatToParts()
Return typed parts of relative expression, including unit annotations for numeric components.
Formal Syntax & Structure
javascript syntaxjavascript
formatter.formatToParts(value, unit)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| value | Number | Signed quantity. |
| unit | String | Supported temporal unit, e.g. day or hour. |
Return Value
Array
Relative-time parts.
Working Example
Example Snippetjavascript
const f=new Intl.RelativeTimeFormat("en");console.log(f.formatToParts(-2,"day").some(p=>p.type==="integer"));