1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-16 21:15:28 -04:00
Files
Sonarr/frontend/src/Utilities/Fetch/getQueryString.ts
2025-03-08 12:33:03 -08:00

38 lines
792 B
TypeScript

import { PropertyFilter } from 'App/State/AppState';
export interface QueryParams {
[key: string]: string | number | boolean | PropertyFilter[] | undefined;
}
const getQueryString = (queryParams?: QueryParams) => {
if (!queryParams) {
return '';
}
const filteredParams = Object.keys(queryParams).reduce<
Record<string, string>
>((acc, key) => {
const value = queryParams[key];
if (value == null) {
return acc;
}
if (Array.isArray(value)) {
value.forEach((filter) => {
acc[filter.key] = String(filter.value);
});
} else {
acc[key] = String(value);
}
return acc;
}, {});
const paramsString = new URLSearchParams(filteredParams).toString();
return `?${paramsString}`;
};
export default getQueryString;