@E18e/Has

1.0.5Last update Aug 9, 2024
by@e18e

Replace has with Object.hasOwn

Introduction

This codemod replaces the usage of the has utility from external libraries with the built-in Object.hasOwn method. This transformation reduces the number of dependencies in your codebase and utilizes native JavaScript features for better performance and smaller bundle size.

Before

import { has } from 'lodash';
const obj = { key: 'value' };
if (has(obj, 'key')) {
console.log('The key exists.');
}

After

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

Build custom codemods

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

background illustrationGet Started Now