intl-relativeformat
Advanced tools
Comparing version 1.0.0-beta-1 to 1.0.0-beta-2
@@ -29,4 +29,5 @@ { | ||
"es6", | ||
"commonjs", | ||
"globals" | ||
] | ||
} |
@@ -1,1 +0,1 @@ | ||
(function(){"use strict";function a(a){var b,c,d,e,f=Array.prototype.slice.call(arguments,1);for(b=0,c=f.length;c>b;b+=1)if(d=f[b])for(e in d)o.call(d,e)&&(a[e]=d[e]);return a}function b(a,b,c){this.locales=a,this.formats=b,this.pluralFn=c}function c(a){this.id=a}function d(a,b,c,d){this.id=a,this.offset=b,this.options=c,this.pluralFn=d}function e(a,b,c,d){this.id=a,this.offset=b,this.numberFormat=c,this.string=d}function f(a,b){this.id=a,this.options=b}function g(a,b,c){var d="string"==typeof a?g.__parse(a):a;if(!d||"messageFormatPattern"!==d.type)throw new TypeError("A message must be provided as a String or AST.");c=this._mergeFormats(g.formats,c),q(this,"_locale",{value:this._resolveLocale(b)});var e=g.__localeData__[this._locale].pluralRuleFunction,f=this._compilePattern(d,b,c,e),h=this;this.format=function(a){return h._format(f,a)}}function h(a){return Math[0>a?"ceil":"floor"](a)}function i(a){return 400*a/146097}function j(a){m(this,"_locale",{value:this._resolveLocale(a)}),m(this,"_messages",{value:n(null)});var b=this;this.format=function(a){return b._format(a)}}var k=Object.prototype.hasOwnProperty,l=function(){try{return!!Object.defineProperty({},"a",{})}catch(a){return!1}}(),m=(!l&&!Object.prototype.__defineGetter__,l?Object.defineProperty:function(a,b,c){"get"in c&&a.__defineGetter__?a.__defineGetter__(b,c.get):(!k.call(a,b)||"value"in c)&&(a[b]=c.value)}),n=Object.create||function(a,b){function c(){}var d,e;c.prototype=a,d=new c;for(e in b)k.call(b,e)&&m(d,e,b[e]);return d},o=Object.prototype.hasOwnProperty,p=function(){try{return!!Object.defineProperty({},"a",{})}catch(a){return!1}}(),q=(!p&&!Object.prototype.__defineGetter__,p?Object.defineProperty:function(a,b,c){"get"in c&&a.__defineGetter__?a.__defineGetter__(b,c.get):(!o.call(a,b)||"value"in c)&&(a[b]=c.value)}),r=Object.create||function(a,b){function c(){}var d,e;c.prototype=a,d=new c;for(e in b)o.call(b,e)&&q(d,e,b[e]);return d},s=b;b.prototype.compile=function(a){return this.pluralStack=[],this.currentPlural=null,this.pluralNumberFormat=null,this.compileMessage(a)},b.prototype.compileMessage=function(a){if(!a||"messageFormatPattern"!==a.type)throw new Error('Message AST is not of type: "messageFormatPattern"');var b,c,d,e=a.elements,f=[];for(b=0,c=e.length;c>b;b+=1)switch(d=e[b],d.type){case"messageTextElement":f.push(this.compileMessageText(d));break;case"argumentElement":f.push(this.compileArgument(d));break;default:throw new Error("Message element does not have a valid type")}return f},b.prototype.compileMessageText=function(a){return this.currentPlural&&/(^|[^\\])#/g.test(a.value)?(this.pluralNumberFormat||(this.pluralNumberFormat=new Intl.NumberFormat(this.locales)),new e(this.currentPlural.id,this.currentPlural.format.offset,this.pluralNumberFormat,a.value)):a.value.replace(/\\#/g,"#")},b.prototype.compileArgument=function(a){var b=a.format;if(!b)return new c(a.id);var e,g=this.formats,h=this.locales,i=this.pluralFn;switch(b.type){case"numberFormat":return e=g.number[b.style],{id:a.id,format:new Intl.NumberFormat(h,e).format};case"dateFormat":return e=g.date[b.style],{id:a.id,format:new Intl.DateTimeFormat(h,e).format};case"timeFormat":return e=g.time[b.style],{id:a.id,format:new Intl.DateTimeFormat(h,e).format};case"pluralFormat":return e=this.compileOptions(a),new d(a.id,b.offset,e,i);case"selectFormat":return e=this.compileOptions(a),new f(a.id,e);default:throw new Error("Message element does not have a valid format type")}},b.prototype.compileOptions=function(a){var b=a.format,c=b.options,d={};this.pluralStack.push(this.currentPlural),this.currentPlural="pluralFormat"===b.type?a:null;var e,f,g;for(e=0,f=c.length;f>e;e+=1)g=c[e],d[g.selector]=this.compileMessage(g.value);return this.currentPlural=this.pluralStack.pop(),d},c.prototype.format=function(a){return a?"string"==typeof a?a:String(a):""},d.prototype.getOption=function(a){var b=this.options,c=b["="+a]||b[this.pluralFn(a-this.offset)];return c||b.other},e.prototype.format=function(a){var b=this.numberFormat.format(a-this.offset);return this.string.replace(/(^|[^\\])#/g,"$1"+b).replace(/\\#/g,"#")},f.prototype.getOption=function(a){var b=this.options;return b[a]||b.other};var t=function(){function a(a,b){function c(){this.constructor=a}c.prototype=b.prototype,a.prototype=new c}function b(a,b,c,d,e,f){this.message=a,this.expected=b,this.found=c,this.offset=d,this.line=e,this.column=f,this.name="SyntaxError"}function c(a){function c(b){function c(b,c,d){var e,f;for(e=c;d>e;e++)f=a.charAt(e),"\n"===f?(b.seenCR||b.line++,b.column=1,b.seenCR=!1):"\r"===f||"\u2028"===f||"\u2029"===f?(b.line++,b.column=1,b.seenCR=!0):(b.column++,b.seenCR=!1)}return Ob!==b&&(Ob>b&&(Ob=0,Pb={line:1,column:1,seenCR:!1}),c(Pb,Ob,b),Ob=b),Pb}function d(a){Qb>Mb||(Mb>Qb&&(Qb=Mb,Rb=[]),Rb.push(a))}function e(d,e,f){function g(a){var b=1;for(a.sort(function(a,b){return a.description<b.description?-1:a.description>b.description?1:0});b<a.length;)a[b-1]===a[b]?a.splice(b,1):b++}function h(a,b){function c(a){function b(a){return a.charCodeAt(0).toString(16).toUpperCase()}return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(a){return"\\x0"+b(a)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(a){return"\\x"+b(a)}).replace(/[\u0180-\u0FFF]/g,function(a){return"\\u0"+b(a)}).replace(/[\u1080-\uFFFF]/g,function(a){return"\\u"+b(a)})}var d,e,f,g=new Array(a.length);for(f=0;f<a.length;f++)g[f]=a[f].description;return d=a.length>1?g.slice(0,-1).join(", ")+" or "+g[a.length-1]:g[0],e=b?'"'+c(b)+'"':"end of input","Expected "+d+" but "+e+" found."}var i=c(f),j=f<a.length?a.charAt(f):null;return null!==e&&g(e),new b(null!==d?d:h(e,j),e,j,f,i.line,i.column)}function f(){var a;return a=g()}function g(){var a,b,c;for(a=Mb,b=[],c=h();c!==C;)b.push(c),c=h();return b!==C&&(Nb=a,b=F(b)),a=b}function h(){var a;return a=j(),a===C&&(a=l()),a}function i(){var b,c,d,e,f,g;if(b=Mb,c=[],d=Mb,e=u(),e!==C?(f=z(),f!==C?(g=u(),g!==C?(e=[e,f,g],d=e):(Mb=d,d=G)):(Mb=d,d=G)):(Mb=d,d=G),d!==C)for(;d!==C;)c.push(d),d=Mb,e=u(),e!==C?(f=z(),f!==C?(g=u(),g!==C?(e=[e,f,g],d=e):(Mb=d,d=G)):(Mb=d,d=G)):(Mb=d,d=G);else c=G;return c!==C&&(Nb=b,c=H(c)),b=c,b===C&&(b=Mb,c=t(),c!==C&&(c=a.substring(b,Mb)),b=c),b}function j(){var a,b;return a=Mb,b=i(),b!==C&&(Nb=a,b=I(b)),a=b}function k(){var b,c,e;if(b=x(),b===C){if(b=Mb,c=[],J.test(a.charAt(Mb))?(e=a.charAt(Mb),Mb++):(e=C,0===Sb&&d(K)),e!==C)for(;e!==C;)c.push(e),J.test(a.charAt(Mb))?(e=a.charAt(Mb),Mb++):(e=C,0===Sb&&d(K));else c=G;c!==C&&(c=a.substring(b,Mb)),b=c}return b}function l(){var b,c,e,f,g,h,i,j,l;return b=Mb,123===a.charCodeAt(Mb)?(c=L,Mb++):(c=C,0===Sb&&d(M)),c!==C?(e=u(),e!==C?(f=k(),f!==C?(g=u(),g!==C?(h=Mb,44===a.charCodeAt(Mb)?(i=O,Mb++):(i=C,0===Sb&&d(P)),i!==C?(j=u(),j!==C?(l=m(),l!==C?(i=[i,j,l],h=i):(Mb=h,h=G)):(Mb=h,h=G)):(Mb=h,h=G),h===C&&(h=N),h!==C?(i=u(),i!==C?(125===a.charCodeAt(Mb)?(j=Q,Mb++):(j=C,0===Sb&&d(R)),j!==C?(Nb=b,c=S(f,h),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function m(){var a;return a=n(),a===C&&(a=o(),a===C&&(a=p())),a}function n(){var b,c,e,f,g,h,i;return b=Mb,a.substr(Mb,6)===T?(c=T,Mb+=6):(c=C,0===Sb&&d(U)),c===C&&(a.substr(Mb,4)===V?(c=V,Mb+=4):(c=C,0===Sb&&d(W)),c===C&&(a.substr(Mb,4)===X?(c=X,Mb+=4):(c=C,0===Sb&&d(Y)))),c!==C?(e=u(),e!==C?(f=Mb,44===a.charCodeAt(Mb)?(g=O,Mb++):(g=C,0===Sb&&d(P)),g!==C?(h=u(),h!==C?(i=z(),i!==C?(g=[g,h,i],f=g):(Mb=f,f=G)):(Mb=f,f=G)):(Mb=f,f=G),f===C&&(f=N),f!==C?(Nb=b,c=Z(c,f),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function o(){var b,c,e,f,g,h,i,j,k;if(b=Mb,a.substr(Mb,6)===$?(c=$,Mb+=6):(c=C,0===Sb&&d(_)),c!==C)if(e=u(),e!==C)if(44===a.charCodeAt(Mb)?(f=O,Mb++):(f=C,0===Sb&&d(P)),f!==C)if(g=u(),g!==C)if(h=s(),h===C&&(h=N),h!==C)if(i=u(),i!==C){if(j=[],k=r(),k!==C)for(;k!==C;)j.push(k),k=r();else j=G;j!==C?(Nb=b,c=ab(h,j),b=c):(Mb=b,b=G)}else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;return b}function p(){var b,c,e,f,g,h,i;if(b=Mb,a.substr(Mb,6)===bb?(c=bb,Mb+=6):(c=C,0===Sb&&d(cb)),c!==C)if(e=u(),e!==C)if(44===a.charCodeAt(Mb)?(f=O,Mb++):(f=C,0===Sb&&d(P)),f!==C)if(g=u(),g!==C){if(h=[],i=r(),i!==C)for(;i!==C;)h.push(i),i=r();else h=G;h!==C?(Nb=b,c=db(h),b=c):(Mb=b,b=G)}else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;return b}function q(){var b,c,e,f;return b=Mb,c=Mb,61===a.charCodeAt(Mb)?(e=eb,Mb++):(e=C,0===Sb&&d(fb)),e!==C?(f=x(),f!==C?(e=[e,f],c=e):(Mb=c,c=G)):(Mb=c,c=G),c!==C&&(c=a.substring(b,Mb)),b=c,b===C&&(b=z()),b}function r(){var b,c,e,f,h,i,j,k,l;return b=Mb,c=u(),c!==C?(e=q(),e!==C?(f=u(),f!==C?(123===a.charCodeAt(Mb)?(h=L,Mb++):(h=C,0===Sb&&d(M)),h!==C?(i=u(),i!==C?(j=g(),j!==C?(k=u(),k!==C?(125===a.charCodeAt(Mb)?(l=Q,Mb++):(l=C,0===Sb&&d(R)),l!==C?(Nb=b,c=gb(e,j),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function s(){var b,c,e,f;return b=Mb,a.substr(Mb,7)===hb?(c=hb,Mb+=7):(c=C,0===Sb&&d(ib)),c!==C?(e=u(),e!==C?(f=x(),f!==C?(Nb=b,c=jb(f),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function t(){var b,c;if(Sb++,b=[],lb.test(a.charAt(Mb))?(c=a.charAt(Mb),Mb++):(c=C,0===Sb&&d(mb)),c!==C)for(;c!==C;)b.push(c),lb.test(a.charAt(Mb))?(c=a.charAt(Mb),Mb++):(c=C,0===Sb&&d(mb));else b=G;return Sb--,b===C&&(c=C,0===Sb&&d(kb)),b}function u(){var b,c,e;for(Sb++,b=Mb,c=[],e=t();e!==C;)c.push(e),e=t();return c!==C&&(c=a.substring(b,Mb)),b=c,Sb--,b===C&&(c=C,0===Sb&&d(nb)),b}function v(){var b;return ob.test(a.charAt(Mb))?(b=a.charAt(Mb),Mb++):(b=C,0===Sb&&d(pb)),b}function w(){var b;return qb.test(a.charAt(Mb))?(b=a.charAt(Mb),Mb++):(b=C,0===Sb&&d(rb)),b}function x(){var b,c,e,f,g,h;if(b=Mb,48===a.charCodeAt(Mb)?(c=sb,Mb++):(c=C,0===Sb&&d(tb)),c===C){if(c=Mb,e=Mb,ub.test(a.charAt(Mb))?(f=a.charAt(Mb),Mb++):(f=C,0===Sb&&d(vb)),f!==C){for(g=[],h=v();h!==C;)g.push(h),h=v();g!==C?(f=[f,g],e=f):(Mb=e,e=G)}else Mb=e,e=G;e!==C&&(e=a.substring(c,Mb)),c=e}return c!==C&&(Nb=b,c=wb(c)),b=c}function y(){var b,c,e,f,g,h,i,j;return xb.test(a.charAt(Mb))?(b=a.charAt(Mb),Mb++):(b=C,0===Sb&&d(yb)),b===C&&(b=Mb,a.substr(Mb,2)===zb?(c=zb,Mb+=2):(c=C,0===Sb&&d(Ab)),c!==C&&(Nb=b,c=Bb()),b=c,b===C&&(b=Mb,a.substr(Mb,2)===Cb?(c=Cb,Mb+=2):(c=C,0===Sb&&d(Db)),c!==C&&(Nb=b,c=Eb()),b=c,b===C&&(b=Mb,a.substr(Mb,2)===Fb?(c=Fb,Mb+=2):(c=C,0===Sb&&d(Gb)),c!==C&&(Nb=b,c=Hb()),b=c,b===C&&(b=Mb,a.substr(Mb,2)===Ib?(c=Ib,Mb+=2):(c=C,0===Sb&&d(Jb)),c!==C?(e=Mb,f=Mb,g=w(),g!==C?(h=w(),h!==C?(i=w(),i!==C?(j=w(),j!==C?(g=[g,h,i,j],f=g):(Mb=f,f=G)):(Mb=f,f=G)):(Mb=f,f=G)):(Mb=f,f=G),f!==C&&(f=a.substring(e,Mb)),e=f,e!==C?(Nb=b,c=Kb(e),b=c):(Mb=b,b=G)):(Mb=b,b=G))))),b}function z(){var a,b,c;if(a=Mb,b=[],c=y(),c!==C)for(;c!==C;)b.push(c),c=y();else b=G;return b!==C&&(Nb=a,b=Lb(b)),a=b}var A,B=arguments.length>1?arguments[1]:{},C={},D={start:f},E=f,F=function(a){return{type:"messageFormatPattern",elements:a}},G=C,H=function(a){var b,c,d,e,f,g="";for(b=0,d=a.length;d>b;b+=1)for(e=a[b],c=0,f=e.length;f>c;c+=1)g+=e[c];return g},I=function(a){return{type:"messageTextElement",value:a}},J=/^[^ \t\n\r,.+={}#]/,K={type:"class",value:"[^ \\t\\n\\r,.+={}#]",description:"[^ \\t\\n\\r,.+={}#]"},L="{",M={type:"literal",value:"{",description:'"{"'},N=null,O=",",P={type:"literal",value:",",description:'","'},Q="}",R={type:"literal",value:"}",description:'"}"'},S=function(a,b){return{type:"argumentElement",id:a,format:b&&b[2]}},T="number",U={type:"literal",value:"number",description:'"number"'},V="date",W={type:"literal",value:"date",description:'"date"'},X="time",Y={type:"literal",value:"time",description:'"time"'},Z=function(a,b){return{type:a+"Format",style:b&&b[2]}},$="plural",_={type:"literal",value:"plural",description:'"plural"'},ab=function(a,b){return{type:"pluralFormat",offset:a||0,options:b}},bb="select",cb={type:"literal",value:"select",description:'"select"'},db=function(a){return{type:"selectFormat",options:a}},eb="=",fb={type:"literal",value:"=",description:'"="'},gb=function(a,b){return{type:"optionalFormatPattern",selector:a,value:b}},hb="offset:",ib={type:"literal",value:"offset:",description:'"offset:"'},jb=function(a){return a},kb={type:"other",description:"whitespace"},lb=/^[ \t\n\r]/,mb={type:"class",value:"[ \\t\\n\\r]",description:"[ \\t\\n\\r]"},nb={type:"other",description:"optionalWhitespace"},ob=/^[0-9]/,pb={type:"class",value:"[0-9]",description:"[0-9]"},qb=/^[0-9a-f]/i,rb={type:"class",value:"[0-9a-f]i",description:"[0-9a-f]i"},sb="0",tb={type:"literal",value:"0",description:'"0"'},ub=/^[1-9]/,vb={type:"class",value:"[1-9]",description:"[1-9]"},wb=function(a){return parseInt(a,10)},xb=/^[^{}\\\0-\x1F \t\n\r]/,yb={type:"class",value:"[^{}\\\\\\0-\\x1F \\t\\n\\r]",description:"[^{}\\\\\\0-\\x1F \\t\\n\\r]"},zb="\\#",Ab={type:"literal",value:"\\#",description:'"\\\\#"'},Bb=function(){return"\\#"},Cb="\\{",Db={type:"literal",value:"\\{",description:'"\\\\{"'},Eb=function(){return"{"},Fb="\\}",Gb={type:"literal",value:"\\}",description:'"\\\\}"'},Hb=function(){return"}"},Ib="\\u",Jb={type:"literal",value:"\\u",description:'"\\\\u"'},Kb=function(a){return String.fromCharCode(parseInt(a,16))},Lb=function(a){return a.join("")},Mb=0,Nb=0,Ob=0,Pb={line:1,column:1,seenCR:!1},Qb=0,Rb=[],Sb=0;if("startRule"in B){if(!(B.startRule in D))throw new Error("Can't start parsing from rule \""+B.startRule+'".');E=D[B.startRule]}if(A=E(),A!==C&&Mb===a.length)return A;throw A!==C&&Mb<a.length&&d({type:"end",description:"end of input"}),e(null,Rb,Qb)}return a(b,Error),{SyntaxError:b,parse:c}}(),u=g;q(g,"formats",{enumerable:!0,value:{number:{currency:{style:"currency"},percent:{style:"percent"}},date:{"short":{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},"long":{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{"short":{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},"long":{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}}}),q(g,"__availableLocales__",{value:[]}),q(g,"__localeData__",{value:r(null)}),q(g,"__addLocaleData",{value:function(a){if(!a||!a.locale)throw new Error("Locale data does not contain a `locale` property");if(!a.pluralRuleFunction)throw new Error("Locale data does not contain a `pluralRuleFunction` property");var b=g.__availableLocales__,c=g.__localeData__;b.push(a.locale),c[a.locale]=a}}),q(g,"__parse",{value:t.parse}),q(g,"defaultLocale",{enumerable:!0,writable:!0,value:void 0}),g.prototype.resolvedOptions=function(){return{locale:this._locale}},g.prototype._compilePattern=function(a,b,c,d){var e=new s(b,c,d);return e.compile(a)},g.prototype._format=function(a,b){var c,d,e,f,g,h="";for(c=0,d=a.length;d>c;c+=1)if(e=a[c],"string"!=typeof e){if(f=e.id,!b||!o.call(b,f))throw new Error("A value must be provided for: "+f);g=b[f],h+=e.options?this._format(e.getOption(g),b):e.format(g)}else h+=e;return h},g.prototype._mergeFormats=function(b,c){var d,e,f={};for(d in b)o.call(b,d)&&(f[d]=e=r(b[d]),c&&o.call(c,d)&&a(e,c[d]));return f},g.prototype._resolveLocale=function(a){var b,c,d,e=g.__availableLocales__;if(0===e.length)throw new Error("No locale data has been provided for IntlMessageFormat yet");if("string"==typeof a&&(a=[a]),a&&a.length)for(c=0,d=a.length;d>c;c+=1){if(b=a[c].toLowerCase().split("-")[0],!/[a-z]{2,3}/i.test(b))throw new RangeError('"'+a[c]+'" is not a structurally valid language tag');if(e.indexOf(b)>=0)break}return b||g.defaultLocale.split("-")[0]};var v={locale:"en",pluralRuleFunction:function(a){var b=Math.floor(Math.abs(a)),c=a.toString().replace(/^[^.]*\.?/,"").length;return a=Math.floor(a),1===b&&0===c?"one":"other"}};u.__addLocaleData(v),u.defaultLocale="en";var w=u,x=function(a,b){var c=Math.round,d=h(b.getTime()-a.getTime()),e=Math.abs(d),f=c(e/1e3),g=c(f/60),j=c(g/60),k=c(j/24),l=c(k/7);return{duration:d,week:l,day:k,hour:j,minute:g,second:f,millisecond:e,year:c((g+12*i(k))/12),month:c(g+12*i(k))}},y=j,z=["second","minute","hour","day","month","year"];m(j,"__availableLocales__",{value:[]}),m(j,"__localeData__",{value:n(null)}),m(j,"__addLocaleData",{value:function(a){if(!a||!a.locale)throw new Error("Locale data does not contain a `locale` property");if(!a.fields)throw new Error("Locale data does not contain a `fields` property");w.__addLocaleData(a);var b=j.__availableLocales__,c=j.__localeData__,d=a.locale.toLowerCase().split("-")[0];b.push(d),c[d]=a}}),m(j,"defaultLocale",{enumerable:!0,writable:!0,value:void 0}),m(j,"thresholds",{enumerable:!0,value:{second:45,minute:45,hour:22,day:26,month:11}}),j.prototype.resolvedOptions=function(){return{locale:this._locale}},j.prototype._format=function(a){if(a=new Date(a),!a||!a.getTime())throw new TypeError("A date must be provided.");var b,c,d,e,f=x(new Date,a);for(d=0,e=z.length;e>d&&(b=z[d],!(f[b]<j.thresholds[b]));d++);return c=this._resolveMessage(b),c.format({0:f[b],when:f.duration<0?"past":"future"})},j.prototype._resolveMessage=function(a){var b,c,d,e,f,g=this._messages;if(!g[a]){b=j.__localeData__[this._locale].fields[a],c=b.relativeTime,e="",f="";for(d in c.future)c.future.hasOwnProperty(d)&&(e+=" "+d+" {"+c.future[d].replace("{0}","#")+"}");for(d in c.past)c.past.hasOwnProperty(d)&&(f+=" "+d+" {"+c.past[d].replace("{0}","#")+"}");g[a]=new w("{when, select, future {{0, plural, "+e+"}}past {{0, plural, "+f+"}}}",this._locale)}return g[a]},j.prototype._resolveLocale=function(a){var b,c,d,e=j.__availableLocales__;if(0===e.length)throw new Error("No locale data has been provided for IntlRelativeFormat yet");if("string"==typeof a&&(a=[a]),a&&a.length)for(c=0,d=a.length;d>c;c+=1){if(b=a[c].toLowerCase().split("-")[0],!/[a-z]{2,3}/i.test(b))throw new RangeError('"'+a[c]+'" is not a structurally valid language tag');if(e.indexOf(b)>=0)break}return b||j.defaultLocale.split("-")[0]};var A={locale:"en",pluralRuleFunction:function(a){var b=Math.floor(Math.abs(a)),c=a.toString().replace(/^[^.]*\.?/,"").length;return a=Math.floor(a),1===b&&0===c?"one":"other"},fields:{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"}}},minute:{displayName:"Minute",relativeTime:{future:{one:"in {0} minute",other:"in {0} minutes"},past:{one:"{0} minute ago",other:"{0} minutes ago"}}},hour:{displayName:"Hour",relativeTime:{future:{one:"in {0} hour",other:"in {0} hours"},past:{one:"{0} hour ago",other:"{0} hours ago"}}},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"}}},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"}}},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"}}}}};y.__addLocaleData(A),y.defaultLocale="en";var B=y;this.IntlRelativeFormat=B}).call(this); | ||
(function(){"use strict";function a(a){var b,c,d,e,f=Array.prototype.slice.call(arguments,1);for(b=0,c=f.length;c>b;b+=1)if(d=f[b])for(e in d)n.call(d,e)&&(a[e]=d[e]);return a}function b(a,b,c){this.locales=a,this.formats=b,this.pluralFn=c}function c(a){this.id=a}function d(a,b,c,d){this.id=a,this.offset=b,this.options=c,this.pluralFn=d}function e(a,b,c,d){this.id=a,this.offset=b,this.numberFormat=c,this.string=d}function f(a,b){this.id=a,this.options=b}function g(a,b,c){var d="string"==typeof a?g.__parse(a):a;if(!d||"messageFormatPattern"!==d.type)throw new TypeError("A message must be provided as a String or AST.");c=this._mergeFormats(g.formats,c),p(this,"_locale",{value:this._resolveLocale(b)});var e=g.__localeData__[this._locale].pluralRuleFunction,f=this._compilePattern(d,b,c,e),h=this;this.format=function(a){return h._format(f,a)}}function h(a){return 400*a/146097}function i(a,b){b=b||{},l(this,"_locale",{value:this._resolveLocale(a)}),l(this,"_options",{value:{style:this._resolveStyle(b.style),units:this._isValidUnits(b.units)&&b.units}}),l(this,"_messages",{value:m(null)});var c=this;this.format=function(a){return c._format(a)}}var j=Object.prototype.hasOwnProperty,k=function(){try{return!!Object.defineProperty({},"a",{})}catch(a){return!1}}(),l=(!k&&!Object.prototype.__defineGetter__,k?Object.defineProperty:function(a,b,c){"get"in c&&a.__defineGetter__?a.__defineGetter__(b,c.get):(!j.call(a,b)||"value"in c)&&(a[b]=c.value)}),m=Object.create||function(a,b){function c(){}var d,e;c.prototype=a,d=new c;for(e in b)j.call(b,e)&&l(d,e,b[e]);return d},n=Object.prototype.hasOwnProperty,o=function(){try{return!!Object.defineProperty({},"a",{})}catch(a){return!1}}(),p=(!o&&!Object.prototype.__defineGetter__,o?Object.defineProperty:function(a,b,c){"get"in c&&a.__defineGetter__?a.__defineGetter__(b,c.get):(!n.call(a,b)||"value"in c)&&(a[b]=c.value)}),q=Object.create||function(a,b){function c(){}var d,e;c.prototype=a,d=new c;for(e in b)n.call(b,e)&&p(d,e,b[e]);return d},r=b;b.prototype.compile=function(a){return this.pluralStack=[],this.currentPlural=null,this.pluralNumberFormat=null,this.compileMessage(a)},b.prototype.compileMessage=function(a){if(!a||"messageFormatPattern"!==a.type)throw new Error('Message AST is not of type: "messageFormatPattern"');var b,c,d,e=a.elements,f=[];for(b=0,c=e.length;c>b;b+=1)switch(d=e[b],d.type){case"messageTextElement":f.push(this.compileMessageText(d));break;case"argumentElement":f.push(this.compileArgument(d));break;default:throw new Error("Message element does not have a valid type")}return f},b.prototype.compileMessageText=function(a){return this.currentPlural&&/(^|[^\\])#/g.test(a.value)?(this.pluralNumberFormat||(this.pluralNumberFormat=new Intl.NumberFormat(this.locales)),new e(this.currentPlural.id,this.currentPlural.format.offset,this.pluralNumberFormat,a.value)):a.value.replace(/\\#/g,"#")},b.prototype.compileArgument=function(a){var b=a.format;if(!b)return new c(a.id);var e,g=this.formats,h=this.locales,i=this.pluralFn;switch(b.type){case"numberFormat":return e=g.number[b.style],{id:a.id,format:new Intl.NumberFormat(h,e).format};case"dateFormat":return e=g.date[b.style],{id:a.id,format:new Intl.DateTimeFormat(h,e).format};case"timeFormat":return e=g.time[b.style],{id:a.id,format:new Intl.DateTimeFormat(h,e).format};case"pluralFormat":return e=this.compileOptions(a),new d(a.id,b.offset,e,i);case"selectFormat":return e=this.compileOptions(a),new f(a.id,e);default:throw new Error("Message element does not have a valid format type")}},b.prototype.compileOptions=function(a){var b=a.format,c=b.options,d={};this.pluralStack.push(this.currentPlural),this.currentPlural="pluralFormat"===b.type?a:null;var e,f,g;for(e=0,f=c.length;f>e;e+=1)g=c[e],d[g.selector]=this.compileMessage(g.value);return this.currentPlural=this.pluralStack.pop(),d},c.prototype.format=function(a){return a?"string"==typeof a?a:String(a):""},d.prototype.getOption=function(a){var b=this.options,c=b["="+a]||b[this.pluralFn(a-this.offset)];return c||b.other},e.prototype.format=function(a){var b=this.numberFormat.format(a-this.offset);return this.string.replace(/(^|[^\\])#/g,"$1"+b).replace(/\\#/g,"#")},f.prototype.getOption=function(a){var b=this.options;return b[a]||b.other};var s=function(){function a(a,b){function c(){this.constructor=a}c.prototype=b.prototype,a.prototype=new c}function b(a,b,c,d,e,f){this.message=a,this.expected=b,this.found=c,this.offset=d,this.line=e,this.column=f,this.name="SyntaxError"}function c(a){function c(b){function c(b,c,d){var e,f;for(e=c;d>e;e++)f=a.charAt(e),"\n"===f?(b.seenCR||b.line++,b.column=1,b.seenCR=!1):"\r"===f||"\u2028"===f||"\u2029"===f?(b.line++,b.column=1,b.seenCR=!0):(b.column++,b.seenCR=!1)}return Ob!==b&&(Ob>b&&(Ob=0,Pb={line:1,column:1,seenCR:!1}),c(Pb,Ob,b),Ob=b),Pb}function d(a){Qb>Mb||(Mb>Qb&&(Qb=Mb,Rb=[]),Rb.push(a))}function e(d,e,f){function g(a){var b=1;for(a.sort(function(a,b){return a.description<b.description?-1:a.description>b.description?1:0});b<a.length;)a[b-1]===a[b]?a.splice(b,1):b++}function h(a,b){function c(a){function b(a){return a.charCodeAt(0).toString(16).toUpperCase()}return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(a){return"\\x0"+b(a)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(a){return"\\x"+b(a)}).replace(/[\u0180-\u0FFF]/g,function(a){return"\\u0"+b(a)}).replace(/[\u1080-\uFFFF]/g,function(a){return"\\u"+b(a)})}var d,e,f,g=new Array(a.length);for(f=0;f<a.length;f++)g[f]=a[f].description;return d=a.length>1?g.slice(0,-1).join(", ")+" or "+g[a.length-1]:g[0],e=b?'"'+c(b)+'"':"end of input","Expected "+d+" but "+e+" found."}var i=c(f),j=f<a.length?a.charAt(f):null;return null!==e&&g(e),new b(null!==d?d:h(e,j),e,j,f,i.line,i.column)}function f(){var a;return a=g()}function g(){var a,b,c;for(a=Mb,b=[],c=h();c!==C;)b.push(c),c=h();return b!==C&&(Nb=a,b=F(b)),a=b}function h(){var a;return a=j(),a===C&&(a=l()),a}function i(){var b,c,d,e,f,g;if(b=Mb,c=[],d=Mb,e=u(),e!==C?(f=z(),f!==C?(g=u(),g!==C?(e=[e,f,g],d=e):(Mb=d,d=G)):(Mb=d,d=G)):(Mb=d,d=G),d!==C)for(;d!==C;)c.push(d),d=Mb,e=u(),e!==C?(f=z(),f!==C?(g=u(),g!==C?(e=[e,f,g],d=e):(Mb=d,d=G)):(Mb=d,d=G)):(Mb=d,d=G);else c=G;return c!==C&&(Nb=b,c=H(c)),b=c,b===C&&(b=Mb,c=t(),c!==C&&(c=a.substring(b,Mb)),b=c),b}function j(){var a,b;return a=Mb,b=i(),b!==C&&(Nb=a,b=I(b)),a=b}function k(){var b,c,e;if(b=x(),b===C){if(b=Mb,c=[],J.test(a.charAt(Mb))?(e=a.charAt(Mb),Mb++):(e=C,0===Sb&&d(K)),e!==C)for(;e!==C;)c.push(e),J.test(a.charAt(Mb))?(e=a.charAt(Mb),Mb++):(e=C,0===Sb&&d(K));else c=G;c!==C&&(c=a.substring(b,Mb)),b=c}return b}function l(){var b,c,e,f,g,h,i,j,l;return b=Mb,123===a.charCodeAt(Mb)?(c=L,Mb++):(c=C,0===Sb&&d(M)),c!==C?(e=u(),e!==C?(f=k(),f!==C?(g=u(),g!==C?(h=Mb,44===a.charCodeAt(Mb)?(i=O,Mb++):(i=C,0===Sb&&d(P)),i!==C?(j=u(),j!==C?(l=m(),l!==C?(i=[i,j,l],h=i):(Mb=h,h=G)):(Mb=h,h=G)):(Mb=h,h=G),h===C&&(h=N),h!==C?(i=u(),i!==C?(125===a.charCodeAt(Mb)?(j=Q,Mb++):(j=C,0===Sb&&d(R)),j!==C?(Nb=b,c=S(f,h),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function m(){var a;return a=n(),a===C&&(a=o(),a===C&&(a=p())),a}function n(){var b,c,e,f,g,h,i;return b=Mb,a.substr(Mb,6)===T?(c=T,Mb+=6):(c=C,0===Sb&&d(U)),c===C&&(a.substr(Mb,4)===V?(c=V,Mb+=4):(c=C,0===Sb&&d(W)),c===C&&(a.substr(Mb,4)===X?(c=X,Mb+=4):(c=C,0===Sb&&d(Y)))),c!==C?(e=u(),e!==C?(f=Mb,44===a.charCodeAt(Mb)?(g=O,Mb++):(g=C,0===Sb&&d(P)),g!==C?(h=u(),h!==C?(i=z(),i!==C?(g=[g,h,i],f=g):(Mb=f,f=G)):(Mb=f,f=G)):(Mb=f,f=G),f===C&&(f=N),f!==C?(Nb=b,c=Z(c,f),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function o(){var b,c,e,f,g,h,i,j,k;if(b=Mb,a.substr(Mb,6)===$?(c=$,Mb+=6):(c=C,0===Sb&&d(_)),c!==C)if(e=u(),e!==C)if(44===a.charCodeAt(Mb)?(f=O,Mb++):(f=C,0===Sb&&d(P)),f!==C)if(g=u(),g!==C)if(h=s(),h===C&&(h=N),h!==C)if(i=u(),i!==C){if(j=[],k=r(),k!==C)for(;k!==C;)j.push(k),k=r();else j=G;j!==C?(Nb=b,c=ab(h,j),b=c):(Mb=b,b=G)}else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;return b}function p(){var b,c,e,f,g,h,i;if(b=Mb,a.substr(Mb,6)===bb?(c=bb,Mb+=6):(c=C,0===Sb&&d(cb)),c!==C)if(e=u(),e!==C)if(44===a.charCodeAt(Mb)?(f=O,Mb++):(f=C,0===Sb&&d(P)),f!==C)if(g=u(),g!==C){if(h=[],i=r(),i!==C)for(;i!==C;)h.push(i),i=r();else h=G;h!==C?(Nb=b,c=db(h),b=c):(Mb=b,b=G)}else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;else Mb=b,b=G;return b}function q(){var b,c,e,f;return b=Mb,c=Mb,61===a.charCodeAt(Mb)?(e=eb,Mb++):(e=C,0===Sb&&d(fb)),e!==C?(f=x(),f!==C?(e=[e,f],c=e):(Mb=c,c=G)):(Mb=c,c=G),c!==C&&(c=a.substring(b,Mb)),b=c,b===C&&(b=z()),b}function r(){var b,c,e,f,h,i,j,k,l;return b=Mb,c=u(),c!==C?(e=q(),e!==C?(f=u(),f!==C?(123===a.charCodeAt(Mb)?(h=L,Mb++):(h=C,0===Sb&&d(M)),h!==C?(i=u(),i!==C?(j=g(),j!==C?(k=u(),k!==C?(125===a.charCodeAt(Mb)?(l=Q,Mb++):(l=C,0===Sb&&d(R)),l!==C?(Nb=b,c=gb(e,j),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function s(){var b,c,e,f;return b=Mb,a.substr(Mb,7)===hb?(c=hb,Mb+=7):(c=C,0===Sb&&d(ib)),c!==C?(e=u(),e!==C?(f=x(),f!==C?(Nb=b,c=jb(f),b=c):(Mb=b,b=G)):(Mb=b,b=G)):(Mb=b,b=G),b}function t(){var b,c;if(Sb++,b=[],lb.test(a.charAt(Mb))?(c=a.charAt(Mb),Mb++):(c=C,0===Sb&&d(mb)),c!==C)for(;c!==C;)b.push(c),lb.test(a.charAt(Mb))?(c=a.charAt(Mb),Mb++):(c=C,0===Sb&&d(mb));else b=G;return Sb--,b===C&&(c=C,0===Sb&&d(kb)),b}function u(){var b,c,e;for(Sb++,b=Mb,c=[],e=t();e!==C;)c.push(e),e=t();return c!==C&&(c=a.substring(b,Mb)),b=c,Sb--,b===C&&(c=C,0===Sb&&d(nb)),b}function v(){var b;return ob.test(a.charAt(Mb))?(b=a.charAt(Mb),Mb++):(b=C,0===Sb&&d(pb)),b}function w(){var b;return qb.test(a.charAt(Mb))?(b=a.charAt(Mb),Mb++):(b=C,0===Sb&&d(rb)),b}function x(){var b,c,e,f,g,h;if(b=Mb,48===a.charCodeAt(Mb)?(c=sb,Mb++):(c=C,0===Sb&&d(tb)),c===C){if(c=Mb,e=Mb,ub.test(a.charAt(Mb))?(f=a.charAt(Mb),Mb++):(f=C,0===Sb&&d(vb)),f!==C){for(g=[],h=v();h!==C;)g.push(h),h=v();g!==C?(f=[f,g],e=f):(Mb=e,e=G)}else Mb=e,e=G;e!==C&&(e=a.substring(c,Mb)),c=e}return c!==C&&(Nb=b,c=wb(c)),b=c}function y(){var b,c,e,f,g,h,i,j;return xb.test(a.charAt(Mb))?(b=a.charAt(Mb),Mb++):(b=C,0===Sb&&d(yb)),b===C&&(b=Mb,a.substr(Mb,2)===zb?(c=zb,Mb+=2):(c=C,0===Sb&&d(Ab)),c!==C&&(Nb=b,c=Bb()),b=c,b===C&&(b=Mb,a.substr(Mb,2)===Cb?(c=Cb,Mb+=2):(c=C,0===Sb&&d(Db)),c!==C&&(Nb=b,c=Eb()),b=c,b===C&&(b=Mb,a.substr(Mb,2)===Fb?(c=Fb,Mb+=2):(c=C,0===Sb&&d(Gb)),c!==C&&(Nb=b,c=Hb()),b=c,b===C&&(b=Mb,a.substr(Mb,2)===Ib?(c=Ib,Mb+=2):(c=C,0===Sb&&d(Jb)),c!==C?(e=Mb,f=Mb,g=w(),g!==C?(h=w(),h!==C?(i=w(),i!==C?(j=w(),j!==C?(g=[g,h,i,j],f=g):(Mb=f,f=G)):(Mb=f,f=G)):(Mb=f,f=G)):(Mb=f,f=G),f!==C&&(f=a.substring(e,Mb)),e=f,e!==C?(Nb=b,c=Kb(e),b=c):(Mb=b,b=G)):(Mb=b,b=G))))),b}function z(){var a,b,c;if(a=Mb,b=[],c=y(),c!==C)for(;c!==C;)b.push(c),c=y();else b=G;return b!==C&&(Nb=a,b=Lb(b)),a=b}var A,B=arguments.length>1?arguments[1]:{},C={},D={start:f},E=f,F=function(a){return{type:"messageFormatPattern",elements:a}},G=C,H=function(a){var b,c,d,e,f,g="";for(b=0,d=a.length;d>b;b+=1)for(e=a[b],c=0,f=e.length;f>c;c+=1)g+=e[c];return g},I=function(a){return{type:"messageTextElement",value:a}},J=/^[^ \t\n\r,.+={}#]/,K={type:"class",value:"[^ \\t\\n\\r,.+={}#]",description:"[^ \\t\\n\\r,.+={}#]"},L="{",M={type:"literal",value:"{",description:'"{"'},N=null,O=",",P={type:"literal",value:",",description:'","'},Q="}",R={type:"literal",value:"}",description:'"}"'},S=function(a,b){return{type:"argumentElement",id:a,format:b&&b[2]}},T="number",U={type:"literal",value:"number",description:'"number"'},V="date",W={type:"literal",value:"date",description:'"date"'},X="time",Y={type:"literal",value:"time",description:'"time"'},Z=function(a,b){return{type:a+"Format",style:b&&b[2]}},$="plural",_={type:"literal",value:"plural",description:'"plural"'},ab=function(a,b){return{type:"pluralFormat",offset:a||0,options:b}},bb="select",cb={type:"literal",value:"select",description:'"select"'},db=function(a){return{type:"selectFormat",options:a}},eb="=",fb={type:"literal",value:"=",description:'"="'},gb=function(a,b){return{type:"optionalFormatPattern",selector:a,value:b}},hb="offset:",ib={type:"literal",value:"offset:",description:'"offset:"'},jb=function(a){return a},kb={type:"other",description:"whitespace"},lb=/^[ \t\n\r]/,mb={type:"class",value:"[ \\t\\n\\r]",description:"[ \\t\\n\\r]"},nb={type:"other",description:"optionalWhitespace"},ob=/^[0-9]/,pb={type:"class",value:"[0-9]",description:"[0-9]"},qb=/^[0-9a-f]/i,rb={type:"class",value:"[0-9a-f]i",description:"[0-9a-f]i"},sb="0",tb={type:"literal",value:"0",description:'"0"'},ub=/^[1-9]/,vb={type:"class",value:"[1-9]",description:"[1-9]"},wb=function(a){return parseInt(a,10)},xb=/^[^{}\\\0-\x1F \t\n\r]/,yb={type:"class",value:"[^{}\\\\\\0-\\x1F \\t\\n\\r]",description:"[^{}\\\\\\0-\\x1F \\t\\n\\r]"},zb="\\#",Ab={type:"literal",value:"\\#",description:'"\\\\#"'},Bb=function(){return"\\#"},Cb="\\{",Db={type:"literal",value:"\\{",description:'"\\\\{"'},Eb=function(){return"{"},Fb="\\}",Gb={type:"literal",value:"\\}",description:'"\\\\}"'},Hb=function(){return"}"},Ib="\\u",Jb={type:"literal",value:"\\u",description:'"\\\\u"'},Kb=function(a){return String.fromCharCode(parseInt(a,16))},Lb=function(a){return a.join("")},Mb=0,Nb=0,Ob=0,Pb={line:1,column:1,seenCR:!1},Qb=0,Rb=[],Sb=0;if("startRule"in B){if(!(B.startRule in D))throw new Error("Can't start parsing from rule \""+B.startRule+'".');E=D[B.startRule]}if(A=E(),A!==C&&Mb===a.length)return A;throw A!==C&&Mb<a.length&&d({type:"end",description:"end of input"}),e(null,Rb,Qb)}return a(b,Error),{SyntaxError:b,parse:c}}(),t=g;p(g,"formats",{enumerable:!0,value:{number:{currency:{style:"currency"},percent:{style:"percent"}},date:{"short":{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},"long":{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{"short":{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},"long":{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}}}),p(g,"__availableLocales__",{value:[]}),p(g,"__localeData__",{value:q(null)}),p(g,"__addLocaleData",{value:function(a){if(!a||!a.locale)throw new Error("Locale data does not contain a `locale` property");if(!a.pluralRuleFunction)throw new Error("Locale data does not contain a `pluralRuleFunction` property");var b=g.__availableLocales__,c=g.__localeData__;b.push(a.locale),c[a.locale]=a}}),p(g,"__parse",{value:s.parse}),p(g,"defaultLocale",{enumerable:!0,writable:!0,value:void 0}),g.prototype.resolvedOptions=function(){return{locale:this._locale}},g.prototype._compilePattern=function(a,b,c,d){var e=new r(b,c,d);return e.compile(a)},g.prototype._format=function(a,b){var c,d,e,f,g,h="";for(c=0,d=a.length;d>c;c+=1)if(e=a[c],"string"!=typeof e){if(f=e.id,!b||!n.call(b,f))throw new Error("A value must be provided for: "+f);g=b[f],h+=e.options?this._format(e.getOption(g),b):e.format(g)}else h+=e;return h},g.prototype._mergeFormats=function(b,c){var d,e,f={};for(d in b)n.call(b,d)&&(f[d]=e=q(b[d]),c&&n.call(c,d)&&a(e,c[d]));return f},g.prototype._resolveLocale=function(a){var b,c,d,e=g.__availableLocales__;if(0===e.length)throw new Error("No locale data has been provided for IntlMessageFormat yet");if("string"==typeof a&&(a=[a]),a&&a.length)for(c=0,d=a.length;d>c;c+=1){if(b=a[c].toLowerCase().split("-")[0],!/[a-z]{2,3}/i.test(b))throw new RangeError('"'+a[c]+'" is not a structurally valid language tag');if(e.indexOf(b)>=0)break}return b||g.defaultLocale.split("-")[0]};var u={locale:"en",pluralRuleFunction:function(a){var b=Math.floor(Math.abs(a)),c=a.toString().replace(/^[^.]*\.?/,"").length;return a=Math.floor(a),1===b&&0===c?"one":"other"}};t.__addLocaleData(u),t.defaultLocale="en";var v=t,w=Math.round,x=function(a,b){var c=w(b.getTime()-a.getTime()),d=w(c/1e3),e=w(d/60),f=w(e/60),g=w(f/24),i=w(g/7),j=h(g),k=w(12*j),l=w(j);return{millisecond:c,second:d,minute:e,hour:f,day:g,week:i,month:k,year:l}},y=i,z=["second","minute","hour","day","month","year"],A=["best fit","numeric"];l(i,"__availableLocales__",{value:[]}),l(i,"__localeData__",{value:m(null)}),l(i,"__addLocaleData",{value:function(a){if(!a||!a.locale)throw new Error("Locale data provided to IntlRelativeFormat does not contain a `locale` property");if(!a.fields)throw new Error("Locale data provided to IntlRelativeFormat does not contain a `fields` property");v.__addLocaleData(a);var b=i.__availableLocales__,c=i.__localeData__,d=a.locale.toLowerCase().split("-")[0];b.push(d),c[d]=a}}),l(i,"defaultLocale",{enumerable:!0,writable:!0,value:void 0}),l(i,"thresholds",{enumerable:!0,value:{second:45,minute:45,hour:22,day:26,month:11}}),i.prototype.resolvedOptions=function(){return{locale:this._locale,style:this._options.style,units:this._options.units}},i.prototype._format=function(a){if(a=new Date(a),!a||!a.getTime())throw new TypeError("A Date must be provided to a IntlRelativeFormat instance's `format()` function");var b=x(new Date,a),c=this._options.units||this._selectUnits(b),d=b[c];if("numeric"!==this._options.style){var e=this._resolveRelativeUnits(d,c);if(e)return e}return this._resolveMessage(c).format({0:Math.abs(d),when:0>d?"past":"future"})},i.prototype._isValidUnits=function(a){if(!a||z.indexOf(a)>=0)return!0;if("string"==typeof a){var b=/s$/.test(a)&&a.substr(0,a.length-1);if(b&&z.indexOf(b)>=0)throw new Error('"'+a+'" is not a valid IntlRelativeFormat `units` value, did you mean: '+b)}throw new Error('"'+a+'" is not a valid IntlRelativeFormat `units` value, it must be one of: "'+z.join('", "')+'"')},i.prototype._resolveLocale=function(a){a||(a=i.defaultLocale),"string"==typeof a&&(a=[a]);var b,c,d,e=i.__availableLocales__;for(b=0,c=a.length;c>b;b+=1){if(d=a[b].split("-")[0].toLowerCase(),!/[a-z]{2,3}/.test(d))throw new Error("Language tag provided to IntlRelativeFormat is not structrually valid: "+d);if(e.indexOf(d)>=0)return d}throw new Error("No locale data has been added to IntlRelativeFormat for: "+a.join(", "))},i.prototype._resolveMessage=function(a){var b,c,d,e,f,g,h=this._messages;if(!h[a]){b=i.__localeData__[this._locale].fields[a],c=b.relativeTime,e="",f="";for(d in c.future)c.future.hasOwnProperty(d)&&(e+=" "+d+" {"+c.future[d].replace("{0}","#")+"}");for(d in c.past)c.past.hasOwnProperty(d)&&(f+=" "+d+" {"+c.past[d].replace("{0}","#")+"}");g="{when, select, future {{0, plural, "+e+"}}past {{0, plural, "+f+"}}}",h[a]=new v(g,this._locale)}return h[a]},i.prototype._resolveRelativeUnits=function(a,b){var c=i.__localeData__[this._locale].fields[b];return c.relative?c.relative[a]:void 0},i.prototype._resolveStyle=function(a){if(!a)return A[0];if(A.indexOf(a)>=0)return a;throw new Error('"'+a+'" is not a valid IntlRelativeFormat `style` value, it must be one of: "'+A.join('", "')+'"')},i.prototype._selectUnits=function(a){var b,c,d;for(b=0,c=z.length;c>b&&(d=z[b],!(Math.abs(a[d])<i.thresholds[d]));b+=1);return d};var B={locale:"en",pluralRuleFunction:function(a){var b=Math.floor(Math.abs(a)),c=a.toString().replace(/^[^.]*\.?/,"").length;return a=Math.floor(a),1===b&&0===c?"one":"other"},fields:{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"}}},minute:{displayName:"Minute",relativeTime:{future:{one:"in {0} minute",other:"in {0} minutes"},past:{one:"{0} minute ago",other:"{0} minutes ago"}}},hour:{displayName:"Hour",relativeTime:{future:{one:"in {0} hour",other:"in {0} hours"},past:{one:"{0} hour ago",other:"{0} hours ago"}}},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"}}},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"}}},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"}}}}};y.__addLocaleData(B),y.defaultLocale="en";var C=y;this.IntlRelativeFormat=C}).call(this); |
177
lib/core.js
@@ -16,3 +16,4 @@ "use strict"; | ||
var priority = ['second', 'minute', 'hour', 'day', 'month', 'year']; | ||
var FIELDS = ['second', 'minute', 'hour', 'day', 'month', 'year']; | ||
var STYLES = ['best fit', 'numeric']; | ||
@@ -22,3 +23,10 @@ // -- RelativeFormat -------------------------------------------------------- | ||
function RelativeFormat(locales, options) { | ||
options = options || {}; | ||
src$es5$$.defineProperty(this, '_locale', {value: this._resolveLocale(locales)}); | ||
src$es5$$.defineProperty(this, '_options', {value: { | ||
style: this._resolveStyle(options.style), | ||
units: this._isValidUnits(options.units) && options.units | ||
}}); | ||
src$es5$$.defineProperty(this, '_messages', {value: src$es5$$.objCreate(null)}); | ||
@@ -29,3 +37,3 @@ | ||
var relativeFormat = this; | ||
this.format = function (date) { | ||
this.format = function format(date) { | ||
return relativeFormat._format(date); | ||
@@ -40,7 +48,13 @@ }; | ||
if (!(data && data.locale)) { | ||
throw new Error('Locale data does not contain a `locale` property'); | ||
throw new Error( | ||
'Locale data provided to IntlRelativeFormat does not contain a ' + | ||
'`locale` property' | ||
); | ||
} | ||
if (!data.fields) { | ||
throw new Error('Locale data does not contain a `fields` property'); | ||
throw new Error( | ||
'Locale data provided to IntlRelativeFormat does not contain a ' + | ||
'`fields` property' | ||
); | ||
} | ||
@@ -85,5 +99,6 @@ | ||
RelativeFormat.prototype.resolvedOptions = function () { | ||
// TODO: Provide anything else? | ||
return { | ||
locale: this._locale | ||
locale: this._locale, | ||
style : this._options.style, | ||
units : this._options.units | ||
}; | ||
@@ -97,30 +112,89 @@ }; | ||
if (!(date && date.getTime())) { | ||
throw new TypeError('A date must be provided.'); | ||
throw new TypeError( | ||
'A Date must be provided to a IntlRelativeFormat instance\'s ' + | ||
'`format()` function' | ||
); | ||
} | ||
var d = src$diff$$.default(new Date(), date), | ||
key, msg, i, l; | ||
var diffReport = src$diff$$.default(new Date(), date); | ||
var units = this._options.units || this._selectUnits(diffReport); | ||
var diffInUnits = diffReport[units]; | ||
for (i = 0, l = priority.length; i < l; i++) { | ||
key = priority[i]; | ||
if (d[key] < RelativeFormat.thresholds[key]) { | ||
break; | ||
if (this._options.style !== 'numeric') { | ||
var relativeUnits = this._resolveRelativeUnits(diffInUnits, units); | ||
if (relativeUnits) { | ||
return relativeUnits; | ||
} | ||
} | ||
msg = this._resolveMessage(key); | ||
return msg.format({ | ||
'0' : d[key], | ||
when: d.duration < 0 ? 'past' : 'future' | ||
return this._resolveMessage(units).format({ | ||
'0' : Math.abs(diffInUnits), | ||
when: diffInUnits < 0 ? 'past' : 'future' | ||
}); | ||
}; | ||
RelativeFormat.prototype._resolveMessage = function (key) { | ||
var messages = this._messages, | ||
field, relativeTime, i, future, past; | ||
RelativeFormat.prototype._isValidUnits = function (units) { | ||
if (!units || FIELDS.indexOf(units) >= 0) { | ||
return true; | ||
} | ||
if (typeof units === 'string') { | ||
var suggestion = /s$/.test(units) && units.substr(0, units.length - 1); | ||
if (suggestion && FIELDS.indexOf(suggestion) >= 0) { | ||
throw new Error( | ||
'"' + units + '" is not a valid IntlRelativeFormat `units` ' + | ||
'value, did you mean: ' + suggestion | ||
); | ||
} | ||
} | ||
throw new Error( | ||
'"' + units + '" is not a valid IntlRelativeFormat `units` value, it ' + | ||
'must be one of: "' + FIELDS.join('", "') + '"' | ||
); | ||
}; | ||
RelativeFormat.prototype._resolveLocale = function (locales) { | ||
if (!locales) { | ||
locales = RelativeFormat.defaultLocale; | ||
} | ||
if (typeof locales === 'string') { | ||
locales = [locales]; | ||
} | ||
var availableLocales = RelativeFormat.__availableLocales__; | ||
var i, len, locale; | ||
for (i = 0, len = locales.length; i < len; i += 1) { | ||
// We just need the root part of the langage tag. | ||
locale = locales[i].split('-')[0].toLowerCase(); | ||
// Validate that the langage tag is structurally valid. | ||
if (!/[a-z]{2,3}/.test(locale)) { | ||
throw new Error( | ||
'Language tag provided to IntlRelativeFormat is not ' + | ||
'structrually valid: ' + locale | ||
); | ||
} | ||
// Return the first locale for which we have CLDR data registered. | ||
if (availableLocales.indexOf(locale) >= 0) { | ||
return locale; | ||
} | ||
} | ||
throw new Error( | ||
'No locale data has been added to IntlRelativeFormat for: ' + | ||
locales.join(', ') | ||
); | ||
}; | ||
RelativeFormat.prototype._resolveMessage = function (units) { | ||
var messages = this._messages; | ||
var field, relativeTime, i, future, past, message; | ||
// Create a new synthetic message based on the locale data from CLDR. | ||
if (!messages[key]) { | ||
field = RelativeFormat.__localeData__[this._locale].fields[key]; | ||
if (!messages[units]) { | ||
field = RelativeFormat.__localeData__[this._locale].fields[units]; | ||
relativeTime = field.relativeTime; | ||
@@ -136,2 +210,3 @@ future = ''; | ||
} | ||
for (i in relativeTime.past) { | ||
@@ -144,43 +219,49 @@ if (relativeTime.past.hasOwnProperty(i)) { | ||
messages[key] = new intl$messageformat$$.default( | ||
'{when, select, future {{0, plural, ' + future + '}}' + | ||
'past {{0, plural, ' + past + '}}}', | ||
this._locale | ||
); | ||
message = '{when, select, future {{0, plural, ' + future + '}}' + | ||
'past {{0, plural, ' + past + '}}}'; | ||
messages[units] = new intl$messageformat$$.default(message, this._locale); | ||
} | ||
return messages[key]; | ||
return messages[units]; | ||
}; | ||
RelativeFormat.prototype._resolveLocale = function (locales) { | ||
var availableLocales = RelativeFormat.__availableLocales__, | ||
locale, parts, i, len; | ||
RelativeFormat.prototype._resolveRelativeUnits = function (diff, units) { | ||
var field = RelativeFormat.__localeData__[this._locale].fields[units]; | ||
if (availableLocales.length === 0) { | ||
throw new Error('No locale data has been provided for IntlRelativeFormat yet'); | ||
if (field.relative) { | ||
return field.relative[diff]; | ||
} | ||
}; | ||
if (typeof locales === 'string') { | ||
locales = [locales]; | ||
RelativeFormat.prototype._resolveStyle = function (style) { | ||
// Default to "best fit" style. | ||
if (!style) { | ||
return STYLES[0]; | ||
} | ||
if (locales && locales.length) { | ||
for (i = 0, len = locales.length; i < len; i += 1) { | ||
locale = locales[i].toLowerCase().split('-')[0]; | ||
if (STYLES.indexOf(style) >= 0) { | ||
return style; | ||
} | ||
// Make sure the first part of the locale that we care about is | ||
// structurally valid. | ||
if (!/[a-z]{2,3}/i.test(locale)) { | ||
throw new RangeError('"' + locales[i] + '" is not a structurally valid language tag'); | ||
} | ||
throw new Error( | ||
'"' + style + '" is not a valid IntlRelativeFormat `style` value, it ' + | ||
'must be one of: "' + STYLES.join('", "') + '"' | ||
); | ||
}; | ||
if (availableLocales.indexOf(locale) >= 0) { | ||
break; | ||
} | ||
RelativeFormat.prototype._selectUnits = function (diffReport) { | ||
var i, l, units; | ||
for (i = 0, l = FIELDS.length; i < l; i += 1) { | ||
units = FIELDS[i]; | ||
if (Math.abs(diffReport[units]) < RelativeFormat.thresholds[units]) { | ||
break; | ||
} | ||
} | ||
return locale || RelativeFormat.defaultLocale.split('-')[0]; | ||
return units; | ||
}; | ||
//# sourceMappingURL=core.js.map |
@@ -13,5 +13,3 @@ "use strict"; | ||
function absRound(number) { | ||
return Math[number < 0 ? 'ceil' : 'floor'](number); | ||
} | ||
var round = Math.round; | ||
@@ -24,21 +22,22 @@ function daysToYears (days) { | ||
var src$diff$$default = function (dfrom, dto) { | ||
var round = Math.round, | ||
duration = absRound(dto.getTime() - dfrom.getTime()), | ||
ms = Math.abs(duration), | ||
ss = round(ms / 1000), | ||
mm = round(ss / 60), | ||
hh = round(mm / 60), | ||
dd = round(hh / 24), | ||
ww = round(dd / 7); | ||
var millisecond = round(dto.getTime() - dfrom.getTime()), | ||
second = round(millisecond / 1000), | ||
minute = round(second / 60), | ||
hour = round(minute / 60), | ||
day = round(hour / 24), | ||
week = round(day / 7); | ||
var rawYears = daysToYears(day), | ||
month = round(rawYears * 12), | ||
year = round(rawYears); | ||
return { | ||
duration: duration, | ||
week: ww, | ||
day: dd, | ||
hour: hh, | ||
minute: mm, | ||
second: ss, | ||
millisecond: ms, | ||
year: round((mm + daysToYears(dd) * 12) / 12), | ||
month: round(mm + daysToYears(dd) * 12), | ||
millisecond: millisecond, | ||
second : second, | ||
minute : minute, | ||
hour : hour, | ||
day : day, | ||
week : week, | ||
month : month, | ||
year : year | ||
}; | ||
@@ -45,0 +44,0 @@ }; |
{ | ||
"name": "intl-relativeformat", | ||
"version": "1.0.0-beta-1", | ||
"version": "1.0.0-beta-2", | ||
"description": "Formats JavaScript dates to relative time strings.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
177
src/core.js
@@ -15,3 +15,4 @@ /* | ||
var priority = ['second', 'minute', 'hour', 'day', 'month', 'year']; | ||
var FIELDS = ['second', 'minute', 'hour', 'day', 'month', 'year']; | ||
var STYLES = ['best fit', 'numeric']; | ||
@@ -21,3 +22,10 @@ // -- RelativeFormat -------------------------------------------------------- | ||
function RelativeFormat(locales, options) { | ||
options = options || {}; | ||
defineProperty(this, '_locale', {value: this._resolveLocale(locales)}); | ||
defineProperty(this, '_options', {value: { | ||
style: this._resolveStyle(options.style), | ||
units: this._isValidUnits(options.units) && options.units | ||
}}); | ||
defineProperty(this, '_messages', {value: objCreate(null)}); | ||
@@ -28,3 +36,3 @@ | ||
var relativeFormat = this; | ||
this.format = function (date) { | ||
this.format = function format(date) { | ||
return relativeFormat._format(date); | ||
@@ -39,7 +47,13 @@ }; | ||
if (!(data && data.locale)) { | ||
throw new Error('Locale data does not contain a `locale` property'); | ||
throw new Error( | ||
'Locale data provided to IntlRelativeFormat does not contain a ' + | ||
'`locale` property' | ||
); | ||
} | ||
if (!data.fields) { | ||
throw new Error('Locale data does not contain a `fields` property'); | ||
throw new Error( | ||
'Locale data provided to IntlRelativeFormat does not contain a ' + | ||
'`fields` property' | ||
); | ||
} | ||
@@ -84,5 +98,6 @@ | ||
RelativeFormat.prototype.resolvedOptions = function () { | ||
// TODO: Provide anything else? | ||
return { | ||
locale: this._locale | ||
locale: this._locale, | ||
style : this._options.style, | ||
units : this._options.units | ||
}; | ||
@@ -96,30 +111,89 @@ }; | ||
if (!(date && date.getTime())) { | ||
throw new TypeError('A date must be provided.'); | ||
throw new TypeError( | ||
'A Date must be provided to a IntlRelativeFormat instance\'s ' + | ||
'`format()` function' | ||
); | ||
} | ||
var d = diff(new Date(), date), | ||
key, msg, i, l; | ||
var diffReport = diff(new Date(), date); | ||
var units = this._options.units || this._selectUnits(diffReport); | ||
var diffInUnits = diffReport[units]; | ||
for (i = 0, l = priority.length; i < l; i++) { | ||
key = priority[i]; | ||
if (d[key] < RelativeFormat.thresholds[key]) { | ||
break; | ||
if (this._options.style !== 'numeric') { | ||
var relativeUnits = this._resolveRelativeUnits(diffInUnits, units); | ||
if (relativeUnits) { | ||
return relativeUnits; | ||
} | ||
} | ||
msg = this._resolveMessage(key); | ||
return msg.format({ | ||
'0' : d[key], | ||
when: d.duration < 0 ? 'past' : 'future' | ||
return this._resolveMessage(units).format({ | ||
'0' : Math.abs(diffInUnits), | ||
when: diffInUnits < 0 ? 'past' : 'future' | ||
}); | ||
}; | ||
RelativeFormat.prototype._resolveMessage = function (key) { | ||
var messages = this._messages, | ||
field, relativeTime, i, future, past; | ||
RelativeFormat.prototype._isValidUnits = function (units) { | ||
if (!units || FIELDS.indexOf(units) >= 0) { | ||
return true; | ||
} | ||
if (typeof units === 'string') { | ||
var suggestion = /s$/.test(units) && units.substr(0, units.length - 1); | ||
if (suggestion && FIELDS.indexOf(suggestion) >= 0) { | ||
throw new Error( | ||
'"' + units + '" is not a valid IntlRelativeFormat `units` ' + | ||
'value, did you mean: ' + suggestion | ||
); | ||
} | ||
} | ||
throw new Error( | ||
'"' + units + '" is not a valid IntlRelativeFormat `units` value, it ' + | ||
'must be one of: "' + FIELDS.join('", "') + '"' | ||
); | ||
}; | ||
RelativeFormat.prototype._resolveLocale = function (locales) { | ||
if (!locales) { | ||
locales = RelativeFormat.defaultLocale; | ||
} | ||
if (typeof locales === 'string') { | ||
locales = [locales]; | ||
} | ||
var availableLocales = RelativeFormat.__availableLocales__; | ||
var i, len, locale; | ||
for (i = 0, len = locales.length; i < len; i += 1) { | ||
// We just need the root part of the langage tag. | ||
locale = locales[i].split('-')[0].toLowerCase(); | ||
// Validate that the langage tag is structurally valid. | ||
if (!/[a-z]{2,3}/.test(locale)) { | ||
throw new Error( | ||
'Language tag provided to IntlRelativeFormat is not ' + | ||
'structrually valid: ' + locale | ||
); | ||
} | ||
// Return the first locale for which we have CLDR data registered. | ||
if (availableLocales.indexOf(locale) >= 0) { | ||
return locale; | ||
} | ||
} | ||
throw new Error( | ||
'No locale data has been added to IntlRelativeFormat for: ' + | ||
locales.join(', ') | ||
); | ||
}; | ||
RelativeFormat.prototype._resolveMessage = function (units) { | ||
var messages = this._messages; | ||
var field, relativeTime, i, future, past, message; | ||
// Create a new synthetic message based on the locale data from CLDR. | ||
if (!messages[key]) { | ||
field = RelativeFormat.__localeData__[this._locale].fields[key]; | ||
if (!messages[units]) { | ||
field = RelativeFormat.__localeData__[this._locale].fields[units]; | ||
relativeTime = field.relativeTime; | ||
@@ -135,2 +209,3 @@ future = ''; | ||
} | ||
for (i in relativeTime.past) { | ||
@@ -143,41 +218,47 @@ if (relativeTime.past.hasOwnProperty(i)) { | ||
messages[key] = new IntlMessageFormat( | ||
'{when, select, future {{0, plural, ' + future + '}}' + | ||
'past {{0, plural, ' + past + '}}}', | ||
this._locale | ||
); | ||
message = '{when, select, future {{0, plural, ' + future + '}}' + | ||
'past {{0, plural, ' + past + '}}}'; | ||
messages[units] = new IntlMessageFormat(message, this._locale); | ||
} | ||
return messages[key]; | ||
return messages[units]; | ||
}; | ||
RelativeFormat.prototype._resolveLocale = function (locales) { | ||
var availableLocales = RelativeFormat.__availableLocales__, | ||
locale, parts, i, len; | ||
RelativeFormat.prototype._resolveRelativeUnits = function (diff, units) { | ||
var field = RelativeFormat.__localeData__[this._locale].fields[units]; | ||
if (availableLocales.length === 0) { | ||
throw new Error('No locale data has been provided for IntlRelativeFormat yet'); | ||
if (field.relative) { | ||
return field.relative[diff]; | ||
} | ||
}; | ||
if (typeof locales === 'string') { | ||
locales = [locales]; | ||
RelativeFormat.prototype._resolveStyle = function (style) { | ||
// Default to "best fit" style. | ||
if (!style) { | ||
return STYLES[0]; | ||
} | ||
if (locales && locales.length) { | ||
for (i = 0, len = locales.length; i < len; i += 1) { | ||
locale = locales[i].toLowerCase().split('-')[0]; | ||
if (STYLES.indexOf(style) >= 0) { | ||
return style; | ||
} | ||
// Make sure the first part of the locale that we care about is | ||
// structurally valid. | ||
if (!/[a-z]{2,3}/i.test(locale)) { | ||
throw new RangeError('"' + locales[i] + '" is not a structurally valid language tag'); | ||
} | ||
throw new Error( | ||
'"' + style + '" is not a valid IntlRelativeFormat `style` value, it ' + | ||
'must be one of: "' + STYLES.join('", "') + '"' | ||
); | ||
}; | ||
if (availableLocales.indexOf(locale) >= 0) { | ||
break; | ||
} | ||
RelativeFormat.prototype._selectUnits = function (diffReport) { | ||
var i, l, units; | ||
for (i = 0, l = FIELDS.length; i < l; i += 1) { | ||
units = FIELDS[i]; | ||
if (Math.abs(diffReport[units]) < RelativeFormat.thresholds[units]) { | ||
break; | ||
} | ||
} | ||
return locale || RelativeFormat.defaultLocale.split('-')[0]; | ||
return units; | ||
}; |
@@ -9,5 +9,3 @@ /* | ||
function absRound(number) { | ||
return Math[number < 0 ? 'ceil' : 'floor'](number); | ||
} | ||
var round = Math.round; | ||
@@ -20,22 +18,23 @@ function daysToYears (days) { | ||
export default function (dfrom, dto) { | ||
var round = Math.round, | ||
duration = absRound(dto.getTime() - dfrom.getTime()), | ||
ms = Math.abs(duration), | ||
ss = round(ms / 1000), | ||
mm = round(ss / 60), | ||
hh = round(mm / 60), | ||
dd = round(hh / 24), | ||
ww = round(dd / 7); | ||
var millisecond = round(dto.getTime() - dfrom.getTime()), | ||
second = round(millisecond / 1000), | ||
minute = round(second / 60), | ||
hour = round(minute / 60), | ||
day = round(hour / 24), | ||
week = round(day / 7); | ||
var rawYears = daysToYears(day), | ||
month = round(rawYears * 12), | ||
year = round(rawYears); | ||
return { | ||
duration: duration, | ||
week: ww, | ||
day: dd, | ||
hour: hh, | ||
minute: mm, | ||
second: ss, | ||
millisecond: ms, | ||
year: round((mm + daysToYears(dd) * 12) / 12), | ||
month: round(mm + daysToYears(dd) * 12), | ||
millisecond: millisecond, | ||
second : second, | ||
minute : minute, | ||
hour : hour, | ||
day : day, | ||
week : week, | ||
month : month, | ||
year : year | ||
}; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1247033
6590