Comparing version 0.0.0-5176f56 to 0.0.0-57ffa46
@@ -60,6 +60,2 @@ import LRU from 'lru-cache'; | ||
} | ||
export interface BulkLookupResponse { | ||
responses: LookupResponse[]; | ||
status: number; | ||
} | ||
export default class IPData { | ||
@@ -70,3 +66,3 @@ apiKey?: string; | ||
lookup(ip?: string, selectField?: string, fields?: string[]): Promise<LookupResponse>; | ||
bulkLookup(ips: string[], fields?: string[]): Promise<BulkLookupResponse>; | ||
bulkLookup(ips: string[], fields?: string[]): Promise<LookupResponse[]>; | ||
} |
@@ -106,3 +106,3 @@ "use strict"; | ||
this.cache.set(ip || DEFAULT_IP, data); | ||
return [3 /*break*/, 4]; | ||
return [2 /*return*/, this.cache.get(ip || DEFAULT_IP)]; | ||
case 3: | ||
@@ -115,3 +115,3 @@ e_1 = _b.sent(); | ||
throw e_1; | ||
case 4: return [2 /*return*/, this.cache.get(ip || DEFAULT_IP)]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -123,3 +123,3 @@ }); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var params, responses, bulk, result, response, e_2, response; | ||
var params, responses, bulk, response_1, e_2, response; | ||
var _this = this; | ||
@@ -152,13 +152,12 @@ return tslib_1.__generator(this, function (_a) { | ||
_a.trys.push([1, 4, , 5]); | ||
result = { responses: responses, status: 200 }; | ||
if (!(bulk.length > 0)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, axios_1.default.post(url_join_1.default(BASE_URL, 'bulk'), bulk, { params: params })]; | ||
case 2: | ||
response = _a.sent(); | ||
response.data.forEach(function (info) { | ||
_this.cache.set(info.ip, info); | ||
response_1 = _a.sent(); | ||
response_1.data.forEach(function (info) { | ||
_this.cache.set(info.ip, tslib_1.__assign(tslib_1.__assign({}, info), { status: response_1.status })); | ||
responses.push(_this.cache.get(info.ip)); | ||
}); | ||
result = { responses: tslib_1.__spreadArrays(responses, response.data), status: response.status }; | ||
_a.label = 3; | ||
case 3: return [2 /*return*/, result]; | ||
case 3: return [2 /*return*/, responses]; | ||
case 4: | ||
@@ -165,0 +164,0 @@ e_2 = _a.sent(); |
{ | ||
"name": "ipdata", | ||
"version": "0.0.0-5176f56", | ||
"version": "0.0.0-57ffa46", | ||
"description": "JavaScript library to gather information for an ip using https://ipdata.co.", | ||
@@ -25,20 +25,20 @@ "main": "./lib/ipdata.js", | ||
"is-ip": "^3.1.0", | ||
"lodash": "4.17.15", | ||
"lru-cache": "5.1.1", | ||
"tslib": "1.10.0", | ||
"url-join": "4.0.0" | ||
"lodash": "^4.17.15", | ||
"lru-cache": "^5.1.1", | ||
"tslib": "^1.10.0", | ||
"url-join": "^4.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.19", | ||
"@types/lodash": "4.14.144", | ||
"@types/lru-cache": "5.1.0", | ||
"@types/nock": "9.3.0", | ||
"@types/node": "10.9.4", | ||
"@types/url-join": "0.8.2", | ||
"@typescript-eslint/eslint-plugin": "^2.4.0", | ||
"@typescript-eslint/parser": "^2.4.0", | ||
"@types/jest": "^24.0.22", | ||
"@types/lodash": "^4.14.144", | ||
"@types/lru-cache": "^5.1.0", | ||
"@types/node": "^12.12.6", | ||
"@types/url-join": "^4.0.0", | ||
"@typescript-eslint/eslint-plugin": "^2.6.1", | ||
"@typescript-eslint/parser": "^2.6.1", | ||
"del-cli": "^3.0.0", | ||
"dotenv-cli": "3.0.0", | ||
"dotenv-cli": "^3.0.0", | ||
"eslint": "^6.5.1", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
"eslint-plugin-jest": "^23.0.2", | ||
"eslint-config-prettier": "^6.4.0", | ||
@@ -48,6 +48,5 @@ "eslint-plugin-import": "^2.18.2", | ||
"jest": "^24.9.0", | ||
"nock": "9.6.1", | ||
"prettier": "^1.18.2", | ||
"ts-jest": "^24.1.0", | ||
"typescript": "^3.6.4" | ||
"typescript": "^3.7.2" | ||
}, | ||
@@ -54,0 +53,0 @@ "files": [ |
@@ -5,3 +5,3 @@ # IPData JavaScript Library | ||
JavaScript library that can be used in a web browser or Node.js application to gather information using https://ipdata.co. | ||
JavaScript library that can be used in a web browser or Node.js application to gather information for an IP address using https://ipdata.co. | ||
@@ -11,6 +11,7 @@ **Table of Contents** | ||
- [Install](#install) | ||
- [Import the library](#import-the-library) | ||
- [Use](#use) | ||
- [Import Library](#import-library) | ||
- [Create an Instance](#create-an-instance) | ||
- [Lookup](#lookup) | ||
- [Lookup Bulk](#lookup-bulk) | ||
- [Bulk Lookup](#bulk-lookup) | ||
@@ -23,10 +24,20 @@ ## Install | ||
## Import the library | ||
## Use | ||
### Import library | ||
Import the library. | ||
```js | ||
import ipdata from 'ipdata'; | ||
import IPData from 'ipdata'; | ||
``` | ||
**Note:** If you are using `require()` then you will need to use the default value exported from the library. | ||
```js | ||
const IPData = require('ipdata').default; | ||
``` | ||
### Create an Instance | ||
Create an instance of the `IPData` class and pass your api key for IPData as the first parameter. | ||
@@ -62,6 +73,7 @@ | ||
```js | ||
ipdata.lookup().then(function(info) { | ||
// info.ip === '<hostcomputerip>' | ||
// ... | ||
}); | ||
ipdata.lookup() | ||
.then(function(info) { | ||
// info.ip === '<hostcomputerip>' | ||
// ... | ||
}); | ||
``` | ||
@@ -72,6 +84,8 @@ | ||
```js | ||
ipdata.lookup('1.1.1.1').then(function(info) { | ||
// info.ip === 1.1.1.1 | ||
// ... | ||
}); | ||
const ip = '1.1.1.1'; | ||
ipdata.lookup(ip) | ||
.then(function(info) { | ||
// info.ip === 1.1.1.1 | ||
// ... | ||
}); | ||
``` | ||
@@ -84,6 +98,7 @@ | ||
const selectField = 'ip'; | ||
ipdata.lookup(ip, selectField).then(function(info) { | ||
// info.select_field === 1.1.1.1 | ||
// ... | ||
}); | ||
ipdata.lookup(ip, selectField) | ||
.then(function(info) { | ||
// info.select_field === 1.1.1.1 | ||
// ... | ||
}); | ||
``` | ||
@@ -96,5 +111,6 @@ | ||
const fields = ['ip', 'city']; | ||
ipdata.lookup(ip, null, fields).then(function(info) { | ||
// ... | ||
}); | ||
ipdata.lookup(ip, null, fields) | ||
.then(function(info) { | ||
// ... | ||
}); | ||
``` | ||
@@ -107,6 +123,8 @@ | ||
```js | ||
ipdata.bulkLookup(['1.1.1.1', '1.0.0.1']).then(function(info) { | ||
// info.responses[0].ip === 1.1.1.1 | ||
// ... | ||
}); | ||
const ips = ['1.1.1.1', '1.0.0.1']; | ||
ipdata.bulkLookup(ips) | ||
.then(function(info) { | ||
// info[0].ip === 1.1.1.1 | ||
// ... | ||
}); | ||
``` | ||
@@ -119,5 +137,6 @@ | ||
const fields = ['ip', 'city']; | ||
ipdata.bulkLookup(ips, fields).then(function(info) { | ||
// ... | ||
}); | ||
ipdata.bulkLookup(ips, fields) | ||
.then(function(info) { | ||
// ... | ||
}); | ||
``` |
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
18863
19
134
239
+ Addedlodash@4.17.21(transitive)
+ Addedtslib@1.14.1(transitive)
+ Addedurl-join@4.0.1(transitive)
- Removedlodash@4.17.15(transitive)
- Removedtslib@1.10.0(transitive)
- Removedurl-join@4.0.0(transitive)
Updatedlodash@^4.17.15
Updatedlru-cache@^5.1.1
Updatedtslib@^1.10.0
Updatedurl-join@^4.0.1