@E18e/Hasown

1.0.5Last update Aug 9, 2024
by@e18e

hasown Codemod

Introduction

This codemod replaces the use of the hasown function from an external package with the built-in Object.hasOwn method in JavaScript. This transformation reduces the number of dependencies in the codebase while improving performance by utilizing a native feature.

Before

import hasown from 'hasown';
const obj = { key: 'value' };
if (hasown(obj, 'key')) {
console.log('Key exists!');
}

After

const obj = { key: 'value' };
if (Object.hasOwn(obj, 'key')) {
console.log('Key exists!');
}

Build custom codemods

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

background illustrationGet Started Now