Skip to content

Commit

Permalink
Require Node.js 14 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 1, 2022
1 parent 25678d0 commit 4baabdf
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 55 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
49 changes: 24 additions & 25 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
declare namespace ipify {
interface Options {
/**
Use the IPv6 API endpoint. The IPv6 endpoint will return an IPv6 address if available, IPv4 address otherwise.
export interface Options {
/**
Use the IPv6 API endpoint. The IPv6 endpoint will return an IPv6 address if available, IPv4 address otherwise.
Setting the `endpoint` option will override this.
Setting the `endpoint` option will override this.
@default true
*/
readonly useIPv6?: boolean;
@default true
/**
Custom API endpoint.
@example
```
import ipify from 'ipify';
@default 'https://api6.ipify.org'
*/
readonly endpoint?: string;
}
console.log(await ipify({useIPv6: false}));
//=> '82.142.31.236'
```
*/
readonly useIPv6?: boolean;

/**
Custom API endpoint.
@default 'https://api6.ipify.org'
*/
readonly endpoint?: string;
}

/**
Expand All @@ -25,17 +31,10 @@ Get your public IP address.
@example
```
import ipify = require('ipify');
import ipify from 'ipify';
(async () => {
console.log(await ipify());
//=> '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
console.log(await ipify({useIPv6: false}));
//=> '82.142.31.236'
})();
console.log(await ipify());
//=> '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
```
*/
declare function ipify(options?: ipify.Options): Promise<string>;

export = ipify;
export default function ipify(options?: Options): Promise<string>;
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';
const got = require('got');
import got from 'got';

const IPIFY_ENDPOINT_IPV4 = 'https://api.ipify.org';
const IPIFY_ENDPOINT_IPV6 = 'https://api6.ipify.org';

module.exports = async ({useIPv6 = true, endpoint} = {}) => {
export default async function ipify({useIPv6 = true, endpoint} = {}) {
if (endpoint === undefined) {
endpoint = useIPv6 ? IPIFY_ENDPOINT_IPV6 : IPIFY_ENDPOINT_IPV4;
}

const {body} = await got(endpoint);
return body;
};
}
7 changes: 3 additions & 4 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {expectType} from 'tsd';
import ipify = require('.');
import ipify from './index.js';

const options: ipify.Options = {};
expectType<Promise<string>>(ipify());
expectType<Promise<string>>(ipify({useIPv6: true}));
expectType<Promise<string>>(ipify({useIPv6: false}));
expectType<Promise<string>>(ipify({useIPv6: true})); // eslint-disable-line @typescript-eslint/naming-convention
expectType<Promise<string>>(ipify({useIPv6: false})); // eslint-disable-line @typescript-eslint/naming-convention
expectType<Promise<string>>(ipify({endpoint: 'https://example.com'}));
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": "^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -30,12 +32,12 @@
"own"
],
"dependencies": {
"got": "^11.8.0"
"got": "^12.0.0"
},
"devDependencies": {
"ava": "^2.4.0",
"ava": "^3.15.0",
"is-ip": "^3.1.0",
"tsd": "^0.13.1",
"xo": "^0.35.0"
"tsd": "^0.19.1",
"xo": "^0.47.0"
}
}
22 changes: 12 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@ Using the [Ipify API](https://www.ipify.org) or a [custom Ipify instance](https:

## Install

```
$ npm install ipify
```sh
npm install ipify
```

## Usage

```js
const ipify = require('ipify');

(async () => {
console.log(await ipify());
//=> '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
import ipify from 'ipify';

console.log(await ipify({useIPv6: false}));
//=> '82.142.31.236'
})();
console.log(await ipify());
//=> '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
```

## API
Expand All @@ -43,6 +38,13 @@ Use the IPv6 API endpoint. The IPv6 endpoint will return an IPv6 address if avai

Setting the `endpoint` option will override this.

```js
import ipify from 'ipify';

console.log(await ipify({useIPv6: false}));
//=> '82.142.31.236'
```

##### endpoint

Type: `string`\
Expand Down
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import process from 'node:process';
import test from 'ava';
import isIp from 'is-ip';
import ipify from '.';
import ipify from './index.js';

// GitHub Actions doesn't support IPv6: https://github.com/actions/virtual-environments/issues/668
if (!process.env.CI) {
Expand Down

0 comments on commit 4baabdf

Please sign in to comment.