ip-utilities 1.0.0

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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -0
  3. package/dist/cidr.d.ts +2 -0
  4. package/dist/cidr.d.ts.map +1 -0
  5. package/dist/cidr.js +1 -0
  6. package/dist/index.d.ts +54 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +89 -0
  9. package/dist/internal/cidr.d.ts +112 -0
  10. package/dist/internal/cidr.d.ts.map +1 -0
  11. package/dist/internal/cidr.js +297 -0
  12. package/dist/internal/ipv4-ranges.d.ts +26 -0
  13. package/dist/internal/ipv4-ranges.d.ts.map +1 -0
  14. package/dist/internal/ipv4-ranges.js +73 -0
  15. package/dist/internal/ipv4.d.ts +44 -0
  16. package/dist/internal/ipv4.d.ts.map +1 -0
  17. package/dist/internal/ipv4.js +183 -0
  18. package/dist/internal/ipv6-ranges.d.ts +47 -0
  19. package/dist/internal/ipv6-ranges.d.ts.map +1 -0
  20. package/dist/internal/ipv6-ranges.js +159 -0
  21. package/dist/internal/ipv6.d.ts +67 -0
  22. package/dist/internal/ipv6.d.ts.map +1 -0
  23. package/dist/internal/ipv6.js +385 -0
  24. package/dist/internal/regex.d.ts +37 -0
  25. package/dist/internal/regex.d.ts.map +1 -0
  26. package/dist/internal/regex.js +118 -0
  27. package/dist/internal/sort.d.ts +22 -0
  28. package/dist/internal/sort.d.ts.map +1 -0
  29. package/dist/internal/sort.js +207 -0
  30. package/dist/ipv4.d.ts +2 -0
  31. package/dist/ipv4.d.ts.map +1 -0
  32. package/dist/ipv4.js +1 -0
  33. package/dist/ipv6.d.ts +2 -0
  34. package/dist/ipv6.d.ts.map +1 -0
  35. package/dist/ipv6.js +1 -0
  36. package/dist/ranges.d.ts +3 -0
  37. package/dist/ranges.d.ts.map +1 -0
  38. package/dist/ranges.js +2 -0
  39. package/dist/regex.d.ts +3 -0
  40. package/dist/regex.d.ts.map +1 -0
  41. package/dist/regex.js +1 -0
  42. package/dist/sort.d.ts +2 -0
  43. package/dist/sort.d.ts.map +1 -0
  44. package/dist/sort.js +1 -0
  45. package/dist/types.d.ts +26 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js +1 -0
  48. package/package.json +78 -0
@@ -0,0 +1,118 @@
1
+ const v4 = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)" +
2
+ "(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}";
3
+ const v6seg = "[a-fA-F\\d]{1,4}";
4
+ const v6core = [
5
+ `(?:${v6seg}:){7}(?:${v6seg}|:)`,
6
+ `(?:${v6seg}:){6}(?:${v4}|:${v6seg}|:)`,
7
+ `(?:${v6seg}:){5}(?::${v4}|(?::${v6seg}){1,2}|:)`,
8
+ `(?:${v6seg}:){4}(?:(?::${v6seg}){0,1}:${v4}|(?::${v6seg}){1,3}|:)`,
9
+ `(?:${v6seg}:){3}(?:(?::${v6seg}){0,2}:${v4}|(?::${v6seg}){1,4}|:)`,
10
+ `(?:${v6seg}:){2}(?:(?::${v6seg}){0,3}:${v4}|(?::${v6seg}){1,5}|:)`,
11
+ `(?:${v6seg}:){1}(?:(?::${v6seg}){0,4}:${v4}|(?::${v6seg}){1,6}|:)`,
12
+ `(?::(?:(?::${v6seg}){0,5}:${v4}|(?::${v6seg}){1,7}|:))`,
13
+ ].join("|");
14
+ const v6 = `(?:${v6core})(?:%[0-9a-zA-Z]+)?`;
15
+ const v4ExactRe = new RegExp(`^${v4}$`);
16
+ const v6ExactRe = new RegExp(`^${v6}$`);
17
+ const v46ExactRe = new RegExp(`^(?:${v4})$|^(?:${v6})$`);
18
+ const WB_START = "(?<=\\s|^)";
19
+ const WB_END = "(?=\\s|$)";
20
+ const v46ScanRe = new RegExp(`(?:${v4})|(?:${v6})`, "g");
21
+ const v46ScanBRe = new RegExp(`(?:${WB_START}${v4}${WB_END})|(?:${WB_START}${v6}${WB_END})`, "g");
22
+ const v4ScanRe = new RegExp(v4, "g");
23
+ const v4ScanBRe = new RegExp(`${WB_START}${v4}${WB_END}`, "g");
24
+ const v6ScanRe = new RegExp(v6, "g");
25
+ const v6ScanBRe = new RegExp(`${WB_START}${v6}${WB_END}`, "g");
26
+ const candidateRe = /[0-9a-fA-F:][0-9a-fA-F.:_%]{1,48}/g;
27
+ const MAX_V4_LEN = 15;
28
+ const MAX_V6_LEN = 50;
29
+ // Whitespace character bitmap for word-boundary detection
30
+ const WS = new Uint8Array(256);
31
+ WS[9] = 1;
32
+ WS[10] = 1;
33
+ WS[12] = 1;
34
+ WS[13] = 1;
35
+ WS[32] = 1;
36
+ /**
37
+ * Tests whether a string is a valid IPv4 address using regex.
38
+ * @param s - The string to test
39
+ * @returns True if the string matches IPv4 format
40
+ */
41
+ export function testV4(s) {
42
+ return s.length <= MAX_V4_LEN && v4ExactRe.test(s);
43
+ }
44
+ /**
45
+ * Tests whether a string is a valid IPv6 address using regex.
46
+ * @param s - The string to test
47
+ * @returns True if the string matches IPv6 format
48
+ */
49
+ export function testV6(s) {
50
+ return s.length <= MAX_V6_LEN && v6ExactRe.test(s);
51
+ }
52
+ /**
53
+ * Tests whether a string is a valid IPv4 or IPv6 address using regex.
54
+ * @param s - The string to test
55
+ * @returns True if the string matches either format
56
+ */
57
+ export function testV46(s) {
58
+ return s.length <= MAX_V6_LEN && v46ExactRe.test(s);
59
+ }
60
+ function createScanner(testFn) {
61
+ return (input, options) => {
62
+ const useBoundaries = options?.includeBoundaries ?? false;
63
+ const results = [];
64
+ const inputLen = input.length;
65
+ candidateRe.lastIndex = 0;
66
+ let m;
67
+ while ((m = candidateRe.exec(input)) !== null) {
68
+ const raw = m[0];
69
+ const idx = m.index;
70
+ if (useBoundaries) {
71
+ if (idx > 0 && !WS[input.charCodeAt(idx - 1)])
72
+ continue;
73
+ const afterIdx = idx + raw.length;
74
+ if (afterIdx < inputLen && !WS[input.charCodeAt(afterIdx)])
75
+ continue;
76
+ }
77
+ if (testFn(raw)) {
78
+ results.push({ value: raw, index: idx });
79
+ }
80
+ else {
81
+ const maxTry = Math.min(raw.length - 1, MAX_V6_LEN);
82
+ for (let len = maxTry; len >= 2; len--) {
83
+ const sub = raw.slice(0, len);
84
+ if (testFn(sub)) {
85
+ results.push({ value: sub, index: idx });
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ }
91
+ return results;
92
+ };
93
+ }
94
+ const ipRegex = ((options) => {
95
+ if (options?.exact)
96
+ return v46ExactRe;
97
+ const re = options?.includeBoundaries ? v46ScanBRe : v46ScanRe;
98
+ re.lastIndex = 0;
99
+ return re;
100
+ });
101
+ ipRegex.v4 = (options) => {
102
+ if (options?.exact)
103
+ return v4ExactRe;
104
+ const re = options?.includeBoundaries ? v4ScanBRe : v4ScanRe;
105
+ re.lastIndex = 0;
106
+ return re;
107
+ };
108
+ ipRegex.v6 = (options) => {
109
+ if (options?.exact)
110
+ return v6ExactRe;
111
+ const re = options?.includeBoundaries ? v6ScanBRe : v6ScanRe;
112
+ re.lastIndex = 0;
113
+ return re;
114
+ };
115
+ ipRegex.scanAll = createScanner(testV46);
116
+ ipRegex.scanAllV4 = createScanner(testV4);
117
+ ipRegex.scanAllV6 = createScanner(testV6);
118
+ export default ipRegex;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Compares two IP address or CIDR strings for sort ordering.
3
+ * IPv4 sorts before IPv6. Invalid strings sort last, ordered lexicographically.
4
+ * Results are cached across calls.
5
+ * @param a - First IP/CIDR string
6
+ * @param b - Second IP/CIDR string
7
+ * @returns Negative if a < b, positive if a > b, zero if equal
8
+ */
9
+ export declare function compareIPs(a: string, b: string): number;
10
+ /**
11
+ * Sorts an array of IP address and CIDR strings in network order.
12
+ * IPv4 addresses sort before IPv6. Invalid strings sort last.
13
+ * CIDR entries with the same network sort by prefix length.
14
+ * @param ips - Array of IP/CIDR strings
15
+ * @returns A new sorted array
16
+ */
17
+ export declare function sortIPs(ips: string[]): string[];
18
+ /**
19
+ * Clears the internal sort comparison cache.
20
+ */
21
+ export declare function clearSortCache(): void;
22
+ //# sourceMappingURL=sort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/internal/sort.ts"],"names":[],"mappings":"AA4HA;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAwD/C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAIrC"}
@@ -0,0 +1,207 @@
1
+ import { parseIPv4Raw } from "./ipv4.js";
2
+ import { parseIPv6Raw, ipv6RawBuf } from "./ipv6.js";
3
+ import { parsePrefixInline } from "./cidr.js";
4
+ // Layout per entry: [kind, v4_ip, w0, w1, w2, w3, prefix]
5
+ const STRIDE = 7;
6
+ const K_KIND = 0;
7
+ const K_V4 = 1;
8
+ const K_W0 = 2;
9
+ const K_W1 = 3;
10
+ const K_W2 = 4;
11
+ const K_W3 = 5;
12
+ const K_PREFIX = 6;
13
+ const NO_PREFIX = -1;
14
+ // Two-generation LRU cache for parsed sort keys
15
+ const HALF_CACHE = 5000;
16
+ let young = new Map();
17
+ let old = new Map();
18
+ // Pooled buffers for sortIPs — reused across calls, shrink if 4x oversized
19
+ const SORT_POOL_MIN = 64 * STRIDE;
20
+ let _sortStore = new Float64Array(SORT_POOL_MIN);
21
+ let _sortIndices = [];
22
+ let cacheStore = new Float64Array(HALF_CACHE * 2 * STRIDE);
23
+ let cacheIdx = 0;
24
+ function cacheGet(s) {
25
+ let v = young.get(s);
26
+ if (v !== undefined)
27
+ return v;
28
+ v = old.get(s);
29
+ if (v !== undefined) {
30
+ young.set(s, v);
31
+ return v;
32
+ }
33
+ return -1;
34
+ }
35
+ function cachePut(s, offset) {
36
+ if (young.size >= HALF_CACHE) {
37
+ old = young;
38
+ young = new Map();
39
+ }
40
+ young.set(s, offset);
41
+ }
42
+ function ensureCacheStore(needed) {
43
+ if (needed <= cacheStore.length)
44
+ return;
45
+ const next = new Float64Array(needed * 2);
46
+ next.set(cacheStore);
47
+ cacheStore = next;
48
+ }
49
+ function _parseInto(store, offset, s, ipEnd, prefix) {
50
+ const ip = parseIPv4Raw(s, 0, ipEnd);
51
+ if (ip !== -1) {
52
+ store[offset + K_KIND] = 4;
53
+ store[offset + K_V4] = ip;
54
+ store[offset + K_PREFIX] = prefix;
55
+ return;
56
+ }
57
+ if (parseIPv6Raw(s, ipEnd)) {
58
+ store[offset + K_KIND] = 6;
59
+ store[offset + K_W0] = ipv6RawBuf[0];
60
+ store[offset + K_W1] = ipv6RawBuf[1];
61
+ store[offset + K_W2] = ipv6RawBuf[2];
62
+ store[offset + K_W3] = ipv6RawBuf[3];
63
+ store[offset + K_PREFIX] = prefix;
64
+ return;
65
+ }
66
+ store[offset + K_KIND] = 0;
67
+ store[offset + K_PREFIX] = prefix;
68
+ }
69
+ function parseForSortCached(s) {
70
+ const cached = cacheGet(s);
71
+ if (cached !== -1)
72
+ return cached;
73
+ const offset = cacheIdx;
74
+ ensureCacheStore(offset + STRIDE);
75
+ cacheIdx += STRIDE;
76
+ cacheStore[offset + K_PREFIX] = NO_PREFIX;
77
+ const slashIdx = s.indexOf('/');
78
+ if (slashIdx === -1) {
79
+ _parseInto(cacheStore, offset, s, s.length, NO_PREFIX);
80
+ }
81
+ else {
82
+ const prefix = parsePrefixInline(s, slashIdx + 1, s.length, 128);
83
+ if (prefix !== -1) {
84
+ _parseInto(cacheStore, offset, s, slashIdx, prefix);
85
+ }
86
+ }
87
+ cachePut(s, offset);
88
+ return offset;
89
+ }
90
+ function _compare(store, oa, ob, sa, sb) {
91
+ const ka = store[oa + K_KIND];
92
+ const kb = store[ob + K_KIND];
93
+ if (ka === 0 && kb === 0)
94
+ return sa < sb ? -1 : sa > sb ? 1 : 0;
95
+ if (ka === 0)
96
+ return 1;
97
+ if (kb === 0)
98
+ return -1;
99
+ if (ka !== kb)
100
+ return ka === 4 ? -1 : 1;
101
+ let cmp;
102
+ if (ka === 4) {
103
+ cmp = store[oa + K_V4] - store[ob + K_V4];
104
+ }
105
+ else {
106
+ cmp = store[oa + K_W0] - store[ob + K_W0];
107
+ if (cmp === 0)
108
+ cmp = store[oa + K_W1] - store[ob + K_W1];
109
+ if (cmp === 0)
110
+ cmp = store[oa + K_W2] - store[ob + K_W2];
111
+ if (cmp === 0)
112
+ cmp = store[oa + K_W3] - store[ob + K_W3];
113
+ }
114
+ if (cmp !== 0)
115
+ return cmp;
116
+ const defaultPfx = ka === 4 ? 32 : 128;
117
+ const pa = store[oa + K_PREFIX];
118
+ const pb = store[ob + K_PREFIX];
119
+ return (pa === NO_PREFIX ? defaultPfx : pa) - (pb === NO_PREFIX ? defaultPfx : pb);
120
+ }
121
+ /**
122
+ * Compares two IP address or CIDR strings for sort ordering.
123
+ * IPv4 sorts before IPv6. Invalid strings sort last, ordered lexicographically.
124
+ * Results are cached across calls.
125
+ * @param a - First IP/CIDR string
126
+ * @param b - Second IP/CIDR string
127
+ * @returns Negative if a < b, positive if a > b, zero if equal
128
+ */
129
+ export function compareIPs(a, b) {
130
+ const oa = parseForSortCached(a);
131
+ const ob = parseForSortCached(b);
132
+ return _compare(cacheStore, oa, ob, a, b);
133
+ }
134
+ /**
135
+ * Sorts an array of IP address and CIDR strings in network order.
136
+ * IPv4 addresses sort before IPv6. Invalid strings sort last.
137
+ * CIDR entries with the same network sort by prefix length.
138
+ * @param ips - Array of IP/CIDR strings
139
+ * @returns A new sorted array
140
+ */
141
+ export function sortIPs(ips) {
142
+ const n = ips.length;
143
+ if (n <= 1)
144
+ return n === 0 ? [] : [ips[0]];
145
+ const needed = n * STRIDE;
146
+ if (_sortStore.length < needed) {
147
+ _sortStore = new Float64Array(needed);
148
+ }
149
+ else if (_sortStore.length > SORT_POOL_MIN && _sortStore.length > needed * 4) {
150
+ _sortStore = new Float64Array(needed);
151
+ }
152
+ const store = _sortStore;
153
+ for (let i = 0; i < n; i++) {
154
+ const off = i * STRIDE;
155
+ store[off + K_PREFIX] = NO_PREFIX;
156
+ const s = ips[i];
157
+ const slashIdx = s.indexOf('/');
158
+ if (slashIdx === -1) {
159
+ _parseInto(store, off, s, s.length, NO_PREFIX);
160
+ }
161
+ else {
162
+ const prefix = parsePrefixInline(s, slashIdx + 1, s.length, 128);
163
+ if (prefix !== -1) {
164
+ _parseInto(store, off, s, slashIdx, prefix);
165
+ }
166
+ }
167
+ }
168
+ if (_sortIndices.length < n) {
169
+ _sortIndices = new Array(n);
170
+ }
171
+ else if (_sortIndices.length > 64 && _sortIndices.length > n * 4) {
172
+ _sortIndices = new Array(n);
173
+ }
174
+ const indices = _sortIndices;
175
+ for (let i = 0; i < n; i++)
176
+ indices[i] = i;
177
+ if (n <= 16) {
178
+ for (let i = 1; i < n; i++) {
179
+ const key = indices[i];
180
+ const keyOff = key * STRIDE;
181
+ let j = i - 1;
182
+ while (j >= 0) {
183
+ const jIdx = indices[j];
184
+ if (_compare(store, jIdx * STRIDE, keyOff, ips[jIdx], ips[key]) <= 0)
185
+ break;
186
+ indices[j + 1] = jIdx;
187
+ j--;
188
+ }
189
+ indices[j + 1] = key;
190
+ }
191
+ }
192
+ else {
193
+ indices.sort((ai, bi) => _compare(store, ai * STRIDE, bi * STRIDE, ips[ai], ips[bi]));
194
+ }
195
+ const result = new Array(n);
196
+ for (let i = 0; i < n; i++)
197
+ result[i] = ips[indices[i]];
198
+ return result;
199
+ }
200
+ /**
201
+ * Clears the internal sort comparison cache.
202
+ */
203
+ export function clearSortCache() {
204
+ young = new Map();
205
+ old = new Map();
206
+ cacheIdx = 0;
207
+ }
package/dist/ipv4.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { parseIPv4, isIPv4, parseIPv4Loose, ipv4ToOctets, ipv4ToString } from './internal/ipv4.ts';
2
+ //# sourceMappingURL=ipv4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipv4.d.ts","sourceRoot":"","sources":["../src/ipv4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA"}
package/dist/ipv4.js ADDED
@@ -0,0 +1 @@
1
+ export { parseIPv4, isIPv4, parseIPv4Loose, ipv4ToOctets, ipv4ToString } from "./internal/ipv4.js";
package/dist/ipv6.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { parseIPv6, isIPv6, isIPv4Mapped, ipv6ToWords, ipv6ToString, ipv6ToNormalizedString, ipv6ToFixedString, ipv6ToIPv4, ipv6GetZoneId } from './internal/ipv6.ts';
2
+ //# sourceMappingURL=ipv6.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipv6.d.ts","sourceRoot":"","sources":["../src/ipv6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA"}
package/dist/ipv6.js ADDED
@@ -0,0 +1 @@
1
+ export { parseIPv6, isIPv6, isIPv4Mapped, ipv6ToWords, ipv6ToString, ipv6ToNormalizedString, ipv6ToFixedString, ipv6ToIPv4, ipv6GetZoneId } from "./internal/ipv6.js";
@@ -0,0 +1,3 @@
1
+ export { ipv4Range, isPrivateIPv4, isLoopbackIPv4, isLinkLocalIPv4 } from './internal/ipv4-ranges.ts';
2
+ export { ipv6Range, isPrivateIPv6, isLoopbackIPv6, isLinkLocalIPv6 } from './internal/ipv6-ranges.ts';
3
+ //# sourceMappingURL=ranges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ranges.d.ts","sourceRoot":"","sources":["../src/ranges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AACrG,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA"}
package/dist/ranges.js ADDED
@@ -0,0 +1,2 @@
1
+ export { ipv4Range, isPrivateIPv4, isLoopbackIPv4, isLinkLocalIPv4 } from "./internal/ipv4-ranges.js";
2
+ export { ipv6Range, isPrivateIPv6, isLoopbackIPv6, isLinkLocalIPv6 } from "./internal/ipv6-ranges.js";
@@ -0,0 +1,3 @@
1
+ export { default, testV4, testV6, testV46 } from './internal/regex.ts';
2
+ export type { Options, ScanResult, IpRegex } from './internal/regex.ts';
3
+ //# sourceMappingURL=regex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../src/regex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACtE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA"}
package/dist/regex.js ADDED
@@ -0,0 +1 @@
1
+ export { default, testV4, testV6, testV46 } from "./internal/regex.js";
package/dist/sort.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { compareIPs, sortIPs, clearSortCache } from './internal/sort.ts';
2
+ //# sourceMappingURL=sort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA"}
package/dist/sort.js ADDED
@@ -0,0 +1 @@
1
+ export { compareIPs, sortIPs, clearSortCache } from "./internal/sort.js";
@@ -0,0 +1,26 @@
1
+ export interface IPv4Addr {
2
+ readonly ip: number;
3
+ readonly kind: 4;
4
+ }
5
+ export interface IPv6Addr {
6
+ readonly w0: number;
7
+ readonly w1: number;
8
+ readonly w2: number;
9
+ readonly w3: number;
10
+ readonly kind: 6;
11
+ }
12
+ export type IPAddr = IPv4Addr | IPv6Addr;
13
+ export interface CIDRv4 {
14
+ readonly addr: IPv4Addr;
15
+ readonly prefix: number;
16
+ readonly kind: 4;
17
+ }
18
+ export interface CIDRv6 {
19
+ readonly addr: IPv6Addr;
20
+ readonly prefix: number;
21
+ readonly kind: 6;
22
+ }
23
+ export type CIDR = CIDRv4 | CIDRv6;
24
+ export type IPv4RangeName = 'unspecified' | 'broadcast' | 'multicast' | 'linkLocal' | 'loopback' | 'carrierGradeNat' | 'private' | 'reserved' | 'as112' | 'amt' | 'benchmarking' | 'unicast';
25
+ export type IPv6RangeName = 'unspecified' | 'linkLocal' | 'multicast' | 'loopback' | 'uniqueLocal' | 'ipv4Mapped' | 'discard' | 'rfc6145' | 'rfc6052' | '6to4' | 'teredo' | 'benchmarking' | 'amt' | 'as112v6' | 'deprecated' | 'orchid2' | 'droneRemoteIdProtocolEntityTags' | 'reserved' | 'unicast';
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CACjB;AAED,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAExC,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CACjB;AAED,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CACjB;AAED,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;AAElC,MAAM,MAAM,aAAa,GACrB,aAAa,GACb,WAAW,GACX,WAAW,GACX,WAAW,GACX,UAAU,GACV,iBAAiB,GACjB,SAAS,GACT,UAAU,GACV,OAAO,GACP,KAAK,GACL,cAAc,GACd,SAAS,CAAA;AAEb,MAAM,MAAM,aAAa,GACrB,aAAa,GACb,WAAW,GACX,WAAW,GACX,UAAU,GACV,aAAa,GACb,YAAY,GACZ,SAAS,GACT,SAAS,GACT,SAAS,GACT,MAAM,GACN,QAAQ,GACR,cAAc,GACd,KAAK,GACL,SAAS,GACT,YAAY,GACZ,SAAS,GACT,iCAAiC,GACjC,UAAU,GACV,SAAS,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "ip-utilities",
3
+ "version": "1.0.0",
4
+ "description": "IP address parsing, validation, and CIDR operations for TypeScript",
5
+ "license": "MIT",
6
+ "author": "DrSkillIssue",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/DrSkillIssue/ip-utilities.git"
10
+ },
11
+ "homepage": "https://github.com/DrSkillIssue/ip-utilities",
12
+ "bugs": "https://github.com/DrSkillIssue/ip-utilities/issues",
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./ipv4": {
20
+ "types": "./dist/ipv4.d.ts",
21
+ "import": "./dist/ipv4.js"
22
+ },
23
+ "./ipv6": {
24
+ "types": "./dist/ipv6.d.ts",
25
+ "import": "./dist/ipv6.js"
26
+ },
27
+ "./cidr": {
28
+ "types": "./dist/cidr.d.ts",
29
+ "import": "./dist/cidr.js"
30
+ },
31
+ "./sort": {
32
+ "types": "./dist/sort.d.ts",
33
+ "import": "./dist/sort.js"
34
+ },
35
+ "./regex": {
36
+ "types": "./dist/regex.d.ts",
37
+ "import": "./dist/regex.js"
38
+ },
39
+ "./ranges": {
40
+ "types": "./dist/ranges.d.ts",
41
+ "import": "./dist/ranges.js"
42
+ }
43
+ },
44
+ "files": [
45
+ "dist"
46
+ ],
47
+ "engines": {
48
+ "node": ">=24.0.0"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc -p tsconfig.build.json",
52
+ "typecheck": "tsc --noEmit",
53
+ "test": "bun test",
54
+ "bench": "bun run test/bench/ip.bench.ts"
55
+ },
56
+ "keywords": [
57
+ "ip",
58
+ "ipv4",
59
+ "ipv6",
60
+ "cidr",
61
+ "subnet",
62
+ "network",
63
+ "address",
64
+ "validate",
65
+ "parse",
66
+ "regex",
67
+ "private",
68
+ "range",
69
+ "sort"
70
+ ],
71
+ "sideEffects": false,
72
+ "devDependencies": {
73
+ "@types/bun": "^1.3.11",
74
+ "ipaddr.js": "^2.3.0",
75
+ "mitata": "^1.0.34",
76
+ "typescript": "^6.0.2"
77
+ }
78
+ }