Skip to content

Instantly share code, notes, and snippets.

@cvan
Last active April 5, 2019 19:12
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 cvan/414a0c1cc8df3a48aed2767729c51f38 to your computer and use it in GitHub Desktop.
Save cvan/414a0c1cc8df3a48aed2767729c51f38 to your computer and use it in GitHub Desktop.
get truthy value from key from `URLSearchParams`
const qs = new URLSearchParams(window.location.search);
function getTruthyQS (key) {
if (!qs || !qs.has(key)) {
return false;
}
const valueLower = (qs.get('key') || '').trim().toLowerCase();
return valueLower === '' || valueLower === '1' || valueLower === 'true' || valueLower === 'yes' || valueLower === 'on';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment