MCPcopy Create free account
hub / github.com/nodejs/node / normalizeSearchParams

Function normalizeSearchParams

deps/undici/src/lib/mock/mock-utils.js:96–125  ·  view source on GitHub ↗
(query)

Source from the content-addressed store, hash-verified

94}
95
96function normalizeSearchParams (query) {
97 if (typeof query !== 'string') {
98 return query
99 }
100
101 const originalQp = new URLSearchParams(query)
102 const normalizedQp = new URLSearchParams()
103
104 for (let [key, value] of originalQp.entries()) {
105 key = key.replace('[]', '')
106
107 const valueRepresentsString = /^(['"]).*\1$/.test(value)
108 if (valueRepresentsString) {
109 normalizedQp.append(key, value)
110 continue
111 }
112
113 if (value.includes(',')) {
114 const values = value.split(',')
115 for (const v of values) {
116 normalizedQp.append(key, v)
117 }
118 continue
119 }
120
121 normalizedQp.append(key, value)
122 }
123
124 return normalizedQp
125}
126
127function safeUrl (path) {
128 if (typeof path !== 'string') {

Callers 1

dispatchMethod · 0.85

Calls 5

entriesMethod · 0.95
appendMethod · 0.95
includesMethod · 0.80
testMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected