mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-16 21:15:28 -04:00
38 lines
792 B
TypeScript
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;
|