sonar 1 left. all regex fixed
This commit is contained in:
@@ -62,7 +62,12 @@ export default {
|
||||
if(uploadFile) {
|
||||
await this.filesStore.upload(formData);
|
||||
}
|
||||
this.uploadFileName = (uploadFile.name).match(/(.*)\.csv/)[1];
|
||||
if (uploadFile.name.endsWith('.csv')) {
|
||||
this.uploadFileName = uploadFile.name.slice(0, -4);
|
||||
} else {
|
||||
// 處理錯誤或無效的文件格式
|
||||
this.uploadFileName = ''; // 或者其他適合的錯誤處理方式
|
||||
}
|
||||
// 清除選擇文件
|
||||
if(fileInput) {
|
||||
fileInput.value = '';
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
// sonar-qube replace regex method
|
||||
const formatNumberWithCommas = (numberStr) => {
|
||||
// 反轉字符串
|
||||
let reversedStr = numberStr.split('').reverse().join('');
|
||||
|
||||
// 將反轉後的字符串每 3 個字符為一組進行分割
|
||||
let groupedStr = reversedStr.match(/.{1,3}/g);
|
||||
|
||||
// 用逗號將這些組連接起來
|
||||
let joinedStr = groupedStr.join(',');
|
||||
|
||||
// 再次反轉回原來的順序
|
||||
let finalStr = joinedStr.split('').reverse().join('');
|
||||
|
||||
return finalStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 將數字轉換成帶有逗號格式(ex: 1000 -> 1,000)
|
||||
* 也可以改用原生 JS 方法 `.toLocaleString('en-US')`
|
||||
@@ -6,6 +23,7 @@
|
||||
*/
|
||||
export default function numberLabel(num) {
|
||||
let parts = num.toString().split('.');
|
||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
parts[0] = formatNumberWithCommas(parts[0]);
|
||||
console.log(parts[0]);
|
||||
return parts.join('.');
|
||||
}
|
||||
|
||||
@@ -228,7 +228,8 @@ export function formatTime(seconds) {
|
||||
export function formatMaxTwo(times) {
|
||||
const formattedTimes = [];
|
||||
for (let time of times) {
|
||||
let units = time.match(/\d+[dhms]/g); // 匹配數字和單位(天、小時、分鐘、秒)
|
||||
// 匹配數字和單位(天、小時、分鐘、秒), 假設數字不可能大於10位數
|
||||
let units = time.match(/\d{1,10}[dhms]/g);
|
||||
let formattedTime = '';
|
||||
let count = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user