UNPKG

owtlab-tracking

Version:
17 lines (14 loc) 495 B
module.exports = parseParams; function parseParams(str) { // via: http://stackoverflow.com/a/2880929/2511985 const urlParams = {}; let match; const pl = /\+/g; // Regex for replacing addition symbol with a space const search = /([^&=]+)=?([^&]*)/g; const decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')); }; const query = str.split('?')[1]; while (match = search.exec(query)) { urlParams[decode(match[1])] = decode(match[2]); } return urlParams; }