ip2ldb-reader
Advanced tools
+42
-42
@@ -57,3 +57,3 @@ "use strict"; | ||
| const tmp = ip.replace(/^[:0]+F{4}:/i, "").replace(/:/, ""); | ||
| ip = (tmp.match(/../g) || []).map((b) => parseInt("0x" + b)).join("."); | ||
| ip = (tmp.match(/../g) ?? []).map((b) => parseInt("0x" + b)).join("."); | ||
| ipVersion = import_node_net.default.isIP(ip); | ||
@@ -283,3 +283,3 @@ } | ||
| import_node_fs.default.closeSync(this.fd_); | ||
| } catch (ex) { | ||
| } catch { | ||
| } | ||
@@ -294,16 +294,16 @@ } | ||
| } | ||
| this.dbStats_.DBType = this.readInt8(1) || 0; | ||
| this.dbStats_.DBColumn = this.readInt8(2) || 0; | ||
| this.dbStats_.DBYear = this.readInt8(3) || 0; | ||
| this.dbStats_.DBMonth = this.readInt8(4) || 0; | ||
| this.dbStats_.DBDay = this.readInt8(5) || 0; | ||
| this.dbStats_.DBCount = this.readInt32(6) || 0; | ||
| this.dbStats_.BaseAddr = this.readInt32(10) || 0; | ||
| this.dbStats_.DBCountIPv6 = this.readInt32(14) || 0; | ||
| this.dbStats_.BaseAddrIPv6 = this.readInt32(18) || 0; | ||
| this.dbStats_.IndexBaseAddr = this.readInt32(22) || 0; | ||
| this.dbStats_.IndexBaseAddrIPv6 = this.readInt32(26) || 0; | ||
| this.dbStats_.ProductCode = this.readInt8(30) || 0; | ||
| this.dbStats_.ProductType = this.readInt8(31) || 0; | ||
| this.dbStats_.FileSize = this.readInt32(32) || 0; | ||
| this.dbStats_.DBType = this.readInt8(1) ?? 0; | ||
| this.dbStats_.DBColumn = this.readInt8(2) ?? 0; | ||
| this.dbStats_.DBYear = this.readInt8(3) ?? 0; | ||
| this.dbStats_.DBMonth = this.readInt8(4) ?? 0; | ||
| this.dbStats_.DBDay = this.readInt8(5) ?? 0; | ||
| this.dbStats_.DBCount = this.readInt32(6) ?? 0; | ||
| this.dbStats_.BaseAddr = this.readInt32(10) ?? 0; | ||
| this.dbStats_.DBCountIPv6 = this.readInt32(14) ?? 0; | ||
| this.dbStats_.BaseAddrIPv6 = this.readInt32(18) ?? 0; | ||
| this.dbStats_.IndexBaseAddr = this.readInt32(22) ?? 0; | ||
| this.dbStats_.IndexBaseAddrIPv6 = this.readInt32(26) ?? 0; | ||
| this.dbStats_.ProductCode = this.readInt8(30) ?? 0; | ||
| this.dbStats_.ProductType = this.readInt8(31) ?? 0; | ||
| this.dbStats_.FileSize = this.readInt32(32) ?? 0; | ||
| if (this.dbStats_.ProductCode !== 1 && this.dbStats_.DBYear >= 21) { | ||
@@ -323,8 +323,6 @@ throw new Error( | ||
| const dbType = this.dbStats_.DBType; | ||
| Object.keys(Position).forEach((key) => { | ||
| for (const key of Object.keys(Position)) { | ||
| this.offset_[key] = Position[key][dbType] ? Position[key][dbType] - 2 << 2 : 0; | ||
| }); | ||
| Object.keys(Position).forEach((key) => { | ||
| this.enabled_[key] = Boolean(Position[key][dbType]); | ||
| }); | ||
| } | ||
| this.indiciesIPv4_ = new Array(MAX_SIZE); | ||
@@ -335,3 +333,3 @@ this.indiciesIPv6_ = new Array(MAX_SIZE); | ||
| for (let x = 0; x < MAX_SIZE; x++) { | ||
| this.indiciesIPv4_[x] = [this.readInt32(pointer) || 0, this.readInt32(pointer + 4) || 0]; | ||
| this.indiciesIPv4_[x] = [this.readInt32(pointer) ?? 0, this.readInt32(pointer + 4) ?? 0]; | ||
| pointer += 8; | ||
@@ -341,3 +339,3 @@ } | ||
| for (let x = 0; x < MAX_SIZE; x++) { | ||
| this.indiciesIPv6_[x] = [this.readInt32(pointer) || 0, this.readInt32(pointer + 4) || 0]; | ||
| this.indiciesIPv6_[x] = [this.readInt32(pointer) ?? 0, this.readInt32(pointer + 4) ?? 0]; | ||
| pointer += 8; | ||
@@ -363,3 +361,3 @@ } | ||
| import_node_fs.default.closeSync(this.fd_); | ||
| } catch (ex) { | ||
| } catch { | ||
| } | ||
@@ -411,5 +409,5 @@ } | ||
| this.dbPath_ = dbPath; | ||
| this.cacheInMemory_ = options?.cacheDatabaseInMemory || false; | ||
| this.cacheInMemory_ = options?.cacheDatabaseInMemory ?? false; | ||
| this.loadDatabase(); | ||
| if (options && options.reloadOnDbUpdate) { | ||
| if (options?.reloadOnDbUpdate) { | ||
| this.watchDbFile(); | ||
@@ -506,7 +504,10 @@ } | ||
| } | ||
| Object.keys(this.enabled_).filter((key) => this.enabled_[key]).forEach((key) => { | ||
| const enabledKeys = Object.keys(this.enabled_).filter( | ||
| (key) => this.enabled_[key] | ||
| ); | ||
| for (const key of enabledKeys) { | ||
| if (key === "country") { | ||
| const countrypos = this.readBufferInt32(this.offset_[key], buff); | ||
| data["country_short"] = this.readString(countrypos) || ""; | ||
| data["country_long"] = this.readString(countrypos + 3) || ""; | ||
| data.country_short = this.readString(countrypos) ?? ""; | ||
| data.country_long = this.readString(countrypos + 3) ?? ""; | ||
| } else if (key === "longitude" || key === "latitude") { | ||
@@ -516,5 +517,5 @@ const num = this.readBufferFloat(this.offset_[key], buff); | ||
| } else { | ||
| data[key] = this.readString(this.readBufferInt32(this.offset_[key], buff)) || ""; | ||
| data[key] = this.readString(this.readBufferInt32(this.offset_[key], buff)) ?? ""; | ||
| } | ||
| }); | ||
| } | ||
| data.status = "OK"; | ||
@@ -687,3 +688,3 @@ return; | ||
| } | ||
| const countryMap = this.subdivisionMap_[country_code] || {}; | ||
| const countryMap = this.subdivisionMap_[country_code] ?? {}; | ||
| countryMap[subdivision_name] = subdivisionCode; | ||
@@ -709,5 +710,5 @@ this.subdivisionMap_[country_code] = countryMap; | ||
| if (!country || !region) { | ||
| return ""; | ||
| return null; | ||
| } | ||
| return (this.subdivisionMap_[country] || {})[region] || ""; | ||
| return this.subdivisionMap_[country]?.[region] ?? null; | ||
| } | ||
@@ -733,4 +734,4 @@ }; | ||
| } | ||
| const countryMap = this.geoNameIdMap_[country_code] || {}; | ||
| const regionMap = countryMap[region_name] || {}; | ||
| const countryMap = this.geoNameIdMap_[country_code] ?? {}; | ||
| const regionMap = countryMap[region_name] ?? {}; | ||
| regionMap[city_name] = parseInt(geonameid); | ||
@@ -758,6 +759,5 @@ countryMap[region_name] = regionMap; | ||
| if (!country || !region || !city) { | ||
| return 0; | ||
| return null; | ||
| } | ||
| const geoNameId = ((this.geoNameIdMap_[country] || {})[region] || {})[city]; | ||
| return geoNameId != void 0 ? geoNameId : null; | ||
| return this.geoNameIdMap_[country]?.[region]?.[city] ?? null; | ||
| } | ||
@@ -822,3 +822,3 @@ }; | ||
| } | ||
| return this.countryInfoMap_[country] || null; | ||
| return this.countryInfoMap_[country] ?? null; | ||
| } | ||
@@ -869,4 +869,4 @@ }; | ||
| } | ||
| const countryMap = this.iataIcaoMap_[country_code] || {}; | ||
| const regionArray = countryMap[region_name] || []; | ||
| const countryMap = this.iataIcaoMap_[country_code] ?? {}; | ||
| const regionArray = countryMap[region_name] ?? []; | ||
| regionArray.push(airportOutputData); | ||
@@ -895,3 +895,3 @@ countryMap[region_name] = regionArray; | ||
| } | ||
| return (this.iataIcaoMap_[country] || {})[region] || []; | ||
| return this.iataIcaoMap_[country]?.[region] ?? []; | ||
| } | ||
@@ -898,0 +898,0 @@ }; |
+42
-42
@@ -20,3 +20,3 @@ // src/db-reader.ts | ||
| const tmp = ip.replace(/^[:0]+F{4}:/i, "").replace(/:/, ""); | ||
| ip = (tmp.match(/../g) || []).map((b) => parseInt("0x" + b)).join("."); | ||
| ip = (tmp.match(/../g) ?? []).map((b) => parseInt("0x" + b)).join("."); | ||
| ipVersion = net.isIP(ip); | ||
@@ -246,3 +246,3 @@ } | ||
| fs.closeSync(this.fd_); | ||
| } catch (ex) { | ||
| } catch { | ||
| } | ||
@@ -257,16 +257,16 @@ } | ||
| } | ||
| this.dbStats_.DBType = this.readInt8(1) || 0; | ||
| this.dbStats_.DBColumn = this.readInt8(2) || 0; | ||
| this.dbStats_.DBYear = this.readInt8(3) || 0; | ||
| this.dbStats_.DBMonth = this.readInt8(4) || 0; | ||
| this.dbStats_.DBDay = this.readInt8(5) || 0; | ||
| this.dbStats_.DBCount = this.readInt32(6) || 0; | ||
| this.dbStats_.BaseAddr = this.readInt32(10) || 0; | ||
| this.dbStats_.DBCountIPv6 = this.readInt32(14) || 0; | ||
| this.dbStats_.BaseAddrIPv6 = this.readInt32(18) || 0; | ||
| this.dbStats_.IndexBaseAddr = this.readInt32(22) || 0; | ||
| this.dbStats_.IndexBaseAddrIPv6 = this.readInt32(26) || 0; | ||
| this.dbStats_.ProductCode = this.readInt8(30) || 0; | ||
| this.dbStats_.ProductType = this.readInt8(31) || 0; | ||
| this.dbStats_.FileSize = this.readInt32(32) || 0; | ||
| this.dbStats_.DBType = this.readInt8(1) ?? 0; | ||
| this.dbStats_.DBColumn = this.readInt8(2) ?? 0; | ||
| this.dbStats_.DBYear = this.readInt8(3) ?? 0; | ||
| this.dbStats_.DBMonth = this.readInt8(4) ?? 0; | ||
| this.dbStats_.DBDay = this.readInt8(5) ?? 0; | ||
| this.dbStats_.DBCount = this.readInt32(6) ?? 0; | ||
| this.dbStats_.BaseAddr = this.readInt32(10) ?? 0; | ||
| this.dbStats_.DBCountIPv6 = this.readInt32(14) ?? 0; | ||
| this.dbStats_.BaseAddrIPv6 = this.readInt32(18) ?? 0; | ||
| this.dbStats_.IndexBaseAddr = this.readInt32(22) ?? 0; | ||
| this.dbStats_.IndexBaseAddrIPv6 = this.readInt32(26) ?? 0; | ||
| this.dbStats_.ProductCode = this.readInt8(30) ?? 0; | ||
| this.dbStats_.ProductType = this.readInt8(31) ?? 0; | ||
| this.dbStats_.FileSize = this.readInt32(32) ?? 0; | ||
| if (this.dbStats_.ProductCode !== 1 && this.dbStats_.DBYear >= 21) { | ||
@@ -286,8 +286,6 @@ throw new Error( | ||
| const dbType = this.dbStats_.DBType; | ||
| Object.keys(Position).forEach((key) => { | ||
| for (const key of Object.keys(Position)) { | ||
| this.offset_[key] = Position[key][dbType] ? Position[key][dbType] - 2 << 2 : 0; | ||
| }); | ||
| Object.keys(Position).forEach((key) => { | ||
| this.enabled_[key] = Boolean(Position[key][dbType]); | ||
| }); | ||
| } | ||
| this.indiciesIPv4_ = new Array(MAX_SIZE); | ||
@@ -298,3 +296,3 @@ this.indiciesIPv6_ = new Array(MAX_SIZE); | ||
| for (let x = 0; x < MAX_SIZE; x++) { | ||
| this.indiciesIPv4_[x] = [this.readInt32(pointer) || 0, this.readInt32(pointer + 4) || 0]; | ||
| this.indiciesIPv4_[x] = [this.readInt32(pointer) ?? 0, this.readInt32(pointer + 4) ?? 0]; | ||
| pointer += 8; | ||
@@ -304,3 +302,3 @@ } | ||
| for (let x = 0; x < MAX_SIZE; x++) { | ||
| this.indiciesIPv6_[x] = [this.readInt32(pointer) || 0, this.readInt32(pointer + 4) || 0]; | ||
| this.indiciesIPv6_[x] = [this.readInt32(pointer) ?? 0, this.readInt32(pointer + 4) ?? 0]; | ||
| pointer += 8; | ||
@@ -326,3 +324,3 @@ } | ||
| fs.closeSync(this.fd_); | ||
| } catch (ex) { | ||
| } catch { | ||
| } | ||
@@ -374,5 +372,5 @@ } | ||
| this.dbPath_ = dbPath; | ||
| this.cacheInMemory_ = options?.cacheDatabaseInMemory || false; | ||
| this.cacheInMemory_ = options?.cacheDatabaseInMemory ?? false; | ||
| this.loadDatabase(); | ||
| if (options && options.reloadOnDbUpdate) { | ||
| if (options?.reloadOnDbUpdate) { | ||
| this.watchDbFile(); | ||
@@ -469,7 +467,10 @@ } | ||
| } | ||
| Object.keys(this.enabled_).filter((key) => this.enabled_[key]).forEach((key) => { | ||
| const enabledKeys = Object.keys(this.enabled_).filter( | ||
| (key) => this.enabled_[key] | ||
| ); | ||
| for (const key of enabledKeys) { | ||
| if (key === "country") { | ||
| const countrypos = this.readBufferInt32(this.offset_[key], buff); | ||
| data["country_short"] = this.readString(countrypos) || ""; | ||
| data["country_long"] = this.readString(countrypos + 3) || ""; | ||
| data.country_short = this.readString(countrypos) ?? ""; | ||
| data.country_long = this.readString(countrypos + 3) ?? ""; | ||
| } else if (key === "longitude" || key === "latitude") { | ||
@@ -479,5 +480,5 @@ const num = this.readBufferFloat(this.offset_[key], buff); | ||
| } else { | ||
| data[key] = this.readString(this.readBufferInt32(this.offset_[key], buff)) || ""; | ||
| data[key] = this.readString(this.readBufferInt32(this.offset_[key], buff)) ?? ""; | ||
| } | ||
| }); | ||
| } | ||
| data.status = "OK"; | ||
@@ -650,3 +651,3 @@ return; | ||
| } | ||
| const countryMap = this.subdivisionMap_[country_code] || {}; | ||
| const countryMap = this.subdivisionMap_[country_code] ?? {}; | ||
| countryMap[subdivision_name] = subdivisionCode; | ||
@@ -672,5 +673,5 @@ this.subdivisionMap_[country_code] = countryMap; | ||
| if (!country || !region) { | ||
| return ""; | ||
| return null; | ||
| } | ||
| return (this.subdivisionMap_[country] || {})[region] || ""; | ||
| return this.subdivisionMap_[country]?.[region] ?? null; | ||
| } | ||
@@ -696,4 +697,4 @@ }; | ||
| } | ||
| const countryMap = this.geoNameIdMap_[country_code] || {}; | ||
| const regionMap = countryMap[region_name] || {}; | ||
| const countryMap = this.geoNameIdMap_[country_code] ?? {}; | ||
| const regionMap = countryMap[region_name] ?? {}; | ||
| regionMap[city_name] = parseInt(geonameid); | ||
@@ -721,6 +722,5 @@ countryMap[region_name] = regionMap; | ||
| if (!country || !region || !city) { | ||
| return 0; | ||
| return null; | ||
| } | ||
| const geoNameId = ((this.geoNameIdMap_[country] || {})[region] || {})[city]; | ||
| return geoNameId != void 0 ? geoNameId : null; | ||
| return this.geoNameIdMap_[country]?.[region]?.[city] ?? null; | ||
| } | ||
@@ -785,3 +785,3 @@ }; | ||
| } | ||
| return this.countryInfoMap_[country] || null; | ||
| return this.countryInfoMap_[country] ?? null; | ||
| } | ||
@@ -832,4 +832,4 @@ }; | ||
| } | ||
| const countryMap = this.iataIcaoMap_[country_code] || {}; | ||
| const regionArray = countryMap[region_name] || []; | ||
| const countryMap = this.iataIcaoMap_[country_code] ?? {}; | ||
| const regionArray = countryMap[region_name] ?? []; | ||
| regionArray.push(airportOutputData); | ||
@@ -858,3 +858,3 @@ countryMap[region_name] = regionArray; | ||
| } | ||
| return (this.iataIcaoMap_[country] || {})[region] || []; | ||
| return this.iataIcaoMap_[country]?.[region] ?? []; | ||
| } | ||
@@ -861,0 +861,0 @@ }; |
+13
-11
| { | ||
| "name": "ip2ldb-reader", | ||
| "version": "3.0.1", | ||
| "version": "3.0.2", | ||
| "description": "Reader for IP2Location databases", | ||
@@ -18,3 +18,3 @@ "type": "module", | ||
| "format": "prettier --write .", | ||
| "lint": "eslint src", | ||
| "lint": "eslint .", | ||
| "prepare": "npm run compile", | ||
@@ -70,18 +70,20 @@ "test": "jest" | ||
| "devDependencies": { | ||
| "@types/jest": "^29.5.13", | ||
| "@types/node": "^20.16.6", | ||
| "@typescript-eslint/eslint-plugin": "^7.18.0", | ||
| "@typescript-eslint/parser": "^7.18.0", | ||
| "eslint": "^8.57.1", | ||
| "@eslint/js": "^9.15.0", | ||
| "@types/eslint__js": "^8.42.3", | ||
| "@types/jest": "^29.5.14", | ||
| "@types/node": "^20.17.6", | ||
| "eslint": "^9.15.0", | ||
| "eslint-config-prettier": "^9.1.0", | ||
| "eslint-plugin-jsdoc": "^50.2.4", | ||
| "eslint-plugin-jest": "^28.9.0", | ||
| "eslint-plugin-jsdoc": "^50.5.0", | ||
| "eslint-plugin-prettier": "^5.2.1", | ||
| "jest": "^29.7.0", | ||
| "prettier": "^3.3.3", | ||
| "publint": "^0.2.11", | ||
| "publint": "^0.2.12", | ||
| "rimraf": "^6.0.1", | ||
| "ts-jest": "^29.2.5", | ||
| "tsup": "^8.3.0", | ||
| "typescript": "~5.5.4" | ||
| "tsup": "^8.3.5", | ||
| "typescript": "~5.6.3", | ||
| "typescript-eslint": "^8.15.0" | ||
| } | ||
| } |
+1
-1
@@ -113,3 +113,3 @@ # ip2ldb-reader | ||
| region?: string; | ||
| subdivision?: string; | ||
| subdivision?: string | null; | ||
| timezone?: string; | ||
@@ -116,0 +116,0 @@ usagetype?: string; |
83868
-0.15%17
13.33%