# Sort Lines Alphabetically

> Sorts lines from A to Z, ignoring case and accents

Version: 1.0.0 · By Deck

- Install in Deck: deck://install-plugin?id=sort-lines&url=https%3A%2F%2Fgithub.com%2Fyuzeguitarist%2Fdeck-plugins%2Freleases%2Fdownload%2Fplugins%2Fsort-lines-1.0.0.zip
- Download .zip: https://github.com/yuzeguitarist/deck-plugins/releases/download/plugins/sort-lines-1.0.0.zip
- View on GitHub: https://github.com/yuzeguitarist/deck-plugins/tree/main/plugins/sort-lines

Or install with Terminal: 

```sh
mkdir -p ~/.deck/scripts/sort-lines && curl -fsSL https://github.com/yuzeguitarist/deck-plugins/releases/download/plugins/sort-lines-1.0.0.zip | tar -xf - -C ~/.deck/scripts/sort-lines
```

## Script

```js
// Sorts the lines from A to Z, ignoring case and accents. Lines that compare equal keep their order.
function transform(input) {
  const text = String(input ?? "").replace(/\r\n?/g, "\n");
  if (text === "") return "";
  const end = text.endsWith("\n") ? "\n" : "";
  const lines = (end ? text.slice(0, -1) : text).split("\n");
  // NFD splits accents off their letters so they can be dropped. Comparing code units instead of using
  // locale rules gives the same order in every JavaScript engine.
  const keys = lines.map((line) => line.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase());
  const order = lines.map((line, index) => index);
  order.sort((a, b) => (keys[a] < keys[b] ? -1 : keys[a] > keys[b] ? 1 : a - b));
  return order.map((index) => lines[index]).join("\n") + end;
}
```

---

- HTML: https://deckclip.app/plugins/sort-lines
- 中文: https://deckclip.app/zh-cn/plugins/sort-lines.md

© 2026 Yuze Pan
