CoastalCommitsPastes/client/lib/server/parse-query-param.ts

14 lines
358 B
TypeScript
Raw Normal View History

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