MCPcopy Index your code
hub / github.com/code100x/cms / searchParamsToObject

Function searchParamsToObject

src/lib/utils.ts:216–236  ·  view source on GitHub ↗
(
  searchParams: URLSearchParams,
)

Source from the content-addressed store, hash-verified

214};
215
216export 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
238export const paginationData = (searchParams: QueryParams) => {
239 const pageNumber = parseInt((searchParams.page || 1).toString(), 10);

Callers 3

SearchFunction · 0.90
NewPostDialogFunction · 0.90
PaginationFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected