From af44cac699b0591eba908db3835c4e5792303095 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Mon, 22 Jan 2024 15:16:04 +0000 Subject: Refactors getFirstQueryParam to separate file --- api/_getFirstQueryParam.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 api/_getFirstQueryParam.ts (limited to 'api/_getFirstQueryParam.ts') diff --git a/api/_getFirstQueryParam.ts b/api/_getFirstQueryParam.ts new file mode 100644 index 0000000..2073e7a --- /dev/null +++ b/api/_getFirstQueryParam.ts @@ -0,0 +1,13 @@ +import type { VercelRequest } from '@vercel/node'; + +export function getFirstQueryParam(key: string, query: VercelRequest['query']): string | null { + const value = query[key]; + if (!value) { + return null; + } + if (typeof(value) === 'string') { + return value; + } + return value[0] as string; +} + -- cgit v1.2.3