Slugify a string

PHOTO EMBED

Tue Aug 09 2022 19:29:48 GMT+0000 (Coordinated Universal Time)

Saved by @johnnye562 #javascript

const slugify = (text) => {
  if (!(typeof text === "string" || text instanceof String)) {
    console.error(`string expected, ${typeof str} provided`)
    return str
  }
  return text.toLowerCase()
    .replace(/ /g, "-")
    .replace(/[^\w-]+/g, "")
}

slugify("Hello, everyone!") // hello-everyone
content_copyCOPY

https://justacoding.blog/9-useful-javascript-utility-functions/