added file icon functions
This commit is contained in:
@@ -1,11 +1,50 @@
|
|||||||
export const isEmpty = (obj: object | string) => {
|
/**
|
||||||
if (obj) {
|
* Tests if an object or string is empty.
|
||||||
if (typeof obj === "string") {
|
*
|
||||||
return obj.length == 0;
|
* @param {object|string} objOrString The object or string.
|
||||||
} else if (typeof obj == "object" && Object.keys(obj).length === 0) {
|
* @returns {boolean} If the object or string is empty.
|
||||||
|
*/
|
||||||
|
export const isEmpty = (objOrString: object | string): boolean => {
|
||||||
|
if (objOrString) {
|
||||||
|
if (typeof objOrString === "string") {
|
||||||
|
return objOrString.length == 0;
|
||||||
|
} else if (
|
||||||
|
typeof objOrString == "object" &&
|
||||||
|
Object.keys(objOrString).length === 0
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a url to a file type icon based on file name.
|
||||||
|
*
|
||||||
|
* @param {string} fileName The filename with extension.
|
||||||
|
* @returns {string} The url to the file type icon.
|
||||||
|
*/
|
||||||
|
export const getFileIconImagePath = (fileName: string): string => {
|
||||||
|
const ext = fileName.split(".").pop();
|
||||||
|
return `/img/fileicons/${ext}.png`;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a url to a file preview icon based on file url.
|
||||||
|
*
|
||||||
|
* @param {string} url The url of the file.
|
||||||
|
* @returns {string} The url to the file preview icon.
|
||||||
|
*/
|
||||||
|
export const getFilePreview = (url: string): string => {
|
||||||
|
const ext = url.split(".").pop();
|
||||||
|
if (ext) {
|
||||||
|
if (/(gif|jpe?g|png)/i.test(ext)) {
|
||||||
|
return `${url}?w=200`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `/img/fileicons/${ext}.png`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "/img/fileicons/unknown.png";
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user