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

endspurt

v0.3.0

Published

A simple and framework agnostic countdown library

Downloads

79

Readme

Endspurt: A feature-rich countdown library

⚠ Warning: Endspurt is still under development. There can still be breaking changes in 0.x.x-Verions. See the release notes for more information.

Installation

Via a CDN

<script src="https://cdn.jsdelivr.net/npm/endspurt"></script>
<script src="https://unpkg.com/endspurt"></script>

Via NPM

npm install --save endspurt
import Endspurt from 'endspurt';

Basic usage

const options = { include: ['hours', 'minutes', 'seconds'] };
const myCountdown = new Endspurt('YYYY-MM-DDT00:00:00', options);

myCountdown.on('updated', (distance) => {
  const { hours, minutes, seconds } = distance;
  console.log(`${hours.value} hours, ${minutes.padded} minutes and ${seconds.padded} seconds remaining.`);
});

myCountdown.on('finished', () => {
  console.log('Celebrate!');
});

myCountdown.start();

API

new Endspurt(value, options)

value

Allowed formats:

  • undefined
  • new Date()
  • Timestamp as Number
  • Timestamp as String
  • 'YYYY-MM-DD'
  • 'YYYY-MM-DDT00:00:00'
  • {
      year: 'YYYY',
      month: 'MM',
      day: 'DD',
      hour: 'HH',   // optional, default: '00'
      minute: 'II', // optional, default: '00'
      second: 'SS', // optional, default: '00'
    }

options

Defined as Object. See options reference

Methods

const myCountdown = new Endspurt(value, options);

myCountdown.setEndDate(Date);      // set new end-date, see valid value formats above
myCountdown.setOptions(Object);    // override options
myCountdown.start();               // start countdown interval
myCountdown.stop();                // stop countdown interval
myCountdown.on(String, Function);  // register event callbacks

Events

myCountdown.on('finished', Function);        // triggered when time is reached
myCountdown.on('started', Function);         // triggered when myCountdown.start() is called
myCountdown.on('stopped', Function);         // triggered when myCountdown.stop() is called
myCountdown.on('terminated', Function);      // triggered when time is reached and options.terminate is set to true
myCountdown.on('updated', Function);         // triggered on every interval iteration
myCountdown.on('updated-enddate', Function); // triggered when myCountdown.setEndDate() is called

Every event gets the distance object as first parameter.

myCountdown.on('updated', function (distance) {
  console.log(distance);
});

Example output

{
  years: { value: 1, padded: '01', raw: 1 },
  months: { value: 1, padded: '01', raw: 1 },
  weeks: { value: 2, padded: '02', raw: 2 },
  days: { value: 6, padded: '06', raw: 6 },
  hours: { value: 2, padded: '02', raw: 2 },
  minutes: { value: 59, padded: '59', raw: 59 },
  seconds: { value: 13, padded: '13', raw: 13 },
  milliseconds: { value: 987, padded: '0987', raw: 987 },
}

Options

| Option | Format | Default value | Description |-----------------|---------|------------------------------------------:|------------ | include | Array | See below | Include defined periods in calculation | interval | Number | 200 | Define (in milliseconds) at which interval the updated-event should be called | terminate | Boolean | true | Stop interval if countdown has finished | timezoneOffset | Number | 0 | Manual timezone offset in milliseconds | yearsPad | Number | 1 | Number of leading zeros for distance.years.padded output | monthsPad | Number | 2 | Number of leading zeros for distance.months.padded output | weeksPad | Number | 2 | Number of leading zeros for distance.weeks.padded output | daysPad | Number | 2 | Number of leading zeros for distance.days.padded output | hoursPad | Number | 2 | Number of leading zeros for distance.hours.padded output | minutesPad | Number | 2 | Number of leading zeros for distance.minutes.padded output | secondsPad | Number | 2 | Number of leading zeros for distance.seconds.padded output | millisecondsPad | Number | 4 | Number of leading zeros for distance.milliseconds.padded output

Default value for include

['years', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds']