fix: include slug helpers
This commit is contained in:
parent
ecad81b0ea
commit
4951e82834
1 changed files with 17 additions and 0 deletions
17
src/lib/slug.ts
Normal file
17
src/lib/slug.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
export function slugify(value: string): string {
|
||||||
|
const ascii = value
|
||||||
|
.normalize("NFD")
|
||||||
|
.replace(/[\u0300-\u036f]/g, "")
|
||||||
|
.replace(/[\u2013\u2014]/g, "-")
|
||||||
|
const sanitized = ascii.replace(/[^a-zA-Z0-9\s-]/g, "")
|
||||||
|
const hyphenized = sanitized.replace(/[_\s]+/g, "-").replace(/-+/g, "-")
|
||||||
|
return hyphenized.replace(/^-+|-+$/g, "").toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeSlug(input?: string | null): string | undefined {
|
||||||
|
if (!input) return undefined
|
||||||
|
const trimmed = input.trim()
|
||||||
|
if (!trimmed) return undefined
|
||||||
|
const slug = slugify(trimmed)
|
||||||
|
return slug || undefined
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue