pmcf 1.37.1 → 1.37.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.
- package/package.json +1 -1
- package/src/utils.mjs +9 -12
package/package.json
CHANGED
package/src/utils.mjs
CHANGED
|
@@ -82,17 +82,12 @@ function decodeIPv4(address, length = 32) {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export function encodeIPv6(address) {
|
|
85
|
-
const words = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
86
|
-
|
|
87
|
-
let i = 0;
|
|
88
|
-
for (const a of normalizeIPAddress(address).split(/\:/)) {
|
|
89
|
-
words[i++] = parseInt(a,16);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
85
|
let res = 0n;
|
|
93
86
|
let shift = 128n;
|
|
94
87
|
|
|
95
|
-
for(const word of
|
|
88
|
+
for (const word of normalizeIPAddress(address)
|
|
89
|
+
.split(/\:/)
|
|
90
|
+
.map(a => parseInt(a, 16))) {
|
|
96
91
|
shift -= 16n;
|
|
97
92
|
res += BigInt(word) << shift;
|
|
98
93
|
}
|
|
@@ -101,13 +96,12 @@ export function encodeIPv6(address) {
|
|
|
101
96
|
}
|
|
102
97
|
|
|
103
98
|
export function decodeIPv6(address, length = 128) {
|
|
104
|
-
|
|
105
99
|
let words = [];
|
|
106
100
|
let shift = 128n;
|
|
107
101
|
|
|
108
|
-
for(let i = 0; i < length / 16; i++) {
|
|
102
|
+
for (let i = 0; i < length / 16; i++) {
|
|
109
103
|
shift -= 16n;
|
|
110
|
-
words
|
|
104
|
+
words.push(((address >> shift) & 0xffffn).toString(16).padStart(4, "0"));
|
|
111
105
|
}
|
|
112
106
|
|
|
113
107
|
return words.join(":");
|
|
@@ -127,7 +121,10 @@ export function normalizeCIDR(address) {
|
|
|
127
121
|
prefix = decodeIPv4(n, prefixLength);
|
|
128
122
|
} else {
|
|
129
123
|
let n = encodeIPv6(prefix);
|
|
130
|
-
n =
|
|
124
|
+
n =
|
|
125
|
+
n &
|
|
126
|
+
(0xffffffffffffffffffffffffffffffffn <<
|
|
127
|
+
(128n - BigInt(prefixLength)));
|
|
131
128
|
prefix = decodeIPv6(n, prefixLength);
|
|
132
129
|
}
|
|
133
130
|
} else {
|