Use Number.parseInt/parseFloat/isNaN/isFinite instead of globals (S7773)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 00:26:59 +08:00
parent 12068281e9
commit 3768c6e5ec
11 changed files with 27 additions and 27 deletions

View File

@@ -341,7 +341,7 @@ const secondaryStatData = ref(null);
*/ */
const getPercentLabel = (val) => { const getPercentLabel = (val) => {
if (Number((val * 100).toFixed(1)) >= 100) return 100; if (Number((val * 100).toFixed(1)) >= 100) return 100;
else return parseFloat((val * 100).toFixed(1)); else return Number.parseFloat((val * 100).toFixed(1));
}; };
/** /**

View File

@@ -505,7 +505,7 @@ const progressWidth = (value) => {
*/ */
const getPercentLabel = (val) => { const getPercentLabel = (val) => {
if (Number((val * 100).toFixed(1)) >= 100) return 100; if (Number((val * 100).toFixed(1)) >= 100) return 100;
else return parseFloat((val * 100).toFixed(1)); else return Number.parseFloat((val * 100).toFixed(1));
}; };
/** /**

View File

@@ -277,7 +277,7 @@ watch(infinite404, (newValue) => {
*/ */
function getPercentLabel(val) { function getPercentLabel(val) {
if (Number((val * 100).toFixed(1)) >= 100) return 100; if (Number((val * 100).toFixed(1)) >= 100) return 100;
else return parseFloat((val * 100).toFixed(1)); else return Number.parseFloat((val * 100).toFixed(1));
} }
/** /**
* set progress bar width * set progress bar width

View File

@@ -936,7 +936,7 @@ function sliderValueRange(e, direction) {
} }
} }
// Recalculate the chart mask // Recalculate the chart mask
if (!isNaN(closestIndexes[0]) && !isNaN(closestIndexes[1])) if (!Number.isNaN(closestIndexes[0]) && !Number.isNaN(closestIndexes[1]))
resizeMask(chartComplete.value); resizeMask(chartComplete.value);
else return; else return;
} }

View File

@@ -391,7 +391,7 @@ function sliderTimeRange(e, direction) {
if (direction === "start") endMinDate.value = e; if (direction === "start") endMinDate.value = e;
else if (direction === "end") startMaxDate.value = e; else if (direction === "end") startMaxDate.value = e;
// Recalculate the chart mask // Recalculate the chart mask
if (!isNaN(closestIndexes[0]) && !isNaN(closestIndexes[1])) if (!Number.isNaN(closestIndexes[0]) && !Number.isNaN(closestIndexes[1]))
resizeMask(chart.value); resizeMask(chart.value);
else return; else return;
} }

View File

@@ -334,7 +334,7 @@ function barOptions() {
*/ */
function getPercentLabel(val) { function getPercentLabel(val) {
if (Number((val * 100).toFixed(1)) >= 100) return 100; if (Number((val * 100).toFixed(1)) >= 100) return 100;
else return parseFloat((val * 100).toFixed(1)); else return Number.parseFloat((val * 100).toFixed(1));
} }
/** /**

View File

@@ -179,7 +179,7 @@ const statData = ref(null);
*/ */
function getPercentLabel(val) { function getPercentLabel(val) {
if (Number((val * 100).toFixed(1)) >= 100) return 100; if (Number((val * 100).toFixed(1)) >= 100) return 100;
else return parseFloat((val * 100).toFixed(1)); else return Number.parseFloat((val * 100).toFixed(1));
} }
/** Transforms raw stats into display-ready format with localized numbers and time labels. */ /** Transforms raw stats into display-ready format with localized numbers and time labels. */

View File

@@ -196,16 +196,16 @@ function onFocus(event) {
*/ */
function onChange(event) { function onChange(event) {
let decoratedInputValue; let decoratedInputValue;
if (isNaN(event.target.value)) { if (Number.isNaN(Number(event.target.value))) {
event.target.value = "00"; event.target.value = "00";
} else { } else {
event.target.value = event.target.value.toString(); event.target.value = event.target.value.toString();
} }
decoratedInputValue = event.target.value.toString(); decoratedInputValue = event.target.value.toString();
const inputValue = parseInt(event.target.value, 10); const inputValue = Number.parseInt(event.target.value, 10);
const max = parseInt(event.target.dataset.max, 10); const max = Number.parseInt(event.target.dataset.max, 10);
const min = parseInt(event.target.dataset.min, 10); const min = Number.parseInt(event.target.dataset.min, 10);
if (inputValue > max) { if (inputValue > max) {
decoratedInputValue = max.toString().padStart(2, "0"); decoratedInputValue = max.toString().padStart(2, "0");
} else if (inputValue < min) { } else if (inputValue < min) {
@@ -266,8 +266,8 @@ function actionUpDown(input, goUp, selectIt = false) {
} }
function getNewValue(input) { function getNewValue(input) {
const newVal = parseInt(input.value, 10); const newVal = Number.parseInt(input.value, 10);
return isNaN(newVal) ? 0 : newVal; return Number.isNaN(newVal) ? 0 : newVal;
} }
function handleArrowUp(newVal, tUnit, input) { function handleArrowUp(newVal, tUnit, input) {
@@ -294,7 +294,7 @@ function handleArrowDown(newVal, tUnit) {
function incrementPreviousUnit(input) { function incrementPreviousUnit(input) {
if (input.dataset.index > 0) { if (input.dataset.index > 0) {
const prevUnit = document.querySelector( const prevUnit = document.querySelector(
`input[data-index="${parseInt(input.dataset.index, 10) - 1}"]`, `input[data-index="${Number.parseInt(input.dataset.index, 10) - 1}"]`,
); );
if (prevUnit) actionUpDown(prevUnit, true); if (prevUnit) actionUpDown(prevUnit, true);
} }
@@ -324,8 +324,8 @@ function updateInputValue(input, newVal, tUnit) {
* @param {string} [size] - 'max' or 'min' to set boundary days. * @param {string} [size] - 'max' or 'min' to set boundary days.
*/ */
function secondToDate(totalSec, size) { function secondToDate(totalSec, size) {
totalSec = parseInt(totalSec, 10); totalSec = Number.parseInt(totalSec, 10);
if (!isNaN(totalSec)) { if (!Number.isNaN(totalSec)) {
seconds.value = totalSec % 60; seconds.value = totalSec % 60;
minutes.value = (Math.floor(totalSec - seconds.value) / 60) % 60; minutes.value = (Math.floor(totalSec - seconds.value) / 60) % 60;
hours.value = Math.floor(totalSec / 3600) % 24; hours.value = Math.floor(totalSec / 3600) % 24;
@@ -344,8 +344,8 @@ function calculateTotalSeconds() {
let total = 0; let total = 0;
for (const unit in tUnits.value) { for (const unit in tUnits.value) {
const val = parseInt(tUnits.value[unit].val, 10); const val = Number.parseInt(tUnits.value[unit].val, 10);
if (!isNaN(val)) { if (!Number.isNaN(val)) {
total += val * tUnits.value[unit].rate; total += val * tUnits.value[unit].rate;
} }
} }

View File

@@ -22,8 +22,8 @@ export default function abbreviateNumber(totalSeconds) {
let result = ""; let result = "";
let symbols = ["d", "h", "m", "s"]; let symbols = ["d", "h", "m", "s"];
totalSeconds = parseInt(totalSeconds); totalSeconds = Number.parseInt(totalSeconds);
if (!isNaN(totalSeconds)) { if (!Number.isNaN(totalSeconds)) {
seconds = totalSeconds % 60; seconds = totalSeconds % 60;
minutes = (Math.floor(totalSeconds - seconds) / 60) % 60; minutes = (Math.floor(totalSeconds - seconds) / 60) % 60;
hours = Math.floor(totalSeconds / 3600) % 24; hours = Math.floor(totalSeconds / 3600) % 24;

View File

@@ -231,7 +231,7 @@ export function getXIndex(data, xValue) {
* or null if the input is NaN. * or null if the input is NaN.
*/ */
export function formatTime(seconds) { export function formatTime(seconds) {
if (!isNaN(seconds)) { if (!Number.isNaN(Number(seconds))) {
const remainingSeconds = seconds % 60; const remainingSeconds = seconds % 60;
const minutes = (Math.floor(seconds - remainingSeconds) / 60) % 60; const minutes = (Math.floor(seconds - remainingSeconds) / 60) % 60;
const hours = Math.floor(seconds / 3600) % 24; const hours = Math.floor(seconds / 3600) % 24;

View File

@@ -17,10 +17,10 @@
*/ */
export function sortNumEngZhtw(data) { export function sortNumEngZhtw(data) {
return data.sort((a, b) => { return data.sort((a, b) => {
const isANumber = !isNaN(parseFloat(a)) && isFinite(a); const isANumber = !Number.isNaN(Number.parseFloat(a)) && Number.isFinite(Number(a));
const isBNumber = !isNaN(parseFloat(b)) && isFinite(b); const isBNumber = !Number.isNaN(Number.parseFloat(b)) && Number.isFinite(Number(b));
if (isANumber && isBNumber) return parseFloat(a) - parseFloat(b); if (isANumber && isBNumber) return Number.parseFloat(a) - Number.parseFloat(b);
if (isANumber) return -1; if (isANumber) return -1;
if (isBNumber) return 1; if (isBNumber) return 1;
@@ -40,10 +40,10 @@ export function sortNumEngZhtw(data) {
* @returns {number} Negative if a < b, positive if a > b, zero if equal. * @returns {number} Negative if a < b, positive if a > b, zero if equal.
*/ */
export function sortNumEngZhtwForFilter(a, b) { export function sortNumEngZhtwForFilter(a, b) {
const isANumber = !isNaN(parseFloat(a)) && isFinite(a); const isANumber = !Number.isNaN(Number.parseFloat(a)) && Number.isFinite(Number(a));
const isBNumber = !isNaN(parseFloat(b)) && isFinite(b); const isBNumber = !Number.isNaN(Number.parseFloat(b)) && Number.isFinite(Number(b));
if (isANumber && isBNumber) return parseFloat(a) - parseFloat(b); if (isANumber && isBNumber) return Number.parseFloat(a) - Number.parseFloat(b);
if (isANumber) return -1; if (isANumber) return -1;
if (isBNumber) return 1; if (isBNumber) return 1;