@utilix-tech/sdk 0.46.0 → 0.48.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/CHANGELOG.md +8 -0
- package/README.md +35 -10
- package/dist/{chunk-L6V4W4SU.js → chunk-226EH3ZI.js} +87 -1
- package/dist/{chunk-JR354NH4.js → chunk-4TIY6COQ.js} +64 -1
- package/dist/{chunk-7PEKYLRB.js → chunk-Y7YY733Z.js} +98 -1
- package/dist/{data-BKpEOcOX.d.ts → data-BJVJ879p.d.cts} +30 -2
- package/dist/{data-BKpEOcOX.d.cts → data-BJVJ879p.d.ts} +30 -2
- package/dist/index.cjs +253 -7
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/{media-fD8dJ5qR.d.cts → media-BUvwm4wU.d.cts} +27 -2
- package/dist/{media-fD8dJ5qR.d.ts → media-BUvwm4wU.d.ts} +27 -2
- package/dist/{network-Bzm1tjMA.d.cts → network-DelcJeJa.d.cts} +70 -2
- package/dist/{network-Bzm1tjMA.d.ts → network-DelcJeJa.d.ts} +70 -2
- package/dist/tools/data.cjs +63 -0
- package/dist/tools/data.d.cts +1 -1
- package/dist/tools/data.d.ts +1 -1
- package/dist/tools/data.js +1 -1
- package/dist/tools/media.cjs +86 -0
- package/dist/tools/media.d.cts +1 -1
- package/dist/tools/media.d.ts +1 -1
- package/dist/tools/media.js +1 -1
- package/dist/tools/network.cjs +97 -0
- package/dist/tools/network.d.cts +1 -1
- package/dist/tools/network.d.ts +1 -1
- package/dist/tools/network.js +1 -1
- package/package.json +1 -1
package/dist/tools/network.cjs
CHANGED
|
@@ -1497,6 +1497,53 @@ function validateSitemap(xml) {
|
|
|
1497
1497
|
const valid = !issues.some((i) => i.severity === "error");
|
|
1498
1498
|
return { type, urlCount: entries.length, entries, issues, valid };
|
|
1499
1499
|
}
|
|
1500
|
+
var SITEMAP_SPLITTER_MAX_URLS_PER_FILE = 5e4;
|
|
1501
|
+
function escapeXmlUrl(url) {
|
|
1502
|
+
return url.replace(/&(?!amp;|lt;|gt;|apos;|quot;|#\d+;)/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1503
|
+
}
|
|
1504
|
+
function splitSitemap(urlsText, options) {
|
|
1505
|
+
const urls = (urlsText ?? "").split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
1506
|
+
if (urls.length === 0) return { error: "No URLs provided" };
|
|
1507
|
+
for (let i = 0; i < urls.length; i++) {
|
|
1508
|
+
if (!/^https?:\/\//i.test(urls[i])) {
|
|
1509
|
+
return { error: `Line ${i + 1}: "${urls[i]}" is not an absolute URL starting with http:// or https://` };
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
if (!options || !/^https?:\/\//i.test(options.baseUrl ?? "")) {
|
|
1513
|
+
return { error: "baseUrl must be an absolute URL starting with http:// or https://" };
|
|
1514
|
+
}
|
|
1515
|
+
const baseUrl = options.baseUrl.replace(/\/+$/, "") + "/";
|
|
1516
|
+
let urlsPerFile = options.urlsPerFile ?? SITEMAP_SPLITTER_MAX_URLS_PER_FILE;
|
|
1517
|
+
if (urlsPerFile <= 0) urlsPerFile = SITEMAP_SPLITTER_MAX_URLS_PER_FILE;
|
|
1518
|
+
if (urlsPerFile > SITEMAP_SPLITTER_MAX_URLS_PER_FILE) urlsPerFile = SITEMAP_SPLITTER_MAX_URLS_PER_FILE;
|
|
1519
|
+
const filePrefix = (options.filePrefix || "sitemap").replace(/[^A-Za-z0-9_-]/g, "");
|
|
1520
|
+
const files = [];
|
|
1521
|
+
for (let i = 0; i < urls.length; i += urlsPerFile) {
|
|
1522
|
+
const chunk = urls.slice(i, i + urlsPerFile);
|
|
1523
|
+
const fileIndex = files.length + 1;
|
|
1524
|
+
const filename = `${filePrefix}-${fileIndex}.xml`;
|
|
1525
|
+
const urlLines = chunk.map((url) => ` <url>
|
|
1526
|
+
<loc>${escapeXmlUrl(url)}</loc>
|
|
1527
|
+
</url>`).join("\n");
|
|
1528
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
1529
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
1530
|
+
${urlLines}
|
|
1531
|
+
</urlset>
|
|
1532
|
+
`;
|
|
1533
|
+
files.push({ filename, urlCount: chunk.length, xml });
|
|
1534
|
+
}
|
|
1535
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
1536
|
+
const indexEntries = files.map((f) => ` <sitemap>
|
|
1537
|
+
<loc>${escapeXmlUrl(baseUrl + f.filename)}</loc>
|
|
1538
|
+
<lastmod>${today}</lastmod>
|
|
1539
|
+
</sitemap>`).join("\n");
|
|
1540
|
+
const indexXml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
1541
|
+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
1542
|
+
${indexEntries}
|
|
1543
|
+
</sitemapindex>
|
|
1544
|
+
`;
|
|
1545
|
+
return { files, indexXml, totalUrls: urls.length };
|
|
1546
|
+
}
|
|
1500
1547
|
var KNOWN_ROBOTS_DIRECTIVES = /* @__PURE__ */ new Set(["user-agent", "disallow", "allow", "sitemap", "crawl-delay", "host"]);
|
|
1501
1548
|
function validateRobotsTxt(text) {
|
|
1502
1549
|
if (!text || !text.trim()) return { error: "Input is empty" };
|
|
@@ -2623,6 +2670,53 @@ function parseClientHintHeaders(rawHeaders) {
|
|
|
2623
2670
|
}
|
|
2624
2671
|
return { hints, unrecognized };
|
|
2625
2672
|
}
|
|
2673
|
+
function encodeRFC5987ValueChars(value) {
|
|
2674
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (c) => "%" + c.charCodeAt(0).toString(16).toUpperCase());
|
|
2675
|
+
}
|
|
2676
|
+
function buildContentDisposition(options = {}) {
|
|
2677
|
+
const type = options.type ?? "attachment";
|
|
2678
|
+
if (type !== "inline" && type !== "attachment") return { error: 'type must be "inline" or "attachment"' };
|
|
2679
|
+
if (!options.filename) return { header: type, type, filenameEncoded: false };
|
|
2680
|
+
const filename = options.filename;
|
|
2681
|
+
if (filename.includes("/") || filename.includes("\\")) return { error: "filename must not contain path separators" };
|
|
2682
|
+
const isAscii = /^[\x20-\x7e]*$/.test(filename);
|
|
2683
|
+
const asciiFallback = filename.replace(/[^\x20-\x7e]/g, "_").replace(/(["\\])/g, "\\$1");
|
|
2684
|
+
let header = `${type}; filename="${asciiFallback}"`;
|
|
2685
|
+
let filenameEncoded = false;
|
|
2686
|
+
if (!isAscii) {
|
|
2687
|
+
header += `; filename*=UTF-8''${encodeRFC5987ValueChars(filename)}`;
|
|
2688
|
+
filenameEncoded = true;
|
|
2689
|
+
}
|
|
2690
|
+
return { header, type, filename, filenameEncoded };
|
|
2691
|
+
}
|
|
2692
|
+
function parseContentDisposition(header) {
|
|
2693
|
+
if (typeof header !== "string" || header.trim() === "") return { error: "header is required" };
|
|
2694
|
+
const parts = header.split(";").map((p) => p.trim()).filter(Boolean);
|
|
2695
|
+
const type = parts[0]?.toLowerCase();
|
|
2696
|
+
if (!type) return { error: "Could not parse a disposition type from the header" };
|
|
2697
|
+
const params = {};
|
|
2698
|
+
for (let i = 1; i < parts.length; i++) {
|
|
2699
|
+
const eq = parts[i].indexOf("=");
|
|
2700
|
+
if (eq === -1) continue;
|
|
2701
|
+
const key = parts[i].slice(0, eq).trim().toLowerCase();
|
|
2702
|
+
let value = parts[i].slice(eq + 1).trim();
|
|
2703
|
+
if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1).replace(/\\(.)/g, "$1");
|
|
2704
|
+
params[key] = value;
|
|
2705
|
+
}
|
|
2706
|
+
let filename = params.filename;
|
|
2707
|
+
let filenameIsExtended = false;
|
|
2708
|
+
if (params["filename*"]) {
|
|
2709
|
+
const match = params["filename*"].match(/^([^']*)'([^']*)'(.*)$/);
|
|
2710
|
+
if (match) {
|
|
2711
|
+
try {
|
|
2712
|
+
filename = decodeURIComponent(match[3]);
|
|
2713
|
+
filenameIsExtended = true;
|
|
2714
|
+
} catch {
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
return { type, filename, filenameIsExtended, params };
|
|
2719
|
+
}
|
|
2626
2720
|
|
|
2627
2721
|
exports.CLIENT_HINTS = CLIENT_HINTS;
|
|
2628
2722
|
exports.DNS_RECORD_TYPES = DNS_RECORD_TYPES;
|
|
@@ -2634,6 +2728,7 @@ exports.STATUS_CODES = STATUS_CODES;
|
|
|
2634
2728
|
exports.analyzeEmailHeaders = analyzeEmailHeaders;
|
|
2635
2729
|
exports.buildCacheControl = buildCacheControl;
|
|
2636
2730
|
exports.buildClientHints = buildClientHints;
|
|
2731
|
+
exports.buildContentDisposition = buildContentDisposition;
|
|
2637
2732
|
exports.buildDnsQueryUrl = buildDnsQueryUrl;
|
|
2638
2733
|
exports.buildGeoUrl = buildGeoUrl;
|
|
2639
2734
|
exports.buildLinkHeader = buildLinkHeader;
|
|
@@ -2658,6 +2753,7 @@ exports.isValidIp = isValidIp;
|
|
|
2658
2753
|
exports.isValidIpv4 = isValidIpv4;
|
|
2659
2754
|
exports.isValidIpv6 = isValidIpv6;
|
|
2660
2755
|
exports.parseClientHintHeaders = parseClientHintHeaders;
|
|
2756
|
+
exports.parseContentDisposition = parseContentDisposition;
|
|
2661
2757
|
exports.parseContentRangeHeader = parseContentRangeHeader;
|
|
2662
2758
|
exports.parseDnsResponse = parseDnsResponse;
|
|
2663
2759
|
exports.parseGeoResponse = parseGeoResponse;
|
|
@@ -2668,6 +2764,7 @@ exports.parseUserAgent = parseUserAgent;
|
|
|
2668
2764
|
exports.parseVaryHeader = parseVaryHeader;
|
|
2669
2765
|
exports.searchHeaders = searchHeaders;
|
|
2670
2766
|
exports.searchStatusCodes = searchStatusCodes;
|
|
2767
|
+
exports.splitSitemap = splitSitemap;
|
|
2671
2768
|
exports.statusCodeToText = statusCodeToText;
|
|
2672
2769
|
exports.typeNumberToLabel = typeNumberToLabel;
|
|
2673
2770
|
exports.validateDomain = validateDomain;
|
package/dist/tools/network.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AuthResultEntry, B as BuildRangeHeaderOptions, C as CLIENT_HINTS, a as CacheControlDirective, b as CacheControlOptions, c as CacheControlResult, d as ClientHintDef, e as ClientHintValueType, f as ClientHintsBuildResult, g as ClientHintsParseResult, h as
|
|
1
|
+
export { A as AuthResultEntry, B as BuildRangeHeaderOptions, C as CLIENT_HINTS, a as CacheControlDirective, b as CacheControlOptions, c as CacheControlResult, d as ClientHintDef, e as ClientHintValueType, f as ClientHintsBuildResult, g as ClientHintsParseResult, h as ContentDispositionBuildOptions, i as ContentDispositionBuildResult, j as ContentDispositionParseResult, k as ContentRangeResult, l as CookieAttributes, m as CookieCheckResult, D as DNS_RECORD_TYPES, o as DnsRecord, p as DnsRecordType, q as DnsResponse, E as EmailHeaderAnalysis, r as EmailHeaderField, G as GeoResult, H as HTTP_HEADERS, s as HarEntry, t as HarParseResult, u as HarSummary, v as HeaderCategory, w as HttpHeader, I as Ipv6AddressType, x as Ipv6ParseResult, L as LINK_REL_VALUES, y as LinkHeaderEntry, z as LinkHeaderEntryInput, F as LinkHeaderResult, J as LinkRel, M as ManifestIconInfo, K as ManifestIssue, N as ManifestValidationResult, P as PERMISSIONS_POLICY_FEATURES, O as ParsedClientHint, Q as ParsedDnsResult, R as ParsedGeoResult, S as PermissionsPolicyDirective, T as PermissionsPolicyFeatureInput, U as PermissionsPolicyResult, V as REFERRER_POLICY_VALUES, W as RangeEntry, X as RangeEntryInput, Y as RangeHeaderResult, Z as ReceivedHop, _ as ReferrerPolicyEntry, $ as ReferrerPolicyResult, a0 as ReferrerPolicyValue, a1 as RobotsGroup, a2 as RobotsIssue, a3 as RobotsRule, a4 as RobotsValidationResult, a5 as STATUS_CODES, a6 as SameSiteValue, a7 as SitemapIndexEntry, a8 as SitemapIssue, a9 as SitemapSplitFile, aa as SitemapUrlEntry, ab as SitemapValidationResult, ac as SplitSitemapOptions, ad as SplitSitemapResult, ae as StatusCode, af as UaDeviceType, ag as UserAgentInfo, ah as VaryHeaderEntry, ai as VaryHeaderResult, aj as analyzeEmailHeaders, ak as buildCacheControl, al as buildClientHints, am as buildContentDisposition, an as buildDnsQueryUrl, ao as buildGeoUrl, ap as buildLinkHeader, aq as buildMapUrl, ar as buildPermissionsPolicy, as as buildRangeHeader, at as buildReferrerPolicy, au as buildVaryHeader, av as checkSetCookieHeader, aw as countryCodeToFlag, ax as formatCoordinates, ay as formatTtl, az as getByCategory, aA as getHeader, aB as getHeadersByCategory, aC as getStatusByCategory, aD as getStatusCode, aE as isClientError, aF as isServerError, aG as isSuccess, aH as isValidIp, aI as isValidIpv4, aJ as isValidIpv6, aK as parseClientHintHeaders, aL as parseContentDisposition, aM as parseContentRangeHeader, aN as parseDnsResponse, aO as parseGeoResponse, aP as parseHar, aQ as parseIpv6Address, aR as parsePermissionsPolicy, aS as parseUserAgent, aT as parseVaryHeader, aU as searchHeaders, aV as searchStatusCodes, aW as splitSitemap, aX as statusCodeToText, aY as typeNumberToLabel, aZ as validateDomain, a_ as validateHeaderName, a$ as validateHeaderValue, b0 as validateManifest, b1 as validateRobotsTxt, b2 as validateSitemap } from '../network-DelcJeJa.cjs';
|
package/dist/tools/network.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AuthResultEntry, B as BuildRangeHeaderOptions, C as CLIENT_HINTS, a as CacheControlDirective, b as CacheControlOptions, c as CacheControlResult, d as ClientHintDef, e as ClientHintValueType, f as ClientHintsBuildResult, g as ClientHintsParseResult, h as
|
|
1
|
+
export { A as AuthResultEntry, B as BuildRangeHeaderOptions, C as CLIENT_HINTS, a as CacheControlDirective, b as CacheControlOptions, c as CacheControlResult, d as ClientHintDef, e as ClientHintValueType, f as ClientHintsBuildResult, g as ClientHintsParseResult, h as ContentDispositionBuildOptions, i as ContentDispositionBuildResult, j as ContentDispositionParseResult, k as ContentRangeResult, l as CookieAttributes, m as CookieCheckResult, D as DNS_RECORD_TYPES, o as DnsRecord, p as DnsRecordType, q as DnsResponse, E as EmailHeaderAnalysis, r as EmailHeaderField, G as GeoResult, H as HTTP_HEADERS, s as HarEntry, t as HarParseResult, u as HarSummary, v as HeaderCategory, w as HttpHeader, I as Ipv6AddressType, x as Ipv6ParseResult, L as LINK_REL_VALUES, y as LinkHeaderEntry, z as LinkHeaderEntryInput, F as LinkHeaderResult, J as LinkRel, M as ManifestIconInfo, K as ManifestIssue, N as ManifestValidationResult, P as PERMISSIONS_POLICY_FEATURES, O as ParsedClientHint, Q as ParsedDnsResult, R as ParsedGeoResult, S as PermissionsPolicyDirective, T as PermissionsPolicyFeatureInput, U as PermissionsPolicyResult, V as REFERRER_POLICY_VALUES, W as RangeEntry, X as RangeEntryInput, Y as RangeHeaderResult, Z as ReceivedHop, _ as ReferrerPolicyEntry, $ as ReferrerPolicyResult, a0 as ReferrerPolicyValue, a1 as RobotsGroup, a2 as RobotsIssue, a3 as RobotsRule, a4 as RobotsValidationResult, a5 as STATUS_CODES, a6 as SameSiteValue, a7 as SitemapIndexEntry, a8 as SitemapIssue, a9 as SitemapSplitFile, aa as SitemapUrlEntry, ab as SitemapValidationResult, ac as SplitSitemapOptions, ad as SplitSitemapResult, ae as StatusCode, af as UaDeviceType, ag as UserAgentInfo, ah as VaryHeaderEntry, ai as VaryHeaderResult, aj as analyzeEmailHeaders, ak as buildCacheControl, al as buildClientHints, am as buildContentDisposition, an as buildDnsQueryUrl, ao as buildGeoUrl, ap as buildLinkHeader, aq as buildMapUrl, ar as buildPermissionsPolicy, as as buildRangeHeader, at as buildReferrerPolicy, au as buildVaryHeader, av as checkSetCookieHeader, aw as countryCodeToFlag, ax as formatCoordinates, ay as formatTtl, az as getByCategory, aA as getHeader, aB as getHeadersByCategory, aC as getStatusByCategory, aD as getStatusCode, aE as isClientError, aF as isServerError, aG as isSuccess, aH as isValidIp, aI as isValidIpv4, aJ as isValidIpv6, aK as parseClientHintHeaders, aL as parseContentDisposition, aM as parseContentRangeHeader, aN as parseDnsResponse, aO as parseGeoResponse, aP as parseHar, aQ as parseIpv6Address, aR as parsePermissionsPolicy, aS as parseUserAgent, aT as parseVaryHeader, aU as searchHeaders, aV as searchStatusCodes, aW as splitSitemap, aX as statusCodeToText, aY as typeNumberToLabel, aZ as validateDomain, a_ as validateHeaderName, a$ as validateHeaderValue, b0 as validateManifest, b1 as validateRobotsTxt, b2 as validateSitemap } from '../network-DelcJeJa.js';
|
package/dist/tools/network.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { CLIENT_HINTS, DNS_RECORD_TYPES, HTTP_HEADERS, LINK_REL_VALUES, PERMISSIONS_POLICY_FEATURES, REFERRER_POLICY_VALUES, STATUS_CODES, analyzeEmailHeaders, buildCacheControl, buildClientHints, buildDnsQueryUrl, buildGeoUrl, buildLinkHeader, buildMapUrl, buildPermissionsPolicy, buildRangeHeader, buildReferrerPolicy, buildVaryHeader, checkSetCookieHeader, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, parseClientHintHeaders, parseContentRangeHeader, parseDnsResponse, parseGeoResponse, parseHar, parseIpv6Address, parsePermissionsPolicy, parseUserAgent, parseVaryHeader, searchHeaders, searchStatusCodes, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue, validateManifest, validateRobotsTxt, validateSitemap } from '../chunk-
|
|
1
|
+
export { CLIENT_HINTS, DNS_RECORD_TYPES, HTTP_HEADERS, LINK_REL_VALUES, PERMISSIONS_POLICY_FEATURES, REFERRER_POLICY_VALUES, STATUS_CODES, analyzeEmailHeaders, buildCacheControl, buildClientHints, buildContentDisposition, buildDnsQueryUrl, buildGeoUrl, buildLinkHeader, buildMapUrl, buildPermissionsPolicy, buildRangeHeader, buildReferrerPolicy, buildVaryHeader, checkSetCookieHeader, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, parseClientHintHeaders, parseContentDisposition, parseContentRangeHeader, parseDnsResponse, parseGeoResponse, parseHar, parseIpv6Address, parsePermissionsPolicy, parseUserAgent, parseVaryHeader, searchHeaders, searchStatusCodes, splitSitemap, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue, validateManifest, validateRobotsTxt, validateSitemap } from '../chunk-Y7YY733Z.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.
|
|
3
|
+
"version": "0.48.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",
|