Comparing version 2.0.0-next.2 to 2.0.0
@@ -1,2 +0,1 @@ | ||
export declare function clearCache(ip?: string): void; | ||
export interface LookupResponse { | ||
@@ -3,0 +2,0 @@ ip: string; |
@@ -14,3 +14,29 @@ "use strict"; | ||
var DEFAULT_IP = 'DEFAULT_IP'; | ||
var VALID_FIELDS = ['ip', 'is_eu', 'city', 'region', 'region_code', 'country_name', 'country_code', 'continent_name', 'continent_code', 'latitude', 'longitude', 'asn', 'organisation', 'postal', 'calling_code', 'flag', 'emoji_flag', 'emoji_unicode', 'carrier', 'languages', 'currency', 'time_zone', 'threat', 'count', 'status']; | ||
var VALID_FIELDS = [ | ||
'ip', | ||
'is_eu', | ||
'city', | ||
'region', | ||
'region_code', | ||
'country_name', | ||
'country_code', | ||
'continent_name', | ||
'continent_code', | ||
'latitude', | ||
'longitude', | ||
'asn', | ||
'organisation', | ||
'postal', | ||
'calling_code', | ||
'flag', | ||
'emoji_flag', | ||
'emoji_unicode', | ||
'carrier', | ||
'languages', | ||
'currency', | ||
'time_zone', | ||
'threat', | ||
'count', | ||
'status', | ||
]; | ||
var BASE_URL = 'https://api.ipdata.co/'; | ||
@@ -31,4 +57,3 @@ function isValidIP(ip) { | ||
} | ||
for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) { | ||
var field = fields_1[_i]; | ||
fields.forEach(function (field) { | ||
var index = VALID_FIELDS.indexOf(field); | ||
@@ -38,12 +63,5 @@ if (index === -1) { | ||
} | ||
} | ||
}); | ||
return true; | ||
} | ||
function clearCache(ip) { | ||
if (isValidIP(ip)) { | ||
return cache.del(ip); | ||
} | ||
return cache.reset(); | ||
} | ||
exports.clearCache = clearCache; | ||
var IPData = /** @class */ (function () { | ||
@@ -88,6 +106,3 @@ function IPData(apiKey, useCache) { | ||
data = tslib_1.__assign(tslib_1.__assign({}, response.data), { status: response.status }); | ||
if (selectField) { | ||
data = { 'select_field': response.data, status: response.status }; | ||
} | ||
if (this.useCache) { | ||
if ((!selectField || !fields) && this.useCache) { | ||
cache.set(ip || DEFAULT_IP, data); | ||
@@ -105,6 +120,3 @@ } | ||
} | ||
else { | ||
throw e_1; | ||
} | ||
return [3 /*break*/, 4]; | ||
throw e_1; | ||
case 4: return [2 /*return*/, cache.get(ip || DEFAULT_IP)]; | ||
@@ -117,3 +129,3 @@ } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var params, _i, ips_1, ip, response, e_2, response; | ||
var params, response, e_2, response; | ||
return tslib_1.__generator(this, function (_a) { | ||
@@ -126,8 +138,7 @@ switch (_a.label) { | ||
} | ||
for (_i = 0, ips_1 = ips; _i < ips_1.length; _i++) { | ||
ip = ips_1[_i]; | ||
ips.forEach(function (ip) { | ||
if (!isValidIP(ip)) { | ||
throw new Error(ip + " is an invalid IP address."); | ||
} | ||
} | ||
}); | ||
if (fields && isValidFields(fields)) { | ||
@@ -149,6 +160,3 @@ params.fields = fields.join(','); | ||
} | ||
else { | ||
throw e_2; | ||
} | ||
return [3 /*break*/, 4]; | ||
throw e_2; | ||
case 4: return [2 /*return*/]; | ||
@@ -155,0 +163,0 @@ } |
{ | ||
"name": "ipdata", | ||
"version": "2.0.0-next.2", | ||
"version": "2.0.0", | ||
"description": "JavaScript library to gather information for an ip using https://ipdata.co.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
226
0
17061