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

chronos-js

v0.5.5

Published

A JavaScript timer with simple and convenient API

Readme

chronos

A JavaScript timer with simple and convenient API

Installation

Library can be installed via Bower package manager:

bower i chronosjs

An npm package also available:

$ npm install chronos-js

Or you can clone a git repo:

git clone https://github.com/happyCoda/chronos.git

Getting started

Just as simple as is.

var chr = new Chronos();

chr.start({
  direction: 'forward',
  callback: function (chr) {
    console.log(chr.composeString());
  }
});

Usage

Chronos.js is written as an AMD module, so it's intended to use with loaders like Require.js, Almond, etc. However, library can be used directly in browser, since it exposes global wrapper – ChronosWrapper.

API

start

Library entry point. Here all the gears and sprocket starts running.

chr.start({
  duration: 10000,
  callback: function (chrInst) {
    console.log(chrInst.composedToArray(chrInst.composeString())[2] + ' seconds left before explosion!');
  }
});

Start method expects to get an Object as an argument. This object can must have some of these configuration properties – direction, callback, duration and timeString. The first one, direction decides whether Chronos will act like a regular clock, or like a countdown timer. If direction is omitted, then Chronos will work like a timer. The callback option specifies a function callback which will be invoked every second with Chronos instance passed as an argument. duration represents time in milliseconds for a timer set up. If you have your setup time represented by a unix timestamp, you can pass this time as timeString property instead of duration.

stop

Chronos last stop.

chr.stop();

This method does exactly as it says. If you need to stop Chronos for time counting, just call stop.

composeString

Assembles current time value into a string.

Chronos.composeString();

composedToArray

Converts composed string into a usable array of time units (hours, mins, secs).

Chronos.composedToArray(composedString);

Examples

Create timer and write time to the page

In this example, we start Chronos with forward option and update changed time every second:

var clockDisplay = document.querySelector('.clock-display');

Chronos.start({
  direction: 'forward',
  callback: function (chr) {
    clockDisplay.textContent = chr.composeString();
  }
});

Counting time backwards

Creating a reverse timer:

var $timeLeft = $('.time-left'),
timeString = new Date(Date.now() + 60 * 60 * 1000);

Chronos.start({
  direction: 'backward',
  timeString: timeString
  callback: function (chr) {
    timeLeft.text(chr.composeString());
  }
});

Release History

  • 2016-02-06   v0.5.4   Switched from singleton to constructor. Now multiple Chronos instances allowed.
  • 2016-02-06   v0.4.4   Added support for timer duration in milliseconds.
  • 2016-02-06   v0.4.3   AMD support refactor.
  • 2016-02-05   v0.4.2   Case when backwards time is past fix.
  • 2016-02-05   v0.4.1   Chronos time runner added.
  • 2016-02-04   v0.3.0   Forward counting logic added.
  • 2016-02-04   v0.2.3   Docs and bower integration.
  • 2016-02-04   v0.2.2   adjustUnits method bug fixed.
  • 2016-02-04   v0.2.1   Code refactor.
  • 2016-02-04   v0.2.0   composedToArray method added & copyrights.
  • 2016-02-04   v0.1.0   First official release. Tests and main logic.