@smpx/koa-request 1.2.0 → 1.2.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.
Files changed (2) hide show
  1. package/Request.js +18 -8
  2. package/package.json +1 -1
package/Request.js CHANGED
@@ -1394,19 +1394,19 @@ class Request {
1394
1394
  const loc = this.geoipLoc();
1395
1395
  const country = loc.country;
1396
1396
  const city = loc.city;
1397
- const state = loc.subdivisions && loc.subdivisions[0];
1397
+ const state = loc.subdivisions?.[0];
1398
1398
  this._ipLoc = {
1399
1399
  country: {
1400
- name: (country && country.names.en) || '',
1401
- isoCode: (country && country.iso_code) || '',
1400
+ name: country?.names?.en || '',
1401
+ isoCode: country?.iso_code || '',
1402
1402
  },
1403
1403
  city: {
1404
- name: (city && city.names.en) || '',
1405
- isoCode: (city && city.iso_code) || '',
1404
+ name: city?.names?.en || '',
1405
+ isoCode: city?.iso_code || '',
1406
1406
  },
1407
1407
  state: {
1408
- name: (state && state.names.en) || '',
1409
- isoCode: (state && state.iso_code) || '',
1408
+ name: state?.names?.en || '',
1409
+ isoCode: state?.iso_code || '',
1410
1410
  },
1411
1411
  };
1412
1412
  }
@@ -1414,8 +1414,18 @@ class Request {
1414
1414
  return this._ipLoc;
1415
1415
  }
1416
1416
 
1417
+ ipCountryISO() {
1418
+ if (this._ipciso === undefined) {
1419
+ this._ipciso = this.geoipLoc().country?.iso_code?.toLowerCase() || '';
1420
+ }
1421
+ return this._ipciso;
1422
+ }
1423
+
1417
1424
  ipCountry() {
1418
- return this.ipLocation().country.name;
1425
+ if (this._ipcname === undefined) {
1426
+ this._ipcname = this.geoipLoc().country?.names?.en || '';
1427
+ }
1428
+ return this._ipcname;
1419
1429
  }
1420
1430
 
1421
1431
  ipCity() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smpx/koa-request",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Handle basic tasks for koajs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",