From 78645fcdf7149a1f29519d07c91b3f894ea4d705 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:22:30 +0100 Subject: [PATCH] refactor: move `fail` to outer scope, rename to `failOriginParam` --- src/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2575240..4511206 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,11 +14,11 @@ export interface AccessControlOptions { const isIterable = (obj: unknown): obj is Iterable => typeof obj[Symbol.iterator] === 'function' -const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response) => void) => { - const fail = () => { - throw new TypeError('No other objects allowed. Allowed types is array of strings or RegExp') - } +const failOriginParam = () => { + throw new TypeError('No other objects allowed. Allowed types is array of strings or RegExp') +} +const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response) => void) => { if (typeof origin === 'boolean') { return origin ? (_, res) => { @@ -40,11 +40,11 @@ const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response) } } - if (typeof origin !== 'object') fail() + if (typeof origin !== 'object') failOriginParam() if (isIterable(origin)) { const originArray = Array.from(origin) - if (originArray.some((element) => typeof element !== 'string')) fail() + if (originArray.some((element) => typeof element !== 'string')) failOriginParam() const originSet = new Set(origin) @@ -71,7 +71,7 @@ const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response) } } - fail() + failOriginParam() } /**