diff --git a/scripts/core/proxyParser.ts b/scripts/core/proxyParser.ts new file mode 100644 index 00000000..244290d5 --- /dev/null +++ b/scripts/core/proxyParser.ts @@ -0,0 +1,27 @@ +import { URL } from 'node:url' + +type ProxyParserResult = { + protocol: string | null + auth: { + username: string | null + password: string | null + } + host: string + port: number | null +} + +export class ProxyParser { + parse(_url: string): ProxyParserResult { + const parsed = new URL(_url) + + return { + protocol: parsed.protocol.replace(':', '') || null, + auth: { + username: parsed.username || null, + password: parsed.password || null + }, + host: parsed.hostname, + port: parsed.port ? parseInt(parsed.port) : null + } + } +}