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

timemitter

v1.1.0

Published

Timer based event Emitter for casual use

Downloads

15

Readme

timemitter

Time based event Emitter for casual use.

Internal clock is a setInterval(), so I don't reccomend this for serious use.

Install

npm install timemitter
# or
yarn add timemitter

Usage

import Timemitter from 'timemitter';

const timer = new Timemitter();
timer
  .at(0, time => console.log(`${time}: start!`))
  .at(3, time => console.log(`${time}: at 3sec`))
  .at(5, time => console.log(`${time}: at 5sec`))
  .every(2, time => console.log(`${time}: every 2sec`))
  .at(60, time => console.log(`${time}: at 1min`))
  .start();

This code logs,

0: start!
2: every 2sec
3: at 3sec
4: every 2sec
5: at 5sec
6: every 2sec
8: every 2sec

// ...

60: at 1min
60: every 2sec

API

at(time, handler)

Fire handler only once at specified time.

  • time: number
  • handler: (time: number) => {}
new Timemitter()
  .at(3, time => console.log(`Fired after ${time}sec`)) // 3
  .start();

If negative value passed to time, it is treated as 0.

every(time, handler)

Fire handler every time in interval.

  • time: number
  • handler: (time: number) => {}
new Timemitter()
  .every(3, () => console.log(`Fired after every ${time}sec`)) // 3, 6, 9, 12...
  .start();

If zero or negative value passed to time, it is treated as 1.

start(interval)

Start the timer. Default interval is 1sec = 1000.

  • interval: number
new Timemitter()
  .at(2, () => console.log(`Fired after ${time} * 0.5sec`))
  .start(500);

In this case, interval is 500. So handler called in 1sec.

pause() / resume()

Pause and resume timer.

const timer = new Timemitter();

timer
  .at(0, () => console.log('fire'))
  .at(2, () => timer.pause())
  .at(3, () => console.log('will not fire');

If you resume later, timer will restart from paused time.

timer.resume();

In this case, timer restarts from 2, next fire time is 3.

reset()

Reset timer count to 0.

const timer = new Timemitter();
timer
  .at(3, () => console.log('Fired after 3sec'))
  .at(5, () => timer.reset())
  .start();

This case,

  • called once after 3sec
  • and reset() at 5sec
  • called again at 8sec point from start

destroy()

Stop interval and remove all handlers.

const timer = new Timemitter();
timer
  .at(3, () => console.log('Fired after 3sec'))
  .start();

timer.destroy();

In this case, 3sec handler do not be called.