chore: create a utils/languages file
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
|
||||
export function findLang(pathname: string) {
|
||||
return Object.values(Lang).find(
|
||||
(l) => pathname.startsWith(`/${l}/`) || pathname === `/${l}`
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to convert langs in uppercase or capitalized format (e.g. the Hotel endpoint)
|
||||
* to to Lang enum.
|
||||
*/
|
||||
export function fromUppercaseToLangEnum(lang: string): Lang | undefined {
|
||||
const lowerCaseLang = lang.toLowerCase()
|
||||
return Object.values(Lang).find((l) => l === lowerCaseLang)
|
||||
}
|
||||
Reference in New Issue
Block a user