-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convert utility function and update imports
- Loading branch information
1 parent
299422a
commit 47c8eec
Showing
3 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type Filter = { [key: string]: string | string[] }; | ||
|
||
export function ensureArrayValues<T = Filter>(filters: Filter): T { | ||
const result: Filter = {}; | ||
|
||
for (const key in filters) { | ||
if (Array.isArray(filters[key])) { | ||
result[key] = filters[key]; // If it's already an array, keep it as is | ||
} else { | ||
result[key] = [filters[key] as string]; // Convert string value to array | ||
} | ||
} | ||
|
||
return result as T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { ReadonlyURLSearchParams } from "next/navigation"; | ||
import queryString from "query-string"; | ||
|
||
export const getQueries = (searchParams: ReadonlyURLSearchParams) => | ||
export const getQueries = ( | ||
searchParams: ReadonlyURLSearchParams | ||
): Record<string, any> => | ||
queryString.parse(searchParams.toString(), { arrayFormat: "comma" }); | ||
|
||
export const buildQuery = (queries: Record<string, string | string[]>) => | ||
queryString.stringify(queries, { arrayFormat: "comma" }); |