Created
September 4, 2017 05:59
-
-
Save itsdouges/33cab23455b13091d86ee1860ef6ac31 to your computer and use it in GitHub Desktop.
Very naive query string implementation
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
// @flow | |
export default function getParameterByName ( | |
name: string, | |
url: string = window.location.href | |
): string { | |
const normalisedName = name.replace(/[[\]]/g, '\\$&'); | |
const regex = new RegExp(`[?&]${normalisedName}(=([^&#]*)|&|#|$)`); | |
const results = regex.exec(url); | |
if (!results || !results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, ' ')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment