Codemod Registry
Explore community-led codemods to migrate, optimize, and transform your codebase.
Ready to contribute?
Build your own codemod and share it with the community.
Explore community-led codemods to migrate, optimize, and transform your codebase.
Build your own codemod and share it with the community.
Explore community-led codemods to migrate, optimize, and transform your codebase.
# String.prototype.trim Codemod ## Introduction This codemod replaces uses of the `String.prototype.trim` method from a polyfill or external library with the built-in ES feature. By utilizing the native implementation, it helps reduce unnecessary dependencies and improves both the performance and maintainability of the codebase. ### Before ```javascript import trim from 'string.prototype.trim'; const cleanString = trim(someString); ``` ### After ```javascript const cleanString = someString.trim(); ```
# number.prototype.toexponential Codemod ## Introduction This codemod removes the import statement for `number.prototype.toexponential`, which is an unnecessary dependency in the codebase. By utilizing built-in JavaScript functionalities instead, this codemod helps to decrease bundle size and improve code performance. ### Before ```javascript import 'number.prototype.toexponential'; const num = 5; const expNum = num.toExponential(2); ``` ### After ```javascript const num = 5; const expNum = num.toExponential(2); ```
# data-view-byte-length Codemod ## Introduction This codemod replaces instances of the `data-view-byte-length` package with the built-in `DataView.byteLength` property. The goal is to eliminate unnecessary dependencies, thereby reducing the bundle size and improving the performance of the codebase. ### Before ```javascript import byteLength from 'data-view-byte-length'; const buffer = new ArrayBuffer(8); const view = new DataView(buffer); const length = byteLength(view); ``` ### After ```javascript const buffer = new ArrayBuffer(8); const view = new DataView(buffer); const length = view.byteLength; ```
# Object.getPrototypeOf Codemod ## Introduction This codemod replaces the use of the `object.getprototypeof` npm module with the built-in `Object.getPrototypeOf` method. This change helps to eliminate unnecessary dependencies, reducing the bundle size and improving the performance of the codebase. ### Before ```javascript import object from 'object.getprototypeof'; const proto = object.getPrototypeOf(someObject); ``` ### After ```javascript const proto = Object.getPrototypeOf(someObject); ```
# String.prototype.padLeft Codemod ## Introduction This codemod replaces uses of the `String.prototype.padLeft` method with the built-in `String.prototype.padStart` method. The goal is to eliminate the reliance on the less common `padLeft` method, reducing unnecessary dependencies and simplifying the codebase. ### Before ```javascript const paddedString = myString.padLeft(5, '0'); ``` ### After ```javascript const paddedString = myString.padStart(5, '0'); ```
# Reflect.getPrototypeOf Codemod ## Introduction This codemod replaces calls to the `reflect.getprototypeof` module with the built-in `Reflect.getPrototypeOf` function. This change helps to eliminate an unnecessary dependency, thereby reducing bundle size and improving code performance. ### Before ```javascript import reflect from 'reflect.getprototypeof'; const proto = reflect.getprototypeof(obj); ``` ### After ```javascript const proto = Reflect.getPrototypeOf(obj); ```
# Codemod for Replacing `string.prototype.matchall` ## Introduction This codemod replaces calls to the `string.prototype.matchall` npm package with the built-in `String.prototype.matchAll` method. The goal is to eliminate the dependency on the `string.prototype.matchall` package, thereby reducing bundle size and enhancing performance. ### Before ```javascript import matchAll from 'string.prototype.matchall'; const result = matchAll("test string", /test/g); ``` ### After ```javascript const result = "test string".matchAll(/test/g); ```
# Replace `for-each` with `Array.prototype.forEach` ## Introduction This codemod replaces the usage of the `for-each` npm package with the built-in `Array.prototype.forEach` method. The goal is to minimize dependencies and utilize native JavaScript functions, ultimately improving performance and reducing bundle size. ### Before ```javascript import forEach from 'for-each'; forEach(array, (item) => { console.log(item); }); ``` ### After ```javascript array.forEach((item) => { console.log(item); }); ```
# Array.prototype.with Codemod ## Introduction This codemod replaces instances of `array.prototype.with` with the native JavaScript `with` method. This transformation helps to streamline array operations by utilizing built-in functionalities, reducing the need for external libraries, and ultimately improving the codebase's performance and reduce its bundle size. ### Before ```javascript const myArray = [1, 2, 3]; const newArray = myArray.with(1, 4); // Using array.prototype.with ``` ### After ```javascript const myArray = [1, 2, 3]; const newArray = myArray.with(1, 4); // This is now a native method ```
# Array.prototype.splice Codemod ## Introduction This codemod replaces usages of the `array.prototype.splice` package with native JavaScript's built-in `Array.prototype.splice` method. By eliminating the dependency on the external package, it reduces bundle size and enhances performance. ### Before ```javascript import splice from 'array.prototype.splice'; const myArray = [1, 2, 3]; splice(myArray, 1, 1, 4); // Removes 2 and adds 4 ``` ### After ```javascript const myArray = [1, 2, 3]; myArray.splice(1, 1, 4); // Removes 2 and adds 4 ```
# es-string-html-methods Codemod ## Introduction This codemod replaces usage of deprecated string HTML methods from the `es-string-html-methods` package with their corresponding member method calls directly on string instances. By doing this, it eliminates unnecessary imports and reduces dependencies, thereby optimizing bundle size and performance. ### Before ```javascript import { blink, bold } from 'es-string-html-methods'; const str1 = blink('foo'); const str2 = bold('bar'); ``` ### After ```javascript const str1 = 'foo'.blink(); const str2 = 'bar'.bold(); ```
# String.prototype.split Codemod ## Introduction This codemod replaces the use of the `split` method from external libraries with the built-in `String.prototype.split` method. This improves performance by reducing unnecessary dependencies, thereby minimizing the bundle size and enhancing the overall efficiency of the codebase. ### Before ```javascript import split from 'some-string-split-library'; const result = split('apple,banana,cherry', ','); ``` ### After ```javascript const result = 'apple,banana,cherry'.split(','); ```
Build your own codemod and share it with the community.