diff options
| author | Joe Carstairs <jcarstairs@scottlogic.com> | 2024-01-22 15:16:04 +0000 |
|---|---|---|
| committer | Joe Carstairs <jcarstairs@scottlogic.com> | 2024-01-29 10:51:49 +0000 |
| commit | af44cac699b0591eba908db3835c4e5792303095 (patch) | |
| tree | 412ba0f2b4aabdb67023e1ffca895ffc2a750dd3 /api/_getFirstQueryParam.ts | |
| parent | 2ed34859b6d90bffe7c2c6b39668b1dace41c292 (diff) | |
Refactors getFirstQueryParam to separate file
Diffstat (limited to 'api/_getFirstQueryParam.ts')
| -rw-r--r-- | api/_getFirstQueryParam.ts | 13 |
1 files changed, 13 insertions, 0 deletions
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; +} + |
