diff --git a/src/runtime/includes/utils.ts b/src/runtime/includes/utils.ts deleted file mode 100644 index a131e0d..0000000 --- a/src/runtime/includes/utils.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { GetClientLocaleOptions } from '../types' - -const getFromQueryString = (queryString: string, key: string) => { - const keyVal = queryString.split('&').find(i => i.indexOf(`${key}=`) === 0) - - if (keyVal) { - return keyVal.split('=').pop() - } - return null -} - -const getFirstMatch = (base: string, pattern: RegExp) => { - const match = pattern.exec(base) - // istanbul ignore if - if (!match) return null - // istanbul ignore else - return match[1] || null -} - -export const getClientLocale = ({ - navigator, - hash, - search, - pathname, - hostname, -}: GetClientLocaleOptions) => { - let locale - - // istanbul ignore next - if (typeof window === 'undefined') return null - - if (hostname) { - locale = getFirstMatch(window.location.hostname, hostname) - if (locale) return locale - } - - if (pathname) { - locale = getFirstMatch(window.location.pathname, pathname) - if (locale) return locale - } - - if (navigator) { - // istanbul ignore else - locale = window.navigator.language || window.navigator.languages[0] - if (locale) return locale - } - - if (search) { - locale = getFromQueryString(window.location.search.substr(1), search) - if (locale) return locale - } - - if (hash) { - locale = getFromQueryString(window.location.hash.substr(1), hash) - if (locale) return locale - } - - return null -}