worker-timer
Advanced tools
Comparing version 0.1.1 to 1.0.0
16
index.js
"use strict"; | ||
if (!(global === global.window && global.URL && global.Blob && global.Worker)) { | ||
module.exports = global; | ||
} else { | ||
if (global === global.window && global.URL && global.Blob && global.Worker) { | ||
module.exports = (function() { | ||
@@ -32,3 +30,3 @@ var TIMER_WORKER_SOURCE = [ | ||
if (_callbacks[e.data]) { | ||
_callbacks[e.data](); | ||
_callbacks[e.data].callback.apply(null, _callbacks[e.data].params); | ||
} | ||
@@ -39,6 +37,8 @@ }; | ||
setInterval: function(callback, delay) { | ||
var params = Array.prototype.slice.call(arguments, 2); | ||
_timerId += 1; | ||
_timer.postMessage({ type: "setInterval", timerId: _timerId, delay: delay }); | ||
_callbacks[_timerId] = callback; | ||
_callbacks[_timerId] = { callback: callback, params: params }; | ||
@@ -48,6 +48,8 @@ return _timerId; | ||
setTimeout: function(callback, delay) { | ||
var params = Array.prototype.slice.call(arguments, 2); | ||
_timerId += 1; | ||
_timer.postMessage({ type: "setTimeout", timerId: _timerId, delay: delay }); | ||
_callbacks[_timerId] = callback; | ||
_callbacks[_timerId] = { callback: callback, params: params }; | ||
@@ -66,2 +68,4 @@ return _timerId; | ||
})(); | ||
} else { | ||
module.exports = global; | ||
} |
{ | ||
"name": "worker-timer", | ||
"description": "Stable timer API", | ||
"version": "0.1.1", | ||
"description": "Timer API that works stable in background tabs", | ||
"version": "1.0.0", | ||
"author": "mohayonao <mohayonao@gmail.com>", | ||
@@ -10,14 +10,21 @@ "bugs": { | ||
"devDependencies": { | ||
"browserify": "^8.1.1", | ||
"mocha-phantomjs": "^3.5.3", | ||
"phantomjs": "^1.9.13", | ||
"uglify-js": "^2.4.16" | ||
"karma": "^0.12.37", | ||
"karma-browserify": "^4.4.2", | ||
"karma-chrome-launcher": "^0.1.12", | ||
"karma-firefox-launcher": "^0.1.7", | ||
"karma-mocha": "^0.1.10", | ||
"mocha": "^2.3.4" | ||
}, | ||
"files": [ | ||
"package.json", | ||
"index.js", | ||
"README.md" | ||
], | ||
"homepage": "https://github.com/mohayonao/worker-timer/", | ||
"keywords": [ | ||
"timer", | ||
"clearInterval", | ||
"clearTimeout", | ||
"setInterval", | ||
"setTimeout", | ||
"clearInterval", | ||
"clearTimeout", | ||
"timer", | ||
"webworker" | ||
@@ -32,7 +39,4 @@ ], | ||
"scripts": { | ||
"build": "npm run build-browser && npm run build-minify", | ||
"build-browser": "browserify index.js --standalone WorkerTimer > build/worker-timer.js", | ||
"build-minify": "uglifyjs build/worker-timer.js > build/worker-timer.min.js", | ||
"test": "mocha-phantomjs index.html" | ||
"test": "karma start" | ||
} | ||
} |
# worker-timer | ||
[![Build Status](http://img.shields.io/travis/mohayonao/worker-timer.svg?style=flat-square)](https://travis-ci.org/mohayonao/worker-timer) | ||
[![NPM Version](http://img.shields.io/npm/v/worker-timer.svg?style=flat-square)](https://www.npmjs.org/package/worker-timer) | ||
[![Bower](https://img.shields.io/bower/v/worker-timer.svg?style=flat-square)](https://github.com/mohayonao/worker-timer) | ||
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://mohayonao.mit-license.org/) | ||
> Stable timer API | ||
> Timer API that works stable in background tabs | ||
## Installation | ||
bower: | ||
``` | ||
bower install worker-timer | ||
npm install worker-timer | ||
``` | ||
downloads: | ||
- [worker-timer.js](https://raw.githubusercontent.com/mohayonao/tickable-timer/master/build/worker-timer.js) | ||
- [worker-timer.min.js](https://raw.githubusercontent.com/mohayonao/tickable-timer/master/build/worker-timer.min.js) | ||
## API | ||
- `setInterval(callback: function, delay: number): number` | ||
- `setInterval(callback: function, delay: number, ...params: any): number` | ||
- `clearInterval(timerId: number): void` | ||
- `setTimeout(callback: function, delay: number): number` | ||
- `setTimeout(callback: function, delay: number, ...params: any): number` | ||
- `clearTimeout(timerId: number): void` | ||
## Example | ||
Same as the native Timer API | ||
```js | ||
const WorkerTimer = require("worker-timer"); | ||
let count = 0; | ||
WorkerTimer.setInterval(() => { | ||
count += 1; | ||
console.log("count: " + count); | ||
}, 1000); | ||
``` | ||
## License | ||
MIT |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
39
0
4058
6
3
57