@k03mad/ip2geo 9.4.0 → 9.6.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.
@@ -2,11 +2,10 @@ import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
4
  import _debug from 'debug';
5
+ import {isIP} from 'is-ip';
5
6
 
6
7
  const debug = _debug('mad:geoip');
7
8
 
8
- const ipRe = /((25[0-5]|((?:2[0-4]|1\d|[1-9])?)\d)\.?\b){4}/;
9
-
10
9
  const outputKeys = [
11
10
  'ip',
12
11
  'continent',
@@ -171,7 +170,15 @@ export const pruneCache = async (cacheDir, cacheFileSeparator, cacheFileNewline)
171
170
  fs.readFile(fullFilePath, {encoding: 'utf8'}),
172
171
  ]);
173
172
 
174
- if (stat.isDirectory() || !ipRe.test(data)) {
173
+ const firstIp = data
174
+ .split(cacheFileNewline)
175
+ .find(Boolean)
176
+ .split(cacheFileSeparator)[0];
177
+
178
+ if (
179
+ stat.isDirectory()
180
+ || !isIP(firstIp)
181
+ ) {
175
182
  throw new Error(`Folder has subfolders or files without IPs, wrong cache folder arg?\n${fullFilePath}`);
176
183
  }
177
184
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/ip2geo",
3
- "version": "9.4.0",
3
+ "version": "9.6.0",
4
4
  "description": "GeoIP library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -20,14 +20,15 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@k03mad/request": "6.1.0",
23
- "@k03mad/simple-log": "3.0.0",
23
+ "@k03mad/simple-log": "4.0.0",
24
24
  "chalk": "5.3.0",
25
- "debug": "4.3.6"
25
+ "debug": "4.3.6",
26
+ "is-ip": "5.0.1"
26
27
  },
27
28
  "devDependencies": {
28
- "@k03mad/eslint-config": "23.0.0",
29
+ "@k03mad/eslint-config": "23.1.0",
29
30
  "eslint": "8.57.0",
30
- "husky": "9.1.4",
31
+ "husky": "9.1.5",
31
32
  "mocha": "10.7.3",
32
33
  "npm-run-all": "4.1.5"
33
34
  },