1 line
2.4 KiB
JavaScript
1 line
2.4 KiB
JavaScript
define(["exports","./globalize.js"],function(_exports,_globalize){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var units=[["year",31536e6],["month",2592e6],["week",6048e5],["day",864e5],["hour",36e5],["minute",6e4],["second",1e3]];function numberToString(value,maximumFractionDigits){try{return new Intl.NumberFormat(_globalize.default.getCurrentLocales(),{style:"decimal",maximumFractionDigits:null==maximumFractionDigits?1:maximumFractionDigits}).format(value)}catch(err){return console.log("Error in NumberFormat: "+err),value}}var humaneDateFn=window.Intl&&window.Intl.RelativeTimeFormat?function(date_str,isPastEvent){for(var unit,date_str=new Date(Date.parse(date_str)).getTime()-Date.now(),elapsedMsAbs=Math.abs(date_str),i=0,length=units.length;i<length&&!(elapsedMsAbs>=(unit=units[i])[1]);i++);return date_str=Math.round(date_str/unit[1]),!1!==isPastEvent&&-1<(date_str=Math.min(date_str,1))&&(date_str=-1,unit=units[units.length-1]),new Intl.RelativeTimeFormat(_globalize.default.getCurrentLocales()).format(date_str,unit[0])}:function(date_str){var format,time_formats=[[90,"a minute"],[3600,"minutes",60],[5400,"an hour"],[86400,"hours",3600],[129600,"a day"],[604800,"days",86400],[907200,"a week"],[2628e3,"weeks",604800],[3942e3,"a month"],[31536e3,"months",2628e3],[47304e3,"a year"],[31536e5,"years",31536e3]],seconds=(new Date-new Date(Date.parse(date_str)))/1e3,i=0;for(seconds<0&&(seconds=Math.abs(seconds));null!=(format=time_formats[i++]);)if(seconds<format[0])return 2===format.length?format[1]+" ago":Math.round(seconds/format[2])+" "+format[1]+" ago";return 47304e5<seconds?Math.round(seconds/47304e5)+" centuries ago":date_str};_exports.default={formatRelativeTime:humaneDateFn,bitrateToString:function(value){return 1e3<(value/=1e3)?numberToString(value/=1e3,0)+" mbps":numberToString(parseInt(value))+" kbps"},sizeToString:function(size){var gb=1073741824;return gb<=size?numberToString(size/gb,1)+" GB":numberToString(size/1048576,1)+" MB"},numberToString:numberToString,getResolutionText:function(item){var width,height;return"Video"!==item.MediaType?item.Width&&item.Height?item.Width+"x"+item.Height:null:(width=item.Width,height=item.Height,width&&height?3800<=width||2e3<=height?"4K":2500<=width||1400<=height?item.IsInterlaced?"1440i":"1440p":1800<=width||1e3<=height?item.IsInterlaced?"1080i":"1080p":1200<=width||700<=height?item.IsInterlaced?"720i":"720p":700<=width||400<=height?item.IsInterlaced?"480i":"480p":"SD":null)}}}); |