(line)
| 17 | * @returns {{ email: string, password: string, proxy: string|null } | null} 解析失败返回 null |
| 18 | */ |
| 19 | const parseAccountLine = (line) => { |
| 20 | if (typeof line !== 'string') return null |
| 21 | const trimmed = line.trim() |
| 22 | if (!trimmed) return null |
| 23 | |
| 24 | // 先按第一个 '|' 切出可选 proxy(proxy 部分自身可能含有 '|',例如 query 参数极少见,这里按首个分隔) |
| 25 | const pipeIdx = trimmed.indexOf('|') |
| 26 | const credentials = pipeIdx === -1 ? trimmed : trimmed.slice(0, pipeIdx) |
| 27 | const proxyRaw = pipeIdx === -1 ? '' : trimmed.slice(pipeIdx + 1) |
| 28 | const proxy = proxyRaw.trim() || null |
| 29 | |
| 30 | // credentials 部分按第一个 ':' 切分,保留密码中可能存在的 ':' |
| 31 | const colonIdx = credentials.indexOf(':') |
| 32 | if (colonIdx === -1) return null |
| 33 | |
| 34 | const email = credentials.slice(0, colonIdx).trim() |
| 35 | const password = credentials.slice(colonIdx + 1).trim() |
| 36 | |
| 37 | if (!email || !password) return null |
| 38 | |
| 39 | return { email, password, proxy } |
| 40 | } |
| 41 | |
| 42 | module.exports = { |
| 43 | parseAccountLine |
no outgoing calls
no test coverage detected