Documents serverside

This commit is contained in:
tmshv committed 2017-05-26 13:44:53 +03:00
1 parent 244f1efd03
commit 864d895105
17 files changed
+528 -119

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
function splitBy(key) {
return items => {
return items.reduce((acc, item) => {
const name = key(item)
const items = acc.get(name) || []
return acc.set(key(item), [...items, item])
}, new Map())
}
}
exports.splitBy = splitBy
+27
View File
@@ -0,0 +1,27 @@
function ext(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)
return i > -1
? extd[i]
: defaultExt(ext)
}
function size(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]}`
}
exports.ext = ext
exports.size = size
+12
View File
@@ -0,0 +1,12 @@
function titleCase(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
function trim(string) {
return string
.replace(/^\s+/, '')
.replace(/\s+$/, '')
}
exports.titleCase = titleCase
exports.trim = trim