From 295cf50060145ac881f6f86da5455c0407a2870f Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:41:46 -0600 Subject: [PATCH] feat: add slug function --- lib/slug.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/slug.ts diff --git a/lib/slug.ts b/lib/slug.ts new file mode 100644 index 00000000..a4982a0e --- /dev/null +++ b/lib/slug.ts @@ -0,0 +1,15 @@ +import slug from "slugify"; + +export const slugify = (text: string | undefined) => { + if (!text) { + return ""; + } + + const cleanedText = text.trim().replace(/[^a-zA-Z0-9\s]/g, ""); + + return slug(cleanedText, { + lower: true, + trim: true, + strict: true, + }); +};