docs: add audit tools

This commit is contained in:
2026-09-12 21:48:39 +05:00
parent ce33201302
commit 71b5c90a4a
2 changed files with 66 additions and 0 deletions
@@ -4,6 +4,7 @@
FieldSpecKind, FieldSpecKind,
ToolSchema, ToolSchema,
} from "$lib/registry-schema"; } from "$lib/registry-schema";
import { fieldLabel as labelOf } from "$lib/i18n/schema-tool-strings";
import { RotateCcw } from "@lucide/svelte"; import { RotateCcw } from "@lucide/svelte";
import type { Component } from "svelte"; import type { Component } from "svelte";
import DimensionField from "./fields/DimensionField.svelte"; import DimensionField from "./fields/DimensionField.svelte";
+65
View File
@@ -0,0 +1,65 @@
import type { ToolEntry } from "$lib/registry";
import type { Field } from "$lib/registry-schema";
import { ru } from "./ru";
import { getMergedDict } from "./locale.svelte";
import type { SearchDoc } from "./matching";
import { t } from "./t";
function labelOf(id: string): string {
return id
.replace(/([a-z])([A-Z])/g, "$1 $2")
.replace(/[_-]+/g, " ")
.replace(/\b\w/g, (c) => c.toUpperCase());
}
export function toolTitle(tool: ToolEntry): string {
return getMergedDict().tools[tool.id]?.title ?? tool.title;
}
export function toolDescription(tool: ToolEntry): string {
return getMergedDict().tools[tool.id]?.description ?? tool.description;
}
export function fieldLabel(field: Field<unknown>, id: string): string {
const key = (field.spec as { label?: string }).label;
if (key) {
const translated = t(key);
if (translated !== key) return translated;
}
return labelOf(id);
}
export function groupLabel(title: string): string {
return t(title);
}
export function verdictText(toolId: string, key: string): string {
return getMergedDict().tools[toolId]?.results?.[key] ?? key;
}
export function verdictTone(key: string): "success" | "danger" | "info" {
if (/[Yy]es$|[Tt]rue$/.test(key)) return "success";
if (/[Nn]o$|[Ff]alse$/.test(key)) return "danger";
return "info";
}
function dedupe(values: string[]): string[] {
return [...new Set(values.filter((v) => v.length > 0))];
}
export function toolSearchDoc(tool: ToolEntry): SearchDoc {
const active = getMergedDict().tools[tool.id];
return {
id: tool.id,
titles: dedupe([
active?.title ?? "",
ru.tools[tool.id]?.title ?? "",
tool.title,
]),
descriptions: dedupe([
active?.description ?? "",
ru.tools[tool.id]?.description ?? "",
tool.description,
]),
};
}