Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
mail.ts 16.25 KiB
import Degree from "./degrees";
import Gender from "./genders";
import { locales, type Locale } from "./i18n/i18n";
import type { Tutor } from "./server/database/entities/Tutor.entity";
import markdownit from "markdown-it";
import type { Localized } from "./utils";
import type { Config } from "./server/database/entities/Config.entity";
import type { DateTimeFormatOptions } from "intl";
const md = markdownit({
breaks: true,
linkify: true,
quotes: "„“‚‘",
typographer: true,
html: true,
});
export type MailTemplate = {
replyTo: string;
subject: Localized;
text: Localized;
type: TemplateType;
};
export const formatters: Record<string, { description: string, format: (l: Locale, arg: unknown, constructorArg: unknown|null)=>string }> = {
date: {
description: "Formatiert ein Datum, Kontruktorargumente sind die Optionen für Intl.DateTimeFormat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)",
format: (locale, arg, constructorArg)=>new Intl.DateTimeFormat(locale, constructorArg as DateTimeFormatOptions ?? undefined).format(arg as Date),
},
dateLong: {
description: "Formatiert ein Datum, z.B. 01. Januar 1970",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "2-digit" }).format(arg as Date),
},
dateShort: {
description: "Formatiert ein Datum, z.B. 1. Januar",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { month: "long", day: "numeric" }).format(arg as Date),
},
dateWeekday: {
description: "Gibt den Wochentag eines Datums zurück, z.B. Montag",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { weekday: "long" }).format(arg as Date),
},
dateWeekdayShort: {
description: "Gibt den Wochentag eines Datums zurück, z.B. Mo",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { weekday: "short" }).format(arg as Date),
},
dateRange: {
description: "Formatiert einen Datumsbereich, Konsruktorargumente sind die Optionen für Intl.DateTimeFormat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)",
format: (locale, arg, constructorArg)=>new Intl.DateTimeFormat(locale, constructorArg as DateTimeFormatOptions ?? undefined).formatRange((arg as [Date, Date])[0], (arg as [Date, Date])[1]),
},
dateRangeLong: {
description: "Formatiert einen Datumsbereich, z.B. 1. - 2. Januar 1970",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", day: "2-digit" }).formatRange((arg as [Date, Date])[0], (arg as [Date, Date])[1]),
},
dateRangeShort: {
description: "Formatiert einen Datumsbereich, z.B. 1. - 2. Januar",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { month: "long", day: "numeric" }).formatRange((arg as [Date, Date])[0], (arg as [Date, Date])[1]),
},
time: {
description: "Formatiert eine Uhrzeit, z.B. 12:34",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" }).format(arg as Date),
},
timeRange: {
description: "Formatiert einen Zeitbereich, z.B. 12:34 - 13:45 Uhr",
format: (locale, arg)=>new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" }).formatRange((arg as [Date, Date])[0], (arg as [Date, Date])[1]),
},
lowercase: {
description: "Konvertiert den Text in Kleinbuchstaben",
format: (_, arg)=>String(arg).toLowerCase(),
},
uppercase: {