From ff088f50e219a645581435274ac04aad40a49739 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Thu, 30 Jan 2020 11:20:31 -0300 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20unused=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/runtime/includes/utils.ts | 59 ----------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 src/runtime/includes/utils.ts 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 -}