Last active
February 23, 2016 17:46
-
-
Save rolfen/16e1b6501f06f73b8330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parses a GET-style query string into a key/value object | |
* example: | |
* decodeQueryString("?sdf=ABC&xyz=jj%C3%BC"); | |
* Object {sdf: "ABC", xyz: "jjü"} | |
* | |
* @param {String} s The query string | |
*/ | |
function decodeQueryString(s) { | |
var decoded = {}; | |
var parts = s.replace(/^[?/]*/,'').split('&'); | |
parts.forEach(function(part){ | |
var pair = part.split('='); | |
var key = pair[0]; | |
var value = pair[1]; | |
decoded[key] = decodeURIComponent(value); | |
}); | |
return(decoded); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function safeStringify(o) { | |
// JSON stringify that does not break on circular references | |
// http://stackoverflow.com/a/11616993/370786 | |
var cache = []; | |
var ret = JSON.stringify(o, function(key, value) { | |
if (typeof value === 'object' && value !== null) { | |
if (cache.indexOf(value) !== -1) { | |
// Circular reference found, discard key | |
return; | |
} | |
// Store value in our collection | |
cache.push(value); | |
} | |
return value; | |
}, "\t"); | |
return ret; | |
// cache = null; // Enable garbage collection | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment