1.1.0 • Published 10 months ago

chronify v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

∆ Chronify

NPM Version Repository Size License Downloads Support

Chronify is a Node.js package that provides a simple way to calculate and display human-readable time differences between dates. Perfect for applications that need to show elapsed or remaining time in a user-friendly format.

Features

  • Flexible Time Units: Shows time differences in years, months, days, hours, and minutes.
  • Customizable Output: Supports both full and abbreviated unit formats.
  • Human-readable Format: Easy-to-understand phrases like "2 weeks ago" or "in 3 days."

Installation

Install Chronify via npm:

npm install chronify

Usage

Import and use Chronify in your Node.js project:

const { chronify } = require("chronify");

Example

Display the time difference from the current date:

console.log(chronify("2024-09-01T12:00:00Z"));
// Example Output: "2 weeks ago" (depending on the current date)

Customizing Output

Control the number of units displayed and use abbreviated formats:

console.log(chronify("2024-09-01T12:00:00Z", { maxUnits: 1, short: true }));
// Example Output: "2w ago" (depending on the current date)

Options

  • maxUnits (number): Maximum number of time units to display. Defaults to 2.
  • short (boolean): Use abbreviated units if true. Defaults to false.