Skip to content

Instantly share code, notes, and snippets.

@stekhn
Created October 2, 2023 13:42
Show Gist options
  • Save stekhn/ce0a0f7fc258523800cf33b1f7ea44a9 to your computer and use it in GitHub Desktop.
Save stekhn/ce0a0f7fc258523800cf33b1f7ea44a9 to your computer and use it in GitHub Desktop.
Convert a string like a headline to a slug than can be used in a URL. German umlauts get transcribed.
const slugify = (string) =>
string
.trim()
.toLowerCase()
.replace(/\s+/g, "-")
.replace(/ä/g, "ae")
.replace(/ö/g, "oe")
.replace(/ü/g, "ue")
.replace(/\u00df/g, "ss")
.replace(/[^a-z0-9-]/g, "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment