lil-stopwatch
v1.0.5
Published
A timestamp based stopwatch library
Maintainers
Readme
lil-stopwatch
A lightweight lil stopwatch ⏱
Zero-dependency stopwatch using timestamps. This does not implement intervals or "ticking", the utility simply provides the elapsed time when you need it. The rest is up to you.
Docs ↗
<div id="stopwatch">00:00:00</div>import Stopwatch from 'lil-stopwatch';
const stopwatch = new Stopwatch();
const container = document.getElementById('stopwatch');
container.onclick = () => stopwatch.toggle();
setInterval(() => {
container.innerText = stopwatch.display;
}, 50);API
const stopwatch = new Stopwatch({ ...options });name | description
--- | ---
constructor options | {startImmediately: boolean (default false),displayHours: boolean (default false),displaySeparator: string (default ':')displayMsPrecision: 1-3 (default 2)}
play() | start the timer
stop() | stop/pause the timer
toggle() | toggle between stop and play
reset() | clear the current state and stop the timer
state | {hours, minutes, seconds, milliseconds}
display | string - '00:00:00'
isRunning | bool - specifies if the stopwatch is currently running
isPaused | bool - specifies if the stopwatch is paused or stopped
totalMilliseconds | float - total elapsed milliseconds
totalSeconds | float - total elapsed seconds
totalMinutes | float - total elapsed minutes
totalHours | float - total elapsed hours
