initial commit

This commit is contained in:
Matthias
2026-06-15 11:33:23 +02:00
commit fc0a6fb975
155 changed files with 24526 additions and 0 deletions

41
src/lib/format.ts Normal file
View File

@@ -0,0 +1,41 @@
import { format as dfFormat } from "date-fns";
import { de } from "date-fns/locale";
export const eur = new Intl.NumberFormat("de-DE", {
style: "currency",
currency: "EUR",
});
export const pct = new Intl.NumberFormat("de-DE", {
style: "percent",
minimumFractionDigits: 1,
maximumFractionDigits: 1,
});
export function formatDate(date: Date | string | undefined): string {
if (!date) return "";
const d = typeof date === "string" ? new Date(date) : date;
return dfFormat(d, "dd.MM.yyyy", { locale: de });
}
export function formatMonth(monthKey: string | undefined): string {
if (!monthKey) return "";
const [year, month] = monthKey.split("-");
return `${month}.${year}`;
}
export function formatAmount(amount: number): string {
if (amount === 0) return eur.format(0);
return eur.format(amount);
}
export function amountClass(amount: number): string {
if (amount < 0) return "text-red-600 dark:text-red-400";
if (amount > 0) return "text-emerald-600 dark:text-emerald-400";
return "";
}
export function dashIfZero(value: number, formatter: (n: number) => string = (n) => String(n)): string {
if (value === 0) return "";
return formatter(value);
}