abbott-methods
Version:
abbott,methods,method,functions,function
42 lines (39 loc) • 1.34 kB
text/typescript
const accept: Record<string | number | symbol, any> = {
imgAll: 'image/*',
gif: 'image/gif',
jpg: 'image/jpg',
jpeg: 'image/jpeg,',
png: 'image/png',
webp: 'image/webp',
bmp: 'image/bmp',
svg: 'image/svg+xml',
xls: 'application/vnd.ms-excel',
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
doc: 'application/msword',
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
txt: 'text/plain',
csv: 'text/csv',
pdf: 'application/pdf',
zip: 'application/zip',
rar: 'application/x-rar-compressed',
gz: 'application/x-gzip'
}
export const defineAccept = (ary: any[]): string => {
const n: any[] = []
for (let index = 0; index < ary.length; index++) {
const element = ary[index]
if (accept[element]) {
n.push(accept[element])
} else {
n.push(element)
}
}
return n.join(',')
}
export const acceptImage: string = defineAccept(['imgAll'])
export const acceptImgPdf: string = defineAccept(['imgAll', 'pdf'])
export const acceptPdf: string = defineAccept(['pdf'])
export const acceptExcel: string = defineAccept(['xls', 'xlsx'])
export const acceptWord: string = defineAccept(['doc', 'docx'])
export const acceptText: string = defineAccept(['txt', 'csv'])
export const acceptZip: string = defineAccept(['zip', 'rar', 'gz'])