85 lines
2.5 KiB
JavaScript
85 lines
2.5 KiB
JavaScript
export const isImage = (file) => {
|
|
// looks for "image/whatever" in mime type
|
|
const regex = new RegExp("^image/.+", "gi");
|
|
// returns boolean
|
|
return regex.test(file.mime);
|
|
};
|
|
|
|
export const isAudio = (file) => {
|
|
// looks for "audio/whatever" in mime type
|
|
const regex = new RegExp("^audio/.+", "gi");
|
|
// returns boolean
|
|
return regex.test(file.mime);
|
|
};
|
|
|
|
export const isVideo = (file) => {
|
|
// looks for "video/whatever" in mime type
|
|
const regex = new RegExp("^video/.+", "gi");
|
|
// returns boolean
|
|
return regex.test(file.mime);
|
|
};
|
|
|
|
export const isText = (file) => {
|
|
// looks for "text/whatever" in mime type
|
|
const regex = new RegExp("^text/.+", "gi");
|
|
// checks that file.mime is neither text/pdf or text/x-pdf
|
|
if (file.mime == "text/pdf" || file.mime == "text/x-pdf") return false;
|
|
// returns boolean
|
|
return regex.test(file.mime);
|
|
};
|
|
|
|
export const isPdf = (file) => {
|
|
// matches against known pdf formats
|
|
const formats = [
|
|
"text/pdf",
|
|
"text/x-pdf",
|
|
"application/pdf",
|
|
"application/x-pdf",
|
|
"application/vnd.pdf",
|
|
"application/acrobat",
|
|
];
|
|
|
|
return formats.includes(file.mime);
|
|
};
|
|
|
|
export const isDoc = (file) => {
|
|
// matches against known word/doc formats
|
|
const formats = [
|
|
"application/msword",
|
|
"application/vnd.ms-word.document.macroEnabled12",
|
|
"application/vnd.ms-word.template.macroEnabled.12",
|
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
"application/vnd.oasis.opendocument.text",
|
|
"application/x-abiword",
|
|
];
|
|
|
|
return formats.includes(file.mime);
|
|
};
|
|
|
|
export const isSpreadsheet = (file) => {
|
|
// matches against known excel/spreadsheet formats
|
|
const formats = [
|
|
"application/vnd.mx-excel",
|
|
"application/vnd.ms-exce;.sheet.macroEnabled12",
|
|
"application/vnd.ms-excel.template.macroEnabled.12",
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"application/vnd.oasis.opendocument.spreadsheet",
|
|
];
|
|
|
|
return formats.includes(file.mime);
|
|
};
|
|
|
|
export const isArchive = (file) => {
|
|
// matches against known archive formats
|
|
const formats = [
|
|
"application/zip",
|
|
"application/gzip",
|
|
"application/x-freearc",
|
|
"application/x-bzip",
|
|
"application/x-bzip2",
|
|
"application/vnd.rar",
|
|
"application/x-7z-compressed",
|
|
];
|
|
|
|
return formats.includes(file.mime);
|
|
};
|