mirror of
				https://github.com/DerTyp7/explainegy-nextjs.git
				synced 2025-10-29 21:02:13 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			17 lines
		
	
	
		
			478 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			17 lines
		
	
	
		
			478 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { isValidName } from "./validators";
 | |
| export function formatTextToUrlName(text: string): string {
 | |
|   text = text.toLowerCase();
 | |
|   let name = text;
 | |
| 
 | |
|   name = name.replace(/[^a-z0-9\-_\s]+/gi, ""); // Replace all invalid characters (except spaces)
 | |
|   name = name.replace(/\s/g, "-"); // Replace spaces to -
 | |
| 
 | |
|   // double check to be sure
 | |
|   if (isValidName(name)) {
 | |
|     return name;
 | |
|   } else {
 | |
|     console.error("formatTitleToName function not working");
 | |
|     return null;
 | |
|   }
 | |
| }
 | 
