CoastalCommitsPastes/client/lib/server/parse-query-param.ts
2022-11-09 23:11:36 -08:00

13 lines
358 B
TypeScript

/*
* Parses a URL query string from string | string[] | ...
* to string | undefined. If it's an array, we return the last item.
*/
export function parseQueryParam(query: string | string[] | undefined) {
if (typeof query === "string") {
return query
} else if (Array.isArray(query)) {
return query[query.length - 1]
} else {
return undefined
}
}