-
-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathquerystring.js
More file actions
34 lines (26 loc) · 666 Bytes
/
querystring.js
File metadata and controls
34 lines (26 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function parseQueryString(queryString) {
const queryParams = {};
if (queryString.length === 0) {
return queryParams;
}
const keyValuePairs = queryString.split("&");
for (const pair of keyValuePairs) {
if (pair === "") {
continue;
}
const indexOfEquals = pair.indexOf("=");
let key;
let value;
if (indexOfEquals === -1) {
// no "=", treat whole pair as key with empty value
key = pair;
value = "";
} else {
key = pair.slice(0, indexOfEquals);
value = pair.slice(indexOfEquals + 1);
}
queryParams[key] = value;
}
return queryParams;
}
module.exports = parseQueryString;