(
obj:
| undefined
| Record<string, string | string[] | number | number[] | boolean | boolean[] | undefined>
)
| 2 | import { fromZodError } from "zod-validation-error"; |
| 3 | |
| 4 | export function objectToSearchParams( |
| 5 | obj: |
| 6 | | undefined |
| 7 | | Record<string, string | string[] | number | number[] | boolean | boolean[] | undefined> |
| 8 | ): URLSearchParams | undefined { |
| 9 | if (!obj) return undefined; |
| 10 | |
| 11 | const searchParams = new URLSearchParams(); |
| 12 | //for each item add to the search params, skip undefined and join arrays with commas |
| 13 | Object.entries(obj).forEach(([key, value]) => { |
| 14 | if (value === undefined) return; |
| 15 | if (Array.isArray(value)) { |
| 16 | searchParams.append(key, value.join(",")); |
| 17 | } else { |
| 18 | searchParams.append(key, value.toString()); |
| 19 | } |
| 20 | }); |
| 21 | |
| 22 | return searchParams; |
| 23 | } |
| 24 | |
| 25 | class SearchParams<TParams extends ParamType> { |
| 26 | constructor(private params: TParams, readonly schema: ZodType<TParams>) {} |
no test coverage detected
searching dependent graphs…