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

@axiostudio/xtimer

v1.0.0

Published

An universal timer class for Javascript projects

Downloads

70

Readme

xTimer

xTimer is a JavaScript class that implements a simple timer with functionalities for starting, stopping, adding time, displaying elapsed time, and resetting. This class is useful for tracking time in various scenarios such as stopwatches, timers, or time management in applications.

The xTimer class offers a simple and flexible way to manage a timer in JavaScript applications. It can be extended and modified to suit various use cases as needed.

Features

The xTimer class provides the following methods:

start(start_at)

Starts the timer. If a date (start_at) is provided, the timer will start from that specific time. Otherwise, the timer starts from the current time.

  • Parameters:
    • start_at (optional): An optional date from which to start the timer. If omitted, the current date is used.
  • Behavior:
    • If the timer is not already running, it starts counting seconds.
    • Logs the start action in the history.

stop()

Stops the timer and accumulates the elapsed seconds into the offset.

  • Behavior:
    • Stops the counting interval.
    • Updates the offset with the elapsed seconds.
    • Resets the current seconds to 0.
    • Logs the stop action in the history.

add(seconds)

Adds a specified number of seconds to the current offset.

  • Parameters:
    • seconds: Number of seconds to add to the timer.
  • Behavior:
    • Updates the offset with the specified number of seconds.
    • Logs the add action in the history.

elapsed()

Returns the total elapsed time in seconds.

  • Behavior:
    • Returns the sum of the offset and the current seconds.

display()

Returns the total elapsed time in HH:MM:SS format.

  • Behavior:
    • Calculates the total elapsed time.
    • Converts the time into a string in HH:MM:SS format.

reset()

Resets the timer by clearing the offset and the seconds.

  • Behavior:
    • Stops the counting interval if active.
    • Resets the offset and seconds to 0.
    • Sets the timer state to not running.
    • Logs the reset action in the history.

Usage Example

import { xTimer } from './xtimer.js';

const timer = new xTimer();
timer.start();
// ... after a few seconds
console.log(timer.display()); // Shows the elapsed time
timer.add(120); // Adds 120 seconds (2 minutes)
console.log(timer.display()); // Shows the updated time
timer.stop(); // Stops the timer
timer.reset(); // Resets the timer

Action History

Every method that modifies the timer state logs the action in the history property, which tracks all operations performed on the timer.