Skip to content

Commit d30a16c

Browse files
authored
Merge pull request #15 from ConnerTechnology/release-2.1.0
Release 2.1.0
2 parents f0c6610 + 3cbec79 commit d30a16c

10 files changed

Lines changed: 220 additions & 98 deletions

File tree

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ module.exports = {
3131
},
3232
env: {
3333
jest: true
34-
}
34+
},
35+
parserOptions: {
36+
project: path.resolve(__dirname, './tsconfig.test.json')
37+
},
3538
}
3639
],
3740
settings: {

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
- name: Install dependencies
2626
run: npm ci
2727
- name: Test
28+
env:
29+
IPDATA_API_KEY: ${{ secrets.IPDATA_API_KEY }}
2830
run: npm test
2931

3032
release:

README.md

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# IPData JavaScript Library
22

3-
![](https://github.com/ConnerTechnology/ipdata-js-library/workflows/CI/badge.svg)
3+
[![CI Status](https://github.com/ConnerTechnology/ipdata-js-library/workflows/.github/workflows/main.yml/badge.svg)](https://github.com/ConnerTechnology/ipdata-js-library/actions)
44

55
JavaScript library that can be used in a web browser or Node.js application to gather information using https://ipdata.co.
66

77
**Table of Contents**
8+
89
- [Install](#install)
910
- [Import the library](#import-the-library)
1011
- [Use](#use)
11-
* [Lookup](#lookup)
12-
* [Lookup Bulk](#lookup-bulk)
13-
12+
- [Lookup](#lookup)
13+
- [Lookup Bulk](#lookup-bulk)
1414

1515
## Install
1616

@@ -32,76 +32,83 @@ Create an instance of the `IPData` class and pass your api key for IPData as the
3232
const ipdata = new IPData('<apiKey>');
3333
```
3434

35-
The library will cache responses using the `lookup()` method for 24 hours using a LRU cache. You can turn off the cache by passing `false` as the second parameter to the constructor.
35+
The library will cache 4096 ip addresses responses for 24 hours using a LRU cache by default. You can configure the cache by passing an object as the second paramenter.
36+
37+
```js
38+
const cacheConfig = {
39+
max: 1000, // max size
40+
maxAge: 10 * 60 * 1000, // max age in ms (i.e. 10 minutes)
41+
};
42+
const ipdata = new IPData('<apiKey>', cacheConfig);
43+
```
44+
45+
**Note:** To disable the cache pass `-1` as the `maxAge`.
3646

3747
```js
38-
const ipdata = new IPData('<apiKey>', false);
48+
const cacheConfig = {
49+
maxAge: -1, // disable the cache
50+
};
51+
const ipdata = new IPData('<apiKey>', cacheConfig);
3952
```
4053

4154
### Lookup
4255

4356
The library will lookup the ip address of the host computer if no ip address is provided.
4457

4558
```js
46-
ipdata.lookup()
47-
.then(function(info) {
48-
// info.ip === '<hostcomputerip>'
49-
// ...
50-
});
59+
ipdata.lookup().then(function(info) {
60+
// info.ip === '<hostcomputerip>'
61+
// ...
62+
});
5163
```
5264

5365
You can pass an ip address as the first parameter to the `lookup()` method to lookup information about the ip address using IPData.
5466

5567
```js
56-
ipdata.lookup('1.1.1.1')
57-
.then(function(info) {
58-
// info.ip === 1.1.1.1
59-
// ...
60-
});
68+
ipdata.lookup('1.1.1.1').then(function(info) {
69+
// info.ip === 1.1.1.1
70+
// ...
71+
});
6172
```
6273

6374
You can specify only a select field to be returned when looking up an ip address by passing a field as the second parameter to the `lookup()` method.
6475

6576
```js
6677
const ip = '1.1.1.1';
67-
const selectField = 'ip'
68-
ipdata.lookup(ip, selectField)
69-
.then(function(info) {
70-
// info.select_field === 1.1.1.1
71-
// ...
72-
});
78+
const selectField = 'ip';
79+
ipdata.lookup(ip, selectField).then(function(info) {
80+
// info.select_field === 1.1.1.1
81+
// ...
82+
});
7383
```
7484

7585
You can specify only certain fields to be returned when looking up an ip address by passing an array of fields as the third parameter to the `lookup()` method.
7686

7787
```js
7888
const ip = '1.1.1.1';
7989
const fields = ['ip', 'city'];
80-
ipdata.lookup(ip, null, fields)
81-
.then(function(info) {
82-
// ...
83-
});
90+
ipdata.lookup(ip, null, fields).then(function(info) {
91+
// ...
92+
});
8493
```
8594

8695
### Bulk Lookup
8796

8897
You can lookup multiple ip addresses with one API call using the `bulkLookup()` method.
8998

9099
```js
91-
ipdata.bulkLookup(['1.1.1.1', '1.0.0.1'])
92-
.then(function(info) {
93-
// info.responses[0].ip === 1.1.1.1
94-
// ...
95-
});
100+
ipdata.bulkLookup(['1.1.1.1', '1.0.0.1']).then(function(info) {
101+
// info.responses[0].ip === 1.1.1.1
102+
// ...
103+
});
96104
```
97105

98106
You can specify only certain fields to be returned when looking up multiple ip addresses by passing an array of fields as the second parameter to the `bulkLookup()` method.
99107

100108
```js
101109
const ips = ['1.1.1.1', '1.0.0.1'];
102110
const fields = ['ip', 'city'];
103-
ipdata.bulkLookup(ips, fields)
104-
.then(function(info) {
105-
// ...
106-
});
111+
ipdata.bulkLookup(ips, fields).then(function(info) {
112+
// ...
113+
});
107114
```

package-lock.json

Lines changed: 77 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "ipdata",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "JavaScript library to gather information for an ip using https://ipdata.co.",
5-
"main": "./lib/index.js",
5+
"main": "./lib/ipdata.js",
66
"scripts": {
77
"prebuild": "del lib",
88
"build": "tsc",
99
"lint": "eslint --fix \"src/**\"",
10-
"test": "jest"
10+
"test": "dotenv jest"
1111
},
1212
"repository": {
1313
"type": "git",
@@ -24,7 +24,7 @@
2424
"is-ip": "^3.1.0",
2525
"lodash": "4.17.15",
2626
"lru-cache": "5.1.1",
27-
"tslib": "1.9.3",
27+
"tslib": "1.10.0",
2828
"url-join": "4.0.0"
2929
},
3030
"devDependencies": {
@@ -37,6 +37,7 @@
3737
"@typescript-eslint/eslint-plugin": "^2.4.0",
3838
"@typescript-eslint/parser": "^2.4.0",
3939
"del-cli": "^3.0.0",
40+
"dotenv-cli": "3.0.0",
4041
"eslint": "^6.5.1",
4142
"eslint-config-airbnb-base": "^14.0.0",
4243
"eslint-config-prettier": "^6.4.0",

0 commit comments

Comments
 (0)