( searchParams: URLSearchParams, )
| 214 | }; |
| 215 | |
| 216 | export const searchParamsToObject = ( |
| 217 | searchParams: URLSearchParams, |
| 218 | ): Record<string, string | string[]> => { |
| 219 | const obj: Record<string, string | string[]> = {}; |
| 220 | searchParams.forEach((value, key) => { |
| 221 | // If the key already exists, transform into an array or push to existing array |
| 222 | // todo remove eslint-disable |
| 223 | // eslint-disable-next-line no-prototype-builtins |
| 224 | if (obj.hasOwnProperty(key)) { |
| 225 | if (Array.isArray(obj[key])) { |
| 226 | (obj[key] as string[]).push(value); |
| 227 | } else { |
| 228 | obj[key] = [obj[key] as string, value]; |
| 229 | } |
| 230 | } else { |
| 231 | // Add the key-value pair |
| 232 | obj[key] = value; |
| 233 | } |
| 234 | }); |
| 235 | return obj; |
| 236 | }; |
| 237 | |
| 238 | export const paginationData = (searchParams: QueryParams) => { |
| 239 | const pageNumber = parseInt((searchParams.page || 1).toString(), 10); |
no outgoing calls
no test coverage detected