Socket
Socket
Sign inDemoInstall

@formatjs/intl-relativetimeformat

Package Overview
Dependencies
Maintainers
2
Versions
176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/intl-relativetimeformat - npm Package Compare versions

Comparing version 2.5.2 to 2.6.0

dist/aliases.d.ts

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [2.6.0](https://github.com/formatjs/formatjs/compare/@formatjs/intl-relativetimeformat@2.5.2...@formatjs/intl-relativetimeformat@2.6.0) (2019-08-09)
### Features
* **@formatjs/intl-relativetimeformat:** add aliases support ([a2aec8c](https://github.com/formatjs/formatjs/commit/a2aec8c))
## [2.5.2](https://github.com/formatjs/formatjs/compare/@formatjs/intl-relativetimeformat@2.5.1...@formatjs/intl-relativetimeformat@2.5.2) (2019-08-06)

@@ -8,0 +19,0 @@

2

dist/core.d.ts

@@ -67,3 +67,5 @@ import { LocaleData, FormattableUnit } from './types';

static __addLocaleData(...data: LocaleData[]): void;
static __languageAliases__: Record<string, string>;
static __setLanguageAliases(aliases: Record<string, string>): void;
static polyfilled: boolean;
}

9

dist/core.js

@@ -35,7 +35,8 @@ "use strict";

function resolveLocale(locales) {
var localeData = RelativeTimeFormat.__localeData__, languageAliases = RelativeTimeFormat.__languageAliases__;
var resolvedLocales = (Array.isArray(locales) ? locales : [locales]).concat([
// default locale
DEFAULT_LOCALE
]).filter(function (s) { return typeof s === 'string'; });
var localeData = RelativeTimeFormat.__localeData__;
]).filter(function (s) { return typeof s === 'string'; })
.map(function (l) { return languageAliases[l] || l; });
var i, len, localeParts, data;

@@ -293,2 +294,5 @@ // Using the set of locales + the default locale, we look for the first one

};
RelativeTimeFormat.__setLanguageAliases = function (aliases) {
RelativeTimeFormat.__languageAliases__ = aliases;
};
RelativeTimeFormat.supportedLocalesOf = function (locales) {

@@ -313,2 +317,3 @@ var _a = [];

RelativeTimeFormat.__localeData__ = {};
RelativeTimeFormat.__languageAliases__ = {};
RelativeTimeFormat.polyfilled = true;

@@ -315,0 +320,0 @@ return RelativeTimeFormat;

@@ -5,2 +5,4 @@ "use strict";

var locales_1 = require("./locales");
var aliases_1 = require("./aliases");
locales_1.default.__setLanguageAliases(aliases_1.default);
polyfill_1.default(locales_1.default);

@@ -57,7 +57,8 @@ (function (global, factory) {

function resolveLocale(locales) {
var localeData = RelativeTimeFormat.__localeData__, languageAliases = RelativeTimeFormat.__languageAliases__;
var resolvedLocales = (Array.isArray(locales) ? locales : [locales]).concat([
// default locale
DEFAULT_LOCALE
]).filter(function (s) { return typeof s === 'string'; });
var localeData = RelativeTimeFormat.__localeData__;
]).filter(function (s) { return typeof s === 'string'; })
.map(function (l) { return languageAliases[l] || l; });
var i, len, localeParts, data;

@@ -315,2 +316,5 @@ // Using the set of locales + the default locale, we look for the first one

};
RelativeTimeFormat.__setLanguageAliases = function (aliases) {
RelativeTimeFormat.__languageAliases__ = aliases;
};
RelativeTimeFormat.supportedLocalesOf = function (locales) {

@@ -335,2 +339,3 @@ var _a = [];

RelativeTimeFormat.__localeData__ = {};
RelativeTimeFormat.__languageAliases__ = {};
RelativeTimeFormat.polyfilled = true;

@@ -337,0 +342,0 @@ return RelativeTimeFormat;

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).IntlRelativeTimeFormat={})}(this,function(e){"use strict";var t=["second","minute","hour","day","week","month","quarter","year","seconds","minutes","hours","days","weeks","months","quarters","years"],d=function(){return(d=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function p(e,t,r){return"long"==r?e[t]:"narrow"==r&&e[t+"-narrow"]||e[t+"-short"]}function r(e,t){return Object.is?Object.is(e,t):e===t?0!==e||1/e==1/t:e!=e&&t!=t}function y(e){return r(e,-0)?"past":r(e,0)?"future":e<0?"past":"future"}function v(e,t){if(!(e instanceof u))throw new TypeError("Method Intl.RelativeTimeFormat.prototype."+t+" called on incompatible receiver "+String(e))}function w(e){if(!~t.indexOf(e+""))throw new RangeError("Invalid unit argument for format() '"+String(e)+"'");return"s"===e[e.length-1]?e.slice(0,e.length-1):e}function g(e,t){void 0===t&&(t="format");var r="string"==typeof e?new Number(e).valueOf():e;if(!isFinite(r))throw new RangeError("Value need to be finite number for Intl.RelativeTimeFormat.prototype."+t+"()");return r}function b(e){return!!e}function n(e,t,r,o,a){var n=e[t];if(void 0===n)return a;if("boolean"!==r&&"string"!==r)throw new TypeError("invalid type");if("boolean"===r&&(n=new Boolean(n)),"string"===r&&(n=new String(n)),void 0!==o&&!o.filter(function(e){return e==n}).length)throw new RangeError(n+" in not within "+o);return n}function i(e,t){return e.filter(function(e){return~t.indexOf(e)})}var s=(new Intl.NumberFormat).resolvedOptions().locale,u=(l.prototype.format=function(e,t){v(this,"format");var r=w(t),o=g(e),a=this._style,n=this._numeric,i=p(this._fields,r,a);if(!i)throw new Error("Unsupported unit "+t);var l=i.relative,s=i.relativeTime,u="";if("auto"==n&&(u=l[String(o)]||""))return u;var h=this._pl.select(o),m=s[y(o)];return(m[h]||m.other).replace(/\{0\}/,this._nf.format(Math.abs(o)))},l.prototype.formatToParts=function(e,t){v(this,"format");var r=w(t),o=g(e,"formatToParts"),a=this._style,n=this._numeric,i=p(this._fields,r,a);if(!i)throw new Error("Unsupported unit "+t);var l=i.relative,s=i.relativeTime,u="";if("auto"==n&&(u=l[String(o)]||""))return[{type:"literal",value:u}];var h=this._pl.select(o),m=s[y(o)],f=m[h]||m.other,c=this._nf.formatToParts(Math.abs(o)).map(function(e){return d({},e,{unit:r})});return f.split(/(\{0\})/).filter(b).reduce(function(e,t){return e.concat("{0}"===t?c:[{type:"literal",value:t}])},[])},l.prototype.resolvedOptions=function(){v(this,"resolvedOptions");var e=Object.create(Object.prototype);return Object.defineProperties(e,{locale:{value:this._locale,writable:!0,enumerable:!0,configurable:!0},style:{value:this._style.valueOf(),writable:!0,enumerable:!0,configurable:!0},numeric:{value:this._numeric.valueOf(),writable:!0,enumerable:!0,configurable:!0},numberingSystem:{value:this._numberingSystem.valueOf(),writable:!0,enumerable:!0,configurable:!0}}),e},l.prototype.toString=function(){return"[object Intl.RelativeTimeFormat]"},l.__addLocaleData=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var r=0,o=e;r<o.length;r++){var a=o[r];if(!a||!a.locale)throw new Error("Locale data provided to RelativeTimeFormat is missing a `locale` property value");l.__localeData__[a.locale.toLowerCase()]=a}},l.supportedLocalesOf=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var o=t[0],a="best fit";if(null===o)throw new TypeError("opts cannot be null");return o&&(a=n(o,"localeMatcher","string",["best fit","lookup"],"best fit")),i(Intl.NumberFormat.supportedLocalesOf(e,{localeMatcher:a}),Intl.PluralRules.supportedLocalesOf(e,{localeMatcher:a})).slice()},l.__localeData__={},l.polyfilled=!0,l);function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=e[0],o=e[1];if(!(this&&this instanceof l?this.constructor:void 0))throw new TypeError("Intl.RelativeTimeFormat must be called with 'new'");var a=void 0===o?Object.create(null):function(e){if(null==e)throw new TypeError("undefined/null cannot be converted to object");return Object(e)}(o);this._locale=void 0===r?s:function(e){var t,r,o,a,n=(Array.isArray(e)?e:[e]).concat([s]).filter(function(e){return"string"==typeof e}),i=u.__localeData__;for(t=0,r=n.length;t<r;t+=1)for(o=n[t].toLowerCase().split("-");o.length;){if(a=i[o.join("-")])return a.locale;o.pop()}var l=n.pop();throw new Error("No locale data has been added to IntlRelativeTimeFormat for: "+n.join(", ")+", or the default locale: "+l)}(i(Intl.NumberFormat.supportedLocalesOf(r),Intl.PluralRules.supportedLocalesOf(r))),this._localeMatcher=n(a,"localeMatcher","string",["best fit","lookup"],"best fit"),this._style=n(a,"style","string",["long","narrow","short"],"long"),this._numeric=n(a,"numeric","string",["always","auto"],"always"),this._fields=function(e){for(var t=u.__localeData__,r=t[e.toLowerCase()];r;){if(r.fields)return r.fields;r=r.parentLocale?t[r.parentLocale.toLowerCase()]:void 0}throw new Error("Locale data added to RelativeTimeFormat is missing 'fields' for \""+e+'"')}(this._locale),this._nf=new Intl.NumberFormat(this._locale),this._pl=new Intl.PluralRules(this._locale),this._numberingSystem=this._nf.resolvedOptions().numberingSystem}u.__addLocaleData({locale:"en",fields:{year:{displayName:"year",relative:{0:"this year",1:"next year","-1":"last year"},relativeTime:{future:{one:"in {0} year",other:"in {0} years"},past:{one:"{0} year ago",other:"{0} years ago"}}},"year-short":{displayName:"yr.",relative:{0:"this yr.",1:"next yr.","-1":"last yr."},relativeTime:{future:{one:"in {0} yr.",other:"in {0} yr."},past:{one:"{0} yr. ago",other:"{0} yr. ago"}}},"year-narrow":{displayName:"yr.",relative:{0:"this yr.",1:"next yr.","-1":"last yr."},relativeTime:{future:{one:"in {0} yr.",other:"in {0} yr."},past:{one:"{0} yr. ago",other:"{0} yr. ago"}}},quarter:{displayName:"quarter",relative:{0:"this quarter",1:"next quarter","-1":"last quarter"},relativeTime:{future:{one:"in {0} quarter",other:"in {0} quarters"},past:{one:"{0} quarter ago",other:"{0} quarters ago"}}},"quarter-short":{displayName:"qtr.",relative:{0:"this qtr.",1:"next qtr.","-1":"last qtr."},relativeTime:{future:{one:"in {0} qtr.",other:"in {0} qtrs."},past:{one:"{0} qtr. ago",other:"{0} qtrs. ago"}}},"quarter-narrow":{displayName:"qtr.",relative:{0:"this qtr.",1:"next qtr.","-1":"last qtr."},relativeTime:{future:{one:"in {0} qtr.",other:"in {0} qtrs."},past:{one:"{0} qtr. ago",other:"{0} qtrs. ago"}}},month:{displayName:"month",relative:{0:"this month",1:"next month","-1":"last month"},relativeTime:{future:{one:"in {0} month",other:"in {0} months"},past:{one:"{0} month ago",other:"{0} months ago"}}},"month-short":{displayName:"mo.",relative:{0:"this mo.",1:"next mo.","-1":"last mo."},relativeTime:{future:{one:"in {0} mo.",other:"in {0} mo."},past:{one:"{0} mo. ago",other:"{0} mo. ago"}}},"month-narrow":{displayName:"mo.",relative:{0:"this mo.",1:"next mo.","-1":"last mo."},relativeTime:{future:{one:"in {0} mo.",other:"in {0} mo."},past:{one:"{0} mo. ago",other:"{0} mo. ago"}}},week:{displayName:"week",relative:{0:"this week",1:"next week","-1":"last week"},relativeTime:{future:{one:"in {0} week",other:"in {0} weeks"},past:{one:"{0} week ago",other:"{0} weeks ago"}},relativePeriod:"the week of {0}"},"week-short":{displayName:"wk.",relative:{0:"this wk.",1:"next wk.","-1":"last wk."},relativeTime:{future:{one:"in {0} wk.",other:"in {0} wk."},past:{one:"{0} wk. ago",other:"{0} wk. ago"}},relativePeriod:"the week of {0}"},"week-narrow":{displayName:"wk.",relative:{0:"this wk.",1:"next wk.","-1":"last wk."},relativeTime:{future:{one:"in {0} wk.",other:"in {0} wk."},past:{one:"{0} wk. ago",other:"{0} wk. ago"}},relativePeriod:"the week of {0}"},day:{displayName:"day",relative:{0:"today",1:"tomorrow","-1":"yesterday"},relativeTime:{future:{one:"in {0} day",other:"in {0} days"},past:{one:"{0} day ago",other:"{0} days ago"}}},"day-short":{displayName:"day",relative:{0:"today",1:"tomorrow","-1":"yesterday"},relativeTime:{future:{one:"in {0} day",other:"in {0} days"},past:{one:"{0} day ago",other:"{0} days ago"}}},"day-narrow":{displayName:"day",relative:{0:"today",1:"tomorrow","-1":"yesterday"},relativeTime:{future:{one:"in {0} day",other:"in {0} days"},past:{one:"{0} day ago",other:"{0} days ago"}}},hour:{displayName:"hour",relative:{0:"this hour"},relativeTime:{future:{one:"in {0} hour",other:"in {0} hours"},past:{one:"{0} hour ago",other:"{0} hours ago"}}},"hour-short":{displayName:"hr.",relative:{0:"this hour"},relativeTime:{future:{one:"in {0} hr.",other:"in {0} hr."},past:{one:"{0} hr. ago",other:"{0} hr. ago"}}},"hour-narrow":{displayName:"hr.",relative:{0:"this hour"},relativeTime:{future:{one:"in {0} hr.",other:"in {0} hr."},past:{one:"{0} hr. ago",other:"{0} hr. ago"}}},minute:{displayName:"minute",relative:{0:"this minute"},relativeTime:{future:{one:"in {0} minute",other:"in {0} minutes"},past:{one:"{0} minute ago",other:"{0} minutes ago"}}},"minute-short":{displayName:"min.",relative:{0:"this minute"},relativeTime:{future:{one:"in {0} min.",other:"in {0} min."},past:{one:"{0} min. ago",other:"{0} min. ago"}}},"minute-narrow":{displayName:"min.",relative:{0:"this minute"},relativeTime:{future:{one:"in {0} min.",other:"in {0} min."},past:{one:"{0} min. ago",other:"{0} min. ago"}}},second:{displayName:"second",relative:{0:"now"},relativeTime:{future:{one:"in {0} second",other:"in {0} seconds"},past:{one:"{0} second ago",other:"{0} seconds ago"}}},"second-short":{displayName:"sec.",relative:{0:"now"},relativeTime:{future:{one:"in {0} sec.",other:"in {0} sec."},past:{one:"{0} sec. ago",other:"{0} sec. ago"}}},"second-narrow":{displayName:"sec.",relative:{0:"now"},relativeTime:{future:{one:"in {0} sec.",other:"in {0} sec."},past:{one:"{0} sec. ago",other:"{0} sec. ago"}}}}}),e.VALID_UNITS=t,e.default=u,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).IntlRelativeTimeFormat={})}(this,function(e){"use strict";var t=["second","minute","hour","day","week","month","quarter","year","seconds","minutes","hours","days","weeks","months","quarters","years"],d=function(){return(d=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function p(e,t,r){return"long"==r?e[t]:"narrow"==r&&e[t+"-narrow"]||e[t+"-short"]}function r(e,t){return Object.is?Object.is(e,t):e===t?0!==e||1/e==1/t:e!=e&&t!=t}function y(e){return r(e,-0)?"past":r(e,0)?"future":e<0?"past":"future"}function v(e,t){if(!(e instanceof h))throw new TypeError("Method Intl.RelativeTimeFormat.prototype."+t+" called on incompatible receiver "+String(e))}function g(e){if(!~t.indexOf(e+""))throw new RangeError("Invalid unit argument for format() '"+String(e)+"'");return"s"===e[e.length-1]?e.slice(0,e.length-1):e}function w(e,t){void 0===t&&(t="format");var r="string"==typeof e?new Number(e).valueOf():e;if(!isFinite(r))throw new RangeError("Value need to be finite number for Intl.RelativeTimeFormat.prototype."+t+"()");return r}function _(e){return!!e}function n(e,t,r,o,a){var n=e[t];if(void 0===n)return a;if("boolean"!==r&&"string"!==r)throw new TypeError("invalid type");if("boolean"===r&&(n=new Boolean(n)),"string"===r&&(n=new String(n)),void 0!==o&&!o.filter(function(e){return e==n}).length)throw new RangeError(n+" in not within "+o);return n}function i(e,t){return e.filter(function(e){return~t.indexOf(e)})}var u=(new Intl.NumberFormat).resolvedOptions().locale,h=(l.prototype.format=function(e,t){v(this,"format");var r=g(t),o=w(e),a=this._style,n=this._numeric,i=p(this._fields,r,a);if(!i)throw new Error("Unsupported unit "+t);var l=i.relative,s=i.relativeTime,u="";if("auto"==n&&(u=l[String(o)]||""))return u;var h=this._pl.select(o),m=s[y(o)];return(m[h]||m.other).replace(/\{0\}/,this._nf.format(Math.abs(o)))},l.prototype.formatToParts=function(e,t){v(this,"format");var r=g(t),o=w(e,"formatToParts"),a=this._style,n=this._numeric,i=p(this._fields,r,a);if(!i)throw new Error("Unsupported unit "+t);var l=i.relative,s=i.relativeTime,u="";if("auto"==n&&(u=l[String(o)]||""))return[{type:"literal",value:u}];var h=this._pl.select(o),m=s[y(o)],f=m[h]||m.other,c=this._nf.formatToParts(Math.abs(o)).map(function(e){return d({},e,{unit:r})});return f.split(/(\{0\})/).filter(_).reduce(function(e,t){return e.concat("{0}"===t?c:[{type:"literal",value:t}])},[])},l.prototype.resolvedOptions=function(){v(this,"resolvedOptions");var e=Object.create(Object.prototype);return Object.defineProperties(e,{locale:{value:this._locale,writable:!0,enumerable:!0,configurable:!0},style:{value:this._style.valueOf(),writable:!0,enumerable:!0,configurable:!0},numeric:{value:this._numeric.valueOf(),writable:!0,enumerable:!0,configurable:!0},numberingSystem:{value:this._numberingSystem.valueOf(),writable:!0,enumerable:!0,configurable:!0}}),e},l.prototype.toString=function(){return"[object Intl.RelativeTimeFormat]"},l.__addLocaleData=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var r=0,o=e;r<o.length;r++){var a=o[r];if(!a||!a.locale)throw new Error("Locale data provided to RelativeTimeFormat is missing a `locale` property value");l.__localeData__[a.locale.toLowerCase()]=a}},l.__setLanguageAliases=function(e){l.__languageAliases__=e},l.supportedLocalesOf=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var o=t[0],a="best fit";if(null===o)throw new TypeError("opts cannot be null");return o&&(a=n(o,"localeMatcher","string",["best fit","lookup"],"best fit")),i(Intl.NumberFormat.supportedLocalesOf(e,{localeMatcher:a}),Intl.PluralRules.supportedLocalesOf(e,{localeMatcher:a})).slice()},l.__localeData__={},l.__languageAliases__={},l.polyfilled=!0,l);function l(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=e[0],o=e[1];if(!(this&&this instanceof l?this.constructor:void 0))throw new TypeError("Intl.RelativeTimeFormat must be called with 'new'");var a=void 0===o?Object.create(null):function(e){if(null==e)throw new TypeError("undefined/null cannot be converted to object");return Object(e)}(o);this._locale=void 0===r?u:function(e){var t,r,o,a,n=h.__localeData__,i=h.__languageAliases__,l=(Array.isArray(e)?e:[e]).concat([u]).filter(function(e){return"string"==typeof e}).map(function(e){return i[e]||e});for(t=0,r=l.length;t<r;t+=1)for(o=l[t].toLowerCase().split("-");o.length;){if(a=n[o.join("-")])return a.locale;o.pop()}var s=l.pop();throw new Error("No locale data has been added to IntlRelativeTimeFormat for: "+l.join(", ")+", or the default locale: "+s)}(i(Intl.NumberFormat.supportedLocalesOf(r),Intl.PluralRules.supportedLocalesOf(r))),this._localeMatcher=n(a,"localeMatcher","string",["best fit","lookup"],"best fit"),this._style=n(a,"style","string",["long","narrow","short"],"long"),this._numeric=n(a,"numeric","string",["always","auto"],"always"),this._fields=function(e){for(var t=h.__localeData__,r=t[e.toLowerCase()];r;){if(r.fields)return r.fields;r=r.parentLocale?t[r.parentLocale.toLowerCase()]:void 0}throw new Error("Locale data added to RelativeTimeFormat is missing 'fields' for \""+e+'"')}(this._locale),this._nf=new Intl.NumberFormat(this._locale),this._pl=new Intl.PluralRules(this._locale),this._numberingSystem=this._nf.resolvedOptions().numberingSystem}h.__addLocaleData({locale:"en",fields:{year:{displayName:"year",relative:{0:"this year",1:"next year","-1":"last year"},relativeTime:{future:{one:"in {0} year",other:"in {0} years"},past:{one:"{0} year ago",other:"{0} years ago"}}},"year-short":{displayName:"yr.",relative:{0:"this yr.",1:"next yr.","-1":"last yr."},relativeTime:{future:{one:"in {0} yr.",other:"in {0} yr."},past:{one:"{0} yr. ago",other:"{0} yr. ago"}}},"year-narrow":{displayName:"yr.",relative:{0:"this yr.",1:"next yr.","-1":"last yr."},relativeTime:{future:{one:"in {0} yr.",other:"in {0} yr."},past:{one:"{0} yr. ago",other:"{0} yr. ago"}}},quarter:{displayName:"quarter",relative:{0:"this quarter",1:"next quarter","-1":"last quarter"},relativeTime:{future:{one:"in {0} quarter",other:"in {0} quarters"},past:{one:"{0} quarter ago",other:"{0} quarters ago"}}},"quarter-short":{displayName:"qtr.",relative:{0:"this qtr.",1:"next qtr.","-1":"last qtr."},relativeTime:{future:{one:"in {0} qtr.",other:"in {0} qtrs."},past:{one:"{0} qtr. ago",other:"{0} qtrs. ago"}}},"quarter-narrow":{displayName:"qtr.",relative:{0:"this qtr.",1:"next qtr.","-1":"last qtr."},relativeTime:{future:{one:"in {0} qtr.",other:"in {0} qtrs."},past:{one:"{0} qtr. ago",other:"{0} qtrs. ago"}}},month:{displayName:"month",relative:{0:"this month",1:"next month","-1":"last month"},relativeTime:{future:{one:"in {0} month",other:"in {0} months"},past:{one:"{0} month ago",other:"{0} months ago"}}},"month-short":{displayName:"mo.",relative:{0:"this mo.",1:"next mo.","-1":"last mo."},relativeTime:{future:{one:"in {0} mo.",other:"in {0} mo."},past:{one:"{0} mo. ago",other:"{0} mo. ago"}}},"month-narrow":{displayName:"mo.",relative:{0:"this mo.",1:"next mo.","-1":"last mo."},relativeTime:{future:{one:"in {0} mo.",other:"in {0} mo."},past:{one:"{0} mo. ago",other:"{0} mo. ago"}}},week:{displayName:"week",relative:{0:"this week",1:"next week","-1":"last week"},relativeTime:{future:{one:"in {0} week",other:"in {0} weeks"},past:{one:"{0} week ago",other:"{0} weeks ago"}},relativePeriod:"the week of {0}"},"week-short":{displayName:"wk.",relative:{0:"this wk.",1:"next wk.","-1":"last wk."},relativeTime:{future:{one:"in {0} wk.",other:"in {0} wk."},past:{one:"{0} wk. ago",other:"{0} wk. ago"}},relativePeriod:"the week of {0}"},"week-narrow":{displayName:"wk.",relative:{0:"this wk.",1:"next wk.","-1":"last wk."},relativeTime:{future:{one:"in {0} wk.",other:"in {0} wk."},past:{one:"{0} wk. ago",other:"{0} wk. ago"}},relativePeriod:"the week of {0}"},day:{displayName:"day",relative:{0:"today",1:"tomorrow","-1":"yesterday"},relativeTime:{future:{one:"in {0} day",other:"in {0} days"},past:{one:"{0} day ago",other:"{0} days ago"}}},"day-short":{displayName:"day",relative:{0:"today",1:"tomorrow","-1":"yesterday"},relativeTime:{future:{one:"in {0} day",other:"in {0} days"},past:{one:"{0} day ago",other:"{0} days ago"}}},"day-narrow":{displayName:"day",relative:{0:"today",1:"tomorrow","-1":"yesterday"},relativeTime:{future:{one:"in {0} day",other:"in {0} days"},past:{one:"{0} day ago",other:"{0} days ago"}}},hour:{displayName:"hour",relative:{0:"this hour"},relativeTime:{future:{one:"in {0} hour",other:"in {0} hours"},past:{one:"{0} hour ago",other:"{0} hours ago"}}},"hour-short":{displayName:"hr.",relative:{0:"this hour"},relativeTime:{future:{one:"in {0} hr.",other:"in {0} hr."},past:{one:"{0} hr. ago",other:"{0} hr. ago"}}},"hour-narrow":{displayName:"hr.",relative:{0:"this hour"},relativeTime:{future:{one:"in {0} hr.",other:"in {0} hr."},past:{one:"{0} hr. ago",other:"{0} hr. ago"}}},minute:{displayName:"minute",relative:{0:"this minute"},relativeTime:{future:{one:"in {0} minute",other:"in {0} minutes"},past:{one:"{0} minute ago",other:"{0} minutes ago"}}},"minute-short":{displayName:"min.",relative:{0:"this minute"},relativeTime:{future:{one:"in {0} min.",other:"in {0} min."},past:{one:"{0} min. ago",other:"{0} min. ago"}}},"minute-narrow":{displayName:"min.",relative:{0:"this minute"},relativeTime:{future:{one:"in {0} min.",other:"in {0} min."},past:{one:"{0} min. ago",other:"{0} min. ago"}}},second:{displayName:"second",relative:{0:"now"},relativeTime:{future:{one:"in {0} second",other:"in {0} seconds"},past:{one:"{0} second ago",other:"{0} seconds ago"}}},"second-short":{displayName:"sec.",relative:{0:"now"},relativeTime:{future:{one:"in {0} sec.",other:"in {0} sec."},past:{one:"{0} sec. ago",other:"{0} sec. ago"}}},"second-narrow":{displayName:"sec.",relative:{0:"now"},relativeTime:{future:{one:"in {0} sec.",other:"in {0} sec."},past:{one:"{0} sec. ago",other:"{0} sec. ago"}}}}}),e.VALID_UNITS=t,e.default=h,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=intl-relativetimeformat.min.js.map
{
"name": "@formatjs/intl-relativetimeformat",
"version": "2.5.2",
"version": "2.6.0",
"description": "Formats JavaScript dates to relative time strings.",

@@ -23,3 +23,3 @@ "keywords": [

"devDependencies": {
"formatjs-extract-cldr-data": "^9.3.3"
"formatjs-extract-cldr-data": "^9.4.0"
},

@@ -30,12 +30,13 @@ "main": "dist/index",

"scripts": {
"build": "npm run cldr && npm run compile",
"cldr": "node scripts/cldr",
"clean": "rimraf dist lib",
"compile": "tsc && npm run mjs && tsc -p tsconfig.cjs.json && rollup -c rollup.config.js",
"jest": "TS_NODE_PROJECT='./tsconfig.cjs.json' cross-env NODE_ENV=test jest",
"mjs": "find ./dist -depth -name \"*.js\" -exec sh -c 'f=\"{}\"; mv -- \"$f\" \"${f%.js}.mjs\"' \\;",
"compile": "tsc && npm run mjs && tsc -p tsconfig.cjs.json && rollup -c rollup.config.js",
"build": "npm run cldr && npm run compile",
"cldr": "node scripts/cldr",
"test": "TS_NODE_PROJECT=tsconfig.cjs.json ts-node tests/runner"
"test": "npm run jest && TS_NODE_PROJECT=tsconfig.cjs.json ts-node tests/runner"
},
"homepage": "https://github.com/formatjs/formatjs",
"license": "MIT",
"gitHead": "5712b2950f1ca82c7ea987a88a490a28157838fc"
"gitHead": "58f2442649916d22bb64f986de45fa399b4d23b7"
}

@@ -52,2 +52,11 @@ # Intl RelativeTimeFormat

### Language Aliases
Language aliases are useful when we have to resolve deprecated locale (e.g `zh-CN` is technically `zh-Hans-CN`). Without aliases we would resolve `zh-CN` to `zh` which is less accurate. In order to include lang aliases, you can do:
```js
import '@formatjs/intl-relativetimeformat/polyfill';
import '@formatjs/intl-relativetimeformat/dist/include-aliases'; // Add locale data for de
```
## Tests

@@ -54,0 +63,0 @@

@@ -92,2 +92,6 @@ import {

function resolveLocale(locales: Array<string | undefined>) {
const {
__localeData__: localeData,
__languageAliases__: languageAliases
} = RelativeTimeFormat;
let resolvedLocales: string[] = [

@@ -97,6 +101,7 @@ ...(Array.isArray(locales) ? locales : [locales]),

DEFAULT_LOCALE
].filter<string>((s): s is string => typeof s === 'string');
]
.filter<string>((s): s is string => typeof s === 'string')
.map(l => languageAliases[l] || l);
var localeData = RelativeTimeFormat.__localeData__;
var i, len, localeParts, data;
let i, len, localeParts, data;

@@ -463,3 +468,3 @@ // Using the set of locales + the default locale, we look for the first one

static __localeData__ = {} as Record<string, LocaleData>;
static __localeData__: Record<string, LocaleData> = {};
public static __addLocaleData(...data: LocaleData[]) {

@@ -477,3 +482,7 @@ for (const datum of data) {

}
static __languageAliases__: Record<string, string> = {};
public static __setLanguageAliases(aliases: Record<string, string>) {
RelativeTimeFormat.__languageAliases__ = aliases;
}
public static polyfilled = true;
}
import polyfill from './polyfill';
import RelativeTimeFormatWithLocales from './locales';
import aliases from './aliases';
RelativeTimeFormatWithLocales.__setLanguageAliases(aliases);
polyfill(RelativeTimeFormatWithLocales);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc