From 61df80112a1396e8826a55b13319e33a925cc277 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Wed, 30 Aug 2023 15:43:39 -0700 Subject: [PATCH] Updated subdivision check. --- src/lib/detect.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/detect.ts b/src/lib/detect.ts index d60435062..b16bab7ab 100644 --- a/src/lib/detect.ts +++ b/src/lib/detect.ts @@ -57,6 +57,14 @@ export function getDevice(screen, os) { } } +function getRegionCode(country, region) { + if (!country || !region) { + return undefined; + } + + return region.includes('-') ? region : `${country}-${region}`; +} + export async function getLocation(ip, req) { // Ignore local ips if (await isLocalhost(ip)) { @@ -71,7 +79,7 @@ export async function getLocation(ip, req) { return { country, - subdivision1: subdivision1?.includes('-') ? subdivision1 : `${country}-${subdivision1}`, + subdivision1: getRegionCode(country, subdivision1), city, }; } @@ -84,7 +92,7 @@ export async function getLocation(ip, req) { return { country, - subdivision1: subdivision1?.includes('-') ? subdivision1 : `${country}-${subdivision1}`, + subdivision1: getRegionCode(country, subdivision1), city, }; }