MCPcopy
hub / github.com/ionic-team/capacitor / buildUrlParams

Function buildUrlParams

core/src/core-plugins.ts:321–347  ·  view source on GitHub ↗
(params?: HttpParams, shouldEncode = true)

Source from the content-addressed store, hash-verified

319 * @param shouldEncode true if you should encodeURIComponent() the values (true by default)
320 */
321const buildUrlParams = (params?: HttpParams, shouldEncode = true): string | null => {
322 if (!params) return null;
323
324 const output = Object.entries(params).reduce((accumulator, entry) => {
325 const [key, value] = entry;
326
327 let encodedValue: string;
328 let item: string;
329 if (Array.isArray(value)) {
330 item = '';
331 value.forEach((str) => {
332 encodedValue = shouldEncode ? encodeURIComponent(str) : str;
333 item += `${key}=${encodedValue}&`;
334 });
335 // last character will always be "&" so slice it off
336 item.slice(0, -1);
337 } else {
338 encodedValue = shouldEncode ? encodeURIComponent(value) : value;
339 item = `${key}=${encodedValue}`;
340 }
341
342 return `${accumulator}&${item}`;
343 }, '');
344
345 // Remove initial "&" from the reduce
346 return output.substr(1);
347};
348
349/**
350 * Build the RequestInit object based on the options passed into the initial request

Callers 1

requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected