geoip-lite2 2.1.31 → 2.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- bce4730dc8642d5e87ee19118dfc2b7612babcfa5ca6f2c5f87cc1d2ccdbe9e4 GeoLite2-City-CSV_20240308.zip
1
+ 26c2b88d13252c48cf2a267ae7613d82f29d469c6d889bf31e980fc670809d03 GeoLite2-City-CSV_20240405.zip
@@ -1 +1 @@
1
- 4dbbe1037e9658ad9779bc422d275bdde8a25beae3947ee90d2c4a35d37bb799 GeoLite2-Country-CSV_20240308.zip
1
+ 32edf69458b56fa3477092d4650156e28dc07b41c344cfa6b13df700b4e5f00b GeoLite2-Country-CSV_20240405.zip
Binary file
Binary file
Binary file
Binary file
Binary file
package/lib/fsWatcher.js CHANGED
@@ -1 +1 @@
1
- const n=require('fs'),t=require('path'),e={};function o(n){e[n].close()}module.exports.makeFsWatchFilter=function(u,l,c,r,i){let s=null;function f(){s=null,i()}'function'==typeof r&&(i=r,r=c,c=null),e[u]&&o(u),e[u]=n.watch(l,(function(e,o){if(!o)return;const u=t.join(l,o);c&&c!==o||n.access(u,n.constants.F_OK,(n=>{if(n)return console.error(n);null!==s&&(clearTimeout(s),s=null),s=setTimeout(f,r)}))}))},module.exports.stopWatching=o;
1
+ const{access:n,constants:t,watch:e}=require('fs'),{join:o}=require('path'),u={};function l(n){u[n].close()}module.exports.makeFsWatchFilter=function(c,r,i,s,f){let a=null;function m(){a=null,f()}'function'==typeof s&&(f=s,s=i,i=null),u[c]&&l(c),u[c]=e(r,(function(e,u){if(!u)return;const l=o(r,u);i&&i!==u||n(l,t.F_OK,(n=>{if(n)return console.error(n);null!==a&&(clearTimeout(a),a=null),a=setTimeout(m,s)}))}))},module.exports.stopWatching=l;
package/lib/main.js CHANGED
@@ -1 +1 @@
1
- const e=require('fs'),t=require('net'),r=require('path'),n=require('async'),i=require('./utils.js'),a=require('./fsWatcher.js'),{version:o}=require('../package.json');e.existsSync=e.existsSync||r.existsSync;const c='dataWatcher',s=r.resolve(__dirname,global.geoDataDir||process.env.geoDataDIR||'../data/'),f={city:r.join(s,'geoip-city.dat'),city6:r.join(s,'geoip-city6.dat'),cityNames:r.join(s,'geoip-city-names.dat'),country:r.join(s,'geoip-country.dat'),country6:r.join(s,'geoip-country6.dat')},l=[[i.aton4('10.0.0.0'),i.aton4('10.255.255.255')],[i.aton4('172.16.0.0'),i.aton4('172.31.255.255')],[i.aton4('192.168.0.0'),i.aton4('192.168.255.255')]],u={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},d={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d));const p={range:'',country:'',region:'',eu:'',timezone:'',city:'',ll:[0,0]},B=e=>{let t,r,n=0,i=y.lastIP,a=y.lastLine,o=y.firstIP;const c=y.mainBuffer,s=y.locationBuffer,f=l,u=y.recordSize,d=y.locationRecordSize;let S;if(e>y.lastIP||e<y.firstIP)return null;for(S=0;S<f.length;S++)if(e>=f[S][0]&&e<=f[S][1])return null;for(;;){if(t=Math.round((a-n)/2)+n,i=c.readUInt32BE(t*u),o=c.readUInt32BE(t*u+4),i<=e&&o>=e)return p.range=[i,o],10===u?p.country=c.toString('utf8',t*u+8,t*u+10):(r=c.readUInt32BE(t*u+8),-1>>>0>r&&(p.country=s.toString('utf8',r*d,r*d+2).replace(/\u0000.*/,''),p.region=s.toString('utf8',r*d+2,r*d+5).replace(/\u0000.*/,''),p.metro=s.readInt32BE(r*d+5),p.ll[0]=c.readInt32BE(t*u+12)/1e4,p.ll[1]=c.readInt32BE(t*u+16)/1e4,p.area=c.readUInt32BE(t*u+20),p.eu=s.toString('utf8',r*d+9,r*d+10).replace(/\u0000.*/,''),p.timezone=s.toString('utf8',r*d+10,r*d+42).replace(/\u0000.*/,''),p.city=s.toString('utf8',r*d+42,r*d+d).replace(/\u0000.*/,''))),p;if(n===a)return null;n===a-1?t===n?n=a:a=n:i>e?a=t:o<e&&(n=t)}},I=['0:0:0:0:0:FFFF:','::FFFF:'];function g(t){let r,i;const a=JSON.parse(JSON.stringify(u));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(f.cityNames,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,a.locationBuffer=Buffer.alloc(i),t(e)}))},t=>{e.read(r,a.locationBuffer,0,i,0,t)},t=>{e.close(r,t)},t=>{e.open(f.city,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(f.country,'r',((n,o)=>{n?t(n):(r=o,e.fstat(r,((e,r)=>{i=r.size,a.recordSize=10,t()})))}))}else t()}))},()=>{a.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,a.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(a.lastLine=i/a.recordSize-1,a.lastIP=a.mainBuffer.readUInt32BE(a.lastLine*a.recordSize+4),a.firstIP=a.mainBuffer.readUInt32BE(0),y=a),t(e)}))}]);else{try{if(r=e.openSync(f.cityNames,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'};y.locationBuffer=Buffer.alloc(i),e.readSync(r,y.locationBuffer,0,i,0),e.closeSync(r),r=e.openSync(f.city,'r'),i=e.fstatSync(r).size}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(f.country,'r'),i=e.fstatSync(r).size,y.recordSize=10}y.mainBuffer=Buffer.alloc(i),e.readSync(r,y.mainBuffer,0,i,0),e.closeSync(r),y.lastLine=i/y.recordSize-1,y.lastIP=y.mainBuffer.readUInt32BE(y.lastLine*y.recordSize+4),y.firstIP=y.mainBuffer.readUInt32BE(0)}}function m(t){let r,i;const a=JSON.parse(JSON.stringify(d));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(f.city6,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(f.country6,'r',((n,o)=>{n?t(n):(r=o,e.fstat(r,((e,r)=>{i=r.size,a.recordSize=34,t()})))}))}else t()}))},()=>{a.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,a.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(a.lastLine=i/a.recordSize-1,S=a),t(e)}))}]);else{try{if(r=e.openSync(f.city6,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'}}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(f.country6,'r'),i=e.fstatSync(r).size,S.recordSize=34}S.mainBuffer=Buffer.alloc(i),e.readSync(r,S.mainBuffer,0,i,0),e.closeSync(r),S.lastLine=i/S.recordSize-1}}module.exports={cmp:i.cmp,lookup:e=>{if(!e)return null;if('number'==typeof e)return B(e);if(4===t.isIP(e))return B(i.aton4(e));if(6===t.isIP(e)){const t=(e=>{const t=e.toUpperCase();for(let e=0;e<I.length;e++){const r=I[e];if(0===t.indexOf(r))return t.substring(r.length)}return null})(e);return t?B(i.aton4(t)):(e=>{const t=S.mainBuffer,r=S.recordSize,n=y.locationBuffer,a=y.locationRecordSize,o=(e,n)=>{let i;const a=[];for(i=0;i<2;i++)a.push(t.readUInt32BE(e*r+16*n+4*i));return a};S.lastIP=o(S.lastLine,1),S.firstIP=o(0,0);let c,s,f=0,l=S.lastIP,u=S.lastLine,d=S.firstIP;if(i.cmp6(e,S.lastIP)>0||i.cmp6(e,S.firstIP)<0)return null;for(;;){if(c=Math.round((u-f)/2)+f,l=o(c,0),d=o(c,1),i.cmp6(l,e)<=0&&i.cmp6(d,e)>=0)return 34===r?p.country=t.toString('utf8',c*r+32,c*r+34).replace(/\u0000.*/,''):(s=t.readUInt32BE(c*r+32),-1>>>0>s&&(p.country=n.toString('utf8',s*a,s*a+2).replace(/\u0000.*/,''),p.region=n.toString('utf8',s*a+2,s*a+5).replace(/\u0000.*/,''),p.metro=n.readInt32BE(s*a+5),p.ll[0]=t.readInt32BE(c*r+36)/1e4,p.ll[1]=t.readInt32BE(c*r+40)/1e4,p.area=t.readUInt32BE(c*r+44),p.eu=n.toString('utf8',s*a+9,s*a+10).replace(/\u0000.*/,''),p.timezone=n.toString('utf8',s*a+10,s*a+42).replace(/\u0000.*/,''),p.city=n.toString('utf8',s*a+42,s*a+a).replace(/\u0000.*/,''))),p;if(f===u)return null;f===u-1?c===f?f=u:u=f:i.cmp6(l,e)>0?u=c:i.cmp6(d,e)<0&&(f=c)}})(i.aton6(e))}return null},pretty:e=>'string'==typeof e?e:'number'==typeof e?i.ntoa4(e):Array.isArray(e)?i.ntoa6(e):e,startWatchingDataUpdate:e=>{a.makeFsWatchFilter(c,s,6e4,(async()=>{await n.series([e=>{g(e)},e=>{m(e)}],e)}))},stopWatchingDataUpdate:()=>{a.stopWatching(c)},clear:()=>{y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d))},reloadDataSync:()=>{g(),m()},reloadData:async e=>{await n.series([e=>{g(e)},e=>{m(e)}],e)},version:o},g(),m();
1
+ const e=require('fs'),{isIP:t}=require('net'),r=require('path'),n=require('async'),{aton4:i,aton6:a,cmp6:o,ntoa4:c,ntoa6:f,cmp:s}=require('./utils.js'),l=require('./fsWatcher.js'),{version:u}=require('../package.json');e.existsSync=e.existsSync||r.existsSync;const d='dataWatcher',y=r.resolve(__dirname,global.geoDataDir||process.env.geoDataDIR||'../data/'),S={city:r.join(y,'geoip-city.dat'),city6:r.join(y,'geoip-city6.dat'),cityNames:r.join(y,'geoip-city-names.dat'),country:r.join(y,'geoip-country.dat'),country6:r.join(y,'geoip-country6.dat')},p=[[i('10.0.0.0'),i('10.255.255.255')],[i('172.16.0.0'),i('172.31.255.255')],[i('192.168.0.0'),i('192.168.255.255')]],B={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},I={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let g=JSON.parse(JSON.stringify(B)),E=JSON.parse(JSON.stringify(I));const m={range:'',country:'',region:'',eu:'',timezone:'',city:'',ll:[0,0]},z=e=>{let t,r,n=0,i=g.lastIP,a=g.lastLine,o=g.firstIP;const c=g.mainBuffer,f=g.locationBuffer,s=p,l=g.recordSize,u=g.locationRecordSize;let d;if(e>g.lastIP||e<g.firstIP)return null;for(d=0;d<s.length;d++)if(e>=s[d][0]&&e<=s[d][1])return null;for(;;){if(t=Math.round((a-n)/2)+n,i=c.readUInt32BE(t*l),o=c.readUInt32BE(t*l+4),i<=e&&o>=e)return m.range=[i,o],10===l?m.country=c.toString('utf8',t*l+8,t*l+10):(r=c.readUInt32BE(t*l+8),-1>>>0>r&&(m.country=f.toString('utf8',r*u,r*u+2).replace(/\u0000.*/,''),m.region=f.toString('utf8',r*u+2,r*u+5).replace(/\u0000.*/,''),m.metro=f.readInt32BE(r*u+5),m.ll[0]=c.readInt32BE(t*l+12)/1e4,m.ll[1]=c.readInt32BE(t*l+16)/1e4,m.area=c.readUInt32BE(t*l+20),m.eu=f.toString('utf8',r*u+9,r*u+10).replace(/\u0000.*/,''),m.timezone=f.toString('utf8',r*u+10,r*u+42).replace(/\u0000.*/,''),m.city=f.toString('utf8',r*u+42,r*u+u).replace(/\u0000.*/,''))),m;if(n===a)return null;n===a-1?t===n?n=a:a=n:i>e?a=t:o<e&&(n=t)}},N=['0:0:0:0:0:FFFF:','::FFFF:'];function P(t){let r,i;const a=JSON.parse(JSON.stringify(B));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(S.cityNames,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,a.locationBuffer=Buffer.alloc(i),t(e)}))},t=>{e.read(r,a.locationBuffer,0,i,0,t)},t=>{e.close(r,t)},t=>{e.open(S.city,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(S.country,'r',((n,o)=>{n?t(n):(r=o,e.fstat(r,((e,r)=>{i=r.size,a.recordSize=10,t()})))}))}else t()}))},()=>{a.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,a.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(a.lastLine=i/a.recordSize-1,a.lastIP=a.mainBuffer.readUInt32BE(a.lastLine*a.recordSize+4),a.firstIP=a.mainBuffer.readUInt32BE(0),g=a),t(e)}))}]);else{try{if(r=e.openSync(S.cityNames,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'};g.locationBuffer=Buffer.alloc(i),e.readSync(r,g.locationBuffer,0,i,0),e.closeSync(r),r=e.openSync(S.city,'r'),i=e.fstatSync(r).size}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(S.country,'r'),i=e.fstatSync(r).size,g.recordSize=10}g.mainBuffer=Buffer.alloc(i),e.readSync(r,g.mainBuffer,0,i,0),e.closeSync(r),g.lastLine=i/g.recordSize-1,g.lastIP=g.mainBuffer.readUInt32BE(g.lastLine*g.recordSize+4),g.firstIP=g.mainBuffer.readUInt32BE(0)}}function h(t){let r,i;const a=JSON.parse(JSON.stringify(I));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(S.city6,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(S.country6,'r',((n,o)=>{n?t(n):(r=o,e.fstat(r,((e,r)=>{i=r.size,a.recordSize=34,t()})))}))}else t()}))},()=>{a.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,a.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(a.lastLine=i/a.recordSize-1,E=a),t(e)}))}]);else{try{if(r=e.openSync(S.city6,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'}}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(S.country6,'r'),i=e.fstatSync(r).size,E.recordSize=34}E.mainBuffer=Buffer.alloc(i),e.readSync(r,E.mainBuffer,0,i,0),e.closeSync(r),E.lastLine=i/E.recordSize-1}}module.exports={cmp:s,lookup:e=>{if(!e)return null;if('number'==typeof e)return z(e);if(4===t(e))return z(i(e));if(6===t(e)){const t=(e=>{const t=e.toUpperCase();for(let e=0;e<N.length;e++){const r=N[e];if(0===t.indexOf(r))return t.substring(r.length)}return null})(e);return t?z(i(t)):(e=>{const t=E.mainBuffer,r=E.recordSize,n=g.locationBuffer,i=g.locationRecordSize,a=(e,n)=>{let i;const a=[];for(i=0;i<2;i++)a.push(t.readUInt32BE(e*r+16*n+4*i));return a};E.lastIP=a(E.lastLine,1),E.firstIP=a(0,0);let c,f,s=0,l=E.lastIP,u=E.lastLine,d=E.firstIP;if(o(e,E.lastIP)>0||o(e,E.firstIP)<0)return null;for(;;){if(c=Math.round((u-s)/2)+s,l=a(c,0),d=a(c,1),o(l,e)<=0&&o(d,e)>=0)return 34===r?m.country=t.toString('utf8',c*r+32,c*r+34).replace(/\u0000.*/,''):(f=t.readUInt32BE(c*r+32),-1>>>0>f&&(m.country=n.toString('utf8',f*i,f*i+2).replace(/\u0000.*/,''),m.region=n.toString('utf8',f*i+2,f*i+5).replace(/\u0000.*/,''),m.metro=n.readInt32BE(f*i+5),m.ll[0]=t.readInt32BE(c*r+36)/1e4,m.ll[1]=t.readInt32BE(c*r+40)/1e4,m.area=t.readUInt32BE(c*r+44),m.eu=n.toString('utf8',f*i+9,f*i+10).replace(/\u0000.*/,''),m.timezone=n.toString('utf8',f*i+10,f*i+42).replace(/\u0000.*/,''),m.city=n.toString('utf8',f*i+42,f*i+i).replace(/\u0000.*/,''))),m;if(s===u)return null;s===u-1?c===s?s=u:u=s:o(l,e)>0?u=c:o(d,e)<0&&(s=c)}})(a(e))}return null},pretty:e=>'string'==typeof e?e:'number'==typeof e?c(e):Array.isArray(e)?f(e):e,startWatchingDataUpdate:e=>{l.makeFsWatchFilter(d,y,6e4,(async()=>{await n.series([e=>{P(e)},e=>{h(e)}],e)}))},stopWatchingDataUpdate:()=>{l.stopWatching(d)},clear:()=>{g=JSON.parse(JSON.stringify(B)),E=JSON.parse(JSON.stringify(I))},reloadDataSync:()=>{P(),h()},reloadData:async e=>{await n.series([e=>{P(e)},e=>{h(e)}],e)},version:u},P(),h();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geoip-lite2",
3
- "version": "2.1.31",
3
+ "version": "2.1.32",
4
4
  "description": "A light weight native JavaScript implementation of GeoIP API from MaxMind. Improved and faster version by Sefinek.",
5
5
  "keywords": [
6
6
  "city",
@@ -47,7 +47,7 @@
47
47
  "version": "node test/version.js"
48
48
  },
49
49
  "dependencies": {
50
- "adm-zip": "^0.5.10",
50
+ "adm-zip": "^0.5.12",
51
51
  "async": "^3.2.5",
52
52
  "iconv-lite": "0.6.3",
53
53
  "ip-address": "^9.0.5",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "devDependencies": {
58
58
  "jest": "^29.7.0",
59
- "terser": "^5.29.1"
59
+ "terser": "^5.30.3"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=10.3.0"
@@ -1 +1 @@
1
- const e=require('../lib/main.js');describe('GeoIP2',(()=>{describe('#testLookup()',(()=>{it('should return data about IPv4',(()=>{const t=e.lookup('1.1.1.1');expect(t).toBeTruthy()})),it('should return data about IPv6',(()=>{const t=e.lookup('2606:4700:4700::64');expect(t).toBeTruthy()}))})),describe('#testDataIP4()',(()=>{it('should match data for IPv4 - US',(()=>{const t=e.lookup('72.229.28.185');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('US'),expect(t.region).toBe('NY'),expect(t.eu).toBe('0'),expect(t.timezone).toBe('America/New_York'),expect(t.city).toBe('New York'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(501),expect(t.area).toBe(200)})),it('should match data for IPv4 - JP',(()=>{const t=e.lookup('210.138.184.59');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('JP'),expect(t.region).toBe('13'),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Asia/Tokyo'),expect(t.city).toBe(''),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(200)})),it('should match data for IPv4 - PL',(()=>{const t=e.lookup('104.113.255.255');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('PL'),expect(t.region).toBe('14'),expect(t.eu).toBe('1'),expect(t.timezone).toBe('Europe/Warsaw'),expect(t.city).toBe('Warsaw'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(20)})),it('should match data for IPv4 - RU',(()=>{const t=e.lookup('109.108.63.255');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('RU'),expect(t.region).toBe('IVA'),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Europe/Moscow'),expect(t.city).toBe('Ivanovo'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(50)}))})),describe('#testDataIP6()',(()=>{it('should match data for IPv6',(()=>{const t=e.lookup('2001:1c04:400::1');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('NL'),expect(t.region).toBe('NH'),expect(t.eu).toBe('1'),expect(t.timezone).toBe('Europe/Amsterdam'),expect(t.city).toBe('Zandvoort'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(5)})),it('should match data for IPv4 - JP',(()=>{const t=e.lookup('2400:8500:1302:814:a163:44:173:238f');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('JP'),expect(t.region).toBe(''),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Asia/Tokyo'),expect(t.city).toBe(''),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(500)})),it('should match data for IPv4 - JP',(()=>{const t=e.lookup('1.79.255.115');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('JP'),expect(t.region).toBe(''),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Asia/Tokyo'),expect(t.city).toBe(''),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(500)}))})),describe('#testUTF8()',(()=>{it('should return UTF8 city name',(()=>{const t=e.lookup('2.139.175.1');expect(t).toBeTruthy(),expect(t.city).toBe('Madrid')}))})),describe('#testMetro()',(()=>{it('should match metro data',(()=>{const t=e.lookup('23.240.63.68');expect(t.metro).toBe(803)}))})),describe('#testIPv4MappedIPv6()',(()=>{it('should match IPv4 mapped IPv6 data',(()=>{const t=e.lookup('195.16.170.74');expect(t.metro).toBe(0)}))})),describe('#testSyncReload()',(()=>{it('should reload data synchronously',(()=>{const t=e.lookup('75.82.117.180');expect(t).not.toBeNull();const o=e.lookup('::ffff:173.185.182.82');expect(o).not.toBeNull(),e.clear();const c=e.lookup('75.82.117.180');expect(c).toBeNull();const l=e.lookup('::ffff:173.185.182.82');expect(l).toBeNull(),e.reloadDataSync();const p=e.lookup('75.82.117.180');expect(t).toEqual(p);const r=e.lookup('::ffff:173.185.182.82');expect(o).toEqual(r)}))})),describe('#testAsyncReload()',(()=>{it('should reload data asynchronously',(t=>{const o=e.lookup('75.82.117.180');expect(o).not.toBeNull();const c=e.lookup('::ffff:173.185.182.82');expect(c).not.toBeNull(),e.clear();const l=e.lookup('75.82.117.180');expect(l).toBeNull();const p=e.lookup('::ffff:173.185.182.82');expect(p).toBeNull(),e.reloadData((()=>{const l=e.lookup('75.82.117.180');expect(o).toEqual(l);const p=e.lookup('::ffff:173.185.182.82');expect(c).toEqual(p),t()}))}))})),describe('#testInvalidIP()',(()=>{it('should return null for an invalid IP address',(()=>{const t=e.lookup('invalid_ip_address');expect(t).toBeNull()}))})),describe('#testEmptyIP()',(()=>{it('should return null for an empty IP address',(()=>{const t=e.lookup('');expect(t).toBeNull()}))})),describe('#testNullIP()',(()=>{it('should return null for a null IP address',(()=>{const t=e.lookup(null);expect(t).toBeNull()}))})),describe('#testUnknownIP()',(()=>{it('should return null for an unknown IP address',(()=>{const t=e.lookup('192.168.1.1');expect(t).toBeNull()}))})),describe('#testNoDataForIP()',(()=>{it('should return null for an IP address with no data',(()=>{const t=e.lookup('203.0.113.0');expect(t).toBeNull()}))})),describe('#testSpecialCharactersIP()',(()=>{it('should return null for an IP address with special characters',(()=>{const t=e.lookup('1.2.3.@');expect(t).toBeNull()}))}))}));
1
+ const e=require('../lib/main.js');describe('GeoIP2',(()=>{describe('#testLookup()',(()=>{it('should return data about IPv4',(()=>{const t=e.lookup('1.1.1.1');expect(t).toBeTruthy()})),it('should return data about IPv6',(()=>{const t=e.lookup('2606:4700:4700::64');expect(t).toBeTruthy()}))})),describe('#testDataIP4()',(()=>{it('should match data for IPv4 - US',(()=>{const t=e.lookup('72.229.28.185');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('US'),expect(t.region).toBe('NY'),expect(t.eu).toBe('0'),expect(t.timezone).toBe('America/New_York'),expect(t.city).toBe('New York'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(501),expect(t.area).toBe(5)})),it('should match data for IPv4 - JP',(()=>{const t=e.lookup('210.138.184.59');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('JP'),expect(t.region).toBe('13'),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Asia/Tokyo'),expect(t.city).toBe(''),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(200)})),it('should match data for IPv4 - PL',(()=>{const t=e.lookup('104.113.255.255');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('PL'),expect(t.region).toBe('14'),expect(t.eu).toBe('1'),expect(t.timezone).toBe('Europe/Warsaw'),expect(t.city).toBe('Warsaw'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(20)})),it('should match data for IPv4 - RU',(()=>{const t=e.lookup('109.108.63.255');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('RU'),expect(t.region).toBe('IVA'),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Europe/Moscow'),expect(t.city).toBe('Ivanovo'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(50)}))})),describe('#testDataIP6()',(()=>{it('should match data for IPv6',(()=>{const t=e.lookup('2001:1c04:400::1');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('NL'),expect(t.region).toBe('NH'),expect(t.eu).toBe('1'),expect(t.timezone).toBe('Europe/Amsterdam'),expect(t.city).toBe('Zandvoort'),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(5)})),it('should match data for IPv4 - JP',(()=>{const t=e.lookup('2400:8500:1302:814:a163:44:173:238f');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('JP'),expect(t.region).toBe(''),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Asia/Tokyo'),expect(t.city).toBe(''),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(500)})),it('should match data for IPv4 - JP',(()=>{const t=e.lookup('1.79.255.115');expect(void 0!==t.range).toBe(!0),expect(t.country).toBe('JP'),expect(t.region).toBe(''),expect(t.eu).toBe('0'),expect(t.timezone).toBe('Asia/Tokyo'),expect(t.city).toBe(''),expect(t.ll).toBeTruthy(),expect(t.metro).toBe(0),expect(t.area).toBe(500)}))})),describe('#testUTF8()',(()=>{it('should return UTF8 city name',(()=>{const t=e.lookup('2.139.175.1');expect(t).toBeTruthy(),expect(t.city).toBe('Madrid')}))})),describe('#testMetro()',(()=>{it('should match metro data',(()=>{const t=e.lookup('23.240.63.68');expect(t.metro).toBe(803)}))})),describe('#testIPv4MappedIPv6()',(()=>{it('should match IPv4 mapped IPv6 data',(()=>{const t=e.lookup('195.16.170.74');expect(t.metro).toBe(0)}))})),describe('#testSyncReload()',(()=>{it('should reload data synchronously',(()=>{const t=e.lookup('75.82.117.180');expect(t).not.toBeNull();const o=e.lookup('::ffff:173.185.182.82');expect(o).not.toBeNull(),e.clear();const c=e.lookup('75.82.117.180');expect(c).toBeNull();const l=e.lookup('::ffff:173.185.182.82');expect(l).toBeNull(),e.reloadDataSync();const p=e.lookup('75.82.117.180');expect(t).toEqual(p);const r=e.lookup('::ffff:173.185.182.82');expect(o).toEqual(r)}))})),describe('#testAsyncReload()',(()=>{it('should reload data asynchronously',(t=>{const o=e.lookup('75.82.117.180');expect(o).not.toBeNull();const c=e.lookup('::ffff:173.185.182.82');expect(c).not.toBeNull(),e.clear();const l=e.lookup('75.82.117.180');expect(l).toBeNull();const p=e.lookup('::ffff:173.185.182.82');expect(p).toBeNull(),e.reloadData((()=>{const l=e.lookup('75.82.117.180');expect(o).toEqual(l);const p=e.lookup('::ffff:173.185.182.82');expect(c).toEqual(p),t()}))}))})),describe('#testInvalidIP()',(()=>{it('should return null for an invalid IP address',(()=>{const t=e.lookup('invalid_ip_address');expect(t).toBeNull()}))})),describe('#testEmptyIP()',(()=>{it('should return null for an empty IP address',(()=>{const t=e.lookup('');expect(t).toBeNull()}))})),describe('#testNullIP()',(()=>{it('should return null for a null IP address',(()=>{const t=e.lookup(null);expect(t).toBeNull()}))})),describe('#testUnknownIP()',(()=>{it('should return null for an unknown IP address',(()=>{const t=e.lookup('192.168.1.1');expect(t).toBeNull()}))})),describe('#testNoDataForIP()',(()=>{it('should return null for an IP address with no data',(()=>{const t=e.lookup('203.0.113.0');expect(t).toBeNull()}))})),describe('#testSpecialCharactersIP()',(()=>{it('should return null for an IP address with special characters',(()=>{const t=e.lookup('1.2.3.@');expect(t).toBeNull()}))}))}));