Skip to content

Commit a1d376f

Browse files
committed
Rewrite README to reflect Node.js-only library
The library uses the `net` module for IP validation, making it Node-only. Updated the README to drop the inaccurate browser support claim, document the Node 18+ requirement, use modern async/await examples, and add a TypeScript section listing exported types. https://claude.ai/code/session_01UabaLo3R3sXovyxaZo2yCF
1 parent 2b0154b commit a1d376f

File tree

1 file changed

+54
-75
lines changed

1 file changed

+54
-75
lines changed

README.md

Lines changed: 54 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# IPData JavaScript Library
1+
# IPData Node.js Library
22

33
[![](https://github.com/ipdata/node/workflows/CI/badge.svg)](https://github.com/ipdata/node/actions)
44

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.
5+
A Node.js library for the [ipdata](https://ipdata.co) API. Look up IP addresses for geolocation, threat intelligence, company data, and more.
6+
7+
Requires **Node.js 18** or later. Uses the native `fetch` API with zero HTTP dependencies.
68

79
**Table of Contents**
810

@@ -14,18 +16,17 @@ JavaScript library that can be used in a web browser or Node.js application to g
1416
- [Lookup](#lookup)
1517
- [Bulk Lookup](#bulk-lookup)
1618
- [Response Fields](#response-fields)
19+
- [TypeScript](#typescript)
1720

1821
## Install
1922

2023
```sh
21-
$ npm install ipdata
24+
npm install ipdata
2225
```
2326

2427
## Use
2528

26-
### Import library
27-
28-
Import the library.
29+
### Import Library
2930

3031
```js
3132
import IPData from 'ipdata';
@@ -37,148 +38,126 @@ A named export is also available:
3738
import { IPData } from 'ipdata';
3839
```
3940

40-
If you are using `require()`:
41+
CommonJS:
4142

4243
```js
4344
const { IPData } = require('ipdata');
4445
```
4546

4647
### Create an Instance
4748

48-
Create an instance of the `IPData` class and pass your api key for IPData as the first parameter.
49+
Create an instance of the `IPData` class with your [API key](https://ipdata.co/).
4950

5051
```js
5152
const ipdata = new IPData('<apiKey>');
5253
```
5354

54-
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.
55+
#### Caching
56+
57+
The library caches up to 4096 responses for 24 hours using an LRU cache by default. You can configure the cache by passing an options object as the second parameter.
5558

5659
```js
57-
const cacheConfig = {
58-
max: 1000, // max size
59-
ttl: 10 * 60 * 1000, // time-to-live in ms (i.e. 10 minutes)
60-
};
61-
const ipdata = new IPData('<apiKey>', cacheConfig);
60+
const ipdata = new IPData('<apiKey>', {
61+
max: 1000, // max number of entries
62+
ttl: 10 * 60 * 1000, // 10 minutes
63+
});
6264
```
6365

64-
**Note:** To disable the cache pass `1` as the `ttl` (1ms effectively disables caching).
66+
To disable caching, set `ttl` to `1`:
6567

6668
```js
67-
const cacheConfig = {
68-
ttl: 1, // disable the cache
69-
};
70-
const ipdata = new IPData('<apiKey>', cacheConfig);
69+
const ipdata = new IPData('<apiKey>', { ttl: 1 });
7170
```
7271

7372
### EU Endpoint
7473

75-
By default requests are routed to the global endpoint (`https://api.ipdata.co`). To ensure end user data stays in the EU, pass the EU endpoint as the third parameter.
74+
By default requests are routed to the global endpoint (`https://api.ipdata.co`). To ensure end-user data stays in the EU, pass the EU endpoint as the third parameter.
7675

7776
```js
7877
import IPData, { EU_BASE_URL } from 'ipdata';
7978

8079
const ipdata = new IPData('<apiKey>', undefined, EU_BASE_URL);
8180
```
8281

83-
You can also pass a custom base URL if needed.
82+
You can also pass any custom base URL:
8483

8584
```js
8685
const ipdata = new IPData('<apiKey>', undefined, 'https://eu-api.ipdata.co/');
8786
```
8887

8988
### Lookup
9089

91-
The `lookup()` method accepts either positional arguments or a single named-params object.
92-
93-
The library will lookup the ip address of the host computer if no ip address is provided.
90+
Look up the current machine's IP when called with no arguments:
9491

9592
```js
96-
ipdata.lookup()
97-
.then(function(info) {
98-
// info.ip === '<hostcomputerip>'
99-
// ...
100-
});
93+
const info = await ipdata.lookup();
94+
// info.ip === '<your ip>'
10195
```
10296

103-
You can pass an ip address to lookup information about it.
97+
Pass an IP address to look it up:
10498

10599
```js
106-
ipdata.lookup('1.1.1.1')
107-
.then(function(info) {
108-
// info.ip === '1.1.1.1'
109-
// ...
110-
});
100+
const info = await ipdata.lookup('1.1.1.1');
101+
// info.ip === '1.1.1.1'
111102
```
112103

113-
You can specify a single field to be returned.
104+
Return a single field:
114105

115106
```js
116-
ipdata.lookup('1.1.1.1', 'ip')
117-
.then(function(info) {
118-
// info.ip === '1.1.1.1'
119-
// ...
120-
});
107+
const info = await ipdata.lookup('1.1.1.1', 'city');
121108
```
122109

123-
You can specify multiple fields to be returned.
110+
Return multiple fields:
124111

125112
```js
126-
ipdata.lookup('1.1.1.1', undefined, ['ip', 'city'])
127-
.then(function(info) {
128-
// ...
129-
});
113+
const info = await ipdata.lookup('1.1.1.1', undefined, ['ip', 'city']);
130114
```
131115

132116
#### Named Parameters
133117

134-
You can also pass a single object, which is especially convenient when you only need `fields` or `selectField` without specifying an IP.
118+
You can also pass a single object, which is convenient when you only need `fields` or `selectField` without specifying an IP.
135119

136120
```js
137-
// Lookup your own IP with specific fields
138-
ipdata.lookup({ fields: ['ip', 'city'] })
139-
.then(function(info) {
140-
// ...
141-
});
121+
// Look up your own IP with specific fields
122+
const info = await ipdata.lookup({ fields: ['ip', 'city'] });
142123

143-
// Lookup a specific IP with a select field
144-
ipdata.lookup({ ip: '1.1.1.1', selectField: 'city' })
145-
.then(function(info) {
146-
// ...
147-
});
124+
// Look up a specific IP with a single field
125+
const info = await ipdata.lookup({ ip: '1.1.1.1', selectField: 'city' });
148126
```
149127

150128
### Bulk Lookup
151129

152-
You can lookup multiple ip addresses with one API call using the `bulkLookup()` method.
130+
Look up multiple IP addresses in a single API call:
153131

154132
```js
155-
const ips = ['1.1.1.1', '1.0.0.1'];
156-
ipdata.bulkLookup(ips)
157-
.then(function(info) {
158-
// info[0].ip === 1.1.1.1
159-
// ...
160-
});
133+
const info = await ipdata.bulkLookup(['1.1.1.1', '1.0.0.1']);
134+
// info[0].ip === '1.1.1.1'
161135
```
162136

163-
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.
137+
With field filtering:
164138

165139
```js
166-
const ips = ['1.1.1.1', '1.0.0.1'];
167-
const fields = ['ip', 'city'];
168-
ipdata.bulkLookup(ips, fields)
169-
.then(function(info) {
170-
// ...
171-
});
140+
const info = await ipdata.bulkLookup(['1.1.1.1', '1.0.0.1'], ['ip', 'city']);
172141
```
173142

174143
## Response Fields
175144

176-
The following fields are available for use with `selectField` and `fields` parameters:
145+
The following fields are available for use with `selectField` and `fields`:
177146

178147
`ip`, `is_eu`, `city`, `region`, `region_code`, `country_name`, `country_code`, `continent_name`, `continent_code`, `latitude`, `longitude`, `asn`, `company`, `organisation`, `postal`, `calling_code`, `flag`, `emoji_flag`, `emoji_unicode`, `carrier`, `languages`, `currency`, `time_zone`, `threat`, `count`
179148

180-
The `company` field returns an object with `name`, `domain`, `network`, and `type` properties.
149+
**`asn`**`{ asn, name, domain, route, type }`
150+
151+
**`company`**`{ name, domain, network, type }`
181152

182-
The `carrier` field returns an object with `name`, `mcc`, and `mnc` properties.
153+
**`carrier`**`{ name, mcc, mnc }`
183154

184-
The `threat` field returns an object with `is_tor`, `is_icloud_relay`, `is_proxy`, `is_datacenter`, `is_anonymous`, `is_known_attacker`, `is_known_abuser`, `is_threat`, `is_bogon`, and `blocklists` properties.
155+
**`threat`**`{ is_tor, is_icloud_relay, is_proxy, is_datacenter, is_anonymous, is_known_attacker, is_known_abuser, is_threat, is_bogon, blocklists }`
156+
157+
## TypeScript
158+
159+
The library is written in TypeScript and exports the following types:
160+
161+
```ts
162+
import IPData, { EU_BASE_URL, CacheConfig, LookupParams, LookupResponse } from 'ipdata';
163+
```

0 commit comments

Comments
 (0)