@cjser/ipify 7.0.0-cjser.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjser/index.cjs +40 -0
- package/index.d.ts +60 -0
- package/index.js +20 -0
- package/license +9 -0
- package/package.json +70 -0
- package/readme.md +88 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/@cjser/ipify.tmp-26-1778152364913/index.js
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
default: () => ipify
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(index_exports);
|
|
25
|
+
var IPIFY_ENDPOINT_IPV4 = "https://api.ipify.org";
|
|
26
|
+
var IPIFY_ENDPOINT_IPV6 = "https://api6.ipify.org";
|
|
27
|
+
async function ipify({ useIPv6 = true, endpoint } = {}) {
|
|
28
|
+
endpoint ??= useIPv6 ? IPIFY_ENDPOINT_IPV6 : IPIFY_ENDPOINT_IPV4;
|
|
29
|
+
if (Array.isArray(endpoint)) {
|
|
30
|
+
if (endpoint.length === 0) {
|
|
31
|
+
throw new TypeError("Endpoint array cannot be empty");
|
|
32
|
+
}
|
|
33
|
+
return Promise.any(endpoint.map(async (url) => {
|
|
34
|
+
const response2 = await fetch(url);
|
|
35
|
+
return response2.text();
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
const response = await fetch(endpoint);
|
|
39
|
+
return response.text();
|
|
40
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type Options = {
|
|
2
|
+
/**
|
|
3
|
+
Use the IPv6 API endpoint. The IPv6 endpoint will return an IPv6 address if available, IPv4 address otherwise.
|
|
4
|
+
|
|
5
|
+
Setting the `endpoint` option will override this.
|
|
6
|
+
|
|
7
|
+
@default true
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import ipify from '@cjser/ipify';
|
|
12
|
+
|
|
13
|
+
console.log(await ipify({useIPv6: false}));
|
|
14
|
+
//=> '82.142.31.236'
|
|
15
|
+
```
|
|
16
|
+
*/
|
|
17
|
+
readonly useIPv6?: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
Custom API endpoint.
|
|
21
|
+
|
|
22
|
+
Can be a single endpoint or an array of endpoints. When multiple endpoints are provided, they will be tried concurrently and the first successful response will be returned.
|
|
23
|
+
|
|
24
|
+
@default 'https://api6.ipify.org'
|
|
25
|
+
|
|
26
|
+
@example
|
|
27
|
+
```
|
|
28
|
+
import ipify from '@cjser/ipify';
|
|
29
|
+
|
|
30
|
+
// Single endpoint
|
|
31
|
+
console.log(await ipify({endpoint: 'https://api.ipify.org'}));
|
|
32
|
+
//=> '82.142.31.236'
|
|
33
|
+
|
|
34
|
+
// Multiple endpoints for resilience
|
|
35
|
+
console.log(await ipify({
|
|
36
|
+
endpoint: [
|
|
37
|
+
'https://api.ipify.org',
|
|
38
|
+
'https://ipify.example.org'
|
|
39
|
+
]
|
|
40
|
+
}));
|
|
41
|
+
//=> '82.142.31.236'
|
|
42
|
+
```
|
|
43
|
+
*/
|
|
44
|
+
readonly endpoint?: string | readonly string[];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
Get your public IP address.
|
|
49
|
+
|
|
50
|
+
@returns An IP address.
|
|
51
|
+
|
|
52
|
+
@example
|
|
53
|
+
```
|
|
54
|
+
import ipify from '@cjser/ipify';
|
|
55
|
+
|
|
56
|
+
console.log(await ipify());
|
|
57
|
+
//=> '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
|
|
58
|
+
```
|
|
59
|
+
*/
|
|
60
|
+
export default function ipify(options?: Options): Promise<string>;
|
package/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const IPIFY_ENDPOINT_IPV4 = 'https://api.ipify.org';
|
|
2
|
+
const IPIFY_ENDPOINT_IPV6 = 'https://api6.ipify.org';
|
|
3
|
+
|
|
4
|
+
export default async function ipify({useIPv6 = true, endpoint} = {}) {
|
|
5
|
+
endpoint ??= useIPv6 ? IPIFY_ENDPOINT_IPV6 : IPIFY_ENDPOINT_IPV4;
|
|
6
|
+
|
|
7
|
+
if (Array.isArray(endpoint)) {
|
|
8
|
+
if (endpoint.length === 0) {
|
|
9
|
+
throw new TypeError('Endpoint array cannot be empty');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return Promise.any(endpoint.map(async url => {
|
|
13
|
+
const response = await fetch(url);
|
|
14
|
+
return response.text();
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const response = await fetch(endpoint);
|
|
19
|
+
return response.text();
|
|
20
|
+
}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/ipify",
|
|
3
|
+
"version": "7.0.0-cjser.2",
|
|
4
|
+
"description": "Get your public IP address",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://code.moenext.com/3rdeye/cjser.git"
|
|
9
|
+
},
|
|
10
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Sindre Sorhus",
|
|
13
|
+
"email": "sindresorhus@gmail.com",
|
|
14
|
+
"url": "https://sindresorhus.com"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"require": "./dist-cjser/index.cjs",
|
|
20
|
+
"default": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "xo && node --test && tsd"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"index.js",
|
|
31
|
+
"index.d.ts",
|
|
32
|
+
"dist-cjser"
|
|
33
|
+
],
|
|
34
|
+
"keywords": [
|
|
35
|
+
"ip",
|
|
36
|
+
"ipv6",
|
|
37
|
+
"ipv4",
|
|
38
|
+
"address",
|
|
39
|
+
"public",
|
|
40
|
+
"external",
|
|
41
|
+
"own"
|
|
42
|
+
],
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"is-ip": "^5.0.1",
|
|
45
|
+
"tsd": "^0.33.0",
|
|
46
|
+
"xo": "^1.2.2"
|
|
47
|
+
},
|
|
48
|
+
"types": "./index.d.ts",
|
|
49
|
+
"main": "./dist-cjser/index.cjs",
|
|
50
|
+
"cjser": {
|
|
51
|
+
"sourceVersion": "7.0.0",
|
|
52
|
+
"cjserVersion": 2,
|
|
53
|
+
"original": {
|
|
54
|
+
"name": "ipify",
|
|
55
|
+
"version": "7.0.0",
|
|
56
|
+
"exports": {
|
|
57
|
+
"types": "./index.d.ts",
|
|
58
|
+
"default": "./index.js"
|
|
59
|
+
},
|
|
60
|
+
"repository": "sindresorhus/ipify",
|
|
61
|
+
"files": [
|
|
62
|
+
"index.js",
|
|
63
|
+
"index.d.ts"
|
|
64
|
+
],
|
|
65
|
+
"scripts": {
|
|
66
|
+
"test": "xo && node --test && tsd"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# ipify
|
|
2
|
+
|
|
3
|
+
> Get your public IP address
|
|
4
|
+
|
|
5
|
+
Using the [Ipify API](https://www.ipify.org) or a [custom Ipify instance](https://github.com/rdegges/ipify-api).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install ipify
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import ipify from 'ipify';
|
|
17
|
+
|
|
18
|
+
console.log(await ipify());
|
|
19
|
+
//=> '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API
|
|
23
|
+
|
|
24
|
+
### ipify(options?)
|
|
25
|
+
|
|
26
|
+
Returns a `Promise<string>` with an IP address.
|
|
27
|
+
|
|
28
|
+
#### options
|
|
29
|
+
|
|
30
|
+
Type: `object`
|
|
31
|
+
|
|
32
|
+
##### useIPv6
|
|
33
|
+
|
|
34
|
+
Type: `boolean`\
|
|
35
|
+
Default: `true`
|
|
36
|
+
|
|
37
|
+
Use the IPv6 API endpoint. The IPv6 endpoint will return an IPv6 address if available, IPv4 address otherwise.
|
|
38
|
+
|
|
39
|
+
Setting the `endpoint` option will override this.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import ipify from 'ipify';
|
|
43
|
+
|
|
44
|
+
console.log(await ipify({useIPv6: false}));
|
|
45
|
+
//=> '82.142.31.236'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
##### endpoint
|
|
49
|
+
|
|
50
|
+
Type: `string | string[]`\
|
|
51
|
+
Default: `'https://api6.ipify.org'`
|
|
52
|
+
|
|
53
|
+
Custom API endpoint.
|
|
54
|
+
|
|
55
|
+
Can be a single endpoint or an array of endpoints. When multiple endpoints are provided, they will be tried concurrently and the first successful response will be returned.
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import ipify from 'ipify';
|
|
59
|
+
|
|
60
|
+
// Single endpoint
|
|
61
|
+
console.log(await ipify({endpoint: 'https://api.ipify.org'}));
|
|
62
|
+
//=> '82.142.31.236'
|
|
63
|
+
|
|
64
|
+
// Multiple endpoints for resilience
|
|
65
|
+
console.log(await ipify({
|
|
66
|
+
endpoint: [
|
|
67
|
+
'https://api.ipify.org',
|
|
68
|
+
'https://ipify.example.org'
|
|
69
|
+
]
|
|
70
|
+
}));
|
|
71
|
+
//=> '82.142.31.236'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## FAQ
|
|
75
|
+
|
|
76
|
+
### How is this different from [`public-ip`](https://github.com/sindresorhus/public-ip)?
|
|
77
|
+
|
|
78
|
+
This package only targets the Ipify service, while `public-ip` targets multiple services, is faster, and more resilient. Unless you run your own Ipify instance, you probably want `public-ip` instead.
|
|
79
|
+
|
|
80
|
+
## Related
|
|
81
|
+
|
|
82
|
+
- [ipify-cli](https://github.com/sindresorhus/ipify-cli) - CLI for this package
|
|
83
|
+
- [internal-ip](https://github.com/sindresorhus/internal-ip) - Get your internal IPv4 or IPv6 address
|
|
84
|
+
|
|
85
|
+
## cjser
|
|
86
|
+
|
|
87
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
88
|
+
Original repository: https://github.com/sindresorhus/ipify
|