Skip to content

moment-lessTemporal API formatting

Moment.js token syntax for the native Temporal API. Zero dependencies. < 2KB gzipped.

Quick Look

ts
import { format, fromNow, calendar, humanizeDuration, fromDate } from 'moment-less'

// Token-based formatting — any Temporal type
const dt = Temporal.PlainDateTime.from('2026-04-09T14:05:00')
format(dt, 'MMMM Do, YYYY [at] h:mm A')
// → "April 9th, 2026 at 2:05 PM"

// Relative time — measured against an Instant
const now = Temporal.Instant.from('2026-04-09T14:00:00Z')
fromNow(now.subtract({ hours: 3 }), now)
// → "3 hours ago"

// Calendar label — measured against a PlainDate
calendar(dt, Temporal.PlainDate.from('2026-04-09'))
// → "Today at 2:05 PM"

// Duration humanization
humanizeDuration(Temporal.Duration.from({ hours: 2, minutes: 45 }))
// → "3 hours"

// Bridge from a legacy Date
format(fromDate(new Date('2026-04-09T14:05:00Z')), 'YYYY-MM-DD[T]HH:mm:ssZ')
// → "2026-04-09T14:05:00+00:00"

Released under the MIT License.