anywhen is a tiny (1.1kb gzip) zero-dependency date formatter that provides three modes: smart (context-aware, showing relative or absolute depending on distance from now), absolute (via Intl.DateTimeFormat), and relative (via Intl.RelativeTimeFormat). It supports any Intl locale out of the box, requires no locale files or plugins, and ships TypeScript types. Current stable version is 0.3.1. It is actively maintained (as of mid-2025) and is more lightweight than libraries like dayjs or date-fns while focusing specifically on human-readable output. Key differentiators: single function with intelligent defaults, SSR-safe with custom `now` and `timeZone` options, and no dependencies.
npm install anywhenNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates smart, absolute, and relative modes with various locales and SSR-safe options.
Use named import: `import { anywhen } from 'anywhen'`Ensure input is valid: new Date(), Date.now(), or '2025-06-15T10:00:00.000Z'
Polyfill Intl.RelativeTimeFormat or use a fallback library for older browsers
Set `time: false` to hide clock: `anywhen(date, { time: false })`Verify Intl support for the desired locale; or use a locale polyfill
Replace `import anywhen from 'anywhen'` with `import { anywhen } from 'anywhen'`Ensure input is a Date, number (milliseconds), or ISO 8601 string. Use `new Date('2025-06-15T10:00:00Z')` instead of non-standard formats.Use a valid IANA time zone name like 'America/New_York' or 'Europe/London'. Check Intl.supportedValuesOf('timeZone').No dependency data recorded yet.