@k03mad/ip2geo 9.6.0 → 10.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/app/cli.js CHANGED
@@ -46,7 +46,13 @@ if (isPrune) {
46
46
  log(blue(cacheFolder));
47
47
 
48
48
  try {
49
- const {duplicates, empty, longLinesFiles} = await pruneCache(
49
+ const {
50
+ different,
51
+ duplicates,
52
+ empty,
53
+ entries,
54
+ longLinesFiles,
55
+ } = await pruneCache(
50
56
  cacheFolder,
51
57
  DEFAULT_CACHE_FILE_SEPARATOR,
52
58
  DEFAULT_CACHE_FILE_NEWLINE,
@@ -56,6 +62,8 @@ if (isPrune) {
56
62
  '',
57
63
  green(`Removed duplicate cache entries: ${bold(duplicates.length)}`),
58
64
  ...duplicates.map(elem => dim(`— ${elem}`)),
65
+ green(`Removed different cache entries: ${bold(different.length)}`),
66
+ ...different.map(elem => dim(`— ${elem}`)),
59
67
  green(`Removed empty cache entries: ${bold(empty.length)}`),
60
68
  ...empty.map(elem => dim(`— ${elem}`)),
61
69
  ]);
@@ -66,6 +74,11 @@ if (isPrune) {
66
74
  ...longLinesFiles.map(({file, elem}) => dim(`— ${file}\n|— ${elem}`)),
67
75
  ]);
68
76
  }
77
+
78
+ log([
79
+ '',
80
+ green(`Current cache entries: ${bold(entries)}`),
81
+ ]);
69
82
  } catch (err) {
70
83
  logErrorExit(red(err));
71
84
  }
@@ -191,8 +191,10 @@ export const pruneCache = async (cacheDir, cacheFileSeparator, cacheFileNewline)
191
191
  );
192
192
 
193
193
  const duplicates = new Set();
194
+ const different = new Set();
194
195
  const empty = [];
195
196
  const longLinesFiles = new Set();
197
+ let entries = 0;
196
198
 
197
199
  await Promise.all(files.map(async file => {
198
200
  const fullFilePath = path.join(cacheDir, file);
@@ -215,17 +217,38 @@ export const pruneCache = async (cacheDir, cacheFileSeparator, cacheFileNewline)
215
217
  });
216
218
 
217
219
  const uniq = [...new Set(dataArrRemoveEmpty)]
218
- .sort((a, b) => cacheLineToNum(a) - cacheLineToNum(b));
220
+ .sort((a, b) => cacheLineToNum(a) - cacheLineToNum(b))
221
+ .filter((elem, i, arr) => {
222
+ for (const [j, line] of arr.entries()) {
223
+ if (
224
+ i !== j
225
+ && line.split(cacheFileSeparator)[0] === elem.split(cacheFileSeparator)[0]
226
+ ) {
227
+ different.add(elem);
228
+ return false;
229
+ }
230
+ }
231
+
232
+ return true;
233
+ });
219
234
 
220
235
  const fileContent = uniq.join(cacheFileNewline).trim();
221
- await (fileContent ? fs.writeFile(fullFilePath, fileContent) : fs.rm(fullFilePath));
236
+
237
+ if (fileContent) {
238
+ await fs.writeFile(fullFilePath, fileContent);
239
+ entries += uniq.length;
240
+ } else {
241
+ await fs.rm(fullFilePath);
242
+ }
222
243
 
223
244
  dataArrRemoveEmpty
224
245
  .forEach((elem, i, arr) => arr.indexOf(elem) !== i && duplicates.add(elem));
225
246
  }));
226
247
 
227
248
  return {
249
+ entries,
228
250
  duplicates: [...duplicates],
251
+ different: [...different],
229
252
  empty,
230
253
  longLinesFiles: [...longLinesFiles],
231
254
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/ip2geo",
3
- "version": "9.6.0",
3
+ "version": "10.0.0",
4
4
  "description": "GeoIP library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"