You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/UI/Shared/FormatHelpers.js

66 lines
1.5 KiB

10 years ago
var moment = require('moment');
var filesize = require('filesize');
var UiSettings = require('./UiSettingsModel');
module.exports = {
bytes : function(sourceSize) {
10 years ago
var size = Number(sourceSize);
if (isNaN(size)) {
10 years ago
return '';
}
10 years ago
return filesize(size, {
base : 2,
round : 1
});
},
relativeDate : function(sourceDate) {
if (!sourceDate) {
10 years ago
return '';
}
10 years ago
var date = moment(sourceDate);
var calendarDate = date.calendar();
//TODO: It would be nice to not have to hack this...
10 years ago
var strippedCalendarDate = calendarDate.substring(0, calendarDate.indexOf(' at '));
if (strippedCalendarDate) {
10 years ago
return strippedCalendarDate;
}
if (date.isAfter(moment())) {
10 years ago
return date.fromNow(true);
}
if (date.isBefore(moment().add('years', -1))) {
10 years ago
return date.format(UiSettings.get('shortDateFormat'));
}
10 years ago
return date.fromNow();
},
pad : function(n, width, z) {
10 years ago
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
},
number : function(input) {
if (!input) {
10 years ago
return '0';
}
10 years ago
return input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
},
plural : function(input, unit) {
if (input === 1) {
return unit;
}
return unit + 's';
10 years ago
}
};