mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-26 02:21:06 -04:00
* Test * Add pretty formatting * Fix Tests * Fix Tests * Fix Tests * Fix * Add pretty formatting fix * Fix * Test * Fix tests * Clean typeckech * Add prettier check * Fix api tsconfig * Fix api tsconfig * Fix tsconfig * Fix * Fix * Prettier
13 lines
550 B
TypeScript
13 lines
550 B
TypeScript
export const slugify = (text: string, separator = '-', maxLength = 35): string => {
|
|
return text
|
|
.toString()
|
|
.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)
|
|
.substring(0, maxLength)
|
|
.replace(new RegExp(separator + '+$', 'g'), '') // remove terminal separators
|
|
}
|