The fns-to-temporal transform converts several patterns from the temporal-polyfill/fns API to standard Temporal syntax:
Constructors and Methods
Function calls are converted into constructors or instance methods:
// Before
import * as PlainDateFns from 'temporal-polyfill/fns/PlainDate'
const date = PlainDateFns.create(2024, 5, 1)
const next = PlainDateFns.addDays(date, 3)
// After
const date = new Temporal.PlainDate(2024, 5, 1)
const next = date.add({ days: 3 })
Calendar Records to IDs
Calendar record objects are converted to string IDs where Temporal expects a string:
// Before
PlainDateFns.create(2024, 5, 1, CalendarFns.getBuddhist())
// After
new Temporal.PlainDate(2024, 5, 1, 'buddhist')
Types and Type Guards
- Types: Record and option types are rewritten to their
Temporal equivalents (e.g., PlainDateRecord becomes Temporal.PlainDate). If no direct equivalent exists, it falls back to temporal-utils. - Type Guards:
isRecord checks are converted to instanceof checks:
// Before
if (PlainDateFns.isRecord(value)) { /* ... */ }
// After
if (value instanceof Temporal.PlainDate) { /* ... */ }
Note on temporal-utils
If a function has no direct Temporal equivalent, the codemod rewrites it to use temporal-utils. The codemod will print a note for you to add this dependency to your package.json, but it will not edit your package.json automatically.