Last active
April 15, 2017 20:52
-
-
Save aeinbu/c78996dd5a51ac4fbd2f 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
define([], function () { | |
"use strict"; | |
function parse(querystring) { | |
var obj = {}; | |
if (querystring) { | |
var params = querystring.split(/&|\?/); | |
for (var i = 0; i < params.length; i++) { | |
var param = params[i]; | |
var paramParts = param.split('='); | |
if (paramParts.length == 2) { | |
var name = paramParts[0]; | |
var value = paramParts[1]; | |
obj[name] = value; | |
} | |
} | |
} | |
return obj; | |
} | |
function format(obj) { | |
var count = 0; | |
var querystring = ''; | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
if (count++) { | |
querystring += '&'; | |
} | |
querystring += key + '=' + obj[key].toString(); | |
} | |
} | |
return querystring; | |
} | |
return { | |
parse: parse, | |
format: format | |
}; | |
}); |
Author
aeinbu
commented
Aug 14, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment