@E18e/Clone Regexp

1.0.5Last update Aug 9, 2024
by@e18e

Clone RegExp Codemod

Introduction

This codemod removes the use of the clone-regexp npm module by replacing its functionality with the built-in RegExp constructor. This helps to reduce unnecessary dependencies and improve the performance of the codebase.

Before

import cloneRegexp from 'clone-regexp';
const originalRegex = /test/gi;
const clonedRegex = cloneRegexp(originalRegex, { flag: 'i' });

After

const originalRegex = /test/gi;
const clonedRegex = new RegExp(originalRegex.source, originalRegex.flags);

Note: If options were being passed to clone-regexp, please modify the new regular expression accordingly, as indicated by the warning in the console.

Build custom codemods

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

background illustrationGet Started Now