Text sluify javascript

const slugify = (string) => {
  const newText = string
    .toLowerCase()
    .replace(/ /g, "-")
    .replace(/[^\w-]+/g, "");
  
  return newText
};

console.log(slugify("Hello world"))
//hello-world
mrmalik610