@k03mad/ip2geo 6.1.0 → 7.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/helpers/cache.js +3 -1
- package/app/lib/ip2geo.js +4 -1
- package/package.json +1 -1
- package/tests/cache-file-entries.js +35 -0
package/app/helpers/cache.js
CHANGED
|
@@ -29,7 +29,9 @@ export const collectOutputData = dataArr => {
|
|
|
29
29
|
const outputData = {};
|
|
30
30
|
|
|
31
31
|
outputKeys.forEach((key, i) => {
|
|
32
|
-
outputData[key] = dataArr[i]
|
|
32
|
+
outputData[key] = key === 'connectionAsn' && dataArr[i]
|
|
33
|
+
? Number(dataArr[i])
|
|
34
|
+
: dataArr[i];
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
return outputData;
|
package/app/lib/ip2geo.js
CHANGED
|
@@ -75,7 +75,10 @@ export const ip2geo = async ({
|
|
|
75
75
|
return mapCache;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
const fsCache = await readFromFsCache(
|
|
78
|
+
const fsCache = await readFromFsCache(
|
|
79
|
+
ip, cacheDir,
|
|
80
|
+
cacheFileName, cacheFileSeparator, cacheFileNewline,
|
|
81
|
+
);
|
|
79
82
|
|
|
80
83
|
if (fsCache) {
|
|
81
84
|
writeToMapCache(fsCache, cacheMap, cacheMapMaxEntries);
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
|
|
3
|
+
import {describe, it} from 'mocha';
|
|
4
|
+
|
|
5
|
+
import {ip2geo} from '../app/index.js';
|
|
6
|
+
|
|
7
|
+
import {REQUEST_IPV4} from './helpers/consts.js';
|
|
8
|
+
import {getCurrentFilename, getTestFolder} from './helpers/path.js';
|
|
9
|
+
import {checkCacheFile, removeCacheFolder} from './shared/fs.js';
|
|
10
|
+
|
|
11
|
+
const testName = getCurrentFilename(import.meta.url);
|
|
12
|
+
|
|
13
|
+
describe(testName, () => {
|
|
14
|
+
const opts = {
|
|
15
|
+
cacheDir: getTestFolder(testName),
|
|
16
|
+
cacheMap: new Map(),
|
|
17
|
+
cacheMapMaxEntries: 0,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
it('should remove fs cache dir if exist', () => removeCacheFolder(opts.cacheDir));
|
|
21
|
+
|
|
22
|
+
['first try', 'second try'].forEach(name => {
|
|
23
|
+
describe(name, () => {
|
|
24
|
+
it(`should return correct response for IP: "${REQUEST_IPV4.ip}"`, async () => {
|
|
25
|
+
const data = await ip2geo({ip: REQUEST_IPV4.ip, ...opts});
|
|
26
|
+
assert.deepEqual(data, REQUEST_IPV4);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should have cache file', () => checkCacheFile({
|
|
30
|
+
...opts,
|
|
31
|
+
response: REQUEST_IPV4,
|
|
32
|
+
}));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|