Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions codemods/abort-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Abort Controller Codemod

## Introduction

This codemod removes the unnecessary import of the `abort-controller` npm module, ensuring that the codebase relies on built-in browser functionality where applicable. This helps to decrease bundle size and improve performance by eliminating unused dependencies.

### Before

```javascript
import AbortController from 'abort-controller';

const controller = new AbortController();
const signal = controller.signal;
```

### After

```javascript
const controller = new AbortController();
const signal = controller.signal;
```
21 changes: 21 additions & 0 deletions codemods/array-buffer-byte-length/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# array-buffer-byte-length Codemod

## Introduction

This codemod replaces the use of the `array-buffer-byte-length` library with the native `byteLength` property of `ArrayBuffer` instances. This transformation helps reduce dependencies and enhances performance by leveraging built-in JavaScript features.

### Before

```ts
import arrayBufferByteLength from 'array-buffer-byte-length';

const buffer = new ArrayBuffer(10);
const length = arrayBufferByteLength(buffer);
```

### After

```ts
const buffer = new ArrayBuffer(10);
const length = buffer.byteLength;
```
19 changes: 19 additions & 0 deletions codemods/array-every/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Array Every Codemod

## Introduction

This codemod transforms usages of the custom `array-every` method into the built-in `Array.prototype.every` method. This change reduces dependency on unnecessary custom utilities by leveraging native JavaScript functionality, leading to cleaner code and potentially better performance.

### Before

```javascript
import { arrayEvery } from 'array-utils';

const allAdults = arrayEvery(users, user => user.age >= 18);
```

### After

```javascript
const allAdults = users.every(user => user.age >= 18);
```
19 changes: 19 additions & 0 deletions codemods/array-includes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Array Includes Codemod

## Introduction

This codemod replaces instances of the `array-includes` library with the built-in `Array.prototype.includes` method. This transformation reduces unnecessary dependencies by leveraging native JavaScript features, thereby optimizing the codebase and potentially improving performance.

### Before

```javascript
import arrayIncludes from 'array-includes';

const exists = arrayIncludes([1, 2, 3], 2);
```

### After

```javascript
const exists = [1, 2, 3].includes(2);
```
19 changes: 19 additions & 0 deletions codemods/array-map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Array Map Codemod

## Introduction

This codemod transforms instances of using custom `array-map` utility functions into native JavaScript `Array.prototype.map` methods. The goal is to reduce dependency on external libraries, improve performance by utilizing built-in functionality, and streamline the codebase.

### Before

```javascript
import { arrayMap } from 'array-map';

const result = arrayMap(array, item => item * 2);
```

### After

```javascript
const result = array.map(item => item * 2);
```
19 changes: 19 additions & 0 deletions codemods/array.from/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Codemod: Replace `Array.from` Import with Built-in ES Feature

## Introduction

This codemod transforms instances of `array.from` by replacing them with the built-in `Array.from` method. This helps to eliminate the dependency on the `array.from` package, reducing bundle size and improving performance by utilizing native JavaScript functionality.

### Before

```javascript
import array from 'array.from';

const result = array.from(someIterable);
```

### After

```javascript
const result = Array.from(someIterable);
```
19 changes: 19 additions & 0 deletions codemods/array.of/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Array.of Codemod

## Introduction

This codemod replaces instances of the `array.of` npm package with the built-in `Array.of` method. By doing this, it eliminates an unnecessary dependency, thereby reducing the bundle size and improving the performance of the codebase.

### Before

```javascript
import array from 'array.of';

const arr = array(1, 2, 3);
```

### After

```javascript
const arr = Array.of(1, 2, 3);
```
21 changes: 21 additions & 0 deletions codemods/array.prototype.at/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# array.prototype.at Codemod

## Introduction

This codemod replaces instances of the deprecated or inefficient usage of `array.prototype.at` with the native `Array.prototype.at` method. The goal is to leverage built-in ES features, thereby reducing unnecessary dependencies, and improving performance and code clarity.

### Before

```javascript
import { at } from 'some-array-library';

const firstElement = at(myArray, 0);
const lastElement = at(myArray, -1);
```

### After

```javascript
const firstElement = myArray.at(0);
const lastElement = myArray.at(-1);
```
21 changes: 21 additions & 0 deletions codemods/array.prototype.concat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Array.prototype.concat Codemod

## Introduction

This codemod optimizes the usage of the `Array.prototype.concat` method by transforming its usage into a more efficient syntax. This helps to reduce redundancy and improve performance within the codebase.

### Before

```javascript
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const combined = array1.concat(array2);
```

### After

```javascript
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const combined = [...array1, ...array2];
```
19 changes: 19 additions & 0 deletions codemods/array.prototype.copywithin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Array.prototype.copyWithin Codemod

## Introduction

This codemod replaces the usage of the `Array.prototype.copyWithin` method with the `copyWithin` method without the need for the `Array` prototype. It aims to streamline the code by ensuring that the native method is used directly, which can enhance performance and reduce unnecessary abstraction.

### Before

```javascript
const array = [1, 2, 3, 4, 5];
array.copyWithin(0, 3); // This is using the prototype method
```

### After

```javascript
const array = [1, 2, 3, 4, 5];
array.copyWithin(0, 3); // This is using the native method, directly through the array
```
21 changes: 21 additions & 0 deletions codemods/array.prototype.entries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Codemod: Replace `array.prototype.entries` with Built-in Method

## Introduction

This codemod replaces the usage of the `array.prototype.entries` function with the built-in `entries` method directly on arrays. By utilizing native methods, we can reduce unnecessary dependencies, improve performance, and simplify the codebase.

### Before

```javascript
import arrayProtoEntries from 'array.prototype.entries';

const arr = [1, 2, 3];
const entries = arrayProtoEntries(arr);
```

### After

```javascript
const arr = [1, 2, 3];
const entries = arr.entries();
```
17 changes: 17 additions & 0 deletions codemods/array.prototype.every/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Array.prototype.every Codemod

## Introduction

This codemod replaces calls to the `Array.prototype.every` method found in existing code with a more optimized and performant alternative. The goal is to enhance performance by using native array methods instead of custom implementations or other less efficient approaches.

### Before

```javascript
const isAllPositive = myArray.every((num) => num > 0);
```

### After

```javascript
const isAllPositive = myArray.filter((num) => num <= 0).length === 0;
```
17 changes: 17 additions & 0 deletions codemods/array.prototype.filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# array.prototype.filter Codemod

## Introduction

This codemod transforms usages of the `Array.prototype.filter` method to utilize a more optimized or standardized approach. It helps in reducing unnecessary code and improving performance by ensuring that the built-in `filter` method is used effectively.

### Before

```javascript
const result = array.filter(item => item.active);
```

### After

```javascript
const result = array.filter(item => item.active);
```
26 changes: 26 additions & 0 deletions codemods/array.prototype.find/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Array.prototype.find Codemod

## Introduction

This codemod replaces instances of using a custom implementation to find elements in an array with the built-in `Array.prototype.find` method. By utilizing native JavaScript features, it reduces unnecessary dependencies and improves the performance and readability of the codebase.

### Before

```javascript
const findElement = (array, predicate) => {
for (let i = 0; i < array.length; i++) {
if (predicate(array[i])) {
return array[i];
}
}
return undefined;
};

const result = findElement(myArray, element => element.id === 1);
```

### After

```javascript
const result = myArray.find(element => element.id === 1);
```
17 changes: 17 additions & 0 deletions codemods/array.prototype.findindex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# array.prototype.findindex Codemod

## Introduction

This codemod replaces instances of `array.prototype.findindex` with the built-in `Array.prototype.findIndex` method. By making this change, we eliminate the need for an external dependency, which helps reduce bundle size and improves performance.

### Before

```javascript
const index = array.prototype.findindex(array, element);
```

### After

```javascript
const index = array.findIndex(element);
```
17 changes: 17 additions & 0 deletions codemods/array.prototype.findlast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Array.prototype.findLast Codemod

## Introduction

This codemod replaces instances of `Array.prototype.findlast` with the built-in `findLast` method, which offers a more efficient and modern solution for finding the last element in an array that satisfies a given condition. This change reduces reliance on custom implementations and enhances code readability.

### Before

```javascript
const result = array.findlast(item => item.active);
```

### After

```javascript
const result = array.findLast(item => item.active);
```
21 changes: 21 additions & 0 deletions codemods/array.prototype.findlastindex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Array Prototype Find Last Index Codemod

## Introduction

This codemod transforms the usage of the `Array.prototype.findLastIndex` method to its more efficient counterpart, ensuring consistent coding practices and potentially reducing bundle size by leveraging built-in ES features instead of polyfills or outdated methods.

### Before

```javascript
const array = [1, 2, 3, 4, 5];

const lastIndex = array.findLastIndex(element => element === 3);
```

### After

```javascript
const array = [1, 2, 3, 4, 5];

const lastIndex = array.findLastIndex(element => element === 3);
```
17 changes: 17 additions & 0 deletions codemods/array.prototype.flat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Array.prototype.flat Codemod

## Introduction

This codemod replaces instances of the `Array.prototype.flatten` method with the native `Array.prototype.flat` method. The goal is to utilize built-in JavaScript features, reducing dependencies and improving performance in the codebase.

### Before

```javascript
const flattenedArray = array.flatten();
```

### After

```javascript
const flattenedArray = array.flat();
```
Loading