Skip to content

yanaemon/moment-to-dayjs-codemod

Repository files navigation

moment-to-dayjs-codemod

A jscodeshift tranformer for migrating moment to dayjs.

How to use

$ 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

Supported dayjs plugins

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published