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

@ramstack/timeago

v1.0.0

Published

@ramstack/timeago is a tiny utility that turns dates into live-updating relative time text like '3 minutes ago' or in '2 hours'.

Readme

@ramstack/timeago

NPM MIT

@ramstack/timeago is a tiny utility that turns dates into live-updating relative time text like "3 minutes ago" or "in 2 hours".

It automatically tracks elements with datetime or data-datetime, updates text only when needed (using smart intervals), reacts to DOM changes, and cleans up after itself.

No polling every second. No manual updates.

The library is small enough - around 1.7 KB, or about 900 bytes gzipped.

Formatting is handled by the browser using Intl.RelativeTimeFormat, so the output follows the browser's locale rules and language data.

Installation

Using NPM

npm install @ramstack/timeago

Using CDN

<script src="https://cdn.jsdelivr.net/npm/@ramstack/timeago@1/dist/timeago.min.js"></script>

Quick start

Just call timeago() and pass a selector. It will find matching elements and start updating them.

<time datetime="2026-01-13T10:00:00Z"></time>
import { timeago } from "@ramstack/timeago";

const cleanup = timeago("time");

That's it. The text content will update automatically as time passes.

When you no longer need it:

cleanup();

Using a custom locale

By default, the browser's locale is used. You can override it if needed:

timeago(".timeago", { locale: "es" });

How it works (short version)

  • Looks for elements matching your selector
  • Reads date from datetime or data-datetime
  • Updates text only when needed (smart intervals)
  • Watches DOM changes using MutationObserver
  • Cleans everything up when you call the returned function

No polling every second. No manual updates.

API

timeago(selector, options?)

Starts tracking elements and returns a cleanup function.

Parameters

selector (required) A CSS selector for elements that should display relative time.

timeago("[datetime]");

options (optional)

{
  locale?: string;
}
  • locale — locale code for formatting ("en", "fr", "ru", etc.)
  • Defaults to the browser's locale

Returns

A function that stops all updates and disconnects the observer.

const cleanup = timeago(".timeago");

// later
cleanup();

Supported date formats

The date value can be:

  • An ISO date string

    <time datetime="2026-01-13T10:00:00Z"></time>
  • A unix timestamp in milliseconds

    <span data-datetime="1705140000"></span>

If the date is invalid, the element is ignored.

Source Code

You can find the source code for this plugin:

https://github.com/rameel/ramstack.timeago.js/blob/main/src/timeago.ts

Contributions

Bug reports and contributions are welcome.

License

This package is released as open source under the MIT License. See the LICENSE file for more details.