Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Typescript slug function
// ref:
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
.replace(/[^a-z0-9 ]/g, '') // remove all chars not letters, numbers and spaces (to be replaced)
.replace(/\s+/g, '-') // separator
Copy link

andreasnuesslein commented Mar 16, 2021


Copy link

shabith commented Apr 26, 2021

Thanks for sharing this!

Copy link

bernardomontoya commented Jul 28, 2021

Looks beautiful! 😍

Copy link

hellhoundsx commented Nov 16, 2021

This is amazing man! Helped me greatly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment