9 lines
262 B
TypeScript
9 lines
262 B
TypeScript
export function checkFileType(file: File, accepts: string[]) {
|
|
if (!accepts || accepts.length === 0) {
|
|
return true;
|
|
}
|
|
const newTypes = accepts.join('|');
|
|
const reg = new RegExp(`${String.raw`\.(` + newTypes})$`, 'i');
|
|
return reg.test(file.name);
|
|
}
|