@doranjs/codemod
v0.1.0
Published
jscodeshift codemod that rewrites moment / moment-jalaali to @doranjs/core.
Maintainers
Readme
@doranjs/codemod
A jscodeshift codemod that rewrites moment / moment-jalaali to @doranjs/core. Anything it can't safely convert is reported, never silently changed.
npx @doranjs/codemod "src/**/*.{ts,tsx}"
npx @doranjs/codemod src --dry --print # preview without writingAny extra flags pass straight through to jscodeshift.
What it does
| Before | After |
| ------------------------------------------ | ------------------------------------------- |
| import moment from 'moment-jalaali' | import { DoranDate } from '@doranjs/core' |
| moment() | DoranDate.now() |
| moment(x) | DoranDate.fromGregorian(new Date(x)) |
| .format('jYYYY/jMM/jDD') | .format('YYYY/MM/DD') |
| .format('YYYY-MM-DD') (Gregorian) | .formatGregorian('YYYY-MM-DD') |
| .utc().format() / .format() | .toISOString() |
| moment.loadPersian() | (removed) |
| .fromNow() / .diff() / .isBefore() … | kept 1:1 on the rewritten value |
What it flags (manual review)
moment(value, format)— a calendar parse, not a 1:1 instant. UseparseJalali(value, format)/parse(...)from@doranjs/core.moment.duration(...)— useDuration/durationToHumanfrom@doranjs/core..format(<dynamic>)— a non-literal pattern (jalali vs Gregorian tokens differ).
Doran is immutable.
momentmutates in place;d.add(...)returns a new value. Review chained mutations after running the codemod.
See the migration guide for the full parity table and the eslint-plugin-doran rule that keeps moment from creeping back.
