file component and lib updated

This commit is contained in:
tmshv committed 2020-03-27 19:28:41 +03:00
1 parent b50b4b3ab3
commit 1756d89cb4
2 files changed
+32 -25

No files matched your search

+11 -10
View File
@@ -1,16 +1,17 @@
const getExt = (name: string) => /\.(\w+)$/.exec(name)[1]
const defaultExt = (ext: string) => ext.toUpperCase()
const exts = ['png', 'pdf', 'jpg', 'jpeg', 'gif', 'doc']
const extd = ['ПНГ', 'ПДФ', 'ЖПГ', 'ЖПГ', 'ГИФ', 'ДОК']
const units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ']
export function ext(filname: string): string {
const ext = getExt(filname)
const i = exts.indexOf(ext)
const mime = new Map([
['application/pdf', 'ПДФ'],
['image/jpeg', 'ЖПГ'],
['image/png', 'ПНГ'],
])
return i > -1
? extd[i]
: defaultExt(ext)
export function ext(mimeType: string): string {
if (mime.has(mimeType)) {
return mime.get(mimeType)
}
return mimeType
}
export function size(bytes: any, precision = 1): string {