notatimer

0.3.0 • Public • Published

notatimer

notatimer is "not a timer." It is, in fact, a stopwatch, though it doesn't stop some people (see: speedrunners) from calling it a timer.

Install

npm i notatimer

Requiring/Importing

// CommonJS
const Stopwatch = require('notatimer');

// ESM
import Stopwatch from 'notawatch';

It is a default export, so it can be named whatever you want.

Creating an Instance

const stopwatch = new Stopwatch()

Optionally, an object can be passed into the constructor, with three possible properties.

const stopwatch = new Stopwatch({
    initial: 0, // must be a number
    delay: 0, // must be a nonnegative number
    callback: null // must be a function with one parameter -- details below
})

The callback function is passed an object containing a time property and times property.

These three properties can be updated after construction using stopwatch.set(object).

Usage

Properties

stopwatch.time

Current time in milliseconds (accurate to 5 microseconds).

stopwatch.times

Current time as an array in the format [hours, minutes, seconds, milliseconds].

stopwatch.started

If the stopwatch has started (true/false).

stopwatch.running

If the stopwatch is currently running (true/false).

stopwatch.finished

If the stopwatch has finished (true/false).

stopwatch.initial

The initial time for the stopwatch (use the constructor or stopwatch.set() to set).

stopwatch.delay

The initial delay for the stopwatch (use the constructor or stopwatch.set() to set).

stopwatch.laps

Array of objects, each with a time property and times property.

stopwatch.callback

Function that is called every step or when setting a property. Use this function to update where the time is displayed.

Methods

stopwatch.start()

Start the timer. Returns void.

stopwatch.pause()

Pause the timer. Returns void.

stopwatch.stop()

Stops the timer. Returns an object with a time property and times property.

stopwatch.reset()

Stops and resets the timer to the initial value. Returns void.

stopwatch.lap()

Adds an object with a time property and times property to thestopwatch.laps array. Returns the aforementioned object.

stopwatch.set(object)

Sets the initial property, delay property, and/or callback function. Returns void.

Readme

Keywords

Package Sidebar

Install

npm i notatimer

Weekly Downloads

0

Version

0.3.0

License

GPL-3.0-or-later

Unpacked Size

42.3 kB

Total Files

6

Last publish

Collaborators

  • slashinfty