UNPKG

642 BPlain TextView Raw
1import { setup } from '../setup/internal'
2
3import { USERNAME_BLOCKLIST } from './blocklist'
4
5/**
6 * Check if a username is available.
7 */
8export 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 * Check if a username is valid.
17 */
18export 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}