mirror of
https://github.com/DerTyp7/explainegy-nextjs.git
synced 2025-10-29 12:52:13 +01:00
cherry
This commit is contained in:
16
utils.ts
Normal file
16
utils.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user