# Convert to kebab-case

> Converts each line to kebab-case, splitting words at spaces, hyphens, underscores and case changes

Version: 1.0.0 · By Deck

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

Or install with Terminal: 

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

## Script

```js
// Converts each line to kebab-case, splitting words at spaces, hyphens, underscores, other punctuation and case changes.
function words(line) {
  const result = [];
  const runs = line.replace(/['\u2019]/g, "").match(/[\p{L}\p{M}\p{N}]+/gu) ?? [];
  for (const run of runs) {
    const spaced = run.replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, "$1 $2").replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu, "$1 $2");
    for (const word of spaced.split(" ")) result.push(word.toLowerCase());
  }
  return result;
}

// A line without letters or digits stays as it is.
function convert(line) {
  const list = words(line);
  return list.length === 0 ? line : list.join("-");
}

function transform(input) {
  return String(input ?? "").split(/(\r\n|\r|\n)/).map((part, k) => (k % 2 === 0 ? convert(part) : part)).join("");
}
```

---

- HTML: https://deckclip.app/plugins/to-kebab-case
- 中文: https://deckclip.app/zh-cn/plugins/to-kebab-case.md

© 2026 Yuze Pan
