timerel

Teeny-tiny relative date formatting

BSD-2-Clause 42 个版本
安装
npm install timerel
yarn add timerel
pnpm add timerel
bun add timerel
README

timerel

timerel formats dates to short english relative format 5 mins ago and does so around 11 times faster than its competition.

Usage

import {timerel} from "timerel";

console.log(timerel(Date.now() - 1e6));
// => 16 mins ago

When formatting multiple dates in a loop, pass {now: Date.now()} to avoid repeated Date.now() calls internally:

const now = Date.now();
for (const date of dates) {
  console.log(timerel(date, {now}));
}

API

timerel(date, opts?)

  • date String, Number or Date: The date to format.

Options

  • now String, Number or Date: The date to compare to. Default: Date.now().
  • noAffix Boolean: Whether to omit ago and in affixes. Default: false.
  • times Array: A custom time table that overrides the built-in one.
  • nowThreshold Number: Number of milliseconds below which to output "now". Default: 2000.
  • nowString String: String to output for now. Default: "now".
  • unknownString String: String to output for invalid dates. Default: String(date).
  • aliases Boolean: Use aliases like "yesterday" instead of "1 day ago". Default: false.
  • aliasesMap Object: A custom aliases object to use instead of the built-in one.
  • longUnits Boolean: Use minutes/secoonds instead of mins/secs. Default: false.

© silverwind, distributed under BSD licence

版本列表
5.8.7 2026-04-21
5.8.6 2026-02-24
5.8.5 2025-12-03
5.8.4 2025-12-03
5.8.3 2025-10-27
5.8.2 2025-09-14
5.8.1 2024-12-02
5.8.0 2024-05-27
5.7.0 2024-05-24
5.6.3 2024-05-13
5.6.2 2024-05-13
5.6.1 2024-05-03
5.6.0 2024-05-03
5.5.0 2024-01-23
5.4.3 2023-09-01
5.4.2 2023-07-03
5.4.1 2023-03-31
5.4.0 2022-12-22
5.3.0 2022-11-20
5.2.0 2022-11-20
5.1.0 2022-11-20
5.0.6 2022-11-20
5.0.5 2022-11-10
5.0.4 2022-08-03
5.0.3 2022-08-03
5.0.2 2022-07-30
5.0.1 2022-07-30
5.0.0 2022-07-30
4.0.3 2022-07-30
4.0.2 2022-07-30
4.0.1 2022-07-30
4.0.0 2022-07-29
3.0.0 2022-07-29
2.2.0 2022-07-29
2.1.1 2022-07-29
2.1.0 2022-07-29
2.0.2 2022-07-29
2.0.1 2022-07-29
2.0.0 2022-07-29
1.0.2 2022-07-29
1.0.1 2022-07-29
1.0.0 2022-07-29