MCPcopy Index your code
hub / github.com/nodejs/node / parseParams

Function parseParams

lib/internal/url.js:1259–1354  ·  view source on GitHub ↗
(qs)

Source from the content-addressed store, hash-verified

1257// application/x-www-form-urlencoded parser
1258// Ref: https://url.spec.whatwg.org/#concept-urlencoded-parser
1259function parseParams(qs) {
1260 const out = [];
1261 let seenSep = false;
1262 let buf = '';
1263 let encoded = false;
1264 let encodeCheck = 0;
1265 let i = qs[0] === '?' ? 1 : 0;
1266 let pairStart = i;
1267 let lastPos = i;
1268 for (; i < qs.length; ++i) {
1269 const code = StringPrototypeCharCodeAt(qs, i);
1270
1271 // Try matching key/value pair separator
1272 if (code === CHAR_AMPERSAND) {
1273 if (pairStart === i) {
1274 // We saw an empty substring between pair separators
1275 lastPos = pairStart = i + 1;
1276 continue;
1277 }
1278
1279 if (lastPos < i)
1280 buf += qs.slice(lastPos, i);
1281 if (encoded)
1282 buf = querystring.unescape(buf);
1283 out.push(buf);
1284
1285 // If `buf` is the key, add an empty value.
1286 if (!seenSep)
1287 out.push('');
1288
1289 seenSep = false;
1290 buf = '';
1291 encoded = false;
1292 encodeCheck = 0;
1293 lastPos = pairStart = i + 1;
1294 continue;
1295 }
1296
1297 // Try matching key/value separator (e.g. '=') if we haven't already
1298 if (!seenSep && code === CHAR_EQUAL) {
1299 // Key/value separator match!
1300 if (lastPos < i)
1301 buf += qs.slice(lastPos, i);
1302 if (encoded)
1303 buf = querystring.unescape(buf);
1304 out.push(buf);
1305
1306 seenSep = true;
1307 buf = '';
1308 encoded = false;
1309 encodeCheck = 0;
1310 lastPos = i + 1;
1311 continue;
1312 }
1313
1314 // Handle + and percent decoding.
1315 if (code === CHAR_PLUS) {
1316 if (lastPos < i)

Callers 2

URLSearchParamsClass · 0.85
constructorMethod · 0.85

Calls 3

sliceMethod · 0.65
unescapeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…