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

jquery-tinytimer

v0.1.4

Published

TinyTimer is a very simple plugin that lets you create a countdown (or countup) timer on a web page.

Downloads

2

Readme

jQuery TinyTimer Plugin

TinyTimer is a very simple jQuery plugin that lets you create a countdown (or countup) timer on a web page.

Basic Usage

Create a HTML element for your timer somewhere in the page:

<p>
	Time remaining: <span id="timer"></span>
</p>

Then, wrap that element in a jQuery object and call its tinyTimer method, passing the date to count to as the to option. Here's an example that starts a 30-minute countdown:

var d = new Date();
d.setMinutes(d.getMinutes() + 30);
$('#timer').tinyTimer({ to: d });

To create a timer counting up from a moment in time, use the from option instead of to. This produces a timer that shows the number of days since a specific date:

var d = new Date('January 1, 2013');
$('#timer').tinyTimer({ from: d, format: '%d' });

Options

  • format

    The format used to display the date/time. See Time Format for details.

  • from

    Date/time to count (up) from. Can be a JavaScript Date object or a string (IETF-compliant RFC 2822 timestamp).

  • to

    Date/time to count (down) to.

  • onTick

    Callback function to be invoked on every tick (every second). See Callback Functions for details.

  • onEnd

    Callback function to be invoked when the countdown is over. See Callback Functions for details.

Time Format

The format option allows you to define how the time will be displayed. The different values are represented by tokens composed of a percent sign and a formatting character:

  • %d - days
  • %h - hours
  • %m - minutes
  • %s - seconds

If the format character is preceded by 0 (e.g., %0m), then single-digit numbers will be displayed with a leading zero (e.g., 04:20 instead of 4:20). If it is preceded by - (e.g., %-h), then the number won't be displayed if it is zero. The two modifiers can be combined (e.g., %-0h).

The above format characters can also be used in uppercase form, in which case they represent total quantities. For instance, if the current time is 2 days and 4 hours, d and h would be 2 and 4 respectively, while the values of D and H would be 2 and 52 (2 * 24 + 4 = 52).

The format character can also be followed by a suffix, enclosed in curly braces, to denote the unit of time. You can set different suffixes for singular and plural form by separating them with |. For example, a format setting of %d {day|days} would output the number of days followed by the appropriate form.

Anything else in the format string will be included in the output as it is.

A few examples:

  • %-d {day,|days,} %0h {hour|hours} - 2 days, 07 hours
  • %m minutes and %s seconds - 12 minutes and 4 seconds
  • %H:%0m:%0s - 55:12:04

The default format is %-H{:}%0m:%0s, which is the total number of hours (not displayed if zero), then minutes and seconds, separated by colons.

Callback Functions

The onTick and onEnd callback functions take one argument, which is an object that represents the current value of the timer. This object has the following properties:

  • s - seconds
  • m - minutes
  • h - hours
  • d - days
  • S - total seconds
  • M - total minutes
  • H - total hours
  • D - total days (same as d)
  • text - textual representation of the current time (formatted according to the format option)

Here's an example of a timer that counts from the time that the page is loaded and uses the onTick callback function to display an alert every minute:

$('#timer').tinyTimer({
	from: Date.now(),
	onTick: function (val) {
		if (val.m > 0 && val.s == 0)
			alert('You decided to stay on this site for another minute! Yay!');
	}
});

Using with Moment.js

TinyTimer can be used with the great Moment.js library, which makes date manipulation much easier than with plain Date objects. You just need to convert the moment object to Date using its toDate method before passing it as to or from:

// 30-minute countdown
var m = moment().add('minutes', 30);
$('#timer').tinyTimer({ to: m.toDate() });

// Hours since the beginning of the week
var m = moment().startOf('week');
$('#timer').tinyTimer({ from: m.toDate(), format: '%H' });