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

easy-countdown

v3.1.0

Published

Simple, lightweight and easy to use countdown plugin

Readme

easy-countdown

Simple, lightweight and easy to use countdown plugin

CI npm

  • no dependencies — jQuery is optional
  • you control the markup: rendering is a callback
  • written in TypeScript, ships its own types
  • ESM + CJS + UMD builds, ~1.2 kB gzipped

Install

npm install easy-countdown

Usage

import { Countdown } from 'easy-countdown';

new Countdown(document.querySelector('.countdown'), {
  date: '2087-06-07T15:03:25Z',
  render(diff) {
    this.el.innerHTML =
      `${this.leadingZeros(diff.hours)}:` +
      `${this.leadingZeros(diff.min)}:` +
      `${this.leadingZeros(diff.sec)}`;
  },
  onEnd() {
    this.el.innerHTML = 'Time is up';
  },
});

It starts automatically. Via a script tag, the UMD bundle exposes a global Countdown:

<script src="node_modules/easy-countdown/dist/countdown.min.js"></script>
<script>
  new Countdown(document.querySelector('.countdown'), { date: '2087-06-07' });
</script>

jQuery

<script src="jquery.js"></script>
<script src="node_modules/easy-countdown/dist/jquery.countdown.min.js"></script>
<script>
  $('.countdown').countdown({ date: '2087-06-07T15:03:25Z' });

  // the instance lives on the element's data
  $('.countdown').data('countdown').update('2099-01-01');

  // tear it down
  $('.countdown').countdown('destroy');
</script>

The plugin never touches the global $, so it works under jQuery.noConflict(). As a module, when jQuery is not a global:

import { registerJQueryPlugin } from 'easy-countdown/jquery';
import $ from 'jquery';

registerJQueryPlugin($);

The date can also come from the element. It wins over the date option, so one call can configure many elements with their own dates — the same ordering 2.x used:

<div class="countdown" data-date="2087-06-07T15:03:25Z"></div>

Dates

Pass a Date, a timestamp, or a string. Prefer ISO 8601 — anything else is parsed inconsistently across browsers. "August 23, 2016 24:00:00" is the classic trap: V8 rolls hour 24 into the next day, Safari rejects it outright.

Values that cannot be parsed now throw rather than silently counting down to zero, which used to be indistinguishable from a finished countdown:

new Countdown(el, { date: 'nonsense' });
// TypeError: countdown: invalid date "nonsense". Prefer an ISO 8601 string …

Options

| Option | Default | Description | | --- | --- | --- | | date | 2087-06-07T15:03:25 | When the countdown reaches zero. Date, string or timestamp | | refresh | 1000 | Re-render interval in ms. 0 renders once and never repeats | | offset | 0 | Milliseconds added to the remaining time, e.g. to correct clock skew | | render | writes a sentence | (diff) => void, called on every tick | | onEnd | — | () => void, called once when the countdown reaches zero |

render and onEnd are bound to the instance, so this.el, this.options, this.running and this.leadingZeros() are available inside them. Arrow functions keep their own this, as usual.

Decimal seconds

leadingZeros takes an optional third argument for decimal places. Only the integer part is padded, so the field width does not jitter as the fraction ticks:

render(diff) {
  this.el.textContent =
    this.leadingZeros(diff.sec + diff.millisec / 1000, 2, 2) + ' sec';
  // "07.35 sec"
}

Pair it with a small refreshrefresh: 50 or so — otherwise the decimals only move once a second.

The diff object

render receives, and getDiffDate() returns:

| Field | Description | | --- | --- | | years days hours min sec | remaining time, each within its own range | | millisec | 0999 | | total | whole milliseconds remaining; 0 once finished |

API

| Method | Description | | --- | --- | | start() | Start ticking. Idempotent — it will not stack intervals | | stop() | Stop ticking, leaving the last output in place | | restart(options) | Apply new options and start again | | update(date) | Point at a new date and re-render. Call start() afterwards to resume ticking if it had already finished | | updateOffset(ms) | Adjust the offset | | render() | Render once, now | | destroy() | Stop ticking and release the element | | getDiffDate() | The remaining time. Has no side effects | | leadingZeros(num, length?, fractionDigits?) | Pad with zeros; optionally keep decimal places | | running / finished | Getters for the current state | | options / el | The resolved options and the host element |

All methods except destroy() and getDiffDate() return the instance for chaining.

Examples

Run npm run build, then open examples/index.html in a browser.

Migrating from 2.x

  • Distributed as ESM (dist/countdown.mjs), CommonJS (dist/countdown.cjs) and a minified UMD bundle for script tags (dist/countdown.min.js). The UMD global is still Countdown. The npm package is still easy-countdown.
  • Bower packaging was removed. Install from npm.
  • Licensing is MIT only. The 2.x manifest claimed MIT and GPL, with no LICENSE file in the repo.
  • getDiffDate() no longer fires onEnd as a side effect of being read. render() owns that now, so inspecting the remaining time is safe.
  • millisec is now 0999. It used to be a fraction of a second times 1000.
  • The diff object gained total.
  • Invalid dates throw instead of rendering zeros.
  • leadingZeros gained a third argument for decimal places.
  • New: destroy(), finished, running, and TypeScript types.
  • The build output moved to dist/. The 2.x dest/ filenames are still published as copies, so existing CDN and <script src> URLs keep working.

Fixed in 3.0

  • onEnd never fired when the target date was already in the past, or when refresh was 0 — it was gated on an interval already running.
  • restart() did not clear the running interval, leaking a timer on each call and multiplying the render rate.
  • sec could render as 60 just under a minute, because it was rounded rather than floored.
  • The jQuery plugin used the global $ internally and broke under jQuery.noConflict().
  • new Countdown(el) and $el.countdown() threw when no options were given.

License

MIT