React + Vite frontend with a local-JSON-backed API (Vite middleware) for tracking portfolio holdings, contributions/withdrawals, recurring contribution plans, and a forecast chart comparing the portfolio's real value against a same-contributions S&P 500 benchmark. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
18 lines
496 B
TypeScript
18 lines
496 B
TypeScript
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
const DATA_DIR = join(process.cwd(), "data");
|
|
|
|
export function dataPath(file: string): string {
|
|
return join(DATA_DIR, file);
|
|
}
|
|
|
|
export function readJson<T>(file: string): T {
|
|
const raw = readFileSync(dataPath(file), "utf-8");
|
|
return JSON.parse(raw) as T;
|
|
}
|
|
|
|
export function writeJson<T>(file: string, data: T): void {
|
|
writeFileSync(dataPath(file), JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
}
|