pmcf 1.102.1 → 1.102.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.102.1",
3
+ "version": "1.102.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/utils.mjs CHANGED
@@ -79,7 +79,12 @@ export function asIterator(value) {
79
79
  }
80
80
 
81
81
  export function isIPv4Address(address) {
82
- return address.indexOf(".") >= 0;
82
+ switch (typeof address) {
83
+ case "string":
84
+ return address.indexOf(".") >= 0;
85
+ }
86
+
87
+ return false;
83
88
  }
84
89
 
85
90
  export function generateEU64(mac) {
@@ -123,6 +128,7 @@ const ipv4 = {
123
128
  };
124
129
  const ipv6 = {
125
130
  separator: ":",
131
+ compressor: "::",
126
132
  length: 128,
127
133
  segmentLength: 16,
128
134
  segmentMask: 0xffffn,
@@ -132,22 +138,44 @@ const ipv6 = {
132
138
  };
133
139
 
134
140
  function _decode(definition, address, length = definition.length) {
135
- const words = [];
141
+ let result = "";
142
+ let compressed = 0;
136
143
  let shift = definition.length;
144
+ let j, word;
145
+ const last = length / definition.segmentLength;
146
+
147
+ for (let i = 0; i < last; i = j + 1) {
148
+ for (j = i; j < last; j++) {
149
+ shift -= definition.segmentLength;
150
+ word = (address >> BigInt(shift)) & definition.segmentMask;
137
151
 
138
- for (let i = 0; i < length / definition.segmentLength; i++) {
139
- shift -= definition.segmentLength;
140
- words.push(
141
- ((address >> BigInt(shift)) & definition.segmentMask)
142
- .toString(definition.base)
143
- .padStart(definition.pad, "0")
144
- );
152
+ if (word !== 0n || !definition.compressor || compressed > 0) {
153
+ break;
154
+ }
155
+ }
156
+
157
+ if (j > i + 1) {
158
+ compressed++;
159
+ result += definition.compressor;
160
+ } else {
161
+ if (result.length > 0) {
162
+ result += definition.separator;
163
+ }
164
+ }
165
+
166
+ if (j < last) {
167
+ result += word.toString(definition.base).padStart(definition.pad, "0");
168
+ }
145
169
  }
146
170
 
147
- return words.join(definition.separator);
171
+ return result;
148
172
  }
149
173
 
150
174
  export function _encode(definition, address) {
175
+ if (typeof address !== "string") {
176
+ return address;
177
+ }
178
+
151
179
  let res = 0n;
152
180
  let shift = BigInt(definition.length);
153
181
 
package/types/utils.d.mts CHANGED
@@ -11,13 +11,13 @@ export function isIPv6Address(address: any): boolean;
11
11
  export function isLinkLocal(address: any): any;
12
12
  export function isLocalhost(address: any): boolean;
13
13
  export function normalizeIPAddress(address: any): any;
14
- export function _encode(definition: any, address: any): bigint;
14
+ export function _encode(definition: any, address: any): any;
15
15
  export function decodeIPv6(address: any, length: any): string;
16
- export function encodeIPv6(address: any): bigint;
16
+ export function encodeIPv6(address: any): any;
17
17
  export function decodeIPv4(address: any, length: any): string;
18
- export function encodeIPv4(address: any): bigint;
18
+ export function encodeIPv4(address: any): any;
19
19
  export function decodeIP(address: any, length: any): string;
20
- export function encodeIP(address: any): bigint;
20
+ export function encodeIP(address: any): any;
21
21
  export function formatCIDR(address: any, subnet: any): any;
22
22
  export function normalizeCIDR(address: any): {
23
23
  prefix?: undefined;
@@ -29,7 +29,7 @@ export function normalizeCIDR(address: any): {
29
29
  cidr: string;
30
30
  };
31
31
  export function hasWellKnownSubnet(address: any): any;
32
- export const IPV4_LOCALHOST: bigint;
33
- export const IPV6_LOCALHOST: bigint;
34
- export const IPV6_LINK_LOCAL_BROADCAST: bigint;
35
- export const IPV6_ROUTER_BROADCAST: bigint;
32
+ export const IPV4_LOCALHOST: any;
33
+ export const IPV6_LOCALHOST: any;
34
+ export const IPV6_LINK_LOCAL_BROADCAST: any;
35
+ export const IPV6_ROUTER_BROADCAST: any;