mirror of
https://github.com/skidoodle/albert.lol.git
synced 2025-02-15 06:09:15 +01:00
19 lines
468 B
TypeScript
19 lines
468 B
TypeScript
export default function age() {
|
|
const BIRTHDATE = process.env.NEXT_PUBLIC_BIRTHDATE;
|
|
if (!BIRTHDATE) {
|
|
console.warn("Missing environment variable: BIRTHDATE");
|
|
return 0;
|
|
}
|
|
|
|
return Math.floor(
|
|
(new Date().getTime() - new Date(BIRTHDATE).getTime()) / 3.15576e10,
|
|
);
|
|
}
|
|
|
|
export const truncate = (str: string, n: number): string => {
|
|
if (str.length > n) {
|
|
const truncated = str.slice(0, n - 3).trimEnd();
|
|
return `${truncated}...`;
|
|
}
|
|
return str.trim();
|
|
};
|