ip-utilties 3.7.1 → 3.7.3
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 +4 -9
- package/src/ip.mjs +9 -28
- package/types/ip.d.mts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ip-utilties",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -42,17 +42,12 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"ava": "^8.0.1",
|
|
45
|
-
"browser-ava": "^2.3.
|
|
46
|
-
"c8": "^
|
|
45
|
+
"browser-ava": "^2.3.69",
|
|
46
|
+
"c8": "^12.0.0",
|
|
47
47
|
"documentation": "^14.0.3",
|
|
48
|
-
"semantic-release": "^25.0.
|
|
48
|
+
"semantic-release": "^25.0.8",
|
|
49
49
|
"typescript": "^7.0.2"
|
|
50
50
|
},
|
|
51
|
-
"overrides": {
|
|
52
|
-
"c8": {
|
|
53
|
-
"yargs": "^18.0.0"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
51
|
"engines": {
|
|
57
52
|
"node": ">=26.4.0"
|
|
58
53
|
},
|
package/src/ip.mjs
CHANGED
|
@@ -19,7 +19,6 @@ const ipv4 = {
|
|
|
19
19
|
segmentMask: 0xffn,
|
|
20
20
|
base: 10,
|
|
21
21
|
localHost: new Uint8Array([127, 0, 0, 1]),
|
|
22
|
-
localHostPrefixLenth: 8,
|
|
23
22
|
|
|
24
23
|
// https://www.geeksforgeeks.org/computer-networks/subnet-cheat-sheet/
|
|
25
24
|
wellKnownAddresses: [
|
|
@@ -63,7 +62,6 @@ const ipv6 = {
|
|
|
63
62
|
segmentMask: 0xffffn,
|
|
64
63
|
base: 16,
|
|
65
64
|
localHost: new Uint16Array([0, 0, 0, 0, 0, 0, 0, 1]),
|
|
66
|
-
localHostPrefixLenth: 128,
|
|
67
65
|
wellKnownAddresses: [
|
|
68
66
|
[new Uint16Array([0xfe80, 0, 0, 0, 0, 0, 0, 0]), 64, 64, true],
|
|
69
67
|
[new Uint16Array([0xfd00, 0, 0, 0, 0, 0, 0, 0]), 8, 64, false, true],
|
|
@@ -298,8 +296,9 @@ export function normalizeCIDR(address) {
|
|
|
298
296
|
let encoded = _encode(family, prefix);
|
|
299
297
|
const wns = _wellKnownSubnet(family, encoded);
|
|
300
298
|
|
|
301
|
-
if (wns
|
|
302
|
-
prefixLength = wns[2];
|
|
299
|
+
if (wns) {
|
|
300
|
+
prefixLength = prefixLength === undefined ? wns[2] : parseInt(prefixLength);
|
|
301
|
+
|
|
303
302
|
prefix = _decode(
|
|
304
303
|
family,
|
|
305
304
|
_prefix(family, encoded, prefixLength),
|
|
@@ -307,31 +306,13 @@ export function normalizeCIDR(address) {
|
|
|
307
306
|
);
|
|
308
307
|
longPrefix = _decode(family, wns[0]);
|
|
309
308
|
} else {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (family === ipv6) {
|
|
316
|
-
if (!prefix.endsWith("::")) {
|
|
317
|
-
// TODO
|
|
318
|
-
prefix += prefix.endsWith(":") ? ":" : "::";
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
longPrefix = prefix;
|
|
322
|
-
} else {
|
|
323
|
-
prefixLength = prefixLength === undefined ? 0 : parseInt(prefixLength);
|
|
324
|
-
|
|
325
|
-
if (prefixLength) {
|
|
326
|
-
encoded = _prefix(family, prefix, prefixLength);
|
|
327
|
-
} else {
|
|
328
|
-
if (_isLocalhost(family, encoded)) {
|
|
329
|
-
prefixLength = family.localHostPrefixLenth;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
prefix = _decode(family, encoded, prefixLength);
|
|
333
|
-
longPrefix = _decode(family, encoded);
|
|
309
|
+
prefixLength = prefixLength === undefined ? 0 : parseInt(prefixLength);
|
|
310
|
+
|
|
311
|
+
if (prefixLength) {
|
|
312
|
+
encoded = _prefix(family, prefix, prefixLength);
|
|
334
313
|
}
|
|
314
|
+
prefix = _decode(family, encoded, prefixLength);
|
|
315
|
+
longPrefix = _decode(family, encoded);
|
|
335
316
|
}
|
|
336
317
|
|
|
337
318
|
return {
|
package/types/ip.d.mts
CHANGED
|
@@ -41,7 +41,7 @@ export declare function prefixOnlyIP(address: any, length: any): string;
|
|
|
41
41
|
export declare function rangeIP(address: any, prefix: any, lowerAdd?: number, upperReduce?: number): any[];
|
|
42
42
|
export declare function matchPrefixIP(prefix: any, length: any, address: any): boolean;
|
|
43
43
|
export declare function normalizeCIDR(address: any): {
|
|
44
|
-
longPrefix:
|
|
44
|
+
longPrefix: string;
|
|
45
45
|
prefix: any;
|
|
46
46
|
prefixLength: any;
|
|
47
47
|
cidr: string;
|