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 🙏

© 2024 – Pkg Stats / Ryan Hefner

horologe

v2.3.2

Published

An interval timer

Downloads

8

Readme

horologe

Install

npm install --save horologe

horologe is now at version 2. There have been changes. Check this documentation to see what is different from version 1.

Usage

var Timer = require('horologe');
var count = 0;
var timer = Timer.create(1000, {sync: true});
timer.on('tick', function(time, passed){
    var d = new Date(time);
    console.log((++count) + ' ' + d.getHours()+':'+d.getMinutes()+':'+d.getSeconds() + ' ' + passed);
});
timer.start(20);

or create, and setup all at once.

var count = 0, timer = Timer.create(1000, {sync: true}).on('tick', onTick).start(5);

function onTick(time, passed){
    var d = new Date(time);
    console.log((++count)+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds() + ' ' + passed);
}

Timer creation

new Timer(interval, options)

interval is the time between ticks.

options is an optional object argument.

There are two ways to create a timer.

let timer1 = Timer.create(1000, {});
let timer2 = new Timer(1000, {});

options

options.sync = 1000

What should the timer be synchronized to? Using milliseconds you can adjust the timer synchronization to system time. Using a falsy value will set no synchronization.

options.tick = null

Set a tick function. This is the same as timer.on('tick', ()=>{})

options.highres = false

options.highres is an experimental option. Setting it will make the timer use performance.now() instead of Date.now() for timing.

options.name

Set the name property of the timer.

Properties

timer.interval

The interval set in the constructor.

timer.paused

Is the timer paused?

timer.running

Is the timer running?

timer.count

How many ticks of the timer have been done?

timer.percent

What's the percentage of time complete until the timer is stopped by it's range? If the range is infinite timer.percent returns zero.

timer.name

The name set in the options.

timer.startTime

Get the time that the timer started. timer.startTime returns null if the timer is not running.

Methods

timer.start(wait)

Start the timer at the current time.

The wait parameter is optional. Specify an integer duration for the first tick to wait. If wait isn't set then the most optimal period before the first tick is chosen using rounding to the nearest interval in the past, or future.

If the timer has already started, and hasn't been paused timer.start() does nothing.

timer.range(amount)

timer.range(amount) sets the time range, or when the timer ends. The default is Infinity.

timer.stop()

Stop the timer. timer.stop() resets the timer entirely to a non-running, and non-paused state.

timer.pause(limit)

Pause the timer.

limit has a default of Infinity.

limit controls how long the timer will be paused.

on(name, callback)

Set a listener on an event.

off(name, callback)

Remove a listener.

dispose()

Destroy the timer.

Events

tick

Emitted at every interval of the timer.

The arguments to the listener are time, and passed.

timer.on('tick', function(time, passed){

});

time is the current system time.

passed is how much time has passed since the timer was started.

start

Emitted when the timer is started.

startTime is the only argument for the start listener.

timer.on('start', function(startTime){

});

stop

Emitted when the timer is stopped. No arguments are passed to the listener.

pause

Emitted when the timer is paused. No arguments are passed to the listener.

complete

Emitted when the timer ends, and only if an amount is passed to the range method.

timer.on('complete', (time, passed)=>{

});

About

The horologe timer is very close to the millisecond precision. At worst it will be off by a 100th of a second. In my tests it remained in the 2 millisecond range of precision for most iterations of the interval. horologe doesn't use precision.now so keep that in mind.