UNPKG

594 BJavaScriptView Raw
1module.exports = {
2 parse: function (string) {
3 var params = {}
4
5 string.split('&').forEach(function (component) {
6 var split = component.split('=')
7 if (split[1]) {
8 params[decodeURIComponent(split[0])] = decodeURIComponent(split[1])
9 }
10 })
11
12 return params
13 },
14
15 stringify: function (params) {
16 return Object.keys(params)
17 .filter(function (key) {
18 return typeof (params[key]) !== 'undefined'
19 })
20 .map(function (key) {
21 return encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
22 })
23 .join('&')
24 }
25}