@xevrion/gsc-mcp 0.0.0-stage → 0.1.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/dist/demo.js ADDED
@@ -0,0 +1,330 @@
1
+ import { fallbackCtr } from "./analysis.js";
2
+ // A deterministic, fictional coffee site with the problems a real one has:
3
+ // decaying posts, cannibalizing pages, weak titles, striking-distance queries.
4
+ export const DEMO_SITE = "sc-domain:brewguide.coffee";
5
+ const ORIGIN = "https://brewguide.coffee";
6
+ // Snapshot of Google's Search Status Dashboard so demo mode works offline.
7
+ const DEMO_UPDATES = [
8
+ ["December 2026 core update", "2026-11-24", undefined],
9
+ ["November 2026 core update", "2026-11-10", "2026-11-24"],
10
+ ["September 2026 spam update", "2026-09-24", "2026-10-08"],
11
+ ["August 2026 spam update", "2026-08-18", "2026-08-21"],
12
+ ["June 2026 spam update", "2026-06-24", "2026-06-26"],
13
+ ["May 2026 core update", "2026-05-21", "2026-06-02"],
14
+ ["March 2026 core update", "2026-03-27", "2026-04-08"],
15
+ ["March 2026 spam update", "2026-03-24", "2026-03-25"],
16
+ ["December 2025 core update", "2025-12-11", "2025-12-29"],
17
+ ].map(([external_desc, begin, end]) => ({ external_desc, begin: `${begin}T00:00:00+00:00`, end: end && `${end}T00:00:00+00:00`, service_name: "Ranking" }));
18
+ export const DEMO_AUTH = { headers: async () => new Headers() };
19
+ function rng(seed) {
20
+ return () => {
21
+ seed |= 0;
22
+ seed = (seed + 0x6d2b79f5) | 0;
23
+ let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
24
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
25
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
26
+ };
27
+ }
28
+ const PAGES = [
29
+ ["/", ["brewguide", "brew guide coffee", "brewguide.coffee"], { position: 1.1, ctrFactor: 1.6, branded: true, daily: 90 }],
30
+ ["/blog/pour-over-coffee-guide", ["pour over coffee", "how to make pour over coffee", "pour over ratio", "v60 recipe", "pour over technique"], { position: 3.2, daily: 420 }],
31
+ ["/blog/french-press-ratio", ["french press ratio", "french press coffee to water ratio", "how much coffee for french press", "french press grams"], { position: 2.4, daily: 380, trend: -0.55 }],
32
+ ["/blog/cold-brew-at-home", ["cold brew recipe", "how to make cold brew", "cold brew ratio", "cold brew concentrate"], { position: 6.8, daily: 610, trend: 0.4 }],
33
+ ["/reviews/best-coffee-grinder", ["best coffee grinder", "best burr grinder", "coffee grinder reviews", "best grinder for espresso"], { position: 8.9, daily: 720 }],
34
+ ["/reviews/best-espresso-machine-under-500", ["best espresso machine under 500", "budget espresso machine", "best home espresso machine"], { position: 11.4, daily: 540 }],
35
+ ["/blog/aeropress-recipes", ["aeropress recipe", "best aeropress recipe", "inverted aeropress", "aeropress ratio"], { position: 4.6, daily: 300, ctrFactor: 0.35 }],
36
+ ["/blog/coffee-grind-size-chart", ["coffee grind size chart", "grind size for french press", "grind size for pour over", "espresso grind size"], { position: 3.9, daily: 350, trend: 0.15 }],
37
+ ["/blog/how-to-descale-coffee-maker", ["how to descale coffee maker", "descale coffee machine vinegar", "descaling solution"], { position: 5.3, daily: 260, ctrFactor: 0.4 }],
38
+ ["/blog/moka-pot-guide", ["moka pot", "how to use a moka pot", "moka pot coffee ratio"], { position: 7.2, daily: 210 }],
39
+ ["/blog/light-vs-dark-roast", ["light vs dark roast", "which roast has more caffeine", "dark roast caffeine"], { position: 9.8, daily: 330, trend: -0.4 }],
40
+ ["/blog/caffeine-in-coffee", ["how much caffeine in coffee", "caffeine in espresso shot", "caffeine per cup"], { position: 14.2, daily: 900 }],
41
+ ["/blog/latte-art-for-beginners", ["latte art", "latte art for beginners", "how to steam milk"], { position: 12.7, daily: 280 }],
42
+ ["/guides/espresso-dialing-in", ["dialing in espresso", "espresso extraction time", "sour espresso fix"], { position: 6.1, daily: 160 }],
43
+ ["/guides/water-for-coffee", ["best water for coffee", "coffee water recipe"], { position: 4.4, daily: 90 }],
44
+ ["/reviews/best-pour-over-kettle", ["best gooseneck kettle", "pour over kettle"], { position: 5.6, daily: 240, trend: 0.25 }],
45
+ ["/reviews/fellow-ode-review", ["fellow ode review", "fellow ode gen 2"], { position: 3.1, daily: 120 }],
46
+ ["/blog/chemex-vs-v60", ["chemex vs v60", "chemex recipe"], { position: 4.9, daily: 140 }],
47
+ ["/blog/old-iced-coffee-post-2021", ["iced coffee recipe", "how to make iced coffee"], { position: 18.5, daily: 160, trend: -0.7 }],
48
+ ];
49
+ // The same queries ranked by a second page: the cannibalization the analysis should catch.
50
+ const CANNIBALS = [
51
+ ["pour over ratio", "/blog/coffee-grind-size-chart", 0.8, 7.5],
52
+ ["cold brew ratio", "/blog/french-press-ratio", 0.7, 9.1],
53
+ ["best burr grinder", "/reviews/fellow-ode-review", 0.9, 10.2],
54
+ ["iced coffee recipe", "/blog/cold-brew-at-home", 1.4, 9.4],
55
+ ["grind size for pour over", "/blog/pour-over-coffee-guide", 0.9, 6.3],
56
+ ];
57
+ const DEVICES = [
58
+ ["MOBILE", 0.63, 0.4],
59
+ ["DESKTOP", 0.33, -0.6],
60
+ ["TABLET", 0.04, 0.9],
61
+ ];
62
+ // [country, share of impressions, position offset, CTR multiplier]
63
+ const COUNTRIES = [
64
+ ["usa", 0.46, 0, 1.05],
65
+ ["gbr", 0.12, -0.6, 1.1],
66
+ ["can", 0.09, -0.3, 1.08],
67
+ ["ind", 0.08, 2.1, 0.55],
68
+ ["aus", 0.07, -0.4, 1.02],
69
+ ["deu", 0.05, 3.2, 0.7],
70
+ ["phl", 0.04, 1.5, 0.6],
71
+ ["bra", 0.03, 4.0, 0.5],
72
+ ["nld", 0.03, 1.1, 0.9],
73
+ ["zaf", 0.03, 0.8, 0.85],
74
+ ];
75
+ let PAIRS;
76
+ function pairs() {
77
+ if (PAIRS)
78
+ return PAIRS;
79
+ const r = rng(42);
80
+ const out = [];
81
+ for (const [path, queries, o = {}] of PAGES) {
82
+ queries.forEach((q, i) => {
83
+ const share = i === 0 ? 0.45 : 0.55 / (queries.length - 1);
84
+ out.push({
85
+ query: q,
86
+ page: ORIGIN + path,
87
+ daily: (o.daily ?? 200) * share * (0.8 + r() * 0.4),
88
+ position: Math.max(1, (o.position ?? 5) + (i === 0 ? 0 : (r() - 0.3) * 4)),
89
+ ctrFactor: (o.ctrFactor ?? 1) * (0.85 + r() * 0.3),
90
+ trend: o.trend ?? (r() - 0.5) * 0.2,
91
+ branded: o.branded ?? false,
92
+ });
93
+ });
94
+ }
95
+ for (const [q, path, rel, position] of CANNIBALS) {
96
+ const base = out.find((p) => p.query === q);
97
+ out.push({ ...base, page: ORIGIN + path, daily: base.daily * rel, position, ctrFactor: base.ctrFactor * 0.8 });
98
+ }
99
+ // A long tail of low-volume queries so totals look like a real site.
100
+ const tails = ["near me", "reddit", "for beginners", "uk", "2026", "without scale", "tips", "vs", "best", "cheap"];
101
+ for (const [path, queries] of PAGES.slice(1)) {
102
+ for (let k = 0; k < 6; k++) {
103
+ out.push({
104
+ query: `${queries[k % queries.length]} ${tails[Math.floor(r() * tails.length)]}`,
105
+ page: ORIGIN + path,
106
+ daily: 2 + r() * 8,
107
+ position: 6 + r() * 30,
108
+ ctrFactor: 0.6 + r() * 0.6,
109
+ trend: (r() - 0.5) * 0.4,
110
+ branded: false,
111
+ });
112
+ }
113
+ }
114
+ const seen = new Set();
115
+ PAIRS = out.filter((p) => {
116
+ const k = p.query + p.page;
117
+ if (seen.has(k))
118
+ return false;
119
+ seen.add(k);
120
+ return true;
121
+ });
122
+ return PAIRS;
123
+ }
124
+ const DAY = 86_400_000;
125
+ function matches(value, f) {
126
+ switch (f.operator) {
127
+ case "equals":
128
+ return value === f.expression;
129
+ case "notEquals":
130
+ return value !== f.expression;
131
+ case "contains":
132
+ return value.toLowerCase().includes(f.expression.toLowerCase());
133
+ case "notContains":
134
+ return !value.toLowerCase().includes(f.expression.toLowerCase());
135
+ case "includingRegex":
136
+ return re2ish(f.expression).test(value);
137
+ case "excludingRegex":
138
+ return !re2ish(f.expression).test(value);
139
+ }
140
+ return true;
141
+ }
142
+ // Google uses RE2, where (?i) turns on case-insensitivity; JS wants a flag instead.
143
+ function re2ish(expr) {
144
+ return expr.startsWith("(?i)") ? new RegExp(expr.slice(4), "i") : new RegExp(expr);
145
+ }
146
+ function analytics(body) {
147
+ const dims = body.dimensions ?? [];
148
+ const filters = body.dimensionFilterGroups?.[0]?.filters ?? [];
149
+ const lists = body.filterLists ?? [];
150
+ const start = Date.parse(body.startDate + "T00:00:00Z");
151
+ const end = Date.parse(body.endDate + "T00:00:00Z");
152
+ const today = Date.now();
153
+ const typeScale = body.type === "image" ? 0.18 : body.type === "video" ? 0.04 : body.type === "discover" ? 0.3 : body.type && body.type !== "web" ? 0.02 : 1;
154
+ const hourly = dims.includes("hour");
155
+ // Real Search Console hides rare queries; totals without a query breakdown
156
+ // include them, so they come out higher than the sum of query rows.
157
+ const anon = dims.includes("query") || filters.some((f) => f.dimension === "query") ? 1 : 1.22;
158
+ const groups = new Map();
159
+ const devs = dims.includes("device") || filters.some((f) => f.dimension === "device") || lists.some((l) => l.dimension === "device") ? DEVICES : [["", 1, 0]];
160
+ const ctrs = dims.includes("country") || filters.some((f) => f.dimension === "country") || lists.some((l) => l.dimension === "country") ? COUNTRIES : [["", 1, 0, 1]];
161
+ for (const p of pairs()) {
162
+ const brandedVal = p.branded ? "BRANDED" : "NON_BRANDED";
163
+ const base = { query: p.query, page: p.page, searchAppearance: "WEB_LIGHT_RESULTS", brandedClassification: brandedVal };
164
+ if (!filters.every((f) => !(f.dimension in base) || matches(base[f.dimension], f)))
165
+ continue;
166
+ for (const [dev, devShare, devPos] of devs) {
167
+ if (dev && !filters.filter((f) => f.dimension === "device").every((f) => matches(dev, f)))
168
+ continue;
169
+ if (dev && lists.some((l) => l.dimension === "device" && !l.values.includes(dev)))
170
+ continue;
171
+ for (const [ctry, cShare, cPos, cCtr] of ctrs) {
172
+ if (ctry && !filters.filter((f) => f.dimension === "country").every((f) => matches(ctry, f)))
173
+ continue;
174
+ if (ctry && lists.some((l) => l.dimension === "country" && !l.values.includes(ctry)))
175
+ continue;
176
+ for (let t = start; t <= end; t += DAY) {
177
+ const yearsAgo = (today - t) / (365 * DAY);
178
+ const dow = new Date(t).getUTCDay();
179
+ const season = dow === 0 || dow === 6 ? 0.82 : 1.06;
180
+ const wobble = 1 + 0.12 * Math.sin(t / DAY / 9 + p.daily);
181
+ // Planted events for the anomaly finder: a tracking dip and a viral day.
182
+ const daysAgo = Math.round((today - t) / DAY);
183
+ const event = daysAgo === 47 ? 0.45 : daysAgo === 19 && p.page.includes("cold-brew") ? 4 : 1;
184
+ const impr = (anon > 1 ? 1.15 : 1) * p.daily * devShare * cShare * season * wobble * typeScale * Math.max(0.05, 1 - p.trend * yearsAgo) * event;
185
+ // Decaying pages also slip in rankings over time.
186
+ const position = Math.max(1, p.position + devPos + cPos + (p.trend < -0.3 ? -p.trend * yearsAgo * -6 : 0) + 0.4 * Math.sin(t / DAY / 5));
187
+ const clicks = impr * Math.min(0.9, fallbackCtr(position) * p.ctrFactor * cCtr) * anon;
188
+ const hours = hourly ? Array.from({ length: 24 }, (_, h) => h) : [-1];
189
+ for (const h of hours) {
190
+ const hw = h < 0 ? 1 : (0.5 + Math.sin(((h - 6) / 24) * Math.PI * 2) * 0.45 + 0.5) / 24;
191
+ const values = {
192
+ ...base,
193
+ device: dev,
194
+ country: ctry,
195
+ date: new Date(t).toISOString().slice(0, 10),
196
+ hour: h < 0 ? "" : `${new Date(t).toISOString().slice(0, 10)}T${String(h).padStart(2, "0")}:00:00-08:00`,
197
+ };
198
+ const keys = dims.map((d) => values[d]);
199
+ const k = keys.join("\u0000");
200
+ const g = groups.get(k) ?? { keys, clicks: 0, impressions: 0, posSum: 0 };
201
+ g.impressions += impr * hw;
202
+ g.clicks += clicks * hw;
203
+ g.posSum += position * impr * hw;
204
+ groups.set(k, g);
205
+ }
206
+ }
207
+ }
208
+ }
209
+ }
210
+ const rows = [...groups.values()]
211
+ .map((g) => {
212
+ const impressions = Math.round(g.impressions);
213
+ const clicks = Math.round(g.clicks);
214
+ return { keys: g.keys, clicks, impressions, ctr: impressions ? clicks / impressions : 0, position: g.impressions ? g.posSum / g.impressions : 0 };
215
+ })
216
+ .filter((r) => r.impressions > 0)
217
+ .sort((a, b) => b.clicks - a.clicks || b.impressions - a.impressions);
218
+ const startRow = body.startRow ?? 0;
219
+ return { rows: rows.slice(startRow, startRow + (body.rowLimit ?? 1000)) };
220
+ }
221
+ function inspect(url) {
222
+ const path = url.replace(ORIGIN, "");
223
+ const known = PAGES.find(([p]) => p === path);
224
+ const lastCrawl = new Date(Date.now() - 4 * DAY).toISOString();
225
+ if (path.includes("old-iced-coffee")) {
226
+ return {
227
+ verdict: "NEUTRAL",
228
+ coverageState: "Crawled - currently not indexed",
229
+ robotsTxtState: "ALLOWED",
230
+ indexingState: "INDEXING_ALLOWED",
231
+ lastCrawlTime: lastCrawl,
232
+ pageFetchState: "SUCCESSFUL",
233
+ googleCanonical: url,
234
+ userCanonical: url,
235
+ };
236
+ }
237
+ if (path === "/reviews/fellow-ode-review") {
238
+ return {
239
+ verdict: "PASS",
240
+ coverageState: "Submitted and indexed",
241
+ robotsTxtState: "ALLOWED",
242
+ indexingState: "INDEXING_ALLOWED",
243
+ lastCrawlTime: lastCrawl,
244
+ pageFetchState: "SUCCESSFUL",
245
+ googleCanonical: ORIGIN + "/reviews/best-coffee-grinder",
246
+ userCanonical: url,
247
+ };
248
+ }
249
+ if (!known)
250
+ return { noRich: true, verdict: "NEUTRAL", coverageState: "URL is unknown to Google", robotsTxtState: "ALLOWED", indexingState: "INDEXING_ALLOWED", pageFetchState: "PAGE_FETCH_STATE_UNSPECIFIED" };
251
+ return { verdict: "PASS", coverageState: "Submitted and indexed", robotsTxtState: "ALLOWED", indexingState: "INDEXING_ALLOWED", lastCrawlTime: lastCrawl, pageFetchState: "SUCCESSFUL", googleCanonical: url, userCanonical: url, sitemap: [ORIGIN + "/sitemap.xml"] };
252
+ }
253
+ function json(data, status = 200) {
254
+ return new Response(JSON.stringify(data), { status, headers: { "content-type": "application/json" } });
255
+ }
256
+ export function demoSitemapXml() {
257
+ const urls = [...PAGES.map(([p]) => ORIGIN + p), ORIGIN + "/blog/turkish-coffee-guide", ORIGIN + "/blog/coffee-storage-tips"];
258
+ return `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.map((u) => `<url><loc>${u}</loc></url>`).join("")}</urlset>`;
259
+ }
260
+ export const demoFetch = async (input, init) => {
261
+ const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
262
+ const body = init?.body ? JSON.parse(String(init.body)) : {};
263
+ const p = decodeURIComponent(url.pathname);
264
+ if (url.hostname === "status.search.google.com")
265
+ return json(DEMO_UPDATES);
266
+ if (url.href === ORIGIN + "/sitemap.xml")
267
+ return new Response(demoSitemapXml(), { headers: { "content-type": "application/xml" } });
268
+ if (p.endsWith("/webmasters/v3/sites"))
269
+ return json({ siteEntry: [{ siteUrl: DEMO_SITE, permissionLevel: "siteOwner" }, { siteUrl: "https://shop.brewguide.coffee/", permissionLevel: "siteFullUser" }] });
270
+ if (p.endsWith("/searchAnalytics/query")) {
271
+ if (!p.includes(DEMO_SITE))
272
+ return json({ rows: [] });
273
+ return json(analytics(body));
274
+ }
275
+ if (p.endsWith("/urlInspection/index:inspect")) {
276
+ const { noRich, ...status } = inspect(body.inspectionUrl);
277
+ const rich = noRich ? undefined : body.inspectionUrl.includes("/reviews/")
278
+ ? { verdict: "FAIL", detectedItems: [{ richResultType: "Review snippets", items: [{ name: "Review", issues: [{ issueMessage: "Missing field \"itemReviewed\"", severity: "ERROR" }] }] }] }
279
+ : { verdict: "PASS", detectedItems: [{ richResultType: "Breadcrumbs", items: [{ name: "Unnamed item" }] }] };
280
+ return json({ inspectionResult: { inspectionResultLink: "https://search.google.com/search-console/inspect", indexStatusResult: status, mobileUsabilityResult: { verdict: "PASS" }, richResultsResult: rich } });
281
+ }
282
+ if (p.endsWith("/sitemaps")) {
283
+ return json({
284
+ sitemap: [
285
+ { path: ORIGIN + "/sitemap.xml", lastSubmitted: "2026-10-02T10:00:00Z", lastDownloaded: new Date(Date.now() - 2 * DAY).toISOString(), isPending: false, isSitemapsIndex: false, type: "sitemap", warnings: "0", errors: "0", contents: [{ type: "web", submitted: "21", indexed: "0" }] },
286
+ { path: ORIGIN + "/old-sitemap.xml", lastSubmitted: "2023-01-12T10:00:00Z", lastDownloaded: "2025-03-01T10:00:00Z", isPending: false, isSitemapsIndex: false, type: "sitemap", warnings: "0", errors: "3", contents: [{ type: "web", submitted: "40", indexed: "0" }] },
287
+ ],
288
+ });
289
+ }
290
+ if (p.includes("/sitemaps/"))
291
+ return json({});
292
+ if (url.hostname === "www.googleapis.com" && p.includes("/pagespeedonline/")) {
293
+ const target = url.searchParams.get("url") ?? "";
294
+ const slow = target.includes("/reviews/");
295
+ const mobile = url.searchParams.get("strategy") !== "desktop";
296
+ const m = (v, good, poor) => ({ percentile: v, category: v <= good ? "FAST" : v <= poor ? "AVERAGE" : "SLOW" });
297
+ const field = {
298
+ overall_category: slow ? "SLOW" : "FAST",
299
+ metrics: {
300
+ LARGEST_CONTENTFUL_PAINT_MS: m(slow ? (mobile ? 4300 : 2900) : 1900, 2500, 4000),
301
+ INTERACTION_TO_NEXT_PAINT: m(slow ? 310 : 140, 200, 500),
302
+ CUMULATIVE_LAYOUT_SHIFT_SCORE: m(slow ? 18 : 3, 10, 25),
303
+ FIRST_CONTENTFUL_PAINT_MS: m(slow ? 2400 : 1100, 1800, 3000),
304
+ EXPERIMENTAL_TIME_TO_FIRST_BYTE: m(slow ? 1300 : 420, 800, 1800),
305
+ },
306
+ };
307
+ return json({
308
+ loadingExperience: field,
309
+ originLoadingExperience: field,
310
+ lighthouseResult: {
311
+ categories: { performance: { score: slow ? (mobile ? 0.41 : 0.68) : 0.93 } },
312
+ audits: {
313
+ "largest-contentful-paint": { displayValue: slow ? "5.1 s" : "1.8 s" },
314
+ "cumulative-layout-shift": { displayValue: slow ? "0.21" : "0.02" },
315
+ "total-blocking-time": { displayValue: slow ? "640 ms" : "90 ms" },
316
+ "first-contentful-paint": { displayValue: slow ? "2.6 s" : "1.0 s" },
317
+ "speed-index": { displayValue: slow ? "5.9 s" : "2.1 s" },
318
+ ...(slow
319
+ ? {
320
+ "uses-optimized-images": { title: "Efficiently encode images", score: 0.2, details: { type: "opportunity", overallSavingsMs: 1650 } },
321
+ "render-blocking-resources": { title: "Eliminate render-blocking resources", score: 0.3, details: { type: "opportunity", overallSavingsMs: 980 } },
322
+ "unused-javascript": { title: "Reduce unused JavaScript", score: 0.4, details: { type: "opportunity", overallSavingsMs: 720 } },
323
+ }
324
+ : {}),
325
+ },
326
+ },
327
+ });
328
+ }
329
+ return json({ error: { message: `Demo mode does not implement ${p}` } }, 404);
330
+ };
package/dist/format.js ADDED
@@ -0,0 +1,55 @@
1
+ export function int(n) {
2
+ return Math.round(n).toLocaleString("en-US");
3
+ }
4
+ export function pct(n, digits = 1) {
5
+ if (n === null || n === undefined || !Number.isFinite(n))
6
+ return "-";
7
+ return `${(n * 100).toFixed(digits)}%`;
8
+ }
9
+ export function signedPct(n) {
10
+ if (n === null || !Number.isFinite(n))
11
+ return "new";
12
+ return `${n >= 0 ? "+" : ""}${(n * 100).toFixed(1)}%`;
13
+ }
14
+ export function signed(n) {
15
+ return `${n >= 0 ? "+" : ""}${int(n)}`;
16
+ }
17
+ export function pos(n) {
18
+ return n ? n.toFixed(1) : "-";
19
+ }
20
+ // Markdown tables are compact, readable to humans, and cost far fewer tokens
21
+ // than the equivalent JSON once rows run into the hundreds.
22
+ export function table(headers, rows) {
23
+ if (!rows.length)
24
+ return "_No rows._";
25
+ const esc = (c) => String(c ?? "").replace(/\|/g, "\\|").replace(/\n/g, " ");
26
+ const head = [...headers];
27
+ const body = rows.map((r) => r.map(esc));
28
+ // When every URL in a column shares one origin, say it once in the header.
29
+ head.forEach((_, col) => {
30
+ const cells = body.map((r) => r[col]).filter(Boolean);
31
+ const origin = commonOrigin(cells);
32
+ if (!origin || cells.length < 2)
33
+ return;
34
+ head[col] = `${head[col]} (on ${origin})`;
35
+ for (const r of body)
36
+ if (r[col]?.startsWith(origin))
37
+ r[col] = r[col].slice(origin.length) || "/";
38
+ });
39
+ return [`| ${head.join(" | ")} |`, `| ${head.map(() => "---").join(" | ")} |`, ...body.map((r) => `| ${r.join(" | ")} |`)].join("\n");
40
+ }
41
+ function commonOrigin(cells) {
42
+ let origin = null;
43
+ for (const c of cells) {
44
+ const m = c.match(/^https?:\/\/[^/\s]+/);
45
+ if (!m || (origin && m[0] !== origin))
46
+ return null;
47
+ origin = m[0];
48
+ }
49
+ return origin;
50
+ }
51
+ export function delta(cur, prev) {
52
+ if (!prev)
53
+ return cur ? "new" : "-";
54
+ return signedPct((cur - prev) / prev);
55
+ }