From 6b9122357cd799b26185e9699e3c51df59d60ba6 Mon Sep 17 00:00:00 2001 From: Kevin Fawcett Date: Thu, 22 Feb 2024 16:01:20 -0500 Subject: [PATCH] refactor: replacing protocol lookup with ternary --- packages/access-token-jwt/src/fetch.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/access-token-jwt/src/fetch.ts b/packages/access-token-jwt/src/fetch.ts index 4c03a8e..d60fea4 100644 --- a/packages/access-token-jwt/src/fetch.ts +++ b/packages/access-token-jwt/src/fetch.ts @@ -2,7 +2,7 @@ import { URL } from 'url'; import { Agent as HttpAgent, get as getHttp } from 'http'; import { Agent as HttpsAgent, get as getHttps } from 'https'; import { once } from 'events'; -import type { ClientRequest, IncomingMessage } from 'http'; +import type { IncomingMessage } from 'http'; import { TextDecoder } from 'util'; const decoder = new TextDecoder(); @@ -18,13 +18,6 @@ const concat = (...buffers: Uint8Array[]): Uint8Array => { return buf; }; -const protocols: { - [protocol: string]: (...args: Parameters) => ClientRequest; -} = { - 'https:': getHttps, - 'http:': getHttp, -}; - export interface FetchOptions { agent?: HttpAgent | HttpsAgent; timeoutDuration?: number; @@ -34,7 +27,9 @@ const fetch = async ( url: URL, { agent, timeoutDuration: timeout }: FetchOptions ): Promise => { - const req = protocols[url.protocol](url.href, { + const get = url.protocol === 'https:' ? getHttps : getHttp; + + const req = get(url.href, { agent, timeout, });