# Trim Trailing Newlines

> Removes the line breaks at the end of the text

Version: 1.0.0 · By Deck

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

Or install with Terminal: 

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

## Script

```js
// Removes the line breaks at the end of the text. Line breaks inside the text are kept.
function transform(input) {
  const text = String(input ?? "");
  let end = text.length;
  while (end > 0 && (text[end - 1] === "\n" || text[end - 1] === "\r")) {
    end -= 1;
  }
  return text.slice(0, end);
}
```

---

- HTML: https://deckclip.app/plugins/trim-trailing-newlines
- 中文: https://deckclip.app/zh-cn/plugins/trim-trailing-newlines.md

© 2026 Yuze Pan
