Skip to content

Instantly share code, notes, and snippets.

@3imed-jaberi
Created November 29, 2021 13:20
Show Gist options
  • Select an option

  • Save 3imed-jaberi/0ceec8de7a18eaaf022c45044393fcde to your computer and use it in GitHub Desktop.

Select an option

Save 3imed-jaberi/0ceec8de7a18eaaf022c45044393fcde to your computer and use it in GitHub Desktop.
implementation of query-string parse.
// implementation of querystring parse.
const queryStringDotParse = (str = '') =>
str.split('&').reduce((parsedObject, param) => {
if (param === '') return parsedObject
const [key, value] = param.split('=')
parsedObject[key] = decodeURIComponent(value)
return parsedObject
}, {})
// test with chai behave.
// expect(queryStringDotParse('a=1&b=2')).to.be.equal({ a: 1, b: 2 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment