Files
order_site/apps/frontend/src/utils/douyu-role-name.ts
T

25 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const DOUYU_ROLE_NAME_FORMAT_HINT =
'只填写游戏角色名,不要填写 UID、区服或微信/QQ;登录方式和设备系统请在上方选择。'
export const DOUYU_ROLE_NAME_MIXED_WARNING =
'这里只能填写游戏角色名。检测到 UID、区服或登录方式,请只保留角色名称,例如“花乔妖精”。'
const ROLE_NAME_SEPARATOR = /[\s,,、|/\\·::;;_-]+/u
const STANDALONE_UID = /^\d{6,}$/u
const LONG_NUMBER = /\d{8,}/u
const STANDALONE_LOGIN_OR_SYSTEM = /^(?:安卓区?|苹果区?|ios|android|微信|qq|q区|v区|手q)$/iu
export function getDouyuRoleNameIssue(value: string): string | null {
const roleName = String(value ?? '').trim()
if (!roleName) return null
const tokens = roleName.split(ROLE_NAME_SEPARATOR).filter(Boolean)
const hasStandaloneUid = tokens.some((token) => STANDALONE_UID.test(token))
const hasLongNumber = LONG_NUMBER.test(roleName)
const hasStandaloneLoginOrSystem = tokens.some((token) => STANDALONE_LOGIN_OR_SYSTEM.test(token))
return hasStandaloneUid || hasLongNumber || hasStandaloneLoginOrSystem
? DOUYU_ROLE_NAME_MIXED_WARNING
: null
}