fix: 修改file工具函数
All checks were successful
deploy to server / build-and-deploy (push) Successful in 6m20s
All checks were successful
deploy to server / build-and-deploy (push) Successful in 6m20s
- 新增基于filename获取拓展名的函数 - 将文件大小格式化由以KB为基准修改为以Byte为基准
This commit is contained in:
@ -1,12 +1,19 @@
|
|||||||
export function formatFileSize(sizeInKB: number): string {
|
export function formatFileSize(sizeInBytes: number): string {
|
||||||
if (sizeInKB < 1024) {
|
if (sizeInBytes < 1024) {
|
||||||
|
return `${sizeInBytes.toFixed(2)} B`;
|
||||||
|
} else if (sizeInBytes < 1024 * 1024) {
|
||||||
|
const sizeInKB = sizeInBytes / 1024;
|
||||||
return `${sizeInKB.toFixed(2)} KB`;
|
return `${sizeInKB.toFixed(2)} KB`;
|
||||||
} else {
|
} else {
|
||||||
const sizeInMB = sizeInKB / 1024;
|
const sizeInMB = sizeInBytes / 1024 / 1024;
|
||||||
return `${sizeInMB.toFixed(2)} MB`;
|
return `${sizeInMB.toFixed(2)} MB`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFileExtension(filename: string): string {
|
||||||
|
return filename.split('.').pop() || '';
|
||||||
|
}
|
||||||
|
|
||||||
export function formatFileExtension(ext: string): string {
|
export function formatFileExtension(ext: string): string {
|
||||||
return ext.startsWith('.') ? ext.slice(1).toUpperCase() : ext.toUpperCase();
|
return ext.startsWith('.') ? ext.slice(1).toUpperCase() : ext.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user