ip-utilties 3.4.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 +3 -3
- package/src/ip.mjs +41 -4
- package/types/ip.d.mts +3 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ip-utilties",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
7
7
|
},
|
|
8
|
-
"packageManager": "npm@11.
|
|
8
|
+
"packageManager": "npm@11.18.0",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"default": "./src/ip.mjs"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"ava": "^8.0.1",
|
|
44
|
-
"browser-ava": "^2.3.
|
|
44
|
+
"browser-ava": "^2.3.65",
|
|
45
45
|
"c8": "^11.0.0",
|
|
46
46
|
"documentation": "^14.0.3",
|
|
47
47
|
"semantic-release": "^25.0.5",
|
package/src/ip.mjs
CHANGED
|
@@ -21,7 +21,12 @@ const ipv4 = {
|
|
|
21
21
|
linkLocalPrefix: new Uint8Array([169, 254]),
|
|
22
22
|
linkLocalPrefixLength: 16,
|
|
23
23
|
localHost: new Uint8Array([127, 0, 0, 1]),
|
|
24
|
-
localHostPrefixLenth: 8
|
|
24
|
+
localHostPrefixLenth: 8,
|
|
25
|
+
wellKnownClasses: [
|
|
26
|
+
[new Uint8Array([10]), 8],
|
|
27
|
+
[new Uint8Array([172, 16]), 16],
|
|
28
|
+
[new Uint8Array([192, 168]), 24]
|
|
29
|
+
]
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
const ipv6 = {
|
|
@@ -266,7 +271,7 @@ export function normalizeCIDR(address) {
|
|
|
266
271
|
const n = _prefix(family, address, prefixLength);
|
|
267
272
|
prefix = _decode(family, n, prefixLength);
|
|
268
273
|
|
|
269
|
-
if (family
|
|
274
|
+
if (family === ipv6) {
|
|
270
275
|
if (!prefix.endsWith("::")) {
|
|
271
276
|
// TODO
|
|
272
277
|
prefix += prefix.endsWith(":") ? ":" : "::";
|
|
@@ -346,7 +351,6 @@ export function isLocalhost(address) {
|
|
|
346
351
|
if (family) {
|
|
347
352
|
return _equal(family.localHost, _encode(family, address));
|
|
348
353
|
}
|
|
349
|
-
|
|
350
354
|
return false;
|
|
351
355
|
}
|
|
352
356
|
|
|
@@ -367,8 +371,41 @@ export function isUniqueLocal(address) {
|
|
|
367
371
|
return eaddr?.[0] >> 9 === 126 ? true : false;
|
|
368
372
|
}
|
|
369
373
|
|
|
374
|
+
export function _isUniqueLocal(eaddr) {
|
|
375
|
+
return eaddr?.[0] >> 9 === 126 ? true : false;
|
|
376
|
+
}
|
|
377
|
+
|
|
370
378
|
export function hasWellKnownSubnet(address) {
|
|
371
|
-
return
|
|
379
|
+
return wellKnownSubnet(address) !== undefined;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function wellKnownSubnet(address) {
|
|
383
|
+
const family = _family(address);
|
|
384
|
+
if (family) {
|
|
385
|
+
return _wellKnownSubnet(family, address);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function _wellKnownSubnet(family, address) {
|
|
390
|
+
const encoded = _encode(family, address);
|
|
391
|
+
|
|
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;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
372
409
|
}
|
|
373
410
|
|
|
374
411
|
/*
|
package/types/ip.d.mts
CHANGED
|
@@ -44,7 +44,10 @@ export function isLocalhost(address: any): boolean;
|
|
|
44
44
|
export function isLinkLocal(address: any): boolean;
|
|
45
45
|
export function _isLinkLocal(family: any, address: any): boolean;
|
|
46
46
|
export function isUniqueLocal(address: any): boolean;
|
|
47
|
+
export function _isUniqueLocal(eaddr: any): boolean;
|
|
47
48
|
export function hasWellKnownSubnet(address: any): boolean;
|
|
49
|
+
export function wellKnownSubnet(address: any): any;
|
|
50
|
+
export function _wellKnownSubnet(family: any, address: any): any;
|
|
48
51
|
/**
|
|
49
52
|
* Address familiy IPv4
|
|
50
53
|
*/
|