| 1 | import generated from "@/data/features.generated.json"; |
| 2 | import { REPO_URL } from "./i18n/links"; |
| 3 | |
| 4 | export type FeatureStatus = "stable" | "flagged" | "experimental"; |
| 5 | export type SurfaceStatus = "stable" | "partial" | "preview" | "none"; |
| 6 | export interface Feature { |
| 7 | id: string; |
| 8 | name: string; |
| 9 | summary: string; |
| 10 | status: FeatureStatus; |
| 11 | surfaces: Partial<Record<"tui" | "desktop" | "web" | "api", SurfaceStatus>>; |
| 12 | since: string | null; |
| 13 | flag: string | null; |
| 14 | docs: string | null; |
| 15 | registryLine: number; |
| 16 | } |
| 17 | |
| 18 | export const FEATURE_CATALOGUE = generated as { |
| 19 | format: string; |
| 20 | source: { path: string; sha256: string }; |
| 21 | features: Feature[]; |
| 22 | }; |
| 23 | |
| 24 | export function featureDocsHref(feature: Feature): string { |
| 25 | return `${REPO_URL}/blob/main/${feature.docs ?? `docs/features.toml#L${feature.registryLine}`}`; |
| 26 | } |
| 27 | |
| 28 | export function compareVersions(left: string, right: string): number | null { |
| 29 | const parts = (value: string) => /^\d+\.\d+\.\d+$/.test(value) ? value.split(".").map(Number) : null; |
| 30 | const a = parts(left); |
| 31 | const b = parts(right); |
| 32 | if (!a || !b) return null; |
| 33 | for (let i = 0; i < 3; i++) { |
| 34 | if (a[i] !== b[i]) return a[i] - b[i]; |
| 35 | } |
| 36 | return 0; |
| 37 | } |
| 38 |