All files / src/apps/user/pages/knowledge util.ts

75% Statements 6/8
75% Branches 3/4
75% Functions 3/4
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30            110x       35x                             43x 43x 29x    
import { encodeResourceId } from "@/components/detail";
import { APP_ROUTES, ROUTE_PARAMS } from "@/routes/const";
import type { LucideIcon } from "lucide-react";
import { sourceType } from "./sourceTypes";
 
export function sourceIcon(key: string): LucideIcon {
  return sourceType(key).Icon;
}
 
export function repositoryHref(id: string): string {
  return APP_ROUTES.USER.KNOWLEDGE.REPOSITORIES.id.replace(
    ROUTE_PARAMS.REPOSITORY.id,
    encodeResourceId(id),
  );
}
 
export function knowledgeHref(id: string): string {
  return APP_ROUTES.USER.KNOWLEDGE.id.replace(
    ROUTE_PARAMS.KNOWLEDGE.id,
    encodeResourceId(id),
  );
}
 
/** A file's size, as the knowledge pages show it. */
export function formatBytes(bytes: number): string {
  Iif (bytes < 1024) return `${bytes} B`;
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}