Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Typescript slug function
// ref: https://gist.github.com/codeguy/6684588#gistcomment-3426313
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
}
@andreasnuesslein
Copy link

andreasnuesslein commented Mar 16, 2021

😍

@shabith
Copy link

shabith commented Apr 26, 2021

Thanks for sharing this!

@bernardomontoya
Copy link

bernardomontoya commented Jul 28, 2021

Looks beautiful! 😍

@hellhoundsx
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