Skip to content

Commit 6ee840b

Browse files
committed
chore: update README
1 parent 29054ce commit 6ee840b

1 file changed

Lines changed: 46 additions & 27 deletions

File tree

README.md

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,41 @@
22

33
[![](https://github.com/ConnerTechnology/ipdata-js-library/workflows/CI/badge.svg)](https://github.com/ConnerTechnology/ipdata-js-library/actions)
44

5-
JavaScript library that can be used in a web browser or Node.js application to gather information using https://ipdata.co.
5+
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.
66

77
**Table of Contents**
88

99
- [Install](#install)
10-
- [Import the library](#import-the-library)
1110
- [Use](#use)
11+
- [Import Library](#import-library)
12+
- [Create an Instance](#create-an-instance)
1213
- [Lookup](#lookup)
13-
- [Lookup Bulk](#lookup-bulk)
14+
- [Bulk Lookup](#bulk-lookup)
1415

1516
## Install
1617

1718
```sh
1819
$ npm install ipdata
1920
```
2021

21-
## Import the library
22+
## Use
23+
24+
### Import library
2225

2326
Import the library.
2427

2528
```js
26-
import ipdata from 'ipdata';
29+
import IPData from 'ipdata';
30+
```
31+
32+
**Note:** If you are using `require()` then you will need to use the default value exported from the library.
33+
34+
```js
35+
const IPData = require('ipdata').default;
2736
```
2837

38+
### Create an Instance
39+
2940
Create an instance of the `IPData` class and pass your api key for IPData as the first parameter.
3041

3142
```js
@@ -56,59 +67,67 @@ const ipdata = new IPData('<apiKey>', cacheConfig);
5667
The library will lookup the ip address of the host computer if no ip address is provided.
5768

5869
```js
59-
ipdata.lookup().then(function(info) {
60-
// info.ip === '<hostcomputerip>'
61-
// ...
62-
});
70+
ipdata.lookup()
71+
.then(function(info) {
72+
// info.ip === '<hostcomputerip>'
73+
// ...
74+
});
6375
```
6476

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

6779
```js
68-
ipdata.lookup('1.1.1.1').then(function(info) {
69-
// info.ip === 1.1.1.1
70-
// ...
71-
});
80+
const ip = '1.1.1.1';
81+
ipdata.lookup(ip)
82+
.then(function(info) {
83+
// info.ip === 1.1.1.1
84+
// ...
85+
});
7286
```
7387

7488
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.
7589

7690
```js
7791
const ip = '1.1.1.1';
7892
const selectField = 'ip';
79-
ipdata.lookup(ip, selectField).then(function(info) {
80-
// info.select_field === 1.1.1.1
81-
// ...
82-
});
93+
ipdata.lookup(ip, selectField)
94+
.then(function(info) {
95+
// info.select_field === 1.1.1.1
96+
// ...
97+
});
8398
```
8499

85100
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.
86101

87102
```js
88103
const ip = '1.1.1.1';
89104
const fields = ['ip', 'city'];
90-
ipdata.lookup(ip, null, fields).then(function(info) {
91-
// ...
92-
});
105+
ipdata.lookup(ip, null, fields)
106+
.then(function(info) {
107+
// ...
108+
});
93109
```
94110

95111
### Bulk Lookup
96112

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

99115
```js
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-
});
116+
const ips = ['1.1.1.1', '1.0.0.1'];
117+
ipdata.bulkLookup(ips)
118+
.then(function(info) {
119+
// info[0].ip === 1.1.1.1
120+
// ...
121+
});
104122
```
105123

106124
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.
107125

108126
```js
109127
const ips = ['1.1.1.1', '1.0.0.1'];
110128
const fields = ['ip', 'city'];
111-
ipdata.bulkLookup(ips, fields).then(function(info) {
112-
// ...
113-
});
129+
ipdata.bulkLookup(ips, fields)
130+
.then(function(info) {
131+
// ...
132+
});
114133
```

0 commit comments

Comments
 (0)