blob: 6c18bb61119bcfaea8bc6b15606dd5956b0b49c7 [file] [log] [blame]
svishnevea5e43c2018-04-15 09:06:57 +03001export default function objectPropsToUrlString(data) {
2 let str = '';
3 Object.keys(data).map(key => {
4 if (typeof data[key] === 'object') {
5 let obj = data[key];
6 let arr = [];
7
8 Object.keys(obj).map(prop => {
9 if (obj[prop]) {
10 arr.push(encodeURIComponent(prop));
11 }
12 });
13 if (arr.length) {
14 str += `&${encodeURIComponent(key)}=${arr.join(',')}`;
15 }
16 } else if (data[key]) {
17 str += `&${encodeURIComponent(key)}=${encodeURIComponent(
18 data[key]
19 )}`;
20 }
21 });
22 return str;
23}