All checks were successful
continuous-integration/drone/push Build is passing
30 lines
638 B
TypeScript
30 lines
638 B
TypeScript
type BuildListQueryOptions = {
|
|
q?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
sort?: string;
|
|
defaultSort: string;
|
|
};
|
|
|
|
export function buildListQuery({
|
|
q,
|
|
page = 1,
|
|
pageSize = 10,
|
|
sort,
|
|
defaultSort,
|
|
}: BuildListQueryOptions): string {
|
|
const query = new URLSearchParams();
|
|
const normalizedQuery = q?.trim();
|
|
const normalizedSort = sort?.trim();
|
|
|
|
if (normalizedQuery) {
|
|
query.set('q', normalizedQuery);
|
|
}
|
|
|
|
query.set('page', String(page));
|
|
query.set('pageSize', String(pageSize));
|
|
query.set('sort', normalizedSort || defaultSort);
|
|
|
|
return query.toString();
|
|
}
|