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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@clovergaze/simple-timer

v1.1.0

Published

A simple Node module that implements a timer with logging.

Downloads

18

Readme

Simple Timer

A simple Node module that implements a timer with logging.

Install

npm install @clovergaze/simple-timer

Usage

import { SimpleTimer } from "@clovergaze/simple-timer";
import { SimpleLogger } from "@clovergaze/simple-logger";

const simpleTimer: SimpleTimer = new SimpleTimer();

// Runs timer for 30 seconds with console output when the
// timer is started, has finished or if an error occurred.
simpleTimer
    .on("start", () => {
        console.log("Timer started..");
    })
    .on("finish", () => {
        console.log("Timer finished..");

        // Retrieve log messages
        simpleTimer.getLog().forEach((entry: SimpleLogger.Entry): void => {
            console.log(`${entry.date} - ${entry.message}`);
        });
    })
    .on("error", (error) => {
        console.log(`${error.message} (name=${error.name})`);
    })
    .start(30);

Output on the console is:

Timer started..
Timer has finished..
Sun Apr 11 2021 21:58:18 GMT+0200 (Central European Summer Time) - CREATION
Sun Apr 11 2021 21:58:18 GMT+0200 (Central European Summer Time) - START
Sun Apr 11 2021 21:58:48 GMT+0200 (Central European Summer Time) - FINISH

Methods

public start(seconds: number): void

Runs timer for specified number of seconds. Internally the timer uses a resolution of 100 ms.

public pause(): void

Pauses the timer. Calling this method when the timer is paused resumes the timer.

public stop(): void

Immediately stops running the timer.

public getCurrentState(): SimpleTimer.State

Returns the current state of the timer. The state can be RUNNING, PAUSED or STOPPED.

public getLog(): SimpleLogger.Entry[]

Returns a list of log entries.

public clearLog(): void

Removes all entries from the log.

Events

Use on to listen for these events.

creation

Emitted once when the timer is created.

start

Emitted once when the timer is started.

pause

Emitted when the timer gets paused.

resume

Emitted when the timer resumes running after being paused.

stop

Emitted once when the timer has been explicitly stopped.

tick

Emitted every second the timer is running.

finish

Emitted once when the specified time is up.

error

Emitted if an error occurred.

This event also emits an argument of type Error that contains the name of the error and the error message. The error's name property can be TIMER_START_ERROR, TIMER_PAUSE_ERROR or TIMER_STOP_ERROR.

Development

For most development steps, like continuous build mode, test coverage report generation and releasing, everything must be built first. Running tests is an exception, here the TypeScript files are used directly.

Building

npm run build

This executes the Grunt build:dev task (via the default task) which lints and transpiles the source files.

To build the production version run:

npm run build:prod

This omits source map file generation. Generating them leave comments in the generated JavaScript files that are not needed in the production code.

Continuous build mode

npm run watch

Testing

npm test

This executes test cases inside the test folder which use Mocha.

It is not required to build the sources first when running this step, because ts-node is used to immediately execute the TypeScript files.

Coverage

npm run coverage

This executes istanbul to assess the test coverage and remap-istanbul to generate reports for the TypeScript sources.

Releasing

npm run release

This runs a production build and copies the relevant files to the dist folder.

Cleaning

npm run clean

This removes all generated files and folders but does not touch the dist folder or files it contains.

Bugs & Issues

Something is not working as intended? Please report bugs or issues on the corresponding GitHub page.

Author

Johannes Hillert (GitHub)

License

Copyright (c) 2017 Johannes Hillert. Licensed under the MIT license, see the included LICENSE file for details.