A jscodeshift tranformer for migrating moment to dayjs.
$ npm install -g jscodeshift moment-to-dayjs-codemod
# dry run
$ jscodeshift -t node_modules/moment-to-dayjs-codemod/transform.js -d -p path/to/file.ts
# exec
$ jscodeshift -t node_modules/moment-to-dayjs-codemod/transform.js path/to/file.ts
local use
$ git clone https://github.com/yanaemon/moment-to-dayjs-codemod.git
$ cd moment-to-dayjs-codemod
$ npm install
# dry run
$ npm run-script transform -- -d -p path/to/file.ts
# exec
$ npm run-script transform -- path/to/file.ts
- arraySupport
- duration
- isBetween
- isSameOrAfter
- isSameOrBefore
- isoWeek
- minMax
- objectSupport
- relativeTime
- updateLocale
- utc
- weekday
This lib cannot detect and don't replace below case. Please check whether there is no such a case.
Because moment.js is mutable but dayjs is immutable.
ex.
for (const d = moment(); d.add(1, 'date'); d++) {
console.log(d.toDate());
}
ex.
const d = moment();
// error unless you use objectSupport plugin
console.log(d.add({ date: 1 }).toDate());
I recommend to use ObjectSupport plugin
$ yarn jest