diff --git a/src/shared/lib/utils/buildQueryString/buildQueryString.ts b/src/shared/lib/utils/buildQueryString/buildQueryString.ts index 7c4817c..79cb5b3 100644 --- a/src/shared/lib/utils/buildQueryString/buildQueryString.ts +++ b/src/shared/lib/utils/buildQueryString/buildQueryString.ts @@ -7,7 +7,7 @@ * @example * ```ts * buildQueryString({ category: 'serif', subsets: ['latin', 'latin-ext'] }) - * // Returns: "?category=serif&subsets=latin%2Clatin-ext" + * // Returns: "?category=serif&subsets=latin&subsets=latin-ext" * * buildQueryString({ limit: 50, page: 1 }) * // Returns: "?limit=50&page=1" @@ -16,7 +16,7 @@ * // Returns: "" * * buildQueryString({ search: 'hello world', active: true }) - * // Returns: "?search=hello%20world&active=true" + * // Returns: "?search=hello+world&active=true" * ``` */ @@ -35,7 +35,7 @@ export type QueryParams = Record; * * Handles: * - Primitive values (string, number, boolean) - converted to strings - * - Arrays - comma-separated values + * - Arrays - multiple parameters with same key (e.g., ?key=1&key=2&key=3) * - null/undefined - omitted from output * - Special characters - URL encoded * @@ -51,14 +51,12 @@ export function buildQueryString(params: QueryParams): string { continue; } - // Handle arrays (comma-separated values) + // Handle arrays - append each item as separate parameter with same key if (Array.isArray(value)) { - const joined = value - .filter(item => item !== undefined && item !== null) - .map(String) - .join(','); - if (joined) { - searchParams.append(key, joined); + for (const item of value) { + if (item !== undefined && item !== null) { + searchParams.append(key, String(item)); + } } } else { // Handle primitives