sussy-util
Version:
Util package made by me
52 lines (51 loc) • 1.55 kB
TypeScript
import { EventEmitter } from 'node:events';
import Optional from './Optional';
export default class StopWatch extends EventEmitter {
private readonly rounds;
private totalTimePaused;
private pauseStartTime?;
private threshold?;
private startTime;
constructor();
/**
* Fixes the elapsed time when the stopwatch is paused.
*/
private fixPausedTime;
/**
* Records a round by calculating the lap time and emitting a 'round' event.
*/
round(): void;
/**
* Resets the stopwatch to its initial state and emits a 'reset' event.
*/
reset(): void;
/**
* Returns the elapsed time in milliseconds.
* @returns The elapsed time in milliseconds.
*/
time(): number;
/**
* Returns the recorded rounds.
* @returns An array of lap times for each round.
*/
getRounds(): number[];
/**
* Pauses the stopwatch and emits a 'pause' event.
*/
pause(): void;
/**
* Resumes the stopwatch if paused and emits a 'resume' event.
*/
resume(): void;
formatLapTime(lapTime: number): string;
getAverageLapTime(): number;
getMaximumLapTime(): number;
getMinimumLapTime(): number;
setLapTimeThreshold(threshold: number): void;
getLapTimeAtIndex(index: number): Optional<number>;
/**
* Adds an event listener for the 'round' event.
* @param callback - The callback function to be called when a 'round' event is emitted.
*/
onRound(callback: (lapTime: number) => void): void;
}