pmcf 1.37.0 → 1.37.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.37.0",
3
+ "version": "1.37.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -47,7 +47,7 @@
47
47
  "ava": "^6.2.0",
48
48
  "c8": "^10.1.3",
49
49
  "documentation": "^14.0.3",
50
- "semantic-release": "^24.2.1",
50
+ "semantic-release": "^24.2.2",
51
51
  "typescript": "^5.7.3"
52
52
  },
53
53
  "engines": {
package/src/utils.mjs CHANGED
@@ -100,6 +100,19 @@ export function encodeIPv6(address) {
100
100
  return res;
101
101
  }
102
102
 
103
+ export function decodeIPv6(address, length = 128) {
104
+
105
+ let words = [];
106
+ let shift = 128n;
107
+
108
+ for(let i = 0; i < length / 16; i++) {
109
+ shift -= 16n;
110
+ words[i] = ((address >> shift) & 0xffffn).toString(16).padStart(4,'0');
111
+ }
112
+
113
+ return words.join(":");
114
+ }
115
+
103
116
  export function normalizeCIDR(address) {
104
117
  let [prefix, prefixLength] = address.split(/\//);
105
118
 
@@ -113,9 +126,9 @@ export function normalizeCIDR(address) {
113
126
  n = n & (0xffffffff << (32 - prefixLength));
114
127
  prefix = decodeIPv4(n, prefixLength);
115
128
  } else {
116
- prefix = normalizeIPAddress(prefix);
117
- const parts = prefix.split(/\:/);
118
- prefix = parts.slice(0, prefixLength / 16).join(":");
129
+ let n = encodeIPv6(prefix);
130
+ n = n & (0xffffffffffffffffffffffffffffffffn << (128n - BigInt(prefixLength)));
131
+ prefix = decodeIPv6(n, prefixLength);
119
132
  }
120
133
  } else {
121
134
  return {};
package/types/utils.d.mts CHANGED
@@ -7,6 +7,7 @@ export function isIPv6Address(address: any): boolean;
7
7
  export function isLinkLocal(address: any): any;
8
8
  export function normalizeIPAddress(address: any): any;
9
9
  export function encodeIPv6(address: any): bigint;
10
+ export function decodeIPv6(address: any, length?: number): string;
10
11
  export function normalizeCIDR(address: any): {
11
12
  prefix?: undefined;
12
13
  prefixLength?: undefined;