@utilix-tech/sdk 0.18.0 → 0.20.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.
@@ -19,6 +19,7 @@
19
19
  * - css-minifier (minifyCss, formatCss, countRules, countProperties)
20
20
  * - mime-lookup (lookupMime, MIME_TABLE)
21
21
  * - github-url-parser (parseGithubUrl)
22
+ * - redos-detector (detectRedos)
22
23
  */
23
24
  type RegexFlag = 'g' | 'i' | 'm' | 's' | 'u';
24
25
  declare const ALL_FLAGS: RegexFlag[];
@@ -307,6 +308,32 @@ interface GithubUrlInfo {
307
308
  declare function parseGithubUrl(input: string): GithubUrlInfo | {
308
309
  error: string;
309
310
  };
311
+ type RedosSeverity = 'high' | 'medium';
312
+ interface RedosFinding {
313
+ type: 'nested-quantifier' | 'overlapping-alternation' | 'adjacent-quantifier';
314
+ severity: RedosSeverity;
315
+ message: string;
316
+ snippet: string;
317
+ index: number;
318
+ }
319
+ interface RedosResult {
320
+ pattern: string;
321
+ valid: boolean;
322
+ compileError?: string;
323
+ risk: 'none' | 'medium' | 'high';
324
+ safe: boolean;
325
+ findings: RedosFinding[];
326
+ }
327
+ /**
328
+ * Statically analyze a regex pattern for catastrophic-backtracking (ReDoS)
329
+ * risk. Pass the pattern body only (no delimiters or flags). This is a
330
+ * heuristic linter focused on the classic exponential/quadratic constructs
331
+ * (nested quantifiers, overlapping alternation under a repeat, adjacent
332
+ * overlapping quantifiers), not a formal guarantee.
333
+ */
334
+ declare function detectRedos(pattern: string): RedosResult | {
335
+ error: string;
336
+ };
310
337
 
311
338
  declare const code_ALL_FLAGS: typeof ALL_FLAGS;
312
339
  type code_ApiEndpoint = ApiEndpoint;
@@ -334,6 +361,9 @@ type code_MimeEntry = MimeEntry;
334
361
  type code_MimeLookupResult = MimeLookupResult;
335
362
  declare const code_OPERATIONS: typeof OPERATIONS;
336
363
  type code_ParsedSpec = ParsedSpec;
364
+ type code_RedosFinding = RedosFinding;
365
+ type code_RedosResult = RedosResult;
366
+ type code_RedosSeverity = RedosSeverity;
337
367
  type code_RegexError = RegexError;
338
368
  type code_RegexFlag = RegexFlag;
339
369
  type code_RegexMatch = RegexMatch;
@@ -354,6 +384,7 @@ declare const code_countProperties: typeof countProperties;
354
384
  declare const code_countRules: typeof countRules;
355
385
  declare const code_detectDialect: typeof detectDialect;
356
386
  declare const code_detectOperationType: typeof detectOperationType;
387
+ declare const code_detectRedos: typeof detectRedos;
357
388
  declare const code_envToExport: typeof envToExport;
358
389
  declare const code_envToJson: typeof envToJson;
359
390
  declare const code_formatCss: typeof formatCss;
@@ -389,7 +420,7 @@ declare const code_testPattern: typeof testPattern;
389
420
  declare const code_testRegex: typeof testRegex;
390
421
  declare const code_validateEnvKey: typeof validateEnvKey;
391
422
  declare namespace code {
392
- export { code_ALL_FLAGS as ALL_FLAGS, type code_ApiEndpoint as ApiEndpoint, type code_ApiInfo as ApiInfo, code_CHEATSHEET as CHEATSHEET, type code_CheatsheetEntry as CheatsheetEntry, type code_CssResult as CssResult, type code_DockerImageRef as DockerImageRef, type code_EnvEntry as EnvEntry, type code_EnvParseResult as EnvParseResult, type code_GitCommandConfig as GitCommandConfig, type code_GitCommandResult as GitCommandResult, type code_GitOperation as GitOperation, type code_GithubUrlInfo as GithubUrlInfo, type code_GithubUrlType as GithubUrlType, type code_GqlFormatResult as GqlFormatResult, type code_HtmlFormatResult as HtmlFormatResult, type code_HtmlMinifyOptions as HtmlMinifyOptions, type code_HtmlMinifyResult as HtmlMinifyResult, type code_JsMinifyOptions as JsMinifyOptions, type code_JsMinifyResult as JsMinifyResult, code_MIME_TABLE as MIME_TABLE, type code_MatchResult as MatchResult, type code_MimeEntry as MimeEntry, type code_MimeLookupResult as MimeLookupResult, code_OPERATIONS as OPERATIONS, type code_ParsedSpec as ParsedSpec, type code_RegexError as RegexError, type code_RegexFlag as RegexFlag, type code_RegexMatch as RegexMatch, type code_RegexResult as RegexResult, type code_RegexSuccess as RegexSuccess, code_SQL_DEFAULT_OPTIONS as SQL_DEFAULT_OPTIONS, type code_Segment as Segment, type code_SpecVersion as SpecVersion, type code_SqlDialect as SqlDialect, type code_SqlFormatOptions as SqlFormatOptions, type code_TestPatternResult as TestPatternResult, code_buildDockerPull as buildDockerPull, code_buildDockerRun as buildDockerRun, code_buildGitCommand as buildGitCommand, code_collapseHtmlWhitespace as collapseHtmlWhitespace, code_collapseJsWhitespace as collapseJsWhitespace, code_countProperties as countProperties, code_countRules as countRules, code_detectDialect as detectDialect, code_detectOperationType as detectOperationType, code_envToExport as envToExport, code_envToJson as envToJson, code_formatCss as formatCss, code_formatGql as formatGql, code_formatHtml as formatHtml, code_formatSql as formatSql, code_getEndpointsByTag as getEndpointsByTag, code_getHtmlStats as getHtmlStats, code_getJsStats as getJsStats, code_getMethodColor as getMethodColor, code_isValidTag as isValidTag, code_lookupMime as lookupMime, code_minifyCss as minifyCss, code_minifyGql as minifyGql, code_minifyHtml as minifyHtml, code_minifyJs as minifyJs, code_minifySql as minifySql, code_normalizeRef as normalizeRef, code_parseDockerImage as parseDockerImage, code_parseEnv as parseEnv, code_parseGitCommand as parseGitCommand, code_parseGithubUrl as parseGithubUrl, code_parseSpec as parseSpec, code_removeConsoleCalls as removeConsoleCalls, code_removeEmptyAttributes as removeEmptyAttributes, code_removeHtmlComments as removeHtmlComments, code_removeJsComments as removeJsComments, code_removeRedundantAttributes as removeRedundantAttributes, code_searchCheatsheet as searchCheatsheet, code_searchEndpoints as searchEndpoints, code_splitStatements as splitStatements, code_testPattern as testPattern, code_testRegex as testRegex, code_validateEnvKey as validateEnvKey };
423
+ export { code_ALL_FLAGS as ALL_FLAGS, type code_ApiEndpoint as ApiEndpoint, type code_ApiInfo as ApiInfo, code_CHEATSHEET as CHEATSHEET, type code_CheatsheetEntry as CheatsheetEntry, type code_CssResult as CssResult, type code_DockerImageRef as DockerImageRef, type code_EnvEntry as EnvEntry, type code_EnvParseResult as EnvParseResult, type code_GitCommandConfig as GitCommandConfig, type code_GitCommandResult as GitCommandResult, type code_GitOperation as GitOperation, type code_GithubUrlInfo as GithubUrlInfo, type code_GithubUrlType as GithubUrlType, type code_GqlFormatResult as GqlFormatResult, type code_HtmlFormatResult as HtmlFormatResult, type code_HtmlMinifyOptions as HtmlMinifyOptions, type code_HtmlMinifyResult as HtmlMinifyResult, type code_JsMinifyOptions as JsMinifyOptions, type code_JsMinifyResult as JsMinifyResult, code_MIME_TABLE as MIME_TABLE, type code_MatchResult as MatchResult, type code_MimeEntry as MimeEntry, type code_MimeLookupResult as MimeLookupResult, code_OPERATIONS as OPERATIONS, type code_ParsedSpec as ParsedSpec, type code_RedosFinding as RedosFinding, type code_RedosResult as RedosResult, type code_RedosSeverity as RedosSeverity, type code_RegexError as RegexError, type code_RegexFlag as RegexFlag, type code_RegexMatch as RegexMatch, type code_RegexResult as RegexResult, type code_RegexSuccess as RegexSuccess, code_SQL_DEFAULT_OPTIONS as SQL_DEFAULT_OPTIONS, type code_Segment as Segment, type code_SpecVersion as SpecVersion, type code_SqlDialect as SqlDialect, type code_SqlFormatOptions as SqlFormatOptions, type code_TestPatternResult as TestPatternResult, code_buildDockerPull as buildDockerPull, code_buildDockerRun as buildDockerRun, code_buildGitCommand as buildGitCommand, code_collapseHtmlWhitespace as collapseHtmlWhitespace, code_collapseJsWhitespace as collapseJsWhitespace, code_countProperties as countProperties, code_countRules as countRules, code_detectDialect as detectDialect, code_detectOperationType as detectOperationType, code_detectRedos as detectRedos, code_envToExport as envToExport, code_envToJson as envToJson, code_formatCss as formatCss, code_formatGql as formatGql, code_formatHtml as formatHtml, code_formatSql as formatSql, code_getEndpointsByTag as getEndpointsByTag, code_getHtmlStats as getHtmlStats, code_getJsStats as getJsStats, code_getMethodColor as getMethodColor, code_isValidTag as isValidTag, code_lookupMime as lookupMime, code_minifyCss as minifyCss, code_minifyGql as minifyGql, code_minifyHtml as minifyHtml, code_minifyJs as minifyJs, code_minifySql as minifySql, code_normalizeRef as normalizeRef, code_parseDockerImage as parseDockerImage, code_parseEnv as parseEnv, code_parseGitCommand as parseGitCommand, code_parseGithubUrl as parseGithubUrl, code_parseSpec as parseSpec, code_removeConsoleCalls as removeConsoleCalls, code_removeEmptyAttributes as removeEmptyAttributes, code_removeHtmlComments as removeHtmlComments, code_removeJsComments as removeJsComments, code_removeRedundantAttributes as removeRedundantAttributes, code_searchCheatsheet as searchCheatsheet, code_searchEndpoints as searchEndpoints, code_splitStatements as splitStatements, code_testPattern as testPattern, code_testRegex as testRegex, code_validateEnvKey as validateEnvKey };
393
424
  }
394
425
 
395
- export { getEndpointsByTag as $, ALL_FLAGS as A, buildDockerRun as B, CHEATSHEET as C, type DockerImageRef as D, type EnvEntry as E, buildGitCommand as F, type GitCommandConfig as G, type HtmlFormatResult as H, collapseHtmlWhitespace as I, type JsMinifyOptions as J, collapseJsWhitespace as K, countProperties as L, MIME_TABLE as M, countRules as N, OPERATIONS as O, type ParsedSpec as P, detectDialect as Q, type RegexError as R, SQL_DEFAULT_OPTIONS as S, type TestPatternResult as T, detectOperationType as U, envToExport as V, envToJson as W, formatCss as X, formatGql as Y, formatHtml as Z, formatSql as _, type ApiEndpoint as a, getHtmlStats as a0, getJsStats as a1, getMethodColor as a2, isValidTag as a3, lookupMime as a4, minifyCss as a5, minifyGql as a6, minifyHtml as a7, minifyJs as a8, minifySql as a9, normalizeRef as aa, parseDockerImage as ab, parseEnv as ac, parseGitCommand as ad, parseGithubUrl as ae, parseSpec as af, removeConsoleCalls as ag, removeEmptyAttributes as ah, removeHtmlComments as ai, removeJsComments as aj, removeRedundantAttributes as ak, searchCheatsheet as al, searchEndpoints as am, splitStatements as an, testPattern as ao, testRegex as ap, validateEnvKey as aq, type ApiInfo as b, code as c, type CheatsheetEntry as d, type CssResult as e, type EnvParseResult as f, type GitCommandResult as g, type GitOperation as h, type GithubUrlInfo as i, type GithubUrlType as j, type GqlFormatResult as k, type HtmlMinifyOptions as l, type HtmlMinifyResult as m, type JsMinifyResult as n, type MatchResult as o, type MimeEntry as p, type MimeLookupResult as q, type RegexFlag as r, type RegexMatch as s, type RegexResult as t, type RegexSuccess as u, type Segment as v, type SpecVersion as w, type SqlDialect as x, type SqlFormatOptions as y, buildDockerPull as z };
426
+ export { formatCss as $, ALL_FLAGS as A, type SqlDialect as B, CHEATSHEET as C, type DockerImageRef as D, type EnvEntry as E, type SqlFormatOptions as F, type GitCommandConfig as G, type HtmlFormatResult as H, buildDockerPull as I, type JsMinifyOptions as J, buildDockerRun as K, buildGitCommand as L, MIME_TABLE as M, collapseHtmlWhitespace as N, OPERATIONS as O, type ParsedSpec as P, collapseJsWhitespace as Q, type RedosFinding as R, SQL_DEFAULT_OPTIONS as S, type TestPatternResult as T, countProperties as U, countRules as V, detectDialect as W, detectOperationType as X, detectRedos as Y, envToExport as Z, envToJson as _, type ApiEndpoint as a, formatGql as a0, formatHtml as a1, formatSql as a2, getEndpointsByTag as a3, getHtmlStats as a4, getJsStats as a5, getMethodColor as a6, isValidTag as a7, lookupMime as a8, minifyCss as a9, minifyGql as aa, minifyHtml as ab, minifyJs as ac, minifySql as ad, normalizeRef as ae, parseDockerImage as af, parseEnv as ag, parseGitCommand as ah, parseGithubUrl as ai, parseSpec as aj, removeConsoleCalls as ak, removeEmptyAttributes as al, removeHtmlComments as am, removeJsComments as an, removeRedundantAttributes as ao, searchCheatsheet as ap, searchEndpoints as aq, splitStatements as ar, testPattern as as, testRegex as at, validateEnvKey as au, type ApiInfo as b, code as c, type CheatsheetEntry as d, type CssResult as e, type EnvParseResult as f, type GitCommandResult as g, type GitOperation as h, type GithubUrlInfo as i, type GithubUrlType as j, type GqlFormatResult as k, type HtmlMinifyOptions as l, type HtmlMinifyResult as m, type JsMinifyResult as n, type MatchResult as o, type MimeEntry as p, type MimeLookupResult as q, type RedosResult as r, type RedosSeverity as s, type RegexError as t, type RegexFlag as u, type RegexMatch as v, type RegexResult as w, type RegexSuccess as x, type Segment as y, type SpecVersion as z };
package/dist/index.cjs CHANGED
@@ -1874,6 +1874,7 @@ __export(text_exports, {
1874
1874
  csvToHtml: () => csvToHtml,
1875
1875
  csvToMarkdown: () => csvToMarkdown,
1876
1876
  detectDelimiter: () => detectDelimiter,
1877
+ detectFillerWords: () => detectFillerWords,
1877
1878
  detectPassiveVoice: () => detectPassiveVoice,
1878
1879
  diffLines: () => diffLines,
1879
1880
  diffLinesSimple: () => diffLinesSimple,
@@ -4311,6 +4312,104 @@ function scoreReadability(text) {
4311
4312
  readingLevel: readabilityGradeLabel(fleschReadingEase)
4312
4313
  };
4313
4314
  }
4315
+ var FILLER_WORDS = [
4316
+ "very",
4317
+ "really",
4318
+ "just",
4319
+ "actually",
4320
+ "basically",
4321
+ "literally",
4322
+ "simply",
4323
+ "totally",
4324
+ "definitely",
4325
+ "certainly",
4326
+ "essentially",
4327
+ "absolutely",
4328
+ "completely",
4329
+ "extremely",
4330
+ "truly",
4331
+ "honestly",
4332
+ "seriously",
4333
+ "obviously",
4334
+ "clearly",
4335
+ "quite",
4336
+ "rather",
4337
+ "somewhat",
4338
+ "fairly",
4339
+ "virtually"
4340
+ ];
4341
+ var HEDGE_PHRASES = [
4342
+ "maybe",
4343
+ "perhaps",
4344
+ "probably",
4345
+ "possibly",
4346
+ "arguably",
4347
+ "kind of",
4348
+ "sort of",
4349
+ "a bit",
4350
+ "a little",
4351
+ "more or less",
4352
+ "in my opinion",
4353
+ "i think",
4354
+ "i believe",
4355
+ "to some extent"
4356
+ ];
4357
+ var CLICHE_PHRASES = [
4358
+ "at the end of the day",
4359
+ "think outside the box",
4360
+ "low-hanging fruit",
4361
+ "move the needle",
4362
+ "circle back",
4363
+ "touch base",
4364
+ "on the same page",
4365
+ "hit the ground running",
4366
+ "paradigm shift",
4367
+ "win-win",
4368
+ "game changer",
4369
+ "best of both worlds",
4370
+ "only time will tell",
4371
+ "back to the drawing board",
4372
+ "the tip of the iceberg",
4373
+ "a perfect storm",
4374
+ "needle in a haystack",
4375
+ "raise the bar",
4376
+ "push the envelope",
4377
+ "the elephant in the room",
4378
+ "boil the ocean",
4379
+ "when it rains it pours"
4380
+ ];
4381
+ var FILLER_DICTIONARY = [
4382
+ ...FILLER_WORDS.map((phrase) => ({ phrase, category: "filler" })),
4383
+ ...HEDGE_PHRASES.map((phrase) => ({ phrase, category: "hedge" })),
4384
+ ...CLICHE_PHRASES.map((phrase) => ({ phrase, category: "cliche" }))
4385
+ ];
4386
+ function _fillerRegex(phrase) {
4387
+ const tokens = phrase.split(/\s+/).map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
4388
+ return new RegExp("\\b" + tokens.join("\\s+") + "\\b", "gi");
4389
+ }
4390
+ function detectFillerWords(text) {
4391
+ const totalWords = (text.match(/[A-Za-z0-9']+/g) ?? []).length;
4392
+ const matches = [];
4393
+ for (const entry of FILLER_DICTIONARY) {
4394
+ const re = _fillerRegex(entry.phrase);
4395
+ const indices = [];
4396
+ let m;
4397
+ while ((m = re.exec(text)) !== null) {
4398
+ indices.push(m.index);
4399
+ if (m.index === re.lastIndex) re.lastIndex++;
4400
+ }
4401
+ if (indices.length > 0) {
4402
+ matches.push({ phrase: entry.phrase, category: entry.category, count: indices.length, indices });
4403
+ }
4404
+ }
4405
+ matches.sort((a, b) => b.count - a.count || a.category.localeCompare(b.category) || a.phrase.localeCompare(b.phrase));
4406
+ const fillerCount = matches.filter((x) => x.category === "filler").reduce((s, x) => s + x.count, 0);
4407
+ const hedgeCount = matches.filter((x) => x.category === "hedge").reduce((s, x) => s + x.count, 0);
4408
+ const clicheCount = matches.filter((x) => x.category === "cliche").reduce((s, x) => s + x.count, 0);
4409
+ const totalMatches = fillerCount + hedgeCount + clicheCount;
4410
+ const density = totalWords > 0 ? Math.round(totalMatches / totalWords * 1e3) / 10 : 0;
4411
+ return { totalWords, totalMatches, fillerCount, hedgeCount, clicheCount, density, matches };
4412
+ }
4314
4413
 
4315
4414
  // src/tools/data.ts
4316
4415
  var data_exports = {};
@@ -8009,6 +8108,7 @@ __export(network_exports, {
8009
8108
  DNS_RECORD_TYPES: () => DNS_RECORD_TYPES,
8010
8109
  HTTP_HEADERS: () => HTTP_HEADERS,
8011
8110
  STATUS_CODES: () => STATUS_CODES,
8111
+ buildCacheControl: () => buildCacheControl,
8012
8112
  buildDnsQueryUrl: () => buildDnsQueryUrl,
8013
8113
  buildGeoUrl: () => buildGeoUrl,
8014
8114
  buildMapUrl: () => buildMapUrl,
@@ -9724,6 +9824,98 @@ function parseUserAgent(ua) {
9724
9824
  const device = { type: _detectUaDeviceType(s) };
9725
9825
  return { browser, engine, os, device, raw: s };
9726
9826
  }
9827
+ var _CACHE_NUM_FIELDS = ["maxAge", "sMaxAge", "staleWhileRevalidate", "staleIfError"];
9828
+ function _humanizeSeconds(s) {
9829
+ if (s === 0) return "0 seconds";
9830
+ const units = [
9831
+ [86400, "day"],
9832
+ [3600, "hour"],
9833
+ [60, "minute"],
9834
+ [1, "second"]
9835
+ ];
9836
+ const parts = [];
9837
+ let rem = s;
9838
+ for (const [size, label] of units) {
9839
+ if (rem >= size) {
9840
+ const n = Math.floor(rem / size);
9841
+ rem -= n * size;
9842
+ parts.push(`${n} ${label}${n === 1 ? "" : "s"}`);
9843
+ }
9844
+ }
9845
+ return parts.slice(0, 2).join(" ");
9846
+ }
9847
+ function buildCacheControl(options = {}) {
9848
+ const nums = {
9849
+ maxAge: null,
9850
+ sMaxAge: null,
9851
+ staleWhileRevalidate: null,
9852
+ staleIfError: null
9853
+ };
9854
+ for (const field of _CACHE_NUM_FIELDS) {
9855
+ const v = options[field];
9856
+ if (v === void 0 || v === null) continue;
9857
+ if (typeof v !== "number" || !Number.isFinite(v) || !Number.isInteger(v) || v < 0) {
9858
+ return { error: `${field} must be a non-negative integer number of seconds` };
9859
+ }
9860
+ nums[field] = v;
9861
+ }
9862
+ const directives = [];
9863
+ const warnings = [];
9864
+ if (options.visibility === "public") {
9865
+ directives.push({ name: "public", value: null, explanation: "Any cache, including shared caches and CDNs, may store this response." });
9866
+ }
9867
+ if (options.visibility === "private") {
9868
+ directives.push({ name: "private", value: null, explanation: "Only the user's browser may cache this response; shared caches and CDNs must not." });
9869
+ }
9870
+ if (options.noCache) {
9871
+ directives.push({ name: "no-cache", value: null, explanation: "A cache may store the response but must revalidate it with the origin before every reuse." });
9872
+ }
9873
+ if (options.noStore) {
9874
+ directives.push({ name: "no-store", value: null, explanation: "No cache may store any part of this request or response." });
9875
+ }
9876
+ if (nums.maxAge !== null) {
9877
+ directives.push({ name: "max-age", value: String(nums.maxAge), explanation: `Considered fresh for ${_humanizeSeconds(nums.maxAge)} (${nums.maxAge}s), after which it becomes stale.` });
9878
+ }
9879
+ if (nums.sMaxAge !== null) {
9880
+ directives.push({ name: "s-maxage", value: String(nums.sMaxAge), explanation: `For shared caches (CDNs, proxies) it is fresh for ${_humanizeSeconds(nums.sMaxAge)} (${nums.sMaxAge}s), overriding max-age there.` });
9881
+ }
9882
+ if (options.mustRevalidate) {
9883
+ directives.push({ name: "must-revalidate", value: null, explanation: "Once stale, a cache must revalidate with the origin and never serve the stale copy." });
9884
+ }
9885
+ if (options.proxyRevalidate) {
9886
+ directives.push({ name: "proxy-revalidate", value: null, explanation: "Like must-revalidate, but the requirement applies only to shared caches." });
9887
+ }
9888
+ if (options.immutable) {
9889
+ directives.push({ name: "immutable", value: null, explanation: "The body will not change while fresh, so browsers should not revalidate it on reload." });
9890
+ }
9891
+ if (options.noTransform) {
9892
+ directives.push({ name: "no-transform", value: null, explanation: "Intermediaries must not modify the response body (for example, recompressing images)." });
9893
+ }
9894
+ if (nums.staleWhileRevalidate !== null) {
9895
+ directives.push({ name: "stale-while-revalidate", value: String(nums.staleWhileRevalidate), explanation: `A cache may serve the stale response for up to ${_humanizeSeconds(nums.staleWhileRevalidate)} (${nums.staleWhileRevalidate}s) while it revalidates in the background.` });
9896
+ }
9897
+ if (nums.staleIfError !== null) {
9898
+ directives.push({ name: "stale-if-error", value: String(nums.staleIfError), explanation: `A cache may serve the stale response for up to ${_humanizeSeconds(nums.staleIfError)} (${nums.staleIfError}s) if the origin returns an error.` });
9899
+ }
9900
+ if (options.mustUnderstand) {
9901
+ directives.push({ name: "must-understand", value: null, explanation: "A cache should store the response only if it understands the caching requirements of the response's status code." });
9902
+ }
9903
+ if (options.noStore && directives.length > 1) {
9904
+ warnings.push("no-store means nothing is cached, so the other directives have no effect.");
9905
+ }
9906
+ if (options.noCache && nums.maxAge !== null) {
9907
+ warnings.push("no-cache forces revalidation on every use, so max-age has little practical effect alongside it.");
9908
+ }
9909
+ if (options.immutable && nums.maxAge === null) {
9910
+ warnings.push("immutable only applies while the response is fresh \u2014 add a max-age so it has a freshness lifetime.");
9911
+ }
9912
+ if (directives.length === 0) {
9913
+ warnings.push("No directives set \u2014 an empty Cache-Control header has no effect.");
9914
+ }
9915
+ const header = directives.map((d) => d.value === null ? d.name : `${d.name}=${d.value}`).join(", ");
9916
+ const snippet = `Cache-Control: ${header}`;
9917
+ return { header, headerName: "Cache-Control", snippet, directives, warnings };
9918
+ }
9727
9919
 
9728
9920
  // src/tools/api.ts
9729
9921
  var api_exports = {};
@@ -11007,6 +11199,7 @@ __export(code_exports, {
11007
11199
  countRules: () => countRules,
11008
11200
  detectDialect: () => detectDialect,
11009
11201
  detectOperationType: () => detectOperationType,
11202
+ detectRedos: () => detectRedos,
11010
11203
  envToExport: () => envToExport2,
11011
11204
  envToJson: () => envToJson2,
11012
11205
  formatCss: () => formatCss,
@@ -13464,6 +13657,270 @@ function parseGithubUrl(input) {
13464
13657
  }
13465
13658
  return { error: `Unsupported GitHub URL path: /${rest.join("/")}` };
13466
13659
  }
13660
+ var _REDOS_UNBOUNDED = /* @__PURE__ */ new Set(["*", "+"]);
13661
+ function _redosParseQuant(src, i) {
13662
+ const ch = src[i];
13663
+ if (ch === "*" || ch === "+" || ch === "?") {
13664
+ let end = i + 1;
13665
+ if (src[end] === "?" || src[end] === "+") end++;
13666
+ return { unbounded: _REDOS_UNBOUNDED.has(ch), raw: src.slice(i, end), end };
13667
+ }
13668
+ if (ch === "{") {
13669
+ const close = src.indexOf("}", i);
13670
+ if (close === -1) return null;
13671
+ const inner = src.slice(i + 1, close);
13672
+ if (!/^\d+(,\d*)?$/.test(inner)) return null;
13673
+ let end = close + 1;
13674
+ if (src[end] === "?" || src[end] === "+") end++;
13675
+ const unbounded = /^\d+,$/.test(inner);
13676
+ return { unbounded, raw: src.slice(i, end), end };
13677
+ }
13678
+ return null;
13679
+ }
13680
+ function _redosParseAlternation(src, start, endExclusive) {
13681
+ const alternatives = [];
13682
+ let current = [];
13683
+ let i = start;
13684
+ while (i < endExclusive) {
13685
+ const ch = src[i];
13686
+ if (ch === "|") {
13687
+ alternatives.push(current);
13688
+ current = [];
13689
+ i++;
13690
+ continue;
13691
+ }
13692
+ let node;
13693
+ if (ch === "\\") {
13694
+ const atomEnd = i + 2 <= endExclusive ? i + 2 : i + 1;
13695
+ node = { kind: "char", start: i, end: atomEnd, quant: null, quantEnd: atomEnd, raw: src.slice(i, atomEnd) };
13696
+ i = atomEnd;
13697
+ } else if (ch === "[") {
13698
+ let j = i + 1;
13699
+ if (src[j] === "^") j++;
13700
+ if (src[j] === "]") j++;
13701
+ while (j < endExclusive && src[j] !== "]") {
13702
+ j += src[j] === "\\" ? 2 : 1;
13703
+ }
13704
+ const classEnd = j < endExclusive ? j + 1 : endExclusive;
13705
+ node = { kind: "class", start: i, end: classEnd, quant: null, quantEnd: classEnd, raw: src.slice(i, classEnd) };
13706
+ i = classEnd;
13707
+ } else if (ch === "(") {
13708
+ let depth = 1;
13709
+ let j = i + 1;
13710
+ while (j < endExclusive && depth > 0) {
13711
+ const cj = src[j];
13712
+ if (cj === "\\") {
13713
+ j += 2;
13714
+ continue;
13715
+ }
13716
+ if (cj === "[") {
13717
+ j++;
13718
+ if (src[j] === "^") j++;
13719
+ if (src[j] === "]") j++;
13720
+ while (j < endExclusive && src[j] !== "]") {
13721
+ j += src[j] === "\\" ? 2 : 1;
13722
+ }
13723
+ j++;
13724
+ continue;
13725
+ }
13726
+ if (cj === "(") depth++;
13727
+ else if (cj === ")") depth--;
13728
+ j++;
13729
+ }
13730
+ const closeIdx = depth === 0 ? j - 1 : endExclusive;
13731
+ let contentStart = i + 1;
13732
+ let lookaround = false;
13733
+ if (src[i + 1] === "?") {
13734
+ const after = src[i + 2];
13735
+ if (after === ":") contentStart = i + 3;
13736
+ else if (after === "=" || after === "!") {
13737
+ contentStart = i + 3;
13738
+ lookaround = true;
13739
+ } else if (after === "<") {
13740
+ const a3 = src[i + 3];
13741
+ if (a3 === "=" || a3 === "!") {
13742
+ contentStart = i + 4;
13743
+ lookaround = true;
13744
+ } else {
13745
+ const gt = src.indexOf(">", i + 2);
13746
+ contentStart = gt !== -1 && gt < closeIdx ? gt + 1 : i + 3;
13747
+ }
13748
+ }
13749
+ }
13750
+ node = {
13751
+ kind: "group",
13752
+ start: i,
13753
+ end: closeIdx + 1,
13754
+ quant: null,
13755
+ quantEnd: closeIdx + 1,
13756
+ raw: src.slice(i, closeIdx + 1),
13757
+ alternatives: _redosParseAlternation(src, contentStart, closeIdx),
13758
+ lookaround
13759
+ };
13760
+ i = closeIdx + 1;
13761
+ } else if (ch === ".") {
13762
+ node = { kind: "dot", start: i, end: i + 1, quant: null, quantEnd: i + 1, raw: "." };
13763
+ i++;
13764
+ } else if (ch === "^" || ch === "$") {
13765
+ node = { kind: "anchor", start: i, end: i + 1, quant: null, quantEnd: i + 1, raw: ch };
13766
+ i++;
13767
+ } else {
13768
+ node = { kind: "char", start: i, end: i + 1, quant: null, quantEnd: i + 1, raw: ch };
13769
+ i++;
13770
+ }
13771
+ if (node.kind !== "anchor") {
13772
+ const q = _redosParseQuant(src, i);
13773
+ if (q) {
13774
+ node.quant = q;
13775
+ node.quantEnd = q.end;
13776
+ i = q.end;
13777
+ }
13778
+ }
13779
+ current.push(node);
13780
+ }
13781
+ alternatives.push(current);
13782
+ return alternatives;
13783
+ }
13784
+ var _REDOS_ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ .,-@/:;#%&=";
13785
+ function _redosFirstMatcher(node) {
13786
+ if (node.kind === "dot") return (c) => c !== "\n";
13787
+ if (node.kind === "char") {
13788
+ if (node.raw.startsWith("\\")) {
13789
+ const body = node.raw.slice(1);
13790
+ if (/^[dDwWsS]$/.test(body)) {
13791
+ try {
13792
+ const re = new RegExp("\\" + body);
13793
+ return (c) => re.test(c);
13794
+ } catch {
13795
+ return null;
13796
+ }
13797
+ }
13798
+ const literal = { n: "\n", t: " ", r: "\r", f: "\f", v: "\v" }[body] ?? body;
13799
+ return (c) => c === literal;
13800
+ }
13801
+ const lit = node.raw;
13802
+ return (c) => c === lit;
13803
+ }
13804
+ if (node.kind === "class") {
13805
+ try {
13806
+ const re = new RegExp(node.raw);
13807
+ return (c) => re.test(c);
13808
+ } catch {
13809
+ return null;
13810
+ }
13811
+ }
13812
+ if (node.kind === "group") {
13813
+ const first = node.alternatives?.[0]?.[0];
13814
+ return first ? _redosFirstMatcher(first) : null;
13815
+ }
13816
+ return null;
13817
+ }
13818
+ function _redosOverlaps(a, b) {
13819
+ const fa = _redosFirstMatcher(a);
13820
+ const fb = _redosFirstMatcher(b);
13821
+ if (!fa || !fb) return false;
13822
+ for (const c of _REDOS_ALPHABET) {
13823
+ if (fa(c) && fb(c)) return true;
13824
+ }
13825
+ return false;
13826
+ }
13827
+ function _redosAnalyzeGroup(node, findings) {
13828
+ const alts = node.alternatives ?? [];
13829
+ const outerUnbounded = node.quant?.unbounded === true && !node.lookaround;
13830
+ if (outerUnbounded) {
13831
+ for (const alt of alts) {
13832
+ const meaningful = alt.filter((n) => n.kind !== "anchor");
13833
+ if (meaningful.length === 1 && meaningful[0].quant?.unbounded) {
13834
+ findings.push({
13835
+ type: "nested-quantifier",
13836
+ severity: "high",
13837
+ message: "Nested unbounded quantifiers: a repeated group whose body is itself unbounded-repeated can match the same input in exponentially many ways, causing catastrophic backtracking.",
13838
+ snippet: node.raw + (node.quant?.raw ?? ""),
13839
+ index: node.start
13840
+ });
13841
+ break;
13842
+ }
13843
+ }
13844
+ if (alts.length > 1) {
13845
+ const firsts = alts.map((alt) => alt.find((n) => n.kind !== "anchor")).filter((n) => !!n);
13846
+ let flagged = false;
13847
+ for (let x = 0; x < firsts.length && !flagged; x++) {
13848
+ for (let y = x + 1; y < firsts.length; y++) {
13849
+ if (_redosOverlaps(firsts[x], firsts[y])) {
13850
+ findings.push({
13851
+ type: "overlapping-alternation",
13852
+ severity: "medium",
13853
+ message: "Overlapping alternation under a repetition: two branches can match the same starting input, so the engine has multiple ways to split each repeat and may backtrack heavily.",
13854
+ snippet: node.raw + (node.quant?.raw ?? ""),
13855
+ index: node.start
13856
+ });
13857
+ flagged = true;
13858
+ break;
13859
+ }
13860
+ }
13861
+ }
13862
+ }
13863
+ }
13864
+ for (const alt of alts) {
13865
+ _redosAnalyzeSequence(alt, findings);
13866
+ }
13867
+ }
13868
+ function _redosAnalyzeSequence(seq, findings) {
13869
+ for (let k = 0; k + 1 < seq.length; k++) {
13870
+ const a = seq[k];
13871
+ const b = seq[k + 1];
13872
+ if (a.quant?.unbounded && b.quant?.unbounded && _redosOverlaps(a, b)) {
13873
+ findings.push({
13874
+ type: "adjacent-quantifier",
13875
+ severity: "medium",
13876
+ message: "Adjacent unbounded quantifiers over overlapping characters: the engine can distribute the same input between them in many ways, causing quadratic backtracking.",
13877
+ snippet: seq[k].raw + (a.quant?.raw ?? "") + seq[k + 1].raw + (b.quant?.raw ?? ""),
13878
+ index: a.start
13879
+ });
13880
+ }
13881
+ }
13882
+ for (const node of seq) {
13883
+ if (node.kind === "group") _redosAnalyzeGroup(node, findings);
13884
+ }
13885
+ }
13886
+ function detectRedos(pattern) {
13887
+ if (typeof pattern !== "string" || pattern === "") {
13888
+ return { error: "Empty pattern" };
13889
+ }
13890
+ if (pattern.length > 5e3) {
13891
+ return { error: "Pattern too long (max 5,000 chars)" };
13892
+ }
13893
+ let valid = true;
13894
+ let compileError;
13895
+ try {
13896
+ new RegExp(pattern);
13897
+ } catch (e) {
13898
+ valid = false;
13899
+ compileError = e instanceof Error ? e.message : String(e);
13900
+ }
13901
+ const findings = [];
13902
+ const alternatives = _redosParseAlternation(pattern, 0, pattern.length);
13903
+ for (const alt of alternatives) {
13904
+ _redosAnalyzeSequence(alt, findings);
13905
+ }
13906
+ const seen = /* @__PURE__ */ new Set();
13907
+ const unique = findings.filter((f) => {
13908
+ const key = `${f.type}:${f.index}`;
13909
+ if (seen.has(key)) return false;
13910
+ seen.add(key);
13911
+ return true;
13912
+ });
13913
+ unique.sort((a, b) => a.index - b.index);
13914
+ const risk = unique.some((f) => f.severity === "high") ? "high" : unique.length > 0 ? "medium" : "none";
13915
+ return {
13916
+ pattern,
13917
+ valid,
13918
+ ...compileError ? { compileError } : {},
13919
+ risk,
13920
+ safe: unique.length === 0,
13921
+ findings: unique
13922
+ };
13923
+ }
13467
13924
 
13468
13925
  // src/tools/color.ts
13469
13926
  var color_exports = {};
package/dist/index.d.cts CHANGED
@@ -1,14 +1,14 @@
1
1
  export { j as json } from './json-BjSoIS1h.cjs';
2
2
  export { e as encoding } from './encoding-Dk3wpmb3.cjs';
3
3
  export { h as hashing } from './hashing-CnetQFD_.cjs';
4
- export { t as text } from './text-Bbx-tZ43.cjs';
4
+ export { t as text } from './text-DS70aMY5.cjs';
5
5
  export { d as data } from './data-D8XTI7Du.cjs';
6
6
  export { g as generators } from './generators-BGtRGpJZ.cjs';
7
7
  export { t as time } from './time-DbT8fjaF.cjs';
8
8
  export { u as units } from './units-BFTQwpBu.cjs';
9
- export { n as network } from './network-DZugNyAQ.cjs';
9
+ export { n as network } from './network-BJOjJnmY.cjs';
10
10
  export { a as api } from './api-Xl7OzIgq.cjs';
11
- export { c as code } from './code-Cn9uOIAh.cjs';
11
+ export { c as code } from './code-DaRvff2v.cjs';
12
12
  export { c as color } from './color-tPwZCr9H.cjs';
13
13
  export { c as css } from './css-Cf7AMGM-.cjs';
14
14
  export { m as misc } from './misc-CA3N198T.cjs';
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export { j as json } from './json-BjSoIS1h.js';
2
2
  export { e as encoding } from './encoding-Dk3wpmb3.js';
3
3
  export { h as hashing } from './hashing-CnetQFD_.js';
4
- export { t as text } from './text-Bbx-tZ43.js';
4
+ export { t as text } from './text-DS70aMY5.js';
5
5
  export { d as data } from './data-D8XTI7Du.js';
6
6
  export { g as generators } from './generators-BGtRGpJZ.js';
7
7
  export { t as time } from './time-DbT8fjaF.js';
8
8
  export { u as units } from './units-BFTQwpBu.js';
9
- export { n as network } from './network-DZugNyAQ.js';
9
+ export { n as network } from './network-BJOjJnmY.js';
10
10
  export { a as api } from './api-Xl7OzIgq.js';
11
- export { c as code } from './code-Cn9uOIAh.js';
11
+ export { c as code } from './code-DaRvff2v.js';
12
12
  export { c as color } from './color-tPwZCr9H.js';
13
13
  export { c as css } from './css-Cf7AMGM-.js';
14
14
  export { m as misc } from './misc-CA3N198T.js';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export { media_exports as media } from './chunk-XMKJYVKB.js';
2
2
  export { units_exports as units } from './chunk-U34B5XPK.js';
3
- export { network_exports as network } from './chunk-3QMUUTBH.js';
3
+ export { network_exports as network } from './chunk-Y5OOP6WN.js';
4
4
  export { api_exports as api } from './chunk-Q3B3YWOA.js';
5
- export { code_exports as code } from './chunk-L53LAVAD.js';
5
+ export { code_exports as code } from './chunk-LXKIPPDG.js';
6
6
  export { color_exports as color } from './chunk-BPVAB4P2.js';
7
7
  export { css_exports as css } from './chunk-6YPV2AB5.js';
8
8
  export { misc_exports as misc } from './chunk-GX7H6TAX.js';
@@ -10,7 +10,7 @@ export { ai_agent_exports as ai_agent } from './chunk-265NPGKH.js';
10
10
  export { json_exports as json } from './chunk-TSAGO3XP.js';
11
11
  export { encoding_exports as encoding } from './chunk-DOWQZUTP.js';
12
12
  export { hashing_exports as hashing } from './chunk-GEFVMGZR.js';
13
- export { text_exports as text } from './chunk-F57WMKZO.js';
13
+ export { text_exports as text } from './chunk-2I4O5YCT.js';
14
14
  export { data_exports as data } from './chunk-TINQFTLO.js';
15
15
  export { generators_exports as generators } from './chunk-2CJSLYWI.js';
16
16
  export { time_exports as time } from './chunk-ZPQZEIXP.js';