Skip to content

Instantly share code, notes, and snippets.

@jcchikikomori
Forked from cvan/qs.js
Created May 19, 2021 07:10
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 jcchikikomori/20929cc266f3096855cbed2a98e50e4e to your computer and use it in GitHub Desktop.
Save jcchikikomori/20929cc266f3096855cbed2a98e50e4e to your computer and use it in GitHub Desktop.
get query-string parameters (alternative to `URLSearchParams`)
var queryParams = window.location.search.substr(1).split('&').reduce(function (qs, query) {
var chunks = query.split('=');
var key = chunks[0];
var value = decodeURIComponent(chunks[1] || '');
var valueLower = value.trim().toLowerCase();
if (valueLower === 'true' || value === 'false') {
value = Boolean(value);
} else if (!isNaN(Number(value))) {
value = Number(value);
}
return (qs[key] = value, qs);
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment