Socket
Socket
Sign inDemoInstall

tick-tock

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tick-tock - npm Package Compare versions

Comparing version 0.1.6 to 1.0.0

73

index.js

@@ -12,6 +12,9 @@ 'use strict';

* @param {Function} clear Clears the timer instance.
* @param {Function} duration Duration of the timer.
* @param {Function} fn The functions that need to be executed.
* @api private
*/
function Timer(timer, clear, fn) {
function Timer(timer, clear, duration, fn) {
this.start = +(new Date());
this.duration = duration;
this.clear = clear;

@@ -23,2 +26,22 @@ this.timer = timer;

/**
* Calculate the time left for a given timer.
*
* @returns {Number} Time in milliseconds.
* @api public
*/
Timer.prototype.remaining = function remaining() {
return this.duration - this.taken();
};
/**
* Calculate the amount of time it has taken since we've set the timer.
*
* @returns {Number}
* @api public
*/
Timer.prototype.taken = function taken() {
return +(new Date()) - this.start;
};
/**
* Custom wrappers for the various of clear{whatever} functions. We cannot

@@ -71,2 +94,3 @@ * invoke them directly as this will cause thrown errors in Google Chrome with

if (clear) tock.clear(name);
else tock.start = +new Date();

@@ -89,3 +113,4 @@ for (; i < l; i++) {

Tick.prototype.setTimeout = function timeout(name, fn, time) {
var tick = this;
var tick = this
, tock;

@@ -97,5 +122,7 @@ if (tick.timers[name]) {

tock = ms(time);
tick.timers[name] = new Timer(
setTimeout(tick.tock(name, true), ms(time)),
unsetTimeout,
tock,
fn

@@ -117,3 +144,4 @@ );

Tick.prototype.setInterval = function interval(name, fn, time) {
var tick = this;
var tick = this
, tock;

@@ -125,5 +153,7 @@ if (tick.timers[name]) {

tock = ms(time);
tick.timers[name] = new Timer(
setInterval(tick.tock(name), ms(time)),
unsetInterval,
tock,
fn

@@ -156,2 +186,3 @@ );

unsetImmediate,
0,
fn

@@ -211,17 +242,2 @@ );

/**
* We will no longer use this module, prepare your self for global cleanups.
*
* @returns {Boolean}
* @api public
*/
Tick.prototype.end = Tick.prototype.destroy = function end() {
if (!this.context) return false;
this.clear();
this.context = this.timers = null;
return true;
};
/**
* Adjust a timeout or interval to a new duration.

@@ -235,2 +251,3 @@ *

, tick = this
, tock = ms(time)
, timer = tick.timers[name];

@@ -242,3 +259,5 @@

timer.clear(timer.timer);
timer.timer = (interval ? setInterval : setTimeout)(tick.tock(name, !interval), ms(time));
timer.start = +(new Date());
timer.duration = tock;
timer.timer = (interval ? setInterval : setTimeout)(tick.tock(name, !interval), tock);

@@ -248,5 +267,21 @@ return tick;

/**
* We will no longer use this module, prepare your self for global cleanups.
*
* @returns {Boolean}
* @api public
*/
Tick.prototype.end = Tick.prototype.destroy = function end() {
if (!this.context) return false;
this.clear();
this.context = this.timers = null;
return true;
};
//
// Expose the timer factory.
//
Tick.Timer = Timer;
module.exports = Tick;
{
"name": "tick-tock",
"version": "0.1.6",
"version": "1.0.0",
"description": "Timer management, never forget to clear timers again",

@@ -36,3 +36,3 @@ "main": "index.js",

"mocha": "2.2.x",
"pre-commit": "1.0.x"
"pre-commit": "1.1.x"
},

@@ -39,0 +39,0 @@ "dependencies": {

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