first commit
This commit is contained in:
16
frontend/hooks/useSlug.ts
Normal file
16
frontend/hooks/useSlug.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useCallback } from 'react';
|
||||
|
||||
export const useSlug = () => {
|
||||
const slugify = useCallback((text: string) => {
|
||||
return text
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/\s+/g, '-') // Replace spaces with -
|
||||
.replace(/&/g, '-and-') // Replace & with 'and'
|
||||
.replace(/[^\w-]+/g, '') // Remove all non-word chars
|
||||
.replace(/--+/g, '-'); // Replace multiple - with single -
|
||||
}, []);
|
||||
|
||||
return { slugify };
|
||||
};
|
||||
Reference in New Issue
Block a user