net-address 0.1.2 → 0.2.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.
- package/README.md +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +452 -43
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +452 -43
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/packages/net-address/tsconfig.tsbuildinfo +1 -0
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,30 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CoreResult } from "core-result";
|
|
2
2
|
//#region src/Ipv6Addr.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Represents an IPv6 address.
|
|
5
5
|
* @example
|
|
6
|
-
* const
|
|
6
|
+
* const addrRes1 = Ipv6Addr.from('2001:db8::1');
|
|
7
|
+
* const addr1 = Ipv6Addr.fromOrThrow('2001:db8::1');
|
|
7
8
|
* const addr2 = new Ipv6Addr([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]);
|
|
8
9
|
* const addr3 = new Ipv6Addr(0x20010db8000000000000000000000001n);
|
|
9
10
|
* @since v0.0.1
|
|
10
11
|
*/
|
|
11
|
-
declare class Ipv6Addr {
|
|
12
|
+
export declare class Ipv6Addr {
|
|
12
13
|
#private;
|
|
13
|
-
private static regex;
|
|
14
14
|
/**
|
|
15
15
|
* Creates an IPv6 address from text.
|
|
16
16
|
* @returns A successful result with an IPv6 address, or an error when the input is invalid.
|
|
17
17
|
* @example
|
|
18
|
-
* const
|
|
18
|
+
* const addrRes: CoreResult<Ipv6Addr, TypeError | RangeError> = Ipv6Addr.from('2001:db8::1');
|
|
19
19
|
* @since v0.0.1
|
|
20
20
|
*/
|
|
21
|
-
static from(value: string):
|
|
21
|
+
static from(value: string): CoreResult<Ipv6Addr, TypeError | RangeError>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an IPv6 address from text and throws an error if the input is invalid.
|
|
24
|
+
* @param value The IPv6 address in string format.
|
|
25
|
+
* @returns The IPv6 address instance.
|
|
26
|
+
* @example
|
|
27
|
+
* const addr: Ipv6Addr = Ipv6Addr.fromOrThrow('2001:db8::1');
|
|
28
|
+
* @since v0.2.0
|
|
29
|
+
*/
|
|
30
|
+
static fromOrThrow(value: string): Ipv6Addr;
|
|
22
31
|
/**
|
|
23
32
|
* Creates an IPv6 address from a 16-byte buffer.
|
|
24
33
|
* @returns A successful result with an IPv6 address, or an error when the buffer cannot be read.
|
|
34
|
+
* @example
|
|
35
|
+
* const addrRes: CoreResult<Ipv6Addr> = Ipv6Addr.fromBuffer(buffer);
|
|
25
36
|
* @since v0.0.1
|
|
26
37
|
*/
|
|
27
|
-
static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean):
|
|
38
|
+
static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): CoreResult<Ipv6Addr>;
|
|
39
|
+
/**
|
|
40
|
+
* Creates an IPv6 address from a 16-byte buffer and throws an error if the buffer cannot be read.
|
|
41
|
+
* @param buffer The 16-byte buffer containing the IPv6 address.
|
|
42
|
+
* @param littleEndian Whether the buffer is in little-endian format. Defaults to false (big-endian).
|
|
43
|
+
* @returns The IPv6 address instance.
|
|
44
|
+
* @example
|
|
45
|
+
* const addr: Ipv6Addr = Ipv6Addr.fromBufferOrThrow(buffer);
|
|
46
|
+
* @since v0.2.0
|
|
47
|
+
*/
|
|
48
|
+
static fromBufferOrThrow(buffer: ArrayBuffer, littleEndian?: boolean): Ipv6Addr;
|
|
49
|
+
/**
|
|
50
|
+
* Creates an IPv6 address from a raw bigint value.
|
|
51
|
+
* @param value The raw bigint value representing the IPv6 address.
|
|
52
|
+
* @returns The IPv6 address instance.
|
|
53
|
+
* @example
|
|
54
|
+
* const addr: Ipv6Addr = Ipv6Addr.fromRaw(0x20010db8000000000000000000000001n);
|
|
55
|
+
* @since v0.2.0
|
|
56
|
+
*/
|
|
57
|
+
static fromRaw(value: bigint): Ipv6Addr;
|
|
28
58
|
/**
|
|
29
59
|
* The number of bits in an IPv6 address.
|
|
30
60
|
* @since v0.0.1
|
|
@@ -46,11 +76,12 @@ declare class Ipv6Addr {
|
|
|
46
76
|
*/
|
|
47
77
|
readonly family = "ipv6";
|
|
48
78
|
/**
|
|
49
|
-
* Gets the raw
|
|
79
|
+
* Gets the raw {@link BigInt} representation of the {@link Ipv6Addr} address.
|
|
80
|
+
* @since v0.2.0
|
|
50
81
|
*/
|
|
51
82
|
get value(): bigint;
|
|
52
83
|
/**
|
|
53
|
-
* Creates a new
|
|
84
|
+
* Creates a new {@link Ipv6Addr} address instance.
|
|
54
85
|
* @param value - A bigint representing the IPv6 address or an array of 8 numbers representing the segments of the address.
|
|
55
86
|
* @throws {RangeError} If the segments array does not have exactly 8 elements or if any segment is out of range.
|
|
56
87
|
* @throws {TypeError} If the input is neither a bigint nor an array of 8 numbers.
|
|
@@ -106,6 +137,36 @@ declare class Ipv6Addr {
|
|
|
106
137
|
* @since v0.0.2
|
|
107
138
|
*/
|
|
108
139
|
isMulticastLinkLocal(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Checks whether this address is the all-nodes multicast group address.
|
|
142
|
+
* @returns `true` when the address is multicast and the group ID is 1, otherwise `false`.
|
|
143
|
+
* @since v0.2.0
|
|
144
|
+
*/
|
|
145
|
+
isAllNodesMulticastGroup(): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Checks whether this address is the all-routers multicast group address.
|
|
148
|
+
* @returns `true` when the address is multicast and the group ID is 2, otherwise `false`.
|
|
149
|
+
* @since v0.2.0
|
|
150
|
+
*/
|
|
151
|
+
isAllRoutersMulticastGroup(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Checks whether this address is the mDNS multicast group address.
|
|
154
|
+
* @returns `true` when the address is `ff02::fb`, otherwise `false`.
|
|
155
|
+
* @since v0.2.0
|
|
156
|
+
*/
|
|
157
|
+
isMdnsMulticastGroup(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Checks whether this address is the SSDP multicast group address.
|
|
160
|
+
* @returns `true` when the address is `ff02::c`, otherwise `false`.
|
|
161
|
+
* @since v0.2.0
|
|
162
|
+
*/
|
|
163
|
+
isSsdpMulticastGroup(): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Checks whether this address is the DHCPv6 multicast group address.
|
|
166
|
+
* @returns `true` when the address is `ff02::12`, otherwise `false`.
|
|
167
|
+
* @since v0.2.0
|
|
168
|
+
*/
|
|
169
|
+
isDhcpv6MulticastGroup(): boolean;
|
|
109
170
|
/**
|
|
110
171
|
* Checks whether this address is a multicast realm-local address.
|
|
111
172
|
* @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7
|
|
@@ -184,79 +245,129 @@ declare class Ipv6Addr {
|
|
|
184
245
|
isUniqueLocal(): boolean;
|
|
185
246
|
/**
|
|
186
247
|
* Converts this address to IPv4 when compatible or mapped.
|
|
187
|
-
* @returns
|
|
248
|
+
* @returns A {@link CoreResult} containing either the resulting {@link Ipv4Addr} or a {@link RangeError} if the address is not IPv4 compatible or mapped.
|
|
188
249
|
* @since v0.0.1
|
|
189
250
|
*/
|
|
190
|
-
toIpv4():
|
|
251
|
+
toIpv4(): CoreResult<Ipv4Addr, RangeError>;
|
|
252
|
+
/**
|
|
253
|
+
* Converts this address to IPv4 when compatible or mapped, throwing on failure.
|
|
254
|
+
* @returns An {@link Ipv4Addr} for `::a.b.c.d` or `::ffff:a.b.c.d`.
|
|
255
|
+
* @throws {RangeError} If the address is not IPv4 compatible or mapped.
|
|
256
|
+
* @since v0.2.0
|
|
257
|
+
*/
|
|
258
|
+
toIpv4OrThrow(): Ipv4Addr;
|
|
191
259
|
/**
|
|
192
260
|
* Converts this address to IPv4 only when it is IPv4-mapped.
|
|
193
|
-
* @returns
|
|
261
|
+
* @returns A {@link CoreResult} containing either the resulting {@link Ipv4Addr} or a {@link RangeError} if the address is not IPv4 mapped.
|
|
194
262
|
* @since v0.0.1
|
|
195
263
|
*/
|
|
196
|
-
toIpv4Mapped():
|
|
264
|
+
toIpv4Mapped(): CoreResult<Ipv4Addr, RangeError>;
|
|
265
|
+
/**
|
|
266
|
+
* Converts this address to IPv4 only when it is IPv4-mapped, throwing on failure.
|
|
267
|
+
* @returns An {@link Ipv4Addr} address for `::ffff:a.b.c.d`.
|
|
268
|
+
* @throws {RangeError} If the address is not IPv4 mapped.
|
|
269
|
+
* @since v0.2.0
|
|
270
|
+
*/
|
|
271
|
+
toIpv4MappedOrThrow(): Ipv4Addr;
|
|
197
272
|
/**
|
|
198
273
|
* Formats this address as a compressed IPv6 string.
|
|
199
274
|
* @returns The shortest standard IPv6 text form.
|
|
200
275
|
* @since v0.0.1
|
|
201
276
|
*/
|
|
202
277
|
toString(): string;
|
|
278
|
+
/**
|
|
279
|
+
* Converts this address to its fully expanded IPv6 string representation.
|
|
280
|
+
* @returns The expanded IPv6 string (e.g., `2001:0db8:0000:0000:0000:ff00:0042:8329`).
|
|
281
|
+
* @since v0.2.0
|
|
282
|
+
*/
|
|
283
|
+
toExpandedString(): string;
|
|
203
284
|
/**
|
|
204
285
|
* Encodes this address to a 16-byte buffer.
|
|
205
286
|
* @param littleEndian Whether to use little-endian byte order. Defaults to `false`.
|
|
206
|
-
* @returns An
|
|
287
|
+
* @returns An {@link ArrayBuffer} containing the IPv6 integer value.
|
|
207
288
|
* @since v0.0.1
|
|
208
289
|
*/
|
|
209
290
|
toBuffer(littleEndian?: boolean): ArrayBuffer;
|
|
210
291
|
/**
|
|
211
|
-
* Compares this
|
|
212
|
-
* @param other instance of another
|
|
292
|
+
* Compares this address with another for equality.
|
|
293
|
+
* @param other instance of another {@link Ipv6Addr} or {@link Ipv4Addr} address to compare with.
|
|
213
294
|
* @returns `true` if both addresses are equal, otherwise `false`.
|
|
214
295
|
* @since v0.1.0
|
|
215
296
|
*/
|
|
216
|
-
equals(other
|
|
297
|
+
equals(other?: unknown): boolean;
|
|
217
298
|
}
|
|
218
299
|
//#endregion
|
|
219
300
|
//#region src/Ipv4Addr.d.ts
|
|
220
301
|
/**
|
|
221
302
|
* Represents an IPv4 address.
|
|
222
303
|
* @example
|
|
223
|
-
* const
|
|
304
|
+
* const addr1Res = Ipv4Addr.from('192.168.0.1');
|
|
305
|
+
* const addr1 = Ipv4Addr.fromOrThrow('192.168.0.1');
|
|
224
306
|
* const addr2 = new Ipv4Addr(192, 168, 0, 1);
|
|
225
307
|
* const addr3 = new Ipv4Addr(0xc0a80001);
|
|
226
308
|
* @since v0.0.1
|
|
227
309
|
*/
|
|
228
|
-
declare class Ipv4Addr {
|
|
310
|
+
export declare class Ipv4Addr {
|
|
229
311
|
#private;
|
|
230
312
|
/**
|
|
231
313
|
* Creates an IPv4 address from dotted-decimal text.
|
|
232
|
-
* @returns A successful {@link
|
|
314
|
+
* @returns A successful {@link CoreResult} with an {@link Ipv4Addr}, or an {@link TypeError} when the input is invalid.
|
|
315
|
+
* @example
|
|
316
|
+
* const addr: CoreResult<Ipv4Addr, TypeError> = Ipv4Addr.from('192.168.0.1');
|
|
233
317
|
* @since v0.0.1
|
|
234
318
|
*/
|
|
235
|
-
static from(value: string):
|
|
319
|
+
static from(value: string): CoreResult<Ipv4Addr, TypeError>;
|
|
320
|
+
/**
|
|
321
|
+
* Creates an IPv4 address from text and throws an error if the input is invalid.
|
|
322
|
+
* @param value The IPv4 address in string format.
|
|
323
|
+
* @returns The {@link Ipv4Addr} instance.
|
|
324
|
+
* @throws {TypeError} If the input is not a valid IPv4 address.
|
|
325
|
+
* @example
|
|
326
|
+
* const addr: Ipv4Addr = Ipv4Addr.fromOrThrow('192.168.0.1');
|
|
327
|
+
* @since v0.2.0
|
|
328
|
+
*/
|
|
329
|
+
static fromOrThrow(value: string): Ipv4Addr;
|
|
236
330
|
/**
|
|
237
331
|
* Creates an IPv4 address from a 4-byte buffer.
|
|
238
|
-
* @returns A successful {@link
|
|
332
|
+
* @returns A successful {@link CoreResult} with an {@link Ipv4Addr}, or an {@link Error} when the buffer cannot be read.
|
|
333
|
+
* @example
|
|
334
|
+
* const result: CoreResult<Ipv4Addr, Error> = Ipv4Addr.fromBuffer(buffer);
|
|
239
335
|
* @since v0.0.1
|
|
240
336
|
*/
|
|
241
|
-
static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean):
|
|
337
|
+
static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): CoreResult<Ipv4Addr, Error>;
|
|
338
|
+
/**
|
|
339
|
+
* Creates an IPv4 address from a 4-byte buffer and throws an error if the buffer cannot be read.
|
|
340
|
+
* @param buffer The 4-byte buffer containing the IPv4 address.
|
|
341
|
+
* @param littleEndian Whether the buffer is in little-endian format. Defaults to false (big-endian).
|
|
342
|
+
* @returns The {@link Ipv4Addr} instance.
|
|
343
|
+
* @throws {Error} If the buffer cannot be read.
|
|
344
|
+
* @example
|
|
345
|
+
* const addr: Ipv4Addr = Ipv4Addr.fromBufferOrThrow(buffer);
|
|
346
|
+
* @since v0.2.0
|
|
347
|
+
*/
|
|
348
|
+
static fromBufferOrThrow(buffer: ArrayBuffer, littleEndian?: boolean): Ipv4Addr;
|
|
242
349
|
/**
|
|
243
350
|
* The number of bits in an IPv4 address.
|
|
244
351
|
* @since v0.0.1
|
|
352
|
+
* @see https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#associatedconstant.BITS
|
|
245
353
|
*/
|
|
246
354
|
static readonly BITS = 32;
|
|
247
355
|
/**
|
|
248
356
|
* The broadcast address `255.255.255.255`.
|
|
249
357
|
* @since v0.0.1
|
|
358
|
+
* @see https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#associatedconstant.BROADCAST
|
|
250
359
|
*/
|
|
251
360
|
static readonly BROADCAST: Ipv4Addr;
|
|
252
361
|
/**
|
|
253
362
|
* The localhost address `127.0.0.1`.
|
|
254
363
|
* @since v0.0.1
|
|
364
|
+
* @see https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#associatedconstant.LOCALHOST
|
|
255
365
|
*/
|
|
256
366
|
static readonly LOCALHOST: Ipv4Addr;
|
|
257
367
|
/**
|
|
258
368
|
* The unspecified address `0.0.0.0`.
|
|
259
369
|
* @since v0.0.1
|
|
370
|
+
* @see https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#associatedconstant.UNSPECIFIED
|
|
260
371
|
*/
|
|
261
372
|
static readonly UNSPECIFIED: Ipv4Addr;
|
|
262
373
|
/**
|
|
@@ -357,23 +468,32 @@ declare class Ipv4Addr {
|
|
|
357
468
|
* @see https://datatracker.ietf.org/doc/html/rfc6598
|
|
358
469
|
* @returns `true` when the address is in `100.64.0.0/10`, otherwise `false`.
|
|
359
470
|
* @since v0.0.1
|
|
471
|
+
* @see https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#method.is_shared
|
|
360
472
|
*/
|
|
361
473
|
isShared(): boolean;
|
|
362
474
|
/**
|
|
363
475
|
* Checks whether this address is the unspecified address.
|
|
364
476
|
* @returns `true` when the address is `0.0.0.0`, otherwise `false`.
|
|
365
477
|
* @since v0.0.1
|
|
478
|
+
* @see https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#method.is_unspecified
|
|
366
479
|
*/
|
|
367
480
|
isUnspecified(): boolean;
|
|
368
481
|
/**
|
|
369
|
-
*
|
|
370
|
-
* @returns An
|
|
482
|
+
* Gets the four octets of this IPv4 address.
|
|
483
|
+
* @returns An array containing the four octets `[num1, num2, num3, num4]`.
|
|
484
|
+
* @see https://doc.rust-lang.org/stable/std/net/struct.Ipv4Addr.html#method.octets
|
|
485
|
+
* @since v0.2.0
|
|
486
|
+
*/
|
|
487
|
+
toOctets(): [number, number, number, number];
|
|
488
|
+
/**
|
|
489
|
+
* Converts this address to an IPv4-compatible {@link Ipv6Addr}.
|
|
490
|
+
* @returns An {@link Ipv6Addr} in the form `::a.b.c.d`.
|
|
371
491
|
* @since v0.0.1
|
|
372
492
|
*/
|
|
373
493
|
toIpv6(): Ipv6Addr;
|
|
374
494
|
/**
|
|
375
|
-
* Converts this address to an IPv4-mapped
|
|
376
|
-
* @returns An
|
|
495
|
+
* Converts this address to an IPv4-mapped {@link Ipv6Addr}.
|
|
496
|
+
* @returns An {@link Ipv6Addr} in the form `::ffff:a.b.c.d`.
|
|
377
497
|
* @since v0.0.1
|
|
378
498
|
*/
|
|
379
499
|
toIpv6Mapped(): Ipv6Addr;
|
|
@@ -385,54 +505,343 @@ declare class Ipv4Addr {
|
|
|
385
505
|
toString(): string;
|
|
386
506
|
/**
|
|
387
507
|
* Encodes this address to a 4-byte buffer.
|
|
388
|
-
* @returns An
|
|
508
|
+
* @returns An {@link ArrayBuffer} containing the IPv4 integer value.
|
|
389
509
|
* @since v0.0.1
|
|
510
|
+
* @example
|
|
511
|
+
* const buffer: ArrayBuffer = addr.toBuffer();
|
|
390
512
|
*/
|
|
391
513
|
toBuffer(littleEndian?: boolean): ArrayBuffer;
|
|
392
514
|
/**
|
|
393
515
|
* Compares this IPv4 address with another for equality.
|
|
394
|
-
* @param other instance of another
|
|
516
|
+
* @param other instance of another address like to compare with.
|
|
395
517
|
* @returns `true` if both addresses are equal, otherwise `false`.
|
|
396
518
|
* @since v0.1.0
|
|
397
519
|
*/
|
|
398
|
-
equals(other
|
|
520
|
+
equals(other?: unknown): boolean;
|
|
399
521
|
}
|
|
400
522
|
//#endregion
|
|
401
523
|
//#region src/Ipv4Net.d.ts
|
|
402
524
|
/**
|
|
403
525
|
* Represents an IPv4 network.
|
|
404
526
|
* @example
|
|
405
|
-
* const
|
|
527
|
+
* const addrRes = Ipv4Addr.from('192.168.0.1');
|
|
528
|
+
* const addr = Ipv4Addr.fromOrThrow('192.168.0.1');
|
|
406
529
|
* const network = Ipv4Net.fromAddr(addr, 24);
|
|
407
530
|
* @since v0.1.2
|
|
408
531
|
*/
|
|
409
|
-
declare class Ipv4Net {
|
|
532
|
+
export declare class Ipv4Net {
|
|
410
533
|
#private;
|
|
411
|
-
|
|
534
|
+
/**
|
|
535
|
+
* Size of the network (subnet mask length).
|
|
536
|
+
* @since v0.1.2
|
|
537
|
+
*/
|
|
412
538
|
readonly size: number;
|
|
539
|
+
/**
|
|
540
|
+
* Address family of the network.
|
|
541
|
+
* @since v0.1.2
|
|
542
|
+
*/
|
|
543
|
+
readonly family: "ipv4";
|
|
413
544
|
private constructor();
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
545
|
+
/**
|
|
546
|
+
* Creates an IPv4 network from address and a subnet mask length.
|
|
547
|
+
* @param address The starting {@link Ipv4Addr} of the network.
|
|
548
|
+
* @param size The size of the network (subnet mask length).
|
|
549
|
+
* @returns A {@link CoreResult} containing the parsed {@link Ipv4Net} instance or a {@link RangeError} if the network size is invalid.
|
|
550
|
+
* @example
|
|
551
|
+
* const networkRes: CoreResult<Ipv4Net, RangeError> = Ipv4Net.fromAddr(addr, 24);
|
|
552
|
+
* @since v0.2.0
|
|
553
|
+
*/
|
|
554
|
+
static fromAddr(address: Ipv4Addr, size: number): CoreResult<Ipv4Net, RangeError>;
|
|
555
|
+
/**
|
|
556
|
+
* Creates an IPv4 network from address and a subnet mask length, throwing an error if creation fails.
|
|
557
|
+
* @param address The starting {@link Ipv4Addr} of the network.
|
|
558
|
+
* @param size The size of the network (subnet mask length).
|
|
559
|
+
* @returns The parsed {@link Ipv4Net} instance.
|
|
560
|
+
* @throws {RangeError} If the network size is invalid.
|
|
561
|
+
* @example
|
|
562
|
+
* const network: Ipv4Net = Ipv4Net.fromAddrOrThrow(addr, 24);
|
|
563
|
+
* @since v0.2.0
|
|
564
|
+
*/
|
|
565
|
+
static fromAddrOrThrow(address: Ipv4Addr, size: number): Ipv4Net;
|
|
566
|
+
/**
|
|
567
|
+
* Creates an IPv4 network from its string representation.
|
|
568
|
+
* @param value The string representation of the IPv4 network, e.g., `192.168.0.1/24`.
|
|
569
|
+
* @returns A {@link CoreResult} containing the parsed {@link Ipv4Net} instance or a {@link TypeError} if parsing fails.
|
|
570
|
+
* @example
|
|
571
|
+
* const networkRes: CoreResult<Ipv4Net, TypeError> = Ipv4Net.from('192.168.0.1/24');
|
|
572
|
+
* @since v0.2.0
|
|
573
|
+
*/
|
|
574
|
+
static from(value: string): CoreResult<Ipv4Net, TypeError>;
|
|
575
|
+
/**
|
|
576
|
+
* Creates an IPv4 network from its string representation, throwing an error if parsing fails.
|
|
577
|
+
* @param value The string representation of the IPv4 network, e.g., `192.168.0.1/24`.
|
|
578
|
+
* @returns The parsed {@link Ipv4Net} instance.
|
|
579
|
+
* @throws {TypeError} If the string representation is invalid.
|
|
580
|
+
* @example
|
|
581
|
+
* const network: Ipv4Net = Ipv4Net.fromOrThrow('192.168.0.1/24');
|
|
582
|
+
* @since v0.2.0
|
|
583
|
+
*/
|
|
584
|
+
static fromOrThrow(value: string): Ipv4Net;
|
|
585
|
+
/**
|
|
586
|
+
* Checks if the given IPv4 address is contained within the network.
|
|
587
|
+
* @param addr The {@link Ipv4Addr} to check.
|
|
588
|
+
* @returns `true` if the given address is contained within the network, otherwise `false`.
|
|
589
|
+
* @since v0.2.0
|
|
590
|
+
*/
|
|
591
|
+
contains(addr: Ipv4Addr): boolean;
|
|
592
|
+
/**
|
|
593
|
+
* Gets the broadcast address of the network.
|
|
594
|
+
* @returns The broadcast address as an {@link Ipv4Addr} instance.
|
|
595
|
+
* @since v0.2.0
|
|
596
|
+
*/
|
|
597
|
+
broadcast(): Ipv4Addr;
|
|
598
|
+
/**
|
|
599
|
+
* Gets the network mask of the IPv4 network.
|
|
600
|
+
* @returns The network mask as an {@link Ipv4Addr} instance.
|
|
601
|
+
* @since v0.2.0
|
|
602
|
+
*/
|
|
603
|
+
netmask(): Ipv4Addr;
|
|
604
|
+
/**
|
|
605
|
+
* Gets the string representation of the IPv4 network.
|
|
606
|
+
* @returns The IPv4 network as a string, e.g., `192.168.0.1/24`.
|
|
607
|
+
* @since v0.2.0
|
|
608
|
+
*/
|
|
609
|
+
toString(): string;
|
|
610
|
+
/**
|
|
611
|
+
* Gets the first address within the network.
|
|
612
|
+
* @returns The first address as an {@link Ipv4Addr} instance.
|
|
613
|
+
* @since v0.2.0
|
|
614
|
+
*/
|
|
615
|
+
first(): Ipv4Addr;
|
|
616
|
+
/**
|
|
617
|
+
* Gets the last address within the network.
|
|
618
|
+
* @returns The last address as an {@link Ipv4Addr} instance.
|
|
619
|
+
* @since v0.2.0
|
|
620
|
+
*/
|
|
621
|
+
last(): Ipv4Addr;
|
|
622
|
+
/**
|
|
623
|
+
* Gets the first usable address within the network.
|
|
624
|
+
* @returns The first usable address as an {@link Ipv4Addr} instance.
|
|
625
|
+
* @since v0.2.0
|
|
626
|
+
*/
|
|
627
|
+
firstUsable(): Ipv4Addr;
|
|
628
|
+
/**
|
|
629
|
+
* Gets the last usable address within the network.
|
|
630
|
+
* @returns The last usable address as an {@link Ipv4Addr} instance.
|
|
631
|
+
* @since v0.2.0
|
|
632
|
+
*/
|
|
633
|
+
lastUsable(): Ipv4Addr;
|
|
634
|
+
/**
|
|
635
|
+
* Checks if the current network is equal to another network.
|
|
636
|
+
* @param other The other network to compare with.
|
|
637
|
+
* @returns `true` if the networks are equal, otherwise `false`.
|
|
638
|
+
* @example
|
|
639
|
+
* const isEqual = Ipv4Net.fromOrThrow('192.168.0.0/24').equals(Ipv4Net.fromOrThrow('192.168.0.0/24'));
|
|
640
|
+
* @since v0.2.0
|
|
641
|
+
*/
|
|
642
|
+
equals(other?: unknown): boolean;
|
|
643
|
+
/**
|
|
644
|
+
* Assigns an address to the current network, effectively combining the network with the given address.
|
|
645
|
+
* @param value The other IPv4 address to combine with (e.g., `0.0.0.100`)
|
|
646
|
+
* @returns The combined IPv4 address as a {@link CoreResult} containing either the resulting {@link Ipv4Addr} or a {@link RangeError} if the address does not fit within the host portion of the network.
|
|
647
|
+
* @example
|
|
648
|
+
* const network = Ipv4Net.fromOrThrow('192.168.0.0/24');
|
|
649
|
+
* const result: CoreResult<Ipv4Addr, RangeError | TypeError> = network.assignAddress('0.0.0.100');
|
|
650
|
+
* const result: CoreResult<Ipv4Addr, RangeError | TypeError> = network.assignAddress(Ipv4Addr.fromOrThrow('0.0.0.100'))
|
|
651
|
+
* @since v0.2.0
|
|
652
|
+
*/
|
|
653
|
+
assignAddress(value: Ipv4Addr | string): CoreResult<Ipv4Addr, RangeError | TypeError>;
|
|
654
|
+
/**
|
|
655
|
+
* Assigns an address to the current network, effectively combining the network with the given address.
|
|
656
|
+
* @param other The other IPv4 address to combine with (e.g., `0.0.0.100`)
|
|
657
|
+
* @returns The combined IPv4 address as an {@link Ipv4Addr} instance. (e.g., combining `192.168.0.0/24` with `0.0.0.100` would result in `192.168.0.100`)
|
|
658
|
+
* @throws {RangeError} If the given address does not fit within the host portion of the network.
|
|
659
|
+
* @example
|
|
660
|
+
* const network = Ipv4Net.fromOrThrow('192.168.0.0/24');
|
|
661
|
+
* const combined = network.assignAddressOrThrow('0.0.0.100'); // Ipv4Addr(192.168.0.100)
|
|
662
|
+
* const combined = network.assignAddressOrThrow(Ipv4Addr.fromOrThrow('0.0.0.100')); // Ipv4Addr(192.168.0.100)
|
|
663
|
+
* @since v0.2.0
|
|
664
|
+
*/
|
|
665
|
+
assignAddressOrThrow(other: Ipv4Addr | string): Ipv4Addr;
|
|
666
|
+
/**
|
|
667
|
+
* Checks if the current network is a subnet of the given parent network.
|
|
668
|
+
* @param parent The parent network to check against.
|
|
669
|
+
* @returns `true` if the current network is a subnet of the parent network, `false` otherwise.
|
|
670
|
+
* @since v0.2.0
|
|
671
|
+
*/
|
|
672
|
+
isSubnetOf(parent: Ipv4Net): boolean;
|
|
673
|
+
/**
|
|
674
|
+
* Checks if the current network contains the given child network.
|
|
675
|
+
* @param child The child network to check for containment.
|
|
676
|
+
* @returns `true` if the current network contains the child network, `false` otherwise.
|
|
677
|
+
* @since v0.2.0
|
|
678
|
+
*/
|
|
679
|
+
containsNet(child: Ipv4Net): boolean;
|
|
680
|
+
/**
|
|
681
|
+
* Returns an iterable of all addresses within the network.
|
|
682
|
+
* @returns An {@link Ipv4Addr} {@link Iterable} of all addresses within the network.
|
|
683
|
+
* @since v0.2.0
|
|
684
|
+
*/
|
|
685
|
+
addresses(): Iterable<Ipv4Addr>;
|
|
686
|
+
/**
|
|
687
|
+
* Returns an iterable of all usable host addresses within the network.
|
|
688
|
+
* @returns An {@link Ipv4Addr} {@link Iterable} of all usable host addresses within the network.
|
|
689
|
+
* @since v0.2.0
|
|
690
|
+
*/
|
|
691
|
+
hosts(): Iterable<Ipv4Addr>;
|
|
417
692
|
}
|
|
418
693
|
//#endregion
|
|
419
694
|
//#region src/Ipv6Net.d.ts
|
|
420
695
|
/**
|
|
421
696
|
* Represents an IPv6 network.
|
|
422
697
|
* @example
|
|
423
|
-
* const
|
|
698
|
+
* const addrRes = Ipv6Addr.from('2001:db8::1');
|
|
699
|
+
* const addr = Ipv6Addr.fromOrThrow('2001:db8::1');
|
|
424
700
|
* const network = Ipv6Net.fromAddr(addr, 64);
|
|
425
701
|
* @since v0.1.2
|
|
426
702
|
*/
|
|
427
|
-
declare class Ipv6Net {
|
|
703
|
+
export declare class Ipv6Net {
|
|
428
704
|
#private;
|
|
429
|
-
|
|
705
|
+
/**
|
|
706
|
+
* Size of the network (prefix length).
|
|
707
|
+
* @since v0.1.2
|
|
708
|
+
*/
|
|
430
709
|
readonly size: number;
|
|
710
|
+
/**
|
|
711
|
+
* Address family of the network.
|
|
712
|
+
* @since v0.1.2
|
|
713
|
+
*/
|
|
714
|
+
readonly family: "ipv6";
|
|
431
715
|
private constructor();
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
716
|
+
/**
|
|
717
|
+
* Creates an instance of {@link Ipv6Net} from {@link Ipv6Addr} and network size.
|
|
718
|
+
* @param address The interface address as an {@link Ipv6Addr} instance.
|
|
719
|
+
* @param size The network size (prefix length) as a number.
|
|
720
|
+
* @returns A {@link CoreResult} containing the instance of {@link Ipv6Net} if successful, or a {@link RangeError} if the network size is invalid.
|
|
721
|
+
* @since v0.1.2
|
|
722
|
+
*/
|
|
723
|
+
static fromAddr(address: Ipv6Addr, size: number): CoreResult<Ipv6Net, RangeError>;
|
|
724
|
+
/**
|
|
725
|
+
* Creates an instance of {@link Ipv6Net} from {@link Ipv6Addr} and network size, throwing an error if the size is invalid.
|
|
726
|
+
* @param address The interface address as an {@link Ipv6Addr} instance.
|
|
727
|
+
* @param size The network size (prefix length) as a number.
|
|
728
|
+
* @returns An instance of {@link Ipv6Net}.
|
|
729
|
+
* @throws {RangeError} If the network size is not between 0 and 128.
|
|
730
|
+
* @since v0.2.0
|
|
731
|
+
*/
|
|
732
|
+
static fromAddrOrThrow(address: Ipv6Addr, size: number): Ipv6Net;
|
|
733
|
+
/**
|
|
734
|
+
* Creates an instance of {@link Ipv6Net} from a string representation.
|
|
735
|
+
* @param value The string representation of the IPv6 network, e.g., `2001:db8::/64` or full interface address with size.
|
|
736
|
+
* @returns A {@link CoreResult} containing the instance of {@link Ipv6Net} if successful, or a {@link TypeError} if the input is invalid.
|
|
737
|
+
* @since v0.1.2
|
|
738
|
+
*/
|
|
739
|
+
static from(value: string): CoreResult<Ipv6Net, TypeError>;
|
|
740
|
+
/**
|
|
741
|
+
* Creates an instance of {@link Ipv6Net} from a string representation.
|
|
742
|
+
* @param value The string representation of the IPv6 network, e.g., `2001:db8::/64` or full interface address with size.
|
|
743
|
+
* @returns An instance of {@link Ipv6Net}.
|
|
744
|
+
* @throws {TypeError} If the input string is not a valid IPv6 network representation.
|
|
745
|
+
* @since v0.2.0
|
|
746
|
+
*/
|
|
747
|
+
static fromOrThrow(value: string): Ipv6Net;
|
|
748
|
+
/**
|
|
749
|
+
* Checks if the given IPv6 address is contained within the network.
|
|
750
|
+
* @param addr The {@link Ipv6Addr} to check.
|
|
751
|
+
* @returns `true` if the given address is contained within the network, otherwise `false`.
|
|
752
|
+
* @since v0.2.0
|
|
753
|
+
*/
|
|
754
|
+
contains(addr: Ipv6Addr): boolean;
|
|
755
|
+
/**
|
|
756
|
+
* Gets the network mask of the IPv6 network.
|
|
757
|
+
* @returns The network mask as an {@link Ipv6Addr} instance.
|
|
758
|
+
* @since v0.2.0
|
|
759
|
+
*/
|
|
760
|
+
netmask(): Ipv6Addr;
|
|
761
|
+
/**
|
|
762
|
+
* Gets the string representation of the IPv6 network.
|
|
763
|
+
* @returns The IPv6 network as a string, e.g., `2001:db8::1/64`.
|
|
764
|
+
* @since v0.2.0
|
|
765
|
+
*/
|
|
766
|
+
toString(): string;
|
|
767
|
+
/**
|
|
768
|
+
* Returns the expanded string representation of the IPv6 network.
|
|
769
|
+
* @returns The IPv6 network in expanded notation, e.g., `2001:0db8:0000:0000:0000:0000:0000:0001/64`.
|
|
770
|
+
* @since v0.2.0
|
|
771
|
+
*/
|
|
772
|
+
toExpandedString(): string;
|
|
773
|
+
/**
|
|
774
|
+
* Gets the first address within the network.
|
|
775
|
+
* @returns The first address as an {@link Ipv6Addr} instance.
|
|
776
|
+
* @since v0.2.0
|
|
777
|
+
*/
|
|
778
|
+
first(): Ipv6Addr;
|
|
779
|
+
/**
|
|
780
|
+
* Gets the last address within the network.
|
|
781
|
+
* @returns The last address as an {@link Ipv6Addr} instance.
|
|
782
|
+
* @since v0.2.0
|
|
783
|
+
*/
|
|
784
|
+
last(): Ipv6Addr;
|
|
785
|
+
/**
|
|
786
|
+
* Gets the first usable address within the network.
|
|
787
|
+
* @returns The first usable address as an {@link Ipv6Addr} instance.
|
|
788
|
+
* @since v0.2.0
|
|
789
|
+
*/
|
|
790
|
+
firstUsable(): Ipv6Addr;
|
|
791
|
+
/**
|
|
792
|
+
* Gets the last usable address within the network.
|
|
793
|
+
* @returns The last usable address as an {@link Ipv6Addr} instance.
|
|
794
|
+
* @since v0.2.0
|
|
795
|
+
*/
|
|
796
|
+
lastUsable(): Ipv6Addr;
|
|
797
|
+
/**
|
|
798
|
+
* Checks if the current network is equal to another network.
|
|
799
|
+
* @param other The other network to compare with.
|
|
800
|
+
* @returns `true` if the networks are equal, otherwise `false`.
|
|
801
|
+
* @since v0.2.0
|
|
802
|
+
*/
|
|
803
|
+
equals(other?: unknown): boolean;
|
|
804
|
+
/**
|
|
805
|
+
* Assigns an address to the current network, effectively combining the network with the given address.
|
|
806
|
+
* @param value The other IPv6 address to combine with (e.g., `::100`)
|
|
807
|
+
* @returns The combined IPv6 address as a {@link CoreResult} containing either the resulting {@link Ipv6Addr} or a {@link RangeError} if the address does not fit within the host portion of the network.
|
|
808
|
+
* @since v0.2.0
|
|
809
|
+
*/
|
|
810
|
+
assignAddress(value: Ipv6Addr | string): CoreResult<Ipv6Addr, RangeError>;
|
|
811
|
+
/**
|
|
812
|
+
* Assigns an address to the current network, effectively combining the network with the given address.
|
|
813
|
+
* @param other The other IPv6 address to combine with (e.g., `::100`)
|
|
814
|
+
* @returns The combined IPv6 address as an {@link Ipv6Addr} instance. (e.g., combining `2001:db8::/64` with `::100` would result in `2001:db8::100`)
|
|
815
|
+
* @throws {RangeError} If the given address does not fit within the host portion of the network.
|
|
816
|
+
* @since v0.2.0
|
|
817
|
+
*/
|
|
818
|
+
assignAddressOrThrow(other: Ipv6Addr | string): Ipv6Addr;
|
|
819
|
+
/**
|
|
820
|
+
* Checks if the current network is a subnet of the given parent network.
|
|
821
|
+
* @param parent The parent network to check against.
|
|
822
|
+
* @returns `true` if the current network is a subnet of the parent network, `false` otherwise.
|
|
823
|
+
* @since v0.2.0
|
|
824
|
+
*/
|
|
825
|
+
isSubnetOf(parent: Ipv6Net): boolean;
|
|
826
|
+
/**
|
|
827
|
+
* Checks if the current network contains the given child network.
|
|
828
|
+
* @param child The child network to check for containment.
|
|
829
|
+
* @returns `true` if the current network contains the child network, `false` otherwise.
|
|
830
|
+
* @since v0.2.0
|
|
831
|
+
*/
|
|
832
|
+
containsNet(child: Ipv6Net): boolean;
|
|
833
|
+
/**
|
|
834
|
+
* Gets an iterable of all addresses within the network.
|
|
835
|
+
* @returns An {@link Ipv6Addr} {@link Iterable} of all addresses within the network.
|
|
836
|
+
* @since v0.2.0
|
|
837
|
+
*/
|
|
838
|
+
addresses(): Iterable<Ipv6Addr>;
|
|
839
|
+
/**
|
|
840
|
+
* Gets an iterable of all usable host addresses within the network.
|
|
841
|
+
* @returns An {@link Ipv6Addr} {@link Iterable} of all usable host addresses within the network.
|
|
842
|
+
* @since v0.2.0
|
|
843
|
+
*/
|
|
844
|
+
hosts(): Iterable<Ipv6Addr>;
|
|
435
845
|
}
|
|
436
846
|
//#endregion
|
|
437
|
-
export { Ipv4Addr, Ipv4Net, Ipv6Addr, Ipv6Net };
|
|
438
847
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts","../src/Ipv4Net.ts","../src/Ipv6Net.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts","../src/Ipv4Net.ts","../src/Ipv6Net.ts"],"mappings":"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"}
|