Skip to content

Instantly share code, notes, and snippets.

@srdjan
Forked from yoshuawuyts/qs.js
Created July 21, 2016 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srdjan/ef0bc06630c630ee68307d34cbff3c74 to your computer and use it in GitHub Desktop.
Save srdjan/ef0bc06630c630ee68307d34cbff3c74 to your computer and use it in GitHub Desktop.
const reg = new RegExp("([^?=&]+)(=([^&]*))?", "g")
function qs (uri) {
const obj = {}
uri = uri.replace(/^.*\?/, '')
uri.replace(reg, map)
return obj
function map (a0, a1, a2, a3) {
obj[decodeURIComponent(a1)] = decodeURIComponent(a3)
}
}
console.log(qs('http:///foo/bar/#hello?world=bar'))
console.log(qs('/foo/bar/#hello?world=bar&foo=hey'))
console.log(qs('/foo/bar/#hello?world=bar&foo=hey&bbbbuuuub_foo=oi'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment