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

native-time-ago

v1.0.1

Published

A tiny zero-dependency relative time formatter using the native Intl API.

Downloads

54

Readme

native-time-ago

npm version bundle size license

A tiny, zero-dependency utility that converts JavaScript Dates into human-readable strings like "3 hours ago" or "in 2 days" using native browser APIs.

Why?InstallUsageLocales


Why?

The native Intl.RelativeTimeFormat API is powerful, but it's "dumb"—it doesn't calculate time differences. If you want "3 hours ago," you have to manually calculate how many seconds have passed, divide by 3600 to get hours, and then pass exactly (-3, "hours") to the native formatter.

This package handles the math. It takes a date, calculates the optimal unit (seconds → minutes → hours → days → weeks → months → years), and passes the correct number and unit to the native formatter.

Features

  • Zero Dependencies - Only ~1388 bytes
  • 100+ Languages - Supports any locale via Intl.RelativeTimeFormat
  • Framework Agnostic - Works in React, Vue, Svelte, Angular, Node.js, Bun
  • Auto-updating - Translations improve as browsers update

Install

npm install native-time-ago

Usage

import timeAgo from 'native-time-ago';

// Basic usage
timeAgo(new Date(Date.now() - 3 * 60 * 60 * 1000));  // "3 hours ago"
timeAgo(new Date('2026-03-03T12:00:00Z'));            // "3 hours ago"

// Future dates
timeAgo(new Date(Date.now() + 2 * 24 * 60 * 60 * 1000));  // "in 2 days"

// Different locales
timeAgo(new Date(Date.now() - 3 * 60 * 60 * 1000), 'es');  // "hace 3 horas"
timeAgo(new Date(Date.now() - 3 * 60 * 60 * 1000), 'ja');  // "3 時間前"
timeAgo(new Date(Date.now() - 3 * 60 * 60 * 1000), 'fr');  // "il y a 3 heures"

// Pass string or number
timeAgo('2026-03-03T12:00:00Z', 'en');
timeAgo(1709476800000, 'en');

Comparison

// OLD WAY (heavy, many dependencies)
import { formatDistanceToNow } from 'date-fns';
import { es } from 'date-fns/locale';
formatDistanceToNow(new Date(2026, 2, 3), { locale: es, addSuffix: true });

// NEW WAY (zero dependencies)
import timeAgo from 'native-time-ago';
timeAgo(new Date('2026-03-03T12:00:00Z'), 'es');

Supported Locales

Any locale supported by Intl.RelativeTimeFormat:

  • en, es, fr, de, it, pt, ru, ja, ko, zh, ar, and 100+ more

API

timeAgo(date, locale?)

  • date - Date | string | number - The date to format
  • locale - string - Optional locale code (default: 'en')

Returns a string like "3 hours ago", "in 2 days", or "now".

License

MIT