@k03mad/ip2geo 2.3.2 → 3.1.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/README.md CHANGED
@@ -5,8 +5,6 @@
5
5
 
6
6
  ## Global
7
7
 
8
- Cache directory = `os.tmpDir() / .ip2geo`
9
-
10
8
  ```bash
11
9
  npm i @k03mad/ip2geo -g
12
10
 
@@ -30,8 +28,7 @@ ip2geo 1.1.1.1 --json
30
28
  ## API
31
29
 
32
30
  ```bash
33
- npm i @k03mad/ip2geo --save-exact
34
- echo .geoip >> .gitignore
31
+ npm i @k03mad/ip2geo
35
32
  ```
36
33
 
37
34
  ```js
@@ -39,10 +36,7 @@ import {ip2geo} from '@k03mad/ip2geo';
39
36
 
40
37
  const info = await ip2geo('1.1.1.1', {
41
38
  // defaults
42
-
43
- // current app root
44
- cacheDir: '.geoip',
45
- // will be prefixed with the first IP octet
39
+ cacheDir: path.join(os.tmpdir(), '.ip2geo'),
46
40
  cacheFileName: 'ips.log',
47
41
  cacheFileSeparator: ';;',
48
42
  cacheFileNewline: '\n',
package/app/cli.js CHANGED
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import os from 'node:os';
4
- import path from 'node:path';
5
-
6
3
  import {log, logErrorExit} from '@k03mad/simple-log';
7
4
 
8
5
  import {codeText, errorText, nameText} from './helpers/colors.js';
@@ -33,9 +30,7 @@ if (args.includes(jsonParam)) {
33
30
  }
34
31
 
35
32
  await Promise.all(args.map(async arg => {
36
- const output = await ip2geo(arg, {
37
- cacheDir: path.join(os.tmpdir(), '.ip2geo'),
38
- });
33
+ const output = await ip2geo(arg);
39
34
 
40
35
  if (json) {
41
36
  return log(JSON.stringify(output));
package/app/lib/ip2geo.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
+ import os from 'node:os';
2
3
  import path from 'node:path';
3
4
 
4
5
  import {request} from '@k03mad/request';
@@ -21,7 +22,7 @@ const debug = _debug('mad:geoip');
21
22
 
22
23
  const API = 'https://ipwho.is/';
23
24
 
24
- const DEFAULT_CACHE_FILE_DIR = '.geoip';
25
+ const DEFAULT_CACHE_FILE_DIR = path.join(os.tmpdir(), '.ip2geo');
25
26
  const DEFAULT_CACHE_FILE_NAME = 'ips.log';
26
27
  const DEFAULT_CACHE_FILE_SEPARATOR = ';;';
27
28
  const DEFAULT_CACHE_FILE_NEWLINE = '\n';
@@ -146,6 +147,10 @@ export default async (ip = '', {
146
147
 
147
148
  const {body} = await request(API + ip);
148
149
 
150
+ if (!body?.ip) {
151
+ throw new Error(`API error:\n${body}`);
152
+ }
153
+
149
154
  const usedData = [
150
155
  body.ip,
151
156
  body?.flag?.emoji,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/ip2geo",
3
- "version": "2.3.2",
3
+ "version": "3.1.0",
4
4
  "description": "GeoIP library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -10,4 +10,4 @@ export const getCurrentFilename = file => path.basename(file, '.js');
10
10
  * @param {string} file
11
11
  * @returns {string}
12
12
  */
13
- export const getTestFolder = file => path.join('.geoipCustom', file);
13
+ export const getTestFolder = file => path.join('.geoip', file);
@@ -1,4 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
2
4
 
3
5
  import {describe, it} from 'mocha';
4
6
 
@@ -7,7 +9,7 @@ import {ip2geo} from '../app/index.js';
7
9
  import {checkCacheFile, removeCacheFolder} from './shared/fs.js';
8
10
 
9
11
  describe('opts-default', () => {
10
- const CACHE_FILE_DIR = '.geoip';
12
+ const CACHE_FILE_DIR = path.join(os.tmpdir(), '.ip2geo');
11
13
  const CACHE_FILE_NAME = 'ips.log';
12
14
  const CACHE_FILE_SEPARATOR = ';;';
13
15
  const CACHE_FILE_NEWLINE = '\n';