Files
sorsfonalak/services/frontend/src/lib/astro.ts
T

93 lines
3.1 KiB
TypeScript
Raw Normal View History

// Hungarian names and glyphs for the chart tables.
export const SIGNS: Record<string, { hu: string; glyph: string }> = {
aries: { hu: "Kos", glyph: "♈" },
taurus: { hu: "Bika", glyph: "♉" },
gemini: { hu: "Ikrek", glyph: "♊" },
cancer: { hu: "Rák", glyph: "♋" },
leo: { hu: "Oroszlán", glyph: "♌" },
virgo: { hu: "Szűz", glyph: "♍" },
libra: { hu: "Mérleg", glyph: "♎" },
scorpio: { hu: "Skorpió", glyph: "♏" },
sagittarius: { hu: "Nyilas", glyph: "♐" },
capricorn: { hu: "Bak", glyph: "♑" },
aquarius: { hu: "Vízöntő", glyph: "♒" },
pisces: { hu: "Halak", glyph: "♓" },
};
export const POINTS: Record<string, { hu: string; glyph: string }> = {
sun: { hu: "Nap", glyph: "☉" },
moon: { hu: "Hold", glyph: "☽" },
mercury: { hu: "Merkúr", glyph: "☿" },
venus: { hu: "Vénusz", glyph: "♀" },
mars: { hu: "Mars", glyph: "♂" },
jupiter: { hu: "Jupiter", glyph: "♃" },
saturn: { hu: "Szaturnusz", glyph: "♄" },
uranus: { hu: "Uránusz", glyph: "♅" },
neptune: { hu: "Neptunusz", glyph: "♆" },
pluto: { hu: "Plútó", glyph: "♇" },
north_node: { hu: "Észak-Holdcsomópont", glyph: "☊" },
south_node: { hu: "Dél-Holdcsomópont", glyph: "☋" },
lilith: { hu: "Lilith", glyph: "⚸" },
chiron: { hu: "Kiron", glyph: "⚷" },
ceres: { hu: "Ceres", glyph: "⚳" },
pallas: { hu: "Pallas", glyph: "⚴" },
juno: { hu: "Juno", glyph: "⚵" },
vesta: { hu: "Vesta", glyph: "⚶" },
};
export const ANGLES: [string, string][] = [
["ascendant", "Aszcendens"],
["midheaven", "MC"],
["descendant", "Descendens"],
["imum_coeli", "IC"],
];
export function signName(sign: string | null | undefined): string {
return sign ? (SIGNS[sign]?.hu ?? sign) : "–";
}
/** `12°20'50"` → `12°20′50″` (typographic prime marks). */
export function dms(text: string): string {
return text.replace(/'/g, "′").replace(/"/g, "″");
}
export const ROLE_LABELS: Record<string, string> = {
user: "Felhasználó",
premium: "Prémium",
vip: "VIP",
creator: "Szerző",
admin: "Admin",
};
const regionNames = new Intl.DisplayNames(["hu"], { type: "region" });
/** Hungarian country name from an ISO code (falls back to the given name). */
export function countryName(iso2: string, fallback?: string): string {
try {
return regionNames.of(iso2) ?? fallback ?? iso2;
} catch {
return fallback ?? iso2;
}
}
export function formatDate(iso: string | null | undefined, withTime = false): string {
if (!iso) return "–";
const d = new Date(iso);
return new Intl.DateTimeFormat("hu-HU", {
year: "numeric",
month: "long",
day: "numeric",
...(withTime ? { hour: "2-digit", minute: "2-digit" } : {}),
timeZone: "Europe/Budapest",
}).format(d);
}
/** `1990-03-15` → `1990. március 15.` without time zone shifts. */
export function formatBirthDate(date: string): string {
const [y, m, d] = date.split("-").map(Number);
return new Intl.DateTimeFormat("hu-HU", { year: "numeric", month: "long", day: "numeric", timeZone: "UTC" }).format(
new Date(Date.UTC(y, m - 1, d)),
);
}