Skip to content

Instantly share code, notes, and snippets.

@censuradho
Created February 2, 2023 17:58
Show Gist options
  • Save censuradho/6b32a280294f14d0b32f3f26b4d3855e to your computer and use it in GitHub Desktop.
Save censuradho/6b32a280294f14d0b32f3f26b4d3855e to your computer and use it in GitHub Desktop.
a slug functon generator
export const slugify = (...args: (string | number)[]): string => {
const value = args.join(' ')
return value
.normalize('NFD') // split an accented letter in the base letter and the acent
.replace(/[\u0300-\u036f]/g, '') // remove all previously split accents
.toLowerCase()
.trim()
.replace(/[^a-z0-9 ]/g, '') // remove all chars not letters, numbers and spaces (to be replaced)
.replace(/\s+/g, '-') // separator
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment