const parser = 'babel'
function transformer (file, api) {
const j = api.jscodeshift;
const root = j(file.source);
return root.find(j.Identifier)
.forEach(path => {
// find declaration for "moment" identifier
if (path.node.name === 'moment') {
j(path).replaceWith(
j.identifier('dayjs')
);
}
})
.toSource();
}
module.exports = transformer
module.exports.parser = parser
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter