Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timer-stopwatch-dev

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timer-stopwatch-dev

A stopwatch and countdown timer for node, maintained.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

timer-stopwatch

dependencies Status devDependencies Status

A stopwatch and countdown clock module for node.js, maintained.

Install

npm install timer-stopwatch

How to

The Gist

new Stopwatch([countDownMS], [options]);

Basic timers

var Stopwatch = require("timer-stopwatch");

var timer = new Stopwatch(60000); // A new countdown timer with 60 seconds
var stopwatch = new Stopwatch(); // A new count up stopwatch. Starts at 0.

Event Methods

// Fires every 50ms by default. Change setting the 'refreshRateMS' options
timer.onTime(function(time) {
	console.log(time.ms); // number of milliseconds past (or remaining);
	console.log(time.seconds); // number of seconds past (or remaining);
});

// Fires when the timer is done
timer.onDone(function() {
	console.log("Timer is complete");
});

// Fires when the timer is almost complete - default is 10 seconds remaining. Change with 'almostDoneMS' option
timer.onAlmostDone(function() {
	console.log("Timer is almost complete");
});

//These methods are chainable
timer
	.onTime(cb)
	.onAlmostDone(cb)
	.onDone(cb);

Timer Methods

timer.start();
timer.stop();
timer.startstop(); // Toggles the running state
timer.reset(countDownMS); // optional countDownMS to reset countdown to that many milliseconds
timer.getState() // Return 0, 1 or 2 if the timer is respectively stopped, running or complete
timer.isStopped()
timer.isRunning()
timer.isComplete()

Properties

timer.ms; // Number of milliseconds on the clock
timer.seconds; // Number of seconds on the clock

Options

var options = {
	refreshRateMS: 10, // How often the clock should be updated
	almostDoneMS: 10000 // When counting down - this event will fire with this many milliseconds remaining on the clock
};

var timer = new Stopwatch(60000, options);

Testing

Unit and Integration tests (requires dev dependencies)

npm test

Thanks to

@MickCrozier - The maintainer of the original package.

Other contributors:

  • @danhere
  • @connorjburton
  • @RafaelKaczmarczyk
  • @nitzo

License

MIT License

Keywords

FAQs

Package last updated on 19 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc