@k03mad/ip2geo 18.0.0 → 18.0.1
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/.editorconfig +1 -4
- package/.github/dependabot.yml +2 -2
- package/.husky/pre-commit +1 -1
- package/.oxfmtrc.json +18 -0
- package/.oxlintrc.json +7 -0
- package/.vscode/settings.json +1 -8
- package/app/api.js +8 -20
- package/app/cli.js +54 -47
- package/app/helpers/cache.js +83 -59
- package/package.json +16 -16
- package/tests/cache-file-entries.js +5 -4
- package/tests/cache-file-modify.js +5 -4
- package/tests/cache-file-subfolder.js +6 -9
- package/tests/cache-map-max-entries.js +1 -7
- package/tests/cache-map-off.js +5 -4
- package/tests/default.js +4 -3
- package/tests/ip-multi-requests-cache.js +5 -4
- package/tests/ip-no-data.js +1 -4
- package/tests/ip-v6.js +5 -4
- package/eslint.config.js +0 -1
package/.editorconfig
CHANGED
package/.github/dependabot.yml
CHANGED
package/.husky/pre-commit
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
npm run lint && npm run test
|
package/.oxfmtrc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
3
|
+
"ignorePatterns": ["node_modules/**"],
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"arrowParens": "avoid",
|
|
6
|
+
"bracketSpacing": false,
|
|
7
|
+
"quoteProps": "consistent",
|
|
8
|
+
"experimentalSortImports": {
|
|
9
|
+
"groups": [
|
|
10
|
+
["builtin"],
|
|
11
|
+
["external", "type-external"],
|
|
12
|
+
["internal", "type-internal"],
|
|
13
|
+
["parent", "type-parent"],
|
|
14
|
+
["sibling", "type-sibling"],
|
|
15
|
+
["index", "type-index"]
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
package/.oxlintrc.json
ADDED
package/.vscode/settings.json
CHANGED
package/app/api.js
CHANGED
|
@@ -69,11 +69,7 @@ export const ip2geo = async ({
|
|
|
69
69
|
concurrency,
|
|
70
70
|
} = {}) => {
|
|
71
71
|
if (ip) {
|
|
72
|
-
const mapCache = readFromMapCache(
|
|
73
|
-
ip,
|
|
74
|
-
cacheMap,
|
|
75
|
-
cacheMapMaxEntries,
|
|
76
|
-
);
|
|
72
|
+
const mapCache = readFromMapCache(ip, cacheMap, cacheMapMaxEntries);
|
|
77
73
|
|
|
78
74
|
if (mapCache) {
|
|
79
75
|
return mapCache;
|
|
@@ -88,11 +84,7 @@ export const ip2geo = async ({
|
|
|
88
84
|
);
|
|
89
85
|
|
|
90
86
|
if (fsCache) {
|
|
91
|
-
writeToMapCache(
|
|
92
|
-
fsCache,
|
|
93
|
-
cacheMap,
|
|
94
|
-
cacheMapMaxEntries,
|
|
95
|
-
);
|
|
87
|
+
writeToMapCache(fsCache, cacheMap, cacheMapMaxEntries);
|
|
96
88
|
|
|
97
89
|
return fsCache;
|
|
98
90
|
}
|
|
@@ -112,11 +104,11 @@ export const ip2geo = async ({
|
|
|
112
104
|
const {body} = await request(reqUrl, {}, queueOpts);
|
|
113
105
|
|
|
114
106
|
if (!body?.ip) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
'API error',
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
107
|
+
throw new Error(
|
|
108
|
+
['API error', `request: ${reqUrl}`, `response body: ${JSON.stringify(body)}`].join(
|
|
109
|
+
'\n',
|
|
110
|
+
),
|
|
111
|
+
);
|
|
120
112
|
}
|
|
121
113
|
|
|
122
114
|
const outputData = collectOutputData([
|
|
@@ -135,11 +127,7 @@ export const ip2geo = async ({
|
|
|
135
127
|
body?.connection?.domain,
|
|
136
128
|
]);
|
|
137
129
|
|
|
138
|
-
writeToMapCache(
|
|
139
|
-
outputData,
|
|
140
|
-
cacheMap,
|
|
141
|
-
cacheMapMaxEntries,
|
|
142
|
-
);
|
|
130
|
+
writeToMapCache(outputData, cacheMap, cacheMapMaxEntries);
|
|
143
131
|
|
|
144
132
|
await writeToFsCache(
|
|
145
133
|
body.ip,
|
package/app/cli.js
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_CACHE_FILE_DIR,
|
|
7
|
+
DEFAULT_CACHE_FILE_NEWLINE,
|
|
8
|
+
DEFAULT_CACHE_FILE_SEPARATOR,
|
|
9
|
+
ip2geo,
|
|
10
|
+
} from './api.js';
|
|
6
11
|
import {pruneCache} from './helpers/cache.js';
|
|
7
12
|
import {codeText, nameText} from './helpers/colors.js';
|
|
8
13
|
|
|
@@ -17,25 +22,27 @@ const isPrune = args.includes('-p') || args.includes('--prune');
|
|
|
17
22
|
if (isHelp) {
|
|
18
23
|
const cmd = `${codeText('$')} ${nameText('ip2geo')}`;
|
|
19
24
|
|
|
20
|
-
console.log(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
console.log(
|
|
26
|
+
[
|
|
27
|
+
'',
|
|
28
|
+
codeText('# current external ip'),
|
|
29
|
+
cmd,
|
|
30
|
+
`${cmd} 1.1.1.1`,
|
|
31
|
+
'',
|
|
32
|
+
`${cmd} -h`,
|
|
33
|
+
`${cmd} --help`,
|
|
34
|
+
'',
|
|
35
|
+
`${cmd} 1.1.1.1 -j`,
|
|
36
|
+
`${cmd} 1.1.1.1 --json`,
|
|
37
|
+
'',
|
|
38
|
+
`${cmd} 1.1.1.1 8.8.8.8`,
|
|
39
|
+
`${cmd} 1.1.1.1,8.8.8.8`,
|
|
40
|
+
'',
|
|
41
|
+
codeText('# remove duplicate cache entries'),
|
|
42
|
+
`${cmd} -p`,
|
|
43
|
+
`${cmd} --prune`,
|
|
44
|
+
].join('\n'),
|
|
45
|
+
);
|
|
39
46
|
|
|
40
47
|
process.exit(0);
|
|
41
48
|
}
|
|
@@ -45,47 +52,47 @@ if (isPrune) {
|
|
|
45
52
|
console.log(blue(cacheFolder));
|
|
46
53
|
|
|
47
54
|
try {
|
|
48
|
-
const {
|
|
49
|
-
different,
|
|
50
|
-
duplicates,
|
|
51
|
-
empty,
|
|
52
|
-
entries,
|
|
53
|
-
longLinesFiles,
|
|
54
|
-
} = await pruneCache(
|
|
55
|
+
const {different, duplicates, empty, entries, longLinesFiles} = await pruneCache(
|
|
55
56
|
cacheFolder,
|
|
56
57
|
DEFAULT_CACHE_FILE_SEPARATOR,
|
|
57
58
|
DEFAULT_CACHE_FILE_NEWLINE,
|
|
58
59
|
);
|
|
59
60
|
|
|
60
|
-
console.log(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
console.log(
|
|
62
|
+
[
|
|
63
|
+
'',
|
|
64
|
+
green(`Removed duplicate cache entries: ${bold(duplicates.length)}`),
|
|
65
|
+
...duplicates.map(elem => dim(`— ${elem}`)),
|
|
66
|
+
green(`Removed different cache entries: ${bold(different.length)}`),
|
|
67
|
+
...different.map(elem => dim(`— ${elem}`)),
|
|
68
|
+
green(`Removed empty cache entries: ${bold(empty.length)}`),
|
|
69
|
+
...empty.map(elem => dim(`— ${elem}`)),
|
|
70
|
+
].join('\n'),
|
|
71
|
+
);
|
|
69
72
|
|
|
70
73
|
if (longLinesFiles.length > 0) {
|
|
71
|
-
console.log(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
console.log(
|
|
75
|
+
[
|
|
76
|
+
red(
|
|
77
|
+
`Required manual check, some cache files has too long lines: ${bold(longLinesFiles.length)}`,
|
|
78
|
+
),
|
|
79
|
+
...longLinesFiles.map(({file, elem}) => dim(`— ${file}\n|— ${elem}`)),
|
|
80
|
+
].join('\n'),
|
|
81
|
+
);
|
|
75
82
|
}
|
|
76
83
|
|
|
77
|
-
console.log([
|
|
78
|
-
'',
|
|
79
|
-
green(`Current cache entries: ${bold(entries)}`),
|
|
80
|
-
].join('\n'));
|
|
84
|
+
console.log(['', green(`Current cache entries: ${bold(entries)}`)].join('\n'));
|
|
81
85
|
} catch (err) {
|
|
82
86
|
console.error(red(err));
|
|
83
87
|
process.exit(1);
|
|
84
88
|
}
|
|
85
89
|
} else {
|
|
86
|
-
const output =
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
const output =
|
|
91
|
+
argsExtra.length === 0
|
|
92
|
+
? [await ip2geo()]
|
|
93
|
+
: await Promise.all(
|
|
94
|
+
argsExtra.map(arg => Promise.all(arg.split(',').map(ip => ip2geo({ip})))),
|
|
95
|
+
);
|
|
89
96
|
|
|
90
97
|
const flatten = output.flat();
|
|
91
98
|
|
package/app/helpers/cache.js
CHANGED
|
@@ -32,9 +32,7 @@ export const collectOutputData = dataArr => {
|
|
|
32
32
|
const outputData = {};
|
|
33
33
|
|
|
34
34
|
outputKeys.forEach((key, i) => {
|
|
35
|
-
outputData[key] = key === 'connectionAsn' && dataArr[i]
|
|
36
|
-
? Number(dataArr[i])
|
|
37
|
-
: dataArr[i];
|
|
35
|
+
outputData[key] = key === 'connectionAsn' && dataArr[i] ? Number(dataArr[i]) : dataArr[i];
|
|
38
36
|
});
|
|
39
37
|
|
|
40
38
|
return outputData;
|
|
@@ -59,7 +57,13 @@ const getCacheFileFullPath = (ip, cacheDir, cacheFileName) => {
|
|
|
59
57
|
* @param {string} cacheFileNewline
|
|
60
58
|
* @returns {Promise<object>}
|
|
61
59
|
*/
|
|
62
|
-
export const readFromFsCache = async (
|
|
60
|
+
export const readFromFsCache = async (
|
|
61
|
+
ip,
|
|
62
|
+
cacheDir,
|
|
63
|
+
cacheFileName,
|
|
64
|
+
cacheFileSeparator,
|
|
65
|
+
cacheFileNewline,
|
|
66
|
+
) => {
|
|
63
67
|
const cacheFileFull = getCacheFileFullPath(ip, cacheDir, cacheFileName);
|
|
64
68
|
|
|
65
69
|
try {
|
|
@@ -97,12 +101,23 @@ export const readFromFsCache = async (ip, cacheDir, cacheFileName, cacheFileSepa
|
|
|
97
101
|
* @param {string} cacheFileNewline
|
|
98
102
|
* @returns {Promise<void>}
|
|
99
103
|
*/
|
|
100
|
-
export const writeToFsCache = async (
|
|
104
|
+
export const writeToFsCache = async (
|
|
105
|
+
ip,
|
|
106
|
+
data,
|
|
107
|
+
cacheDir,
|
|
108
|
+
cacheFileName,
|
|
109
|
+
cacheFileSeparator,
|
|
110
|
+
cacheFileNewline,
|
|
111
|
+
) => {
|
|
101
112
|
const cacheFileFull = getCacheFileFullPath(ip, cacheDir, cacheFileName);
|
|
102
113
|
debug('set to fs cache: %o %o', cacheFileFull, data);
|
|
103
114
|
|
|
104
115
|
await fs.mkdir(cacheDir, {recursive: true});
|
|
105
|
-
|
|
116
|
+
|
|
117
|
+
await fs.appendFile(
|
|
118
|
+
cacheFileFull,
|
|
119
|
+
cacheFileNewline + Object.values(data).join(cacheFileSeparator),
|
|
120
|
+
);
|
|
106
121
|
};
|
|
107
122
|
|
|
108
123
|
/**
|
|
@@ -164,81 +179,90 @@ export const writeToMapCache = (body, cacheMap, cacheMapMaxEntries) => {
|
|
|
164
179
|
export const pruneCache = async (cacheDir, cacheFileSeparator, cacheFileNewline) => {
|
|
165
180
|
const files = await fs.readdir(cacheDir);
|
|
166
181
|
|
|
167
|
-
await Promise.all(
|
|
168
|
-
|
|
182
|
+
await Promise.all(
|
|
183
|
+
files.map(async file => {
|
|
184
|
+
const fullFilePath = path.join(cacheDir, file);
|
|
169
185
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
const [stat, data] = await Promise.all([
|
|
187
|
+
fs.lstat(fullFilePath),
|
|
188
|
+
fs.readFile(fullFilePath, {encoding: 'utf8'}),
|
|
189
|
+
]);
|
|
174
190
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
const firstIp = data
|
|
192
|
+
?.split(cacheFileNewline)
|
|
193
|
+
?.find(Boolean)
|
|
194
|
+
?.split(cacheFileSeparator)[0];
|
|
179
195
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
line.split(cacheFileSeparator)[0]
|
|
187
|
-
.split('.')
|
|
188
|
-
.map(num => `00${num}`.slice(-3))
|
|
189
|
-
.join(''),
|
|
196
|
+
if (stat.isDirectory() || (firstIp && !isIP(firstIp))) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
`Folder has subfolders or files without IPs, wrong cache folder arg?\n${fullFilePath}`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}),
|
|
190
202
|
);
|
|
191
203
|
|
|
204
|
+
const cacheLineToNum = line =>
|
|
205
|
+
Number(
|
|
206
|
+
line
|
|
207
|
+
.split(cacheFileSeparator)[0]
|
|
208
|
+
.split('.')
|
|
209
|
+
.map(num => `00${num}`.slice(-3))
|
|
210
|
+
.join(''),
|
|
211
|
+
);
|
|
212
|
+
|
|
192
213
|
const duplicates = new Set();
|
|
193
214
|
const different = new Set();
|
|
194
215
|
const empty = [];
|
|
195
216
|
const longLinesFiles = new Set();
|
|
196
217
|
let entries = 0;
|
|
197
218
|
|
|
198
|
-
await Promise.all(
|
|
199
|
-
|
|
219
|
+
await Promise.all(
|
|
220
|
+
files.map(async file => {
|
|
221
|
+
const fullFilePath = path.join(cacheDir, file);
|
|
200
222
|
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
const data = await fs.readFile(fullFilePath, {encoding: 'utf8'});
|
|
224
|
+
const dataArr = data.split(cacheFileNewline).filter(Boolean);
|
|
203
225
|
|
|
204
|
-
|
|
205
|
-
|
|
226
|
+
const dataArrRemoveEmpty = dataArr.filter(elem => {
|
|
227
|
+
const splitted = elem.split(cacheFileSeparator);
|
|
206
228
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
229
|
+
if (splitted.length > outputKeys.length) {
|
|
230
|
+
longLinesFiles.add({file: fullFilePath, elem});
|
|
231
|
+
}
|
|
210
232
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
233
|
+
if (splitted.filter(Boolean).length > 1) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
214
236
|
|
|
215
|
-
|
|
216
|
-
|
|
237
|
+
empty.push(elem);
|
|
238
|
+
});
|
|
217
239
|
|
|
218
|
-
|
|
219
|
-
|
|
240
|
+
const uniqSorted = [...new Set(dataArrRemoveEmpty)].toSorted(
|
|
241
|
+
(a, b) => cacheLineToNum(a) - cacheLineToNum(b),
|
|
242
|
+
);
|
|
220
243
|
|
|
221
|
-
|
|
222
|
-
|
|
244
|
+
getArrayDups(dataArrRemoveEmpty).forEach(dup => duplicates.add(dup));
|
|
245
|
+
const dupsIp = getArrayDups(uniqSorted.map(elem => elem.split(cacheFileSeparator)[0]));
|
|
223
246
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
247
|
+
const removeDiffs = uniqSorted.filter(elem => {
|
|
248
|
+
if (dupsIp.includes(elem.split(cacheFileSeparator)[0])) {
|
|
249
|
+
different.add(elem);
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
229
252
|
|
|
230
|
-
|
|
231
|
-
|
|
253
|
+
return true;
|
|
254
|
+
});
|
|
232
255
|
|
|
233
|
-
|
|
256
|
+
const fileContent = removeDiffs.join(cacheFileNewline).trim();
|
|
234
257
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
258
|
+
if (fileContent) {
|
|
259
|
+
await fs.writeFile(fullFilePath, fileContent);
|
|
260
|
+
entries += removeDiffs.length;
|
|
261
|
+
} else {
|
|
262
|
+
await fs.rm(fullFilePath);
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
265
|
+
);
|
|
242
266
|
|
|
243
267
|
return {
|
|
244
268
|
entries,
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k03mad/ip2geo",
|
|
3
|
-
"version": "18.0.
|
|
3
|
+
"version": "18.0.1",
|
|
4
4
|
"description": "GeoIP library",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"maintainers": [
|
|
6
7
|
"Kirill Molchanov <k03.mad@gmail.com"
|
|
7
8
|
],
|
|
8
|
-
"bin": {
|
|
9
|
-
"ip2geo": "app/cli.js"
|
|
10
|
-
},
|
|
11
|
-
"main": "app/api.js",
|
|
12
9
|
"repository": {
|
|
13
10
|
"type": "git",
|
|
14
11
|
"url": "git+https://github.com/k03mad/ip2geo.git"
|
|
15
12
|
},
|
|
16
|
-
"
|
|
13
|
+
"bin": {
|
|
14
|
+
"ip2geo": "app/cli.js"
|
|
15
|
+
},
|
|
17
16
|
"type": "module",
|
|
18
|
-
"
|
|
19
|
-
|
|
17
|
+
"main": "app/api.js",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"lint": "oxlint --report-unused-disable-directives && oxfmt --check",
|
|
20
|
+
"test": "rm -rfv ./.geoip && mocha tests --bail",
|
|
21
|
+
"prepare": "husky || true"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@k03mad/request": "
|
|
24
|
+
"@k03mad/request": "14.0.2",
|
|
23
25
|
"chalk": "5.6.2",
|
|
24
26
|
"debug": "4.4.3",
|
|
25
27
|
"is-ip": "5.0.1"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
28
|
-
"@k03mad/
|
|
29
|
-
"eslint": "9.39.2",
|
|
30
|
+
"@k03mad/oxlint-config": "0.0.19",
|
|
30
31
|
"husky": "9.1.7",
|
|
31
32
|
"mocha": "11.7.5",
|
|
32
|
-
"
|
|
33
|
+
"oxfmt": "0.34.0",
|
|
34
|
+
"oxlint": "1.49.0"
|
|
33
35
|
},
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"test": "rm -rfv ./.geoip && mocha tests --bail",
|
|
37
|
-
"prepare": "husky || true"
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=24"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -27,10 +27,11 @@ describe(testName, () => {
|
|
|
27
27
|
assert.deepEqual(data, REQUEST_IPV4);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
it('should have cache file', () =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
it('should have cache file', () =>
|
|
31
|
+
checkCacheFile({
|
|
32
|
+
...opts,
|
|
33
|
+
response: REQUEST_IPV4,
|
|
34
|
+
}));
|
|
34
35
|
});
|
|
35
36
|
});
|
|
36
37
|
});
|
|
@@ -26,8 +26,9 @@ describe(testName, () => {
|
|
|
26
26
|
assert.deepEqual(data, REQUEST_IPV4);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it('should have cache file', () =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
it('should have cache file', () =>
|
|
30
|
+
checkCacheFile({
|
|
31
|
+
...opts,
|
|
32
|
+
response: REQUEST_IPV4,
|
|
33
|
+
}));
|
|
33
34
|
});
|
|
@@ -15,11 +15,7 @@ describe(testName, () => {
|
|
|
15
15
|
const SUBFOLDERS = 5;
|
|
16
16
|
|
|
17
17
|
const opts = {
|
|
18
|
-
cacheDir: getTestFolder(
|
|
19
|
-
path.join(
|
|
20
|
-
...Array.from({length: SUBFOLDERS}, () => testName),
|
|
21
|
-
),
|
|
22
|
-
),
|
|
18
|
+
cacheDir: getTestFolder(path.join(...Array.from({length: SUBFOLDERS}, () => testName))),
|
|
23
19
|
cacheMap: new Map(),
|
|
24
20
|
};
|
|
25
21
|
|
|
@@ -30,8 +26,9 @@ describe(testName, () => {
|
|
|
30
26
|
assert.deepEqual(data, REQUEST_IPV4);
|
|
31
27
|
});
|
|
32
28
|
|
|
33
|
-
it('should have cache file', () =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
it('should have cache file', () =>
|
|
30
|
+
checkCacheFile({
|
|
31
|
+
...opts,
|
|
32
|
+
response: REQUEST_IPV4,
|
|
33
|
+
}));
|
|
37
34
|
});
|
|
@@ -10,13 +10,7 @@ import {removeCacheFolder} from './shared/fs.js';
|
|
|
10
10
|
const testName = getCurrentFilename(import.meta.url);
|
|
11
11
|
|
|
12
12
|
describe(testName, () => {
|
|
13
|
-
const firstReqIps = [
|
|
14
|
-
'10.10.10.10',
|
|
15
|
-
'20.20.20.20',
|
|
16
|
-
'30.30.30.30',
|
|
17
|
-
'40.40.40.40',
|
|
18
|
-
'50.50.50.50',
|
|
19
|
-
];
|
|
13
|
+
const firstReqIps = ['10.10.10.10', '20.20.20.20', '30.30.30.30', '40.40.40.40', '50.50.50.50'];
|
|
20
14
|
|
|
21
15
|
const secondReqIps = ['60.60.60.60'];
|
|
22
16
|
|
package/tests/cache-map-off.js
CHANGED
|
@@ -23,10 +23,11 @@ describe(testName, () => {
|
|
|
23
23
|
assert.deepEqual(data, REQUEST_IPV4_MAP_OFF_ONLY);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
it('should have cache file', () =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
it('should have cache file', () =>
|
|
27
|
+
checkCacheFile({
|
|
28
|
+
...opts,
|
|
29
|
+
response: REQUEST_IPV4_MAP_OFF_ONLY,
|
|
30
|
+
}));
|
|
30
31
|
|
|
31
32
|
it('should not have cache entries', () => {
|
|
32
33
|
assert.equal(cacheStorage.size, 0);
|
package/tests/default.js
CHANGED
|
@@ -19,9 +19,10 @@ describe(testName, () => {
|
|
|
19
19
|
assert.deepEqual(data, REQUEST_IPV4);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
it('should have cache file', () =>
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
it('should have cache file', () =>
|
|
23
|
+
checkCacheFile({
|
|
24
|
+
response: REQUEST_IPV4,
|
|
25
|
+
}));
|
|
25
26
|
|
|
26
27
|
it('should have 1 correct cache entry', () => {
|
|
27
28
|
assert.equal(cacheStorage.size, 1);
|
|
@@ -26,10 +26,11 @@ describe(testName, () => {
|
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it('should have cache file', () =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
it('should have cache file', () =>
|
|
30
|
+
checkCacheFile({
|
|
31
|
+
...opts,
|
|
32
|
+
response: REQUEST_IPV4,
|
|
33
|
+
}));
|
|
33
34
|
|
|
34
35
|
it('should have 1 correct cache entry', () => {
|
|
35
36
|
assert.equal(opts.cacheMap.size, 1);
|
package/tests/ip-no-data.js
CHANGED
|
@@ -11,10 +11,7 @@ import {removeCacheFolder} from './shared/fs.js';
|
|
|
11
11
|
const testName = getCurrentFilename(import.meta.url);
|
|
12
12
|
|
|
13
13
|
describe(testName, () => {
|
|
14
|
-
const responses = [
|
|
15
|
-
{ip: '10.10.10.10'},
|
|
16
|
-
{ip: 'test'},
|
|
17
|
-
];
|
|
14
|
+
const responses = [{ip: '10.10.10.10'}, {ip: 'test'}];
|
|
18
15
|
|
|
19
16
|
const opts = {
|
|
20
17
|
cacheDir: getTestFolder(testName),
|
package/tests/ip-v6.js
CHANGED
|
@@ -23,8 +23,9 @@ describe.skip(testName, () => {
|
|
|
23
23
|
assert.deepEqual(data, REQUEST_IPV6);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
it('should have cache file', () =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
it('should have cache file', () =>
|
|
27
|
+
checkCacheFile({
|
|
28
|
+
...opts,
|
|
29
|
+
response: REQUEST_IPV6,
|
|
30
|
+
}));
|
|
30
31
|
});
|
package/eslint.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {default} from '@k03mad/eslint-config';
|