pmcf 1.37.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.37.0",
3
+ "version": "1.37.2",
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
@@ -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 words) {
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
  }
@@ -100,6 +95,18 @@ export function encodeIPv6(address) {
100
95
  return res;
101
96
  }
102
97
 
98
+ export function decodeIPv6(address, length = 128) {
99
+ let words = [];
100
+ let shift = 128n;
101
+
102
+ for (let i = 0; i < length / 16; i++) {
103
+ shift -= 16n;
104
+ words.push(((address >> shift) & 0xffffn).toString(16).padStart(4, "0"));
105
+ }
106
+
107
+ return words.join(":");
108
+ }
109
+
103
110
  export function normalizeCIDR(address) {
104
111
  let [prefix, prefixLength] = address.split(/\//);
105
112
 
@@ -113,9 +120,12 @@ export function normalizeCIDR(address) {
113
120
  n = n & (0xffffffff << (32 - prefixLength));
114
121
  prefix = decodeIPv4(n, prefixLength);
115
122
  } else {
116
- prefix = normalizeIPAddress(prefix);
117
- const parts = prefix.split(/\:/);
118
- prefix = parts.slice(0, prefixLength / 16).join(":");
123
+ let n = encodeIPv6(prefix);
124
+ n =
125
+ n &
126
+ (0xffffffffffffffffffffffffffffffffn <<
127
+ (128n - BigInt(prefixLength)));
128
+ prefix = decodeIPv6(n, prefixLength);
119
129
  }
120
130
  } else {
121
131
  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;