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

hearken

v4.1.2

Published

A self-adjusting countdown timer capable of carrying out tasks. Hearken tasks can be added at any point during operation through a simple API and they can be set to run just once or on an interval.

Downloads

39

Readme

NPM version Known Vulnerabilities npm NPM downloads Gitter

Installation

To install this module through npm, simply use the following command:

$ npm install --save hearken

Basic Example

To begin using Hearken in your application, you can require the module if you're using it in Node:

const Hearken = require('hearken');

or you can use it on the browser like so:

// Browser
import Hearken from 'node_modules/hearken/hearken.js';

// Webpack
import Hearken from 'hearken';

Then create a new instance of a Hearken timer and specify the time that it should start counting down from in one of two ways, either in milliseconds or in a string format like '00:00:05'.

const hearken = new Hearken(15000);

// OR

const hearken = new Hearken('00:00:15');

Finally, call the Hearken timer's start method to begin the timer's operation.

hearken.start();

Check out the API below to learn all of the methods and events available for the Hearken timer.

API

start

The start method takes no parameters and is used to start the operation of the Hearken timer. Once this method is called, the timer will begin counting down immediately without wait.

This means that if you set the timer to start at 15 seconds, the first tick will be 14 seconds not 15 seconds.

hearken.start();
// Starts the countdown of the timer.

pause

The pause method takes a single optional parameter which is the reason as to why the Hearken timer is being paused.

This reason will be emitted in the details when listening for the pause event.

| param | type | description | default | |--------|--------|-------------------------------------------|---------| | reason | string | An reason as to why the timer was paused. | null |

hearken.pause('Short break');

This method dispatches a signal which can be responded to like below:

hearken.onpause.add(onHearkenPause);

function onHearkenPause(data) {
  // => { currentTime: 0000, elapsedTime: 0000, reason: 'Short break' }
  console.log(data);
}

resume

The resume method takes no parameters and it is used for continuing the operation of the timer after it has been paused.

hearken.resume();

This method emits an event which can be listened to like below:

hearken.onresume.add(onHearkenResume);

function onHearkenResume(data) {
  // => { currentTime: 0000, elapsedTime: 0000 }
  console.log(data);
}

stop

The stop method, like pause takes a single parameter which is the reason as to why the Hearken timer was stopped.

This reason will be emitted when listening for the stop event.

Note that Hearken automatically calls this method when the timer reaches 0.

| param | type | description | default | |--------|--------|-------------------------------------------|---------| | reason | string | An reason as to why the timer was paused. | null |

hearken.stop('No longer needed');

This method emits an event which can be listened to like below:

hearken.onstop.add(onHearkenStop);

function onHearkenStop(data) {
  // => { currentTime: 0000, elapsedTime: 0000, reason: 'No longer needed' }
  console.log(data);
}

Also note that if you're listening to the stop event, it will emit when the timer reaches 0 with no reason.


Tasks

Hearken exposes a tasks API that allows you to easily add and remove tasks from the Hearken timer.

Tasks will emit events that can be listened to when they are run.

A task event can be listened for like below:

hearken.ontask.add(onHearkenTask);

function onHearkenTask(data) {
  // data contains the timer's start time, current time, and all of the task information.
  console.log(data);
}

tasks.add

Add a new task to the Hearken timer. If the repeat parameter of the task is set to true, then Hearken will repeat this task every time seconds.

| param | type | description | default | |--------|----------|-----------------------------------------------------------------------------------------------------------------------------------------|---------| | name | string | A reference name for the task that will be used when a task event is emitted or if you would like to remove the task | | | time | number | The time at which Hearken will run the method related to this task. If this task is being repeated, it will be run every time seconds | | | fn | Function | The method to run every time this task is set to run. | | | repeat | boolean | Whether to run this task on an interval at every time seconds or just once | false |

// This will make the timer log 'Hello World!' to the timer every 2 seconds because repeat is set to true.
hearken.tasks.add('hw', 2000, hello, true);

function hello() {
  console.log('Hello World!');
}

tasks.remove

Remove an existing task from the Hearken timer.

| param | type | description | default | |-------|--------|--------------------------------------------------------------------|---------| | name | string | The reference name of the task as defined when the task was added. | |

// Removes the task named 'hw'.
hearken.tasks.remove('hw');

tasks.clear

Remove all tasks from the Hearken timer.

hearken.tasks.clear();

License

MIT