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

@bekoden/interval-manager

v0.1.0

Published

Shared global interval manager for TypeScript and React apps.

Downloads

11

Readme

@koden/interval-manager

Shared interval ticker for TypeScript apps, with optional React bindings.

Install

npm install @koden/interval-manager

React bindings (if needed):

npm install react

Quick usage (core)

import { createIntervalManager } from "@koden/interval-manager";

const manager = createIntervalManager();

const unsubscribe = manager.subscribe(({ nowMs, tickCount }) => {
  console.log("tick", tickCount, nowMs);
});

manager.start();

// later
unsubscribe();
manager.stop();
manager.dispose();

React usage

import React from "react";
import {
  IntervalManagerProvider,
  useIntervalNow,
  useIntervalCountdown,
} from "@koden/interval-manager/react";

function Clock() {
  const nowMs = useIntervalNow();
  return <p>{new Date(nowMs).toLocaleTimeString()}</p>;
}

function OfferCountdown() {
  const targetMs = Date.now() + 60_000;
  const remainingMs = useIntervalCountdown(targetMs);
  return <p>{Math.ceil(remainingMs / 1000)}s left</p>;
}

export function App() {
  return (
    <IntervalManagerProvider>
      <Clock />
      <OfferCountdown />
    </IntervalManagerProvider>
  );
}

Environment defaults

The manager reads these environment values when created:

  • USE_INTERVAL_KODEN=true|false
  • USE_INTERVAL_SECONDS_KODEN=<seconds>

Parsing rules:

  • USE_INTERVAL_KODEN is case-insensitive and trimmed.
  • Only "true" and "false" are accepted. Any other value falls back to default (true).
  • USE_INTERVAL_SECONDS_KODEN must be a finite positive number.
  • Missing/invalid seconds fall back to 1.
  • Valid seconds are clamped to a minimum of 1.
  • Programmatic config (enabled, intervalSeconds) overrides env values.
  • Runtime API can still update values via setEnabled(...) and setIntervalSeconds(...).

Example:

const manager = createIntervalManager({
  enabled: false,
  intervalSeconds: 5,
});

SSR notes

  • createIntervalManager safely checks for process.env only when available.
  • useIntervalNow uses useSyncExternalStore and provides a server snapshot.
  • Prefer creating one manager instance per request boundary in SSR frameworks.

Migration notes

Replace many component-level setInterval calls with one shared manager:

  1. Create one manager during app bootstrap.
  2. Subscribe from places that need a periodic update.
  3. Remove local timer setup/cleanup from components.
  4. In React, expose it via IntervalManagerProvider and use hooks.

This reduces duplicate timers and keeps ticking behavior centralized.

API

Core:

  • createIntervalManager(config?)
  • start()
  • stop()
  • isRunning()
  • getNow()
  • subscribe(listener)
  • setIntervalSeconds(seconds)
  • setEnabled(enabled)
  • dispose()

React:

  • IntervalManagerProvider
  • useIntervalManager()
  • useIntervalNow()
  • useIntervalCountdown(targetMs)