uploaded-time-ago

1.0.0 • Public • Published

uploaded-time-ago

A simple JavaScript function to display human-readable relative time strings like "5 minutes ago", "2 days ago", etc. Perfect for showing timestamps in a user-friendly format.

Features

  • Converts timestamps to relative time strings.
  • Handles future timestamps and invalid inputs gracefully.
  • Easy to use in both browser and Node.js environments.

Installation

You can install the package using npm:

npm install uploaded-time-ago
import timeAgo from "uploaded-time-ago";

// Example usage
console.log(timeAgo(Date.now() - 45000)); // 45 seconds ago
console.log(timeAgo(Date.now() - 3600000)); // 1 hour ago
console.log(timeAgo(Date.now() - 86400000)); // 1 day ago
console.log(timeAgo(Date.now() + 45000)); // Timestamp is in the future
console.log(timeAgo()); // Invalid timestamp

Package Sidebar

Install

npm i uploaded-time-ago

Weekly Downloads

7

Version

1.0.0

License

ISC

Unpacked Size

2.96 kB

Total Files

3

Last publish

Collaborators

  • webcraftmamun