seo-supervisor 1.2.0 → 2.0.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.
Files changed (207) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +16 -3
  4. package/CHANGELOG.md +430 -0
  5. package/NOTICE +7 -0
  6. package/README.md +230 -25
  7. package/agents/seo-auditor.md +16 -0
  8. package/agents/seo-reviewer.md +16 -0
  9. package/bin/agents.mjs +194 -29
  10. package/bin/extras.mjs +422 -0
  11. package/bin/prompt.mjs +34 -14
  12. package/bin/seo-supervisor.mjs +386 -53
  13. package/commands/seo-audit.md +29 -3
  14. package/commands/seo-brief.md +28 -0
  15. package/commands/seo-connect.md +27 -0
  16. package/commands/seo-fix.md +24 -3
  17. package/commands/seo-grow.md +26 -0
  18. package/commands/seo-launch.md +17 -3
  19. package/commands/seo-review.md +13 -1
  20. package/commands/seo-rewrite.md +25 -0
  21. package/commands/seo-setup.md +17 -1
  22. package/commands/seo-watch.md +28 -0
  23. package/hooks/hooks.json +117 -0
  24. package/package.json +20 -7
  25. package/skills/seo-supervisor/NOTICE +7 -0
  26. package/skills/seo-supervisor/SKILL.md +302 -21
  27. package/skills/seo-supervisor/audience.md +61 -0
  28. package/skills/seo-supervisor/examples/drafts/security.md +41 -0
  29. package/skills/seo-supervisor/examples/hooks/README.md +28 -0
  30. package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
  31. package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
  32. package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
  33. package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
  34. package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
  35. package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
  36. package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
  37. package/skills/seo-supervisor/examples/sample-audit.json +94 -2
  38. package/skills/seo-supervisor/examples/sample-report.html +111 -61
  39. package/skills/seo-supervisor/examples/sample-report.md +147 -44
  40. package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
  41. package/skills/seo-supervisor/examples/snippets.md +648 -1
  42. package/skills/seo-supervisor/grow.md +342 -0
  43. package/skills/seo-supervisor/og-images.md +85 -0
  44. package/skills/seo-supervisor/page-types.md +124 -0
  45. package/skills/seo-supervisor/planning.md +19 -7
  46. package/skills/seo-supervisor/profile-template.md +41 -0
  47. package/skills/seo-supervisor/report-format.md +177 -10
  48. package/skills/seo-supervisor/rewrite.md +59 -0
  49. package/skills/seo-supervisor/rules/ai-search.md +65 -12
  50. package/skills/seo-supervisor/rules/content.md +33 -9
  51. package/skills/seo-supervisor/rules/crawl-index.md +33 -6
  52. package/skills/seo-supervisor/rules/internal-linking.md +49 -6
  53. package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
  54. package/skills/seo-supervisor/rules/media.md +13 -1
  55. package/skills/seo-supervisor/rules/metadata.md +41 -9
  56. package/skills/seo-supervisor/rules/performance.md +50 -5
  57. package/skills/seo-supervisor/rules/rendering.md +39 -2
  58. package/skills/seo-supervisor/rules/search-intent.md +32 -0
  59. package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
  60. package/skills/seo-supervisor/rules/structured-data.md +37 -14
  61. package/skills/seo-supervisor/rules/trust-security.md +25 -2
  62. package/skills/seo-supervisor/rules/urls.md +10 -2
  63. package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
  64. package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
  65. package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
  66. package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
  67. package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
  68. package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
  69. package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
  70. package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
  71. package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
  72. package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
  73. package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
  74. package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
  75. package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
  76. package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
  77. package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
  78. package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
  79. package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
  80. package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
  81. package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
  82. package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
  83. package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
  84. package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
  85. package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
  86. package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
  87. package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
  88. package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
  89. package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
  90. package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
  91. package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
  92. package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
  93. package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
  94. package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
  95. package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
  96. package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
  97. package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
  98. package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
  99. package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
  100. package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
  101. package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
  102. package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
  103. package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
  104. package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
  105. package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
  106. package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
  107. package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
  108. package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
  109. package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
  110. package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
  111. package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
  112. package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
  113. package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
  114. package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
  115. package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
  116. package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
  117. package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
  118. package/skills/seo-supervisor/scripts/google.mjs +1341 -0
  119. package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
  120. package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
  121. package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
  122. package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
  123. package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
  124. package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
  125. package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
  126. package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
  127. package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
  128. package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
  129. package/skills/seo-supervisor/scripts/guard.mjs +74 -0
  130. package/skills/seo-supervisor/scripts/images.mjs +408 -0
  131. package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
  132. package/skills/seo-supervisor/scripts/issues.mjs +217 -0
  133. package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
  134. package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
  135. package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
  136. package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
  137. package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
  138. package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
  139. package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
  140. package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
  141. package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
  142. package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
  143. package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
  144. package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
  145. package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
  146. package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
  147. package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
  148. package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
  149. package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
  150. package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
  151. package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
  152. package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
  153. package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
  154. package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
  155. package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
  156. package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
  157. package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
  158. package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
  159. package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
  160. package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
  161. package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
  162. package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
  163. package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
  164. package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
  165. package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
  166. package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
  167. package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
  168. package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
  169. package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
  170. package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
  171. package/skills/seo-supervisor/scripts/osm.mjs +359 -0
  172. package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
  173. package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
  174. package/skills/seo-supervisor/scripts/report/client.js +37 -0
  175. package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
  176. package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
  177. package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
  178. package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
  179. package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
  180. package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
  181. package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
  182. package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
  183. package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
  184. package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
  185. package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
  186. package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
  187. package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
  188. package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
  189. package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
  190. package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
  191. package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
  192. package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
  193. package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
  194. package/skills/seo-supervisor/scripts/report/styles.css +223 -0
  195. package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
  196. package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
  197. package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
  198. package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
  199. package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
  200. package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
  201. package/skills/seo-supervisor/site-types/content.md +34 -1
  202. package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
  203. package/skills/seo-supervisor/site-types/local-business.md +96 -6
  204. package/skills/seo-supervisor/site-types/services.md +46 -0
  205. package/skills/seo-supervisor/site-types/tools.md +3 -3
  206. package/skills/seo-supervisor/strategy.md +232 -0
  207. package/skills/seo-supervisor/troubleshooting.md +56 -0
@@ -0,0 +1,193 @@
1
+ // @ts-check
2
+ // Picks the schema.org type that fits the business from home page keywords and the site's existing business types.
3
+ // Keyword evidence, not a model, so every audit gives the same answer. A test checks data/business-types.json against
4
+ // data/schema-vocab.json; its fields follow https://developers.google.com/search/docs/appearance/structured-data/
5
+ import { readFileSync } from "node:fs";
6
+ import { isA, isBusinessType } from "../lib/business.mjs";
7
+
8
+ export const BUSINESS_TYPES = JSON.parse(readFileSync(new URL("../data/business-types.json", import.meta.url), "utf8"));
9
+
10
+ export const CHECKS = {
11
+ "schema-too-generic": [
12
+ "SCHEMA-02",
13
+ "medium",
14
+ () => "The business schema uses a general type where a specific one fits",
15
+ "The home page says plainly what kind of business this is, but its schema calls it only a `LocalBusiness`, an `Organization` or another broad type. Google asks for the most specific type that fits: it tells search engines what the business does, and some fields exist only on the specific type, such as a restaurant's `menu` and `servesCuisine` or a hotel's `checkinTime`.",
16
+ "Change the business node's `@type` to the type the evidence names, keep its `@id`, and add the type's key fields where the site has the facts. `examples/snippets.md` (Business types) has an example for each kind of business, and `scripts/data/business-types.json` lists the fields, the Google feature each can unlock and the usual mistakes.",
17
+ ],
18
+ "business-type-unclear": [
19
+ "SCHEMA-02",
20
+ "needs-decision",
21
+ () => "The home page points to two kinds of business",
22
+ "The home page's title or main heading matches two kinds of business, and the schema names neither yet. The schema type should say what the business is, and a wrong specific type is worse than a general one, so this needs the owner's answer.",
23
+ 'Tell the agent which of the two (the evidence names both) describes the business, and the business node gets that type and its key fields. If it really is both, Google accepts a list, such as `"@type": ["Dentist", "MedicalClinic"]`.',
24
+ ],
25
+ };
26
+
27
+ // "Doctor's Café & Bar" becomes " doctors cafe and bar ", padded so every word sits between two spaces.
28
+ const norm = s =>
29
+ ` ${String(s || "")
30
+ .normalize("NFD")
31
+ .replace(/\p{M}/gu, "")
32
+ .toLowerCase()
33
+ .replace(/['’]/g, "")
34
+ .replace(/&/g, " and ")
35
+ .replace(/[^\p{L}\p{N}]+/gu, " ")
36
+ .trim()} `;
37
+ // Phrases that contain a trade's word without being that trade. They match as keywords mapped to null, so the trade
38
+ // can't match those words.
39
+ const NOT_TRADES = [
40
+ "pub sub",
41
+ "dental insurance",
42
+ "dental plan",
43
+ "screen real estate",
44
+ "last resort",
45
+ "website builder",
46
+ "site builder",
47
+ "page builder",
48
+ "form builder",
49
+ "app builder",
50
+ "online store builder",
51
+ "back to school",
52
+ "old school",
53
+ "school holidays",
54
+ "animal hospital",
55
+ "vet clinic",
56
+ "veterinary clinic",
57
+ ];
58
+ const WORD = new Map([
59
+ ...NOT_TRADES.map(k => [norm(k).trim(), null]),
60
+ ...BUSINESS_TYPES.flatMap(b => b.keywords.map(k => [norm(k).trim(), b])),
61
+ ]);
62
+ // Longest phrase first, so "dental clinic" is the dentist's and not a clinic.
63
+ const KW = new RegExp(`(?<= )(${[...WORD.keys()].sort((a, b) => b.length - a.length).join("|")})(?:e?s)?(?= )`, "g");
64
+ // A trade after "for" or before something it buys ("software for dental clinics", "dental supplies") names a supplier,
65
+ // so it counts for nothing, and so does a trade in a later "for" phrase ("gym equipment for home gyms").
66
+ const SERVES =
67
+ /^ (?:(?:and|or) \S+ )?(?:suppl(?:y|ies|iers?)|equipment|gear|parts?|chairs?|furniture|uniforms?|products?|wholesale|jobs?|recruitment|photography|insurance|courses?|training|cleaning|software|apps?|crm|pos|platform|systems?|marketing|seo|websites?|leads|booking) /;
68
+ const hitsIn = s => {
69
+ const t = norm(s);
70
+ let sold = -1;
71
+ return [...t.matchAll(KW)]
72
+ .filter(m => {
73
+ if (
74
+ !WORD.get(m[1]) ||
75
+ t.slice(0, m.index).endsWith(" for ") ||
76
+ (sold >= 0 && t.slice(sold, m.index).includes(" for "))
77
+ )
78
+ return false;
79
+ if (!SERVES.test(t.slice(m.index + m[0].length))) return true;
80
+ if (sold < 0) sold = m.index;
81
+ return false;
82
+ })
83
+ .map(m => [WORD.get(m[1]), m[0]]);
84
+ };
85
+
86
+ // pages: [{ url, title, h1, text, types }]. text is the main text without post teasers; types come from JSON-LD,
87
+ // Microdata and RDFa. The home page is the one at "/", else the first.
88
+ function judge(pages) {
89
+ const home =
90
+ pages.find(p => {
91
+ try {
92
+ return new URL(p.url).pathname === "/";
93
+ } catch {
94
+ return false;
95
+ }
96
+ }) || pages[0];
97
+ // Any Organization type counts, LocalBusiness and its subtypes included.
98
+ const siteTypes = [...new Set(pages.flatMap(p => p.types || []))].filter(
99
+ t => typeof t === "string" && isBusinessType(t),
100
+ );
101
+ const by = new Map(),
102
+ at = b => by.get(b) || by.set(b, { b, schema: [], title: [], h1: [], text: new Set() }).get(b);
103
+ if (home) {
104
+ for (const b of BUSINESS_TYPES) {
105
+ const s = siteTypes.filter(t => isA(t, b.types[0]));
106
+ if (s.length) at(b).schema = s;
107
+ }
108
+ for (const [b, w] of hitsIn(home.title)) at(b).title.push(w);
109
+ for (const [b, w] of hitsIn(home.h1)) at(b).h1.push(w);
110
+ for (const [b, w] of hitsIn(home.text)) at(b).text.add(w);
111
+ }
112
+ // Schema the site already has counts most, then the title and the H1, then up to three different words in the text.
113
+ const list = [...by.values()]
114
+ .map(c => ({
115
+ ...c,
116
+ head: !!(c.schema.length || c.title.length || c.h1.length),
117
+ score: (c.schema.length && 6) + (c.title.length && 3) + (c.h1.length && 3) + Math.min(c.text.size, 3),
118
+ }))
119
+ .sort((x, y) => y.score - x.score || BUSINESS_TYPES.indexOf(x.b) - BUSINESS_TYPES.indexOf(y.b));
120
+ const [top, next] = list;
121
+ if (!top) return { home, siteTypes, list, bt: { guess: null, alternatives: [], evidence: [], confidence: "none" } };
122
+ // Strong: the schema says so, or the title or H1 does and nothing else comes close.
123
+ const strong = top.schema.length > 0 || (top.head && !next?.head && (next?.score || 0) * 2 <= top.score);
124
+ const shown = list.slice(0, 3),
125
+ words = (c, k) => [...new Set(c[k])].map(w => `${w} (${c.b.types[0]})`);
126
+ const line = (label, k) => {
127
+ const w = shown.flatMap(c => words(c, k));
128
+ return w.length ? [`${label}: ${w.join(", ")}`] : [];
129
+ };
130
+ const evidence = [
131
+ ...(shown.some(c => c.schema.length) ? [`schema: ${[...new Set(shown.flatMap(c => c.schema))].join(", ")}`] : []),
132
+ ...line(`title “${home.title}”`, "title"),
133
+ ...line(`H1 “${home.h1}”`, "h1"),
134
+ ...line("home page text", "text"),
135
+ ];
136
+ return {
137
+ home,
138
+ siteTypes,
139
+ list,
140
+ bt: {
141
+ guess: top.b.id,
142
+ alternatives: list.slice(1, 3).map(c => c.b.id),
143
+ evidence,
144
+ confidence: strong ? "strong" : "weak",
145
+ },
146
+ };
147
+ }
148
+
149
+ export const detectBusinessType = pages => judge(pages).bt;
150
+
151
+ // Adds schema-too-generic or business-type-unclear for the home page and returns the guess. Google asks for the most
152
+ // specific subtype that fits. https://developers.google.com/search/docs/appearance/structured-data/local-business
153
+ export function checkBusinessType(pages, add) {
154
+ const {
155
+ home,
156
+ siteTypes,
157
+ list: [a, b],
158
+ bt,
159
+ } = judge(pages);
160
+ const fits = c => siteTypes.some(t => c.b.types.some(x => isA(t, x)));
161
+ const said = c =>
162
+ [
163
+ ["title", c.title],
164
+ ["H1", c.h1],
165
+ ["home page text", [...c.text]],
166
+ ]
167
+ .filter(([, w]) => w.length)
168
+ .map(([s, w]) => `${s}: ${[...new Set(w)].join(", ")}`)
169
+ .join(", ");
170
+ // A site whose schema has products, offers or a store type may be a shop that sells to the trade it names.
171
+ const store = t => isA(t, "Store") || isA(t, "OnlineStore");
172
+ const shop = [...new Set(pages.flatMap(p => p.types || []))].filter(
173
+ t => typeof t === "string" && (isA(t, "Product") || isA(t, "Offer") || store(t)),
174
+ );
175
+ if (bt.confidence === "strong" && !fits(a)) {
176
+ const broad = siteTypes.filter(t => isA(a.b.types[0], t));
177
+ if (broad.length && shop.length && !a.b.types.some(store))
178
+ add(
179
+ "business-type-unclear",
180
+ home.url,
181
+ `${a.b.types[0]} or OnlineStore? ${a.b.types[0]}: ${said(a)}; OnlineStore: schema: ${shop.join(", ")}`,
182
+ );
183
+ else if (broad.length)
184
+ add("schema-too-generic", home.url, `use ${a.b.types.join(" or ")} instead of ${broad.join(", ")}; ${said(a)}`);
185
+ } else if (bt.confidence === "weak" && a.head && b?.head && !fits(a) && !fits(b)) {
186
+ add(
187
+ "business-type-unclear",
188
+ home.url,
189
+ `${a.b.types[0]} or ${b.b.types[0]}? ${a.b.types[0]}: ${said(a)}; ${b.b.types[0]}: ${said(b)}`,
190
+ );
191
+ }
192
+ return bt;
193
+ }
@@ -0,0 +1,391 @@
1
+ // @ts-check
2
+ // Content checks shared by the crawler and content-scan.mjs. Thresholds are local unless a source is named.
3
+
4
+ const norm = s =>
5
+ String(s ?? "")
6
+ .toLowerCase()
7
+ .replace(/[^\p{L}\p{N}]+/gu, " ")
8
+ .trim();
9
+ const SENT = new Intl.Segmenter("en", { granularity: "sentence" });
10
+ const sentences = t => [...SENT.segment(String(t ?? ""))].map(s => s.segment.trim()).filter(Boolean);
11
+ const escRe = s => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
12
+
13
+ // The crawler's findings; content-scan.mjs defines its own.
14
+ export const CHECKS = {
15
+ "desc-mismatch": [
16
+ "META-02",
17
+ "low",
18
+ n => `${n} description(s) barely match their page`,
19
+ "Fewer than a quarter of the description's main words are on the page. Google uses a description only when it may describe the page better than the page's own text, so this one is likely replaced in results, and visitors who click expect something else. It's usually a copied template or a description left over from an older page.",
20
+ "Rewrite the description from what the page actually says and offers.",
21
+ ],
22
+ "desc-brand-tail": [
23
+ "META-02",
24
+ "low",
25
+ n => `${n} description(s) end with the same brand as their title`,
26
+ "The title already ends with the brand, and results show the title right above the description, so the brand at the end of the description spends space saying it again.",
27
+ "End the description with what the visitor gets, and leave the brand to the title.",
28
+ ],
29
+ "templated-desc": [
30
+ "META-02",
31
+ "medium",
32
+ n => `${n} description(s) end in a stock call to action or an ending other pages share`,
33
+ "Descriptions built from one template (a closing “Learn more”, or the same last sentence on many pages) all read alike in results and give searchers no reason to pick this page.",
34
+ "Write each description from what the page offers, in about 120–160 characters; leave calls to action to the page itself.",
35
+ ],
36
+ "stale-guide": [
37
+ "CONTENT-07",
38
+ "low",
39
+ n => `${n} guide(s) were last dated over a year ago`,
40
+ "CONTENT-07 asks for guides to be reviewed every 6 to 12 months, and this guide's newest date (schema dateModified or datePublished, a <time> tag, or a visible “updated” or “published” date) is older than that. Readers take an old date as a sign the advice may be out of date. The 12-month line is our own, not Google's.",
41
+ "Review the guide. If it changed, update it and its date; if it's still right, add a “last reviewed” date. Never move a date without a real review (CONTENT-12).",
42
+ ],
43
+ };
44
+
45
+ // ---------- titles ----------
46
+ // Results cut titles at a pixel width. CJK characters are about two Latin letters wide and combining marks take no
47
+ // room. A rough count, not Google's.
48
+ const WIDE = /[\p{scx=Han}\p{scx=Hira}\p{scx=Kana}\p{scx=Hang} -〿!-⦆¢-₩]/u;
49
+ export const titleWidth = t => [...String(t)].reduce((n, c) => n + (/\p{M}/u.test(c) ? 0 : WIDE.test(c) ? 2 : 1), 0);
50
+ export const widthText = t => {
51
+ const n = [...t].length,
52
+ w = titleWidth(t);
53
+ return w === n ? `${n} chars` : `${n} characters, about as wide as ${w} Latin ones`;
54
+ };
55
+
56
+ // ---------- obsolete tags ----------
57
+ // Obsolete elements beyond the six the crawler already finds (frameset, frame, marquee, blink, font, center).
58
+ // https://html.spec.whatwg.org/multipage/obsolete.html
59
+ const OBSOLETE_MORE = /<(acronym|applet|basefont|bgsound|big|dir|isindex|nobr|spacer|strike|tt)(?=[\s>\/])/gi;
60
+ // The crawler passes noScripts when it has already stripped scripts, styles, templates and comments.
61
+ export const obsoleteMore = (
62
+ html,
63
+ noScripts = html.replace(/<(script|style|template)\b[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " "),
64
+ ) => [...new Set([...noScripts.matchAll(OBSOLETE_MORE)].map(m => m[1].toLowerCase()))];
65
+
66
+ // ---------- descriptions ----------
67
+ const SEP = String.raw`(?:[|·•»–—-]|::)`;
68
+ // Returns the title's brand tail ("… | Brand") when the description also ends with it after a separator.
69
+ export function brandTail(title, desc) {
70
+ const parts = String(title).split(new RegExp(`\\s+${SEP}\\s+`));
71
+ const tail = parts.length > 1 ? parts.at(-1).trim() : "";
72
+ if (tail.length < 2 || tail.length > 40) return null;
73
+ return new RegExp(`(?:^|\\s)${SEP}\\s*${escRe(tail)}[\\s.!]*$`, "i").test(String(desc).trim()) ? tail : null;
74
+ }
75
+
76
+ const CTA =
77
+ /(?:learn more|click here|contact us today|find out more|read more|discover more|find out how|see more|call (?:us )?(?:today|now)|contact us now|get in touch today|get started today|shop now|book now|order now)[.!…\s]*$/i;
78
+ // items: [{ url, desc, title? }]. Duplicate descriptions are left to desc-dup, and fewer than 3 hits isn't a template.
79
+ export function templatedDescs(items, { titleRepeat = false } = {}) {
80
+ const uses = new Map();
81
+ for (const x of items) {
82
+ const k = String(x.desc ?? "").trim();
83
+ if (k) uses.set(k, (uses.get(k) || 0) + 1);
84
+ }
85
+ const own = items
86
+ .filter(x => uses.get(String(x.desc ?? "").trim()) === 1)
87
+ .map(x => {
88
+ const s = sentences(x.desc);
89
+ return { ...x, d: String(x.desc).trim(), end: s.length > 1 ? s.at(-1) : null };
90
+ });
91
+ const endings = new Map();
92
+ for (const x of own) {
93
+ const k = x.end && norm(x.end);
94
+ if (k && k.split(" ").length >= 3) endings.set(k, (endings.get(k) || 0) + 1);
95
+ }
96
+ const hits = [];
97
+ for (const x of own) {
98
+ const cta = x.d.match(CTA),
99
+ shared = x.end ? endings.get(norm(x.end)) : 0,
100
+ t = String(x.title ?? "").trim();
101
+ if (cta) hits.push([x.url, `ends with “${cta[0].trim()}”`]);
102
+ else if (shared >= 3) hits.push([x.url, `ends with “${x.end}”, like ${shared - 1} other description(s)`]);
103
+ else if (
104
+ titleRepeat &&
105
+ t.length >= 10 &&
106
+ x.d.toLowerCase().startsWith(t.toLowerCase()) &&
107
+ x.d
108
+ .slice(t.length)
109
+ .split(/\s+/)
110
+ .filter(w => /[\p{L}\p{N}]/u.test(w)).length < 5
111
+ )
112
+ hits.push([x.url, `repeats the title “${t}”`]);
113
+ }
114
+ return hits.length >= 3 ? hits : [];
115
+ }
116
+
117
+ // A URL's first folder ("/locations/" for /locations/leeds/); a top-level page is in none.
118
+ export const sectionOf = u => {
119
+ try {
120
+ const p = new URL(u, "http://x").pathname.split("/").filter(Boolean);
121
+ return p.length > 1 ? `/${p[0]}/` : "";
122
+ } catch {
123
+ return "";
124
+ }
125
+ };
126
+ // items: [{ url, section }]. A cluster is a section where 3 or more pages and at least half of its pages are templated.
127
+ // Verdict: cluster when clusters hold 80% of the templated pages, site-wide when half the site is templated, else scattered.
128
+ export function templatedShare(items, hitUrls) {
129
+ const hit = new Set(hitUrls),
130
+ per = new Map();
131
+ for (const x of items) {
132
+ const s = per.get(x.section) || per.set(x.section, { section: x.section, pages: 0, templated: 0 }).get(x.section);
133
+ s.pages++;
134
+ if (hit.has(x.url)) s.templated++;
135
+ }
136
+ const templated = items.filter(x => hit.has(x.url)).length;
137
+ const clusters = [...per.values()]
138
+ .filter(s => s.section && s.templated >= 3 && s.templated >= s.pages / 2)
139
+ .sort((a, b) => b.templated - a.templated);
140
+ const inClusters = clusters.reduce((n, s) => n + s.templated, 0),
141
+ share = items.length ? templated / items.length : 0;
142
+ const verdict = !templated
143
+ ? "none"
144
+ : inClusters >= 0.8 * templated
145
+ ? "cluster"
146
+ : share >= 0.5
147
+ ? "site-wide"
148
+ : "scattered";
149
+ return {
150
+ pages: items.length,
151
+ templated,
152
+ share: Math.round(share * 100) / 100,
153
+ clusters,
154
+ outsideClusters: templated - inClusters,
155
+ verdict,
156
+ };
157
+ }
158
+
159
+ // ---------- keyword use ----------
160
+ // For English pages. The phrase is the 2- or 3-word run from the title's main part (most words of 4+ letters) that the
161
+ // text uses most. The 5% and 3% lines are local, from CONTENT-03's "no density targets above about 2–3%".
162
+ const EDGE = new Set(
163
+ "a an and are as at be by for from in into is it of on or our the their to vs with we you your my".split(" "),
164
+ );
165
+ export function keywordUse({ title, headings = [], description = "", text }) {
166
+ const words = norm(text).split(" ").filter(Boolean);
167
+ if (words.length < 150) return null;
168
+ const main = seg => seg.filter(w => w.length >= 4 && !EDGE.has(w)).length;
169
+ const seg = String(title ?? "")
170
+ .split(new RegExp(`\\s+${SEP}\\s+|:\\s+`))
171
+ .map(s => norm(s).split(" ").filter(Boolean))
172
+ .reduce((a, b) => (main(b) > main(a) ? b : a));
173
+ const cands = [];
174
+ for (const n of [3, 2])
175
+ for (let i = 0; i + n <= seg.length; i++) {
176
+ const w = seg.slice(i, i + n);
177
+ if (!EDGE.has(w[0]) && !EDGE.has(w.at(-1)) && w.some(x => x.length >= 4)) cands.push(w.join(" "));
178
+ }
179
+ if (!cands.length) return null;
180
+ const padded = ` ${words.join(" ")} `,
181
+ count = p => padded.match(new RegExp(`(?<= )${p}(?= )`, "g"))?.length || 0;
182
+ const phrase = cands.reduce((a, b) => (count(b) > count(a) ? b : a));
183
+ const has = s => ` ${norm(s)} `.includes(` ${phrase} `),
184
+ h1 = headings.find(h => h.level === 1)?.text || "";
185
+ const subs = headings.filter(h => h.level > 1).map(h => h.text),
186
+ inSubs = subs.filter(has).length;
187
+ const first = ` ${words.slice(0, 100).join(" ")} `.includes(` ${phrase} `);
188
+ const density = Math.round((1000 * count(phrase) * phrase.split(" ").length) / words.length) / 10;
189
+ const spots = [
190
+ has(title) && "title",
191
+ has(h1) && "H1",
192
+ first && "first paragraph",
193
+ headings.some(h => h.level === 2 && has(h.text)) && "H2",
194
+ has(description) && "description",
195
+ ].filter(Boolean);
196
+ const verdict =
197
+ density > 5 || (inSubs >= 3 && inSubs > subs.length / 2)
198
+ ? "forced"
199
+ : density > 3
200
+ ? "repetitive"
201
+ : !has(h1) && !first
202
+ ? "missing"
203
+ : "natural";
204
+ return { phrase, verdict, density, spots };
205
+ }
206
+
207
+ // ---------- guide dates ----------
208
+ export const isGuide = (url, title, types = []) => {
209
+ let p = "";
210
+ try {
211
+ p = new URL(url).pathname;
212
+ } catch {}
213
+ return (
214
+ /\/(?:guides?|how-?to|tutorials?)(?:\/|$)/i.test(p) ||
215
+ /^how to\b|\bguide\b/i.test(title || "") ||
216
+ types.includes("HowTo")
217
+ );
218
+ };
219
+ const MONTHS = "jan feb mar apr may jun jul aug sep oct nov dec".split(" ");
220
+ const MON = String.raw`(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|june?|july?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)\.?`;
221
+ const DATE = String.raw`(\d{4}-\d{2}-\d{2}|\d{1,2}(?:st|nd|rd|th)?\s+${MON},?\s+\d{4}|${MON}\s+\d{1,2}(?:st|nd|rd|th)?,?\s+\d{4}|${MON}\s+\d{4})`;
222
+ const VISIBLE = new RegExp(String.raw`\b(?:updated|reviewed|modified|published|posted)(?:\s+on)?\s*:?\s*${DATE}`, "gi");
223
+ const timeOf = s => {
224
+ if (/^\d{4}-\d{2}-\d{2}/.test(s)) return Date.parse(s.slice(0, 10));
225
+ // Schema values can be anything ("N/A", "{{date}}"), so no four-digit year or no month name means NaN.
226
+ const l = s.toLowerCase(),
227
+ year = l.match(/\b\d{4}\b/)?.[0],
228
+ month = MONTHS.findIndex(m => l.includes(m));
229
+ if (!year || month < 0) return NaN;
230
+ return Date.UTC(+year, month, +(l.match(/\b(\d{1,2})(?:st|nd|rd|th)?\b/)?.[1] || 1));
231
+ };
232
+ // The page's newest date from schema, <time datetime> or a visible "updated" date, ignoring dates over two days
233
+ // ahead. Returns { time, date, from } or null.
234
+ export function newestDate(html, nodes = [], now = Date.now()) {
235
+ const found = [
236
+ ...nodes.flatMap(n => ["dateModified", "datePublished"].filter(k => typeof n[k] === "string").map(k => [n[k], k])),
237
+ ...[...html.matchAll(/<time\b[^>]*\bdatetime\s*=\s*["']?(\d{4}-\d{2}-\d{2})/gi)].map(m => [m[1], "<time>"]),
238
+ ...[
239
+ ...html
240
+ .replace(/<[^>]+>/g, " ")
241
+ .replace(/&nbsp;|&#160;/gi, " ")
242
+ .matchAll(VISIBLE),
243
+ ].map(m => [m[1], "a visible date"]),
244
+ ]
245
+ .map(([s, from]) => ({ time: timeOf(s), from }))
246
+ .filter(x => x.time > Date.UTC(1995, 0, 1) && x.time <= now + 2 * 864e5);
247
+ if (!found.length) return null;
248
+ const best = found.reduce((a, b) => (b.time > a.time ? b : a));
249
+ return { time: best.time, date: new Date(best.time).toISOString().slice(0, 10), from: best.from };
250
+ }
251
+
252
+ // ---------- claims ----------
253
+ // One claim per sentence, the first kind that matches. Each pattern needs a figure, a trend or a named study, so
254
+ // prices, discounts ("save 20%"), opening hours and founding years aren't claims.
255
+ const PEOPLE = String.raw`(?:customers|clients|users|teams|companies|businesses|people|members|subscribers|downloads|installs|students|developers|brands|organi[sz]ations|patients|readers|visitors|homes|drivers|families|websites|stores|shops|merchants|creators)`;
256
+ const NAMED =
257
+ /\b((?:(?:[A-Z][\w&.'’-]*|\d{4})\s+){1,4})(?:study|survey|report|poll|analysis|paper|research|data|researchers|analysts)\s+(?:found|finds|shows?|showed|suggests?|suggested|says|said|reveal(?:s|ed)|estimates?|estimated|predicts?|predicted|reports?|reported|conclude[sd]?)\b/;
258
+ const NOT_NAME = new Set(
259
+ "a an the one our their his her its this that these those new recent latest independent further early earlier previous some many other more most several another major large small leading internal academic scientific industry market customer annual global national local official what why how when where who which so but and yet also then here there now today".split(
260
+ " ",
261
+ ),
262
+ );
263
+ const YEAR = String.raw`(?:19|20)\d{2}`;
264
+ const BY_YEAR = new RegExp(String.raw`\bby\s+(?:the\s+(?:end|start|middle)\s+of\s+)?${YEAR}\b`, "i"),
265
+ IN_YEAR = new RegExp(String.raw`\b(?:in|since|from|between)\s+${YEAR}\b`, "i");
266
+ const FORECAST = /\b(?:will|(?:is|are)\s+(?:expected|projected|forecast|predicted|set|likely)\s+to)\b/i;
267
+ const TREND =
268
+ /\b(?:doubled|tripled|quadrupled|halved|(?:grown|grew|risen|rose|fallen|fell|dropped|increased|decreased|declined|jumped|surged|soared)\s+(?:by\s+)?(?:\d|a\s+(?:third|quarter|half)|half|tenfold|twofold|threefold))/i;
269
+ const MEASURE = /\d|\b(?:half|a\s+third|a\s+quarter|double|twice|triple|majority|most|million|billion)\b/i;
270
+ /** @type {[string, RegExp | ((s: string) => boolean)][]} */
271
+ const KINDS = [
272
+ [
273
+ "named source",
274
+ s => {
275
+ const m = s.match(NAMED);
276
+ return (
277
+ m &&
278
+ m[1]
279
+ .trim()
280
+ .split(/\s+/)
281
+ .some(w => /^[A-Z]/.test(w) && !NOT_NAME.has(w.toLowerCase()))
282
+ );
283
+ },
284
+ ],
285
+ ["study", /\b(?:studies|research|surveys?)\s+(?:show|shows|suggests?|proves?|found|finds|has shown|have shown)\b/i],
286
+ ["statistic", /\b\d{1,3}(?:\.\d+)?\s?%\s+of\b/i],
287
+ [
288
+ "percentage",
289
+ /\b(?:grew|grow|grows|grown|rose|rise|rises|risen|increased?|increases|decreased?|decreases|fell|fall|falls|fallen|dropped|drops?|declined?|declines|jumped|jumps?|cuts?|reduced?|reduces|boost(?:s|ed)?|improved?|improves|lower(?:s|ed)?|raised?|raises|doubled)\s+(?:[\w'’-]+\s+){0,3}?(?:by\s+)?(?:up\s+to\s+|over\s+|more\s+than\s+|nearly\s+|almost\s+|about\s+|around\s+|roughly\s+)?\d+(?:\.\d+)?\s?%|\b\d+(?:\.\d+)?\s?%\s+(?:more|less|fewer|faster|slower|higher|lower|cheaper|better|bigger|smaller|increase|decrease|growth|drop|rise|reduction|improvement|boost|jump|gain)\b/i,
290
+ ],
291
+ [
292
+ "multiplier",
293
+ /\b(?:\d+(?:\.\d+)?\s?[x×]|(?:\d+(?:\.\d+)?|two|three|four|five|ten)\s+times)\s+(?:faster|slower|more|less|fewer|cheaper|better|higher|lower|bigger|smaller|quicker|larger|greater|safer|stronger|longer)\b/i,
294
+ ],
295
+ [
296
+ "big number",
297
+ new RegExp(
298
+ String.raw`[$€£¥]\s?\d+(?:[.,]\d+)?\s?(?:million|billion|trillion|bn|m)\b|\b\d+(?:[.,]\d+)?\s?(?:million|billion|trillion)\b|\b(?:\d{2,3}(?:,\d{3})+|\d(?:,\d{3}){2,}|\d{5,}|[1-9]\d{1,2}k)\+?\s+(?:(?:happy|satisfied|active|paying|monthly|registered|loyal)\s+)?${PEOPLE}\b`,
299
+ "i",
300
+ ),
301
+ ],
302
+ [
303
+ "dated claim",
304
+ s =>
305
+ (BY_YEAR.test(s) && FORECAST.test(s) && MEASURE.test(s.replace(new RegExp(`\\b${YEAR}\\b`, "g"), ""))) ||
306
+ (IN_YEAR.test(s) && TREND.test(s)),
307
+ ],
308
+ ];
309
+ // A source counts in the claim's sentence or the next, unless the next is a claim with its own source. A named study
310
+ // already names its source, so "according to" isn't enough for it: it needs a link or footnote.
311
+ const LINKED = /https?:\/\/|\]\(|\[\^?\d+\]|\[\^[\w-]+\]|<a\s[^>]*href|\bsources?\s*:|\bvia\s*:/i;
312
+ const CITED = new RegExp(`${LINKED.source}|\\baccording to\\b`, "i");
313
+ const kindOf = x => KINDS.find(([, t]) => (typeof t === "function" ? t(x) : t.test(x)))?.[0];
314
+ export function claimsIn(text) {
315
+ const s = [...SENT.segment(String(text ?? ""))].map(x => x.segment).filter(x => x.trim()),
316
+ kinds = s.map(x => kindOf(x.trim())),
317
+ out = [];
318
+ s.forEach((raw, i) => {
319
+ const x = raw.trim(),
320
+ kind = kinds[i],
321
+ next = i + 1 < s.length && !kinds[i + 1] ? s[i + 1] : "";
322
+ // Joined untrimmed: a footnote's "[" can end one sentence and "^1]" start the next.
323
+ if (kind)
324
+ out.push({
325
+ kind,
326
+ claim: x.length > 200 ? x.slice(0, 199) + "…" : x,
327
+ sourced: (kind === "named source" ? LINKED : CITED).test(raw + next),
328
+ });
329
+ });
330
+ return out;
331
+ }
332
+
333
+ // ---------- hidden characters ----------
334
+ // Always hidden: zero-width space, word joiner, BOM, invisible maths operators (U+2061–2064), and tag characters
335
+ // (U+E0000–E007F) outside an emoji flag's tag sequence (🏴 + tag letters + cancel tag).
336
+ // https://www.unicode.org/reports/tr51/
337
+ // Soft hyphens and zero-width (non-)joiners count only inside Latin words, bidi controls only in text with no RTL
338
+ // script, the Hangul filler only with no other Hangul, and the Mongolian vowel separator only with no Mongolian.
339
+ const ALWAYS =
340
+ /[​⁠⁡-⁤]|[\u{E0000}-\u{E002F}\u{E003A}-\u{E0060}\u{E007B}-\u{E007E}]|(?<!\u{1F3F4}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{0,6})[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}\u{E007F}]/u;
341
+ const IN_LATIN = /(?<=[A-Za-z])[­‌‍](?=[A-Za-z])/;
342
+ const BIDI = /[‎‏‪-‮⁦-⁩]/,
343
+ RTL = /[\p{Script=Hebrew}\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Nko}\p{Script=Adlam}]/u;
344
+ const NAMES = {
345
+ "​": "zero-width space",
346
+ "⁠": "word joiner",
347
+ "": "byte-order mark",
348
+ "­": "soft hyphen",
349
+ "‌": "zero-width non-joiner",
350
+ "‍": "zero-width joiner",
351
+ "⁡": "function application",
352
+ "⁢": "invisible times",
353
+ "⁣": "invisible separator",
354
+ "⁤": "invisible plus",
355
+ "‎": "left-to-right mark",
356
+ "‏": "right-to-left mark",
357
+ "‪": "left-to-right embedding",
358
+ "‫": "right-to-left embedding",
359
+ "‬": "pop directional formatting",
360
+ "‭": "left-to-right override",
361
+ "‮": "right-to-left override",
362
+ "⁦": "left-to-right isolate",
363
+ "⁧": "right-to-left isolate",
364
+ "⁨": "first strong isolate",
365
+ "⁩": "pop directional isolate",
366
+ "ㅤ": "Hangul filler",
367
+ "᠎": "Mongolian vowel separator",
368
+ };
369
+ // The first hidden character: { index, char, code, name } or null.
370
+ export function invisibleChar(text) {
371
+ const t = String(text ?? "");
372
+ const res = [
373
+ ALWAYS,
374
+ IN_LATIN,
375
+ !RTL.test(t) && BIDI,
376
+ !/[ᄀ-ᇿㄱ-ㅣㅥ-ㆎ가-힯]/.test(t) && /ㅤ/,
377
+ !/[᠀-᠍᠏-᢯]/.test(t) && /᠎/,
378
+ ].filter(Boolean);
379
+ const m = res
380
+ .map(re => re.exec(t))
381
+ .filter(Boolean)
382
+ .sort((a, b) => a.index - b.index)[0];
383
+ if (!m) return null;
384
+ const cp = m[0].codePointAt(0);
385
+ return {
386
+ index: m.index,
387
+ char: m[0],
388
+ code: `U+${cp.toString(16).toUpperCase().padStart(4, "0")}`,
389
+ name: NAMES[m[0]] || "tag character",
390
+ };
391
+ }