@k03mad/ip2geo 2.3.1 → 3.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Kirill Molchanov
3
+ Copyright (c) Kirill Molchanov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import os from 'node:os';
4
- import path from 'node:path';
3
+ import {log, logErrorExit} from '@k03mad/simple-log';
5
4
 
6
5
  import {codeText, errorText, nameText} from './helpers/colors.js';
7
- import {log, throwError} from './helpers/logging.js';
8
6
 
9
7
  import {ip2geo} from './index.js';
10
8
 
@@ -16,7 +14,7 @@ if (args.length === 0) {
16
14
  const prefix = codeText('$');
17
15
  const name = nameText('ip2geo');
18
16
 
19
- throwError([
17
+ logErrorExit([
20
18
  errorText('IP(s) should be passed as args'),
21
19
  '',
22
20
  `${prefix} ${name} 1.1.1.1`,
@@ -32,9 +30,7 @@ if (args.includes(jsonParam)) {
32
30
  }
33
31
 
34
32
  await Promise.all(args.map(async arg => {
35
- const output = await ip2geo(arg, {
36
- cacheDir: path.join(os.tmpdir(), '.ip2geo'),
37
- });
33
+ const output = await ip2geo(arg);
38
34
 
39
35
  if (json) {
40
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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/ip2geo",
3
- "version": "2.3.1",
3
+ "version": "3.0.0",
4
4
  "description": "GeoIP library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -20,11 +20,12 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@k03mad/request": "5.4.1",
23
+ "@k03mad/simple-log": "2.0.0",
23
24
  "chalk": "5.3.0",
24
25
  "debug": "4.3.4"
25
26
  },
26
27
  "devDependencies": {
27
- "@k03mad/eslint-config": "19.2.0",
28
+ "@k03mad/eslint-config": "19.3.0",
28
29
  "eslint": "8.56.0",
29
30
  "husky": "8.0.3",
30
31
  "mocha": "10.2.0"
@@ -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';
@@ -1,5 +0,0 @@
1
- /**
2
- * @param {any|any[]} elem
3
- * @returns {any[]}
4
- */
5
- export const convertToArray = elem => Array.isArray(elem) ? elem : [elem];
@@ -1,26 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- import {convertToArray} from './array.js';
4
-
5
- /**
6
- * @param {any|any[]} msg
7
- * @returns {void}
8
- */
9
- export const log = msg => convertToArray(msg)
10
- .forEach(elem => console.log(elem));
11
-
12
- /**
13
- * @param {any|any[]} msg
14
- * @returns {void}
15
- */
16
- export const logError = msg => convertToArray(msg)
17
- .forEach(elem => console.error(elem));
18
-
19
- /**
20
- * @param {any|any[]} msg
21
- * @returns {void}
22
- */
23
- export const throwError = msg => {
24
- logError(msg);
25
- process.exit(1);
26
- };