1.1.1 • Published 3 months ago

lapwatch v1.1.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
3 months ago

lapwatch

Stopwatch written in TypeScript

All times are saved as DOMHighResTimeStamps, which are milliseconds accurate to 5 microseconds.

Installation

npm i lapwatch

Importing

// 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 true as a parameter calls the lapwatch.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.laps array
  • 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.

1.1.1

3 months ago

1.1.0

3 months ago

1.0.0

7 months ago