Last active
May 23, 2020 09:38
-
-
Save avaforvr/d74113832da6657eb7d84735c86ea36e to your computer and use it in GitHub Desktop.
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 getClearUrl(url) { | |
if (url.includes('?') || url.includes('#')) { | |
return (url.match(/^.*?(?=[?|#])/))[0]; | |
} else { | |
return url; | |
} | |
} | |
function getSearch(url: string): string { | |
let search: string = ''; | |
if (url.includes('?')) { | |
search = (url.match(/\?.*$/))[0].replace(/#.*$/, ''); | |
} | |
return search; | |
} | |
function getHash(url: string): string { | |
let hash = ''; | |
if (url.includes('#')) { | |
hash = (url.match(/#.*$/))[0].replace(/\?.*$/, ''); | |
} | |
return hash; | |
} | |
export function getLangInPath(path) { | |
if (!path) { | |
path = window.location.pathname; | |
} | |
let langInPath = ''; | |
if (path.search(/^\/[a-z][a-z]\//) === 0) { | |
langInPath = path.substr(0, 4).replace(/\//g, '').toLowerCase() | |
} else if (path.length === 3) { | |
langInPath = path.substr(1, 2); | |
} | |
return languages[langInPath] ? langInPath : 'en'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment