+ Ext, Bytes filters
This commit is contained in:
1 parent
bd7e97a624
commit
900f71b066
3 files changed
+33
No files matched your search
@@ -33,6 +33,8 @@ import RemoveNewline from './filters/RemoveNewline';
|
||||
import Strip from './filters/Strip';
|
||||
import Join from './filters/Join';
|
||||
import UppercaseFirst from './filters/UppercaseFirst';
|
||||
import Bytes from './filters/Bytes';
|
||||
import Ext from './filters/Ext';
|
||||
|
||||
import IOService from './services/io';
|
||||
import MenuService from './services/menu';
|
||||
@@ -79,6 +81,8 @@ app.run(($location, $rootScope, $http) => {
|
||||
Strip,
|
||||
Join,
|
||||
UppercaseFirst,
|
||||
Bytes,
|
||||
Ext,
|
||||
MainMenu,
|
||||
Navigation,
|
||||
Breadcrumbs,
|
||||
|
||||
@@ -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