1.1.1 • Published 2 years ago
lapwatch v1.1.1
lapwatch
Stopwatch written in TypeScript
All times are saved as DOMHighResTimeStamps, which are milliseconds accurate to 5 microseconds.
Installation
npm i lapwatchImporting
// Node.js
import Lapwatch from 'lapwatch';
// Browser
import Lapwatch from 'https://unpkg.com/lapwatch';Note: it is a default export, so you can freely name the import
Constructing
Simple:
const lapwatch = new Lapwatch();Advanced:
const lapwatch = new Lapwatch({
initial: 0,
delay: 0
});Note: see below for descriptions of initial and delay
Properties
lapwatch.initial - number of milliseconds added to the timer at the start
lapwatch.delay - number of milliseconds to wait before starting the timer
lapwatch.laps - array of times saved from the lapwatch.lap() method
Methods
lapwatch.start()
- Starts the timer
- Asynchronous to allow for delay
- Throws an error if the timer is active
lapwatch.stop(lap)
- Stops the timer
- Passing
trueas a parameter calls thelapwatch.lap()method - Returns the current elapsed amount of time
- Throws an error if the timer is inactive
lapwatch.elapsed()
- Returns the current elapsed amount of time
lapwatch.lap()
- Adds the current elapsed amount of time to the
lapwatch.lapsarray - Returns the current elapsed amount of time
- Throws an error if the timer is inactive
lapwatch.set(time)
- Sets the elapsed amount of time to a specific value
lapwatch.reset()
- Resets the timer to all initial values
Discussion
You can discuss this repository more in my Discord.