diff --git a/src/client/app.js b/src/client/app.js index a41ff046..96fd4acc 100644 --- a/src/client/app.js +++ b/src/client/app.js @@ -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, diff --git a/src/client/filters/Bytes.js b/src/client/filters/Bytes.js new file mode 100644 index 00000000..24121a76 --- /dev/null +++ b/src/client/filters/Bytes.js @@ -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]}` + } + }); +}; diff --git a/src/client/filters/Ext.js b/src/client/filters/Ext.js new file mode 100644 index 00000000..fd6ef987 --- /dev/null +++ b/src/client/filters/Ext.js @@ -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); + } + }); +};