timers-ext
Advanced tools
Comparing version 0.1.2 to 0.1.3
14
delay.js
@@ -1,8 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
var callable = require('es5-ext/object/valid-callable') | ||
, nextTick = require('next-tick') | ||
, validTimeout = require('./valid-timeout') | ||
var callable = require("es5-ext/object/valid-callable") | ||
, nextTick = require("next-tick") | ||
, validTimeout = require("./valid-timeout"); | ||
, apply = Function.prototype.apply; | ||
var apply = Function.prototype.apply; | ||
@@ -18,3 +18,5 @@ module.exports = function (fn/*, timeout*/) { | ||
} | ||
return function () { return delay(apply.bind(fn, this, arguments), timeout); }; | ||
return function () { | ||
return delay(apply.bind(fn, this, arguments), timeout); | ||
}; | ||
}; |
@@ -1,3 +0,3 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = 2147483647; |
19
once.js
// It's actually "debounce" | ||
'use strict'; | ||
"use strict"; | ||
var callable = require('es5-ext/object/valid-callable') | ||
, nextTick = require('next-tick') | ||
, validTimeout = require('./valid-timeout') | ||
var isValue = require("es5-ext/object/is-value") | ||
, callable = require("es5-ext/object/valid-callable") | ||
, nextTick = require("next-tick") | ||
, validTimeout = require("./valid-timeout"); | ||
, apply = Function.prototype.apply; | ||
var apply = Function.prototype.apply; | ||
@@ -14,7 +15,7 @@ module.exports = function (fn/*, timeout*/) { | ||
callable(fn); | ||
if (timeout == null) { | ||
delay = nextTick; | ||
} else { | ||
if (isValue(timeout)) { | ||
timeout = validTimeout(timeout); | ||
delay = setTimeout; | ||
} else { | ||
delay = nextTick; | ||
} | ||
@@ -31,3 +32,3 @@ run = function () { | ||
if (scheduled) { | ||
if (handle == null) { | ||
if (!isValue(handle)) { | ||
// 'nextTick' based, no room for debounce | ||
@@ -34,0 +35,0 @@ return; |
{ | ||
"name": "timers-ext", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Timers extensions", | ||
@@ -23,12 +23,21 @@ "author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)", | ||
"devDependencies": { | ||
"tad": "~0.2.7", | ||
"xlint": "~0.2.2", | ||
"xlint-jslint-medikoo": "~0.1.4" | ||
"eslint": "^4.18.1", | ||
"eslint-config-medikoo-es5": "^1.4.7", | ||
"tad": "^0.2.7" | ||
}, | ||
"eslintConfig": { | ||
"extends": "medikoo-es5", | ||
"root": true, | ||
"globals": { | ||
"clearInterval": true, | ||
"clearTimeout": true, | ||
"setInterval": true, | ||
"setTimeout": true | ||
} | ||
}, | ||
"scripts": { | ||
"lint": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --no-cache --no-stream", | ||
"lint-console": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --watch", | ||
"lint": "eslint --ignore-path=.gitignore .", | ||
"test": "node node_modules/tad/bin/tad" | ||
}, | ||
"license": "MIT" | ||
"license": "ISC" | ||
} |
@@ -0,2 +1,8 @@ | ||
[![Build status][nix-build-image]][nix-build-url] | ||
[![Windows status][win-build-image]][win-build-url] | ||
![Transpilation status][transpilation-image] | ||
[![npm version][npm-image]][npm-url] | ||
# timers-ext | ||
## Timers extensions | ||
@@ -6,4 +12,4 @@ | ||
$ npm install timers-ext | ||
$ npm install timers-ext | ||
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/) | ||
@@ -13,3 +19,3 @@ | ||
#### MAX\_TIMEOUT _(timers-ext/max-timeout)_ | ||
#### MAX\_TIMEOUT *(timers-ext/max-timeout)* | ||
@@ -20,3 +26,3 @@ Maximum possible timeout value in milliseconds. It equals to maximum positive value for 32bit signed integer, so _2³¹ (2147483647)_, which makes it around 24.9 days | ||
Returns function which when invoked will call _fn_ function after specified | ||
Returns function which when invoked will call _fn_ function after specified | ||
_timeout_. If _timeout_ is not provided [nextTick](https://github.com/medikoo/next-tick/#next-tick) propagation is used. | ||
@@ -28,7 +34,8 @@ | ||
```javascript | ||
var nextTick = require('next-tick'); | ||
var logFoo = function () { console.log('foo'); }; | ||
var logFooOnce = require('timers-ext/once')(logFoo); | ||
var nextTick = require("next-tick"); | ||
var logFoo = function() { | ||
console.log("foo"); | ||
}; | ||
var logFooOnce = require("timers-ext/once")(logFoo); | ||
@@ -39,9 +46,7 @@ logFooOnce(); | ||
nextTick(function () { | ||
logFooOnce(); // Invokes another log (as tick passed) | ||
logFooOnce(); // ignored | ||
logFooOnce(); // ignored | ||
nextTick(function() { | ||
logFooOnce(); // Invokes another log (as tick passed) | ||
logFooOnce(); // ignored | ||
logFooOnce(); // ignored | ||
}); | ||
``` | ||
@@ -54,8 +59,17 @@ | ||
If _timeout_ resolves to a number: | ||
- for _timeout < 0_ `0` is returned | ||
- for _0 >= timeout <= [MAX_TIMEOUT](#max_timeout-timers-extmax-timeout)_, `timeout` value is returned | ||
- for _timeout > [MAX_TIMEOUT](#max_timeout-timers-extmax-timeout)_ exception is thrown | ||
### Tests [![Build Status](https://travis-ci.org/medikoo/timers-ext.png)](https://travis-ci.org/medikoo/timers-ext) | ||
* for _timeout < 0_ `0` is returned | ||
* for _0 >= timeout <= [MAX_TIMEOUT](#max_timeout-timers-extmax-timeout)_, `timeout` value is returned | ||
* for _timeout > [MAX_TIMEOUT](#max_timeout-timers-extmax-timeout)_ exception is thrown | ||
$ npm test | ||
### Tests | ||
$ npm test | ||
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo/timers-ext/branches/master/shields_badge.svg | ||
[nix-build-url]: https://semaphoreci.com/medikoo/timers-ext | ||
[win-build-image]: https://ci.appveyor.com/api/projects/status/2i5nerowov2ho3o9?svg=true | ||
[win-build-url]: https://ci.appveyor.com/project/medikoo/timers-ext | ||
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg | ||
[npm-image]: https://img.shields.io/npm/v/timers-ext.svg | ||
[npm-url]: https://www.npmjs.com/package/timers-ext |
@@ -1,10 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (t, a, d) { | ||
var data, count = 0 | ||
, x = function (a, b, c) { data = [this, a, b, c, ++count]; } | ||
, y = t(x, 200), z = {}; | ||
var data | ||
, count = 0 | ||
, x = function (a, b, c) { | ||
data = [this, a, b, c, ++count]; | ||
} | ||
, y = t(x, 200) | ||
, z = {}; | ||
a(data, undefined, "Setup"); | ||
y.call(z, 111, 'foo', false); | ||
y.call(z, 111, "foo", false); | ||
a(data, undefined, "Immediately"); | ||
@@ -14,3 +18,3 @@ setTimeout(function () { | ||
setTimeout(function () { | ||
a.deep(data, [z, 111, 'foo', false, 1], "250ms"); | ||
a.deep(data, [z, 111, "foo", false, 1], "250ms"); | ||
data = null; | ||
@@ -17,0 +21,0 @@ clearTimeout(y()); |
@@ -1,6 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (t, a, d) { | ||
var invoked, id; | ||
id = setTimeout(function () { invoked = true; }, t); | ||
id = setTimeout(function () { | ||
invoked = true; | ||
}, t); | ||
setTimeout(function () { | ||
@@ -7,0 +9,0 @@ a(invoked, undefined); |
@@ -1,5 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (t, a, d) { | ||
var called = 0, fn = t(function () { ++called; }); | ||
var called = 0, fn = t(function () { | ||
++called; | ||
}); | ||
@@ -13,3 +15,5 @@ fn(); | ||
called = 0; | ||
fn = t(function () { ++called; }, 50); | ||
fn = t(function () { | ||
++called; | ||
}, 50); | ||
fn(); | ||
@@ -16,0 +20,0 @@ fn(); |
@@ -1,5 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (t, a, d) { | ||
var called = 0, fn = t(function () { ++called; }, 50); | ||
var called = 0, fn = t(function () { | ||
++called; | ||
}, 50); | ||
@@ -6,0 +8,0 @@ fn(); |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,3 +7,5 @@ module.exports = function (t, a) { | ||
a(t(232342), 232342, "Positive"); | ||
a.throws(function () { t(1e23); }, TypeError, "Too large"); | ||
a.throws(function () { | ||
t(1e23); | ||
}, TypeError, "Too large"); | ||
}; |
@@ -1,5 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var callable = require('es5-ext/object/valid-callable') | ||
, validTimeout = require('./valid-timeout') | ||
var callable = require("es5-ext/object/valid-callable") | ||
, validTimeout = require("./valid-timeout") | ||
@@ -6,0 +6,0 @@ , apply = Function.prototype.apply; |
@@ -1,5 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var toPosInt = require('es5-ext/number/to-pos-integer') | ||
, maxTimeout = require('./max-timeout'); | ||
var toPosInt = require("es5-ext/number/to-pos-integer") | ||
, maxTimeout = require("./max-timeout"); | ||
@@ -6,0 +6,0 @@ module.exports = function (value) { |
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
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
11714
19
294
69