@utilix-tech/sdk 0.27.0 → 0.29.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.
@@ -1777,6 +1777,94 @@ function buildCacheControl(options = {}) {
1777
1777
  const snippet = `Cache-Control: ${header}`;
1778
1778
  return { header, headerName: "Cache-Control", snippet, directives, warnings };
1779
1779
  }
1780
+ function isValidIpv6HexGroup(g) {
1781
+ return /^[0-9a-fA-F]{1,4}$/.test(g);
1782
+ }
1783
+ function isValidIpv6Ipv4Quad(quad) {
1784
+ const parts = quad.split(".");
1785
+ if (parts.length !== 4) return false;
1786
+ return parts.every((p) => /^\d{1,3}$/.test(p) && Number(p) <= 255);
1787
+ }
1788
+ function classifyIpv6(groups) {
1789
+ const first = parseInt(groups[0], 16);
1790
+ if (groups.every((g) => g === "0000")) return "unspecified";
1791
+ if (groups.slice(0, 7).every((g) => g === "0000") && groups[7] === "0001") return "loopback";
1792
+ if (groups.slice(0, 4).every((g) => g === "0000") && groups[4] === "0000" && groups[5] === "ffff") return "ipv4-mapped";
1793
+ if (groups[0] === "2001" && groups[1] === "0db8") return "documentation";
1794
+ if ((first & 65280) === 65280) return "multicast";
1795
+ if ((first & 65472) === 65152) return "link-local";
1796
+ if ((first & 65024) === 64512) return "unique-local";
1797
+ return "global-unicast";
1798
+ }
1799
+ function compressIpv6Groups(groups) {
1800
+ const short = groups.map((g) => g.replace(/^0+(?=.)/, ""));
1801
+ let bestStart = -1;
1802
+ let bestLen = 0;
1803
+ let curStart = -1;
1804
+ let curLen = 0;
1805
+ for (let i = 0; i < short.length; i++) {
1806
+ if (short[i] === "0") {
1807
+ if (curStart === -1) curStart = i;
1808
+ curLen++;
1809
+ if (curLen > bestLen) {
1810
+ bestLen = curLen;
1811
+ bestStart = curStart;
1812
+ }
1813
+ } else {
1814
+ curStart = -1;
1815
+ curLen = 0;
1816
+ }
1817
+ }
1818
+ if (bestLen < 2) return short.join(":");
1819
+ const before = short.slice(0, bestStart).join(":");
1820
+ const after = short.slice(bestStart + bestLen).join(":");
1821
+ return `${before}::${after}`;
1822
+ }
1823
+ function parseIpv6Address(input) {
1824
+ let s = input.trim();
1825
+ if (s.startsWith("[") && s.includes("]")) s = s.slice(1, s.indexOf("]"));
1826
+ let zoneId = null;
1827
+ const pctIdx = s.indexOf("%");
1828
+ if (pctIdx !== -1) {
1829
+ zoneId = s.slice(pctIdx + 1);
1830
+ s = s.slice(0, pctIdx);
1831
+ }
1832
+ if (!s) return { error: "Empty address" };
1833
+ const doubleColonCount = (s.match(/::/g) ?? []).length;
1834
+ if (doubleColonCount > 1) return { error: 'Address contains more than one "::"' };
1835
+ const ipv4Match = s.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
1836
+ if (ipv4Match) {
1837
+ const quad = ipv4Match[1];
1838
+ if (!isValidIpv6Ipv4Quad(quad)) return { error: `Invalid embedded IPv4 address: ${quad}` };
1839
+ const parts = quad.split(".").map(Number);
1840
+ const hi = (parts[0] << 8 | parts[1]).toString(16);
1841
+ const lo = (parts[2] << 8 | parts[3]).toString(16);
1842
+ s = s.slice(0, s.length - quad.length) + `${hi}:${lo}`;
1843
+ }
1844
+ let groups;
1845
+ if (s.includes("::")) {
1846
+ const [left, right] = s.split("::");
1847
+ const leftGroups = left ? left.split(":") : [];
1848
+ const rightGroups = right ? right.split(":") : [];
1849
+ const missing = 8 - (leftGroups.length + rightGroups.length);
1850
+ if (missing < 1) return { error: 'The "::" shorthand must represent at least one group of zeros' };
1851
+ if (![...leftGroups, ...rightGroups].every(isValidIpv6HexGroup)) return { error: "Invalid hex group in address" };
1852
+ groups = [...leftGroups, ...Array(missing).fill("0"), ...rightGroups];
1853
+ } else {
1854
+ groups = s.split(":");
1855
+ if (groups.length !== 8) return { error: `Expected 8 groups, got ${groups.length}` };
1856
+ if (!groups.every(isValidIpv6HexGroup)) return { error: "Invalid hex group in address" };
1857
+ }
1858
+ const expandedGroups = groups.map((g) => g.padStart(4, "0").toLowerCase());
1859
+ const suffix = zoneId ? `%${zoneId}` : "";
1860
+ return {
1861
+ expanded: expandedGroups.join(":") + suffix,
1862
+ compressed: compressIpv6Groups(expandedGroups) + suffix,
1863
+ groups: expandedGroups,
1864
+ zoneId,
1865
+ addressType: classifyIpv6(expandedGroups)
1866
+ };
1867
+ }
1780
1868
 
1781
1869
  exports.DNS_RECORD_TYPES = DNS_RECORD_TYPES;
1782
1870
  exports.HTTP_HEADERS = HTTP_HEADERS;
@@ -1802,6 +1890,7 @@ exports.isValidIpv6 = isValidIpv6;
1802
1890
  exports.parseDnsResponse = parseDnsResponse;
1803
1891
  exports.parseGeoResponse = parseGeoResponse;
1804
1892
  exports.parseHar = parseHar;
1893
+ exports.parseIpv6Address = parseIpv6Address;
1805
1894
  exports.parseUserAgent = parseUserAgent;
1806
1895
  exports.searchHeaders = searchHeaders;
1807
1896
  exports.searchStatusCodes = searchStatusCodes;
@@ -1 +1 @@
1
- export { C as CacheControlDirective, a as CacheControlOptions, b as CacheControlResult, D as DNS_RECORD_TYPES, c as DnsRecord, d as DnsRecordType, e as DnsResponse, G as GeoResult, H as HTTP_HEADERS, f as HarEntry, g as HarParseResult, h as HarSummary, i as HeaderCategory, j as HttpHeader, P as ParsedDnsResult, k as ParsedGeoResult, R as RobotsGroup, l as RobotsIssue, m as RobotsRule, o as RobotsValidationResult, S as STATUS_CODES, p as SitemapIndexEntry, q as SitemapIssue, r as SitemapUrlEntry, s as SitemapValidationResult, t as StatusCode, U as UaDeviceType, u as UserAgentInfo, v as buildCacheControl, w as buildDnsQueryUrl, x as buildGeoUrl, y as buildMapUrl, z as countryCodeToFlag, A as formatCoordinates, B as formatTtl, E as getByCategory, F as getHeader, I as getHeadersByCategory, J as getStatusByCategory, K as getStatusCode, L as isClientError, M as isServerError, N as isSuccess, O as isValidIp, Q as isValidIpv4, T as isValidIpv6, V as parseDnsResponse, W as parseGeoResponse, X as parseHar, Y as parseUserAgent, Z as searchHeaders, _ as searchStatusCodes, $ as statusCodeToText, a0 as typeNumberToLabel, a1 as validateDomain, a2 as validateHeaderName, a3 as validateHeaderValue, a4 as validateRobotsTxt, a5 as validateSitemap } from '../network-BJOjJnmY.cjs';
1
+ export { C as CacheControlDirective, a as CacheControlOptions, b as CacheControlResult, D as DNS_RECORD_TYPES, c as DnsRecord, d as DnsRecordType, e as DnsResponse, G as GeoResult, H as HTTP_HEADERS, f as HarEntry, g as HarParseResult, h as HarSummary, i as HeaderCategory, j as HttpHeader, I as Ipv6AddressType, k as Ipv6ParseResult, P as ParsedDnsResult, l as ParsedGeoResult, R as RobotsGroup, m as RobotsIssue, o as RobotsRule, p as RobotsValidationResult, S as STATUS_CODES, q as SitemapIndexEntry, r as SitemapIssue, s as SitemapUrlEntry, t as SitemapValidationResult, u as StatusCode, U as UaDeviceType, v as UserAgentInfo, w as buildCacheControl, x as buildDnsQueryUrl, y as buildGeoUrl, z as buildMapUrl, A as countryCodeToFlag, B as formatCoordinates, E as formatTtl, F as getByCategory, J as getHeader, K as getHeadersByCategory, L as getStatusByCategory, M as getStatusCode, N as isClientError, O as isServerError, Q as isSuccess, T as isValidIp, V as isValidIpv4, W as isValidIpv6, X as parseDnsResponse, Y as parseGeoResponse, Z as parseHar, _ as parseIpv6Address, $ as parseUserAgent, a0 as searchHeaders, a1 as searchStatusCodes, a2 as statusCodeToText, a3 as typeNumberToLabel, a4 as validateDomain, a5 as validateHeaderName, a6 as validateHeaderValue, a7 as validateRobotsTxt, a8 as validateSitemap } from '../network-D7Epuerc.cjs';
@@ -1 +1 @@
1
- export { C as CacheControlDirective, a as CacheControlOptions, b as CacheControlResult, D as DNS_RECORD_TYPES, c as DnsRecord, d as DnsRecordType, e as DnsResponse, G as GeoResult, H as HTTP_HEADERS, f as HarEntry, g as HarParseResult, h as HarSummary, i as HeaderCategory, j as HttpHeader, P as ParsedDnsResult, k as ParsedGeoResult, R as RobotsGroup, l as RobotsIssue, m as RobotsRule, o as RobotsValidationResult, S as STATUS_CODES, p as SitemapIndexEntry, q as SitemapIssue, r as SitemapUrlEntry, s as SitemapValidationResult, t as StatusCode, U as UaDeviceType, u as UserAgentInfo, v as buildCacheControl, w as buildDnsQueryUrl, x as buildGeoUrl, y as buildMapUrl, z as countryCodeToFlag, A as formatCoordinates, B as formatTtl, E as getByCategory, F as getHeader, I as getHeadersByCategory, J as getStatusByCategory, K as getStatusCode, L as isClientError, M as isServerError, N as isSuccess, O as isValidIp, Q as isValidIpv4, T as isValidIpv6, V as parseDnsResponse, W as parseGeoResponse, X as parseHar, Y as parseUserAgent, Z as searchHeaders, _ as searchStatusCodes, $ as statusCodeToText, a0 as typeNumberToLabel, a1 as validateDomain, a2 as validateHeaderName, a3 as validateHeaderValue, a4 as validateRobotsTxt, a5 as validateSitemap } from '../network-BJOjJnmY.js';
1
+ export { C as CacheControlDirective, a as CacheControlOptions, b as CacheControlResult, D as DNS_RECORD_TYPES, c as DnsRecord, d as DnsRecordType, e as DnsResponse, G as GeoResult, H as HTTP_HEADERS, f as HarEntry, g as HarParseResult, h as HarSummary, i as HeaderCategory, j as HttpHeader, I as Ipv6AddressType, k as Ipv6ParseResult, P as ParsedDnsResult, l as ParsedGeoResult, R as RobotsGroup, m as RobotsIssue, o as RobotsRule, p as RobotsValidationResult, S as STATUS_CODES, q as SitemapIndexEntry, r as SitemapIssue, s as SitemapUrlEntry, t as SitemapValidationResult, u as StatusCode, U as UaDeviceType, v as UserAgentInfo, w as buildCacheControl, x as buildDnsQueryUrl, y as buildGeoUrl, z as buildMapUrl, A as countryCodeToFlag, B as formatCoordinates, E as formatTtl, F as getByCategory, J as getHeader, K as getHeadersByCategory, L as getStatusByCategory, M as getStatusCode, N as isClientError, O as isServerError, Q as isSuccess, T as isValidIp, V as isValidIpv4, W as isValidIpv6, X as parseDnsResponse, Y as parseGeoResponse, Z as parseHar, _ as parseIpv6Address, $ as parseUserAgent, a0 as searchHeaders, a1 as searchStatusCodes, a2 as statusCodeToText, a3 as typeNumberToLabel, a4 as validateDomain, a5 as validateHeaderName, a6 as validateHeaderValue, a7 as validateRobotsTxt, a8 as validateSitemap } from '../network-D7Epuerc.js';
@@ -1,2 +1,2 @@
1
- export { DNS_RECORD_TYPES, HTTP_HEADERS, STATUS_CODES, buildCacheControl, buildDnsQueryUrl, buildGeoUrl, buildMapUrl, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, parseDnsResponse, parseGeoResponse, parseHar, parseUserAgent, searchHeaders, searchStatusCodes, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue, validateRobotsTxt, validateSitemap } from '../chunk-Y5OOP6WN.js';
1
+ export { DNS_RECORD_TYPES, HTTP_HEADERS, STATUS_CODES, buildCacheControl, buildDnsQueryUrl, buildGeoUrl, buildMapUrl, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, parseDnsResponse, parseGeoResponse, parseHar, parseIpv6Address, parseUserAgent, searchHeaders, searchStatusCodes, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue, validateRobotsTxt, validateSitemap } from '../chunk-CSNTHZHF.js';
2
2
  import '../chunk-MLKGABMK.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utilix-tech/sdk",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "description": "154+ developer utility tools for Node.js: JSON, encoding, hashing, color, CSS, network and more. Runs locally, no API key required.",
5
5
  "author": "Utilix <hello@utilix.tech>",
6
6
  "license": "MIT",