Files
goGin/frontend/hooks/useSlug.ts
Beyhan Oğur 2a5b661443 first commit
2026-04-26 21:46:42 +03:00

17 lines
518 B
TypeScript

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 };
};