moment-to-dayjs-codemod
v0.0.1
Published
Transforms JS/TS files from moment to dayjs
Downloads
8
Maintainers
Readme
moment-to-dayjs-codemod
A jscodeshift tranformer for migrating moment to dayjs.
How to use
$ npm install -g jscodeshift
$ git clone https://github.com/yanaemon/moment-to-dayjs-codemod.git
$ jscodeshift -t transform.ts --parser tsx path/to/file.ts
Supported dayjs plugins
- [x] arraySupport
- [x] isBetween
- [x] isSameOrAfter
- [x] isSameOrBefore
- [x] isoWeek
- [x] minMax
- [x] objectSupport
- [ ] updateLocale
- [x] utc
- [x] weekday
Warning
This lib cannot detect and don't replace below case. Please check whether there is no such a case.
destructive use
Because moment.js is mutable but dayjs is immutable.
ex.
for (const d = moment(); d.add(1, 'date'); d++) {
console.log(d.toDate());
}
variable assign
ex.
const d = moment();
// error unless you use objectSupport plugin
console.log(d.add({ date: 1 }).toDate());
I recommend to use ObjectSupport plugin
Test
$ yarn jest