📚 Improved documentation and logs structure for better maintainability and troubleshooting. 🖥️🔍

This commit is contained in:
2025-06-01 04:46:49 +02:00
parent f0fe4c29d5
commit 3501bbfddf
30 changed files with 721 additions and 167 deletions

View File

@ -485,16 +485,25 @@ function updateStatsCounter(elementId, value, animate = true) {
return;
}
// Sichere Wert-Validierung hinzufügen
if (value === null || value === undefined) {
console.warn(`Ungültiger Wert für Element '${elementId}':`, value);
value = 0; // Fallback-Wert
}
if (animate) {
// Animierte Zählung
const currentValue = parseInt(element.textContent.replace(/[^\d]/g, '')) || 0;
const targetValue = parseInt(value.toString().replace(/[^\d]/g, '')) || 0;
if (currentValue !== targetValue) {
animateCounter(element, currentValue, targetValue, value.toString());
// Sichere String-Konvertierung
const finalTextValue = value !== null && value !== undefined ? value.toString() : '0';
animateCounter(element, currentValue, targetValue, finalTextValue);
}
} else {
element.textContent = value;
// Sichere Zuweisung ohne Animation
element.textContent = value !== null && value !== undefined ? value.toString() : '0';
}
}
@ -502,6 +511,26 @@ function updateStatsCounter(elementId, value, animate = true) {
* Animierte Counter-Funktion
*/
function animateCounter(element, start, end, finalText) {
// Sichere Parameter-Validierung
if (!element) {
console.warn('animateCounter: Kein gültiges Element übergeben');
return;
}
// Sichere finalText-Validierung mit optimiertem Logging
if (typeof finalText !== 'string') {
// Nur bei problematischen Werten warnen (null, undefined, objects)
if (finalText === null || finalText === undefined || (typeof finalText === 'object' && finalText !== null)) {
console.warn('animateCounter: Problematischer finalText-Wert:', finalText);
}
// Normale Numbers stille konvertieren
finalText = finalText !== null && finalText !== undefined ? String(finalText) : '0';
}
// Sichere start/end-Validierung
start = parseInt(start) || 0;
end = parseInt(end) || 0;
const duration = 1000; // 1 Sekunde
const startTime = performance.now();
@ -513,16 +542,28 @@ function animateCounter(element, start, end, finalText) {
const easeOut = 1 - Math.pow(1 - progress, 3);
const currentValue = Math.round(start + (end - start) * easeOut);
if (finalText.includes('%')) {
element.textContent = currentValue + '%';
} else {
// Sichere includes-Prüfung
try {
if (typeof finalText === 'string' && finalText.includes('%')) {
element.textContent = currentValue + '%';
} else {
element.textContent = currentValue;
}
} catch (error) {
console.warn('animateCounter: Fehler bei finalText.includes:', error, 'finalText:', finalText);
element.textContent = currentValue;
}
if (progress < 1) {
requestAnimationFrame(updateCounter);
} else {
element.textContent = finalText;
// Sichere Zuweisung des finalen Wertes
try {
element.textContent = finalText;
} catch (error) {
console.warn('animateCounter: Fehler bei finaler Zuweisung:', error);
element.textContent = String(end);
}
}
}