Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

accurate-timer

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accurate-timer - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

20

accurate-timer.js
(function(root){
var Timer = root.Timer = function(callback, interval){
if (window) {
var Timer = function(callback, interval){
this.raf = window.requestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.msRequestAnimationFrame;
if (this.raf) {
this.type = 'requestAnimationFrame';
this.raf = window.requestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.msRequestAnimationFrame;
} else {

@@ -20,2 +21,3 @@ this.type = 'setInterval';

Timer.prototype.start = function(){
this.stop();
var that = this;

@@ -25,5 +27,7 @@

case 'requestAnimationFrame':
console.log('using raf')
that._startRAF();
break;
case 'setInterval':
console.log('using SI')
that._startSI();

@@ -78,4 +82,2 @@ break;

})(this);
window.t = new this.Timer(function(time){console.log(time)}, 1000)
})(this);
{
"name": "accurate-timer",
"version": "0.0.3",
"version": "0.0.4",
"description": "An accurate timer using requestAnimationFrame() and performance.now(), defaulting to setInterval when needed.",

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

@@ -1,11 +0,18 @@

### An accurate, multienvironment timer
# accurate_timer uses requestAnimationFrame() and performance.now(), defaulting to setInterval if it's used in a non-browser environment.
# An accurate, multienvironment timer
##### accurate_timer uses requestAnimationFrame() and performance.now(), defaulting to setInterval if it's used in a non-browser or older environment.
## Supported environments
* Node.js (All major versions)
* Chrome*
* Firefox*
* IE*
* Must have requestAnimationFrame supported. Vendor prefixed is OK.
Based on my own (unscientific) measurements, the timer in a node.js environment tends to be accurate to about 3/1000ths of a second. In a browser environment it's a little less than 1/1000ths of a second.
Based on my own (unscientific) measurements, the timer in a node.js environment tends to be accurate to about 3/1000ths of a second. In a browser environment it's a little less than 1/1000ths of a second.
## Usage
* Create a timer object:
```js
var timer = new Timer(<callback>, <interval>);
```
* start / stop the timer:
```js
timer.start();
timer.stop();
```
All done! I hope you enjoy :blush:
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