Files
iot-device-management-frontend/apps/web-antd/src/components/upload/helper.ts

17 lines
483 B
TypeScript
Raw Normal View History

2025-04-17 23:30:34 +08:00
export function checkFileType(file: File, accepts: string[]) {
if (!accepts || accepts.length === 0) {
2025-04-18 13:08:20 +08:00
return true;
2025-04-17 23:30:34 +08:00
}
2025-04-18 13:08:20 +08:00
const newTypes = accepts.join('|');
const reg = new RegExp('\\.(' + newTypes + ')$', 'i');
2025-04-17 23:30:34 +08:00
return reg.test(file.name);
}
2025-04-18 13:08:20 +08:00
/**
*
*/
export const defaultImageAccepts = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
2025-04-17 23:30:34 +08:00
2025-04-18 13:08:20 +08:00
export function checkImgType(file: File, accepts: string[] = defaultImageAccepts) {
return checkFileType(file, accepts);
}