Quick answer: normalise the text, strip accent marks, lowercase it, replace everything that is not a letter or digit with one hyphen, and trim the ends. The function below does that and handles the awkward cases. If you only need a slug once, paste your title into the Slug Generator .
The function
const SPECIAL = { "ß" : "ss" , "æ" : "ae" , "œ" : "oe" , "ø" : "o" , "đ" : "d" , "ł" : "l" } ;
function slugify ( input , { separator = "-" , maxLength = 60 } = { } ) { const sep = separator ; let s = String ( input ?? "" ) . normalize ( "NFKD" ) // split letters from accents: e-acute -> e + accent mark . replace ( / [ \ u0300 - \ u036f ] / g , "" ) // drop the accent marks . replace ( / [ ßæœøđł ] / gi , ( c ) => SPECIAL [ c . toLowerCase ( ) ] ) . replace ( /&/ g , " and " ) . toLowerCase ( ) . replace ( / [ ^ a - z0 - 9 ] +/ g , sep ) // anything else becomes one separator . replace ( new RegExp ( `^${sep}+|${sep}+$` , "g" ) , "" ) ; // trim separators if ( s . length > maxLength ) { s = s .…