Comparing version 0.0.1 to 0.0.2
(function() { | ||
var timer; | ||
var clear, timer; | ||
require.paths.unshift(__dirname); | ||
timer = require('../timer.js').timer; | ||
timer(200, function() { | ||
return console.log('hello'); | ||
}); | ||
timer([500, 200], function() { | ||
return console.log('hello after 500ms and 700ms'); | ||
}); | ||
clear = timer.auto(10 * 1000, function() { | ||
return console.log('BONG', +new Date); | ||
}).clear; | ||
timer(20 * 1000, clear); | ||
return; | ||
(function() { | ||
var clear, clear2; | ||
var clear2; | ||
timer(150, function() { | ||
@@ -25,3 +36,3 @@ return console.log('hello'); | ||
timer(2000, function() { | ||
var clear, ret; | ||
var ret; | ||
clear = timer([100, 150, 200, 500], function() { | ||
@@ -28,0 +39,0 @@ return console.log((Date.now() % 60000) + ': hello you'); |
{ | ||
"author": "Markus Sieber <sieber.m@gmail.com>", | ||
"name": "timer", | ||
"description": "simple utility to simplifiy and chain using setTimeout/setInterval", | ||
"version": "0.0.1", | ||
"description": "utility function to simplify using combinations of setTimeout/setInterval.", | ||
"version": "0.0.2", | ||
"repository": { | ||
@@ -7,0 +7,0 @@ "type": "git", |
(function() { | ||
var AssertSequence, assert, assertEqual, clearTimer, test4, timer, _ref; | ||
var AssertSequence, assert, assertEqual, test4, timer; | ||
var __slice = Array.prototype.slice; | ||
require.paths.unshift(__dirname); | ||
_ref = require('../timer.js'), timer = _ref.timer, clearTimer = _ref.clearTimer; | ||
if (typeof require !== "undefined" && require !== null) { | ||
require.paths.unshift(__dirname); | ||
timer = require('../timer.js').timer; | ||
} else if (typeof window !== "undefined" && window !== null) { | ||
timer = window.timer; | ||
} | ||
assertEqual = function(msg, x, y) { | ||
@@ -50,3 +54,3 @@ if (x !== y) { | ||
o = timer(10, seq('timer 10')); | ||
return clearTimer(o); | ||
return timer.clear(o); | ||
}), 210); | ||
@@ -64,5 +68,5 @@ })(); | ||
}); | ||
o = timer(null, 10, seq('10ms timer - should trigger once', 2)); | ||
o = timer.interval(10, seq('10ms timer - should trigger once', 2)); | ||
return timer(15, function() { | ||
return clearTimer(o); | ||
return timer.clear(o); | ||
}); | ||
@@ -87,3 +91,3 @@ })(); | ||
j = 1; | ||
clear = timer(void 0, 3000, function() { | ||
clear = timer.auto(3000, function() { | ||
var adj; | ||
@@ -112,5 +116,3 @@ seq('adjusted interval', ++j)(); | ||
j = 1; | ||
clear = timer({ | ||
auto: 1 | ||
}, 3000, function() { | ||
clear = timer.auto(3000, function() { | ||
var adj; | ||
@@ -117,0 +119,0 @@ seq('adjusted interval', ++j)(); |
29
timer.js
(function() { | ||
var clearTimer; | ||
exports.timer = function(timeouts, interval, cb) { | ||
var clearTimer, timer; | ||
timer = function(timeouts, interval, cb) { | ||
var entry, setup, timeouts_i, timeouts_l; | ||
@@ -9,5 +9,3 @@ if (cb === void 0) { | ||
} | ||
if ((timeouts != null ? timeouts.auto : void 0) || timeouts === void 0) { | ||
timeouts = [interval - Date.now() % interval]; | ||
} else if (typeof timeouts === 'number') { | ||
if (typeof timeouts === 'number') { | ||
timeouts = [timeouts]; | ||
@@ -35,3 +33,9 @@ } | ||
}; | ||
exports.clearTimer = clearTimer = function(entry) { | ||
timer.auto = function(interval, cb) { | ||
return timer(interval - Date.now() % interval, interval, cb); | ||
}; | ||
timer.interval = function(interval, cb) { | ||
return timer(null, interval, cb); | ||
}; | ||
timer.clear = clearTimer = function(entry) { | ||
if (entry != null ? entry.timeout : void 0) { | ||
@@ -46,2 +50,15 @@ clearTimeout(entry.timeout); | ||
}; | ||
if (typeof exports !== "undefined" && exports !== null) { | ||
exports.timer = timer; | ||
} | ||
if (typeof define === "function") { | ||
define([], function() { | ||
return { | ||
timer: timer | ||
}; | ||
}); | ||
} | ||
if (typeof window !== "undefined" && window !== null) { | ||
window.timer = timer; | ||
} | ||
}).call(this); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
15559
10
234
1
73
1