17 lines
744 B
JavaScript
17 lines
744 B
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.resolveCountryCode = resolveCountryCode;
|
|
const geoip_lite_1 = __importDefault(require("geoip-lite"));
|
|
/** Resolves ISO 3166-1 alpha-2 country code from an IP address (offline DB). */
|
|
function resolveCountryCode(ipAddress) {
|
|
const ip = (ipAddress ?? '').trim();
|
|
if (!ip || ip === 'unknown' || ip === '::1' || ip === '127.0.0.1' || ip.startsWith('::ffff:127.')) {
|
|
return null;
|
|
}
|
|
const lookup = geoip_lite_1.default.lookup(ip);
|
|
return lookup?.country ?? null;
|
|
}
|
|
//# sourceMappingURL=geoIp.js.map
|