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

tickago

v1.0.0

Published

JavaScript library to calculate and compare elapsed time

Readme

TickAgo

Overview

A JavaScript library to calculate and compare elapsed time.

  • Automatically detects elapsed time: seconds, minutes, hours, months, or years ago.
  • Compare two times and get the elapsed time object.
  • Customizable and flexible.
  • And more to explore!

How it Works

It works by getting the given date and calculating the elapsed time.

Installation

  1. Include the source file in your project, either manually or by using our CDN:
<script src="https://cdn.jsdelivr.net/gh/rezzvy/tickago@latest/dist/tickago.min.js"></script>
  1. Assuming you're in a browser environment, you can use the library by calling the method directly TickAgo.{methodName}. In a Node environment, you need to require it first.

Usage

moment() method

// Given parameter as a Date object
console.log(TickAgo.moment(new Date("2011-11-11"))); // Expected output: {x} years ago
// Given parameter as a timestamp
console.log(TickAgo.moment(Date.now() - 5000)); // Expected output: 5 sec ago
// Given parameter as a string
console.log(TickAgo.moment("2011-11-11")); // Expected output: {x} years ago

// Another examples
console.log(
  TickAgo.moment(Date.now() - 5000, {
    labels: {
      sec: "detik yang lalu",
    },
  })
); // Expected output: 5 detik yang lalu (indonesian)

console.log(
  TickAgo.moment("11-2011-11", {
    format: "DD-YYYY-MM",
  })
); // Expected output: {x} years ago

compare() method

 // Given parameters as strings
console.log(TickAgo.compare("2015-01-01", "2025-01-01"));
// Expected Output
{
    "years": 10,
    "months": 0,
    "days": 0,
    "hours": 0,
    "minutes": 0,
    "seconds": 0,
    "elapsedTime": 315619200000
}

// A mix of string and timestamp
console.log(TickAgo.compare("2015-01-01", Date.now())); // Current timestamp 1738479393395
// Expected Output
{
    "years": 10,
    "months": 1,
    "days": 1,
    "hours": 6,
    "minutes": 56,
    "seconds": 33,
    "elapsedTime": 318408993395
}

// Using custom date format
console.log(TickAgo.compare("11-2011-11", "12-2012-12", "MM-YYYY-DD"));
// Expected Output
{
    "years": 1,
    "months": 1,
    "days": 1,
    "hours": 0,
    "minutes": 0,
    "seconds": 0,
    "elapsedTime": 34300800000
}

Documentation

moment(timestamp, options) method

  • First parameter Expected to be a string, timestamp, or date object. If the given value is a date object, the custom date format will be ignored, and the date object will be used as it is.

  • Second parameter (optional)

{
  format: "DD-MM-YYYY", // DD as Day, MM as month, YYYY as year
  labels: {
    sec: "sec ago",
    minutes: "minutes ago",
    hours: "hours ago",
    days: "days ago",
    months: "months ago",
    years: "years ago"
  }
}

compare(dateOne, dateTwo, format) method

[!NOTE]
If the given value contains only the day, month, and year, the hours, minutes, and seconds will always be zero. To make it work, you can pass the time in the given date, e.g., 2012-12-12T19:29, or manually create a date object and set the hours and minutes.

  • First and second parameters
    Expected to be a string, timestamp, or date object. If the given value is a date object, the custom date format will be ignored, and the date object will be used as it is.

  • Third parameter (optional)
    Expected to be a string, e.g., YYYY-MM-DD.

Contributing

There's always room for improvement. Feel free to contribute!

Licensing

The library is licensed under MIT License. Check the license file for more details.