Fix the username formatter returning invalid formatName

'?' is not accepted character in OpenAI api as a valid name
I also switched the order of the replace steps,
so there will be less _- in the final username
This commit is contained in:
Wroclaw 2023-03-18 03:27:44 +01:00
parent 276d70efee
commit d5cb03502f

View file

@ -40,12 +40,12 @@ function formatName(name: string): string {
return FoldToAscii.foldReplacing(name)
// White spaces are not allowed
.replace(" ", "_")
// replace characters that are not accepted by api with '_'
.replace(/[^a-zA-Z0-9_-]/g, "_")
// remove trailing '-_' characters
.replace(/^[-_]+|[-_]+$/g, "")
// remove duplicated '-_' characters
.replace(/([-_])*/g, "")
// replace characters that are not accepted by api with '?'
.replace(/[^a-zA-Z0-9_-]/g, "?");
.replace(/([-_])*/g, "$1");
}
/**