Socket
Socket
Sign inDemoInstall

tick-tock

Package Overview
Dependencies
Maintainers
1
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.0.3 to 0.0.4

23

index.js

@@ -7,8 +7,10 @@ 'use strict';

* @constructor
* @param {Mixed} context Context of the callbacks that we execute.
* @api public
*/
function Tick() {
if (!(this instanceof Tick)) return new Tick();
function Tick(context) {
if (!(this instanceof Tick)) return new Tick(context);
this.timers = {};
this.context = context || this;
}

@@ -37,3 +39,3 @@

for (var i = 0, l = fns.length; i < l; i++) {
fns[i]();
fns[i].call(tock.context);
}

@@ -134,2 +136,17 @@ };

/**
* We will no longer use this module, prepare your self for global cleanups.
*
* @returns {Boolean}
* @api public
*/
Tick.prototype.end = 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.

@@ -136,0 +153,0 @@ *

2

package.json
{
"name": "tick-tock",
"version": "0.0.3",
"version": "0.0.4",
"description": "Timer management, never forget to clear timers again",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,2 +12,4 @@ describe('ticktock', function () {

context = { foo: 'bar' };
beforeEach(function () {

@@ -18,3 +20,3 @@ tock = new Tick();

afterEach(function () {
tock.clear();
tock.end();
});

@@ -106,2 +108,4 @@

assume(this).equals(tock);
if (i === 0) {

@@ -118,2 +122,13 @@ assume(taken).is.above(5);

it('can be called with a custom context', function (next) {
var tock = new Tick(context);
tock.setInterval('test', function () {
assume(this).deep.equals(context);
tock.clear();
next();
}, 10);
});
it('accepts strings for time', function (next) {

@@ -165,2 +180,3 @@ var start = Date.now()

var taken = Date.now() - start;
assume(this).deep.equals(tock);

@@ -174,2 +190,13 @@ assume(taken).is.above(5);

it('can be called with a custom context', function (next) {
var tock = new Tick(context);
tock.setTimeout('test', function () {
assume(this).deep.equals(context);
tock.clear();
next();
}, 10);
});
it('accepts strings for time', function (next) {

@@ -300,2 +327,13 @@ var start = Date.now();

});
describe('#end', function () {
it('returns true when its cleared the first time', function () {
assume(tock.end()).is.true();
});
it('returns false when already cleared', function () {
assume(tock.end()).is.true();
assume(tock.end()).is.false();
});
});
});

Sorry, the diff of this file is not supported yet

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