Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78645fc

Browse files
committed
refactor: move fail to outer scope, rename to failOriginParam
1 parent 7ca7d79 commit 78645fc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export interface AccessControlOptions {
1414

1515
const isIterable = (obj: unknown): obj is Iterable<unknown> => typeof obj[Symbol.iterator] === 'function'
1616

17-
const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response) => void) => {
18-
const fail = () => {
19-
throw new TypeError('No other objects allowed. Allowed types is array of strings or RegExp')
20-
}
17+
const failOriginParam = () => {
18+
throw new TypeError('No other objects allowed. Allowed types is array of strings or RegExp')
19+
}
2120

21+
const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response) => void) => {
2222
if (typeof origin === 'boolean') {
2323
return origin
2424
? (_, res) => {
@@ -40,11 +40,11 @@ const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response)
4040
}
4141
}
4242

43-
if (typeof origin !== 'object') fail()
43+
if (typeof origin !== 'object') failOriginParam()
4444

4545
if (isIterable(origin)) {
4646
const originArray = Array.from(origin)
47-
if (originArray.some((element) => typeof element !== 'string')) fail()
47+
if (originArray.some((element) => typeof element !== 'string')) failOriginParam()
4848

4949
const originSet = new Set(origin)
5050

@@ -71,7 +71,7 @@ const getOriginHeaderHandler = (origin: unknown): ((req: Request, res: Response)
7171
}
7272
}
7373

74-
fail()
74+
failOriginParam()
7575
}
7676

7777
/**

0 commit comments

Comments
 (0)