2 lines
4.5 KiB
JavaScript
2 lines
4.5 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("relative-time-format",[],t):"object"==typeof exports?exports["relative-time-format"]=t():e["relative-time-format"]=t()}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n="en",o={};function a(){return n}function i(e){return o[e]}function l(e){var t=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).localeMatcher||"lookup";switch(t){case"lookup":case"best fit":return u(e);default:throw new RangeError('Invalid "localeMatcher" option: '.concat(t))}}function u(e){if(i(e))return e;for(var t=e.split("-");e.length>1;)if(t.pop(),i(e=t.join("-")))return e}function c(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var s=["second","minute","hour","day","week","month","quarter","year"],h=["auto","always"],p=["long","short","narrow"],d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),f(this,"numeric","always"),f(this,"style","long"),f(this,"localeMatcher","lookup");var n=r.numeric,o=r.style,i=r.localeMatcher;if(n){if(h.indexOf(n)<0)throw new RangeError('Invalid "numeric" option: '.concat(n));this.numeric=n}if(o){if(p.indexOf(o)<0)throw new RangeError('Invalid "style" option: '.concat(o));this.style=o}if(i&&(this.localeMatcher=i),"string"==typeof t&&(t=[t]),t.push(a()),this.locale=e.supportedLocalesOf(t,{localeMatcher:this.localeMatcher})[0],!this.locale)throw new TypeError("No supported locale was found");this.locale=l(this.locale,{localeMatcher:this.localeMatcher}),"undefined"!=typeof Intl&&Intl.NumberFormat&&(this.numberFormat=new Intl.NumberFormat(this.locale))}var t,r,n;return t=e,(r=[{key:"format",value:function(e,t){return this.getRule(e,t).replace("{0}",this.formatNumber(Math.abs(e)))}},{key:"formatToParts",value:function(e,t){var r=this.getRule(e,t),n=r.indexOf("{0}");if(n<0)return[{type:"literal",value:r}];var o=[];return n>0&&o.push({type:"literal",value:r.slice(0,n)}),o.push({unit:t,type:"integer",value:this.formatNumber(Math.abs(e))}),n+"{0}".length<r.length-1&&o.push({type:"literal",value:r.slice(n+"{0}".length)}),o}},{key:"getRule",value:function(e,t){if(s.indexOf(t)<0)throw new RangeError("Unknown time unit: ".concat(t,"."));var r=i(this.locale)[this.style][t];if("auto"===this.numeric)if(-2===e||-1===e){var n=r["previous".concat(-1===e?"":"-"+Math.abs(e))];if(n)return n}else if(1===e||2===e){var o=r["next".concat(1===e?"":"-"+Math.abs(e))];if(o)return o}else if(0===e&&r.current)return r.current;var a=r[e<=0?"past":"future"];if("string"==typeof a)return a;var l=i(this.locale).quantify,u=l&&l(Math.abs(e));return a[u=u||"other"]||a.other}},{key:"formatNumber",value:function(e){return this.numberFormat?this.numberFormat.format(e):String(e)}},{key:"resolvedOptions",value:function(){return{locale:this.locale,style:this.style,numeric:this.numeric}}}])&&c(t.prototype,r),n&&c(t,n),e}();d.supportedLocalesOf=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"string"==typeof e&&(e=[e]),e.filter(function(e){return l(e,t)})},d.addLocale=function(e){if(!e)throw new Error("No locale data passed");o[e.locale]=e},d.setDefaultLocale=function(e){n=e},d.getDefaultLocale=a,r.d(t,"default",function(){return d})}])});
|
|
//# sourceMappingURL=relative-time-format.min.js.map
|