From e02e46562a8e4ace1ee6d44c76fb7d00ba830f29 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Fri, 24 Jan 2025 20:01:57 +0300 Subject: [PATCH] Create proxyParser.ts --- scripts/core/proxyParser.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/core/proxyParser.ts 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 + } + } +}