geoip-lite2 2.1.0 → 2.1.1

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.
package/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .idea
2
+ node_modules
3
+ tmp
package/AUTHORS ADDED
@@ -0,0 +1,2 @@
1
+ Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)
2
+ Arturs Sosins <@ar2rsawseen>
package/README.md CHANGED
@@ -1,9 +1,17 @@
1
- 🗺️ GeoIP-Lite2 v2.1.0 - Now even faster!
1
+ 🗺️ GeoIP-Lite2 v2.1 - Now even faster!
2
2
  ==========
3
3
  A native Node.js API for the GeoLite data from MaxMind.
4
4
 
5
5
  This product includes GeoLite data created by MaxMind, available from: https://www.maxmind.com
6
6
 
7
+ <a href="https://www.npmjs.com/package/geoip-lite2" target="_blank" title="geoip-lite2 - npm" style="text-decoration:none">
8
+ <img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads">
9
+ <img src="https://img.shields.io/github/last-commit/sefinek24/geoip-lite2" alt="Last commit">
10
+ <img src="https://img.shields.io/github/issues/sefinek24/geoip-lite2" alt="Issues">
11
+ <img src="https://img.shields.io/github/commit-activity/w/sefinek24/geoip-lite2" alt="Commit activity">
12
+ <img src="https://img.shields.io/github/languages/code-size/sefinek24/geoip-lite2" alt="Code size">
13
+ </a>
14
+
7
15
  🚀 Improved GeoIP Module by [Sefinek](https://sefinek.net)
8
16
  ------------
9
17
  This module is an improved and updated edition of [geoip-lite](https://github.com/geoip-lite/node-geoip), thoughtfully designed to meet the latest programming standards.
package/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ declare module 'geoip-lite2' {
2
+ export const cmp: number | any | null
3
+
4
+ export type GeoData = {
5
+ range: [number, number];
6
+ country: string;
7
+ region: string;
8
+ eu: string;
9
+ timezone: string;
10
+ city: string;
11
+ ll: [number, number];
12
+ metro: number;
13
+ area: number;
14
+ };
15
+
16
+ export function lookup(ip: string): GeoData | null;
17
+
18
+ export const pretty: (n: string | number | number[]) => string;
19
+ export const startWatchingDataUpdate: (callback: () => void) => void;
20
+ export const reloadDataSync: () => void;
21
+ export const reloadData: (callback: () => void) => void;
22
+ export const version: string;
23
+ }
package/package.json CHANGED
@@ -1,72 +1,74 @@
1
- {
2
- "name": "geoip-lite2",
3
- "version": "2.1.0",
4
- "description": "A light weight native JavaScript implementation of GeoIP API from MaxMind.",
5
- "keywords": [
6
- "city",
7
- "country",
8
- "fast-geoip",
9
- "geo",
10
- "geoip",
11
- "geolite",
12
- "geolite2",
13
- "geolocation",
14
- "geolookup",
15
- "ip",
16
- "ipv4",
17
- "ipv6",
18
- "location",
19
- "maxmind",
20
- "region",
21
- "state"
22
- ],
23
- "homepage": "https://github.com/sefinek24/geoip-lite2",
24
- "bugs": {
25
- "url": "https://github.com/sefinek24/geoip-lite2/issues"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/sefinek24/geoip-lite2.git"
30
- },
31
- "license": "Apache-2.0",
32
- "author": "Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)",
33
- "main": "lib/geoip.js",
34
- "types": "index.d.ts",
35
- "directories": {
36
- "lib": "lib",
37
- "test": "test"
38
- },
39
- "files": [
40
- "lib/",
41
- "data/",
42
- "test/",
43
- "scripts/"
44
- ],
45
- "scripts": {
46
- "eslint": "eslint .",
47
- "minify-linux": "bash _Minify/linux.bash",
48
- "minify-win": "powershell.exe -ExecutionPolicy Bypass .\\_Minify\\windows.ps1",
49
- "test": "mocha test/main.js",
50
- "up": "ncu -u -x chalk && npm install && npm update && npm audit fix",
51
- "updatedb": "node scripts/updatedb.js",
52
- "updatedb-debug": "node scripts/updatedb.js debug",
53
- "updatedb-force": "node scripts/updatedb.js force"
54
- },
55
- "dependencies": {
56
- "adm-zip": "^0.5.10",
57
- "async": "^3.2.4",
58
- "chalk": "4.1.2",
59
- "iconv-lite": "0.6.3",
60
- "ip-address": "^8.1.0",
61
- "lazy": "1.0.11",
62
- "rimraf": "^5.0.1"
63
- },
64
- "devDependencies": {
65
- "eslint": "^8.48.0",
66
- "mocha": "^10.2.0",
67
- "terser": "^5.19.4"
68
- },
69
- "engines": {
70
- "node": ">=5.10.0"
71
- }
72
- }
1
+ {
2
+ "name": "geoip-lite2",
3
+ "version": "2.1.1",
4
+ "description": "A light weight native JavaScript implementation of GeoIP API from MaxMind.",
5
+ "keywords": [
6
+ "city",
7
+ "country",
8
+ "fast-geoip",
9
+ "geo",
10
+ "geoip",
11
+ "geolite",
12
+ "geolite2",
13
+ "geolocation",
14
+ "geolookup",
15
+ "ip",
16
+ "ipv4",
17
+ "ipv6",
18
+ "location",
19
+ "maxmind",
20
+ "region",
21
+ "state"
22
+ ],
23
+ "homepage": "https://github.com/sefinek24/geoip-lite2",
24
+ "bugs": {
25
+ "url": "https://github.com/sefinek24/geoip-lite2/issues"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/sefinek24/geoip-lite2.git"
30
+ },
31
+ "license": "Apache-2.0",
32
+ "author": "Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)",
33
+ "main": "lib/geoip.js",
34
+ "types": "index.d.ts",
35
+ "directories": {
36
+ "data": "data",
37
+ "lib": "lib",
38
+ "scripts": "scripts",
39
+ "test": "test"
40
+ },
41
+ "files": [
42
+ ".gitignore",
43
+ "AUTHORS",
44
+ "index.d.ts",
45
+ "LICENSE"
46
+ ],
47
+ "scripts": {
48
+ "eslint": "eslint .",
49
+ "minify-linux": "echo \"Not finished yet >:\"",
50
+ "minify-win": "powershell.exe -ExecutionPolicy Bypass .\\_Minify\\windows.ps1",
51
+ "test": "mocha test/main.js",
52
+ "up": "ncu -u -x chalk && npm install && npm update && npm audit fix",
53
+ "updatedb": "node scripts/updatedb.js",
54
+ "updatedb-debug": "node scripts/updatedb.js debug",
55
+ "updatedb-force": "node scripts/updatedb.js force"
56
+ },
57
+ "dependencies": {
58
+ "adm-zip": "^0.5.10",
59
+ "async": "^3.2.4",
60
+ "chalk": "4.1.2",
61
+ "iconv-lite": "0.6.3",
62
+ "ip-address": "^8.1.0",
63
+ "lazy": "1.0.11",
64
+ "rimraf": "^5.0.1"
65
+ },
66
+ "devDependencies": {
67
+ "eslint": "^8.49.0",
68
+ "mocha": "^10.2.0",
69
+ "terser": "^5.19.4"
70
+ },
71
+ "engines": {
72
+ "node": ">=5.10.0"
73
+ }
74
+ }
@@ -1 +0,0 @@
1
- 13ea583a2a90502c4f64e9050630d640883b01dfaa3a5c8a3277131926e9d88c GeoLite2-City-CSV_20230906.zip
@@ -1 +0,0 @@
1
- 1c5f3ce35af7f3dd1fbe41ca343e8d9c737c83cba601d86be929acc7b6d5d843 GeoLite2-Country-CSV_20230906.zip
Binary file
Binary file
Binary file
Binary file
Binary file
package/lib/fsWatcher.js DELETED
@@ -1 +0,0 @@
1
- const n=require('node:fs'),t=require('node:path'),e={};function o(n){e[n].close()}module.exports.makeFsWatchFilter=function(u,l,i,c,s){let r=null;function f(){r=null,s()}'function'==typeof c&&(s=c,c=i,i=null),e[u]&&o(u),e[u]=n.watch(l,(function(e,o){if(!o)return;const u=t.join(l,o);i&&i!==o||n.exists(u,(function(n){n&&(null!==r&&(clearTimeout(r),r=null),r=setTimeout(f,c))}))}))},module.exports.stopWatching=o;
package/lib/utils.js DELETED
@@ -1 +0,0 @@
1
- const t=module.exports={};t.aton4=function(t){return t=t.split(/\./),(parseInt(t[0],10)<<24>>>0)+(parseInt(t[1],10)<<16>>>0)+(parseInt(t[2],10)<<8>>>0)+(parseInt(t[3],10)>>>0)},t.aton6=function(t){const n=(t=t.replace(/"/g,'').split(/:/)).length-1;let r;if(''===t[n]&&(t[n]=0),n<7)for(t.length=8,r=n;r>=0&&''!==t[r];r--)t[7-n+r]=t[r];for(r=0;r<8;r++)t[r]?t[r]=parseInt(t[r],16):t[r]=0;const e=[];for(r=0;r<4;r++)e.push((t[2*r]<<16)+t[2*r+1]>>>0);return e},t.cmp=function(t,n){return'number'==typeof t&&'number'==typeof n?t<n?-1:t>n?1:0:t instanceof Array&&n instanceof Array?this.cmp6(t,n):null},t.cmp6=function(t,n){for(let r=0;r<2;r++){if(t[r]<n[r])return-1;if(t[r]>n[r])return 1}return 0},t.isPrivateIP=function(t){return null!=(t=t.toString()).match(/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^172\.16\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^fc00:/)||null!=t.match(/^fe80:/)},t.ntoa4=function(t){return t=((t=t.toString())>>>24&255)+'.'+(t>>>16&255)+'.'+(t>>>8&255)+'.'+(255&t)},t.ntoa6=function(t){let n='[';for(let r=0;r<t.length;r++)n+=(t[r]>>>16).toString(16)+':',n+=(65535&t[r]).toString(16)+':';return n=n.replace(/:$/,']').replace(/:0+/g,':').replace(/::+/,'::'),n};
@@ -1 +0,0 @@
1
- 'use strict';const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://sefinek.net)`,o=require('node:fs'),r=require('node:http'),i=require('node:https'),s=require('node:path'),c=require('node:url'),l=require('node:zlib');o.existsSync=o.existsSync||s.existsSync;const a=require('async'),u=require('chalk'),d=require('iconv-lite'),p=require('lazy'),f=require('rimraf').sync,g=require('adm-zip'),m=require('../lib/utils.js'),{Address6:h,Address4:w}=require('ip-address'),y=process.argv.slice(2);let S=y.find((function(e){return null!==e.match(/^license_key=[a-zA-Z0-9]+/)}));void 0===S&&void 0!==process.env.LICENSE_KEY&&(S='license_key='+process.env.LICENSE_KEY);let v=y.find((function(e){return null!==e.match(/^geoDataDir=[\w./]+/)}));void 0===v&&void 0!==process.env.GEODATADIR&&(v='geoDataDir='+process.env.GEODATADIR);let x=s.resolve(__dirname,'..','data');void 0!==v&&(x=s.resolve(process.cwd(),v.split('=')[1]),o.existsSync(x)||(console.log(u.red('ERROR')+': Directory doesn\'t exist: '+x),process.exit(1)));const E=s.resolve(__dirname,'..','tmp'),k={},I={},D=[{type:'country',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-Country-CSV.zip',src:['GeoLite2-Country-Locations-en.csv','GeoLite2-Country-Blocks-IPv4.csv','GeoLite2-Country-Blocks-IPv6.csv'],dest:['','geoip-country.dat','geoip-country6.dat']},{type:'city',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-City-CSV.zip',src:['GeoLite2-City-Locations-en.csv','GeoLite2-City-Blocks-IPv4.csv','GeoLite2-City-Blocks-IPv6.csv'],dest:['geoip-city-names.dat','geoip-city.dat','geoip-city6.dat']}];function C(e){const t=s.dirname(e);o.existsSync(t)||o.mkdirSync(t)}function R(e){const t=/^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;if(!t.test(e)&&(e=function(e){let t=0,n=-1;for(e=e.replace(/""/,'\\"').replace(/'/g,'\\\'');t<e.length&&n<e.length;)t=n,n=e.indexOf(',',t+1),n<0&&(n=e.length),e.indexOf('\'',t||0)>-1&&e.indexOf('\'',t)<n&&'"'!=e[t+1]&&'"'!=e[n-1]&&(n=(e=e.substr(0,t+1)+'"'+e.substr(t+1,n-t-1)+'"'+e.substr(n,e.length-n)).indexOf(',',n+1),n<0&&(n=e.length));return e}(e),!t.test(e)))return null;const n=[];return e.replace(/(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g,(function(e,t,o,r){return void 0!==t?n.push(t.replace(/\\'/g,'\'')):void 0!==o?n.push(o.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==r&&n.push(r),''})),/,\s*$/.test(e)&&n.push(''),n}function B(e){const t=c.parse(e);if(t.headers={'User-Agent':n},process.env.http_proxy||process.env.https_proxy)try{const e=require('node:https-proxy-agent');t.agent=new e(process.env.http_proxy||process.env.https_proxy)}catch(e){console.error('Install https-proxy-agent to use an HTTP/HTTPS proxy'),process.exit(-1)}return t}function _(e,t){if(-1!==y.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);o.readFile(s.join(x,e.type+'.checksum'),{encoding:'utf8'},(function(o,s){!o&&s&&s.length&&(e.checkValue=s),console.log('Checking ',e.fileName);var c=i.get(B(n),(function(n){const o=n.statusCode;200!==o&&(console.log(u.red('ERROR')+n.data),console.log(u.red('ERROR')+': HTTP Request Failed [%d %s]',o,r.STATUS_CODES[o]),c.abort(),process.exit(1));let i='';n.on('data',(function(e){i+=e})),n.on('end',(function(){i&&i.length?i==e.checkValue?(console.log(u.green('Database "'+e.type+'" is up to date')),e.skip=!0):(console.log(u.green('Database '+e.type+' has new data')),e.checkValue=i):(console.log(u.red('ERROR')+': Could not retrieve checksum for',e.type,u.red('Aborting')),console.log('Run with "force" to update without checksum'),c.abort(),process.exit(1)),t(null,e)}))}))}))}function b(e,t){if(e.skip)return t(null,null,null,e);const n=e.url;let c=e.fileName;const a='.gz'===s.extname(c);a&&(c=c.replace('.gz',''));const d=s.join(E,c);if(o.existsSync(d))return t(null,d,c,e);console.log('Fetching ',c),C(d);var p=i.get(B(n),(function(n){const i=n.statusCode;let s;200!==i&&(console.error(u.red('ERROR')+': HTTP Request Failed [%d %s]',i,r.STATUS_CODES[i]),p.abort(),process.exit(1));const f=o.createWriteStream(d);s=a?n.pipe(l.createGunzip()).pipe(f):n.pipe(f),s.on('close',(function(){console.log(u.green(' DONE')),t(null,d,c,e)}))}));process.stdout.write('Retrieving '+c+'...')}function A(e,t,n,r){if(n.skip)return r(null,n);if('.zip'!==s.extname(t))r(null,n);else{process.stdout.write('Extracting '+t+'...');new g(e).getEntries().forEach((e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],r=s.join(E,n);o.writeFileSync(r,e.getData())})),console.log(u.green(' DONE')),r(null,n)}}function O(e,t,n){let r=0;const i=s.join(x,t),c=s.join(E,e);f(i),C(i),process.stdout.write('Processing data (may take a moment)...');var l=Date.now(),a=o.openSync(i,'w');p(o.createReadStream(c)).lines.map((function(e){return d.decode(e,'latin1')})).skip(1).map((function(e){const t=R(e);if(!t||t.length<6)return void console.warn('weird line: %s::',e);let n,i,s;r++;const c=k[t[1]];let u,d,p;if(c){if(t[0].match(/:/)){for(d=34,s=new h(t[0]),n=m.aton6(s.startAddress().correctForm()),i=m.aton6(s.endAddress().correctForm()),u=Buffer.alloc(d),p=0;p<n.length;p++)u.writeUInt32BE(n[p],4*p);for(p=0;p<i.length;p++)u.writeUInt32BE(i[p],16+4*p)}else d=10,s=new w(t[0]),n=parseInt(s.startAddress().bigInteger(),10),i=parseInt(s.endAddress().bigInteger(),10),u=Buffer.alloc(d),u.fill(0),u.writeUInt32BE(n,0),u.writeUInt32BE(i,4);u.write(c,d-2),o.writeSync(a,u,0,d,null),Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+r+')...'))}})).on('pipe',(function(){console.log(u.green(' DONE')),n()}))}function q(e,t,n){let r=0;const i=s.join(x,t),c=s.join(E,e);f(i),process.stdout.write('Processing Data (may take a moment) ...');var l=Date.now(),a=o.openSync(i,'w');p(o.createReadStream(c)).lines.map((function(e){return d.decode(e,'latin1')})).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=R(e);if(!t)return void console.warn('weird line: %s::',e);let n,i,s,c,u,d,p,f,g,y;if(r++,t[0].match(/:/)){let e=0;for(d=48,s=new h(t[0]),n=m.aton6(s.startAddress().correctForm()),i=m.aton6(s.endAddress().correctForm()),c=parseInt(t[1],10),c=I[c],u=Buffer.alloc(d),u.fill(0),y=0;y<n.length;y++)u.writeUInt32BE(n[y],e),e+=4;for(y=0;y<i.length;y++)u.writeUInt32BE(i[y],e),e+=4;u.writeUInt32BE(c>>>0,32),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),u.writeInt32BE(p,36),u.writeInt32BE(f,40),u.writeInt32BE(g,44)}else d=24,s=new w(t[0]),n=parseInt(s.startAddress().bigInteger(),10),i=parseInt(s.endAddress().bigInteger(),10),c=parseInt(t[1],10),c=I[c],u=Buffer.alloc(d),u.fill(0),u.writeUInt32BE(n>>>0,0),u.writeUInt32BE(i>>>0,4),u.writeUInt32BE(c>>>0,8),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),u.writeInt32BE(p,12),u.writeInt32BE(f,16),u.writeInt32BE(g,20);o.writeSync(a,u,0,u.length,null),Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+r+')...'))})).on('pipe',n)}function L(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,i=e.dest;'country'===n?Array.isArray(r)?function(e,t){const n=s.join(E,e);process.stdout.write('Processing Lookup Data (may take a moment)...'),p(o.createReadStream(n)).lines.map((function(e){return d.decode(e,'latin1')})).skip(1).map((function(e){const t=R(e);!t||t.length<6?console.log('weird line: %s::',e):k[t[0]]=t[4]})).on('pipe',(function(){console.log(u.green(' DONE')),t()}))}(r[0],(function(){O(r[1],i[1],(function(){O(r[2],i[2],(function(){t(null,e)}))}))})):O(r,i,(function(){t(null,e)})):'city'===n&&function(e,t,n){let r=null,i=0;const c=s.join(x,t),l=s.join(E,e);f(c);var a=o.openSync(c,'w');p(o.createReadStream(l)).lines.map((function(e){return d.decode(e,'utf-8')})).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=R(e);if(!n)return void console.warn('weird line: %s::',e);r=parseInt(n[0]),I[r]=i;const s=n[4],c=n[6],l=n[10],u=parseInt(n[11]),d=n[12],p=n[13];t.fill(0),t.write(s,0),t.write(c,2),u&&t.writeInt32BE(u,5),t.write(p,9),t.write(d,10),t.write(l,42),o.writeSync(a,t,0,t.length,null),i++})).on('pipe',n)}(r[0],i[0],(function(){q(r[1],i[1],(function(){console.log('city data processed'),q(r[2],i[2],(function(){console.log(u.green(' DONE')),t(null,e)}))}))}))}function F(e,t){if(e.skip||!e.checkValue)return t();o.writeFile(s.join(x,e.type+'.checksum'),e.checkValue,'utf8',(function(n){n&&console.log(u.red('Failed to Update checksums.'),'Database:',e.type),t()}))}S||(console.error(u.red('ERROR')+': Missing license_key'),process.exit(1)),f(E),C(E),a.eachSeries(D,(function(e,t){a.seq(_,b,A,L,F)(e,t)}),(function(e){e?(console.error(u.red('Failed to Update Databases from MaxMind.'),e),process.exit(1)):(console.log(u.green('Successfully Updated Databases from MaxMind.')),-1!==y.indexOf('debug')?console.log(u.yellow.bold('Notice: temporary files are not deleted for debug purposes.')):f(E),process.exit(0))}));
@@ -1 +0,0 @@
1
- const t=require('assert'),o=+new Date,n=require('../lib/geoip.js'),e=+new Date;if(process.argv.length>2){console.dir(n.lookup(process.argv[2]));const t=+new Date;console.log('Startup: %dms, exec: %dms',e-o,t-e),process.exit(1)}const r=[];let a;const s=3e4,d=[];let h;const i=+new Date;for(let o=0;o<s;o++)a=o%2==0?Math.round(4278190080*Math.random()+16777215):'2001:'+Math.round(65535*Math.random()).toString(16)+':'+Math.round(65535*Math.random()).toString(16)+':'+Math.round(65535*Math.random()).toString(16)+':'+Math.round(65535*Math.random()).toString(16)+':'+Math.round(65535*Math.random()).toString(16)+':'+Math.round(65535*Math.random()).toString(16)+':'+Math.round(65535*Math.random()).toString(16),h=n.lookup(a),null!==h?(r.push([a,h]),t.ok(n.cmp(a,h.range[0])>=0,'Problem with '+n.pretty(a)+' < '+n.pretty(h.range[0])),t.ok(n.cmp(a,h.range[1])<=0,'Problem with '+n.pretty(a)+' > '+n.pretty(h.range[1]))):d.push(a);const g=+new Date;console.log('Found %d (%d/%d) ips in %dms (%s ip/s) (%sμs/ip)',s,r.length,d.length,g-i,(1e3*s/(g-i)).toFixed(3),(1e3*(g-i)/s).toFixed(0)),console.log('Took %d ms to startup',e-o);
package/test/main.js DELETED
@@ -1 +0,0 @@
1
- const t=require('assert'),o=require('../lib/geoip.js');describe('GeoIP2',(function(){describe('#testLookup()',(function(){it('should return data about IPv4',(function(){const u=o.lookup('1.1.1.1');t.ok(u)})),it('should return data about IPv6',(function(){const u=o.lookup('2606:4700:4700::64');t.ok(u)}))})),describe('#testDataIP4()',(function(){it('should match data for IPv4 - US',(function(){const u=o.lookup('72.229.28.185');t.strictEqual(void 0!==u.range,!0),t.strictEqual(u.country,'US'),t.strictEqual(u.region,'NY'),t.strictEqual(u.eu,'0'),t.strictEqual(u.timezone,'America/New_York'),t.strictEqual(u.city,'New York'),t.ok(u.ll),t.strictEqual(u.metro,501),t.strictEqual(u.area,5)})),it('should match data for IPv4 - JP',(function(){const u=o.lookup('210.138.184.59');t.strictEqual(void 0!==u.range,!0),t.strictEqual(u.country,'JP'),t.strictEqual(u.region,'13'),t.strictEqual(u.eu,'0'),t.strictEqual(u.timezone,'Asia/Tokyo'),t.strictEqual(u.city,'Chiyoda-ku'),t.ok(u.ll),t.strictEqual(u.metro,0),t.strictEqual(u.area,200)})),it('should match data for IPv4 - PL',(function(){const u=o.lookup('104.113.255.255');t.strictEqual(void 0!==u.range,!0),t.strictEqual(u.country,'PL'),t.strictEqual(u.region,'14'),t.strictEqual(u.eu,'1'),t.strictEqual(u.timezone,'Europe/Warsaw'),t.strictEqual(u.city,'Warsaw'),t.ok(u.ll),t.strictEqual(u.metro,0),t.strictEqual(u.area,20)})),it('should match data for IPv4 - RU',(function(){const u=o.lookup('109.108.63.255');t.strictEqual(void 0!==u.range,!0),t.strictEqual(u.country,'RU'),t.strictEqual(u.region,'IVA'),t.strictEqual(u.eu,'0'),t.strictEqual(u.timezone,'Europe/Moscow'),t.strictEqual(u.city,'Kineshma'),t.ok(u.ll),t.strictEqual(u.metro,0),t.strictEqual(u.area,200)}))})),describe('#testDataIP6()',(function(){it('should match data for IPv6',(function(){const u=o.lookup('2001:1c04:400::1');t.strictEqual(void 0!==u.range,!0),t.strictEqual(u.country,'NL'),t.strictEqual(u.region,'NH'),t.strictEqual(u.eu,'1'),t.strictEqual(u.timezone,'Europe/Amsterdam'),t.strictEqual(u.city,'Zandvoort'),t.ok(u.ll),t.strictEqual(u.metro,0),t.strictEqual(u.area,5)})),it('should match data for IPv4 - JP',(function(){const u=o.lookup('2400:8500:1302:814:a163:44:173:238f');t.strictEqual(void 0!==u.range,!0),t.strictEqual(u.country,'JP'),t.strictEqual(u.region,''),t.strictEqual(u.eu,'0'),t.strictEqual(u.timezone,'Asia/Tokyo'),t.strictEqual(u.city,''),t.ok(u.ll),t.strictEqual(u.metro,0),t.strictEqual(u.area,500)})),it('should match data for IPv4 - JP',(function(){const u=o.lookup('1.79.255.115');t.strictEqual(void 0!==u.range,!0),t.strictEqual(u.country,'JP'),t.strictEqual(u.region,''),t.strictEqual(u.eu,'0'),t.strictEqual(u.timezone,'Asia/Tokyo'),t.strictEqual(u.city,''),t.ok(u.ll),t.strictEqual(u.metro,0),t.strictEqual(u.area,500)}))})),describe('#testUTF8()',(function(){it('should return UTF8 city name',(function(){const u=o.lookup('2.139.175.1');t.ok(u),t.strictEqual(u.city,'Barbera Del Valles')}))})),describe('#testMetro()',(function(){it('should match metro data',(function(){const u=o.lookup('23.240.63.68');t.strictEqual(u.metro,803)}))})),describe('#testIPv4MappedIPv6()',(function(){it('should match IPv4 mapped IPv6 data',(function(){const u=o.lookup('195.16.170.74');t.strictEqual(u.metro,0)}))})),describe('#testSyncReload()',(function(){it('should reload data synchronously',(function(){const u=o.lookup('75.82.117.180');t.notStrictEqual(u,null);const l=o.lookup('::ffff:173.185.182.82');t.notStrictEqual(l,null),o.clear();const c=o.lookup('75.82.117.180');t.strictEqual(c,null);const r=o.lookup('::ffff:173.185.182.82');t.strictEqual(r,null),o.reloadDataSync();const a=o.lookup('75.82.117.180');t.deepStrictEqual(u,a);const i=o.lookup('::ffff:173.185.182.82');t.deepStrictEqual(l,i)}))})),describe('#testAsyncReload()',(function(){it('should reload data asynchronously',(function(u){const l=o.lookup('75.82.117.180');t.notStrictEqual(l,null);const c=o.lookup('::ffff:173.185.182.82');t.notStrictEqual(c,null),o.clear();const r=o.lookup('75.82.117.180');t.strictEqual(r,null);const a=o.lookup('::ffff:173.185.182.82');t.strictEqual(a,null),o.reloadData((function(){const r=o.lookup('75.82.117.180');t.deepStrictEqual(l,r);const a=o.lookup('::ffff:173.185.182.82');t.deepStrictEqual(c,a),u()}))}))})),describe('#testInvalidIP()',(function(){it('should return null for an invalid IP address',(function(){const u=o.lookup('invalid_ip_address');t.strictEqual(u,null)}))})),describe('#testEmptyIP()',(function(){it('should return null for an empty IP address',(function(){const u=o.lookup('');t.strictEqual(u,null)}))})),describe('#testNullIP()',(function(){it('should return null for a null IP address',(function(){const u=o.lookup(null);t.strictEqual(u,null)}))})),describe('#testUnknownIP()',(function(){it('should return null for an unknown IP address',(function(){const u=o.lookup('192.168.1.1');t.strictEqual(u,null)}))})),describe('#testNoDataForIP()',(function(){it('should return null for an IP address with no data',(function(){const u=o.lookup('203.0.113.0');t.strictEqual(u,null)}))})),describe('#testSpecialCharactersIP()',(function(){it('should return null for an IP address with special characters',(function(){const u=o.lookup('1.2.3.@');t.strictEqual(u,null)}))}))}));
@@ -1 +0,0 @@
1
- require('../lib/geoip.js');console.log(process.memoryUsage());
package/test/one.js DELETED
@@ -1 +0,0 @@
1
- const o=require('../lib/geoip.js').lookup('2003:6:2184:e6d5:5991:6779:38be:654');console.log(o);
package/test/version.js DELETED
@@ -1 +0,0 @@
1
- const o=require('../lib/geoip.js');console.log(o.version);