mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-27 02:44:26 +01:00
16 lines
499 B
TypeScript
16 lines
499 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("&")
|
|
);
|
|
}
|