-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.mjs
32 lines (29 loc) · 892 Bytes
/
util.mjs
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
function getFileNames(name = "") {
const lastDotIndex = name.lastIndexOf(".");
if (lastDotIndex === -1 || lastDotIndex === 0) {
// 未找到点或点出现在文件名的开头,没有有效的扩展名
return {};
}
const fileExt = name.slice(lastDotIndex + 1).toLowerCase();
const fileName = name.slice(0, lastDotIndex);
return { fileExt, fileName };
}
function formatNames(name = "") {
const { fileExt, fileName } = getFileNames(name);
const outputName = `output-${name}`;
return { outputName, fileExt, fileName };
}
function verifyUpLoader(files) {
if (!files || files.length === 0) {
alert("未选择文件!");
return false;
} else {
const { fileExt } = getFileNames(files[0].name);
if (!fileExt) {
alert("非法文件类型!");
return false;
}
return true;
}
}
export { getFileNames, formatNames, verifyUpLoader };