icanhazip-client 0.0.9

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sricharan Krishnan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ ![banner](https://github.com/user-attachments/assets/c68adc2f-21df-42de-87b7-61439e5d56db)
2
+ # Icanhazip Client
3
+ A lightweight JavaScript/TypeScript client for retrieving public IP information using the icanhazip service. This package is **ESM-only** and works in modern browsers and Node.js 18+ environments that support the Fetch API. Provides support for [https://github.com/runvnc/icanhazip](https://github.com/runvnc/icanhazip)
4
+
5
+
6
+ ### Installation:
7
+ ```console
8
+ npm install icanhazip-client
9
+ ```
10
+ Note: If you are using Node.js, ensure your project supports ES modules.
11
+
12
+
13
+ ### Basic Usage:
14
+ Responses are returned as objects instead of plain text to provide a consistent, extensible API that works well with TypeScript.
15
+
16
+ 1. Fetch your IPv4 address
17
+ ```javascript
18
+ import { getIPV4 } from "icanhazip-client";
19
+ const result = await getIPV4();
20
+ console.log(result);
21
+ // { ipv4: "8.8.8.8" }
22
+ ```
23
+
24
+ 2. Fetch your IPv6 address
25
+ ```javascript
26
+ import { getIPV6 } from "icanhazip-client";
27
+ const result = await getIPV6();
28
+ console.log(result);
29
+ // { ipv6: "2001:4860:4860::8888" }
30
+ ```
31
+
32
+ 3. Fetch connection trace information
33
+ ```javascript
34
+ import { getIPTrace } from "icanhazip-client";
35
+ const trace = await getIPTrace();
36
+ console.log(trace);
37
+ /*
38
+ {
39
+ ip: "8.8.8.8",
40
+ loc: "IN",
41
+ tls: "TLSv1.3",
42
+ http: "h2",
43
+ ...
44
+ }
45
+ */
46
+ ```
47
+
48
+ 4. Error Handling Example
49
+ ```javascript
50
+ try {
51
+ const ip = await getIPV4();
52
+ console.log(ip);
53
+ } catch (error) {
54
+ console.error("Failed to fetch IP information", error);
55
+ }
56
+ ```
57
+
58
+ ### Support
59
+ Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.
@@ -0,0 +1,4 @@
1
+ import type { IPTraceRes } from "../types/index.ts";
2
+ declare function getFullTrace(): Promise<IPTraceRes>;
3
+ export { getFullTrace };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/get-full-trace/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,iBAAe,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC,CA+BjD;AAGD,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,36 @@
1
+ /* module */
2
+ async function getFullTrace() {
3
+ /* no fetch */
4
+ if (typeof fetch !== "function") {
5
+ throw new Error("[Bad]: Global Fetch Not Available");
6
+ }
7
+ else {
8
+ /* fetch */
9
+ const URL = "https://icanhazip.com/cdn-cgi/trace";
10
+ const response = await fetch(URL);
11
+ if (!response.ok) {
12
+ throw new Error("[Bad]: getIPV4 Fetch Error");
13
+ }
14
+ else {
15
+ /* get */
16
+ const prelim = (await response.text()).trim();
17
+ const lines = prelim.split("\n");
18
+ /* iterate and set */
19
+ const ipData = {};
20
+ for (const line of lines) {
21
+ const [key, value] = line.split("=");
22
+ if (!key || value === undefined) {
23
+ continue;
24
+ }
25
+ else {
26
+ ipData[key.trim()] = value.trim();
27
+ }
28
+ }
29
+ /* end */
30
+ return ipData;
31
+ }
32
+ }
33
+ }
34
+ /* exports */
35
+ export { getFullTrace };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/get-full-trace/index.ts"],"names":[],"mappings":"AAGA,YAAY;AACZ,KAAK,UAAU,YAAY;IACzB,cAAc;IACd,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,WAAW;QACX,MAAM,GAAG,GAAG,qCAAqC,CAAC;QAClD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,SAAS;YACT,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAEjC,qBAAqB;YACrB,MAAM,MAAM,GAAe,EAAE,CAAC;YAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrC,IAAI,CAAC,GAAG,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBAChC,SAAS;gBACX,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;gBACpC,CAAC;YACH,CAAC;YAED,SAAS;YACT,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;AACH,CAAC;AAED,aAAa;AACb,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { IPV4Res } from "../types/index.ts";
2
+ declare function getIPV4(): Promise<IPV4Res>;
3
+ export { getIPV4 };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/get-ipv4/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD,iBAAe,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAezC;AAGD,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ /* module */
2
+ async function getIPV4() {
3
+ /* no fetch */
4
+ if (typeof fetch !== "function") {
5
+ throw new Error("[Bad]: Global Fetch Not Available");
6
+ }
7
+ else {
8
+ const URL = "https://ipv4.icanhazip.com/";
9
+ const response = await fetch(URL);
10
+ if (!response.ok) {
11
+ throw new Error("[Bad]: getIPV4 Fetch Error");
12
+ }
13
+ else {
14
+ const ipv4 = (await response.text()).trim();
15
+ return { ipv4 };
16
+ }
17
+ }
18
+ }
19
+ /* exports */
20
+ export { getIPV4 };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/get-ipv4/index.ts"],"names":[],"mappings":"AAGA,YAAY;AACZ,KAAK,UAAU,OAAO;IACpB,cAAc;IACd,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,GAAG,6BAA6B,CAAC;QAC1C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC5C,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;IACH,CAAC;AACH,CAAC;AAED,aAAa;AACb,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { IPV6Res } from "../types/index.ts";
2
+ declare function getIPV6(): Promise<IPV6Res>;
3
+ export { getIPV6 };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/get-ipv6/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD,iBAAe,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAezC;AAGD,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ /* module */
2
+ async function getIPV6() {
3
+ /* no fetch */
4
+ if (typeof fetch !== "function") {
5
+ throw new Error("[Bad]: Global Fetch Not Available");
6
+ }
7
+ else {
8
+ const URL = "https://ipv6.icanhazip.com/";
9
+ const response = await fetch(URL);
10
+ if (!response.ok) {
11
+ throw new Error("[Bad]: getIPV6 Fetch Error");
12
+ }
13
+ else {
14
+ const ipv6 = (await response.text()).trim();
15
+ return { ipv6 };
16
+ }
17
+ }
18
+ }
19
+ /* exports */
20
+ export { getIPV6 };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/get-ipv6/index.ts"],"names":[],"mappings":"AAGA,YAAY;AACZ,KAAK,UAAU,OAAO;IACpB,cAAc;IACd,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,GAAG,6BAA6B,CAAC;QAC1C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC5C,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;IACH,CAAC;AACH,CAAC;AAED,aAAa;AACb,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./get-ipv4/index.js";
2
+ export * from "./get-ipv6/index.js";
3
+ export * from "./get-full-trace/index.js";
4
+ export * from "./types/index.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /* exports */
2
+ export * from "./get-ipv4/index.js";
3
+ export * from "./get-ipv6/index.js";
4
+ export * from "./get-full-trace/index.js";
5
+ export * from "./types/index.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type IPV4Res = {
2
+ ipv4: string;
3
+ };
4
+ export type IPV6Res = {
5
+ ipv6: string;
6
+ };
7
+ export type IPTraceRes = Record<string, any>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC;AACrC,MAAM,MAAM,OAAO,GAAG;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC;AACrC,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "icanhazip-client",
3
+ "description": "Tiny fetch-based client for icanhazip.com (IPv4, IPv6, trace)",
4
+ "type": "module",
5
+ "version": "0.0.9",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "files": ["dist"],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "keywords": ["ip", "ipv4", "ipv6", "icanhazip", "icanhazip-client"],
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "typescript": "^5.9.3"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/NPM-Workbench/icanhazip-client"
30
+ },
31
+ "license": "MIT",
32
+ "homepage": "https://github.com/NPM-Workbench/icanhazip-client",
33
+ "bugs": {
34
+ "url": "https://github.com/NPM-Workbench/icanhazip-client/issues"
35
+ }
36
+ }