+ Ext, Bytes filters
This commit is contained in:
1 parent
bd7e97a624
commit
900f71b066
3 files changed
+33
No files matched your search
@@ -0,0 +1,13 @@
|
||||
export default function(app) {
|
||||
app.filter('bytes', () => {
|
||||
return (bytes, precision=1) => {
|
||||
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '';
|
||||
|
||||
const units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ'];
|
||||
const number = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
|
||||
const size = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision);
|
||||
return `${size} ${units[number]}`
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
export default function(app) {
|
||||
app.filter('ext', () => {
|
||||
return (filname) => {
|
||||
let getExt = name => /\.(\w+)$/.exec(name)[1];
|
||||
let defaultExt = ext => ext.toUpperCase();
|
||||
|
||||
const exts = ['png', 'pdf', 'jpg', 'jpeg', 'gif', 'doc'];
|
||||
const extd = ['ПНГ', 'ПДФ', 'ЖПГ', 'ЖПГ', 'ГИФ', 'ДОК'];
|
||||
|
||||
let ext = getExt(filname);
|
||||
const i = exts.indexOf(ext);
|
||||
if(i > -1) return extd[i];
|
||||
return defaultExt(ext);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user