net-socket-address 0.0.1
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 +21 -0
- package/README.md +21 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +109 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luolapeikko
|
|
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,21 @@
|
|
|
1
|
+
# net-socket-address
|
|
2
|
+
|
|
3
|
+
## Runtime agnostic core Socket IpAddr classes base on Rust implementation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i net-socket-address net-address @luolapeikko/result-option
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Examples
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const socketAddr = new SocketAddrV4({port: 6372});
|
|
15
|
+
// or new SocketAddrV4({addr: Ipv4Addr.UNSPECIFIED, port: 6372});
|
|
16
|
+
tcpServer.listen(socketAddr..asNodeListenerOptions(), () => {});
|
|
17
|
+
udpSocket.bind(socketAddr, () => {});
|
|
18
|
+
tcpServer.listen({...socketAddr.asNodeListenerOptions(), ipv6Only: true}, () => {});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Full [Documentation](https://luolapeikko.github.io/net-address-base/)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`net-address`);var t=class{#e;port;address;family=`ipv4`;constructor({addr:t,port:n}){this.#e=t??e.Ipv4Addr.UNSPECIFIED,this.port=n,this.address=this.#e.toString()}asNodeListenerOptions(){return{port:this.port,host:this.address}}getRawAddress(){return this.#e}toString(){return`${this.address}:${this.port}`}},n=class{#e;port;family=`ipv6`;address;flowlabel;constructor({address:t,port:n,flowlabel:r}){this.#e=t??e.Ipv6Addr.UNSPECIFIED,this.port=n,this.flowlabel=r,this.address=this.#e.toString()}asNodeListenerOptions(){return{port:this.port,host:this.address}}getRawAddress(){return this.#e}toString(){return`${this.address}:${this.port}`}};exports.SocketAddrV4=t,exports.SocketAddrV6=n;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#addr","Ipv4Addr","#addr","Ipv6Addr"],"sources":["../src/SocketAddrV4.ts","../src/SocketAddrV6.ts"],"sourcesContent":["import {Ipv4Addr} from 'net-address';\n\n/**\n * Represents an IPv4 socket address, consisting of an IPv4 address and a port number.\n * @example\n * const socketAddr = new SocketAddrV4({port: 6372}); // new SocketAddrV4({addr: Ipv4Addr.UNSPECIFIED, port: 6372});\n * tcpServer.listen(socketAddr.asNodeListenerOptions(), () => {});\n * udpSocket.bind(socketAddr, () => {});\n * tcpServer.listen({...socketAddr.asNodeListenerOptions(), ipv6Only: true}, () => {});\n * @since v0.0.1\n */\nexport class SocketAddrV4 {\n\t#addr: Ipv4Addr;\n\tpublic readonly port: number;\n\tpublic readonly address: string;\n\tpublic readonly family = 'ipv4';\n\t/**\n\t * Creates a new `SocketAddrV4` instance.\n\t * @param options - The options for creating the socket address.\n\t * @param options.addr - The IPv4 address. Defaults to {@link Ipv4Addr.UNSPECIFIED}.\n\t * @param options.port - The port number.\n\t */\n\tpublic constructor({addr, port}: {addr?: Ipv4Addr; port: number}) {\n\t\tthis.#addr = addr ?? Ipv4Addr.UNSPECIFIED;\n\t\tthis.port = port;\n\t\tthis.address = this.#addr.toString();\n\t}\n\n\t/**\n\t * Returns an object suitable for use as options in Node.js `net.Server.listen()` method.\n\t * @returns An object containing the `port` and `host` properties.\n\t * @since v0.0.1\n\t */\n\tpublic asNodeListenerOptions(): {port: number; host: string} {\n\t\treturn {\n\t\t\tport: this.port,\n\t\t\thost: this.address,\n\t\t};\n\t}\n\n\t/**\n\t * Gets the raw `Ipv4Addr` instance representing the IP address of this socket address.\n\t * @returns Ipv4Addr instance of the socket address's IP address.\n\t * @since v0.0.1\n\t */\n\tpublic getRawAddress(): Ipv4Addr {\n\t\treturn this.#addr;\n\t}\n\n\t/**\n\t * Returns a string representation of this socket address.\n\t * @returns The string representation in the format \"address:port\".\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\treturn `${this.address}:${this.port}`;\n\t}\n}\n","import {Ipv6Addr} from 'net-address';\n\n/**\n * Represents an IPv6 socket address, consisting of an IPv6 address, a port number, and an optional flow label.\n * @example\n * const anySocketAddress = new SocketAddrV6(6372); // new SocketAddrV6(Ipv6Addr.UNSPECIFIED, 6372);\n * tcpServer.listen(anySocketAddress.asNodeListenerOptions(), () => {});\n * udpSocket.bind(anySocketAddress, () => {});\n * @since v0.0.1\n */\nexport class SocketAddrV6 {\n\t#addr: Ipv6Addr;\n\tpublic readonly port: number;\n\tpublic readonly family = 'ipv6';\n\tpublic readonly address: string;\n\tpublic flowlabel?: number;\n\n\t/**\n\t * Creates a new `SocketAddrV6` instance.\n\t * @param options - The options for creating the socket address.\n\t * @param options.address - The IPv6 address. Defaults to {@link Ipv6Addr.UNSPECIFIED}.\n\t * @param options.port - The port number.\n\t * @param options.flowlabel - The flow label.\n\t */\n\tpublic constructor({address, port, flowlabel}: {address?: Ipv6Addr; port: number; flowlabel?: number}) {\n\t\tthis.#addr = address ?? Ipv6Addr.UNSPECIFIED;\n\t\tthis.port = port;\n\t\tthis.flowlabel = flowlabel;\n\t\tthis.address = this.#addr.toString();\n\t}\n\n\t/**\n\t * Returns an object suitable for use as options in Node.js `net.Server.listen()` method.\n\t * @returns An object containing the `port` and `host` properties.\n\t * @since v0.0.1\n\t */\n\tpublic asNodeListenerOptions(): {port: number; host: string} {\n\t\treturn {\n\t\t\tport: this.port,\n\t\t\thost: this.address,\n\t\t};\n\t}\n\n\t/**\n\t * Gets the raw `Ipv6Addr` instance representing the IP address of this socket address.\n\t * @returns Ipv6Addr instance of the socket address's IP address.\n\t * @since v0.0.1\n\t */\n\tpublic getRawAddress(): Ipv6Addr {\n\t\treturn this.#addr;\n\t}\n\n\t/**\n\t * Returns a string representation of this socket address.\n\t * @returns The string representation in the format \"address:port\".\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\treturn `${this.address}:${this.port}`;\n\t}\n}\n"],"mappings":"gGAWA,IAAa,EAAb,KAA0B,CACzB,GACA,KACA,QACA,OAAyB,OAOzB,YAAmB,CAAC,OAAM,QAAwC,CACjE,MAAA,EAAa,GAAQC,EAAAA,SAAS,YAC9B,KAAK,KAAO,EACZ,KAAK,QAAU,MAAA,EAAW,UAAU,CAQrC,uBAA6D,CAC5D,MAAO,CACN,KAAM,KAAK,KACX,KAAM,KAAK,QACX,CAQF,eAAiC,CAChC,OAAO,MAAA,EAQR,UAA0B,CACzB,MAAO,GAAG,KAAK,QAAQ,GAAG,KAAK,SC7CpB,EAAb,KAA0B,CACzB,GACA,KACA,OAAyB,OACzB,QACA,UASA,YAAmB,CAAC,UAAS,OAAM,aAAoE,CACtG,MAAA,EAAa,GAAWE,EAAAA,SAAS,YACjC,KAAK,KAAO,EACZ,KAAK,UAAY,EACjB,KAAK,QAAU,MAAA,EAAW,UAAU,CAQrC,uBAA6D,CAC5D,MAAO,CACN,KAAM,KAAK,KACX,KAAM,KAAK,QACX,CAQF,eAAiC,CAChC,OAAO,MAAA,EAQR,UAA0B,CACzB,MAAO,GAAG,KAAK,QAAQ,GAAG,KAAK"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Ipv4Addr, Ipv6Addr } from "net-address";
|
|
2
|
+
|
|
3
|
+
//#region src/SocketAddrV4.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Represents an IPv4 socket address, consisting of an IPv4 address and a port number.
|
|
6
|
+
* @example
|
|
7
|
+
* const socketAddr = new SocketAddrV4({port: 6372}); // new SocketAddrV4({addr: Ipv4Addr.UNSPECIFIED, port: 6372});
|
|
8
|
+
* tcpServer.listen(socketAddr.asNodeListenerOptions(), () => {});
|
|
9
|
+
* udpSocket.bind(socketAddr, () => {});
|
|
10
|
+
* tcpServer.listen({...socketAddr.asNodeListenerOptions(), ipv6Only: true}, () => {});
|
|
11
|
+
* @since v0.0.1
|
|
12
|
+
*/
|
|
13
|
+
declare class SocketAddrV4 {
|
|
14
|
+
#private;
|
|
15
|
+
readonly port: number;
|
|
16
|
+
readonly address: string;
|
|
17
|
+
readonly family = "ipv4";
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new `SocketAddrV4` instance.
|
|
20
|
+
* @param options - The options for creating the socket address.
|
|
21
|
+
* @param options.addr - The IPv4 address. Defaults to {@link Ipv4Addr.UNSPECIFIED}.
|
|
22
|
+
* @param options.port - The port number.
|
|
23
|
+
*/
|
|
24
|
+
constructor({
|
|
25
|
+
addr,
|
|
26
|
+
port
|
|
27
|
+
}: {
|
|
28
|
+
addr?: Ipv4Addr;
|
|
29
|
+
port: number;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Returns an object suitable for use as options in Node.js `net.Server.listen()` method.
|
|
33
|
+
* @returns An object containing the `port` and `host` properties.
|
|
34
|
+
* @since v0.0.1
|
|
35
|
+
*/
|
|
36
|
+
asNodeListenerOptions(): {
|
|
37
|
+
port: number;
|
|
38
|
+
host: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Gets the raw `Ipv4Addr` instance representing the IP address of this socket address.
|
|
42
|
+
* @returns Ipv4Addr instance of the socket address's IP address.
|
|
43
|
+
* @since v0.0.1
|
|
44
|
+
*/
|
|
45
|
+
getRawAddress(): Ipv4Addr;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a string representation of this socket address.
|
|
48
|
+
* @returns The string representation in the format "address:port".
|
|
49
|
+
* @since v0.0.1
|
|
50
|
+
*/
|
|
51
|
+
toString(): string;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/SocketAddrV6.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* Represents an IPv6 socket address, consisting of an IPv6 address, a port number, and an optional flow label.
|
|
57
|
+
* @example
|
|
58
|
+
* const anySocketAddress = new SocketAddrV6(6372); // new SocketAddrV6(Ipv6Addr.UNSPECIFIED, 6372);
|
|
59
|
+
* tcpServer.listen(anySocketAddress.asNodeListenerOptions(), () => {});
|
|
60
|
+
* udpSocket.bind(anySocketAddress, () => {});
|
|
61
|
+
* @since v0.0.1
|
|
62
|
+
*/
|
|
63
|
+
declare class SocketAddrV6 {
|
|
64
|
+
#private;
|
|
65
|
+
readonly port: number;
|
|
66
|
+
readonly family = "ipv6";
|
|
67
|
+
readonly address: string;
|
|
68
|
+
flowlabel?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new `SocketAddrV6` instance.
|
|
71
|
+
* @param options - The options for creating the socket address.
|
|
72
|
+
* @param options.address - The IPv6 address. Defaults to {@link Ipv6Addr.UNSPECIFIED}.
|
|
73
|
+
* @param options.port - The port number.
|
|
74
|
+
* @param options.flowlabel - The flow label.
|
|
75
|
+
*/
|
|
76
|
+
constructor({
|
|
77
|
+
address,
|
|
78
|
+
port,
|
|
79
|
+
flowlabel
|
|
80
|
+
}: {
|
|
81
|
+
address?: Ipv6Addr;
|
|
82
|
+
port: number;
|
|
83
|
+
flowlabel?: number;
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Returns an object suitable for use as options in Node.js `net.Server.listen()` method.
|
|
87
|
+
* @returns An object containing the `port` and `host` properties.
|
|
88
|
+
* @since v0.0.1
|
|
89
|
+
*/
|
|
90
|
+
asNodeListenerOptions(): {
|
|
91
|
+
port: number;
|
|
92
|
+
host: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Gets the raw `Ipv6Addr` instance representing the IP address of this socket address.
|
|
96
|
+
* @returns Ipv6Addr instance of the socket address's IP address.
|
|
97
|
+
* @since v0.0.1
|
|
98
|
+
*/
|
|
99
|
+
getRawAddress(): Ipv6Addr;
|
|
100
|
+
/**
|
|
101
|
+
* Returns a string representation of this socket address.
|
|
102
|
+
* @returns The string representation in the format "address:port".
|
|
103
|
+
* @since v0.0.1
|
|
104
|
+
*/
|
|
105
|
+
toString(): string;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { SocketAddrV4, SocketAddrV6 };
|
|
109
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/SocketAddrV4.ts","../src/SocketAddrV6.ts"],"mappings":";;;;;AAWA;;;;;;;cAAa,YAAA;EAAA;WAEI,IAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA;;;;;;;EAOhB,WAAA,CAAA;IAAoB,IAAA;IAAM;EAAA;IAAQ,IAAA,GAAO,QAAA;IAAU,IAAA;EAAA;;;;;;EAWnD,qBAAA,CAAA;IAAiC,IAAA;IAAc,IAAA;EAAA;;ACvBhD;;;;EDmCC,aAAA,CAAA,GAAwB,QAAA;;;;;;EASxB,QAAA,CAAA;AAAA;;;;;AA3CD;;;;;;cCDa,YAAA;EAAA;WAEI,IAAA;EAAA,SACA,MAAA;EAAA,SACA,OAAA;EAChB,SAAA;;;;;;;;EASA,WAAA,CAAA;IAAoB,OAAA;IAAS,IAAA;IAAM;EAAA;IAAa,OAAA,GAAU,QAAA;IAAU,IAAA;IAAc,SAAA;EAAA;;;;;;EAYlF,qBAAA,CAAA;IAAiC,IAAA;IAAc,IAAA;EAAA;EA1BnC;;;;;EAsCZ,aAAA,CAAA,GAAwB,QAAA;;;;;;EASxB,QAAA,CAAA;AAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Ipv4Addr, Ipv6Addr } from "net-address";
|
|
2
|
+
|
|
3
|
+
//#region src/SocketAddrV4.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Represents an IPv4 socket address, consisting of an IPv4 address and a port number.
|
|
6
|
+
* @example
|
|
7
|
+
* const socketAddr = new SocketAddrV4({port: 6372}); // new SocketAddrV4({addr: Ipv4Addr.UNSPECIFIED, port: 6372});
|
|
8
|
+
* tcpServer.listen(socketAddr.asNodeListenerOptions(), () => {});
|
|
9
|
+
* udpSocket.bind(socketAddr, () => {});
|
|
10
|
+
* tcpServer.listen({...socketAddr.asNodeListenerOptions(), ipv6Only: true}, () => {});
|
|
11
|
+
* @since v0.0.1
|
|
12
|
+
*/
|
|
13
|
+
declare class SocketAddrV4 {
|
|
14
|
+
#private;
|
|
15
|
+
readonly port: number;
|
|
16
|
+
readonly address: string;
|
|
17
|
+
readonly family = "ipv4";
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new `SocketAddrV4` instance.
|
|
20
|
+
* @param options - The options for creating the socket address.
|
|
21
|
+
* @param options.addr - The IPv4 address. Defaults to {@link Ipv4Addr.UNSPECIFIED}.
|
|
22
|
+
* @param options.port - The port number.
|
|
23
|
+
*/
|
|
24
|
+
constructor({
|
|
25
|
+
addr,
|
|
26
|
+
port
|
|
27
|
+
}: {
|
|
28
|
+
addr?: Ipv4Addr;
|
|
29
|
+
port: number;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Returns an object suitable for use as options in Node.js `net.Server.listen()` method.
|
|
33
|
+
* @returns An object containing the `port` and `host` properties.
|
|
34
|
+
* @since v0.0.1
|
|
35
|
+
*/
|
|
36
|
+
asNodeListenerOptions(): {
|
|
37
|
+
port: number;
|
|
38
|
+
host: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Gets the raw `Ipv4Addr` instance representing the IP address of this socket address.
|
|
42
|
+
* @returns Ipv4Addr instance of the socket address's IP address.
|
|
43
|
+
* @since v0.0.1
|
|
44
|
+
*/
|
|
45
|
+
getRawAddress(): Ipv4Addr;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a string representation of this socket address.
|
|
48
|
+
* @returns The string representation in the format "address:port".
|
|
49
|
+
* @since v0.0.1
|
|
50
|
+
*/
|
|
51
|
+
toString(): string;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/SocketAddrV6.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* Represents an IPv6 socket address, consisting of an IPv6 address, a port number, and an optional flow label.
|
|
57
|
+
* @example
|
|
58
|
+
* const anySocketAddress = new SocketAddrV6(6372); // new SocketAddrV6(Ipv6Addr.UNSPECIFIED, 6372);
|
|
59
|
+
* tcpServer.listen(anySocketAddress.asNodeListenerOptions(), () => {});
|
|
60
|
+
* udpSocket.bind(anySocketAddress, () => {});
|
|
61
|
+
* @since v0.0.1
|
|
62
|
+
*/
|
|
63
|
+
declare class SocketAddrV6 {
|
|
64
|
+
#private;
|
|
65
|
+
readonly port: number;
|
|
66
|
+
readonly family = "ipv6";
|
|
67
|
+
readonly address: string;
|
|
68
|
+
flowlabel?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new `SocketAddrV6` instance.
|
|
71
|
+
* @param options - The options for creating the socket address.
|
|
72
|
+
* @param options.address - The IPv6 address. Defaults to {@link Ipv6Addr.UNSPECIFIED}.
|
|
73
|
+
* @param options.port - The port number.
|
|
74
|
+
* @param options.flowlabel - The flow label.
|
|
75
|
+
*/
|
|
76
|
+
constructor({
|
|
77
|
+
address,
|
|
78
|
+
port,
|
|
79
|
+
flowlabel
|
|
80
|
+
}: {
|
|
81
|
+
address?: Ipv6Addr;
|
|
82
|
+
port: number;
|
|
83
|
+
flowlabel?: number;
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Returns an object suitable for use as options in Node.js `net.Server.listen()` method.
|
|
87
|
+
* @returns An object containing the `port` and `host` properties.
|
|
88
|
+
* @since v0.0.1
|
|
89
|
+
*/
|
|
90
|
+
asNodeListenerOptions(): {
|
|
91
|
+
port: number;
|
|
92
|
+
host: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Gets the raw `Ipv6Addr` instance representing the IP address of this socket address.
|
|
96
|
+
* @returns Ipv6Addr instance of the socket address's IP address.
|
|
97
|
+
* @since v0.0.1
|
|
98
|
+
*/
|
|
99
|
+
getRawAddress(): Ipv6Addr;
|
|
100
|
+
/**
|
|
101
|
+
* Returns a string representation of this socket address.
|
|
102
|
+
* @returns The string representation in the format "address:port".
|
|
103
|
+
* @since v0.0.1
|
|
104
|
+
*/
|
|
105
|
+
toString(): string;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { SocketAddrV4, SocketAddrV6 };
|
|
109
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/SocketAddrV4.ts","../src/SocketAddrV6.ts"],"mappings":";;;;;AAWA;;;;;;;cAAa,YAAA;EAAA;WAEI,IAAA;EAAA,SACA,OAAA;EAAA,SACA,MAAA;;;;;;;EAOhB,WAAA,CAAA;IAAoB,IAAA;IAAM;EAAA;IAAQ,IAAA,GAAO,QAAA;IAAU,IAAA;EAAA;;;;;;EAWnD,qBAAA,CAAA;IAAiC,IAAA;IAAc,IAAA;EAAA;;ACvBhD;;;;EDmCC,aAAA,CAAA,GAAwB,QAAA;;;;;;EASxB,QAAA,CAAA;AAAA;;;;;AA3CD;;;;;;cCDa,YAAA;EAAA;WAEI,IAAA;EAAA,SACA,MAAA;EAAA,SACA,OAAA;EAChB,SAAA;;;;;;;;EASA,WAAA,CAAA;IAAoB,OAAA;IAAS,IAAA;IAAM;EAAA;IAAa,OAAA,GAAU,QAAA;IAAU,IAAA;IAAc,SAAA;EAAA;;;;;;EAYlF,qBAAA,CAAA;IAAiC,IAAA;IAAc,IAAA;EAAA;EA1BnC;;;;;EAsCZ,aAAA,CAAA,GAAwB,QAAA;;;;;;EASxB,QAAA,CAAA;AAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Ipv4Addr as e,Ipv6Addr as t}from"net-address";var n=class{#e;port;address;family=`ipv4`;constructor({addr:t,port:n}){this.#e=t??e.UNSPECIFIED,this.port=n,this.address=this.#e.toString()}asNodeListenerOptions(){return{port:this.port,host:this.address}}getRawAddress(){return this.#e}toString(){return`${this.address}:${this.port}`}},r=class{#e;port;family=`ipv6`;address;flowlabel;constructor({address:e,port:n,flowlabel:r}){this.#e=e??t.UNSPECIFIED,this.port=n,this.flowlabel=r,this.address=this.#e.toString()}asNodeListenerOptions(){return{port:this.port,host:this.address}}getRawAddress(){return this.#e}toString(){return`${this.address}:${this.port}`}};export{n as SocketAddrV4,r as SocketAddrV6};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#addr","#addr"],"sources":["../src/SocketAddrV4.ts","../src/SocketAddrV6.ts"],"sourcesContent":["import {Ipv4Addr} from 'net-address';\n\n/**\n * Represents an IPv4 socket address, consisting of an IPv4 address and a port number.\n * @example\n * const socketAddr = new SocketAddrV4({port: 6372}); // new SocketAddrV4({addr: Ipv4Addr.UNSPECIFIED, port: 6372});\n * tcpServer.listen(socketAddr.asNodeListenerOptions(), () => {});\n * udpSocket.bind(socketAddr, () => {});\n * tcpServer.listen({...socketAddr.asNodeListenerOptions(), ipv6Only: true}, () => {});\n * @since v0.0.1\n */\nexport class SocketAddrV4 {\n\t#addr: Ipv4Addr;\n\tpublic readonly port: number;\n\tpublic readonly address: string;\n\tpublic readonly family = 'ipv4';\n\t/**\n\t * Creates a new `SocketAddrV4` instance.\n\t * @param options - The options for creating the socket address.\n\t * @param options.addr - The IPv4 address. Defaults to {@link Ipv4Addr.UNSPECIFIED}.\n\t * @param options.port - The port number.\n\t */\n\tpublic constructor({addr, port}: {addr?: Ipv4Addr; port: number}) {\n\t\tthis.#addr = addr ?? Ipv4Addr.UNSPECIFIED;\n\t\tthis.port = port;\n\t\tthis.address = this.#addr.toString();\n\t}\n\n\t/**\n\t * Returns an object suitable for use as options in Node.js `net.Server.listen()` method.\n\t * @returns An object containing the `port` and `host` properties.\n\t * @since v0.0.1\n\t */\n\tpublic asNodeListenerOptions(): {port: number; host: string} {\n\t\treturn {\n\t\t\tport: this.port,\n\t\t\thost: this.address,\n\t\t};\n\t}\n\n\t/**\n\t * Gets the raw `Ipv4Addr` instance representing the IP address of this socket address.\n\t * @returns Ipv4Addr instance of the socket address's IP address.\n\t * @since v0.0.1\n\t */\n\tpublic getRawAddress(): Ipv4Addr {\n\t\treturn this.#addr;\n\t}\n\n\t/**\n\t * Returns a string representation of this socket address.\n\t * @returns The string representation in the format \"address:port\".\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\treturn `${this.address}:${this.port}`;\n\t}\n}\n","import {Ipv6Addr} from 'net-address';\n\n/**\n * Represents an IPv6 socket address, consisting of an IPv6 address, a port number, and an optional flow label.\n * @example\n * const anySocketAddress = new SocketAddrV6(6372); // new SocketAddrV6(Ipv6Addr.UNSPECIFIED, 6372);\n * tcpServer.listen(anySocketAddress.asNodeListenerOptions(), () => {});\n * udpSocket.bind(anySocketAddress, () => {});\n * @since v0.0.1\n */\nexport class SocketAddrV6 {\n\t#addr: Ipv6Addr;\n\tpublic readonly port: number;\n\tpublic readonly family = 'ipv6';\n\tpublic readonly address: string;\n\tpublic flowlabel?: number;\n\n\t/**\n\t * Creates a new `SocketAddrV6` instance.\n\t * @param options - The options for creating the socket address.\n\t * @param options.address - The IPv6 address. Defaults to {@link Ipv6Addr.UNSPECIFIED}.\n\t * @param options.port - The port number.\n\t * @param options.flowlabel - The flow label.\n\t */\n\tpublic constructor({address, port, flowlabel}: {address?: Ipv6Addr; port: number; flowlabel?: number}) {\n\t\tthis.#addr = address ?? Ipv6Addr.UNSPECIFIED;\n\t\tthis.port = port;\n\t\tthis.flowlabel = flowlabel;\n\t\tthis.address = this.#addr.toString();\n\t}\n\n\t/**\n\t * Returns an object suitable for use as options in Node.js `net.Server.listen()` method.\n\t * @returns An object containing the `port` and `host` properties.\n\t * @since v0.0.1\n\t */\n\tpublic asNodeListenerOptions(): {port: number; host: string} {\n\t\treturn {\n\t\t\tport: this.port,\n\t\t\thost: this.address,\n\t\t};\n\t}\n\n\t/**\n\t * Gets the raw `Ipv6Addr` instance representing the IP address of this socket address.\n\t * @returns Ipv6Addr instance of the socket address's IP address.\n\t * @since v0.0.1\n\t */\n\tpublic getRawAddress(): Ipv6Addr {\n\t\treturn this.#addr;\n\t}\n\n\t/**\n\t * Returns a string representation of this socket address.\n\t * @returns The string representation in the format \"address:port\".\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\treturn `${this.address}:${this.port}`;\n\t}\n}\n"],"mappings":"qDAWA,IAAa,EAAb,KAA0B,CACzB,GACA,KACA,QACA,OAAyB,OAOzB,YAAmB,CAAC,OAAM,QAAwC,CACjE,MAAA,EAAa,GAAQ,EAAS,YAC9B,KAAK,KAAO,EACZ,KAAK,QAAU,MAAA,EAAW,UAAU,CAQrC,uBAA6D,CAC5D,MAAO,CACN,KAAM,KAAK,KACX,KAAM,KAAK,QACX,CAQF,eAAiC,CAChC,OAAO,MAAA,EAQR,UAA0B,CACzB,MAAO,GAAG,KAAK,QAAQ,GAAG,KAAK,SC7CpB,EAAb,KAA0B,CACzB,GACA,KACA,OAAyB,OACzB,QACA,UASA,YAAmB,CAAC,UAAS,OAAM,aAAoE,CACtG,MAAA,EAAa,GAAW,EAAS,YACjC,KAAK,KAAO,EACZ,KAAK,UAAY,EACjB,KAAK,QAAU,MAAA,EAAW,UAAU,CAQrC,uBAA6D,CAC5D,MAAO,CACN,KAAM,KAAK,KACX,KAAM,KAAK,QACX,CAQF,eAAiC,CAChC,OAAO,MAAA,EAQR,UAA0B,CACzB,MAAO,GAAG,KAAK,QAAQ,GAAG,KAAK"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "net-socket-address",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Network socket address instances",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.mts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsdown src/index.ts --sourcemap --minify --format cjs,esm --dts --clean -c tsconfig.build.json",
|
|
21
|
+
"validate": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"repository": "github:luolapeikko/net-address-base",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"network",
|
|
29
|
+
"address",
|
|
30
|
+
"socket"
|
|
31
|
+
],
|
|
32
|
+
"author": "mharj",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/luolapeikko/net-address-base/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/luolapeikko/net-address-base#readme",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"net-address": "workspace:*"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"net-address": ">= 0.0.1"
|
|
43
|
+
}
|
|
44
|
+
}
|