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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@weiseng18/time-ago

v0.2.1

Published

time ago in human readable format

Downloads

23

Readme

time-ago

Utility to present in a human-readable format:

  • time ago
  • time in the future

Usage

ago = require("@weiseng18/time-ago")

// absolute time
ago.fromToday(1) // 52 years ago

// dynamic time (in the past)
ago.fromToday(new Date() - 7 * 24 * 60 * 60 * 1000) // 7 days ago
ago.fromToday(new Date() - 10 * 1000) // 10 seconds ago
ago.fromToday(new Date()) // just now

// dynamic time (in the future)
//
// interestingly, new Date() - 1000 will cast the new Date() to an integer
// however, new Date() + 1000 interprets appending "1000" to the date
// as such, need to do new Date().valueOf() instead
ago.fromToday(new Date().valueOf() + 1) // just now
ago.fromToday(new Date().valueOf() + 10 * 1000) // in 10 seconds
ago.fromToday(new Date().valueOf() - 7 * 24 * 60 * 60 * 1000) // in 7 days

Worked Example

Let initialTime be 31 Jan 2021 at 12PM GMT+8, and let today be 31 Mar 2021 at 12PM GMT+8.

Converting into epoch,

  • initialEpoch (ms) is 1612065600000
  • todayEpoch (ms) is 1617163200000

Calculating todayEpoch - initialEpoch to obtain timePassed, we obtain 5097600000 (ms).

Note that

  • 5097600000 < 31536000000 = year in ms
  • 5097600000 > 2628000000 = month in ms

From here we can tell that the largest unit of time where the elapsed time is still more than the unit, is month.

Dividing timePassed by the number of milliseconds in a month,

  • 5097600000 / 2628000000 ≈ 1.9397
  • Math.round(1.9397) = 2

Now we can conclude that initialTime was 2 months prior to today.

The util then returns "2 months ago".

Caveats

  • The util uses Intl.RelativeTimeFormat, which only supports up to a smallest unit of seconds. For an absolute time less than 1 second ago, the util returns 'just now'.