@verifyhash/ip-cidr 0.1.1 → 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +13 -8
  3. package/index.d.ts +111 -0
  4. package/package.json +4 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 <OWNER-NAME PLACEHOLDER>
3
+ Copyright (c) 2026 verifyhash
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -8,10 +8,15 @@ ip↔integer conversion.
8
8
 
9
9
  No network access, no runtime dependencies, no servers. Just math on the bits.
10
10
 
11
- > **Package name is a placeholder.** The manifest name is
12
- > `PLACEHOLDER-ip-cidr`. TODO: the owner picks the final npm name/scope before
13
- > any publish. This library is **not published** — graduation to npm is a
14
- > human-gated step.
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @verifyhash/ip-cidr
15
+ ```
16
+
17
+ Published as [`@verifyhash/ip-cidr`](https://www.npmjs.com/package/@verifyhash/ip-cidr);
18
+ source lives in the [verifyhash/libs](https://github.com/verifyhash/libs) monorepo.
19
+ Zero runtime dependencies — you can also vendor the folder directly.
15
20
 
16
21
  ## Who it's for
17
22
 
@@ -24,11 +29,11 @@ No network access, no runtime dependencies, no servers. Just math on the bits.
24
29
 
25
30
  ## Install & usage
26
31
 
27
- There is nothing to install beyond Node (uses only built-in `assert` for
28
- tests). Once vendored/published under its final name you would:
32
+ Zero runtime dependencies (tests use only built-in `assert`) — you can also
33
+ vendor the folder directly. In your project:
29
34
 
30
35
  ```js
31
- const ip = require('ip-cidr'); // during development: require('./index.js')
36
+ const ip = require('@verifyhash/ip-cidr'); // during development: require('./index.js')
32
37
 
33
38
  // Containment
34
39
  ip.contains('10.0.0.0/8', '10.1.2.3'); // => true
@@ -140,4 +145,4 @@ validate/parse/contain paths.
140
145
 
141
146
  ## License
142
147
 
143
- MIT — see `LICENSE` (owner name is a placeholder until graduation).
148
+ MIT — see `LICENSE`.
package/index.d.ts ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Type declarations for @verifyhash/ip-cidr — zero-dependency IPv4 (+ basic
3
+ * IPv6) address/CIDR toolkit.
4
+ *
5
+ * IPv4 is fully supported (CIDR math, ip<->integer, containment); IPv6 is
6
+ * limited to validate/parse and containment, using BigInt so no precision is
7
+ * lost. No broadcast/first/last helpers for v6 ("broadcast" is not an IPv6
8
+ * concept).
9
+ */
10
+
11
+ /**
12
+ * Validate a dotted-quad IPv4 string (four octets 0-255, no leading zeros).
13
+ * Returns true/false, never throws.
14
+ */
15
+ export function isValidIPv4(str: string): boolean;
16
+
17
+ /**
18
+ * Convert a valid IPv4 string to its unsigned 32-bit integer value
19
+ * (0 .. 4294967295). Throws on invalid input.
20
+ */
21
+ export function ipv4ToInt(str: string): number;
22
+
23
+ /**
24
+ * Convert an unsigned 32-bit integer to a dotted-quad IPv4 string. Throws on
25
+ * out-of-range / non-integer input.
26
+ */
27
+ export function intToIpv4(int: number): string;
28
+
29
+ /**
30
+ * Validate an IPv6 string (supports "::" compression and an embedded IPv4
31
+ * tail; zone ids like "%eth0" are rejected). Returns true/false, never throws.
32
+ */
33
+ export function isValidIPv6(str: string): boolean;
34
+
35
+ /** Convert an IPv6 string to a BigInt (0 .. 2**128-1). Throws on invalid input. */
36
+ export function ipv6ToBigInt(str: string): bigint;
37
+
38
+ /**
39
+ * Convert a BigInt (0 .. 2**128-1) to a fully-expanded (uncompressed) IPv6
40
+ * string. Throws on out-of-range input.
41
+ */
42
+ export function bigIntToIpv6(value: bigint): string;
43
+
44
+ /** 4 for a valid IPv4 address, 6 for a valid IPv6 address, else null. Never throws. */
45
+ export function ipVersion(str: string): 4 | 6 | null;
46
+
47
+ /** Descriptor returned by parse() for an IPv4 address. */
48
+ export interface ParsedIPv4 {
49
+ version: 4;
50
+ address: string;
51
+ /** Unsigned 32-bit integer value of the address. */
52
+ int: number;
53
+ }
54
+
55
+ /** Descriptor returned by parse() for an IPv6 address. */
56
+ export interface ParsedIPv6 {
57
+ version: 6;
58
+ address: string;
59
+ /** BigInt value of the address. */
60
+ big: bigint;
61
+ }
62
+
63
+ /** Parse any IPv4 or IPv6 address into a descriptor object, or throw. */
64
+ export function parse(str: string): ParsedIPv4 | ParsedIPv6;
65
+
66
+ /** Descriptor returned by parseCidr() for an IPv4 block. */
67
+ export interface Cidr4 {
68
+ version: 4;
69
+ /** Normalised CIDR, e.g. '10.0.0.0/24'. */
70
+ cidr: string;
71
+ prefix: number;
72
+ network: string;
73
+ networkInt: number;
74
+ broadcast: string;
75
+ broadcastInt: number;
76
+ firstHost: string;
77
+ firstHostInt: number;
78
+ lastHost: string;
79
+ lastHostInt: number;
80
+ /** Total addresses in the block. */
81
+ size: number;
82
+ /** Usable host count (/31 and /32 count every address, per RFC 3021). */
83
+ hostCount: number;
84
+ }
85
+
86
+ /** Descriptor returned by parseCidr() for an IPv6 block (no broadcast in v6). */
87
+ export interface Cidr6 {
88
+ version: 6;
89
+ /** Normalised CIDR with a fully-expanded network address. */
90
+ cidr: string;
91
+ prefix: number;
92
+ network: string;
93
+ networkBig: bigint;
94
+ firstHost: string;
95
+ firstHostBig: bigint;
96
+ lastHost: string;
97
+ lastHostBig: bigint;
98
+ /** Total addresses in the block (BigInt). */
99
+ size: bigint;
100
+ /** Same as size — IPv6 has no broadcast reservation. */
101
+ hostCount: bigint;
102
+ }
103
+
104
+ /** Parse a CIDR string ("10.0.0.0/24" or "2001:db8::/32"), or throw. */
105
+ export function parseCidr(str: string): Cidr4 | Cidr6;
106
+
107
+ /**
108
+ * Does the CIDR block contain the given IP? Cross-family never matches
109
+ * (returns false). Throws only if either argument is not parseable.
110
+ */
111
+ export function contains(cidr: string, ip: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verifyhash/ip-cidr",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Zero-dependency IPv4 (and basic IPv6) address/CIDR toolkit for Node.js: validate/parse, CIDR math (network, broadcast, first/last host, host count), ip<->integer, and containment.",
5
5
  "keywords": [
6
6
  "ip",
@@ -15,6 +15,7 @@
15
15
  "ip-to-int"
16
16
  ],
17
17
  "main": "index.js",
18
+ "types": "index.d.ts",
18
19
  "scripts": {
19
20
  "test": "node test/index.test.js"
20
21
  },
@@ -22,7 +23,8 @@
22
23
  "files": [
23
24
  "index.js",
24
25
  "README.md",
25
- "LICENSE"
26
+ "LICENSE",
27
+ "index.d.ts"
26
28
  ],
27
29
  "publishConfig": {
28
30
  "access": "public"