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 🙏

© 2024 – Pkg Stats / Ryan Hefner

timelydiff

v1.0.3

Published

A JavaScript package that converts Unix timestamps into human-readable time differences.

Downloads

5

Readme

TimelyDiff

TimelyDiff is a JavaScript package that converts Unix timestamps into human-readable time differences. It allows you to easily display the time difference between two points in time in a user-friendly manner.

Installation | Usage | API | Contribution

Installation

To install TimelyDiff, you can use NPM:

npm i timelydiff

Usage

To use TimelyDiff, you need to import it in your JavaScript file:

import { timelydiff } from 'timelydiff';

Once you've imported the function, you can use it to convert a Unix timestamp into a human-readable time difference:

const timestamp = 1708868951000; // February 25th, 2024 08:24:36 AM UTC
const timeDiff = timelydiff(timestamp);
console.log(timeDiff); // "in 1 year"

const timestamp2 = 1667499433271;
console.log(timelydiff(timestamp2)); // "4 months ago"

To generate a timestamp at the current moment and store it for later use, you can use the built-in JavaScript function Date.now(), which returns the number of milliseconds since January 1, 1970, 00:00:00 UTC (Unix timestamp).

Optionally, you can pass a second parameter to the function to specify the length of the output string. By default, the function will return a string in the format of x [unit] ago/in [x] [unit], but you can choose to return a shorter string by setting the length parameter to "short" or "shorter".

const timestamp = 1667499433271;
const timeDiffShort = timelydiff(timestamp, "short");
console.log(timeDiffShort); // "4mo ago"

//timelydiff(timestamp, "shorter") -> 4mo

API

timelydiff(timestamp, length) Converts a Unix timestamp into a human-readable time difference.

Parameters

  • timestamp (number) - The Unix timestamp to convert.
  • length (string) - Optional. The length of the output string. Can be set to "short" or "shorter" to return a shorter string. Defaults to null.

Returns A string representing the time difference between the current time and the given timestamp.

Contribution

Contributions are welcome and appreciated! If you have an idea for an improvement or a bug fix, please feel free to open an issue or submit a pull request. Before submitting a pull request, please ensure that your code follows the existing code style and has been thoroughly tested. Thank you for helping to make TimelyDiff even better!

License

TimelyDiff is released under the MIT License.