npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nlist-stopwatchjs

v1.0.0

Published

Simple stopwatch library

Downloads

2

Readme

stopWatch

A simple JavaScript library implementing a stopwatch typically used in timing middle distance fun runs/races.

Background

Note this is a simple stopwatch timer using the setInterval function, be aware of the caveats when using.

Installation

To use with the browser:

<script src="path/to/yourCopyOf/stopwatch.js"></script>

you can also import the named exports stopWatch and msToTime from stopwatch.js using ES6 module static import statement:

import { stopWatch, msToTime } from './path/to/yourCopyOf/stopwatch.js';

Usage

stopwatch.js exports the stopWatch object and the msToTime function.

msToTime is a simple function that translates ms to "hh:mm:ss:---" format.

The stopWatch objects encapsulates all the functions needed for implementing a basic stopWatch.

To configure stopWatch:

stopWatch.setConfig = {
        tickerFunction:()=>{},
        tickerInterval:250,
        distanceMarkers:[]
}
  • tickerFunction is the function you wish to be executed on every tick of the clock. Defaults to
() => {console.log("Time Elapsed ",this.getElapsedTime," ms")
  • tickerInterval is the interval in ms between function calls. Defaults to 250 ms.
  • distanceMarkers is an array containing the distance markers at which you want the pace calculated for. For example [2.5,5.0,7.5] could be used for a 10 km run with a 2.5 km lap, allowing pace feedback to runners after every lap.

stopWatch functions

stopWatch.startTimer()

Starts the timer, firing the tickerFunction after every interval, and records the starting time.

stopWatch.stopTimer()

Stops the timer and records the elapsed time, and finishing time.

stopWatch.togglePause()

Pauses the timer, and records the time when paused, so that on restart the time paused is subtracted from the start - finish time.

stopWatch.resetTimer()

Resets the stopWatch, without clearing the configuration set by stopWatch.setConfig

stopWatch.clearConfig()

Equivalent to

stopWatch.setConfig = {
    tickerFunction: null,
    tickerInterval: null,
    distanceMarkers: []
}

stopWatch.calculatePace

a getter that returns an Array containing the pace at every distancemarker based on the elapsed time.

stopWatch.getTickerTime

a getter that returns the last time setInterval executed the callback. Use JavaScript .toLocaleTimeString() to convert to localized time format.

stopWatch.getElapsedTime

a getter returning the time elapsed from the start time to the last time setInterval executed the callback.

stopWatch.recordSplit()

Pushes the last split time onto the splits Array.

stopWatch.getSplits

a getter that returns an Array of the splits.

msToTime(time)

Converts time in ms to "HH:MM:SS:sss" format