Comparing version 0.0.0 to 0.0.1
14
index.js
@@ -94,2 +94,13 @@ 'use strict'; | ||
/** | ||
* Check if we have a timer set. | ||
* | ||
* @param {String} name | ||
* @returns {Boolean} | ||
* @api public | ||
*/ | ||
Tick.prototype.active = function active(name) { | ||
return name in this.timers; | ||
}; | ||
/** | ||
* Properly clean up all timeout references. If no arguments are supplied we | ||
@@ -144,3 +155,4 @@ * will attempt to clear every single timer that is present. | ||
amount = parseFloat(match[1]); | ||
switch ((match[2] || 'ms').toLowerCase()) { | ||
switch (match[2].toLowerCase()) { | ||
case 'days': | ||
@@ -147,0 +159,0 @@ case 'day': |
{ | ||
"name": "tick-tock", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Timer management", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha --reporter spec --ui bdd test.js" | ||
"test": "mocha --reporter spec --ui bdd test.js", | ||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter spec --ui bdd test.js" | ||
}, | ||
@@ -26,2 +27,3 @@ "keywords": [ | ||
"assume": "0.0.x", | ||
"istanbul": "0.3.x", | ||
"mocha": "1.21.x", | ||
@@ -28,0 +30,0 @@ "pre-commit": "0.0.x" |
@@ -64,4 +64,14 @@ # tick-tock | ||
### Tock.active() | ||
Check if there's an active timer for the given name and returns a boolean. | ||
```js | ||
tock.active('foo'); // true; | ||
tock.clear(); | ||
tock.active('foo'); // false; | ||
``` | ||
## License | ||
MIT |
95
test.js
@@ -22,2 +22,8 @@ describe('ticktock', function () { | ||
it('can be constructed without new', function () { | ||
var tick = Tick(); | ||
assume(tick).is.instanceOf(Tick); | ||
}); | ||
describe('.parse', function () { | ||
@@ -28,4 +34,12 @@ it('should preserve ms', function () { | ||
it('can parse numbers', function () { | ||
assume(Tick.parse(100)).to.equal(100); | ||
}); | ||
it('should convert from m to ms', function () { | ||
assume(Tick.parse('1m')).to.equal(60000); | ||
assume(Tick.parse('1min')).to.equal(60000); | ||
assume(Tick.parse('1mins')).to.equal(60000); | ||
assume(Tick.parse('1minute')).to.equal(60000); | ||
assume(Tick.parse('1minutes')).to.equal(60000); | ||
}); | ||
@@ -35,2 +49,6 @@ | ||
assume(Tick.parse('1h')).to.equal(3600000); | ||
assume(Tick.parse('1hr')).to.equal(3600000); | ||
assume(Tick.parse('1hrs')).to.equal(3600000); | ||
assume(Tick.parse('1hour')).to.equal(3600000); | ||
assume(Tick.parse('1hours')).to.equal(3600000); | ||
}); | ||
@@ -40,2 +58,4 @@ | ||
assume(Tick.parse('2d')).to.equal(172800000); | ||
assume(Tick.parse('2day')).to.equal(172800000); | ||
assume(Tick.parse('2days')).to.equal(172800000); | ||
}); | ||
@@ -45,2 +65,6 @@ | ||
assume(Tick.parse('1s')).to.equal(1000); | ||
assume(Tick.parse('1sec')).to.equal(1000); | ||
assume(Tick.parse('1secs')).to.equal(1000); | ||
assume(Tick.parse('1second')).to.equal(1000); | ||
assume(Tick.parse('1seconds')).to.equal(1000); | ||
}); | ||
@@ -73,2 +97,61 @@ | ||
describe('#setInterval', function () { | ||
it('adds a setInterval', function (next) { | ||
var start = Date.now() | ||
, i = 0; | ||
tock.setInterval('test', function () { | ||
var taken = Date.now() - start; | ||
if (i === 0) { | ||
assume(taken).is.above(5); | ||
assume(taken).is.below(15); | ||
} else { | ||
next(); | ||
} | ||
i++; | ||
}, 10); | ||
}); | ||
it('accepts strings for time', function (next) { | ||
var start = Date.now() | ||
, i = 0; | ||
tock.setInterval('test', function () { | ||
var taken = Date.now() - start; | ||
if (i === 0) { | ||
assume(taken).is.above(5); | ||
assume(taken).is.below(15); | ||
} else { | ||
next(); | ||
} | ||
i++; | ||
}, '10 ms'); | ||
}); | ||
it('run with the same timeout if a known name is provided', function (next) { | ||
var start = Date.now() | ||
, j = 0 | ||
, i = 0; | ||
tock.setInterval('test', function () { | ||
j++; | ||
}, '100 ms'); | ||
setTimeout(function () { | ||
tock.setInterval('test', function () { | ||
i++; | ||
if (i === 10) { | ||
assume(j).equals(i); | ||
next(); | ||
} | ||
}, '100 ms'); | ||
}, 20); | ||
}); | ||
}); | ||
describe('#setTimeout', function () { | ||
@@ -168,2 +251,14 @@ it('adds a setTimeout', function (next) { | ||
}); | ||
describe('#active', function () { | ||
it('returns true if a timer is defined', function () { | ||
assume(tock.active('foo')).is.false(); | ||
tock.setTimeout('foo', function () {}); | ||
assume(tock.active('foo')).is.true(); | ||
tock.clear(); | ||
assume(tock.active('foo')).is.false(); | ||
}); | ||
}); | ||
}); |
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
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
12965
358
77
4