mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-29 06:25:18 -04:00
Cleans code.
This commit is contained in:
parent
cecc5c57a2
commit
885ce9e9e9
1 changed files with 1 additions and 37 deletions
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
|
|
||||||
var reParseSize = /^\s*([\.\d]+)\s*([kmgt]?)b?\s*$/i,
|
var decimalMetric = {
|
||||||
decimalMetric = {
|
|
||||||
t: 1000.0,
|
t: 1000.0,
|
||||||
k: 1000.0,
|
k: 1000.0,
|
||||||
u: ['B', 'KB', 'MB', 'GB', 'TB']
|
u: ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
@ -15,30 +14,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
defaultMetric = decimalMetric,
|
defaultMetric = decimalMetric,
|
||||||
defaultDateFormat = 'YYYY-MM-DD HH:mm',
|
defaultDateFormat = 'YYYY-MM-DD HH:mm',
|
||||||
|
|
||||||
parseSize = function (str) {
|
|
||||||
|
|
||||||
var match = reParseSize.exec(str),
|
|
||||||
kilo = decimalMetric.k,
|
|
||||||
val, unit;
|
|
||||||
|
|
||||||
if (!match) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = parseFloat(match[1]);
|
|
||||||
unit = match[2].toLowerCase();
|
|
||||||
if (unit === 'k') {
|
|
||||||
val *= kilo;
|
|
||||||
} else if (unit === 'm') {
|
|
||||||
val *= kilo * kilo;
|
|
||||||
} else if (unit === 'g') {
|
|
||||||
val *= kilo * kilo * kilo;
|
|
||||||
} else if (unit === 't') {
|
|
||||||
val *= kilo * kilo * kilo * kilo;
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
},
|
|
||||||
|
|
||||||
setDefaultMetric = function (metric) {
|
setDefaultMetric = function (metric) {
|
||||||
|
|
||||||
if (!metric) {
|
if (!metric) {
|
||||||
|
@ -73,15 +48,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
defaultDateFormat = dateFormat;
|
defaultDateFormat = dateFormat;
|
||||||
},
|
},
|
||||||
|
|
||||||
parseDate = function (str, dateFormat) {
|
|
||||||
|
|
||||||
try { // problems with ie < 9 :(
|
|
||||||
return moment(str, dateFormat || defaultDateFormat).valueOf() || null;
|
|
||||||
} catch (err) {}
|
|
||||||
|
|
||||||
return Date.parse(str).valueOf() || null;
|
|
||||||
},
|
|
||||||
|
|
||||||
formatDate = function (millis, dateFormat) {
|
formatDate = function (millis, dateFormat) {
|
||||||
|
|
||||||
if (!_.isNumber(millis) || !millis) {
|
if (!_.isNumber(millis) || !millis) {
|
||||||
|
@ -92,11 +58,9 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parseSize: parseSize,
|
|
||||||
setDefaultMetric: setDefaultMetric,
|
setDefaultMetric: setDefaultMetric,
|
||||||
formatSize: formatSize,
|
formatSize: formatSize,
|
||||||
setDefaultDateFormat: setDefaultDateFormat,
|
setDefaultDateFormat: setDefaultDateFormat,
|
||||||
parseDate: parseDate,
|
|
||||||
formatDate: formatDate
|
formatDate: formatDate
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue