https://github.com/leodevbro/sort-to-tosorted
Codemod to convert `[...array].sort()` into `array.toSorted()` (ES2023)
https://github.com/leodevbro/sort-to-tosorted
Last synced: 2 days ago
JSON representation
Codemod to convert `[...array].sort()` into `array.toSorted()` (ES2023)
- Host: GitHub
- URL: https://github.com/leodevbro/sort-to-tosorted
- Owner: leodevbro
- Created: 2026-05-25T07:25:42.000Z (25 days ago)
- Default Branch: main
- Last Pushed: 2026-05-25T09:09:56.000Z (25 days ago)
- Last Synced: 2026-05-25T10:19:29.793Z (25 days ago)
- Language: TypeScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sort-to-tosorted
Codemod to convert `[...array].sort()` into `array.toSorted()` (ES2023)
## Run the script directly from the Codemod Registry
```bash
npx codemod@latest sort-to-tosorted
```
## Examples
Before:
```ts
const a = [...items].sort();
const b = [...getItems()].sort((x, y) => x - y);
const c = [...arr].sort(compareFn);
const keep = [...a, b].sort();
const keep2 = items.sort();
```
After:
```ts
const a = items.toSorted();
const b = getItems().toSorted((x, y) => x - y);
const c = arr.toSorted(compareFn);
const keep = [...a, b].sort();
const keep2 = items.sort();
```
## Installation
```bash
# Install from registry
codemod run sort-to-tosorted
# Or run locally
codemod run -w workflow.yaml
```
## Usage
Document the exact migration this codemod performs before publishing. At minimum, cover:
- The concrete syntax or API patterns it rewrites
- The file types or paths it targets
- Important preserve/no-op cases and exclusions
## Development
```bash
# Test the transformation
npm test
# Validate the workflow
codemod workflow validate -w workflow.yaml
# Publish to registry
codemod login
codemod publish
```
## License
MIT