class GetParams {
constructor(name) {
this.name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
}
run() {
const regex = new RegExp("[\\?&]" + this.name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
const getParams = new GetParams('hash'),
hash = getParams.run();
Last active
October 25, 2015 23:47
-
-
Save hiz8/ae07b72919c702e7eaef to your computer and use it in GitHub Desktop.
Get query string values in ES6.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment