Jscodeshift installation step-by step

PHOTO EMBED

Mon Mar 28 2022 11:23:03 GMT+0000 (Coordinated Universal Time)

Saved by @GoodRequest. #javascript

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
content_copyCOPY