1 | import { setup } from '../setup/internal'
|
2 |
|
3 | import { USERNAME_BLOCKLIST } from './blocklist'
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export async function isUsernameAvailable(
|
9 | username: string
|
10 | ): Promise<boolean> {
|
11 | const resp = await fetch(`${setup.endpoints.api}/user/data/${username}`)
|
12 | return !resp.ok
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export function isUsernameValid(username: string): boolean {
|
19 | return !username.startsWith("-") &&
|
20 | !username.endsWith("-") &&
|
21 | !username.startsWith("_") &&
|
22 | /^[a-zA-Z0-9_-]+$/.test(username) &&
|
23 | !USERNAME_BLOCKLIST.includes(username.toLowerCase())
|
24 | }
|