Skip to content

Commit

Permalink
Merge pull request #187 from rafis/master
Browse files Browse the repository at this point in the history
Add support for Dates to stringify, also improve stringify Object and Array
  • Loading branch information
tomas authored Feb 7, 2017
2 parents 65e2b96 + b7f05ee commit 76f95b0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/querystring.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// based on the qs module, but handles null objects as expected
// fixes by Tomas Pollak.

var toString = Object.prototype.toString;

function stringify(obj, prefix) {
if (prefix && (obj === null || typeof obj == 'undefined')) {
return prefix + '=';
} else if (obj.constructor == Array) {
} else if (toString.call(obj) == '[object Array]') {
return stringifyArray(obj, prefix);
} else if (obj !== null && typeof obj == 'object') {
} else if (toString.call(obj) == '[object Object]') {
return stringifyObject(obj, prefix);
} else if (toString.call(obj) == '[object Date]') {
return obj.toISOString();
} else if (prefix) { // string inside array or hash
return prefix + '=' + encodeURIComponent(String(obj));
} else if (String(obj).indexOf('=') !== -1) { // string with equal sign
Expand Down

0 comments on commit 76f95b0

Please sign in to comment.