Files
mutiny-web/src/utils/objectToSearchParams.ts
2023-04-11 18:12:26 -05:00

7 lines
391 B
TypeScript

export function objectToSearchParams<T extends Record<string, string | undefined>>(obj: T): string {
return Object.entries(obj)
.filter(([_, value]) => value !== undefined)
// Value shouldn't be null we just filtered it out but typescript is dumb
.map(([key, value]) => value ? `${encodeURIComponent(key)}=${encodeURIComponent(value)}` : "")
.join("&");
}