var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/countryFromPostcode.ts var countryFromPostcode_exports = {}; __export(countryFromPostcode_exports, { getCountryFromPostcode: () => getCountryFromPostcode }); module.exports = __toCommonJS(countryFromPostcode_exports); var postcodeData = { England: { AL: ["*"], B: ["*"], BA: ["*"], BB: ["*"], BD: ["*"], BH: ["*"], BL: ["*"], BN: ["*"], BR: ["*"], BS: ["*"], CA: ["*"], CB: ["*"], CF: ["*"], CH: ["1", "3", "4", "6", "7", "8"], CM: ["*"], CO: ["*"], CR: ["*"], CT: ["*"], CV: ["*"], CW: ["*"], DA: ["*"], DE: ["*"], DG: ["16"], DH: ["*"], DL: ["*"], DN: ["*"], DT: ["*"], DY: ["*"], E: ["*"], EC: ["*"], EN: ["*"], EX: ["*"], FY: ["*"], GL: ["*"], GU: ["*"], HA: ["*"], HD: ["*"], HG: ["*"], HP: ["*"], HR: ["1", "2", "4", "6", "7", "8"], HU: ["*"], HX: ["*"], IG: ["*"], IP: ["*"], KT: ["*"], L: ["*"], LA: ["*"], LD: ["7", "8"], LE: ["*"], LN: ["*"], LS: ["*"], LU: ["*"], M: ["*"], ME: ["*"], MK: ["*"], N: ["*"], NE: ["*"], NG: ["*"], NN: ["*"], NP: ["*"], NR: ["*"], NW: ["*"], OL: ["*"], OX: ["*"], PE: ["*"], PL: ["*"], PO: ["*"], PR: ["*"], RG: ["*"], RH: ["*"], RM: ["*"], S: ["*"], SA: ["*"], SE: ["*"], SG: ["*"], SK: ["*"], SL: ["*"], SM: ["*"], SN: ["*"], SO: ["*"], SP: ["*"], SR: ["*"], SS: ["*"], ST: ["*"], SW: ["*"], SY: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "11"], TA: ["*"], TF: ["*"], TN: ["*"], TS: ["*"], TW: ["*"], UB: ["*"], W: ["*"], WA: ["*"], WC: ["*"], WD: ["*"], WF: ["*"], WN: ["*"], WR: ["*"], WS: ["*"], WV: ["*"], YO: ["*"] }, Wales: { CF: ["*"], CH: ["5"], HR: ["3", "5"], LD: ["1", "2", "3", "4", "5", "6"], LL: ["*"], NP: ["*"], SA: ["*"], SY: [ "10", "11", "15", "16", "17", "18", "19", "20", "21", "22", "23", "99" ] }, Scotland: { AB: ["*"], DD: ["*"], DG: [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" ], EH: ["*"], FK: ["*"], G: ["*"], HS: ["*"], IV: ["*"], KA: ["*"], KW: ["*"], KY: ["*"], ML: ["*"], PA: ["*"], PH: ["*"], TD: [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" ], ZE: ["*"] }, "Northern Ireland": { BT: ["*"] }, "Channel Islands": { GY: ["*"], JE: ["*"] }, "Isle of Man": { IM: ["*"] } }; function getPostcodeArea(postcode) { postcode = postcode.toUpperCase().replace(/\s+/g, ""); const area = postcode.match(/^[A-Z]{1,2}/); return area ? area[0] : ""; } function getPostcodeDistrict(postcode, area) { postcode = postcode.toUpperCase().replace(/\s+/g, "").slice(0, -3); const districtMatch = postcode.match(new RegExp(`^${area}([0-9]{1,2})`)); return districtMatch ? districtMatch[1] : ""; } function getCountryFromPostcode(postcode) { const isValid = /^([A-Z][A-HJ-Y]?\d[A-Z\d]? ?\d[A-Z]{2}|GIR ?0A{2})$/.test(postcode); if (isValid) { const area = getPostcodeArea(postcode); if (!area) return "Unknown"; const district = getPostcodeDistrict(postcode, area); for (const country in postcodeData) { if (postcodeData[country][area]) { if (postcodeData[country][area].includes("*") || postcodeData[country][area].includes(district)) { return country; } } } return "Unknown postcode"; } else { return "Invalid postcode"; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getCountryFromPostcode }); // fix-cjs-exports if (module.exports.default) { Object.assign(module.exports.default, module.exports); module.exports = module.exports.default; delete module.exports.default; }