Add Word Wrangler demos

This commit is contained in:
Mark Backman
2025-04-24 14:29:19 -04:00
parent 09ff836ef6
commit c80d09f66c
54 changed files with 12209 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
/**
* Safely clears any type of timer
* @param timer The timer to clear
* @returns null to reassign to the timer reference
*/
export function clearTimer(timer: NodeJS.Timeout | null): null {
if (timer) {
clearTimeout(timer);
}
return null;
}
/**
* Creates a countdown timer that calls the callback every second
* @returns A function to stop the timer
*/
export function createCountdownTimer(
durationSeconds: number,
onTick: (secondsLeft: number) => void,
onComplete: () => void
): () => void {
let secondsLeft = durationSeconds;
const timer = setInterval(() => {
secondsLeft--;
onTick(secondsLeft);
if (secondsLeft <= 0) {
clearInterval(timer);
onComplete();
}
}, 1000);
return () => {
clearInterval(timer);
};
}