Skip to content

Commit 4552a00

Browse files
committed
Require Node.js 20
1 parent c3247e7 commit 4552a00

File tree

5 files changed

+42
-46
lines changed

5 files changed

+42
-46
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 16
14-
- 14
13+
- 24
14+
- 20
1515
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2
16+
- uses: actions/checkout@v5
17+
- uses: actions/setup-node@v5
1818
with:
1919
node-version: ${{ matrix.node-version }}
2020
- run: npm install

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface Options {
1+
export type Options = {
22
/**
33
Use the IPv6 API endpoint. The IPv6 endpoint will return an IPv6 address if available, IPv4 address otherwise.
44
@@ -42,7 +42,7 @@ export interface Options {
4242
```
4343
*/
4444
readonly endpoint?: string | readonly string[];
45-
}
45+
};
4646

4747
/**
4848
Get your public IP address.

index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import got from 'got';
2-
31
const IPIFY_ENDPOINT_IPV4 = 'https://api.ipify.org';
42
const IPIFY_ENDPOINT_IPV6 = 'https://api6.ipify.org';
53

@@ -11,15 +9,12 @@ export default async function ipify({useIPv6 = true, endpoint} = {}) {
119
throw new TypeError('Endpoint array cannot be empty');
1210
}
1311

14-
// eslint-disable-next-line no-use-extend-native/no-use-extend-native
15-
return Promise.any(
16-
endpoint.map(async url => {
17-
const {body} = await got(url);
18-
return body;
19-
}),
20-
);
12+
return Promise.any(endpoint.map(async url => {
13+
const response = await fetch(url);
14+
return response.text();
15+
}));
2116
}
2217

23-
const {body} = await got(endpoint);
24-
return body;
18+
const response = await fetch(endpoint);
19+
return response.text();
2520
}

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
"url": "https://sindresorhus.com"
1212
},
1313
"type": "module",
14-
"exports": "./index.js",
14+
"exports": {
15+
"types": "./index.d.ts",
16+
"default": "./index.js"
17+
},
18+
"sideEffects": false,
1519
"engines": {
16-
"node": ">=15.0.0"
20+
"node": ">=20"
1721
},
1822
"scripts": {
19-
"test": "xo && ava && tsd"
23+
"test": "xo && node --test && tsd"
2024
},
2125
"files": [
2226
"index.js",
@@ -31,13 +35,9 @@
3135
"external",
3236
"own"
3337
],
34-
"dependencies": {
35-
"got": "^12.0.0"
36-
},
3738
"devDependencies": {
38-
"ava": "^3.15.0",
39-
"is-ip": "^3.1.0",
40-
"tsd": "^0.19.1",
41-
"xo": "^0.47.0"
39+
"is-ip": "^5.0.1",
40+
"tsd": "^0.33.0",
41+
"xo": "^1.2.2"
4242
}
4343
}

test.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,62 @@
1+
import {test} from 'node:test';
2+
import assert from 'node:assert';
13
import process from 'node:process';
2-
import test from 'ava';
3-
import isIp from 'is-ip';
4+
import {isIP, isIPv4} from 'is-ip';
45
import ipify from './index.js';
56

67
// GitHub Actions doesn't support IPv6: https://github.com/actions/virtual-environments/issues/668
78
if (!process.env.CI) {
8-
test('main', async t => {
9-
t.true(isIp(await ipify()));
9+
test('main', async () => {
10+
assert.ok(isIP(await ipify()));
1011
});
1112
}
1213

13-
test('useIPv6:false', async t => {
14-
t.true(isIp.v4(await ipify({useIPv6: false})));
14+
test('useIPv6:false', async () => {
15+
assert.ok(isIPv4(await ipify({useIPv6: false})));
1516
});
1617

17-
test('endpoint:custom', async t => {
18-
t.true(isIp.v4(await ipify({endpoint: 'https://api.ipify.org'})));
18+
test('endpoint:custom', async () => {
19+
assert.ok(isIPv4(await ipify({endpoint: 'https://api.ipify.org'})));
1920
});
2021

21-
test('endpoint:array', async t => {
22+
test('endpoint:array', async () => {
2223
const result = await ipify({
2324
endpoint: [
2425
'https://api.ipify.org',
2526
'https://api6.ipify.org',
2627
],
2728
});
28-
t.true(isIp(result));
29+
assert.ok(isIP(result));
2930
});
3031

31-
test('endpoint:empty array throws', async t => {
32-
await t.throwsAsync(
32+
test('endpoint:empty array throws', async () => {
33+
await assert.rejects(
3334
ipify({endpoint: []}),
34-
{instanceOf: TypeError, message: 'Endpoint array cannot be empty'},
35+
{name: 'TypeError', message: 'Endpoint array cannot be empty'},
3536
);
3637
});
3738

38-
test('endpoint:single-item array', async t => {
39+
test('endpoint:single-item array', async () => {
3940
const result = await ipify({
4041
endpoint: ['https://api.ipify.org'],
4142
});
42-
t.true(isIp.v4(result));
43+
assert.ok(isIPv4(result));
4344
});
4445

45-
test('endpoint overrides useIPv6', async t => {
46+
test('endpoint overrides useIPv6', async () => {
4647
const result = await ipify({
4748
useIPv6: true,
4849
endpoint: 'https://api.ipify.org',
4950
});
50-
t.true(isIp.v4(result));
51+
assert.ok(isIPv4(result));
5152
});
5253

53-
test('endpoint:array with duplicates', async t => {
54+
test('endpoint:array with duplicates', async () => {
5455
const result = await ipify({
5556
endpoint: [
5657
'https://api.ipify.org',
5758
'https://api.ipify.org',
5859
],
5960
});
60-
t.true(isIp.v4(result));
61+
assert.ok(isIPv4(result));
6162
});

0 commit comments

Comments
 (0)