Files
epg/scripts/core/proxyParser.ts

32 lines
740 B
TypeScript
Raw Normal View History

2025-01-24 20:01:57 +03:00
import { URL } from 'node:url'
type ProxyParserResult = {
protocol: string | null
2025-07-17 17:43:00 +03:00
auth?: {
username?: string
password?: string
2025-01-24 20:01:57 +03:00
}
host: string
port: number | null
}
export class ProxyParser {
parse(_url: string): ProxyParserResult {
const parsed = new URL(_url)
2025-07-17 17:43:00 +03:00
const result: ProxyParserResult = {
2025-01-24 20:01:57 +03:00
protocol: parsed.protocol.replace(':', '') || null,
host: parsed.hostname,
port: parsed.port ? parseInt(parsed.port) : null
}
2025-07-17 17:43:00 +03:00
if (parsed.username || parsed.password) {
result.auth = {}
if (parsed.username) result.auth.username = parsed.username
if (parsed.password) result.auth.password = parsed.password
}
return result
2025-01-24 20:01:57 +03:00
}
}