@k03mad/ip2geo 1.0.0 → 2.0.0

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/README.md CHANGED
@@ -24,7 +24,7 @@ const {
24
24
  } = await ip2geo('1.1.1.1', {
25
25
  // defaults
26
26
  cacheDir: 'geoip',
27
- cacheFileName: 'ip.log',
27
+ cacheFileName: 'ips.log',
28
28
  cacheFileSeparator: ';;',
29
29
  cacheFileNewline: '\n',
30
30
  });
package/app/lib/ip2geo.js CHANGED
@@ -13,15 +13,18 @@ const debug = _debug('mad:geoip');
13
13
  * @property {string} [country]
14
14
  * @property {string} [countryA2]
15
15
  * @property {string} [city]
16
+ * @property {string} [region]
17
+ * @property {string} [org]
16
18
  * @property {string} [isp]
19
+ * @property {string} [ispDomain]
17
20
  */
18
21
 
19
22
  const API = 'https://ipwho.is/';
20
23
 
21
- const CACHE_FILE_DIR = 'geoip';
22
- const CACHE_FILE_NAME = 'ip.log';
23
- const CACHE_FILE_SEPARATOR = ';;';
24
- const CACHE_FILE_NEWLINE = '\n';
24
+ const DEFAULT_CACHE_FILE_DIR = 'geoip';
25
+ const DEFAULT_CACHE_FILE_NAME = 'ips.log';
26
+ const DEFAULT_CACHE_FILE_SEPARATOR = ';;';
27
+ const DEFAULT_CACHE_FILE_NEWLINE = '\n';
25
28
 
26
29
  const cacheMap = new Map();
27
30
 
@@ -30,8 +33,11 @@ const outputKeys = [
30
33
  'emoji',
31
34
  'country',
32
35
  'countryA2',
36
+ 'region',
33
37
  'city',
38
+ 'org',
34
39
  'isp',
40
+ 'ispDomain',
35
41
  ];
36
42
 
37
43
  /**
@@ -106,10 +112,10 @@ const writeToFsCache = async (ip, data, cacheDir, cacheFileName, cacheFileSepara
106
112
  * @returns {Promise<GeoIpOutput>}
107
113
  */
108
114
  export default async (ip = '', {
109
- cacheDir = CACHE_FILE_DIR,
110
- cacheFileName = CACHE_FILE_NAME,
111
- cacheFileSeparator = CACHE_FILE_SEPARATOR,
112
- cacheFileNewline = CACHE_FILE_NEWLINE,
115
+ cacheDir = DEFAULT_CACHE_FILE_DIR,
116
+ cacheFileName = DEFAULT_CACHE_FILE_NAME,
117
+ cacheFileSeparator = DEFAULT_CACHE_FILE_SEPARATOR,
118
+ cacheFileNewline = DEFAULT_CACHE_FILE_NEWLINE,
113
119
  } = {}) => {
114
120
  if (ip) {
115
121
  const ipData = cacheMap.get(ip);
@@ -145,8 +151,11 @@ export default async (ip = '', {
145
151
  body?.flag?.emoji,
146
152
  body?.country,
147
153
  body?.country_code,
154
+ body?.region,
148
155
  body?.city,
156
+ body?.connection?.org,
149
157
  body?.connection?.isp,
158
+ body?.connection?.domain,
150
159
  ];
151
160
 
152
161
  const outputData = collectOutputData(usedData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/ip2geo",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "GeoIP library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -7,7 +7,7 @@ import {checkCacheFile, removeCacheFolder} from './shared/fs.js';
7
7
 
8
8
  describe('opts-assigned', () => {
9
9
  const CACHE_FILE_DIR = 'geoip-subfolder/hello_there';
10
- const CACHE_FILE_NAME = 'ip.log';
10
+ const CACHE_FILE_NAME = 'ips.log';
11
11
  const CACHE_FILE_SEPARATOR = ';;';
12
12
  const CACHE_FILE_NEWLINE = '\n';
13
13
 
@@ -20,8 +20,11 @@ describe('opts-assigned', () => {
20
20
  emoji: '🇨🇭',
21
21
  country: 'Switzerland',
22
22
  countryA2: 'CH',
23
+ region: 'Zurich',
23
24
  city: 'Zürich',
25
+ org: 'Quad9',
24
26
  isp: 'Quad9',
27
+ ispDomain: 'quad9.net',
25
28
  };
26
29
 
27
30
  removeCacheFolder(CACHE_FILE_DIR);
@@ -20,8 +20,11 @@ describe('opts-assigned', () => {
20
20
  emoji: '🇺🇸',
21
21
  country: 'United States',
22
22
  countryA2: 'US',
23
+ region: 'California',
23
24
  city: 'Mountain View',
25
+ org: 'Google LLC',
24
26
  isp: 'Google LLC',
27
+ ispDomain: 'google.com',
25
28
  };
26
29
 
27
30
  removeCacheFolder(CACHE_FILE_DIR);
@@ -7,7 +7,7 @@ import {checkCacheFile, removeCacheFolder} from './shared/fs.js';
7
7
 
8
8
  describe('opts-default', () => {
9
9
  const CACHE_FILE_DIR = 'geoip';
10
- const CACHE_FILE_NAME = 'ip.log';
10
+ const CACHE_FILE_NAME = 'ips.log';
11
11
  const CACHE_FILE_SEPARATOR = ';;';
12
12
  const CACHE_FILE_NEWLINE = '\n';
13
13
 
@@ -20,8 +20,11 @@ describe('opts-default', () => {
20
20
  emoji: '🇺🇸',
21
21
  country: 'United States',
22
22
  countryA2: 'US',
23
+ region: 'District of Columbia',
23
24
  city: 'Washington',
25
+ org: 'APNIC and Cloudflare DNS Resolver project',
24
26
  isp: 'Cloudflare, Inc.',
27
+ ispDomain: 'cloudflare.com',
25
28
  };
26
29
 
27
30
  const outputKeys = [
@@ -29,8 +32,11 @@ describe('opts-default', () => {
29
32
  'emoji',
30
33
  'country',
31
34
  'countryA2',
35
+ 'region',
32
36
  'city',
37
+ 'org',
33
38
  'isp',
39
+ 'ispDomain',
34
40
  ];
35
41
 
36
42
  removeCacheFolder(CACHE_FILE_DIR);
@@ -63,5 +69,9 @@ describe('opts-default', () => {
63
69
  assert.ok(data[key]);
64
70
  });
65
71
  });
72
+
73
+ it('should not have extra keys in request response', () => {
74
+ assert.deepEqual(Object.keys(data), outputKeys);
75
+ });
66
76
  });
67
77
  });