forked from cory/tildefriends
Cory McWilliams
2d8a956c14
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3904 ed5197a5-7fde-0310-b194-c3ffbd925b24
34 lines
726 B
JavaScript
34 lines
726 B
JavaScript
function decode(encoded) {
|
|
var result = "";
|
|
for (var i = 0; i < encoded.length; i++) {
|
|
var c = encoded[i];
|
|
if (c == "+") {
|
|
result += " ";
|
|
} else if (c == "%") {
|
|
result += String.fromCharCode(parseInt(encoded.slice(i + 1, i + 3), 16));
|
|
i += 2;
|
|
} else {
|
|
result += c;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function decodeForm(encoded, initial) {
|
|
var result = initial || {};
|
|
if (encoded) {
|
|
encoded = encoded.trim();
|
|
var items = encoded.split('&');
|
|
for (var i = 0; i < items.length; i++) {
|
|
var item = items[i];
|
|
var equals = item.indexOf('=');
|
|
var key = decode(item.slice(0, equals));
|
|
var value = decode(item.slice(equals + 1));
|
|
result[key] = value;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export { decodeForm };
|