timerel
v5.9.0
Published
Teeny-tiny relative date formatting
Downloads
1,986
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 agoWhen 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?)
dateString, Number or Date: The date to format.
Options
nowString, Number or Date: The date to compare to. Default:Date.now().noAffixBoolean: Whether to omitagoandinaffixes. Default:false.timesArray: A custom time table that overrides the built-in one. Entries are[msPerUnit, maxMs, unit, shortUnit?, longUnit?], the optional labels fall back tounit.nowThresholdNumber: Number of milliseconds below which to output"now". Default: 2000.nowStringString: String to output for now. Default:"now".unknownStringString: String to output for invalid dates. Default:String(date).aliasesBoolean: Use aliases like "yesterday" instead of "1 day ago". Default:false.aliasesMapObject: A custom aliases object to use instead of the built-in one.longUnitsBoolean: Use minutes/seconds instead of mins/secs. Default:false.shortUnitsBoolean: Use short units like1d ago, overridinglongUnits. Built-in aliases do not match. Default:false.
© silverwind, distributed under BSD licence
