geoip-lite2 2.2.7 → 2.2.8-beta.10

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
@@ -5,7 +5,7 @@
5
5
  <br>
6
6
  <p>
7
7
  A native <a href="https://nodejs.org" target="_blank" title="Open nodejs.org">Node.js</a> API for the GeoLite data from MaxMind.<br>
8
- This product includes GeoLite data created by MaxMind, available from <a href="https://www.maxmind.com" target="_blank" title="Open www.maxmind.com">maxmind.com</a>.
8
+ This library includes GeoLite data created by MaxMind, available from <a href="https://www.maxmind.com" target="_blank" title="Open www.maxmind.com">maxmind.com</a>.
9
9
  </p>
10
10
  <a href="https://www.npmjs.com/package/geoip-lite2" target="_blank" title="geoip-lite2 - npm" style="text-decoration:none">
11
11
  <img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads">
@@ -18,26 +18,18 @@
18
18
 
19
19
 
20
20
  # 🚀 Improved GeoIP Module by [Sefinek](https://sefinek.net)
21
- This module is an enhanced and updated version of [geoip-lite](https://github.com/geoip-lite/node-geoip), carefully designed to meet the latest programming standards.
21
+ This module is an optimized version of [geoip-lite](https://github.com/geoip-lite/node-geoip) and runs slightly faster.
22
+ The project has been migrated to the [Jest](https://www.npmjs.com/package/jest) testing library.
22
23
 
23
- All components have been thoroughly updated to ensure optimal performance and functionality.
24
- The module now runs even faster, thanks to file minification!
25
-
26
- Furthermore, the testing process has been improved with the adoption of the [Jest](https://www.npmjs.com/package/jest) testing library.
27
-
28
- > I am not the primary creator of this! All copyright rights belong to the original [authors](AUTHORS).
24
+ > I am not the primary creator of this project! All copyright rights belong to the original [authors](AUTHORS).
29
25
 
30
26
 
31
27
  ## ⚠️ Important
32
- Remember to regularly update the Maxmind database. You'll need the token for this.
33
-
28
+ Remember to regularly update the MaxMind database. You'll need the token for this.
34
29
 
35
- ## 🌠 Version without a Local Database
36
- This module requires a significant amount of RAM because geolocation data is stored in memory.
37
- However, you can always opt for the official alternative, the [geoip2-api](https://www.npmjs.com/package/geoip2-api) module, which sends requests to an API server and retrieves information about specific IP addresses directly from there.
38
30
 
39
- ###Demonstration
40
- You can see this module in action using my [official API](https://api.sefinek.net). The API interface is public and can be safely used in your projects without any limits. Happy coding!
31
+ ##API
32
+ You can see this module in action using my [official API](https://api.sefinek.net). The `/api/v2/geoip` endpoint should not be used in production environments.
41
33
 
42
34
  - Specific IP: https://api.sefinek.net/api/v2/geoip/109.207.159.255
43
35
  - Client's IP: https://api.sefinek.net/api/v2/geoip/me
@@ -259,7 +251,6 @@ console.log(process.memoryUsage());
259
251
 
260
252
  ## 👥 Copyright
261
253
  `GeoIP-Lite` is Copyright 2011-2018 **Philip Tellis** <philip@bluesmoon.info>
262
- `GeoIP-Lite2` is Copyright 2023-2024 **Sefinek** <contact@sefinek.net> (https://sefinek.net)
263
254
 
264
255
 
265
256
  ## 🔐 License
@@ -1 +1 @@
1
- 9477be6926b39db95dcf6664e36bddd5900425ddb9952840ec5491d5c6ad6bdd GeoLite2-City-CSV_20250905.zip
1
+ 72c73fdb61f3118464d513df4eac91075f8457767d172b8317c705ad3a575ef3 GeoLite2-City-CSV_20251217.zip
@@ -1 +1 @@
1
- 952a602f47c26afc46782e468b2464fcc7a6a44418bff3819a5d1e63481de5ec GeoLite2-Country-CSV_20250905.zip
1
+ f4194c8a422f1d5c5f784737c8c59fce058d58ba90c22e9fbf061a0f6d1d1ba8 GeoLite2-Country-CSV_20251216.zip
Binary file
Binary file
Binary file
Binary file
Binary file
package/fsWatcher.js ADDED
@@ -0,0 +1,85 @@
1
+ // ============================================================================
2
+ // File System Watcher for Auto-Reloading GeoIP Data
3
+ // ============================================================================
4
+
5
+ const { access, constants, watch } = require('node:fs');
6
+ const { join } = require('node:path');
7
+ const FSWatcher = {};
8
+
9
+ // ============================================================================
10
+ // Watcher Management
11
+ // ============================================================================
12
+
13
+ /**
14
+ * Takes an FSWatcher object and closes it.
15
+ * @param {string} name - The name of the watcher to close.
16
+ */
17
+ const stopWatching = name => FSWatcher[name].close();
18
+
19
+ // ============================================================================
20
+ // File System Watch with Debounce
21
+ // ============================================================================
22
+
23
+ /**
24
+ * Takes a directory/file and watch for change. Upon change, call the callback.
25
+ *
26
+ * @param {String} name - name of this watcher
27
+ * @param {String} directory - path to the directory to watch
28
+ * @param {String} [filename] - (optional) specific filename to watch for, watches for all files in the directory if unspecified
29
+ * @param {Number} cdDelay - delay to wait before triggering the callback
30
+ * @param {Function} callback - function() - called when changes are detected
31
+ */
32
+ const makeFsWatchFilter = (name, directory, filename, cdDelay, callback) => {
33
+ let cdId = null;
34
+
35
+ // Delete the cdId and callback the outer function
36
+ function timeoutCallback() {
37
+ cdId = null;
38
+ callback();
39
+ }
40
+
41
+ // This function is called when there is a change in the data directory
42
+ // It sets a timer to wait for the change to be completed
43
+ function onWatchEvent(event, changedFile) {
44
+ // Check to make sure changedFile is not null
45
+ if (!changedFile) return;
46
+
47
+ const filePath = join(directory, changedFile);
48
+ if (!filename || filename === changedFile) {
49
+ access(filePath, constants.F_OK, err => {
50
+ if (err) return console.error(err);
51
+
52
+ // At this point, a new file system activity has been detected,
53
+ // We have to wait for file transfer to be finished before moving on.
54
+
55
+ // If a cdId already exists, we delete it
56
+ if (cdId !== null) {
57
+ clearTimeout(cdId);
58
+ cdId = null;
59
+ }
60
+
61
+ // Once the cdDelay has passed, the timeoutCallback function will be called
62
+ cdId = setTimeout(timeoutCallback, cdDelay);
63
+ });
64
+ }
65
+ }
66
+
67
+ // Manage the case where filename is missing (because it's optional)
68
+ if (typeof cdDelay === 'function') {
69
+ callback = cdDelay;
70
+ cdDelay = filename;
71
+ filename = null;
72
+ }
73
+
74
+ if (FSWatcher[name]) {
75
+ stopWatching(name);
76
+ }
77
+
78
+ FSWatcher[name] = watch(directory, onWatchEvent);
79
+ };
80
+
81
+ // ============================================================================
82
+ // Exports
83
+ // ============================================================================
84
+
85
+ module.exports = { makeFsWatchFilter, stopWatching };
package/index.d.ts CHANGED
@@ -2,12 +2,12 @@ interface GeoIp2Location {
2
2
  range: [number | null, number | null];
3
3
  country: string;
4
4
  region: string;
5
- eu: '0' | '1';
5
+ eu: '0' | '1' | '';
6
6
  timezone: string;
7
7
  city: string;
8
8
  ll: [number | null, number | null];
9
- metro: number;
10
- area: number;
9
+ metro: number | null;
10
+ area: number | null;
11
11
  }
12
12
 
13
13
  export function lookup(ip: string | number): GeoIp2Location | null;