MCPcopy Index your code
hub / github.com/Kong/insomnia / buildQueryParameter

Function buildQueryParameter

packages/insomnia/src/utils/url/querystring.ts:60–87  ·  view source on GitHub ↗
(
  param: { name?: string; value?: string | number },

  /** allow empty names and values */
  strict?: boolean,
)

Source from the content-addressed store, hash-verified

58 * Build a querystring parameter from a param object
59 */
60export const buildQueryParameter = (
61 param: { name?: string; value?: string | number },
62
63 /** allow empty names and values */
64 strict?: boolean,
65) => {
66 strict = strict === undefined ? true : strict;
67
68 // Skip non-name ones in strict mode
69 if (strict && !param.name) {
70 return '';
71 }
72
73 // Cast number values to strings
74 if (typeof param.value === 'number') {
75 param.value = String(param.value);
76 }
77
78 if (!strict || param.value) {
79 // Don't encode ',' in values
80 const value = flexibleEncodeComponent(param.value || '').replace(/%2C/gi, ',');
81 const name = flexibleEncodeComponent(param.name || '');
82
83 return `${name}=${value}`;
84 } else {
85 return flexibleEncodeComponent(param.name);
86 }
87};
88
89/**
90 * Build a querystring from a list of name/value pairs

Callers 2

Calls 1

flexibleEncodeComponentFunction · 0.85

Tested by

no test coverage detected