правильная true/false сериализация для request

This commit is contained in:
SleepWalker 2016-02-27 12:58:29 +02:00
parent e44360a20b
commit 7e7a31a672

View File

@ -1,8 +1,22 @@
function convertQueryValue(value) {
if (typeof value === 'undefined') {
return '';
}
if (value === true) {
return 1;
}
if (value === false) {
return 0;
}
}
function buildQuery(data) { function buildQuery(data) {
return Object.keys(data) return Object.keys(data)
.map( .map(
(keyName) => (keyName) =>
[keyName, typeof data[keyName] === 'undefined' ? '' : data[keyName]] [keyName, convertQueryValue(data[keyName])]
.map(encodeURIComponent) .map(encodeURIComponent)
.join('=') .join('=')
) )