1.0.5 • Published 2 years ago

lil-stopwatch v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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 });
namedescription
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}
displaystring - '00:00:00'
isRunningbool - specifies if the stopwatch is currently running
isPausedbool - specifies if the stopwatch is paused or stopped
totalMillisecondsfloat - total elapsed milliseconds
totalSecondsfloat - total elapsed seconds
totalMinutesfloat - total elapsed minutes
totalHoursfloat - total elapsed hours
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago