Replace entire repo content with code from /root/shahikitchen-google/

This commit is contained in:
root
2026-07-03 02:51:15 +00:00
parent c8b7dc95e4
commit 8ccf033329
79 changed files with 7611 additions and 439 deletions
+55
View File
@@ -0,0 +1,55 @@
/** Göteborg municipality postcodes used for delivery validation. */
const GOTHENBURG_POSTCODE_PREFIXES = ['41', '42', '43'] as const;
const GOTHENBURG_NAME_PATTERNS = [
'göteborg',
'gothenburg',
'goteborg',
'göteborgs stad',
'goteborgs stad',
] as const;
export interface DeliverableAddressFields {
city?: string;
municipality?: string;
postcode?: string;
countryCode?: string;
formatted?: string;
}
function normalize(value: string): string {
return value.trim().toLowerCase();
}
function matchesGothenburgName(value: string): boolean {
const normalized = normalize(value);
return GOTHENBURG_NAME_PATTERNS.some((pattern) => normalized.includes(pattern));
}
function hasGothenburgPostcode(postcode?: string): boolean {
if (!postcode) return false;
const digits = postcode.replace(/\s/g, '');
return GOTHENBURG_POSTCODE_PREFIXES.some((prefix) => digits.startsWith(prefix));
}
export function isGothenburgDeliveryAddress(fields: DeliverableAddressFields): boolean {
if (fields.countryCode && normalize(fields.countryCode) !== 'se') return false;
if (matchesGothenburgName(fields.city ?? '')) return true;
if (matchesGothenburgName(fields.municipality ?? '')) return true;
if (hasGothenburgPostcode(fields.postcode)) return true;
const formatted = normalize(fields.formatted ?? '');
if (
formatted.includes('göteborg') ||
formatted.includes('gothenburg') ||
formatted.includes('goteborg')
) {
return (
hasGothenburgPostcode(fields.postcode) ||
/\b41\d{3}\b|\b42\d{3}\b|\b43\d{3}\b/.test(formatted)
);
}
return false;
}