Skip to content

Instantly share code, notes, and snippets.

@rtplv
Created December 3, 2018 12:28
Show Gist options
  • Save rtplv/f6199a1613e41ade24887feafd2ea290 to your computer and use it in GitHub Desktop.
Save rtplv/f6199a1613e41ade24887feafd2ea290 to your computer and use it in GitHub Desktop.
Extract search params from url with hash(#)
function extractUrlParams(keys, url) {
if (!keys || !keys.length || !Array.isArray(keys)) {
throw new Error('Keys would be array of params keys');
}
return keys.reduce((agg, key) => {
const matches = url.match('[?&]' + key + '=([^&]+)');
agg[key] = matches[1];
return agg;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment