npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

time-loop

v2.0.3

Published

Javascript time-based events handler

Downloads

36

Readme

time-loop.js

This library helps you easily manage time-based timers with requestAnimationFrame.

How to use

Creating timeouts and intervals is really simple :

var timeLoop = new require('time-loop')();

timeLoop.createTimer(function() {
  // Code here will be executed after one second
}, {
  type: 'timeout',
  time: 1000
});

timeLoop.createTimer(function() {
  // Code here will be executed every half-second
}, {
  type: 'interval',
  time: 500
});

timeLoop.start(); // Starts

API

Timer options

These options can be passed to the timeLoop.createTimer method, or changed on the objet directly.

type {string}

Values timeout or interval. Defaults to timeout.

time {int}

Time in ms before a timeout is executed, or interval between calls (depends on the type option). If value equals 0, the timeout timer is called on the next frame, and the interval timer is called every frame.

priority {int}

Determines the order of calls when multiple callbacks are to be executed at the same frame. Higher numbers are executed prior to lower numbers. Defaults to 1.

namespace {string}

Namespaces help theming your timers and execute actions on multiple timers at once. A dot-separated syntax is recommended, ex: home.scrolling, and home.scrolling.menu.

Note : a default namespace all is applied by default to all timers, the namespace given by this option is appended to this default namespace.

Timer methods

.options(options)

Call this method on an instanced Timer to reset to its default parameters and pass it new options (use it to overwrite an timer by a new one).

.pause()

The timer won't be called until you resume it

.resume()

The timer is resumed

.reset()

Resets the internal elapsed time to 0

.end()

End an timer : it won't be called anymore, and is cached to be rewritten by a new one.

TimeLoop Parameters

autoSort {bool}

By default, when creating new timers, they are automatically sorted by priority. By setting this parameter to false, timers will not be sorted automatically and if you need to do it, you'll have to call the .sort() method yourself.

defaultNamespace {string}

A default namespace prepended to all timers' namespaces. Defaults to all.

TimeLoop Methods

By default, every method returns the instance of TimeLoop for chaining

.start()

Starts the time-loop, timers will be fired when the loop is running.

.pause()

Pauses the time-loop, when calling start() again the timer will resume from where it was (so no "running after time").

Note : the time-loop automatically pauses and resumes when switching tabs on compatible browsers.

.resume()

Alias of start()

.createTimer(callback, [options], [context])

Creates and returns a new Timer with given options (see section above for available options). By default, if no context is passed, the context will be the window object.

.wait(time=0)

Shortcut for creating timeouts, returns a A+ Promise.

.repeat(callback, time=0)

Shortcut for creating intervals, returns the created Timer.

.createPool(nb)

Creates a pool of inactive Timer. This is useful for performances when you need to create a lot of timers during runtime : this will pre-allocate nb Timer that will get overriden and activated when you call the createTimer() method.

.sort()

Sorts the existing timers by priority.

Note : by default, this is automatically called when needed, so you shouldn't bother with it unless you de-activated auto-sort and want to handle the sorting yourself

.namespace(namespace, [action])

Returns the timers that match the given namespace. If a valid action name is passed, following methods will be executed on all matching timers :

  • "pause" : matching timers will be paused
  • "resume" : matching timers will be resumed
  • "reset" : matching timers will be reset
  • "end" : matching timers will be de-activated

Less precise requested namespace will fetch a larger number of timers, ex :

timeLoop.createTimer(function() { [...] }, { namespace: 'home.banner' });

timeLoop.createTimer(function() { [...] }, { namespace: 'home.scrolling' });

timeLoop.namespace('all.home', 'pause'); // returns both timers and pauses them
timeLoop.namespace('all.home.scrolling', 'resume'); // returns only one timer and resume it