Fastify/5/Req Params HasOwnProperty To ObjectHasOwn

/icons/calendar.svg

Last update

Sep 17, 2024

This codemod turns req.params.hasOwnProperty('name') into Object.hasOwn(req.params, 'name'), reflecting the new Fastify v5 approach to property checking.

Before

fastify.get('/route/:name', (req, reply) => {
console.log(req.params.hasOwnProperty('name')); // true
return { hello: req.params.name };
});

After

fastify.get('/route/:name', (req, reply) => {
console.log(Object.hasOwn(req.params, 'name')); // true
return { hello: req.params.name };
});

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now