{"_id":"@ember-intl/intl-relativeformat","_rev":"11-92ff698c27845a94e31713542fbb1ff6","name":"@ember-intl/intl-relativeformat","dist-tags":{"latest":"2.1.0"},"versions":{"2.1.0":{"name":"@ember-intl/intl-relativeformat","version":"2.1.0","keywords":["intl","i18n","relative","moment","format","date"],"author":{"name":"Caridy Patino","email":"caridy@gmail.com"},"license":"BSD-3-Clause","_id":"@ember-intl/intl-relativeformat@2.1.0","maintainers":[{"name":"jasonmit","email":"jason.mitchell.w@gmail.com"}],"contributors":[{"name":"Eric Ferraiuolo","email":"edf@ericf.me"}],"homepage":"https://github.com/yahoo/intl-relativeformat","bugs":{"url":"https://github.com/yahoo/intl-relativeformat/issues"},"dist":{"shasum":"b711accb0bb1de44895715223b58bc626c48dec0","tarball":"https://registry.npmjs.org/@ember-intl/intl-relativeformat/-/intl-relativeformat-2.1.0.tgz","fileCount":265,"integrity":"sha512-HjN1xva7lHVYFAsMhP069CP1Y24iQ2zpQijWgKzkG6gXN+EWyK19MVNGuOAmu+XEKRiBdVUPtblF0fgx2mv8IQ==","signatures":[{"sig":"MEUCIQCTdRFTDmr3d/Q0F88WcIj3mh8KbGYRA94lcBDt3ChzxgIgLs2cOdosy7VCUFQsu5Z7u1JLWEkvsdfchQJS57AScro=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8798363,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbu/b3CRA9TVsSAnZWagAAjr0P+QBxCSwXS++EDrzXMeTv\nE4LTvSH9SZ4tRN/BTK7Zdx7PBgckjU15BvvLUa3T6tjsOZglDl5pFNupvw5Q\n15XPAidinscEEJzUFAtm3JSQzODhBGQo3k/gHHrv7LCBfXVuNYo+MC8PYfVK\n9EhW4wAyBHHY/PW4AMO5180Gqjx7fh3ybqB4MY5qA7l4dtlwuBBR+mVeBcyl\nLIS5jMAkC7Q+ZKYyhWRtEm3zmmkr2JNa/IkJ3KPHN7UXaltruHFuzUpuiOy3\nE5RzCltfZjD2dt+JbfyDv+i+TLnYxMdebX9Sdp0yRlwrranCcggj8g7JLQ2b\nao2GlOc+TPd1S5dUUZNBlL4Zx6X0uXC+kctS+k6ImI76eP6qKdxKEtEK/6iP\nxDBixTgn4v73ceraDGdYRHvUCw86UOdC3lAf0sDQ0GEEKsygyU7Ly9H3Ps0o\nChtT3Ij8apSjcIw6FuCSlkjO9l8wpOasXYcxl21CA8f+OebWvcCaGBxaXcjm\nsnO3Mcc0s/T7mQeTXI9428zkBTkAupvaZMcRNmcXMVzDQoI4L9lgtzrmEFzp\n2mqg931dtckXGCteL8KHSBtWiYcBQcwugFCZgrDQP+07YyNPuQZ6Ixuk2wkY\nCURKCiX6UatpNmmMAWGz0vMsxVcA1zte5fBmPj9CXQyQGeOA9bsyM+At7Gxb\nELoY\r\n=SNgK\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","browser":{"./lib/locales":false,"./lib/locales.js":false},"gitHead":"2509852f24ad5e2cd416678d8a40658768beb540","scripts":{"test":"istanbul cover -x lib/locales.js -- _mocha tests/runner.js --reporter spec","travis":"istanbul cover -x lib/locales.js -- _mocha tests/runner.js --reporter spec && tests/saucelabs.sh","prepublish":"grunt"},"_npmUser":{"name":"jasonmit","email":"jason.mitchell.w@gmail.com"},"repository":{"url":"git+ssh://git@github.com/yahoo/intl-relativeformat.git","type":"git"},"_npmVersion":"6.1.0","description":"Formats JavaScript dates to relative time strings.","directories":{"test":"tests"},"jsnext:main":"src/main.js","_nodeVersion":"10.7.0","dependencies":{"@ember-intl/intl-messageformat":"^2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"intl":"^0.1.4","grunt":"^0.4.5","mocha":"^2.0.1","moment":"^2.8.2","istanbul":"^0.3.2","benchmark":"^1.0.0","expect.js":"^0.3.1","grunt-cli":"^0.1.13","xunit-file":"0.0.6","grunt-benchmark":"^0.3.0","grunt-saucelabs":"^8.3.2","grunt-browserify":"^3.3.0","grunt-contrib-copy":"^0.8.0","grunt-contrib-clean":"^0.6.0","grunt-contrib-concat":"^0.5.0","grunt-contrib-jshint":"^0.11.0","grunt-contrib-uglify":"^0.8.0","grunt-contrib-connect":"^0.9.0","grunt-bundle-jsnext-lib":"^0.5.0","grunt-extract-cldr-data":"^4.1.0","grunt-json-remove-fields":"git://github.com/ericf/grunt-json-remove-fields.git#improve-files-and-output"},"_npmOperationalInternal":{"tmp":"tmp/intl-relativeformat_2.1.0_1539045110550_0.9508993706881856","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-10-09T00:31:50.414Z","modified":"2026-04-01T18:00:27.503Z","2.1.0":"2018-10-09T00:31:50.865Z"},"bugs":{"url":"https://github.com/yahoo/intl-relativeformat/issues"},"author":{"name":"Caridy Patino","email":"caridy@gmail.com"},"license":"BSD-3-Clause","homepage":"https://github.com/yahoo/intl-relativeformat","keywords":["intl","i18n","relative","moment","format","date"],"repository":{"url":"git+ssh://git@github.com/yahoo/intl-relativeformat.git","type":"git"},"description":"Formats JavaScript dates to relative time strings.","contributors":[{"name":"Eric Ferraiuolo","email":"edf@ericf.me"}],"maintainers":[{"email":"isaacjlee@hotmail.com","name":"ijlee2"},{"email":"jason.mitchell.w@gmail.com","name":"jasonmit"},{"email":"jan@buschtoens.me","name":"buschtoens"}],"readme":"Intl RelativeFormat\n===================\n\nFormats JavaScript dates to relative time strings (e.g., \"3 hours ago\").\n\n[![npm Version][npm-badge]][npm]\n[![Build Status][travis-badge]][travis]\n[![Dependency Status][david-badge]][david]\n\n[![Sauce Test Status][sauce-badge]][sauce]\n\n\nOverview\n--------\n\n### Goals\n\nThis package aims to provide a way to format different variations of relative time. You can use this package in the browser and on the server via Node.js.\n\nThis implementation is very similar to [moment.js][], in concept, although it provides only formatting features based on the Unicode [CLDR][] locale data, an industry standard that supports more than 200 languages.\n\n_Note: This `IntlRelativeFormat` API may change to stay in sync with ECMA-402, but this package will follow [semver][]._\n\n### How It Works\n\nThis API is very similar to [ECMA 402][]'s [DateTimeFormat][] and [NumberFormat][].\n\n```js\nvar rf = new IntlRelativeFormat(locales, [options]);\n```\n\nThe `locales` can either be a single language tag, e.g., `\"en-US\"` or an array of them from which the first match will be used. `options` provides a way to control the output of the formatted relative time string.\n\n```js\nvar output = rf.format(someDate, [options]);\n```\n\n### Common Usage Example\n\nThe most common way to use this library is to construct an `IntlRelativeFormat` instance and reuse it many times for formatting different date values; e.g.:\n\n```js\nvar rf = new IntlRelativeFormat('en-US');\n\nvar posts = [\n    {\n        id   : 1,\n        title: 'Some Blog Post',\n        date : new Date(1426271670524)\n    },\n    {\n        id   : 2,\n        title: 'Another Blog Post',\n        date : new Date(1426278870524)\n    }\n];\n\nposts.forEach(function (post) {\n    console.log(rf.format(post.date));\n});\n// => \"3 hours ago\"\n// => \"1 hour ago\"\n```\n\n### Features\n\n* Uses industry standards [CLDR locale data][CLDR].\n\n* Style options for `\"best fit\"` (\"yesterday\") and `\"numeric\"` (\"1 day ago\") output.\n\n* Units options for always rendering in a particular unit; e.g. \"30 days ago\", instead of \"1 month ago\".\n\n* Ability to specify the \"now\" value from which the relative time is calculated, allowing `format()`.\n\n*  Formats numbers in relative time strings using [`Intl.NumberFormat`][NumberFormat].\n\n* Optimized for repeated calls to an `IntlRelativeFormat` instance's `format()` method.\n\n\nUsage\n-----\n\n### `Intl` Dependency\n\nThis package assumes that the [`Intl`][Intl] global object exists in the runtime. `Intl` is present in all modern browsers, and there's work happening to [integrate `Intl` into Node.js][Intl-Node].\n\n**Luckly, there's the [Intl.js][] polyfill!** You will need to conditionally load the polyfill if you want to support runtimes which `Intl` is not already built-in. See [Browser compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Browser_compatibility) if you have doubts.\n\n### Loading IntlRelativeFormat in Node.js\n\nInstall package and polyfill:\n\n```bash\nnpm install intl-relativeformat --save\nnpm install intl --save\n```\n\nSimply `require()` this package:\n\n```js\nif (!global.Intl) {\n    global.Intl = require('intl'); // polyfill for `Intl`\n}\nvar IntlRelativeFormat = require('intl-relativeformat');\nvar rf = new IntlRelativeFormat('en');\nvar output = rf.format(dateValue);\n```\n\n_Note: in Node.js, the data for all 200+ languages is loaded along with the library._\n\n### Loading IntlRelativeFormat in a browser\n\nIf the browser does not already have the `Intl` APIs built-in, the Intl.js Polyfill will need to be loaded on the page along with the locale data for any locales that need to be supported:\n\n```html\n<script src=\"intl/Intl.min.js\"></script>\n<script src=\"intl/locale-data/jsonp/en-US.js\"></script>\n```\n\n_Note: Modern browsers already have the `Intl` APIs built-in, so you can load the Intl.js Polyfill conditionally, by for checking for `window.Intl`._\n\nInclude the library in your page:\n\n```html\n<script src=\"intl-relativeformat/dist/intl-relativeformat.min.js\"></script>\n```\n\nBy default, Intl RelativeFormat ships with the locale data for English (`en`) built-in to the runtime library. When you need to format data in another locale, include its data; e.g., for French:\n\n```html\n<script src=\"intl-relativeformat/dist/locale-data/fr.js\"></script>\n```\n\n_Note: All 200+ languages supported by this package use their root BCP 47 language tag; i.e., the part before the first hyphen (if any)._\n\n### Bundling IntlRelativeFormat with Browserify/Webpack\n\nInstall package:\n\n```bash\nnpm install intl-relativeformat --save\n```\n\nSimply `require()` this package and the specific locales you wish to support in the bundle:\n\n```js\nvar IntlRelativeFormat = require('intl-relativeformat');\nrequire('intl-relativeformat/dist/locale-data/en.js');\nrequire('intl-relativeformat/dist/locale-data/fr.js');\n```\n\n_Note: in Node.js, the data for all 200+ languages is loaded along with the library, but when bundling it with Browserify/Webpack, the data is intentionally ignored (see `package.json` for more details) to avoid blowing up the size of the bundle with data that you might not need._\n\n### Public API\n\n#### `IntlRelativeFormat` Constructor\n\nTo format a date to relative time, use the `IntlRelativeFormat` constructor. The constructor takes two parameters:\n\n - **locales** - _{String | String[]}_ - A string with a BCP 47 language tag, or an array of such strings. If you do not provide a locale, the default locale will be used. When an array of locales is provided, each item and its ancestor locales are checked and the first one with registered locale data is returned. **See: [Locale Resolution](#locale-resolution) for more details.**\n\n - **[options]** - _{Object}_ - Optional object with user defined options for format styles.\n **See: [Custom Options](#custom-options) for more details.**\n\n_Note: The `rf` instance should be enough for your entire application, unless you want to use custom options._\n\n#### Locale Resolution\n\n`IntlRelativeFormat` uses a locale resolution process similar to that of the built-in `Intl` APIs to determine which locale data to use based on the `locales` value passed to the constructor. The result of this resolution process can be determined by call the `resolvedOptions()` prototype method.\n\nThe following are the abstract steps `IntlRelativeFormat` goes through to resolve the locale value:\n\n* If no extra locale data is loaded, the locale will _always_ resolved to `\"en\"`.\n\n* If locale data is missing for a leaf locale like `\"fr-FR\"`, but there _is_ data for one of its ancestors, `\"fr\"` in this case, then its ancestor will be used.\n\n* If there's data for the specified locale, then that locale will be resolved; i.e.,\n\n    ```js\n    var rf = new IntlRelativeFormat('en-US');\n    assert(rf.resolvedOptions().locale === 'en-US'); // true\n    ```\n\n* The resolved locales are now normalized; e.g., `\"en-us\"` will resolve to: `\"en-US\"`.\n\n_Note: When an array is provided for `locales`, the above steps happen for each item in that array until a match is found._\n\n#### Custom Options\n\nThe optional second argument `options` provides a way to customize how the relative time will be formatted.\n\n##### Units\n\nBy default, the relative time is computed to the best fit unit, but you can explicitly call it to force `units` to be displayed in `\"second\"`, `\"second-short\"`, `\"minute\"`, `\"minute-short\"`, `\"hour\"`, `\"hour-short\"`, `\"day\"`, `\"day-short\"`, `\"month\"`, `\"month-short\"`, `\"year\"` or `\"year-short\"`:\n\n```js\nvar rf = new IntlRelativeFormat('en', {\n    units: 'day'\n});\nvar output = rf.format(dateValue);\n```\n\nAs a result, the output will be \"70 days ago\" instead of \"2 months ago\".\n\n##### Style\n\nBy default, the relative time is computed as `\"best fit\"`, which means that instead of \"1 day ago\", it will display \"yesterday\", or \"in 1 year\" will be \"next year\", etc. But you can force to always use the \"numeric\" alternative:\n\n```js\nvar rf = new IntlRelativeFormat('en', {\n    style: 'numeric'\n});\nvar output = rf.format(dateValue);\n```\n\nAs a result, the output will be \"1 day ago\" instead of \"yesterday\".\n\n#### `resolvedOptions()` Method\n\nThis method returns an object with the options values that were resolved during instance creation. It currently only contains a `locale` property; here's an example:\n\n```js\nvar rf = new IntlRelativeFormat('en-us');\nconsole.log(rf.resolvedOptions().locale); // => \"en-US\"\n```\n\nNotice how the specified locale was the all lower-case value: `\"en-us\"`, but it was resolved and normalized to: `\"en-US\"`.\n\n#### `format(date, [options])` Method\n\nThe format method (_which takes a JavaScript date or timestamp_) and optional `options` arguments will compare the `date` with \"now\" (or `options.now`), and returns the formatted string; e.g., \"3 hours ago\" in the corresponding locale passed into the constructor.\n\n```js\nvar output = rf.format(new Date());\nconsole.log(output); // => \"now\"\n```\n\nIf you wish to specify a \"now\" value, it can be provided via `options.now` and will be used instead of querying `Date.now()` to get the current \"now\" value.\n\n\nLicense\n-------\n\nThis software is free to use under the Yahoo! Inc. BSD license.\nSee the [LICENSE file][LICENSE] for license text and copyright information.\n\n\n[npm]: https://www.npmjs.org/package/intl-relativeformat\n[npm-badge]: https://img.shields.io/npm/v/intl-relativeformat.svg?style=flat-square\n[david]: https://david-dm.org/yahoo/intl-relativeformat\n[david-badge]: https://img.shields.io/david/yahoo/intl-relativeformat.svg?style=flat-square\n[travis]: https://travis-ci.org/yahoo/intl-relativeformat\n[travis-badge]: https://img.shields.io/travis/yahoo/intl-relativeformat/master.svg?style=flat-square\n[parser]: https://github.com/yahoo/intl-relativeformat-parser\n[CLDR]: http://cldr.unicode.org/\n[Intl]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl\n[Intl-NF]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat\n[Intl-DTF]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\n[Intl-Node]: https://github.com/joyent/node/issues/6371\n[Intl.js]: https://github.com/andyearnshaw/Intl.js\n[rawgit]: https://rawgit.com/\n[semver]: http://semver.org/\n[LICENSE]: https://github.com/yahoo/intl-relativeformat/blob/master/LICENSE\n[moment.js]: http://momentjs.com/\n[sauce]: https://saucelabs.com/u/intl-relativeformat\n[sauce-badge]: https://saucelabs.com/browser-matrix/intl-relativeformat.svg\n[ECMA 402]: http://www.ecma-international.org/ecma-402/1.0/index.html\n[DateTimeFormat]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat\n[NumberFormat]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat\n","readmeFilename":"README.md"}