Commit c0cf1f5e by Jaxon

feat: 添加全局辅助函数 - 根据文件后缀判断是否为图片

1 parent 7361d632
......@@ -10,3 +10,17 @@ export function readFileAsDataURL(file) {
};
});
}
const IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif", "webp", "bmp", "svg", "ico"];
/**
* 根据文件后缀判断是否为图片
* @param {string} fileName - 文件名
* @returns {boolean}
*/
export function isImageFile(fileName) {
if (!fileName || typeof fileName !== "string")
return false;
const ext = fileName.split(".").pop()?.toLowerCase();
return IMAGE_EXTENSIONS.includes(ext);
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!