Skip to content

Commit 6671209

Browse files
committed
chore: update README
1 parent 74c4a5e commit 6671209

1 file changed

Lines changed: 41 additions & 34 deletions

File tree

README.md

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
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
```

0 commit comments

Comments
 (0)