ip-utilties 3.5.0 → 3.5.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 +1 -1
- package/src/ip.mjs +24 -18
- package/types/ip.d.mts +2 -1
package/package.json
CHANGED
package/src/ip.mjs
CHANGED
|
@@ -22,7 +22,11 @@ const ipv4 = {
|
|
|
22
22
|
linkLocalPrefixLength: 16,
|
|
23
23
|
localHost: new Uint8Array([127, 0, 0, 1]),
|
|
24
24
|
localHostPrefixLenth: 8,
|
|
25
|
-
wellKnownClasses: [
|
|
25
|
+
wellKnownClasses: [
|
|
26
|
+
[new Uint8Array([10]), 8],
|
|
27
|
+
[new Uint8Array([172, 16]), 16],
|
|
28
|
+
[new Uint8Array([192, 168]), 24]
|
|
29
|
+
]
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
const ipv6 = {
|
|
@@ -378,28 +382,30 @@ export function hasWellKnownSubnet(address) {
|
|
|
378
382
|
export function wellKnownSubnet(address) {
|
|
379
383
|
const family = _family(address);
|
|
380
384
|
if (family) {
|
|
381
|
-
|
|
385
|
+
return _wellKnownSubnet(family, address);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
382
388
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
if (_equal(family.linkLocalPrefix, encoded)) {
|
|
387
|
-
return [family.linkLocalPrefix, family.linkLocalPrefixLength];
|
|
388
|
-
}
|
|
389
|
-
if (_isUniqueLocal(encoded)) {
|
|
390
|
-
return [encoded[0], 64];
|
|
391
|
-
}
|
|
389
|
+
export function _wellKnownSubnet(family, address) {
|
|
390
|
+
const encoded = _encode(family, address);
|
|
392
391
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
392
|
+
if (_equal(family.localHost, encoded)) {
|
|
393
|
+
return [family.localHost, family.localHostPrefixLenth];
|
|
394
|
+
}
|
|
395
|
+
if (_equal(family.linkLocalPrefix, encoded)) {
|
|
396
|
+
return [family.linkLocalPrefix, family.linkLocalPrefixLength];
|
|
397
|
+
}
|
|
398
|
+
if (_isUniqueLocal(encoded)) {
|
|
399
|
+
return [encoded[0], 64];
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (family === ipv4) {
|
|
403
|
+
for (const c of family.wellKnownClasses) {
|
|
404
|
+
if (_equal(c[0], encoded)) {
|
|
405
|
+
return c;
|
|
398
406
|
}
|
|
399
407
|
}
|
|
400
408
|
}
|
|
401
|
-
|
|
402
|
-
return undefined;
|
|
403
409
|
}
|
|
404
410
|
|
|
405
411
|
/*
|
package/types/ip.d.mts
CHANGED
|
@@ -46,7 +46,8 @@ export function _isLinkLocal(family: any, address: any): boolean;
|
|
|
46
46
|
export function isUniqueLocal(address: any): boolean;
|
|
47
47
|
export function _isUniqueLocal(eaddr: any): boolean;
|
|
48
48
|
export function hasWellKnownSubnet(address: any): boolean;
|
|
49
|
-
export function wellKnownSubnet(address: any): any
|
|
49
|
+
export function wellKnownSubnet(address: any): any;
|
|
50
|
+
export function _wellKnownSubnet(family: any, address: any): any;
|
|
50
51
|
/**
|
|
51
52
|
* Address familiy IPv4
|
|
52
53
|
*/
|