@k03mad/ip2geo 11.6.0 → 12.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.
Files changed (2) hide show
  1. package/app/api.js +15 -3
  2. package/package.json +4 -4
package/app/api.js CHANGED
@@ -18,7 +18,7 @@ export const DEFAULT_CACHE_FILE_NAME = 'ip.log';
18
18
  export const DEFAULT_CACHE_FILE_SEPARATOR = ';;';
19
19
  export const DEFAULT_CACHE_FILE_NEWLINE = '\n';
20
20
  export const DEFAULT_CACHE_MAP_MAX_ENTRIES = Number.POSITIVE_INFINITY;
21
- export const DEFAULT_RPS = 3;
21
+ export const DEFAULT_CONCURRENCY = 2;
22
22
 
23
23
  export const cacheStorage = new Map();
24
24
 
@@ -33,6 +33,7 @@ export const cacheStorage = new Map();
33
33
  * @property {Map} [opts.cacheMap]
34
34
  * @property {number} [opts.cacheMapMaxEntries]
35
35
  * @property {number} [opts.rps]
36
+ * @property {number} [opts.concurrency]
36
37
  */
37
38
 
38
39
  /**
@@ -64,7 +65,8 @@ export const ip2geo = async ({
64
65
  cacheFileNewline = DEFAULT_CACHE_FILE_NEWLINE,
65
66
  cacheMapMaxEntries = DEFAULT_CACHE_MAP_MAX_ENTRIES,
66
67
  cacheMap = cacheStorage,
67
- rps = DEFAULT_RPS,
68
+ rps,
69
+ concurrency,
68
70
  } = {}) => {
69
71
  if (ip) {
70
72
  const mapCache = readFromMapCache(
@@ -97,7 +99,17 @@ export const ip2geo = async ({
97
99
  }
98
100
 
99
101
  const reqUrl = API + ip;
100
- const {body} = await request(reqUrl, {}, {rps});
102
+ const queueOpts = {};
103
+
104
+ if (rps) {
105
+ queueOpts.rps = rps;
106
+ } else if (concurrency) {
107
+ queueOpts.concurrency = concurrency;
108
+ } else {
109
+ queueOpts.concurrency = DEFAULT_CONCURRENCY;
110
+ }
111
+
112
+ const {body} = await request(reqUrl, {}, queueOpts);
101
113
 
102
114
  if (!body?.ip) {
103
115
  throw new Error([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/ip2geo",
3
- "version": "11.6.0",
3
+ "version": "12.0.0",
4
4
  "description": "GeoIP library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -19,15 +19,15 @@
19
19
  "node": ">=22"
20
20
  },
21
21
  "dependencies": {
22
- "@k03mad/request": "7.7.0",
22
+ "@k03mad/request": "7.8.0",
23
23
  "@k03mad/simple-log": "5.2.1",
24
24
  "chalk": "5.4.1",
25
25
  "debug": "4.4.0",
26
26
  "is-ip": "5.0.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@k03mad/eslint-config": "28.4.0",
30
- "eslint": "9.18.0",
29
+ "@k03mad/eslint-config": "28.5.0",
30
+ "eslint": "9.19.0",
31
31
  "husky": "9.1.7",
32
32
  "mocha": "11.1.0",
33
33
  "npm-run-all": "4.1.5"