ip-utilties 3.4.0 → 3.5.0

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,11 +1,11 @@
1
1
  {
2
2
  "name": "ip-utilties",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
7
7
  },
8
- "packageManager": "npm@11.16.0",
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.64",
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,8 @@ 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: [[new Uint8Array([192, 168]), 8]]
25
26
  };
26
27
 
27
28
  const ipv6 = {
@@ -266,7 +267,7 @@ export function normalizeCIDR(address) {
266
267
  const n = _prefix(family, address, prefixLength);
267
268
  prefix = _decode(family, n, prefixLength);
268
269
 
269
- if (family == ipv6) {
270
+ if (family === ipv6) {
270
271
  if (!prefix.endsWith("::")) {
271
272
  // TODO
272
273
  prefix += prefix.endsWith(":") ? ":" : "::";
@@ -346,7 +347,6 @@ export function isLocalhost(address) {
346
347
  if (family) {
347
348
  return _equal(family.localHost, _encode(family, address));
348
349
  }
349
-
350
350
  return false;
351
351
  }
352
352
 
@@ -367,8 +367,39 @@ export function isUniqueLocal(address) {
367
367
  return eaddr?.[0] >> 9 === 126 ? true : false;
368
368
  }
369
369
 
370
+ export function _isUniqueLocal(eaddr) {
371
+ return eaddr?.[0] >> 9 === 126 ? true : false;
372
+ }
373
+
370
374
  export function hasWellKnownSubnet(address) {
371
- return isLocalhost(address) || isLinkLocal(address) || isUniqueLocal(address);
375
+ return wellKnownSubnet(address) !== undefined;
376
+ }
377
+
378
+ export function wellKnownSubnet(address) {
379
+ const family = _family(address);
380
+ if (family) {
381
+ const encoded = _encode(family, address);
382
+
383
+ if (_equal(family.localHost, encoded)) {
384
+ return [family.localHost, family.localHostPrefixLenth];
385
+ }
386
+ if (_equal(family.linkLocalPrefix, encoded)) {
387
+ return [family.linkLocalPrefix, family.linkLocalPrefixLength];
388
+ }
389
+ if (_isUniqueLocal(encoded)) {
390
+ return [encoded[0], 64];
391
+ }
392
+
393
+ if (family === ipv4) {
394
+ for (const c of family.wellKnownClasses) {
395
+ if (_equal(c[0], encoded)) {
396
+ return c;
397
+ }
398
+ }
399
+ }
400
+ }
401
+
402
+ return undefined;
372
403
  }
373
404
 
374
405
  /*
package/types/ip.d.mts CHANGED
@@ -44,7 +44,9 @@ 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[] | undefined;
48
50
  /**
49
51
  * Address familiy IPv4
50
52
  */