aboutsummaryrefslogtreecommitdiff
path: root/docs/src/util.ts
blob: 26937373545c57e49c993152078931bdcbc3343e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export function getLanguageFromURL(pathname: string) {
  const langCodeMatch = pathname.match(/\/([a-z]{2}-?[A-Z]{0,2})\//);
  return langCodeMatch ? langCodeMatch[1] : 'en';
}

/** Remove \ and / from beginning of string */
export function removeLeadingSlash(path: string) {
  return path.replace(/^[/\\]+/, '');
}

/** Remove \ and / from end of string */
export function removeTrailingSlash(path: string) {
  return path.replace(/[/\\]+$/, '');
}