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

timertasks

v1.1.0

Published

A lightweight utility for centralized management of setInterval tasks

Readme

✨ Features

  • Centralized — every timer lives in one registry, keyed by a name you choose. No more lost setInterval IDs scattered across your codebase.
  • Dynamic — restart any task with a new interval without keeping a reference to its callback.
  • Immediate — optionally fire the callback once on registration, before the first tick.
  • One-call cleanup — clear a single task or all of them at once, perfect for component unmounting or app shutdown.
  • Tiny & universal — zero dependencies, ~1 kB minified+gzip, ships ESM + CJS, runs in browsers and Node.js, TypeScript types included.

📦 Installation

# npm
npm install timertasks

# pnpm
pnpm add timertasks

# yarn
yarn add timertasks

Works out of the box with both module systems via exports conditions:

// ESM
import { setTimedTask, clearAllTimedTask } from 'timertasks';

// CommonJS
const { setTimedTask, clearAllTimedTask } = require('timertasks');

🚀 Usage

import {
  setTimedTask,
  restartTimedTask,
  clearTimedTask,
  clearAllTimedTask,
} from 'timertasks';

// 1. Register and start a task that logs every second
setTimedTask(
  'heartbeat',
  () => console.log('Task is running...'),
  1000,
  { immediate: true }, // fires once right away, then every 1000ms
);

// 2. Switch it to a faster interval — no callback reference needed
restartTimedTask('heartbeat', 500);

// 3. Stop one task
clearTimedTask('heartbeat');

// 4. Stop everything (e.g. on app shutdown)
clearAllTimedTask();

A typical cleanup pattern in React:

useEffect(() => {
  setTimedTask('poll', fetchMetrics, 5_000, { immediate: true });
  return () => clearTimedTask('poll');
}, []);

📖 API Reference

setTimedTask(name, callback, time, options?)

Registers and starts an interval task.

| Parameter | Type | Description | | ------------------- | ---------------------- | ----------------------------------------------- | | name | string | Unique identifier for the task | | callback | () => void | Function to execute on each tick | | time | number | Interval in milliseconds | | options.immediate | boolean (optional) | If true, executes callback once immediately |

[!NOTE] Registering with a name that already exists overwrites the registry entry. Clear the previous task first (clearTimedTask(name)) before re-registering the same name.

restartTimedTask(name, newTime)

Stops the task and starts it again with a new interval, reusing the registered callback. No-op if name is not registered.

clearTimedTask(name)

Stops the task and removes it from the registry. No-op if name is not registered.

clearAllTimedTask()

Stops and removes every registered task.

timerTaskMap

The internal Map<string, [timerId, callback]> registry, exported for introspection (e.g. checking whether a task is registered via timerTaskMap.has(name)).

🛠️ Development

pnpm install        # install dependencies
pnpm run dev        # watch mode
pnpm run build      # build ESM + CJS to dist/
pnpm run test       # run the test suite (Rstest)
pnpm run typecheck  # TypeScript checking for src/ and tests/
pnpm run lint       # lint with Rslint

🤝 Contributing

Issues and pull requests are welcome at MissGwen/timertasks.

📜 Changelog

See CHANGELOG.md for release notes.

📄 License

MIT © MissGwen