chore: team url slugify and profanity filter

Signed-off-by: Adithya Krishna <adi@documenso.com>
This commit is contained in:
Adithya Krishna
2023-12-27 18:57:38 +05:30
parent d546907c53
commit 39869c46a3
4 changed files with 73 additions and 4 deletions

View File

@ -0,0 +1,25 @@
const diacriticRegex = /\p{Diacritic}/gu;
const nonAlphanumericRegex = /[^.\p{L}\p{N}\p{Zs}\p{Emoji}]+/gu;
const whitespaceUnderscoreRegex = /[\s_#]+/g;
const dashStartRegex = /^-+/;
const multipleDotsRegex = /\.{2,}/g;
export const generateURLSlug = (str: string, forDisplayingInput?: boolean) => {
if (!str) {
return '';
}
const slug = str
.toLowerCase()
.trim()
.normalize('NFD')
.replace(diacriticRegex, '')
.replace(nonAlphanumericRegex, '-')
.replace(whitespaceUnderscoreRegex, '-')
.replace(dashStartRegex, '') // Remove dashes from start
.replace(multipleDotsRegex, '.'); // Replace consecutive periods with a single period
return forDisplayingInput ? slug : slug.replace(/-*$/g, ''); // Remove dashes from end
};
export default generateURLSlug;