{"id":16118005,"url":"https://github.com/wessberg/intl-relative-time-format","last_synced_at":"2026-03-01T18:02:24.429Z","repository":{"id":57275400,"uuid":"165722477","full_name":"wessberg/intl-relative-time-format","owner":"wessberg","description":"A fully spec-compliant polyfill for 'Intl.RelativeTimeFormat'","archived":false,"fork":false,"pushed_at":"2019-07-04T23:35:09.000Z","size":298,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-27T21:57:50.439Z","etag":null,"topics":["ecma-402","ecmascript","ecmascript-internationalization-api","i18n","internationalization","intl","polyfill","relativetime","relativetimeformat","time-ago","timeago"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wessberg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-14T19:34:09.000Z","updated_at":"2025-03-21T03:16:26.000Z","dependencies_parsed_at":"2022-09-16T09:50:31.520Z","dependency_job_id":null,"html_url":"https://github.com/wessberg/intl-relative-time-format","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/wessberg/intl-relative-time-format","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fintl-relative-time-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fintl-relative-time-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fintl-relative-time-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fintl-relative-time-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wessberg","download_url":"https://codeload.github.com/wessberg/intl-relative-time-format/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wessberg%2Fintl-relative-time-format/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29977966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecma-402","ecmascript","ecmascript-internationalization-api","i18n","internationalization","intl","polyfill","relativetime","relativetimeformat","time-ago","timeago"],"created_at":"2024-10-09T20:48:19.964Z","updated_at":"2026-03-01T18:02:24.412Z","avatar_url":"https://github.com/wessberg.png","language":"TypeScript","funding_links":["https://www.patreon.com/bePatron?u=11315442"],"categories":[],"sub_categories":[],"readme":"\u003c!-- SHADOW_SECTION_LOGO_START --\u003e\n\n\u003cdiv\u003e\u003cimg alt=\"Logo\" src=\"https://raw.githubusercontent.com/wessberg/intl-relative-time-format/master/documentation/asset/logo.png\" height=\"50\"   /\u003e\u003c/div\u003e\n\n\u003c!-- SHADOW_SECTION_LOGO_END --\u003e\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_SHORT_START --\u003e\n\n\u003e A fully spec-compliant polyfill for 'Intl.RelativeTimeFormat'\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_SHORT_END --\u003e\n\n\u003c!-- SHADOW_SECTION_BADGES_START --\u003e\n\n\u003ca href=\"https://npmcharts.com/compare/intl-relative-time-format?minimal=true\"\u003e\u003cimg alt=\"Downloads per month\" src=\"https://img.shields.io/npm/dm/intl-relative-time-format.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/intl-relative-time-format\"\u003e\u003cimg alt=\"NPM version\" src=\"https://badge.fury.io/js/intl-relative-time-format.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://david-dm.org/wessberg/intl-relative-time-format\"\u003e\u003cimg alt=\"Dependencies\" src=\"https://img.shields.io/david/wessberg%2Fintl-relative-time-format.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/wessberg/intl-relative-time-format/graphs/contributors\"\u003e\u003cimg alt=\"Contributors\" src=\"https://img.shields.io/github/contributors/wessberg%2Fintl-relative-time-format.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/prettier/prettier\"\u003e\u003cimg alt=\"code style: prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"    /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.patreon.com/bePatron?u=11315442\"\u003e\u003cimg alt=\"Support on Patreon\" src=\"https://img.shields.io/badge/patreon-donate-green.svg\"    /\u003e\u003c/a\u003e\n\n\u003c!-- SHADOW_SECTION_BADGES_END --\u003e\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_LONG_START --\u003e\n\n## Description\n\n\u003c!-- SHADOW_SECTION_DESCRIPTION_LONG_END --\u003e\n\nThis is a 1:1 implementation of the [`Intl.RelativeTimeFormat`](https://github.com/tc39/proposal-intl-relative-time) draft spec proposal ECMA-402, or the ECMAScript® Internationalization API Specification.\n`Intl.RelativeTimeFormat` is a really useful low-level primitive to build on top of which avoids the need to parse lots of CLDR raw data at the expense of your users and their internet connections.\n\nIt builds upon other members of the `Intl` family such as `Intl.PluralRules`, `Intl.NumberFormat`, and `Intl.getCanonicalLocales`, so these must be polyfilled. [See this section for an overview](#dependencies--browser-support).\n\nThis implementation passes all 150 [Test262 Conformance tests](https://github.com/tc39/test262) from the Official ECMAScript Conformance Test Suite.\n\n\u003c!-- SHADOW_SECTION_FEATURES_START --\u003e\n\n### Features\n\n\u003c!-- SHADOW_SECTION_FEATURES_END --\u003e\n\nSome highlights of this polyfill include:\n\n- A very precise implementation of the spec, with cross-references inlined in the source code\n- Conditional loading of Locale data for all CLDR locales\n- Well-tested and well-documented.\n- Passes all Official ECMAScript Conformance Tests\n\n\u003c!-- SHADOW_SECTION_FEATURE_IMAGE_START --\u003e\n\n\u003c!-- SHADOW_SECTION_FEATURE_IMAGE_END --\u003e\n\n\u003c!-- SHADOW_SECTION_TOC_START --\u003e\n\n## Table of Contents\n\n- [Description](#description)\n  - [Features](#features)\n- [Table of Contents](#table-of-contents)\n- [Install](#install)\n  - [NPM](#npm)\n  - [Yarn](#yarn)\n- [Applying the polyfill](#applying-the-polyfill)\n- [Loading locale data](#loading-locale-data)\n- [Usage](#usage)\n  - [Intl.RelativeTimeFormat.prototype.format](#intlrelativetimeformatprototypeformat)\n  - [Intl.RelativeTimeFormat.prototype.formatToParts](#intlrelativetimeformatprototypeformattoparts)\n  - [Intl.RelativeTimeFormat.prototype.resolvedOptions](#intlrelativetimeformatprototyperesolvedoptions)\n  - [Intl.RelativeTimeFormat.supportedLocalesOf](#intlrelativetimeformatsupportedlocalesof)\n- [Dependencies \u0026 Browser support](#dependencies--browser-support)\n- [Contributing](#contributing)\n- [Maintainers](#maintainers)\n- [Backers](#backers)\n  - [Patreon](#patreon)\n- [FAQ](#faq)\n  - [What is the default locale?](#what-is-the-default-locale)\n  - [Are there any known quirks?](#are-there-any-known-quirks)\n- [License](#license)\n\n\u003c!-- SHADOW_SECTION_TOC_END --\u003e\n\n\u003c!-- SHADOW_SECTION_INSTALL_START --\u003e\n\n## Install\n\n### NPM\n\n```\n$ npm install intl-relative-time-format\n```\n\n### Yarn\n\n```\n$ yarn add intl-relative-time-format\n```\n\n\u003c!-- SHADOW_SECTION_INSTALL_END --\u003e\n\n## Applying the polyfill\n\nThe polyfill will check for the existence of `Intl.RelativeTimeFormat` and will _only_ be applied if the runtime doesn't already support it.\n\nTo include it, add this somewhere:\n\n```typescript\nimport \"intl-relative-time-format\";\n\n// Or with commonjs:\nrequire(\"intl-relative-time-format\");\n```\n\nHowever, it is strongly suggested that you only include the polyfill for runtimes that don't already support `Intl.RelativeTimeFormat`.\nOne way to do so is with an async import:\n\n```typescript\nif (!(\"RelativeTimeFormat\" in Intl)) {\n\tawait import(\"intl-relative-time-format\");\n\n\t// or with commonjs:\n\trequire(\"intl-relative-time-format\");\n}\n```\n\nAlternatively, you can use [Polyfill.app](https://github.com/wessberg/Polyfiller) which uses this polyfill and takes care of only loading the polyfill if needed as well as adding the language features that the polyfill depends on (See [dependencies](#dependencies--browser-support)).\n\n## Loading locale data\n\nBy default, no CLDR locale data is loaded. Instead, _you_ decide what data you want.\nTo load data, you can import it via the `/locale-data` subfolder that comes with the NPM package:\n\nWith ES modules:\n\n```typescript\n// Load the polyfill\nimport \"intl-relative-time-format\";\n\n// Load data for the 'en' locale\nimport \"intl-relative-time-format/locale-data/en\";\n```\n\nAnd naturally, it also works with commonjs:\n\n```typescript\n// Load the polyfill\nrequire(\"intl-relative-time-format\");\n\n// Load data for the 'en' locale\nrequire(\"intl-relative-time-format/locale-data/en\");\n```\n\nRemember, if you're also depending on a polyfilled version of `Intl.NumberFormat`, `Intl.getCanonicalLocales`, and/or `Intl.PluralRules`, you will need to import those polyfills beforehand.\n\n\u003c!-- SHADOW_SECTION_USAGE_START --\u003e\n\n## Usage\n\n\u003c!-- SHADOW_SECTION_USAGE_END --\u003e\n\nThe following examples are taken [directly from the original proposal](https://github.com/tc39/proposal-intl-relative-time)\n\n### Intl.RelativeTimeFormat.prototype.format\n\n```typescript\n// Create a relative time formatter in your locale\n// with default values explicitly passed in.\nconst rtf = new Intl.RelativeTimeFormat(\"en\", {\n\tlocaleMatcher: \"best fit\", // other values: \"lookup\"\n\tnumeric: \"always\", // other values: \"auto\"\n\tstyle: \"long\" // other values: \"short\" or \"narrow\"\n});\n\n// Format relative time using negative value (-1).\nrtf.format(-1, \"day\");\n// \u003e \"1 day ago\"\n\n// Format relative time using positive  value (1).\nrtf.format(1, \"day\");\n// \u003e \"in 1 day\"\n```\n\n```typescript\n// Create a relative time formatter in your locale\n// with numeric: \"auto\" option value passed in.\nconst rtf = new Intl.RelativeTimeFormat(\"en\", {numeric: \"auto\"});\n\n// Format relative time using negative value (-1).\nrtf.format(-1, \"day\");\n// \u003e \"yesterday\"\n\n// Format relative time using positive day unit (1).\nrtf.format(1, \"day\");\n// \u003e \"tomorrow\"\n```\n\n### Intl.RelativeTimeFormat.prototype.formatToParts\n\n```typescript\nconst rtf = new Intl.RelativeTimeFormat(\"en\", {numeric: \"auto\"});\n\n// Format relative time using the day unit.\nrtf.formatToParts(-1, \"day\");\n// \u003e [{ type: \"literal\", value: \"yesterday\"}]\n\nrtf.formatToParts(100, \"day\");\n// \u003e [{ type: \"literal\", value: \"in \" }, { type: \"integer\", value: \"100\", unit: \"day\" }, { type: \"literal\", value: \" days\" }]\n```\n\n### Intl.RelativeTimeFormat.prototype.resolvedOptions\n\n```typescript\nconst rtf = new Intl.RelativeTimeFormat(\"en\", {\n\tnumeric: \"always\",\n\tstyle: \"narrow\"\n});\n\nrtf.resolvedOptions();\n// \u003e [{ locale: \"en\", numberingSystem: \"latn\", numeric: \"always\", style: \"narrow\"}]\n```\n\n### Intl.RelativeTimeFormat.supportedLocalesOf\n\n```typescript\nIntl.RelativeTimeFormat.supportedLocalesOf([\"foo\", \"bar\", \"en-US\"]);\n// \u003e [\"en-US\"]\n```\n\n## Dependencies \u0026 Browser support\n\nThis polyfill is distributed in ES3-compatible syntax, but is using some additional APIs and language features which must be available:\n\n- `Array.prototype.includes`\n- `Object.create`\n- `Object.is`\n- `Number.prototype.toLocaleString`\n- `String.prototype.includes`\n- `String.prototype.replace`\n- `Symbol.toStringTag`,\n- `WeakMap`\n- `Intl.NumberFormat`\n- `Intl.PluralRules`\n- `Intl.getCanonicalLocales`\n\nFor by far the most browsers, these features will already be natively available.\nGenerally, I would highly recommend using something like [Polyfill.app](https://github.com/wessberg/Polyfiller) which takes care of this stuff automatically.\n\n\u003c!-- SHADOW_SECTION_CONTRIBUTING_START --\u003e\n\n## Contributing\n\nDo you want to contribute? Awesome! Please follow [these recommendations](./CONTRIBUTING.md).\n\n\u003c!-- SHADOW_SECTION_CONTRIBUTING_END --\u003e\n\n\u003c!-- SHADOW_SECTION_MAINTAINERS_START --\u003e\n\n## Maintainers\n\n| \u003cimg alt=\"Frederik Wessberg\" src=\"https://avatars2.githubusercontent.com/u/20454213?s=460\u0026v=4\" height=\"70\"   /\u003e                                             |\n| ----------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [Frederik Wessberg](mailto:frederikwessberg@hotmail.com)\u003cbr\u003e\u003cstrong\u003eTwitter\u003c/strong\u003e: [@FredWessberg](https://twitter.com/FredWessberg)\u003cbr\u003e_Lead Developer_ |\n\n\u003c!-- SHADOW_SECTION_MAINTAINERS_END --\u003e\n\n\u003c!-- SHADOW_SECTION_BACKERS_START --\u003e\n\n## Backers\n\n### Patreon\n\n[Become a backer](https://www.patreon.com/bePatron?u=11315442) and get your name, avatar, and Twitter handle listed here.\n\n\u003ca href=\"https://www.patreon.com/bePatron?u=11315442\"\u003e\u003cimg alt=\"Backers on Patreon\" src=\"https://patreon-badge.herokuapp.com/11315442.png\"  width=\"500\"  /\u003e\u003c/a\u003e\n\n\u003c!-- SHADOW_SECTION_BACKERS_END --\u003e\n\n\u003c!-- SHADOW_SECTION_FAQ_START --\u003e\n\n## FAQ\n\n\u003c!-- SHADOW_SECTION_FAQ_END --\u003e\n\n### What is the default locale?\n\nThe default locale will be equal to the locale file you load first.\n\n### Are there any known quirks?\n\nNope!\n\n\u003c!-- SHADOW_SECTION_LICENSE_START --\u003e\n\n## License\n\nMIT © [Frederik Wessberg](mailto:frederikwessberg@hotmail.com) ([@FredWessberg](https://twitter.com/FredWessberg)) ([Website](https://github.com/wessberg))\n\n\u003c!-- SHADOW_SECTION_LICENSE_END --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessberg%2Fintl-relative-time-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwessberg%2Fintl-relative-time-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessberg%2Fintl-relative-time-format/lists"}