All files / apps/portfolio/app/utils work.ts

100% Statements 18/18
100% Branches 18/18
100% Functions 3/3
100% Lines 15/15

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58        8x   8x                                         63x     8x 59x 59x   59x 27x     32x                 8x 14x   12x 12x   12x   6x    
import type { Work } from "../types/Work.ts";
import type { WorkCase } from "../types/WorkCase.ts";
import type { WorkStudy } from "../types/WorkStudy.ts";
 
export const WORK_PATH = "/work/";
 
export const WORK_FIELDS = [
    "path",
    "order",
    "name",
    "kind",
    "stage",
    "line",
    "live",
    "caseStudy",
    "title",
    "mark",
    "facts",
    "screenshot",
] as const;
 
export type WorkRow = Pick<Work, "name" | "kind" | "stage" | "line" | "live"> &
    Partial<Pick<WorkStudy, "title" | "mark" | "facts" | "screenshot">> & {
        path: string;
        caseStudy: boolean;
    };
 
export const isStudy = (work: Work): work is WorkStudy => work.caseStudy;
 
/** A row that claims a study but lacks a field the lists print is listed as a tool, never as a broken study. */
export const toWork = (row: WorkRow): Work => {
    const { name, kind, stage, line, live, title, mark, facts, screenshot } = row;
    const base = { slug: row.path.slice(WORK_PATH.length), name, kind, stage, line, live };
 
    if (row.caseStudy && title && mark && facts && screenshot) {
        return { ...base, caseStudy: true, title, mark, facts, screenshot };
    }
 
    return { ...base, caseStudy: false };
};
 
type WorkCaseRow = WorkRow &
    Partial<Pick<WorkCase, "why" | "countedOn" | "design" | "decisions">> & {
        inProgress?: boolean;
    };
 
/** A case study is an entry with every field its page prints; one missing one reads as no study. */
export const toWorkCase = (row: WorkCaseRow | null | undefined): WorkCase | null => {
    if (!row) return null;
 
    const work = toWork(row);
    const { why, countedOn, design, decisions } = row;
 
    if (!isStudy(work) || !why || !countedOn || !design || !decisions) return null;
 
    return { ...work, why, countedOn, design, decisions, inProgress: row.inProgress ?? false };
};