Skip to content

Instantly share code, notes, and snippets.

@avaforvr
Last active May 23, 2020 09:38
Show Gist options
  • Save avaforvr/d74113832da6657eb7d84735c86ea36e to your computer and use it in GitHub Desktop.
Save avaforvr/d74113832da6657eb7d84735c86ea36e to your computer and use it in GitHub Desktop.
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