Created
December 3, 2018 12:28
-
-
Save rtplv/f6199a1613e41ade24887feafd2ea290 to your computer and use it in GitHub Desktop.
Extract search params from url with hash(#)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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