pmcf 2.10.3 → 2.10.4
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/package.json +1 -1
- package/src/subnet.mjs +7 -15
- package/src/utils.mjs +9 -0
- package/types/utils.d.mts +1 -0
package/package.json
CHANGED
package/src/subnet.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
normalizeCIDR,
|
|
3
3
|
isLinkLocal,
|
|
4
4
|
isIPv4Address,
|
|
5
|
-
isIPv6Address
|
|
5
|
+
isIPv6Address,
|
|
6
|
+
addressWithPrefixLength
|
|
6
7
|
} from "./utils.mjs";
|
|
7
8
|
import { Base } from "./base.mjs";
|
|
8
9
|
import { addType } from "./types.mjs";
|
|
@@ -62,23 +63,14 @@ export class Subnet extends Base {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
get addressRange() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
return [
|
|
67
|
+
addressWithPrefixLength(this.prefix, this.prefixLength),
|
|
68
|
+
this.prefix + ".255".repeat((32 - this.prefixLength) / 8)
|
|
69
|
+
];
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
get longPrefix() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
switch (this.prefixLength) {
|
|
75
|
-
case 24:
|
|
76
|
-
return prefix + ".0";
|
|
77
|
-
case 16:
|
|
78
|
-
return prefix + ".0.0";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return prefix;
|
|
73
|
+
return addressWithPrefixLength(this.prefix, this.prefixLength);
|
|
82
74
|
}
|
|
83
75
|
|
|
84
76
|
get prefix() {
|
package/src/utils.mjs
CHANGED
|
@@ -143,6 +143,15 @@ const ipv6 = {
|
|
|
143
143
|
base: 16
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
+
export function addressWithPrefixLength(address, prefixLength) {
|
|
147
|
+
const definition = ipv4;
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
address +
|
|
151
|
+
".0".repeat((definition.length - prefixLength) / definition.segmentLength)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
146
155
|
function _decode(definition, address, length = definition.length) {
|
|
147
156
|
if (typeof address === "string") {
|
|
148
157
|
return address;
|
package/types/utils.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ export function isIPv6Address(address: any): boolean;
|
|
|
11
11
|
export function isLinkLocal(address: any): boolean;
|
|
12
12
|
export function isLocalhost(address: any): boolean;
|
|
13
13
|
export function normalizeIPAddress(address: any): any;
|
|
14
|
+
export function addressWithPrefixLength(address: any, prefixLength: any): string;
|
|
14
15
|
export function _encode(definition: any, address: any): any;
|
|
15
16
|
export function decodeIPv6(address: any, length: any): string;
|
|
16
17
|
export function encodeIPv6(address: any): any;
|