diff options
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; +} + |
