Convert article titles into URL slugs: lower case, words joined by single hyphens, no punctuation and no hyphens at the ends.
const slugify = (title) =>
title
.toLowerCase()
.trim()
.replace(/[^a-z0-9\s-]/g, "") // drop punctuation
.replace(/[\s-]+/g, "-"); // spaces and repeated hyphens → one hyphen
console.log(slugify(" 10 JavaScript Tips & Tricks! "));
console.log(slugify("What's New in ES2026?"));
console.log(slugify("Node.js -- the Complete Guide"));
10-javascript-tips-tricks whats-new-in-es2026 nodejs-the-complete-guide
Punctuation is removed first (so "&" and "." disappear), then every run of spaces or hyphens becomes a single hyphen.