Skip to content

Commit 43f0f90

Browse files
committed
Added csv column query string
1 parent 327e977 commit 43f0f90

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ QueryString.prototype.stringify = function (params, options) {
2222
// Iterate through the parameters object that was passed to the method
2323
for (let key in params) {
2424
if (params.hasOwnProperty(key)) {
25-
// Add the URI encoded key and value to the array separated by an equals
26-
queryStringArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]))
25+
// If the element is an array then loop through it
26+
if (Array.isArray(params[key]) === true) {
27+
queryStringArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key].join(',')));
28+
} else {
29+
// Add the URI encoded key and value to the array separated by an equals
30+
queryStringArray.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
31+
}
2732
}
2833
}
2934

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('query-stringifier', function () {
2626
};
2727
var queryString = qs.stringify(test3);
2828

29-
expect(queryString).to.equal('column=a,b,c&anotherCol=2');
29+
expect(queryString).to.equal('column=' + encodeURIComponent('a,b,c') + '&anotherCol=2');
3030
});
3131
});
3232

0 commit comments

Comments
 (0)