-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.tsx
41 lines (39 loc) · 1.24 KB
/
file.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export const imageExtRegex = /jpeg|jpg|png|webp|gif/i;
export const audioExtRegex =
/3gp|aac|aax|act|aiff|flac|gsm|m4a|m4b|m4p|tta|wma|mp3|webm|wav/i;
export const videoExtRegex = /mov|vod|mp4|avi/i;
export const getFileType = (extOrType: string) => {
if (extOrType.indexOf('/') > -1) {
const type = extOrType.split('/')[0];
if (type === 'video') return 'video';
if (type === 'audio') return 'audio';
if (type === 'image') return 'image';
return 'file';
}
if (extOrType.match(imageExtRegex)) return 'image';
if (extOrType.match(audioExtRegex)) return 'audio';
if (extOrType.match(videoExtRegex)) return 'video';
return 'file';
};
export function getFileExtension(filePath: string) {
const idx = filePath.lastIndexOf('.');
if (idx === -1) return '';
return filePath.slice(idx - filePath.length).toLowerCase();
}
export function generateFileName(fileName: string, extension: string) {
if (fileName.indexOf(extension) > -1) {
return fileName;
} else {
if (extension.indexOf('.') === 0) {
return `${fileName}${extension}`;
} else {
return `${fileName}.${extension}`;
}
}
}
export function passwordRuleCheck(): boolean {
return false;
}
export function idRuleCheck(): boolean {
return false;
}