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

@alexpopovme/deadline-timer

v0.1.0

Published

A small TypeScript utility for counting down to an absolute date based on server time

Downloads

142

Readme

DeadlineTimer

English | Русский

A small TypeScript utility that counts down to an absolute date using server time. It is UI-framework-agnostic and makes no network requests.

Installation

pnpm add @alexpopovme/deadline-timer

The package is distributed as ESM and has no runtime dependencies.

Usage

import { createDeadlineTimer } from '@alexpopovme/deadline-timer'

const timer = createDeadlineTimer({
  expiresAt: '2026-08-06T12:30:00Z',
  serverNow: '2026-08-06T12:10:00Z',
})

if (timer) {
  const unsubscribe = timer.subscribe((snapshot) => {
    console.log(snapshot.remainingSeconds)
    console.log(snapshot.status)
  })

  // Когда подписка больше не нужна
  unsubscribe()
}

Input

  • expiresAt — the absolute expiration date or null. When it is null, the factory returns null.
  • serverNow — the server time received together with the deadline. You do not need to pass the device's local time.
  • expirationSafetySeconds — ends the countdown slightly early to account for delay between the server and the client. It defaults to 5 seconds; 0 disables the margin.

Dates are parsed with Date.parse. Always specify the time zone explicitly; the recommended format is 2026-08-14T07:38:51.923Z. An invalid object, type, date, or option causes a synchronous TypeError. Additional properties in input objects are allowed.

The backend must still verify whether an action is available.

Snapshot

type DeadlineTimerSnapshot = Readonly<{
  remainingSeconds: number
  status: 'active' | 'expired'
}>

remainingSeconds is the non-negative number of seconds remaining, rounded up. The status is active when the remaining time is positive and expired when it reaches zero. Previously returned snapshot objects are not mutated.

Methods

  • getSnapshot() returns the current state without starting updates or notifying subscribers.
  • subscribe(listener) immediately calls the listener synchronously with the current state. It then calls the listener only when the remaining time or status changes.
  • The returned function removes only its own subscription and is safe to call repeatedly. Updates stop after the last subscription is removed.
  • For an already expired timer, the listener is called once. The listener must be a function and must not throw.

How time is calculated

The timer stores serverNow when it is created and adds the actual elapsed time to it. After a delay or returning to the tab, it therefore calculates the current remaining time immediately without replaying missed values.

The timer does not contact the server again. If the backend provides new expiresAt or serverNow values, create a new instance. The server remains the source of truth for deciding whether an action is available.

API

type DeadlineTimerInput = Readonly<{
  expiresAt: string | null
  serverNow: string
}>

type DeadlineTimerOptions = Readonly<{
  expirationSafetySeconds?: number
}>

type DeadlineTimerStatus = 'active' | 'expired'

type DeadlineTimerSnapshot = Readonly<{
  remainingSeconds: number
  status: DeadlineTimerStatus
}>

type DeadlineTimerListener = (snapshot: DeadlineTimerSnapshot) => void

type DeadlineTimer = Readonly<{
  getSnapshot(): DeadlineTimerSnapshot
  subscribe(listener: DeadlineTimerListener): () => void
}>

declare const createDeadlineTimer: (
  input: DeadlineTimerInput,
  options?: DeadlineTimerOptions,
) => DeadlineTimer | null

Specifications

The normative project specifications are currently available in Russian: