/* * Copyright (c) 2021-2026 ahriman team. * * This file is part of ahriman * (see https://github.com/arcan1s/ahriman). * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import type { AutoRefreshInterval } from "models/AutoRefreshInterval"; // https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument */ export function applyMixins(clazz: any, classes: any[]): void { classes.forEach(baseClass => { Object.getOwnPropertyNames(baseClass.prototype).forEach(name => { Object.defineProperty( clazz.prototype, name, Object.getOwnPropertyDescriptor(baseClass.prototype, name) || Object.create(null), ); }); }); } /* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument */ export function defaultInterval(intervals: AutoRefreshInterval[]): number { return intervals.find(interval => interval.is_active)?.interval ?? 0; } declare global { interface Array { unique(): T[]; } interface Date { toISOStringShort(): string; } } Array.prototype.unique = function (): T[] { return [...new Set(this)].sort(); }; // custom formatter to print pretty date, because there is no builtin for this Date.prototype.toISOStringShort = function (): string { const pad: (num: number) => string = num => String(num).padStart(2, "0"); return `${this.getFullYear()}-${pad(this.getMonth() + 1)}-${pad(this.getDate())} ${pad(this.getHours())}:${pad(this.getMinutes())}:${pad(this.getSeconds())}`; };